wangfei 6 years ago
parent
commit
d18bd4e52f

+ 46
- 3
app.js View File

@@ -1,4 +1,6 @@
1 1
 //app.js
2
+import fetch from '/utils/http'
3
+const $api = require('/config/api.js').$api
2 4
 
3 5
 const HttpSever = require('./utils/http.js').HttpSever;
4 6
 const $api = require('./config/api.js').$api;
@@ -6,6 +8,42 @@ const $api = require('./config/api.js').$api;
6 8
 App({
7 9
   onLaunch: function() {
8 10
     let _self = this
11
+    wx.login({
12
+      success(res) {
13
+        if (res.code) {
14
+          // 发起网络请求
15
+          fetch({
16
+            url: $api.user.getCode.url + '?code=' + res.code,
17
+            method: $api.user.getCode.method
18
+          }).then((res) => {
19
+            if (res.code === 200) {
20
+              _self.globalData.UserInfo = res.data
21
+            }
22
+          })
23
+        } else {
24
+          console.log('登录失败!' + res.errMsg)
25
+        }
26
+      }
27
+    })
28
+    wx.getSetting({
29
+      success: res => {
30
+        if (res.authSetting['scope.userInfo']) {
31
+          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
32
+          wx.getUserInfo({
33
+            success: res => {
34
+              // 可以将 res 发送给后台解码出 unionId
35
+              this.globalData.UserInfo = res.userInfo
36
+
37
+              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
38
+              // 所以此处加入 callback 以防止这种情况
39
+              if (this.userInfoReadyCallback) {
40
+                this.userInfoReadyCallback(res)
41
+              }
42
+            }
43
+          })
44
+        }
45
+      }
46
+    })
9 47
     wx.getSystemInfo({
10 48
       success(res) {
11 49
         if (res.model.indexOf('iPhone') !== -1 && res.system.indexOf('iOS') !== -1 && res.screenHeight >= 812) { // iphoneX及以上机型适配
@@ -23,9 +61,14 @@ App({
23 61
   },
24 62
   globalData: {
25 63
     UserInfo: {
26
-      UserIcon: '/assets/images/img4.jpg',
27
-      UserName: '用户名',
28
-      UserPhone: '18267901393'
64
+      customerId: 1,
65
+      customerName: '',
66
+      name: '',
67
+      phone: '',
68
+      idNum: '',
69
+      remark: '',
70
+      openid: '',
71
+      avatar: '',
29 72
     },
30 73
     ScreenBottomHeight: 0,
31 74
     Dict: []

+ 20
- 5
config/api.js View File

@@ -10,6 +10,14 @@ const $api = {
10 10
       methods: 'GET',
11 11
       url: `${BaseAPIURl}/wx/info/:appid`
12 12
     },
13
+    getCode: {
14
+      methods: 'GET',
15
+      url: `${BaseAPIURl}/wx/getOpenid`
16
+    },
17
+    update: {
18
+      methods: 'PUT',
19
+      url: `${BaseAPIURl}/wx/user`
20
+    }
13 21
   },
14 22
   dict: {
15 23
     list: {
@@ -33,19 +41,26 @@ const $api = {
33 41
       url: `${BaseAPIURl}/wx/buildingSelectId/:id`
34 42
     }
35 43
   },
36
-  dynamic: {
37
-    list: {
44
+  dynamic: { // 项目
45
+    list: { // 项目列表
38 46
       methods: 'GET',
39 47
       url: `${BaseAPIURl}/wx/buildingDynamiceList`
40 48
     },
41
-    detail: {
49
+    detail: { // 项目详情
42 50
       methods: 'GET',
43 51
       url: `${BaseAPIURl}/wx/buildingDynamiceInfo/:id`
44 52
     }
45 53
   },
46 54
   activity: {
47
-    
48
-  }
55
+    list: { // 活动列表
56
+      methods: 'GET',
57
+      url: `${BaseAPIURl}/wx/activity`
58
+    },
59
+    detail: { // 活动详情
60
+      methods: 'GET',
61
+      url: `${BaseAPIURl}/wx/activity/:id`
62
+    }
63
+  },
49 64
 }
50 65
 
51 66
 module.exports = {

+ 1
- 4
config/code.js View File

@@ -4,10 +4,7 @@
4 4
  *  user 用户未登录
5 5
  */
6 6
 module.exports.apiCode = {
7
-  common: {
8
-    successCode: 200,
9
-    errorCode: 400
10
-  },
7
+  success: 200,
11 8
   user: {
12 9
     notLogin: 401,
13 10
   }

+ 96
- 38
pages/ActivityDetail/index.js View File

@@ -1,15 +1,31 @@
1 1
 //index.js
2 2
 //获取应用实例
3
+import fetch from '../../utils/http'
4
+
3 5
 const app = getApp()
6
+const $api = require('../../config/api.js').$api
4 7
 
5 8
 Page({
6
-  onShow() {
7
-    wx.setNavigationBarTitle({
8
-      title: '活动详情'
9
+  onShow() {},
10
+  onLoad(e) {
11
+    this.setData({
12
+      Id: e.id,
13
+      Type: e.type - 0
9 14
     })
15
+    if (e.type - 0 === 1) {
16
+      wx.setNavigationBarTitle({
17
+        title: '项目详情'
18
+      })
19
+    } else {
20
+      wx.setNavigationBarTitle({
21
+        title: '活动详情'
22
+      })
23
+    }
10 24
   },
11 25
   data: {
12 26
     UserInfo: app.globalData.UserInfo,
27
+    Id: null,
28
+    Type: null,
13 29
     ShowPopup: false,
14 30
     FormData: {
15 31
       Name: '',
@@ -21,47 +37,54 @@ Page({
21 37
       Title: '示例标题',
22 38
       Publisher: '示例发布人',
23 39
       CreateDate: '2019-02-02',
24
-      Content: '',
25
-      CommentList: [{
26
-        FloorUserIcon: '/assets/images/img1.jpg',
27
-        FloorUserName: '楼主姓名',
28
-        CreateDate: '2019-02-02 22:05',
29
-        Content: '就看到杰卡斯大姐大就看到杰卡斯大姐大就看到杰卡斯大姐大就看到杰卡斯大姐大',
30
-        ImgList: ['/assets/images/img1.jpg', '/assets/images/img2.jpg', '/assets/images/img5.jpg'],
31
-        LikeNum: '0',
32
-        Childs: [{
33
-          Name: '回复人姓名',
34
-          CreateDate: '2019-02-02 22:07',
35
-          Content: 'us很大很大声',
36
-          LikeNum: '15',
37
-          ImgList: ['/assets/images/img1.jpg']
38
-        }, {
39
-          Name: '回复人姓名',
40
-          CreateDate: '2019-02-02 22:07',
41
-          Content: 'us很大很大声',
42
-          LikeNum: '15',
43
-          ImgList: []
44
-        }]
40
+      Content: ''
41
+    },
42
+    CommentList: [{
43
+      FloorUserIcon: '/assets/images/img1.jpg',
44
+      FloorUserName: '楼主姓名',
45
+      CreateDate: '2019-02-02 22:05',
46
+      Content: '就看到杰卡斯大姐大就看到杰卡斯大姐大就看到杰卡斯大姐大就看到杰卡斯大姐大',
47
+      ImgList: ['/assets/images/img1.jpg', '/assets/images/img2.jpg', '/assets/images/img5.jpg'],
48
+      LikeNum: '0',
49
+      Childs: [{
50
+        Name: '回复人姓名',
51
+        CreateDate: '2019-02-02 22:07',
52
+        Content: 'us很大很大声',
53
+        LikeNum: '15',
54
+        ImgList: ['/assets/images/img1.jpg']
45 55
       }, {
46
-        FloorUserIcon: '/assets/images/img1.jpg',
47
-        FloorUserName: '楼主姓名',
48
-        CreateDate: '2019-02-02 22:05',
49
-        Content: '就看到杰卡斯大姐大',
50
-        ImgList: [],
51
-        LikeNum: '0',
52
-        Childs: [{
53
-          Name: '回复人姓名',
54
-          CreateDate: '2019-02-02 22:07',
55
-          Content: 'us很大很大声',
56
-          LikeNum: '15',
57
-          ImgList: []
58
-        }]
56
+        Name: '回复人姓名',
57
+        CreateDate: '2019-02-02 22:07',
58
+        Content: 'us很大很大声',
59
+        LikeNum: '15',
60
+        ImgList: []
61
+      }]
62
+    }, {
63
+      FloorUserIcon: '/assets/images/img1.jpg',
64
+      FloorUserName: '楼主姓名',
65
+      CreateDate: '2019-02-02 22:05',
66
+      Content: '就看到杰卡斯大姐大',
67
+      ImgList: [],
68
+      LikeNum: '0',
69
+      Childs: [{
70
+        Name: '回复人姓名',
71
+        CreateDate: '2019-02-02 22:07',
72
+        Content: 'us很大很大声',
73
+        LikeNum: '15',
74
+        ImgList: []
59 75
       }]
76
+    }]
77
+  },
78
+  onReady() {
79
+    if (this.data.Type === 1) {
80
+      this.GetProjectDetail()
81
+    } else {
82
+      this.GetActivityDetail()
60 83
     }
61 84
   },
62 85
   AddComment() { // 添加评论
63 86
     wx.navigateTo({
64
-      url: '/pages/ActivityDetail/comment?id='
87
+      url: '/pages/ActivityDetail/comment?id=' + this.data.Id
65 88
     })
66 89
   },
67 90
   ShowSignUpPopup() { // 打开报名弹窗
@@ -94,5 +117,40 @@ Page({
94 117
       })
95 118
 
96 119
     }
120
+  },
121
+  GetActivityDetail() { // 获取活动详情
122
+    fetch({
123
+      url: $api.activity.detail.url.replace(':id', this.data.Id),
124
+      method: $api.activity.detail.method
125
+    }).then((res) => {
126
+      if (res.code === 200) {
127
+        console.log(res.data)
128
+        this.setData({
129
+          ActivityDetail: {
130
+            Title: res.data.title,
131
+            Publisher: '江北公司',
132
+            CreateDate: res.data.activityDate,
133
+            Content: res.data.context
134
+          }
135
+        })
136
+      }
137
+    })
138
+  },
139
+  GetProjectDetail() { // 获取项目详情
140
+    fetch({
141
+      url: $api.dynamic.detail.url.replace(':id', this.data.Id),
142
+      method: $api.dynamic.detail.method
143
+    }).then((res) => {
144
+      if (res.code === 200) {
145
+        this.setData({
146
+          ActivityDetail: {
147
+            Title: res.data.title,
148
+            Publisher: '发布人',
149
+            CreateDate: res.data.createDate,
150
+            Content: res.data.url
151
+          }
152
+        })
153
+      }
154
+    })
97 155
   }
98 156
 })

+ 4
- 3
pages/ActivityDetail/index.wxml View File

@@ -1,7 +1,8 @@
1 1
 <!--index.wxml-->
2 2
 <view class="container">
3 3
   <view class="container" style="z-index: 1;">
4
-    <view class="MainPage">
4
+    <web-view wx:if="{{Type === 1}}" src="{{ActivityDetail.Content}}"></web-view>
5
+    <view class="MainPage" wx:if="{{Type === 2}}">
5 6
 
6 7
       <!-- 文章主体 -->
7 8
       <view class="article">
@@ -25,7 +26,7 @@
25 26
 
26 27
         <!-- 评论列表 -->
27 28
         <view class="list">
28
-          <view class="flex-h" wx:for="{{ActivityDetail.CommentList}}" wx:for-item="item" wx:for-index="idx" wx:key="key">
29
+          <view class="flex-h" wx:for="{{CommentList}}" wx:for-item="item" wx:for-index="idx" wx:key="key">
29 30
 
30 31
             <!-- 头像 -->
31 32
             <view class="userIcon">
@@ -89,7 +90,7 @@
89 90
 
90 91
     </view>
91 92
   </view>
92
-  <view class="SignUp">
93
+  <view class="SignUp" hidden="{{Type !== 2}}">
93 94
     <view>
94 95
       <text bindtap="ShowSignUpPopup">我要报名</text>
95 96
     </view>

+ 20
- 69
pages/UserCenter/UserInfo/index.js View File

@@ -1,85 +1,36 @@
1
-//index.js
2
-//获取应用实例
1
+import store from '../../../store'
2
+import create from '../../../utils/create'
3
+
3 4
 const app = getApp()
4 5
 
5
-Page({
6
+create(store, {
7
+  data: {
8
+    UserInfo: app.globalData.UserInfo, // 用户信息
9
+    loadding: false, // 表单验重提交开关
10
+  },
6 11
   onReady() {
7 12
     wx.setNavigationBarTitle({
8 13
       title: '个人资料'
9 14
     })
10 15
   },
11
-  data: {
12
-    UserInfo: app.globalData.UserInfo, // 用户信息
13
-    FormOff: true, // 表单验重提交开关
14
-    FormData: { // 提交数据
15
-      UserIcon: '/assets/images/img1.jpg', // 用户头像
16
-      NickName: '示例昵称', // 昵称
17
-      PhoneNum: '18267901393', // 绑定手机号
18
-      CardNum: '346555212451214544', // 证件号码
19
-      CityId: '1' // 所属城市id
20
-    },
21
-    TriggerSelectCity: false, // 显隐选择城市控件
22
-    CityName: '南京', // 所属城市名称
23
-    CityList: [{
24
-      value: '南京',
25
-      id: '1'
26
-    }, {
27
-      value: '上海',
28
-      id: '2'
29
-    }, {
30
-      value: '苏州',
31
-      id: '3'
32
-    }]
33
-  },
34
-  SaveForm() { // 提交表单数据
35
-    if (this.data.FormOff) {
16
+  SaveUserInfo() { // 提交表单数据
17
+    if (!this.data.loadding) {
36 18
       this.setData({
37
-        FormOff: false
19
+        loadding: true
38 20
       })
21
+
22
+
39 23
     }
40 24
   },
41
-  SelectCityConfirm(e) { // 确认选择城市
42
-    this.setData({
43
-      FormData: {
44
-        ...this.data.FormData,
45
-        CityId: e.detail.value.id
46
-      },
47
-      CityName: e.detail.value.value,
48
-      TriggerSelectCity: false
49
-    })
50
-  },
51
-  SelectCityCancel() { // 取消选择城市
52
-    this.setData({
53
-      TriggerSelectCity: false
54
-    })
55
-  },
56
-  SelectCity() { // 打开城市选择器
57
-    this.setData({
58
-      TriggerSelectCity: true
59
-    })
60
-  },
61 25
   FormInput(e) { // 表单输入数据绑定
26
+    const key = e.target.dataset.name
27
+    const val = e.detail.value
28
+    
62 29
     this.setData({
63
-      FormData: {
64
-        ...this.data.FormData,
65
-        [e.target.dataset.name]: e.detail.value
66
-      }
67
-    })
68
-  },
69
-  UpdateIcon() { // 更换头像
70
-    let _self = this
71
-    wx.chooseImage({
72
-      count: 1,
73
-      sizeType: ['original', 'compressed'],
74
-      sourceType: ['album', 'camera'],
75
-      success(res) {
76
-        _self.setData({
77
-          FormData: {
78
-            ..._self.data.FormData,
79
-            UserIcon: res.tempFilePaths
80
-          }
81
-        })
30
+      UserInfo: {
31
+        ...this.data.UserInfo,
32
+        [`${key}`]: val,
82 33
       }
83 34
     })
84 35
   }
85
-})
36
+})

+ 7
- 18
pages/UserCenter/UserInfo/index.wxml View File

@@ -4,14 +4,14 @@
4 4
     <view class="flex-h" style="padding: 16rpx 50rpx;">
5 5
       <text>头像</text>
6 6
       <view class="flex-item"></view>
7
-      <view class="userIcon" bindtap="UpdateIcon">
8
-        <image mode="aspectFill" src="{{FormData.UserIcon}}" class="centerLabel cover"></image>
7
+      <view class="userIcon">
8
+        <image mode="aspectFill" src="{{UserInfo.avatar}}" class="centerLabel cover"></image>
9 9
       </view>
10 10
     </view>
11 11
     <view class="flex-h">
12 12
       <text>昵称</text>
13 13
       <view class="flex-item">
14
-        <input value="{{FormData.NickName}}" data-name="NickName" bindinput="FormInput"></input>
14
+        <input value="{{UserInfo.name}}" data-name="name" bindinput="FormInput"></input>
15 15
       </view>
16 16
     </view>
17 17
   </view>
@@ -19,28 +19,17 @@
19 19
     <view class="flex-h">
20 20
       <text>绑定手机号</text>
21 21
       <view class="flex-item">
22
-        <input type="number" value="{{FormData.PhoneNum}}" data-name="PhoneNum" bindinput="FormInput"></input>
22
+        <input type="number" value="{{UserInfo.phone}}" data-name="phone" bindinput="FormInput"></input>
23 23
       </view>
24 24
     </view>
25 25
     <view class="flex-h">
26 26
       <text>证件号码</text>
27 27
       <view class="flex-item">
28
-        <input type="idcard" value="{{FormData.CardNum}}" data-name="CardNum" bindinput="FormInput"></input>
28
+        <input type="idcard" value="{{UserInfo.idNum}}" data-name="idNum" bindinput="FormInput"></input>
29 29
       </view>
30 30
     </view>
31
-    <view class="flex-h" bindtap="SelectCity">
32
-      <text>城市</text>
33
-      <view class="flex-item"></view>
34
-      <text>{{CityName}}</text>
35
-      <image mode="widthFix" src="/assets/images/icon11.png" style="width: 16rpx;"></image>
36
-    </view>
37 31
   </view>
38
-  <view class="btn" bindtap="SaveUserInfo">
39
-    <text bindtap="SaveForm">保存</text>
40
-  </view>
41
-  <view class="popup" hidden="{{!TriggerSelectCity}}">
42
-    <view>
43
-      <van-picker show-toolbar columns="{{ CityList }}" value-key="value" bind:cancel="SelectCityCancel" bind:confirm="SelectCityConfirm" />
44
-    </view>
32
+  <view class="btn {{ !loadding && 'active' }}" bindtap="SaveUserInfo">
33
+    <text>保存</text>
45 34
   </view>
46 35
 </view>

+ 5
- 1
pages/UserCenter/UserInfo/index.wxss View File

@@ -68,10 +68,14 @@
68 68
   color: #fff;
69 69
   line-height: 88rpx;
70 70
   font-size: 28rpx;
71
-  background: #bb9c79;
71
+  background-color: #ccc;
72 72
   border-radius: 10rpx;
73 73
 }
74 74
 
75
+.btn.active text {
76
+  background: #bb9c79;
77
+}
78
+
75 79
 .popup {
76 80
   width: 100%;
77 81
   position: absolute;

+ 75
- 77
pages/components/Concessions/index.js View File

@@ -1,6 +1,8 @@
1 1
 //index.js
2
+import fetch from '../../../utils/http'
2 3
 //获取应用实例
3 4
 const app = getApp()
5
+const $api = require('../../../config/api.js').$api
4 6
 
5 7
 Component({
6 8
   behaviors: [],
@@ -15,87 +17,80 @@ Component({
15 17
       id: ''
16 18
     }],
17 19
     NavActiveIndex: 0,
18
-    ListA: [{
19
-      Title: '示例数据A',
20
-      CreateDate: '09-02-12',
21
-      Org: '悦见山',
22
-      Img: '/assets/images/img1.jpg',
23
-      Id: ''
24
-    }, {
25
-      Title: '示例数据A',
26
-      CreateDate: '09-02-12',
27
-      Org: '悦见山',
28
-      Img: '/assets/images/img1.jpg',
29
-      Id: ''
30
-    }, {
31
-      Title: '示例数据A',
32
-      CreateDate: '09-02-12',
33
-      Org: '悦见山',
34
-      Img: '/assets/images/img1.jpg',
35
-      Id: ''
36
-    }, {
37
-      Title: '示例数据A',
38
-      CreateDate: '09-02-12',
39
-      Org: '悦见山',
40
-      Img: '/assets/images/img1.jpg',
41
-      Id: ''
42
-    }, {
43
-      Title: '示例数据A',
44
-      CreateDate: '09-02-12',
45
-      Org: '悦见山',
46
-      Img: '/assets/images/img1.jpg',
47
-      Id: ''
48
-    }, {
49
-      Title: '示例数据A',
50
-      CreateDate: '09-02-12',
51
-      Org: '悦见山',
52
-      Img: '/assets/images/img1.jpg',
53
-      Id: ''
54
-    }],
55
-    ListB: [{
56
-      Title: '示例数据B',
57
-      CreateDate: '09-02-12',
58
-      Org: '悦见山',
59
-      Img: '/assets/images/img1.jpg',
60
-      Id: ''
61
-    }, {
62
-      Title: '示例数据B',
63
-      CreateDate: '09-02-12',
64
-      Org: '悦见山',
65
-      Img: '/assets/images/img1.jpg',
66
-      Id: ''
67
-    }, {
68
-      Title: '示例数据B',
69
-      CreateDate: '09-02-12',
70
-      Org: '悦见山',
71
-      Img: '/assets/images/img1.jpg',
72
-      Id: ''
73
-    }, {
74
-      Title: '示例数据B',
75
-      CreateDate: '09-02-12',
76
-      Org: '悦见山',
77
-      Img: '/assets/images/img1.jpg',
78
-      Id: ''
79
-    }, {
80
-      Title: '示例数据B',
81
-      CreateDate: '09-02-12',
82
-      Org: '悦见山',
83
-      Img: '/assets/images/img1.jpg',
84
-      Id: ''
85
-    }, {
86
-      Title: '示例数据B',
87
-      CreateDate: '09-02-12',
88
-      Org: '悦见山',
89
-      Img: '/assets/images/img1.jpg',
90
-      Id: ''
91
-    }]
20
+    ListA: [],
21
+    ListB: [],
22
+    PostDataA: {
23
+      PageNum: 1,
24
+      PageSize: 15
25
+    },
26
+    PostDataB: {
27
+      PageNum: 1,
28
+      PageSize: 15
29
+    }
92 30
   },
93 31
   lifetimes: {},
94
-  ready: function() {},
32
+  ready: function() {
33
+    this.GetProjectList()
34
+    this.GetActivityList()
35
+  },
95 36
   pageLifetimes: {
96 37
     show: function() {},
97 38
   },
98 39
   methods: {
40
+    GetActivityList() { // 获取活动列表
41
+      fetch({
42
+        url: $api.activity.list.url + '?pageNum=' + this.data.PostDataB.PageNum + '&pageSize=' + this.data.PostDataB.PageSize,
43
+        method: $api.activity.list.method
44
+      }).then((res) => {
45
+        if (res.code === 200) {
46
+          let arr = res.data.records || []
47
+          let pArr = this.data.ListB
48
+          arr.map((item) => {
49
+            pArr.push({
50
+              Title: item.title,
51
+              CreateDate: item.activityDate,
52
+              Org: item.buildingName,
53
+              Img: item.imgUrl,
54
+              Id: item.activityId
55
+            })
56
+          })
57
+          this.setData({
58
+            ListB: pArr,
59
+            PostDataB: {
60
+              PageNum: res.data.total === this.data.ListB.length ? this.data.PostDataB.PageNum : this.data.PostDataB.PageNum + 1,
61
+              PageSize: this.data.PostDataB.PageSize
62
+            }
63
+          })
64
+        }
65
+      })
66
+    },
67
+    GetProjectList() { // 获取项目动态列表
68
+      fetch({
69
+        url: $api.dynamic.list.url + '?pageNum=' + this.data.PostDataA.PageNum + '&pageSize=' + this.data.PostDataA.PageSize,
70
+        method: $api.dynamic.list.method
71
+      }).then((res) => {
72
+        if (res.code === 200) {
73
+          let arr = res.data.records || []
74
+          let pArr = this.data.ListA
75
+          arr.map((item) => {
76
+            pArr.push({
77
+              Title: item.title,
78
+              CreateDate: item.createDate,
79
+              Org: item.buildingName,
80
+              Img: item.imgUrl,
81
+              Id: item.dynamicId
82
+            })
83
+          })
84
+          this.setData({
85
+            ListA: pArr,
86
+            PostDataA: {
87
+              PageNum: res.data.total === this.data.ListA.length ? this.data.PostDataA.PageNum : this.data.PostDataA.PageNum + 1,
88
+              PageSize: this.data.PostDataA.PageSize
89
+            }
90
+          })
91
+        }
92
+      })
93
+    },
99 94
     CutNav(e) { // 切换nav
100 95
       if (e.target.dataset.index !== undefined) {
101 96
         this.setData({
@@ -103,8 +98,11 @@ Component({
103 98
         })
104 99
       }
105 100
     },
106
-    ItemClick() {
107
-      console.log(111)
101
+    ItemTap(e) {
102
+      // console.log(e.target.dataset)
103
+      wx.navigateTo({
104
+        url: '/pages/ActivityDetail/index?type=' + e.target.dataset.type + '&id=' + e.target.dataset.id
105
+      })
108 106
     }
109 107
   }
110 108
 })

+ 2
- 2
pages/components/Concessions/index.wxml View File

@@ -7,10 +7,10 @@
7 7
   </view>
8 8
   <view class="content">
9 9
     <view hidden="{{NavActiveIndex !== 0}}">
10
-      <ConcessionsListItem wx:for="{{ListA}}" wx:for-item="item" wx:for-index="index" wx:key="key" Params="{{item}}" />
10
+      <ConcessionsListItem wx:for="{{ListA}}" wx:for-item="item" wx:for-index="index" wx:key="key" Params="{{item}}" data-id="{{item.Id}}" data-type="1" bindtap="ItemTap" />
11 11
     </view>
12 12
     <view hidden="{{NavActiveIndex !== 1}}">
13
-      <ConcessionsListItem wx:for="{{ListB}}" wx:for-item="item" wx:for-index="index" wx:key="key" Params="{{item}}" />
13
+      <ConcessionsListItem wx:for="{{ListB}}" wx:for-item="item" wx:for-index="index" wx:key="key" Params="{{item}}" data-id="{{item.Id}}" data-type="2" bindtap="ItemTap" />
14 14
     </view>
15 15
   </view>
16 16
 </view>

+ 3
- 3
pages/components/ConcessionsListItem/index.js View File

@@ -14,9 +14,9 @@ Component({
14 14
   },
15 15
   methods: {
16 16
     TapItem() {
17
-      wx.navigateTo({
18
-        url: '/pages/ActivityDetail/index'
19
-      })
17
+      // wx.navigateTo({
18
+      //   url: '/pages/ActivityDetail/index'
19
+      // })
20 20
     }
21 21
   }
22 22
 })

+ 8
- 1
pages/components/Estate/index.js View File

@@ -1,7 +1,9 @@
1 1
 //index.js
2
+import fetch from '../../../utils/http'
3
+
2 4
 //获取应用实例
3 5
 const app = getApp()
4
-const HttpSever = require('../../../utils/http.js').HttpSever;
6
+
5 7
 const $api = require('../../../config/api.js').$api;
6 8
 
7 9
 Component({
@@ -58,7 +60,12 @@ Component({
58 60
       wx.getLocation({
59 61
         type: 'wgs84',
60 62
         success(res) {
63
+<<<<<<< HEAD
61 64
           HttpSever.Ajax({
65
+=======
66
+          console.log(res)
67
+          fetch({
68
+>>>>>>> 02bbb13da6392818f573d7fc66c72524bffeb347
62 69
             url: $api.building.list.url,
63 70
             method: $api.building.list.method,
64 71
           }).then((data) => {

+ 2
- 0
project.config.json View File

@@ -19,6 +19,8 @@
19 19
 		"hidedInDevtools": []
20 20
 	},
21 21
 	"isGameTourist": false,
22
+	"simulatorType": "wechat",
23
+	"simulatorPluginLibVersion": {},
22 24
 	"condition": {
23 25
 		"search": {
24 26
 			"current": -1,

+ 6
- 0
store.js View File

@@ -0,0 +1,6 @@
1
+// 本文件不要删除
2
+
3
+export default {
4
+  data: {},
5
+  globalData: {},
6
+}

+ 449
- 0
utils/create.js View File

@@ -0,0 +1,449 @@
1
+import diff from './diff'
2
+
3
+let originData = null
4
+let globalStore = null
5
+let fnMapping = {}
6
+
7
+const ARRAYTYPE = '[object Array]'
8
+const OBJECTTYPE = '[object Object]'
9
+const FUNCTIONTYPE = '[object Function]'
10
+
11
+export default function create(store, option) {
12
+    let updatePath = null
13
+    if (arguments.length === 2) {   
14
+        if (!originData) {
15
+            originData = JSON.parse(JSON.stringify(store.data))
16
+            globalStore = store
17
+            store.instances = {}
18
+            store.update = update
19
+            store.push = push
20
+            store.pull = pull
21
+            store.add = add
22
+            store.remove = remove
23
+            store.originData = originData
24
+            store.env && initCloud(store.env)
25
+            extendStoreMethod(store)
26
+        }
27
+        getApp().globalData && (getApp().globalData.store = store)
28
+        //option.data = store.data
29
+        const onLoad = option.onLoad
30
+        walk(store.data)
31
+        // 解决函数属性初始化不能显示的问题,要求必须在data中声明使用
32
+        // 这段代码是同步store.data到option.data,只有经过walk方法后store.data中的函数才能变成属性,才能被小程序page方法渲染
33
+        if (option.data && Object.keys(option.data).length > 0) {
34
+            updatePath = getUpdatePath(option.data)
35
+            syncValues(store.data, option.data)
36
+        }
37
+        option.onLoad = function (e) {
38
+            this.store = store
39
+            this._updatePath = updatePath
40
+            rewriteUpdate(this)
41
+            store.instances[this.route] = []
42
+            store.instances[this.route].push(this)
43
+            onLoad && onLoad.call(this, e)
44
+            syncValues(store.data, this.data)
45
+            this.setData(this.data)
46
+        }
47
+	
48
+	// 解决执行navigateBack或reLaunch时清除store.instances对应页面的实例
49
+	const onUnload = option.onUnload
50
+        option.onUnload = function () {
51
+            onUnload && onUnload.call(this)
52
+            store.instances[this.route] = []
53
+        }
54
+
55
+        Page(option)
56
+    } else {
57
+        const ready = store.ready
58
+        const pure = store.pure
59
+        const componentUpdatePath = getUpdatePath(store.data)
60
+        store.ready = function () {
61
+            if (pure) {
62
+                this.store = { data: store.data || {} }
63
+                this.store.originData = store.data ? JSON.parse(JSON.stringify(store.data)) : {}
64
+                walk(store.data || {})
65
+                rewritePureUpdate(this)
66
+            } else {
67
+                this.page = getCurrentPages()[getCurrentPages().length - 1]
68
+                this.store = this.page.store
69
+                this._updatePath = componentUpdatePath
70
+                syncValues(this.store.data, store.data)
71
+                walk(store.data || {})
72
+                this.setData.call(this, this.store.data)
73
+                rewriteUpdate(this)
74
+                this.store.instances[this.page.route].push(this)
75
+            }
76
+            ready && ready.call(this)
77
+        }
78
+        Component(store)
79
+    }
80
+}
81
+
82
+function syncValues(from, to){
83
+    Object.keys(to).forEach(key=>{
84
+        if(from.hasOwnProperty(key)){
85
+            to[key] = from[key]
86
+        }
87
+    })
88
+}
89
+
90
+
91
+function getUpdatePath(data) {
92
+	const result = {}
93
+    dataToPath(data, result)
94
+	return result
95
+}
96
+
97
+function dataToPath(data, result) {
98
+	Object.keys(data).forEach(key => {
99
+		result[key] = true
100
+		const type = Object.prototype.toString.call(data[key])
101
+		if (type === OBJECTTYPE) {
102
+			_objToPath(data[key], key, result)
103
+		} else if (type === ARRAYTYPE) {
104
+			_arrayToPath(data[key], key, result)
105
+		}
106
+	})
107
+}
108
+
109
+function _objToPath(data, path, result) {
110
+	Object.keys(data).forEach(key => {
111
+		result[path + '.' + key] = true
112
+		delete result[path]
113
+		const type = Object.prototype.toString.call(data[key])
114
+		if (type === OBJECTTYPE) {
115
+			_objToPath(data[key], path + '.' + key, result)
116
+		} else if (type === ARRAYTYPE) {
117
+			_arrayToPath(data[key], path + '.' + key, result)
118
+		}
119
+	})
120
+}
121
+
122
+function _arrayToPath(data, path, result) {
123
+	data.forEach((item, index) => {
124
+		result[path + '[' + index + ']'] = true
125
+		delete result[path]
126
+		const type = Object.prototype.toString.call(item)
127
+		if (type === OBJECTTYPE) {
128
+			_objToPath(item, path + '[' + index + ']', result)
129
+		} else if (type === ARRAYTYPE) {
130
+			_arrayToPath(item, path + '[' + index + ']', result)
131
+		}
132
+	})
133
+}
134
+
135
+function rewritePureUpdate(ctx) {
136
+    ctx.update = function (patch) {
137
+        const store = this.store
138
+        const that = this
139
+        return new Promise(resolve => {
140
+            //defineFnProp(store.data)
141
+            if (patch) {
142
+                for (let key in patch) {
143
+                    updateByPath(store.data, key, patch[key])
144
+                }
145
+            }
146
+            let diffResult = diff(store.data, store.originData)
147
+            let array = []
148
+            if (Object.keys(diffResult)[0] == '') {
149
+                diffResult = diffResult['']
150
+            }
151
+            if (Object.keys(diffResult).length > 0) {
152
+                array.push( new Promise( cb => that.setData(diffResult, cb) ) )
153
+                store.onChange && store.onChange(diffResult)
154
+                for (let key in diffResult) {
155
+                    updateByPath(store.originData, key, typeof diffResult[key] === 'object' ? JSON.parse(JSON.stringify(diffResult[key])) : diffResult[key])
156
+                }
157
+            }
158
+            Promise.all(array).then( e => resolve(diffResult) )
159
+        })
160
+    }
161
+}
162
+
163
+function initCloud(env) {
164
+    wx.cloud.init()
165
+    globalStore.db = wx.cloud.database({
166
+        env: env
167
+    })
168
+}
169
+
170
+function push(patch) {
171
+    return new Promise(function (resolve, reject) {
172
+        _push(update(patch), resolve, reject)
173
+    })
174
+}
175
+
176
+function _push(diffResult, resolve) {
177
+    const objs = diffToPushObj(diffResult)
178
+    Object.keys(objs).forEach((path) => {
179
+        const arr = path.split('-')
180
+        const id = globalStore.data[arr[0]][parseInt(arr[1])]._id
181
+        const obj = objs[path]
182
+        if (globalStore.methods && globalStore.methods[arr[0]]) {
183
+            Object.keys(globalStore.methods[arr[0]]).forEach(key => {
184
+                if (obj.hasOwnProperty(key)) {
185
+                    delete obj[key]
186
+                }
187
+            })
188
+        }
189
+        globalStore.db.collection(arr[0]).doc(id).update({
190
+            data: obj
191
+        }).then((res) => {
192
+            resolve(res)
193
+        })
194
+    })
195
+}
196
+
197
+function update(patch) {
198
+    return new Promise(resolve => {
199
+        //defineFnProp(globalStore.data)
200
+        if (patch) {
201
+            for (let key in patch) {
202
+                updateByPath(globalStore.data, key, patch[key])
203
+            }
204
+        }
205
+        let diffResult = diff(globalStore.data, originData)
206
+        if (Object.keys(diffResult)[0] == '') {
207
+            diffResult = diffResult['']
208
+        }
209
+        const updateAll = matchGlobalData(diffResult)
210
+        let array = []
211
+        if (Object.keys(diffResult).length > 0) {
212
+            for (let key in globalStore.instances) {
213
+                globalStore.instances[key].forEach(ins => {
214
+                    if(updateAll || globalStore.updateAll || ins._updatePath){
215
+                        // 获取需要更新的字段
216
+                        const needUpdatePathList = getNeedUpdatePathList(diffResult, ins._updatePath)
217
+                        if (needUpdatePathList.length) {
218
+                            const _diffResult = {}
219
+                            for (let _path in diffResult) {
220
+                                if (needUpdatePathList.includes(_path)) {
221
+                                    _diffResult[_path] = diffResult[_path]
222
+                                }
223
+                            }
224
+                            array.push( new Promise(cb => {
225
+                                ins.setData.call(ins, _diffResult, cb)
226
+                            }) )
227
+                        }
228
+                    }
229
+                })
230
+            }
231
+            globalStore.onChange && globalStore.onChange(diffResult)
232
+            for (let key in diffResult) {
233
+                updateByPath(originData, key, typeof diffResult[key] === 'object' ? JSON.parse(JSON.stringify(diffResult[key])) : diffResult[key])
234
+            }
235
+        }
236
+        Promise.all(array).then(e=>{
237
+            resolve(diffResult)
238
+        })
239
+    })
240
+}
241
+
242
+function matchGlobalData(diffResult) {
243
+    if(!globalStore.globalData) return false
244
+    for (let keyA in diffResult) {
245
+        if (globalStore.globalData.indexOf(keyA) > -1) {
246
+            return true
247
+        }
248
+        for (let i = 0, len = globalStore.globalData.length; i < len; i++) {
249
+            if (includePath(keyA, globalStore.globalData[i])) {
250
+                return true
251
+            }
252
+        }
253
+    }
254
+    return false
255
+}
256
+
257
+function getNeedUpdatePathList(diffResult, updatePath){
258
+    const paths = []
259
+    for(let keyA in diffResult){
260
+        if(updatePath[keyA]){
261
+            paths.push(keyA)
262
+        }
263
+        for(let keyB in updatePath){
264
+            if(includePath(keyA, keyB)){
265
+                paths.push(keyA)
266
+            }
267
+        }
268
+    }
269
+    return paths
270
+}
271
+
272
+function includePath(pathA, pathB){
273
+    if(pathA.indexOf(pathB)===0){
274
+        const next = pathA.substr(pathB.length, 1)
275
+        if(next === '['||next === '.'){
276
+            return true
277
+        }
278
+    }
279
+    return false
280
+}
281
+
282
+function rewriteUpdate(ctx) {
283
+    ctx.update = update
284
+}
285
+
286
+function updateByPath(origin, path, value) {
287
+    const arr = path.replace(/]/g, '').replace(/\[/g, '.').split('.')
288
+    let current = origin
289
+    for (let i = 0, len = arr.length; i < len; i++) {
290
+        if (i === len - 1) {
291
+            current[arr[i]] = value
292
+        } else {
293
+            current = current[arr[i]]
294
+        }
295
+    }
296
+}
297
+
298
+function pull(cn, where) {
299
+    return new Promise(function (resolve) {
300
+        globalStore.db.collection(cn).where(where || {}).get().then(res => {
301
+            extend(res, cn)
302
+            resolve(res)
303
+        })
304
+    })
305
+}
306
+
307
+function extend(res, cn) {
308
+    res.data.forEach(item => {
309
+        const mds = globalStore.methods[cn]
310
+        mds && Object.keys(mds).forEach(key => {
311
+            Object.defineProperty(item, key, {
312
+                enumerable: true,
313
+                get: () => {
314
+                    return mds[key].call(item)
315
+                },
316
+                set: () => {
317
+                    //方法不能改写
318
+                }
319
+            })
320
+        })
321
+    })
322
+}
323
+
324
+function add(cn, data) {
325
+    return globalStore.db.collection(cn).add({ data })
326
+}
327
+
328
+function remove(cn, id) {
329
+    return globalStore.db.collection(cn).doc(id).remove()
330
+}
331
+
332
+function diffToPushObj(diffResult) {
333
+    const result = {}
334
+    Object.keys(diffResult).forEach(key => {
335
+        diffItemToObj(key, diffResult[key], result)
336
+    })
337
+    return result
338
+}
339
+
340
+function diffItemToObj(path, value, result) {
341
+    const arr = path.replace(/]/g, '').replace(/\[/g, '.').split('.')
342
+    const obj = {}
343
+    let current = null
344
+    const len = arr.length
345
+    for (let i = 2; i < len; i++) {
346
+        if (len === 3) {
347
+            obj[arr[i]] = value
348
+        } else {
349
+            if (i === len - 1) {
350
+                current[arr[i]] = value
351
+            } else {
352
+                const pre = current
353
+                current = {}
354
+                if (i === 2) {
355
+                    obj[arr[i]] = current
356
+                } else {
357
+                    pre[arr[i]] = current
358
+                }
359
+            }
360
+        }
361
+    }
362
+    const key = arr[0] + '-' + arr[1]
363
+    result[key] = Object.assign(result[key] || {}, obj)
364
+}
365
+
366
+function extendStoreMethod() {
367
+    globalStore.method = function (path, fn) {
368
+        fnMapping[path] = fn
369
+        let ok = getObjByPath(path)
370
+        Object.defineProperty(ok.obj, ok.key, {
371
+            enumerable: true,
372
+            get: () => {
373
+                return fnMapping[path].call(globalStore.data)
374
+            },
375
+            set: () => {
376
+                console.warn('Please using store.method to set method prop of data!')
377
+            }
378
+        })
379
+    }
380
+}
381
+
382
+function getObjByPath(path) {
383
+    const arr = path.replace(/]/g, '').replace(/\[/g, '.').split('.')
384
+    const len = arr.length
385
+    if (len > 1) {
386
+        let current = globalStore.data[arr[0]]
387
+        for (let i = 1; i < len - 1; i++) {
388
+            current = current[arr[i]]
389
+        }
390
+        return { obj: current, key: arr[len - 1] }
391
+    } else {
392
+        return { obj: globalStore.data, key: arr[0] }
393
+    }
394
+}
395
+
396
+function walk(data) {
397
+    Object.keys(data).forEach(key => {
398
+        const obj = data[key]
399
+        const tp = type(obj)
400
+        if (tp == FUNCTIONTYPE) {
401
+            setProp(key, obj)
402
+        } else if (tp == OBJECTTYPE) {
403
+            Object.keys(obj).forEach(subKey => {
404
+                _walk(obj[subKey], key + '.' + subKey)
405
+            })
406
+
407
+        } else if (tp == ARRAYTYPE) {
408
+            obj.forEach((item, index) => {
409
+                _walk(item, key + '[' + index + ']')
410
+            })
411
+
412
+        }
413
+    })
414
+}
415
+
416
+function _walk(obj, path) {
417
+    const tp = type(obj)
418
+    if (tp == FUNCTIONTYPE) {
419
+        setProp(path, obj)
420
+    } else if (tp == OBJECTTYPE) {
421
+        Object.keys(obj).forEach(subKey => {
422
+            _walk(obj[subKey], path + '.' + subKey)
423
+        })
424
+
425
+    } else if (tp == ARRAYTYPE) {
426
+        obj.forEach((item, index) => {
427
+            _walk(item, path + '[' + index + ']')
428
+        })
429
+
430
+    }
431
+}
432
+
433
+function setProp(path, fn) {
434
+    const ok = getObjByPath(path)
435
+    fnMapping[path] = fn
436
+    Object.defineProperty(ok.obj, ok.key, {
437
+        enumerable: true,
438
+        get: () => {
439
+            return fnMapping[path].call(globalStore.data)
440
+        },
441
+        set: () => {
442
+            console.warn('Please using store.method to set method prop of data!')
443
+        }
444
+    })
445
+}
446
+
447
+function type(obj) {
448
+    return Object.prototype.toString.call(obj)
449
+}

+ 106
- 0
utils/diff.js View File

@@ -0,0 +1,106 @@
1
+const ARRAYTYPE = '[object Array]'
2
+const OBJECTTYPE = '[object Object]'
3
+const FUNCTIONTYPE = '[object Function]'
4
+
5
+export default function diff(current, pre) {
6
+    const result = {}
7
+    syncKeys(current, pre)
8
+    _diff(current, pre, '', result)
9
+    return result
10
+}
11
+
12
+function syncKeys(current, pre) {
13
+    if (current === pre) return
14
+    const rootCurrentType = type(current)
15
+    const rootPreType = type(pre)
16
+    if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
17
+        if(Object.keys(current).length >= Object.keys(pre).length){
18
+            for (let key in pre) {
19
+                const currentValue = current[key]
20
+                if (currentValue === undefined) {
21
+                    current[key] = null
22
+                } else {
23
+                    syncKeys(currentValue, pre[key])
24
+                }
25
+            }
26
+        }
27
+    } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
28
+        if (current.length >= pre.length) {
29
+            pre.forEach((item, index) => {
30
+                syncKeys(current[index], item)
31
+            })
32
+        }
33
+    }
34
+}
35
+
36
+function _diff(current, pre, path, result) {
37
+    if (current === pre) return
38
+    const rootCurrentType = type(current)
39
+    const rootPreType = type(pre)
40
+    if (rootCurrentType == OBJECTTYPE) {
41
+        if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length && path !== '') {
42
+            setResult(result, path, current)
43
+        } else {
44
+            for (let key in current) {
45
+                const currentValue = current[key]
46
+                const preValue = pre[key]
47
+                const currentType = type(currentValue)
48
+                const preType = type(preValue)
49
+                if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
50
+                    if (currentValue != pre[key]) {
51
+                        setResult(result, (path == '' ? '' : path + ".") + key, currentValue)
52
+                    }
53
+                } else if (currentType == ARRAYTYPE) {
54
+                    if (preType != ARRAYTYPE) {
55
+                        setResult(result, (path == '' ? '' : path + ".") + key, currentValue)
56
+                    } else {
57
+                        if (currentValue.length < preValue.length) {
58
+                            setResult(result, (path == '' ? '' : path + ".") + key, currentValue)
59
+                        } else {
60
+                            currentValue.forEach((item, index) => {
61
+                                _diff(item, preValue[index], (path == '' ? '' : path + ".") + key + '[' + index + ']', result)
62
+                            })
63
+                        }
64
+                    }
65
+                } else if (currentType == OBJECTTYPE) {
66
+                    if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) {
67
+                        setResult(result, (path == '' ? '' : path + ".") + key, currentValue)
68
+                    } else {
69
+                        for (let subKey in currentValue) {
70
+                            _diff(currentValue[subKey], preValue[subKey], (path == '' ? '' : path + ".") + key + '.' + subKey, result)
71
+                        }
72
+                    }
73
+                }
74
+            }
75
+        }
76
+    } else if (rootCurrentType == ARRAYTYPE) {
77
+        if (rootPreType != ARRAYTYPE) {
78
+            setResult(result, path, current)
79
+        } else {
80
+            if (current.length < pre.length) {
81
+                setResult(result, path, current)
82
+            } else {
83
+                current.forEach((item, index) => {
84
+                    _diff(item, pre[index], path + '[' + index + ']', result)
85
+                })
86
+            }
87
+        }
88
+    } else {
89
+        setResult(result, path, current)
90
+    }
91
+}
92
+
93
+function setResult(result, k, v) {
94
+    const t = type(v)
95
+    if (t != FUNCTIONTYPE) {
96
+        //if (t != OBJECTTYPE && t != ARRAYTYPE) {
97
+        result[k] = v
98
+        // } else {
99
+        //     result[k] = JSON.parse(JSON.stringify(v))
100
+        // }
101
+    }
102
+}
103
+
104
+function type(obj) {
105
+    return Object.prototype.toString.call(obj)
106
+}

+ 21
- 7
utils/http.js View File

@@ -1,7 +1,6 @@
1 1
 const apiCode = require('../config/code.js').apiCode;
2
-const $api = require('../config/api.js').$api;
3
-const $HttpSever = function () { }
4 2
 
3
+<<<<<<< HEAD
5 4
 $HttpSever.prototype = {
6 5
   /**
7 6
    *  通用请求方法
@@ -26,11 +25,26 @@ $HttpSever.prototype = {
26 25
         },
27 26
         error(msg) {
28 27
           reject(msg)
28
+=======
29
+export default (config = {}) => {
30
+  return new Promise((resolve, reject) => {
31
+    wx.request({
32
+      url: config.url,
33
+      method: config.method,
34
+      data: {
35
+        ...config.data
36
+      },
37
+      success(res) {
38
+        if (res.statusCode && res.statusCode === apiCode.success) {
39
+          resolve(res.data)
40
+        } else {
41
+          resolve(res.data.message + "失败")
42
+>>>>>>> 02bbb13da6392818f573d7fc66c72524bffeb347
29 43
         }
30
-      })
44
+      },
45
+      error(msg) {
46
+        reject(msg)
47
+      }
31 48
     })
32
-  },
49
+  })
33 50
 }
34
-module.exports = {
35
-  HttpSever: new $HttpSever()
36
-}