|
@@ -1,7 +1,7 @@
|
|
|
import { Component } from 'react';
|
|
|
import Taro,{getCurrentPages} from '@tarojs/taro';
|
|
|
-import { connect } from 'react-redux'
|
|
|
-import { View, Image,OpenData } from '@tarojs/components'
|
|
|
+import {connect} from 'react-redux'
|
|
|
+import { View, Image } from '@tarojs/components'
|
|
|
|
|
|
import {set} from '../../actions/counter'
|
|
|
import { login,getUserOrderList } from '../../utils/servers/servers'
|
|
@@ -12,7 +12,7 @@ import './index.less'
|
|
|
import background from "../../assets/images/background.png";
|
|
|
import NavBar from "../../components/NavBar";
|
|
|
|
|
|
-import user from '../../custom-tab-bar/image/user.png';
|
|
|
+import userIcon from '../../custom-tab-bar/image/user.png';
|
|
|
|
|
|
@connect(({ counter }) => ({
|
|
|
counter
|
|
@@ -31,6 +31,7 @@ class Index extends Component {
|
|
|
list: [],
|
|
|
pageNo: 0,
|
|
|
listState: 'LOADING',
|
|
|
+ userInfor:Taro.getStorageSync('userInfor') || ''
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -116,7 +117,7 @@ class Index extends Component {
|
|
|
}else{
|
|
|
Taro.showToast({title:msg.error[0].message,icon:'none'});
|
|
|
this.setState({
|
|
|
- listState: 'RELOAD'
|
|
|
+ listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
|
|
|
})
|
|
|
}
|
|
|
Taro.stopPullDownRefresh();
|
|
@@ -133,34 +134,38 @@ class Index extends Component {
|
|
|
onHome={()=>{}}
|
|
|
/>
|
|
|
<Image src={background} className='background'/>
|
|
|
- <View className='userInfor'>
|
|
|
+ <View className='userInfor' onClick={()=>{
|
|
|
+ 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'});
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }}>
|
|
|
<View className='avatar'>
|
|
|
{
|
|
|
Taro.getStorageSync('token') ?
|
|
|
- <OpenData type='userAvatarUrl'/> :
|
|
|
- <Image className='noLogin' src={user}/>
|
|
|
+ <Image src={this.state.userInfor.avatarUrl} className='login'/> :
|
|
|
+ <Image className='noLogin' src={userIcon}/>
|
|
|
}
|
|
|
|
|
|
</View>
|
|
|
<View className='nickName'>
|
|
|
{
|
|
|
Taro.getStorageSync('token') ?
|
|
|
- <OpenData type='userNickName'/> :
|
|
|
- <View onClick={()=>{
|
|
|
- Taro.getUserProfile({
|
|
|
- desc: '用于用户注册',
|
|
|
- success: async (res)=> {
|
|
|
- let userInfo = res.userInfo
|
|
|
- let nickName = userInfo.nickName
|
|
|
- await this.login(nickName);
|
|
|
- await this.getUserOrderList();
|
|
|
- getCurrentPages()[getCurrentPages().length - 1].onLoad()
|
|
|
- },
|
|
|
- fail: ()=>{
|
|
|
- Taro.showToast({title:'请同意授权获取用户信息',icon:'none'});
|
|
|
- }
|
|
|
- })
|
|
|
- }}>点击登录</View>
|
|
|
+ this.state.userInfor.nickName :
|
|
|
+ '点击登录'
|
|
|
}
|
|
|
</View>
|
|
|
</View>
|