yuantianjiao преди 6 години
родител
ревизия
3711c2f2b2
променени са 14 файла, в които са добавени 367 реда и са изтрити 0 реда
  1. 32
    0
      app.js
  2. 12
    0
      app.json
  3. 5
    0
      app.wxss
  4. 23
    0
      constant.js
  5. 77
    0
      pages/goResult/goResult.js
  6. 1
    0
      pages/goResult/goResult.json
  7. 4
    0
      pages/goResult/goResult.wxml
  8. 0
    0
      pages/goResult/goResult.wxss
  9. 96
    0
      pages/index/index.js
  10. 1
    0
      pages/index/index.json
  11. 5
    0
      pages/index/index.wxml
  12. 23
    0
      pages/index/index.wxss
  13. 45
    0
      project.config.json
  14. 43
    0
      utils/util.js

+ 32
- 0
app.js Целия файл

@@ -0,0 +1,32 @@
1
+//app.js
2
+import utils from './utils/util.js'
3
+import constant from './constant'
4
+
5
+App({
6
+  onLaunch: function () {
7
+    // 登录
8
+    wx.login({
9
+      success: res => {
10
+        const { appid, secret, baseURL } = this.globalData;
11
+        utils.$httpServer({
12
+          url: '/wechat/mini/login?code='+res.code,
13
+          method: 'POST'
14
+        }).then(data => {
15
+          this.globalData.appConfig = data.result
16
+        }).catch(error => {
17
+          wx.showToast({
18
+            title: '签到失败',
19
+            duration: 1000,
20
+            mask: true
21
+          })
22
+        })
23
+      }
24
+    })
25
+  },
26
+  globalData: {
27
+    userInfo: null,
28
+    appConfig: null,
29
+    fieldId: '',
30
+    ...constant
31
+  }
32
+})

+ 12
- 0
app.json Целия файл

@@ -0,0 +1,12 @@
1
+{
2
+  "pages":[
3
+    "pages/index/index",
4
+    "pages/goResult/goResult"
5
+  ],
6
+  "window":{
7
+    "backgroundTextStyle":"light",
8
+    "navigationBarBackgroundColor": "#fff",
9
+    "navigationBarTitleText": "城的空间签到助手",
10
+    "navigationBarTextStyle":"black"
11
+  }
12
+}

+ 5
- 0
app.wxss Целия файл

@@ -0,0 +1,5 @@
1
+/**app.wxss**/
2
+page {
3
+  width: 100%;
4
+  height: 100%;
5
+}

+ 23
- 0
constant.js Целия файл

@@ -0,0 +1,23 @@
1
+
2
+const constants = {
3
+  dev: {
4
+    appid: 'wx057860e6eed65159',
5
+    secret: '1edc202e244a0d0f24f03e48c4d90c62',
6
+    baseURL: 'https://dev.ycjcjy.com/api/guest/MQ',
7
+    successURL: 'https://dev.ycjcjy.com/checkSuccess',
8
+  },
9
+  test: {
10
+    appid: 'wxe6ab1ec2d96341db',
11
+    secret: '92d6fda9be5badfce7af57bf053e191e',
12
+    baseURL: 'https://spaceofcheng.ycjcjy.com/api/guest/MQ',
13
+    successURL: 'https://spaceofcheng.ycjcjy.com/checkSuccess',
14
+  },
15
+  prod: {
16
+    appid: 'wxe6ab1ec2d96341db',
17
+    secret: '92d6fda9be5badfce7af57bf053e191e',
18
+    baseURL: 'https://spaceofcheng.ycjcjy.com/api/guest/MQ',
19
+    successURL: 'https://spaceofcheng.ycjcjy.com/checkSuccess',
20
+  },
21
+}
22
+
23
+module.exports = constants.prod

+ 77
- 0
pages/goResult/goResult.js Целия файл

