Pārlūkot izejas kodu

Merge branch 'master' of http://git.ycjcjy.com/whole-estate/wxmini

wangfei 6 gadus atpakaļ
vecāks
revīzija
13bbd44daa

+ 49
- 22
config/api.js Parādīt failu

3
 const $api = {
3
 const $api = {
4
   user: {
4
   user: {
5
     login: { // 模拟用户登陆
5
     login: { // 模拟用户登陆
6
-      methods: 'POST',
7
-      url: `${BaseAPIURl}/wx/registered`
6
+      method: 'POST',
7
+      url: `${BaseAPIURl}wx/registered`
8
     },
8
     },
9
     info: {
9
     info: {
10
-      methods: 'GET',
11
-      url: `${BaseAPIURl}/wx/info/:appid`
10
+      method: 'GET',
11
+      url: `${BaseAPIURl}wx/info/:appid`
12
     },
12
     },
13
     getCode: {
13
     getCode: {
14
-      methods: 'GET',
15
-      url: `${BaseAPIURl}/wx/getOpenid`
14
+      method: 'GET',
15
+      url: `${BaseAPIURl}wx/getOpenid`
16
     },
16
     },
17
     update: {
17
     update: {
18
-      methods: 'PUT',
19
-      url: `${BaseAPIURl}/wx/user`
18
+      method: 'PUT',
19
+      url: `${BaseAPIURl}wx/user`
20
     }
20
     }
21
   },
21
   },
22
   dict: {
22
   dict: {
27
   },
27
   },
28
   banner: {
28
   banner: {
29
     list: {
29
     list: {
30
-      methods: 'GET',
31
-      url: `${BaseAPIURl}/wx/banner`
30
+      method: 'GET',
31
+      url: `${BaseAPIURl}wx/banner`
32
     }
32
     }
33
   },
33
   },
34
   building: {
34
   building: {
35
     list: {
35
     list: {
36
-      methods: 'GET',
37
-      url: `${BaseAPIURl}/wx/building/list`
36
+      method: 'GET',
37
+      url: `${BaseAPIURl}wx/building/list`
38
     },
38
     },
39
     detail: {
39
     detail: {
40
       methods: 'GET',
40
       methods: 'GET',
43
   },
43
   },
44
   dynamic: { // 项目
44
   dynamic: { // 项目
45
     list: { // 项目列表
45
     list: { // 项目列表
46
-      methods: 'GET',
47
-      url: `${BaseAPIURl}/wx/buildingDynamiceList`
46
+      method: 'GET',
47
+      url: `${BaseAPIURl}wx/buildingDynamiceList`
48
     },
48
     },
49
     detail: { // 项目详情
49
     detail: { // 项目详情
50
-      methods: 'GET',
51
-      url: `${BaseAPIURl}/wx/buildingDynamiceInfo/:id`
50
+      method: 'GET',
51
+      url: `${BaseAPIURl}wx/buildingDynamiceInfo/:id`
52
     }
52
     }
53
   },
53
   },
54
   activity: {
54
   activity: {
55
     list: { // 活动列表
55
     list: { // 活动列表
56
-      methods: 'GET',
57
-      url: `${BaseAPIURl}/wx/activity`
56
+      method: 'GET',
57
+      url: `${BaseAPIURl}wx/activity`
58
     },
58
     },
59
     detail: { // 活动详情
59
     detail: { // 活动详情
60
-      methods: 'GET',
61
-      url: `${BaseAPIURl}/wx/activity/:id`
60
+      method: 'GET',
61
+      url: `${BaseAPIURl}wx/activity/:id`
62
     }
62
     }
63
   },
63
   },
64
   appointment: {
64
   appointment: {
87
   }
87
   }
88
 }
88
 }
89
 
89
 
90
+const hasKey = (o, k) => Object.keys(o).indexOf(k) > -1
91
+
92
+// 获取 api 支持 a.b.c 字符串格式
93
+function get(k = '') {
94
+  let found = true
95
+  return k.split('.').reduce((acc, key) => {
96
+    if (!found) return acc;
97
+
98
+    if (acc === 0) {
99
+      if (hasKey($api, key)) {
100
+        return $api[key]
101
+      } else {
102
+        found = false
103
+        return {}
104
+      }
105
+    } else {
106
+      if (hasKey(acc, key)) {
107
+        return acc[key]
108
+      } else {
109
+        found = false
110
+        return acc
111
+      }
112
+    }
113
+  }, 0)
114
+}
115
+
90
 module.exports = {
116
 module.exports = {
91
-  $api: $api
92
-}
117
+  $api: $api,
118
+  get: get,
119
+}

+ 1
- 1
config/baseUrl.js Parādīt failu

1
 module.exports.basePath = {
1
 module.exports.basePath = {
2
-  BASE_API_URL: 'https://dev.jinchengjiaye.com/api',
2
+  BASE_API_URL: 'https://dev.jinchengjiaye.com/api/',
3
   BASE_IMG_URL: 'https://whole-estate.oss-cn-beijing.aliyuncs.com/',
3
   BASE_IMG_URL: 'https://whole-estate.oss-cn-beijing.aliyuncs.com/',
4
 }
4
 }

+ 18
- 6
pages/UserCenter/UserInfo/index.js Parādīt failu

1
 import store from '../../../store'
1
 import store from '../../../store'
2
 import create from '../../../utils/create'
2
 import create from '../../../utils/create'
3
+import fetch from '../../../utils/http'
4
+import { get as getApi } from '../../../config/api'
3
 
5
 
4
 const app = getApp()
6
 const app = getApp()
5
 
7
 
6
 create(store, {
8
 create(store, {
7
   data: {
9
   data: {
8
     UserInfo: app.globalData.UserInfo, // 用户信息
10
     UserInfo: app.globalData.UserInfo, // 用户信息
9
-    loadding: false, // 表单验重提交开关
10
   },
11
   },
11
   onReady() {
12
   onReady() {
12
     wx.setNavigationBarTitle({
13
     wx.setNavigationBarTitle({
14
     })
15
     })
15
   },
16
   },
16
   SaveUserInfo() { // 提交表单数据
17
   SaveUserInfo() { // 提交表单数据
17
-    if (!this.data.loadding) {
18
-      this.setData({
19
-        loadding: true
20
-      })
18
+    wx.showLoading({ title: '数据更新, 请稍后...', mask: true })
21
 
19
 
20
+    fetch({ ...getApi('user.update'), data: this.data.UserInfo }).then((data) => {
21
+      // 同步到 globalData
22
+      this.globalData.UserInfo = { ...this.data.UserInfo }
22
 
23
 
23
-    }
24
+      wx.hideLoading()
25
+      wx.showToast({
26
+        title: '更新成功',
27
+        icon: 'success',
28
+      })
29
+    }).catch(() => {
30
+      wx.hideLoading()
31
+      wx.showToast({
32
+        title: '更新失败',
33
+        icon: 'error',
34
+      })
35
+    })
24
   },
36
   },
25
   FormInput(e) { // 表单输入数据绑定
37
   FormInput(e) { // 表单输入数据绑定
26
     const key = e.target.dataset.name
38
     const key = e.target.dataset.name

+ 1
- 1
pages/UserCenter/UserInfo/index.wxml Parādīt failu

29
       </view>
29
       </view>
30
     </view>
30
     </view>
31
   </view>
31
   </view>
32
-  <view class="btn {{ !loadding && 'active' }}" bindtap="SaveUserInfo">
32
+  <view class="btn active" bindtap="SaveUserInfo">
33
     <text>保存</text>
33
     <text>保存</text>
34
   </view>
34
   </view>
35
 </view>
35
 </view>

+ 2
- 1
utils/http.js Parādīt failu

1
-const apiCode = require('../config/code.js').apiCode;
1
+import { apiCode } from '../config/code'
2
 
2
 
3
 export default (config = {}) => {
3
 export default (config = {}) => {
4
   return new Promise((resolve, reject) => {
4
   return new Promise((resolve, reject) => {
7
       method: config.method,
7
       method: config.method,
8
       data: config.data,
8
       data: config.data,
9
       success(res) {
9
       success(res) {
10
+        console.log(res, apiCode)
10
         if (res.statusCode && res.statusCode === apiCode.success) {
11
         if (res.statusCode && res.statusCode === apiCode.success) {
11
           resolve(res.data)
12
           resolve(res.data)
12
         } else {
13
         } else {