zjxpcyc пре 6 година
родитељ
комит
02bbb13da6

+ 38
- 0
app.js Прегледај датотеку

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

+ 20
- 5
config/api.js Прегледај датотеку

@@ -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
   banner: {
15 23
     list: {
@@ -23,19 +31,26 @@ const $api = {
23 31
       url: `${BaseAPIURl}/wx/building/list`
24 32
     },
25 33
   },
26
-  dynamic: {
27
-    list: {
34
+  dynamic: { // 项目
35
+    list: { // 项目列表
28 36
       methods: 'GET',
29 37
       url: `${BaseAPIURl}/wx/buildingDynamiceList`
30 38
     },
31
-    detail: {
39
+    detail: { // 项目详情
32 40
       methods: 'GET',
33 41
       url: `${BaseAPIURl}/wx/buildingDynamiceInfo/:id`
34 42
     }
35 43
   },
36 44
   activity: {
37
-    
38
-  }
45
+    list: { // 活动列表
46
+      methods: 'GET',
47
+      url: `${BaseAPIURl}/wx/activity`
48
+    },
49
+    detail: { // 活动详情
50
+      methods: 'GET',
51
+      url: `${BaseAPIURl}/wx/activity/:id`
52
+    }
53
+  },
39 54
 }
40 55
 
41 56
 module.exports = {

+ 1
- 4
config/code.js Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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>

+ 2
- 0
pages/UserCenter/UserInfo/index.js Прегледај датотеку

@@ -18,6 +18,8 @@ create(store, {
18 18
       this.setData({
19 19
         loadding: true
20 20
       })
21
+
22
+
21 23
     }
22 24
   },
23 25
   FormInput(e) { // 表单输入数据绑定

+ 75
- 77
pages/components/Concessions/index.js Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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
 })

+ 4
- 2
pages/components/Estate/index.js Прегледај датотеку

@@ -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({
@@ -78,7 +80,7 @@ Component({
78 80
         type: 'wgs84',
79 81
         success(res) {
80 82
           console.log(res)
81
-          HttpSever.Ajax({
83
+          fetch({
82 84
             url: $api.building.list.url,
83 85
             method: $api.building.list.method,
84 86
           }).then((data) => {

+ 18
- 34
utils/http.js Прегледај датотеку

@@ -1,39 +1,23 @@
1 1
 const apiCode = require('../config/code.js').apiCode;
2
-const $api = require('../config/api.js').$api;
3
-const $HttpSever = function () { }
4 2
 
5
-$HttpSever.prototype = {
6
-  /**
7
-   *  通用请求方法
8
-   * 
9
-   * @param {any} [config={}] 
10
-   * @returns 
11
-   */
12
-  Ajax(config = {}) {
13
-    return new Promise((resolve, reject) => {
14
-      wx.request({
15
-        url: config.url,
16
-        method: config.method,
17
-        data: {
18
-          ...config.data
19
-        },
20
-        header: {
21
-          'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
22
-        },
23
-        success(res) {
24
-          if (res.statusCode && res.statusCode === apiCode.common.successCode) {
25
-            resolve(res.data)
26
-          } else {
27
-            resolve(res.data.message + "失败")
28
-          }
29
-        },
30
-        error(msg) {
31
-          reject(msg)
3
+export default (config = {}) => {
4
+  return new Promise((resolve, reject) => {
5
+    wx.request({
6
+      url: config.url,
7
+      method: config.method,
8
+      data: {
9
+        ...config.data
10
+      },
11
+      success(res) {
12
+        if (res.statusCode && res.statusCode === apiCode.success) {
13
+          resolve(res.data)
14
+        } else {
15
+          resolve(res.data.message + "失败")
32 16
         }
33
-      })
17
+      },
18
+      error(msg) {
19
+        reject(msg)
20
+      }
34 21
     })
35
-  },
22
+  })
36 23
 }
37
-module.exports = {
38
-  HttpSever: new $HttpSever()
39
-}