|
@@ -1,13 +1,14 @@
|
|
|
import { Component } from 'react';
|
|
|
-import Taro,{getCurrentPages} from '@tarojs/taro';
|
|
|
+import Taro from '@tarojs/taro';
|
|
|
import {connect} from 'react-redux'
|
|
|
-import { View, Image } from '@tarojs/components'
|
|
|
+import {View, Image} from '@tarojs/components'
|
|
|
|
|
|
import {set} from '../../actions/counter'
|
|
|
-import { login,getUserOrderList } from '../../utils/servers/servers'
|
|
|
+import { login,getUserOrderList,setDecryptData } from '../../utils/servers/servers'
|
|
|
|
|
|
import NavBar from "../../components/NavBar";
|
|
|
import ListBottomStart from "../../components/common/listBottomStart";
|
|
|
+import PhoneWarrantMore from "../../components/common/phoneWarrantMore";
|
|
|
|
|
|
import './index.less'
|
|
|
|
|
@@ -31,7 +32,9 @@ class Index extends Component {
|
|
|
list: [],
|
|
|
pageNo: 0,
|
|
|
listState: 'LOADING',
|
|
|
- userInfor:Taro.getStorageSync('userInfor') || ''
|
|
|
+ userInfor:Taro.getStorageSync('userInfor') || '',
|
|
|
+ token: Taro.getStorageSync('token') || '',
|
|
|
+ visible: false,
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -39,7 +42,8 @@ class Index extends Component {
|
|
|
this.props.set(1);
|
|
|
if(!Taro.getStorageSync('token')){
|
|
|
this.setState({
|
|
|
- list: []
|
|
|
+ list: [],
|
|
|
+ token: '',
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -56,35 +60,27 @@ class Index extends Component {
|
|
|
this.getUserOrderList(this.state.pageNo+1);
|
|
|
}
|
|
|
|
|
|
- async login(nickname){
|
|
|
- Taro.showLoading({
|
|
|
- title:'登录中...',
|
|
|
- })
|
|
|
- let token = Taro.getStorageSync('token');
|
|
|
- if(!token){
|
|
|
- let loginMsg = await Taro.login();
|
|
|
- if (loginMsg.code) {
|
|
|
- try{
|
|
|
- let msg = await login({
|
|
|
- code:loginMsg.code,
|
|
|
- nickname
|
|
|
- });
|
|
|
- if(msg.error.length === 0){
|
|
|
- Taro.setStorageSync('token', msg.token);
|
|
|
- this.getUserOrderList();
|
|
|
- }else{
|
|
|
- Taro.showToast({title:msg.error[0].message,icon:'none'})
|
|
|
+ login(){
|
|
|
+ Taro.getUserProfile({
|
|
|
+ desc: '用于用户登录',
|
|
|
+ success: (userInfor)=> {
|
|
|
+ login(userInfor).then((mobile)=>{
|
|
|
+ if(!mobile){
|
|
|
+ this.setState({
|
|
|
+ visible: true
|
|
|
+ })
|
|
|
}
|
|
|
- }catch (err) {
|
|
|
- Taro.showToast({title:'系统错误,请稍后重试',icon:'none'});
|
|
|
- console.log(err)
|
|
|
- }
|
|
|
- } else {
|
|
|
- Taro.showToast({title:loginMsg.errMsg,icon:'none'})
|
|
|
- console.log('登录失败!' + loginMsg.errMsg)
|
|
|
+ this.setState({
|
|
|
+ userInfor:Taro.getStorageSync('userInfor') || '',
|
|
|
+ token: Taro.getStorageSync('token') || '',
|
|
|
+ })
|
|
|
+ this.getUserOrderList();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: ()=>{
|
|
|
+ Taro.showToast({title:'请同意授权获取用户信息',icon:'none'});
|
|
|
}
|
|
|
- }
|
|
|
- Taro.hideLoading();
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
async getUserOrderList (pageNo = 1){
|
|
@@ -120,6 +116,11 @@ class Index extends Component {
|
|
|
}
|
|
|
}else{
|
|
|
Taro.showToast({title:msg.error[0].message,icon:'none'});
|
|
|
+ if(msg.error[0].field === '403'){
|
|
|
+ this.setState({
|
|
|
+ token: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
this.setState({
|
|
|
listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
|
|
|
})
|
|
@@ -127,6 +128,38 @@ class Index extends Component {
|
|
|
Taro.stopPullDownRefresh();
|
|
|
}
|
|
|
|
|
|
+ async setDecryptData(data){
|
|
|
+ let msg = await setDecryptData({
|
|
|
+ encryptedData : data.encryptedData,
|
|
|
+ iv : data.iv
|
|
|
+ });
|
|
|
+ if(msg.error && msg.error.length !== 0){
|
|
|
+ if(msg.error[0].field === '403'){
|
|
|
+ this.setState({
|
|
|
+ token: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+ Taro.showToast({title:msg.error[0].message,icon:'none'});
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(msg.phoneNumber){
|
|
|
+ let userInfor = Taro.getStorageSync('userInfor');
|
|
|
+ userInfor.mobile = msg.phoneNumber;
|
|
|
+ Taro.setStorageSync('userInfor', userInfor);
|
|
|
+ this.setState({
|
|
|
+ userInfor: userInfor
|
|
|
+ })
|
|
|
+ Taro.showToast({
|
|
|
+ title:'绑定成功',
|
|
|
+ icon:'success'
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ Taro.showToast({
|
|
|
+ title:'绑定失败',
|
|
|
+ icon:'error'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
render () {
|
|
|
return (
|
|
@@ -142,24 +175,11 @@ class Index extends Component {
|
|
|
if(Taro.getStorageSync('token')){
|
|
|
return;
|
|
|
}
|
|
|
- Taro.getUserProfile({
|
|
|
- desc: '用于用户登录',
|
|
|
- success: async (res)=> {
|
|
|
- let userInfo = res.userInfo
|
|
|
- let nickName = userInfo.nickName
|
|
|
- Taro.setStorageSync('userInfor', userInfo);
|
|
|
- await this.login(nickName);
|
|
|
- await this.getUserOrderList();
|
|
|
- getCurrentPages()[getCurrentPages().length - 1].onLoad()
|
|
|
- },
|
|
|
- fail: ()=>{
|
|
|
- Taro.showToast({title:'请同意授权获取用户信息',icon:'none'});
|
|
|
- }
|
|
|
- })
|
|
|
+ this.login()
|
|
|
}}>
|
|
|
<View className='avatar'>
|
|
|
{
|
|
|
- Taro.getStorageSync('token') ?
|
|
|
+ this.state.token ?
|
|
|
<Image src={this.state.userInfor.avatarUrl} className='login'/> :
|
|
|
<Image className='noLogin' src={userIcon}/>
|
|
|
}
|
|
@@ -167,11 +187,17 @@ class Index extends Component {
|
|
|
</View>
|
|
|
<View className='nickName'>
|
|
|
{
|
|
|
- Taro.getStorageSync('token') ?
|
|
|
+ this.state.token ?
|
|
|
this.state.userInfor.nickName :
|
|
|
'点击登录'
|
|
|
}
|
|
|
</View>
|
|
|
+ {this.state.token && this.state.userInfor && !this.state.userInfor.mobile ? <View className='bindPhone' onClick={(e)=>{
|
|
|
+ e.stopPropagation();
|
|
|
+ this.setState({
|
|
|
+ visible:true
|
|
|
+ })
|
|
|
+ }}>绑定手机</View> : null}
|
|
|
</View>
|
|
|
<View className='list'>
|
|
|
{this.state.list.map((v,k)=>(
|
|
@@ -203,6 +229,17 @@ class Index extends Component {
|
|
|
this.getUserOrderList(this.state.pageNo+1);
|
|
|
}}/>
|
|
|
</View>
|
|
|
+ <PhoneWarrantMore
|
|
|
+ visible={this.state.visible}
|
|
|
+ onClose={()=>{
|
|
|
+ this.setState({
|
|
|
+ userInfor: Taro.getStorageSync('userInfor')
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ visible:false
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ />
|
|
|
</View>
|
|
|
)
|
|
|
}
|