HuaJingwen 6 years ago
parent
commit
ec176987a8

+ 17 - 54
app.js

15
   // 在这个app里面this就是app实例
15
   // 在这个app里面this就是app实例
16
   // 监听小程序初始化
16
   // 监听小程序初始化
17
   onLaunch: function (){
17
   onLaunch: function (){
18
-      var system = '', app = this;
18
+      let system = '', app = this;
19
       wx.getSystemInfo({
19
       wx.getSystemInfo({
20
         success: function(res) {
20
         success: function(res) {
21
           system = res.system
21
           system = res.system
35
   // 监听小程序隐藏
35
   // 监听小程序隐藏
36
   onHide: function () {
36
   onHide: function () {
37
   },
37
   },
38
+  onUnload () {
39
+      wx.clearStorage();
40
+  },
38
   // 错误监听函数
41
   // 错误监听函数
39
   onError: function (msg) {
42
   onError: function (msg) {
40
     console.log(msg)
43
     console.log(msg)
47
     wx.login({
50
     wx.login({
48
       success: function(res) {
51
       success: function(res) {
49
         if (res.code) {
52
         if (res.code) {
50
-          wx.getUserInfo({
51
-            success: function(resInfo) {
52
-              // console.log(resInfo);
53
-              wx.request({
53
+            wx.request({
54
                 url: app.globalData.HOST + '/user/wx/login',
54
                 url: app.globalData.HOST + '/user/wx/login',
55
                 method: "POST",
55
                 method: "POST",
56
                 data: {
56
                 data: {
57
                   code: res.code,
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
                   source: source
60
                   source: source
61
                 },
61
                 },
62
                 success: function (resLogin) {
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
         } else {
75
         } else {
113
           console.log('登录失败!' + res.errMsg)
76
           console.log('登录失败!' + res.errMsg)
114
         }
77
         }

+ 2 - 1
app.json

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

+ 1 - 1
pages/feedback/feedback.wxml

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

+ 1 - 2
pages/find/find.js

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

+ 12 - 7
pages/index/index.js

17
   },
17
   },
18
   onLoad: function (options) {
18
   onLoad: function (options) {
19
     var that = this, source = '';
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
     if (options.source) {
26
     if (options.source) {
21
       that.setData({source: options.source})
27
       that.setData({source: options.source})
22
     }
28
     }
23
-    app.login(that);
24
     const dataParam =  Object.assign({}, app.globalData.common, {version: 2, platform: app.globalData.platform});
29
     const dataParam =  Object.assign({}, app.globalData.common, {version: 2, platform: app.globalData.platform});
25
     wx.request({
30
     wx.request({
26
       url: app.globalData.HOST + '/user/product/homeact',
31
       url: app.globalData.HOST + '/user/product/homeact',
72
   },
77
   },
73
   //FormId
78
   //FormId
74
   formSubmit(e) {
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
     this.getFromid(formId,id);
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
   getFromid(formId,ids) {
88
   getFromid(formId,ids) {
81
     wx.request({
89
     wx.request({
83
       method: "POST",
91
       method: "POST",
84
       data: Object.assign({}, app.globalData.common, { from_id: formId }),
92
       data: Object.assign({}, app.globalData.common, { from_id: formId }),
85
       success: function (res) {
93
       success: function (res) {
86
-        wx.navigateTo({
87
-          url: '/pages/details/details?id='+ids
88
-        })
89
       },
94
       },
90
       complete: function () {
95
       complete: function () {
91
       }
96
       }

+ 37 - 0
pages/login/login.js

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

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

+ 24 - 0
pages/login/login.wxml

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

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
 Page({
4
 Page({
5
   data: {
5
   data: {
6
     userInfo: {},
6
     userInfo: {},
7
+    hasUserInfo: false,
8
+    canIUse: wx.canIUse('button.open-type.getUserInfo'),
7
     avatar_url: 'http://m.henhaojie.com/images/KX0004.png',
9
     avatar_url: 'http://m.henhaojie.com/images/KX0004.png',
8
     nick_name: '点击授权登录'
10
     nick_name: '点击授权登录'
9
   },
11
   },
10
   onLoad: function () {
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
   initInfo() {
61
   initInfo() {
14
     var token = wx.getStorageSync('user').token, data = {}, that = this;
62
     var token = wx.getStorageSync('user').token, data = {}, that = this;

+ 2 - 1
pages/mine/mine.wxml

5
     <!-- <view class='title'>{{title}}</view> -->
5
     <!-- <view class='title'>{{title}}</view> -->
6
     <view class='top'></view>
6
     <view class='top'></view>
7
     <view class='ellipse_border'>
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
     </view>
10
     </view>
10
     <text class="user_id">{{nick_name}}</text>
11
     <text class="user_id">{{nick_name}}</text>
11
     <!--内容列表部分-->
12
     <!--内容列表部分-->

+ 8 - 1
pages/mine/mine.wxss

4
   width: 100%;
4
   width: 100%;
5
 }
5
 }
6
 
6
 
7
-.logo_img {
7
+.logo_img, .ellipse_border .userinfo-btn{
8
   width: 60px;
8
   width: 60px;
9
   height: 60px;
9
   height: 60px;
10
   margin: auto;
10
   margin: auto;
14
   border-radius: 50%;
14
   border-radius: 50%;
15
   top: 18px;
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
 .backfff {
25
 .backfff {
19
   background-color: #fff;
26
   background-color: #fff;

+ 3 - 2
pages/template/template.wxml

1
 <template name="jiefItem1">
1
 <template name="jiefItem1">
2
   <view class="weui-cells weui-cells_after-title template">
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
        <!-- <navigator url="/pages/details/details?id={{id}}" id="{{id}}"  hover-class="navigator-hover">  -->
5
        <!-- <navigator url="/pages/details/details?id={{id}}" id="{{id}}"  hover-class="navigator-hover">  -->
5
         <button class='suspendImg'  plain="ture" hover-class="none" data-name="help" formType="submit" style="border:none !important; width:100%;height:100%;" >
6
         <button class='suspendImg'  plain="ture" hover-class="none" data-name="help" formType="submit" style="border:none !important; width:100%;height:100%;" >
6
         <view class="weui-cell borrow-list-temp">
7
         <view class="weui-cell borrow-list-temp">
14
           </view>
15
           </view>
15
         </view>
16
         </view>
16
           <view class="weui-cell__ft weui-cell__ft_in-access"></view>
17
           <view class="weui-cell__ft weui-cell__ft_in-access"></view>
17
-        </button> 
18
+        </button>
18
        <!-- </navigator>  -->
19
        <!-- </navigator>  -->
19
     </form>
20
     </form>
20
   </view>
21
   </view>

+ 8 - 2
project.config.json

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