@@ -0,0 +1,77 @@
1
+import utils from '../../utils/util.js'
2
+
3
+Page({
4
+
5
+  /**
6
+   * 页面的初始数据
7
+   */
8
+  data: {
9
+    baseUrl: '',
10
+    query: {
11
+      tel: '',
12
+      fieldId: '',
13
+    }
14
+  },
15
+
16
+  /**
17
+   * 生命周期函数--监听页面加载
18
+   */
19
+  onLoad: function (query) {
20
+    const app = getApp()
21
+
22
+    console.log(`${app.globalData.successURL}?${utils.query2search(query)}`)
23
+
24
+    this.setData({
25
+      query,
26
+      baseUrl: `${app.globalData.successURL}?${utils.query2search(query)}`
27
+    })
28
+  },
29
+
30
+  /**
31
+   * 生命周期函数--监听页面初次渲染完成
32
+   */
33
+  onReady: function (e) {
34
+  },
35
+
36
+  /**
37
+   * 生命周期函数--监听页面显示
38
+   */
39
+  onShow: function () {
40
+
41
+  },
42
+
43
+  /**
44
+   * 生命周期函数--监听页面隐藏
45
+   */
46
+  onHide: function () {
47
+    
48
+  },
49
+
50
+  /**
51
+   * 生命周期函数--监听页面卸载
52
+   */
53
+  onUnload: function () {
54
+    
55
+  },
56
+
57
+  /**
58
+   * 页面相关事件处理函数--监听用户下拉动作
59
+   */
60
+  onPullDownRefresh: function () {
61
+    
62
+  },
63
+
64
+  /**
65
+   * 页面上拉触底事件的处理函数
66
+   */
67
+  onReachBottom: function () {
68
+    
69
+  },
70
+
71
+  /**
72
+   * 用户点击右上角分享
73
+   */
74
+  onShareAppMessage: function () {
75
+    
76
+  }
77
+})

+ 1
- 0
pages/goResult/goResult.json Целия файл

@@ -0,0 +1 @@
1
+{}

+ 4
- 0
pages/goResult/goResult.wxml Целия файл

@@ -0,0 +1,4 @@
1
+<!--index.wxml-->
2
+<view class="container">
3
+   <web-view src="{{baseUrl}}"></web-view>
4
+</view>

+ 0
- 0
pages/goResult/goResult.wxss Целия файл


+ 96
- 0
pages/index/index.js Целия файл

@@ -0,0 +1,96 @@
1
+//index.js
2
+//获取应用实例
3
+import utils from '../../utils/util.js'
4
+
5
+Page({
6
+  data: {
7
+    motto: 'Hello World',
8
+    userInfo: {},
9
+    hasUserInfo: false,
10
+    canIUse: wx.canIUse('button.open-type.getUserInfo')
11
+  },
12
+  onLoad: function ({ fieldId }) {
13
+    if (!fieldId) {
14
+      wx.showLoading({
15
+        title: '请通过扫码进入或者二维码已过期',
16
+        mask: true,
17
+      })
18
+    }
19
+
20
+    const app = getApp()
21
+    const { userInfo } = app.globalData
22
+
23
+    app.globalData.fieldId = fieldId
24
+
25
+    if (userInfo) {
26
+      this.setData({
27
+        userInfo,
28
+        hasUserInfo: true
29
+      })
30
+    } else if (this.data.canIUse) {
31
+      app.userInfoReadyCallback = res => {
32
+        this.setData({
33
+          userInfo: res.userInfo,
34
+          hasUserInfo: true
35
+        })
36
+      }
37
+    } else {
38
+      // 在没有 open-type=getUserInfo 版本的兼容处理
39
+      wx.getUserInfo({
40
+        success: res => {
41
+          app.globalData.userInfo = res.userInfo
42
+          this.setData({
43
+            userInfo: res.userInfo,
44
+            hasUserInfo: true
45
+          })
46
+        }
47
+      })
48
+    }
49
+  },
50
+  getUserInfo: function (e) {
51
+    const app = getApp()
52
+
53
+    app.globalData.userInfo = e.detail.userInfo
54
+    this.setData({
55
+      userInfo: e.detail.userInfo,
56
+      hasUserInfo: true
57
+    })
58
+  },
59
+  getPhoneNumber: function (e) {
60
+    const app = getApp()
61
+    const { baseURL } = app.globalData
62
+    utils.$httpServer({
63
+      url: '/wechat/mini/decodedata',
64
+      data: {
65
+        encrypted_data: encodeURIComponent(e.detail.encryptedData),
66
+        session_key: encodeURIComponent(app.globalData.appConfig.session_key),
67
+        iv: encodeURIComponent(e.detail.iv)
68
+      },
69
+      method: 'POST'
70
+    }).then(res => {
71
+      const query = {
72
+        tel: res.result.phoneNumber,
73
+        fieldId: app.globalData.fieldId
74
+      }
75
+      
76
+      if (res.result) {
77
+        wx.redirectTo({
78
+          url: `/pages/goResult/goResult?${utils.query2search(query)}`
79
+        })
80
+      } else {
81
+        wx.showToast({
82
+          title: '签到失败',
83
+          duration: 1000,
84
+          mask: true
85
+        })
86
+      }
87
+      }).catch(error => {
88
+      wx.showToast({
89
+        title: '签到失败',
90
+        duration: 1000,
91
+        mask: true
92
+      })
93
+    })
94
+    console.log(e)
95
+  }
96
+})

