|
@@ -0,0 +1,117 @@
|
|
1
|
+import Taro, { Component } from '@tarojs/taro'
|
|
2
|
+import { connect } from '@tarojs/redux'
|
|
3
|
+import * as actions from '@actions/user'
|
|
4
|
+import './index.scss'
|
|
5
|
+import getUserPhone from '@utils/getUserPhone'
|
|
6
|
+import { queryUserInfo, doUserSignin } from '@services/user'
|
|
7
|
+
|
|
8
|
+@connect(state => state.user, { ...actions })
|
|
9
|
+export default class Index extends Component {
|
|
10
|
+ config = {
|
|
11
|
+ navigationBarTitleText: '我的'
|
|
12
|
+ }
|
|
13
|
+ state = {
|
|
14
|
+ isLogin: false,
|
|
15
|
+ isPhone: false
|
|
16
|
+ }
|
|
17
|
+ componentWillMount() {
|
|
18
|
+ const { user = {} } = this.props
|
|
19
|
+ // this.toggleGrantAvatar()
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ toggleGrantAvatar = () => {
|
|
23
|
+ const { userInfo: { person: { avatarurl,tel,phone } } } = this.props
|
|
24
|
+
|
|
25
|
+ if (!avatarurl || avatarurl.indexOf('wx.qlogo.cn') === -1) {
|
|
26
|
+ console.log(this.props.userInfo, "this.props")
|
|
27
|
+ this.setState({isLogin:false})
|
|
28
|
+ }
|
|
29
|
+ console.log(avatarurl, "avatarurl")
|
|
30
|
+ this.setState({isLogin:true})
|
|
31
|
+ if(!tel&&!phone){
|
|
32
|
+ this.setState({isPhone:false})
|
|
33
|
+ }
|
|
34
|
+ this.setState({isPhone:true})
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ getUserInfo() {
|
|
38
|
+ const { dispatchUpdateUserInfo } = this.props
|
|
39
|
+ const sessionKey = Taro.getStorageSync('sessionKey')
|
|
40
|
+ Taro.getUserInfo({
|
|
41
|
+ lang: 'zh_CN',
|
|
42
|
+ success: res => {
|
|
43
|
+ console.log(res, "res")
|
|
44
|
+ const payload = Object.assign(res, { sessionKey })
|
|
45
|
+ // const { userInfo: { nickName, gender, country, city, province } } = payload
|
|
46
|
+ // App.zhuge.identify(nickName, {
|
|
47
|
+ // '昵称': nickName,
|
|
48
|
+ // '性别': gender == 1 ? '男' : '女',
|
|
49
|
+ // '国家': country,
|
|
50
|
+ // '省份': province,
|
|
51
|
+ // '城市': city
|
|
52
|
+ // })
|
|
53
|
+ // 用户信息保存至服务器
|
|
54
|
+ dispatchUpdateUserInfo(payload).then(res => {
|
|
55
|
+ console.log('更新信息')
|
|
56
|
+ this.setState({isLogin:true})
|
|
57
|
+ })
|
|
58
|
+ },
|
|
59
|
+ fail: (err) => {
|
|
60
|
+ console.error(err)
|
|
61
|
+
|
|
62
|
+ Taro.showToast({
|
|
63
|
+ title: '获取用户信息失败',
|
|
64
|
+ icon: 'none'
|
|
65
|
+ })
|
|
66
|
+ return
|
|
67
|
+ // this.toPage(false)
|
|
68
|
+ }
|
|
69
|
+ })
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ getPhoneNumber(e) {
|
|
73
|
+ getUserPhone(e, (phoneNumber) => {
|
|
74
|
+ const { dispatchUpdateUserInfoNew } = this.props
|
|
75
|
+ if (!phoneNumber) {
|
|
76
|
+ Taro.showToast({
|
|
77
|
+ title: '获取手机号失败',
|
|
78
|
+ icon: 'none'
|
|
79
|
+ })
|
|
80
|
+ return
|
|
81
|
+ } else {
|
|
82
|
+ dispatchUpdateUserInfoNew(this.state.user.id)
|
|
83
|
+ this.setState({isPhone:true})
|
|
84
|
+ }
|
|
85
|
+ })
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ render() {
|
|
89
|
+ const {user}=this.state
|
|
90
|
+ if (!this.state.isLogin) {
|
|
91
|
+ return (
|
|
92
|
+ <View className="avatar-page">
|
|
93
|
+ <View className="content">
|
|
94
|
+ <View className="title">请允许获取昵称、头像、地区及性别</View>
|
|
95
|
+ <Image className="touxiang" src={require('@assets/default-avatar.png')}></Image>
|
|
96
|
+ <View className="name">用户昵称</View>
|
|
97
|
+ <Button className="btn" open-type="getUserInfo" lang="zh_CN" onGetUserInfo={this.getUserInfo}>好</Button>
|
|
98
|
+ </View>
|
|
99
|
+ </View>
|
|
100
|
+ )
|
|
101
|
+ } else if (!this.state.isPhone) {
|
|
102
|
+ return (
|
|
103
|
+ <View className='auth-page'>
|
|
104
|
+ <Image className="avatar_img" src={user.avatar} />
|
|
105
|
+ <View className="user_name">{user.nickname}</View>
|
|
106
|
+ <Button className='auth-btn' open-type="getPhoneNumber" onGetphonenumber={this.getPhoneNumber}>微信授权一键登录</Button>
|
|
107
|
+ {/* <View className='adver-btn' onClick={this.handleLogin}><Text>我是置业顾问,立即登录~</Text></View> */}
|
|
108
|
+ </View>
|
|
109
|
+ )
|
|
110
|
+ }
|
|
111
|
+ return (
|
|
112
|
+ <View>
|
|
113
|
+ {this.props.children}
|
|
114
|
+ </View>
|
|
115
|
+ )
|
|
116
|
+ }
|
|
117
|
+}
|