HuaJingwen 6 年 前
コミット
ec176987a8
共有14 個のファイルを変更した231 個の追加72 個の削除を含む
  1. 17 54
      app.js
  2. 2 1
      app.json
  3. 1 1
      pages/feedback/feedback.wxml
  4. 1 2
      pages/find/find.js
  5. 12 7
      pages/index/index.js
  6. 37 0
      pages/login/login.js
  7. 5 0
      pages/login/login.json
  8. 24 0
      pages/login/login.wxml
  9. 62 0
      pages/login/login.wxss
  10. 49 1
      pages/mine/mine.js
  11. 2 1
      pages/mine/mine.wxml
  12. 8 1
      pages/mine/mine.wxss
  13. 3 2
      pages/template/template.wxml
  14. 8 2
      project.config.json

+ 17 - 54
app.js

@@ -15,7 +15,7 @@ App({
15 15
   // 在这个app里面this就是app实例
16 16
   // 监听小程序初始化
17 17
   onLaunch: function (){
18
-      var system = '', app = this;
18
+      let system = '', app = this;
19 19
       wx.getSystemInfo({
20 20
         success: function(res) {
21 21
           system = res.system
@@ -35,6 +35,9 @@ App({
35 35
   // 监听小程序隐藏
36 36
   onHide: function () {
37 37
   },
38
+  onUnload () {
39
+      wx.clearStorage();
40
+  },
38 41
   // 错误监听函数
39 42
   onError: function (msg) {
40 43
     console.log(msg)
@@ -47,68 +50,28 @@ App({
47 50
     wx.login({
48 51
       success: function(res) {
49 52
         if (res.code) {
50
-          wx.getUserInfo({
51
-            success: function(resInfo) {
52
-              // console.log(resInfo);
53
-              wx.request({
53
+            wx.request({
54 54
                 url: app.globalData.HOST + '/user/wx/login',
55 55
                 method: "POST",
56 56
                 data: {
57 57
                   code: res.code,
58
-                  iv: resInfo.iv,
59
-                  encryptedData: resInfo.encryptedData,
58
+                  iv: app.globalData.userInfo.iv,
59
+                  encryptedData: app.globalData.userInfo.encryptedData,
60 60
                   source: source
61 61
                 },
62 62
                 success: function (resLogin) {
63
-                  if (resLogin.data.errno == 0) {
64
-                    user = resLogin.data.rst;
65
-                    wx.setStorageSync("user", user)
66
-                    app.globalData.common['token'] = user.token
67
-                    if (func) {
68
-                      func();
69
-                    }
70
-                    app.initShare();
71
-                  }
72
-                }
73
-              })
74
-            },
75
-            fail: function () {
76
-              // 用户拒绝授权后再次确认
77
-              app.confirmModal('必须授权登录之后才正常使用,是否重新授权', function(){
78
-                if (wx.openSetting) {
79
-                    wx.openSetting({
80
-                        success: (ress) => {
81
-                            if (ress.authSetting["scope.userInfo"]) {
82
-                              wx.getUserInfo({
83
-                                success: function(resInfo) {
84
-                                  wx.request({
85
-                                    url: app.globalData.HOST + '/user/wx/login',
86
-                                    method: "POST",
87
-                                    data: {
88
-                                      code: res.code,
89
-                                      iv: resInfo.iv,
90
-                                      encryptedData: resInfo.encryptedData
91
-                                    },
92
-                                    success: function (resLogin) {
93
-                                      if (resLogin.data.errno == 0) {
94
-                                        user = resLogin.data.rst;
95
-                                        wx.setStorageSync("user", user)
96
-                                        app.globalData.common['token'] = user.token
97
-                                        if (func) {
98
-                                          func();
99
-                                        }
100
-                                      }
101
-                                    }
102
-                                  })
103
-                                }
104
-                              })
105
-                            }
63
+                    if (resLogin.data.errno == 0) {
64
+                        user = resLogin.data.rst;
65
+                        wx.setStorageSync("user", user)
66
+                        app.globalData.common['token'] = user.token
67
+                        wx.switchTab({'url': '/pages/index/index'})
68
+                        if (func) {
69
+                          func();
106 70
                         }
107
-                    })
71
+                        app.initShare();
72
+                    }
108 73
                 }
109
-              });
110
-            }
111
-          })
74
+            })
112 75
         } else {
113 76
           console.log('登录失败!' + res.errMsg)
114 77
         }

+ 2 - 1
app.json

@@ -9,7 +9,8 @@
9 9
     "pages/application/application",
10 10
     "pages/getPhone/getPhone",
11 11
     "pages/getIt/getIt",
12
-    "pages/signup/signup"
12
+    "pages/signup/signup",
13
+    "pages/login/login"
13 14
   ],
14 15
   "window": {
15 16
     "backgroundTextStyle": "dark",

+ 1 - 1
pages/feedback/feedback.wxml

@@ -1,7 +1,7 @@
1 1
 
2 2
 <view class="section">
3 3
   <form bindsubmit="bindFormSubmit">
4
-    <textarea placeholder="请您留下最宝贵的意见,以便更好的为您服务" name="textarea"  bindinput	="bindTextAreaBlur" value='{{userInput}}'/>
4
+    <textarea placeholder="请您留下最宝贵的意见,以便更好的为您服务" name="textarea"  bindinput="bindTextAreaBlur" value='{{userInput}}'/>
5 5
      <text class='text_number'>还可输入<text>{{int_number}}</text>字</text>
6 6
     <button form-type="submit"> 提交 </button>
7 7
   </form>

+ 1 - 2
pages/find/find.js

@@ -95,7 +95,6 @@ Page({
95 95
     var that = this;
96 96
     utils.initList(that, that.data.obj);
97 97
     that.ajaxFilter();
98
-    app.login(that);
99 98
   },
100 99
   onShow () {
101 100
     wx.stopPullDownRefresh()
@@ -138,7 +137,7 @@ Page({
138 137
   formSubmit(e) {
139 138
     var formId = e.detail.formId;
140 139
     var id = e.target.dataset.id;
141
-    this.getFromid(formId, id); 
140
+    this.getFromid(formId, id);
142 141
     console.log(formId + "formID发现")
143 142
   },
144 143
   getFromid(formId, ids) {

+ 12 - 7
pages/index/index.js

@@ -17,10 +17,15 @@ Page({
17 17
   },
18 18
   onLoad: function (options) {
19 19
     var that = this, source = '';
20
+    const userInfo = wx.getStorageSync('userInfo') || null;
21
+    if (userInfo) {
22
+        app.globalData.userInfo = userInfo;
23
+    }else{
24
+      wx.redirectTo({url: '/pages/login/login'})
25
+    }
20 26
     if (options.source) {
21 27
       that.setData({source: options.source})
22 28
     }
23
-    app.login(that);
24 29
     const dataParam =  Object.assign({}, app.globalData.common, {version: 2, platform: app.globalData.platform});
25 30
     wx.request({
26 31
       url: app.globalData.HOST + '/user/product/homeact',
@@ -72,10 +77,13 @@ Page({
72 77
   },
73 78
   //FormId
74 79
   formSubmit(e) {
75
-    var formId = e.detail.formId;
76
-    var id = e.target.dataset.id;
80
+    const formId = e.detail.formId, id = e.target.dataset.id;
81
+    const userInfo = app.globalData.userInfo;
77 82
     this.getFromid(formId,id);
78
-    console.log(formId + "formID首页")
83
+    wx.navigateTo({
84
+        url: '/pages/details/details?id='+id
85
+    })
86
+    // console.log(formId + "formID首页")
79 87
   },
80 88
   getFromid(formId,ids) {
81 89
     wx.request({
@@ -83,9 +91,6 @@ Page({
83 91
       method: "POST",
84 92
       data: Object.assign({}, app.globalData.common, { from_id: formId }),
85 93
       success: function (res) {
86
-        wx.navigateTo({
87
-          url: '/pages/details/details?id='+ids
88
-        })
89 94
       },
90 95
       complete: function () {
91 96
       }

+ 37 - 0
pages/login/login.js

@@ -0,0 +1,37 @@
1
+const app = getApp()
2
+Page({
3
+  data: {
4
+  },
5
+  onLoad: function () {
6
+      if (app.globalData.userInfo) {
7
+        return;
8
+      } else if (this.data.canIUse){
9
+        // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
10
+        // 所以此处加入 callback 以防止这种情况
11
+        app.userInfoReadyCallback = res => {
12
+          this.setData({
13
+            userInfo: res.userInfo,
14
+            hasUserInfo: true
15
+          })
16
+        }
17
+      } else {
18
+        // 在没有 open-type=getUserInfo 版本的兼容处理
19
+        wx.getUserInfo({
20
+          success: res => {
21
+            wx.setStorageSync('userInfo', res.userInfo);
22
+            app.globalData.userInfo = res.userInfo
23
+          }
24
+        })
25
+      }
26
+  },
27
+  getUserInfo: function(e) {
28
+      const that = this, userInfo = {};
29
+      userInfo.encryptedData = e.detail.encryptedData;
30
+      userInfo.iv = e.detail.iv;
31
+      userInfo.avatar_url = e.detail.userInfo.avatarUrl;
32
+      userInfo.nick_name = e.detail.userInfo.nickName;
33
+      app.globalData.userInfo = userInfo;
34
+      wx.setStorageSync('userInfo', userInfo);
35
+      app.login(that);
36
+  },
37
+})

+ 5 - 0
pages/login/login.json

@@ -0,0 +1,5 @@
1
+{
2
+    "navigationBarBackgroundColor": "#FFCF09",
3
+    "navigationBarTextStyle": "#fff",
4
+    "backgroundColor": "#FFCF09"
5
+}

+ 24 - 0
pages/login/login.wxml

@@ -0,0 +1,24 @@
1
+<view class="login-wrapper">
2
+    <view class="bg-wrapper">
3
+        <view class="title">贷款难?20万等你拿</view>
4
+        <view class="content"></view>
5
+        <view class="flow-wrapper">
6
+          <view class="flow">
7
+            <icon class="icon icon-login"></icon>
8
+            <text>利率低</text>
9
+          </view>
10
+          <view class="flow">
11
+            <icon class="icon icon-login"></icon>
12
+            <text>门槛低无抵押</text>
13
+          </view>
14
+          <view class="flow">
15
+            <icon class="icon icon-login"></icon>
16
+            <text>放款快</text>
17
+          </view>
18
+        </view>
19
+
20
+    </view>
21
+    <view class="btn-wrapper">
22
+        <button class="login-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfo">去拿钱</button>
23
+    </view>
24
+</view>

+ 62 - 0
pages/login/login.wxss

@@ -0,0 +1,62 @@
1
+page{
2
+    width: 100%;
3
+    height: 100%;
4
+}
5
+.login-wrapper{
6
+    width: 100%;
7
+    height: 100%;
8
+    background: #f5f5f5;
9
+}
10
+.login-wrapper .bg-wrapper{
11
+    width: 100%;
12
+    height: calc(100% - 288rpx);
13
+    background: -webkit-linear-gradient(#FFCF09 , #FFC323);
14
+    background: linear-gradient(#FFCF09 , #FFC323);
15
+    overflow: hidden;
16
+}
17
+.login-wrapper .bg-wrapper .title{
18
+    font-size: 28px;
19
+    text-align: center;
20
+    color: #fff;
21
+    margin: 100rpx auto 80rpx;
22
+}
23
+.login-wrapper .bg-wrapper .content{
24
+    width: 696rpx;
25
+    height: 348rpx;
26
+    margin: 0 auto;
27
+    background: url('https://chaoshi.henhaojie.com/icon/bg2.png') no-repeat 0 0;
28
+    -webkit-background-size: 100% 100%;
29
+    background-size: 100% 100%;
30
+}
31
+.flow-wrapper{
32
+    display: flex;
33
+    justify-content: center;
34
+    align-items: center;
35
+    margin-top: 126rpx;
36
+}
37
+.flow{
38
+    flex: 1;
39
+    text-align: center;
40
+    font-size: 10px;
41
+    color: #fff;
42
+}
43
+.flow .icon.icon-login{
44
+    width: 28rpx;
45
+    height: 28rpx;
46
+    background: url('https://chaoshi.henhaojie.com/icon/icon-2.png') no-repeat;
47
+    -webkit-background-size: 100% 100%;
48
+    background-size: 100% 100%;
49
+    margin: -2px 4px 0 0;
50
+}
51
+.btn-wrapper .login-btn{
52
+    width: 560rpx;
53
+    height: 88rpx;
54
+    border-radius: 50rpx;
55
+    background: -webkit-linear-gradient(left, #FFCF09 , #FFC323);
56
+    background: linear-gradient(left, #FFCF09 , #FFC323);
57
+    margin-top: 88rpx;
58
+    color: #fff;
59
+}
60
+.btn-wrapper .login-btn:after{
61
+    border: none;
62
+}

+ 49 - 1
pages/mine/mine.js

@@ -4,11 +4,59 @@ const app = getApp()
4 4
 Page({
5 5
   data: {
6 6
     userInfo: {},
7
+    hasUserInfo: false,
8
+    canIUse: wx.canIUse('button.open-type.getUserInfo'),
7 9
     avatar_url: 'http://m.henhaojie.com/images/KX0004.png',
8 10
     nick_name: '点击授权登录'
9 11
   },
10 12
   onLoad: function () {
11
-    this.initInfo();
13
+      if (app.globalData.userInfo) {
14
+        this.setData({
15
+          userInfo: app.globalData.userInfo,
16
+          hasUserInfo: true,
17
+          avatar_url: app.globalData.userInfo.avatar_url,
18
+          nick_name: app.globalData.userInfo.nick_name
19
+        })
20
+      } else if (this.data.canIUse){
21
+        // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
22
+        // 所以此处加入 callback 以防止这种情况
23
+        app.userInfoReadyCallback = res => {
24
+          this.setData({
25
+            userInfo: res.userInfo,
26
+            hasUserInfo: true
27
+          })
28
+        }
29
+      } else {
30
+        // 在没有 open-type=getUserInfo 版本的兼容处理
31
+        wx.getUserInfo({
32
+          success: res => {
33
+            wx.setStorageSync('userInfo', res.userInfo);
34
+            app.globalData.userInfo = res.userInfo
35
+            this.setData({
36
+              userInfo: res.userInfo,
37
+              hasUserInfo: true
38
+            })
39
+          }
40
+        })
41
+      }
42
+  },
43
+  getUserInfo: function(e) {
44
+      const that = this, userInfo = {};
45
+      console.log();
46
+      userInfo.encryptedData = e.detail.encryptedData;
47
+      userInfo.iv = e.detail.iv;
48
+      // console.log(e.detail.userInfo);
49
+      userInfo.avatar_url = e.detail.userInfo.avatarUrl;
50
+      userInfo.nick_name = e.detail.userInfo.nickName;
51
+      app.globalData.userInfo = userInfo;
52
+      wx.setStorageSync('userInfo', userInfo);
53
+      app.login(that);
54
+      this.setData({
55
+          userInfo: e.detail.userInfo,
56
+          hasUserInfo: true,
57
+          avatar_url: e.detail.userInfo.avatarUrl,
58
+          nick_name: e.detail.userInfo.nickName
59
+      })
12 60
   },
13 61
   initInfo() {
14 62
     var token = wx.getStorageSync('user').token, data = {}, that = this;

+ 2 - 1
pages/mine/mine.wxml

@@ -5,7 +5,8 @@
5 5
     <!-- <view class='title'>{{title}}</view> -->
6 6
     <view class='top'></view>
7 7
     <view class='ellipse_border'>
8
-      <image src="{{avatar_url}}" class="logo_img" bindtap="initInfo"/>
8
+      <button wx:if="{{!hasUserInfo && canIUse}}" class="userinfo-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfo"></button>
9
+      <image wx:else src="{{avatar_url}}" class="logo_img" />
9 10
     </view>
10 11
     <text class="user_id">{{nick_name}}</text>
11 12
     <!--内容列表部分-->

+ 8 - 1
pages/mine/mine.wxss

@@ -4,7 +4,7 @@
4 4
   width: 100%;
5 5
 }
6 6
 
7
-.logo_img {
7
+.logo_img, .ellipse_border .userinfo-btn{
8 8
   width: 60px;
9 9
   height: 60px;
10 10
   margin: auto;
@@ -14,6 +14,13 @@
14 14
   border-radius: 50%;
15 15
   top: 18px;
16 16
 }
17
+.ellipse_border .userinfo-btn{
18
+    padding: 0px;
19
+    box-sizing: content-box;
20
+    background: url('http://m.henhaojie.com/images/KX0004.png') no-repeat;
21
+    -webkit-background-size: 100% 100%;
22
+    background-size: 100% 100%;
23
+}
17 24
 
18 25
 .backfff {
19 26
   background-color: #fff;

+ 3 - 2
pages/template/template.wxml

@@ -1,6 +1,7 @@
1 1
 <template name="jiefItem1">
2 2
   <view class="weui-cells weui-cells_after-title template">
3
-    <form bindsubmit="formSubmit" report-submit="{{true}}" style='width:100%;height:100%;display:block;' data-id="{{id}}">
3
+    <button wx:if="{{!hasUserInfo && canIUse}}" class="userinfo-btn" open-type="getUserInfo" bindgetuserinfo="getUserInfo"></button>
4
+    <form wx:else bindsubmit="formSubmit" report-submit="{{true}}" style='width:100%;height:100%;display:block;' data-id="{{id}}">
4 5
        <!-- <navigator url="/pages/details/details?id={{id}}" id="{{id}}"  hover-class="navigator-hover">  -->
5 6
         <button class='suspendImg'  plain="ture" hover-class="none" data-name="help" formType="submit" style="border:none !important; width:100%;height:100%;" >
6 7
         <view class="weui-cell borrow-list-temp">
@@ -14,7 +15,7 @@
14 15
           </view>
15 16
         </view>
16 17
           <view class="weui-cell__ft weui-cell__ft_in-access"></view>
17
-        </button> 
18
+        </button>
18 19
        <!-- </navigator>  -->
19 20
     </form>
20 21
   </view>

+ 8 - 2
project.config.json

@@ -8,7 +8,7 @@
8 8
 		"newFeature": true
9 9
 	},
10 10
 	"compileType": "miniprogram",
11
-	"libVersion": "1.5.2",
11
+	"libVersion": "1.9.98",
12 12
 	"appid": "wx9950d3ab42ae0af4",
13 13
 	"projectname": "bwspp",
14 14
 	"condition": {
@@ -28,7 +28,7 @@
28 28
 			"list": []
29 29
 		},
30 30
 		"miniprogram": {
31
-			"current": 1,
31
+			"current": -1,
32 32
 			"list": [
33 33
 				{
34 34
 					"id": -1,
@@ -155,6 +155,12 @@
155 155
 					"name": "app",
156 156
 					"pathName": "pages/getPhone/getPhone",
157 157
 					"query": ""
158
+				},
159
+				{
160
+					"id": -1,
161
+					"name": "login",
162
+					"pathName": "pages/login/login",
163
+					"query": ""
158 164
 				}
159 165
 			]
160 166
 		}