+ 1
- 0
pages/index/index.json Целия файл

@@ -0,0 +1 @@
1
+{}

+ 5
- 0
pages/index/index.wxml Целия файл

@@ -0,0 +1,5 @@
1
+<!--index.wxml-->
2
+<view class="container">
3
+  <view class='img_logo'></view>
4
+  <button class='button_m_101_sw' open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>
5
+</view>

+ 23
- 0
pages/index/index.wxss Целия файл

@@ -0,0 +1,23 @@
1
+/**index.wxss**/
2
+.container {
3
+  height: 100%;
4
+  display: flex;
5
+  flex-direction: column;
6
+  align-items: center;
7
+  justify-content: center;
8
+  box-sizing: border-box;
9
+  background-image: url('https://spaceofcheng.oss-cn-beijing.aliyuncs.com/mini/bg.jpg');
10
+  background-repeat: no-repeat;
11
+  background-size: 100% 100%;
12
+  position: relative;
13
+}
14
+.button_m_101_sw {
15
+  position: static;
16
+  height: 326rpx;
17
+  width: 326rpx;
18
+  background-color: transparent;
19
+  background-image: url('https://spaceofcheng.oss-cn-beijing.aliyuncs.com/mini/sign.png');
20
+  background-size: 100% 100%;
21
+  background-repeat: no-repeat;
22
+  border-radius: 0!important;
23
+}

+ 45
- 0
project.config.json Целия файл

@@ -0,0 +1,45 @@
1
+{
2
+	"description": "项目配置文件。",
3
+	"setting": {
4
+		"urlCheck": true,
5
+		"es6": true,
6
+		"postcss": true,
7
+		"minified": true,
8
+		"newFeature": true
9
+	},
10
+	"compileType": "miniprogram",
11
+	"libVersion": "1.9.94",
12
+	"appid": "wxe6ab1ec2d96341db",
13
+	"projectname": "checkIn",
14
+	"isGameTourist": false,
15
+	"condition": {
16
+		"search": {
17
+			"current": -1,
18
+			"list": []
19
+		},
20
+		"conversation": {
21
+			"current": -1,
22
+			"list": []
23
+		},
24
+		"plugin": {
25
+			"current": -1,
26
+			"list": []
27
+		},
28
+		"game": {
29
+			"currentL": -1,
30
+			"list": []
31
+		},
32
+		"miniprogram": {
33
+			"current": 0,
34
+			"list": [
35
+				{
36
+					"id": 0,
37
+					"name": "包含案场",
38
+					"pathName": "pages/index/index",
39
+					"query": "fieldId=1",
40
+					"scene": "1011"
41
+				}
42
+			]
43
+		}
44
+	}
45
+}

+ 43
- 0
utils/util.js Целия файл

@@ -0,0 +1,43 @@
1
+import { baseURL } from '../constant.js'
2
+
3
+const formatTime = date => {
4
+  const year = date.getFullYear()
5
+  const month = date.getMonth() + 1
6
+  const day = date.getDate()
7
+  const hour = date.getHours()
8
+  const minute = date.getMinutes()
9
+  const second = date.getSeconds()
10
+
11
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12
+}
13
+
14
+const formatNumber = n => {
15
+  n = n.toString()
16
+  return n[1] ? n : '0' + n
17
+}
18
+
19
+const $httpServer = (config = {}) => {
20
+  const { url, data, method} = config
21
+  return new Promise((resolve, reject) => {
22
+    wx.request({
23
+      url: `${baseURL}/${url}`,
24
+      data,
25
+      method: method,
26
+      success(response) {
27
+        resolve(response.data)
28
+      },
29
+      error(err) {
30
+        reject(err)
31
+      }
32
+    })
33
+  })
34
+}
35
+
36
+const query2search = (query) => Object.keys(query).map(k => (`${k}=${query[k]}`)).join('&')
37
+
38
+module.exports = {
39
+  formatTime: formatTime,
40
+  $httpServer: $httpServer,
41
+  query2search: query2search,
42
+}
43
+