许静 5 år sedan
förälder
incheckning
18cce8212b
2 ändrade filer med 156 tillägg och 0 borttagningar
  1. 78
    0
      src/components/auth/index.js
  2. 78
    0
      src/components/auth/index.scss

+ 78
- 0
src/components/auth/index.js Visa fil

@@ -0,0 +1,78 @@
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
+
6
+@connect(state => state.user, { ...actions })
7
+export default class Index extends Component {
8
+  config = {
9
+    navigationBarTitleText: '登录'
10
+  }
11
+  state = {}
12
+
13
+  getUserInfo() {
14
+    const { dispatchUpdateUserInfo } = this.props
15
+    const sessionKey = Taro.getStorageSync('sessionKey')
16
+    // 获取用户信息
17
+    Taro.getUserInfo({
18
+      success: res => {
19
+        const payload = Object.assign(res, { sessionKey })
20
+        // const { userInfo: { nickName, gender, country, city, province } } = payload
21
+        // App.zhuge.identify(nickName, {
22
+        //   '昵称': nickName,
23
+        //   '性别': gender == 1 ? '男' : '女',
24
+        //   '国家': country,
25
+        //   '省份': province,
26
+        //   '城市': city
27
+        // })
28
+
29
+        // 用户信息保存至服务器
30
+        dispatchUpdateUserInfo(payload).then(res => {
31
+          this.toPage(true)
32
+        })
33
+      },
34
+      fail: () => {
35
+        this.toPage(false)
36
+      }
37
+    })
38
+  }
39
+
40
+  toPage(succed) {
41
+    const router = Taro.getStorageSync('router')
42
+    const { query, path } = router
43
+
44
+    if (!succed && path === 'pages/signin/index') {
45
+      return
46
+    }
47
+    if (path === 'pages/project/index' || path === 'pages/shop/index' || path === 'pages/person/index') {
48
+      Taro.switchTab({
49
+        url: '/' + path
50
+      })
51
+      return
52
+    }
53
+    Taro.reLaunch({
54
+      url: `/${path}?${query.params}`
55
+    })
56
+  }
57
+
58
+  render() {
59
+    return (
60
+      <View>
61
+        <View className="userinfo">
62
+          <View className="userinfo-avatar">
63
+            <open-data type="userAvatarUrl"></open-data>
64
+          </View>
65
+          <View className="userinfo-name">
66
+            <open-data type="userNickName"></open-data>
67
+          </View>
68
+        </View>
69
+        <View className='line'></View>
70
+        <View className='content'>
71
+          <View>申请获取以下权限</View>
72
+          <Text>获得你的公开信息(昵称,头像等)</Text>
73
+        </View>
74
+        <Button className='bottom' open-type="getUserInfo" lang="zh_CN" onGetUserInfo={this.getUserInfo}>授权登录</Button>
75
+      </View>
76
+    )
77
+  }
78
+}

+ 78
- 0
src/components/auth/index.scss Visa fil

@@ -0,0 +1,78 @@
1
+@import "@styles/theme.scss";
2
+
3
+.header {
4
+  margin: 90px 0 90px 50px;
5
+  border-bottom: 1px solid #ccc;
6
+  text-align: center;
7
+  width: 650px;
8
+  height: 300px;
9
+  line-height: 450px;
10
+
11
+}
12
+
13
+.content {
14
+  // margin-left: 50px;
15
+  margin: 70px 0 90px 0;
16
+  text-align: center;
17
+
18
+  view {
19
+    font-size: 35px;
20
+    color: $text-color;
21
+  }
22
+
23
+  text {
24
+    display: block;
25
+    color: #9d9d9d;
26
+    margin-top: 30px;
27
+  }
28
+}
29
+
30
+.bottom {
31
+  width: 300px;
32
+  border-radius: 80px;
33
+  margin: 70px 225px;
34
+  font-size: 30px;
35
+  color: white;
36
+  background-color: $primary-color;
37
+}
38
+
39
+.line {
40
+  width: 250px;
41
+  margin: 40px 0 0 250px;
42
+  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
43
+}
44
+
45
+.userinfo {
46
+  position: relative;
47
+  width: 750px;
48
+  // height: 400px;
49
+  color: #fff;
50
+  display: flex;
51
+  flex-direction: column;
52
+  align-items: center;
53
+
54
+  .userinfo-avatar {
55
+    overflow: hidden;
56
+    display: block;
57
+    width: 230px;
58
+    height: 230px;
59
+    margin: 20px;
60
+    margin-top: 50px;
61
+    border-radius: 50%;
62
+    border: 4px solid #fff;
63
+    box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
64
+  }
65
+
66
+  .userinfo-name {
67
+    color: #000;
68
+    text-align: center;
69
+    font-size: 35px;
70
+  }
71
+
72
+  .userinfo text {
73
+    font-size: 14px;
74
+    background-color: #c0c0c0;
75
+    border-radius: 40%;
76
+  }
77
+
78
+}