|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
import {CSSProperties, FC, useState} from "react"; |
|
|
|
|
import {View,Image} from "@tarojs/components"; |
|
|
|
|
import {View, Image} from "@tarojs/components"; |
|
|
|
|
import styles from './index.module.scss' |
|
|
|
|
import NoLogin from '@/static/img/noLogin.png' |
|
|
|
|
import {Profile} from "@/store"; |
|
|
|
@ -9,55 +9,60 @@ import {userApi} from "@/api"; |
|
|
|
|
interface Props { |
|
|
|
|
tips?: string |
|
|
|
|
height?: number |
|
|
|
|
paddingTop?: number |
|
|
|
|
style?: CSSProperties |
|
|
|
|
offImage?: boolean |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const LoginView: FC<Props> = (props) => { |
|
|
|
|
const LoginView: FC<Props> = (props) => { |
|
|
|
|
const [isLoading, setLoading] = useState(false) |
|
|
|
|
const {setUser,setToken,setCompany} = Profile.useContainer() |
|
|
|
|
const text = props.tips ?? '登录后可查看更多内容' |
|
|
|
|
const size: string = props.height? `${props.height}px`:'0rpx' |
|
|
|
|
const {setUser, setToken, setCompany} = Profile.useContainer() |
|
|
|
|
const sizeStyle: CSSProperties = { |
|
|
|
|
height:'1000rpx', |
|
|
|
|
paddingTop:size, |
|
|
|
|
height: `${props.height || 1000}rpx`, |
|
|
|
|
paddingTop: `${props.paddingTop || 0}rpx`, |
|
|
|
|
...props.style, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function login() { |
|
|
|
|
if (isLoading) return; |
|
|
|
|
Taro.showLoading({title:'微信授权中...'}) |
|
|
|
|
Taro.showLoading({title: '微信授权中...'}) |
|
|
|
|
setLoading(true) |
|
|
|
|
Taro.login({ |
|
|
|
|
success: async (res) => { |
|
|
|
|
try { |
|
|
|
|
const {catch_key, user, token, company} = await userApi.login(res.code) |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
if (token) { |
|
|
|
|
Taro.showToast({title:'授权成功',duration:1500,icon:'success',mask:true}) |
|
|
|
|
setTimeout(()=>{ |
|
|
|
|
setUser(user) |
|
|
|
|
setToken(token) |
|
|
|
|
setCompany(company) |
|
|
|
|
setLoading(false) |
|
|
|
|
Taro.switchTab({url: '/pages/home/home'}) |
|
|
|
|
},1500) |
|
|
|
|
} else { |
|
|
|
|
Taro.setStorageSync('openid', catch_key) |
|
|
|
|
Taro.reLaunch({url: '/pages/check/check'}) |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
Taro.login({ |
|
|
|
|
success: async (res) => { |
|
|
|
|
try { |
|
|
|
|
const {catch_key, user, token, company} = await userApi.login(res.code) |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
if (token) { |
|
|
|
|
Taro.showToast({title: '授权成功', duration: 1500, icon: 'success', mask: true}) |
|
|
|
|
setTimeout(() => { |
|
|
|
|
setUser(user) |
|
|
|
|
setToken(token) |
|
|
|
|
setCompany(company) |
|
|
|
|
setLoading(false) |
|
|
|
|
Taro.switchTab({url: '/pages/home/home'}) |
|
|
|
|
}, 1500) |
|
|
|
|
} else { |
|
|
|
|
Taro.setStorageSync('openid', catch_key) |
|
|
|
|
Taro.reLaunch({url: '/pages/check/check'}) |
|
|
|
|
} |
|
|
|
|
setLoading(false) |
|
|
|
|
} catch (e) { |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
setLoading(false) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className={styles.content} style={sizeStyle}> |
|
|
|
|
<Image src={NoLogin}></Image> |
|
|
|
|
<View className={styles.title}>暂未登录</View> |
|
|
|
|
<View className={styles.label}>{text}</View> |
|
|
|
|
<View onClick={()=>{login()}} className={styles.button}>立即登录</View> |
|
|
|
|
<View className={styles.nextLabel}>点击立即登录完成微信授权以继续使用</View> |
|
|
|
|
{ |
|
|
|
|
!props.offImage && <> |
|
|
|
|
<Image src={NoLogin}/> |
|
|
|
|
<View className={styles.title}>暂未登录</View> |
|
|
|
|
</> |
|
|
|
|
} |
|
|
|
|
<View className={styles.label}>点击按钮完成微信授权</View> |
|
|
|
|
<View onClick={login} className={styles.button}>立即登录</View> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|