| New file |
| | |
| | | import Taro from '@tarojs/taro'; |
| | | import { Component } from 'react'; |
| | | import { View, Button } from '@tarojs/components'; |
| | | import { connect } from 'react-redux'; |
| | | import { dispatch } from '../../../utils/redux'; |
| | | import { _UID } from '../../../constants/api'; |
| | | import { dispatchLoginStatusUpdate } from '../../../actions/user'; |
| | | import { dispatchLogout } from '../../../actions/user_weapp'; |
| | | import { jumpTo } from '../../../utils/jump'; |
| | | import { getStorage } from '../../../utils/tools'; |
| | | import { loginStatus as loginStatusConst } from '../../../constants/user'; |
| | | import gioReport from '../../../utils/gio'; |
| | | |
| | | import './index.less' |
| | | import { createPage } from '../../../utils/page'; |
| | | |
| | | type Props = { |
| | | dispatch: any |
| | | dispatchLogout: any |
| | | dispatchLoginStatusUpdate: any |
| | | }; |
| | | type State = { |
| | | loginStatus: number |
| | | }; |
| | | |
| | | // @ts-ignore |
| | | @connect(() => ({}), { |
| | | dispatch, |
| | | dispatchLogout, |
| | | dispatchLoginStatusUpdate |
| | | }) |
| | | // @ts-ignore |
| | | @createPage() |
| | | export default class Set extends Component<Props, State> { |
| | | $app: any = Taro.getApp().$app; |
| | | state = { |
| | | loginStatus: loginStatusConst.NOT_LOGIN, |
| | | } |
| | | async componentDidShow() { |
| | | this.$app.xpReportShow(); |
| | | const otp = await getStorage('otp'); |
| | | if (!otp) { |
| | | this.setState({ loginStatus: loginStatusConst.NOT_LOGIN }); |
| | | } else { |
| | | this.setState({ loginStatus: loginStatusConst.LOGIN }); |
| | | } |
| | | } |
| | | |
| | | |
| | | componentDidHide() { |
| | | this.$app.xpReportHide(); |
| | | } |
| | | |
| | | handleLogout = () => { |
| | | this.$app.xpReportSend({ pageId: 'P10037', buttonId: 'B026' }); |
| | | Taro.showModal({ |
| | | title: '确定要退出登录吗', |
| | | content: '', |
| | | confirmColor: '#7BAE3F', |
| | | cancelColor: '#808080', |
| | | }) |
| | | .then(res => { |
| | | if (res.confirm) { |
| | | this.props.dispatch({ type: 'loginOut' }); |
| | | this.$app.xpReportSend({ pageId: 'P10037', buttonId: 'B006' }); |
| | | this.props.dispatchLogout({}) |
| | | .then(() => { |
| | | gioReport.logoutClearReport(); |
| | | Taro.setStorage({ key: _UID, data: '-1' }); |
| | | Taro.setStorage({ key: 'otp', data: '', complete: () => { |
| | | jumpTo({ type: 'back' }); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | }) |
| | | |
| | | // 通知webview刷新code |
| | | this.props.dispatchLoginStatusUpdate({ userUpdate: true }); |
| | | } |
| | | |
| | | render() { |
| | | const { loginStatus } = this.state |
| | | |
| | | return ( |
| | | <View className='set-page-box'> |
| | | {loginStatus === loginStatusConst.LOGIN && ( |
| | | <View className='logout-cont'> |
| | | <Button className='btn-logout' onClick={this.handleLogout}>退出登录</Button> |
| | | </View> |
| | | )} |
| | | </View> |
| | | ); |
| | | } |
| | | } |