瀏覽代碼

Merge branch 'dev' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into dev

xujing 5 年之前
父節點
當前提交
17631272ae
共有 3 個檔案被更改,包括 221 行新增1 行删除
  1. 1
    1
      project.config.json
  2. 117
    0
      src/components/authorizationComponent/index.js
  3. 103
    0
      src/components/authorizationComponent/index.scss

+ 1
- 1
project.config.json 查看文件

@@ -1,7 +1,7 @@
1 1
 {
2 2
 	"miniprogramRoot": "dist/",
3 3
 	"projectname": "mini-chengjiao",
4
-	"description": "知与行联调",
4
+	"description": "知与行互动",
5 5
 	"appid": "wxd9ee3a9480a4e544",
6 6
 	"setting": {
7 7
 		"urlCheck": false,

+ 117
- 0
src/components/authorizationComponent/index.js 查看文件

@@ -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
+}

+ 103
- 0
src/components/authorizationComponent/index.scss 查看文件

@@ -0,0 +1,103 @@
1
+@import "@styles/theme.scss";
2
+
3
+.auth-page{
4
+  position: relative;
5
+  width: 100%;
6
+  height: 100%;
7
+  .avatar_img{
8
+    position: absolute;
9
+    width:120px;
10
+    height:120px;
11
+    left:50%;
12
+    margin-left:-60px;
13
+    top:20%;
14
+    border-radius:20px;
15
+  }
16
+  .user_name{
17
+    position: absolute;
18
+    width:100%;
19
+    left:0;
20
+    text-align:center;
21
+    top:33%;
22
+    font-size:32px;
23
+  }
24
+  .auth-btn{
25
+    position: absolute;
26
+    width: 80%;
27
+    left: 10%;
28
+    height:90px;
29
+    border-radius: 10px;
30
+    top:40%;
31
+    font-size:32px;
32
+    font-weight: 500;
33
+    line-height: 90px;
34
+    color: white;
35
+    background-color: $primary-color;
36
+  }
37
+  .adver-btn{
38
+    position: absolute;
39
+    color: #5B90FF;
40
+    
41
+    width: 100%;
42
+    text-align: center;
43
+    top:52%;
44
+    Text{
45
+      border-bottom: 1px solid #5B90FF;
46
+    }
47
+  }
48
+}
49
+
50
+
51
+.avatar-page{
52
+  position: fixed;
53
+  width: 100vw;
54
+  height: 100vh;
55
+  left: 0;
56
+  top: 0;
57
+  z-index: 9999;
58
+  background: rgba(0, 0, 0, 0.22);
59
+  display: flex;
60
+  flex-direction: column;
61
+  justify-content: center;
62
+  align-items: center;
63
+  
64
+  .content {
65
+    width: 94vw;
66
+    height: 430px;
67
+    position: absolute;
68
+    left: 50%;
69
+    top: 50%;
70
+    margin-left: -47vw;
71
+    transform: translateY(-50%);
72
+    background-color: #fff;
73
+    border-radius: 12px;
74
+    padding: 40px;
75
+    text-align: center;
76
+    .title{
77
+      font-size: 34px;
78
+      color: #333;
79
+    }
80
+    .touxiang{
81
+      width: 110px;
82
+      height: 110px;
83
+      border-radius: 50%;
84
+      margin: 20px 0 10px 0;
85
+    }
86
+    .name{
87
+      font-size: 26px;
88
+      color: #333;
89
+    }
90
+  
91
+  
92
+    .btn{
93
+      width:290px;
94
+      height:90px;
95
+      background:rgba(187,156,121,1);
96
+      border-radius:12px;
97
+      font-size: 34px;
98
+      color: #fff;
99
+      line-height: 90px;
100
+      margin-top: 40px;
101
+    }
102
+  }
103
+}