diff --git a/app.js b/app.js index 1ed57c4..c0bd792 100644 --- a/app.js +++ b/app.js @@ -6,10 +6,15 @@ App({ logs.unshift(Date.now()) wx.setStorageSync('logs', logs) - // 登录 - wx.login({ - success: res => { - // 发送 res.code 到后台换取 openId, sessionKey, unionId + wx.checkSession({ + success (e) { + //session_key 未过期,并且在本生命周期一直有效 + console.log('有效', e) + }, + fail (e) { + // session_key 已经失效,需要重新执行登录流程 + console.log('失效', e) + // wx.login() //重新登录 } }) }, diff --git a/app.json b/app.json index 3d7616f..bba67e2 100644 --- a/app.json +++ b/app.json @@ -1,14 +1,29 @@ { - "pages":[ - "pages/index/index", - "pages/logs/logs" + "pages": [ + "pages/basicInformation/basicInformation", + "pages/authorization/authorization" ], - "window":{ - "backgroundTextStyle":"light", + "permission": { + "scope.userLocation": { + "desc": "你的位置信息将用于小程序位置接口的效果展示" + } + }, + "window": { + "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "Weixin", - "navigationBarTextStyle":"black" + "navigationBarTextStyle": "black" }, "style": "v2", - "sitemapLocation": "sitemap.json" -} + "sitemapLocation": "sitemap.json", + "plugins": { + "WechatSI": { + "version": "0.3.4", + "provider": "wx069ba97219f66d99" + }, + "ocr-plugin": { + "version": "3.0.6", + "provider": "wx4418e3e031e551be" + } + } +} \ No newline at end of file diff --git a/app.wxss b/app.wxss index 06c6fc9..283c72b 100644 --- a/app.wxss +++ b/app.wxss @@ -1,10 +1,4 @@ /**app.wxss**/ .container { - height: 100%; - display: flex; - flex-direction: column; - align-items: center; - justify-content: space-between; - padding: 200rpx 0; - box-sizing: border-box; + padding: 0 10px; } diff --git a/pages/authorization/authorization.js b/pages/authorization/authorization.js new file mode 100644 index 0000000..622b9af --- /dev/null +++ b/pages/authorization/authorization.js @@ -0,0 +1,55 @@ +Page({ + data: { + motto: 'Hello World', + userInfo: {}, + hasUserInfo: false, + canIUse: wx.canIUse('button.open-type.getUserInfo'), + canIUseGetUserProfile: false, + canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false + }, + + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '授权登录', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + // 授权成功关闭当前页面,跳转至基础信息登记页面 + wx.redirectTo({ + url: '../basicInformation/basicInformation' + }) + } + }) + }, + // 分享朋友 + onShareAppMessage: (res) => { + return { + title: '业主思维', + path: '/pages/index/index', + imageUrl: "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D450%2C600/sign=e98512f3b5fd5266a77e34109e28bb1d/8d5494eef01f3a2945bbcbd69a25bc315c607cb2.jpg", + success: (res) => { + console.log("转发成功", res); + }, + fail: (res) => { + console.log("转发失败", res); + } + } + }, + // 分享朋友圈 + onShareTimeline: (res) => { + return { + title: '业主思维', + path: '/pages/index/index', + imageUrl: "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D450%2C600/sign=e98512f3b5fd5266a77e34109e28bb1d/8d5494eef01f3a2945bbcbd69a25bc315c607cb2.jpg", + success: (res) => { + console.log("转发成功", res); + }, + fail: (res) => { + console.log("转发失败", res); + } + } + } +}) \ No newline at end of file diff --git a/pages/authorization/authorization.json b/pages/authorization/authorization.json new file mode 100644 index 0000000..0b9639f --- /dev/null +++ b/pages/authorization/authorization.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "授权", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/authorization/authorization.wxml similarity index 98% rename from pages/index/index.wxml rename to pages/authorization/authorization.wxml index cb99070..261a5c0 100644 --- a/pages/index/index.wxml +++ b/pages/authorization/authorization.wxml @@ -1,4 +1,4 @@ - + diff --git a/pages/index/index.wxss b/pages/authorization/authorization.wxss similarity index 100% rename from pages/index/index.wxss rename to pages/authorization/authorization.wxss diff --git a/pages/basicInformation/basicInformation.js b/pages/basicInformation/basicInformation.js new file mode 100644 index 0000000..372c382 --- /dev/null +++ b/pages/basicInformation/basicInformation.js @@ -0,0 +1,86 @@ +var plugin = requirePlugin("WechatSI") +let manager = plugin.getRecordRecognitionManager() + +Page({ + data: { + scrollTop: '0', + formData: { + switch: true, + radio: 'radio1' + }, + loading: true, + text: '' + }, + + formSubmit(e) { + console.log('form发生了submit事件,携带数据为:', e.detail.value) + }, + + formReset(e) { + console.log('form发生了reset事件,携带数据为:', e.detail.value) + this.setData({ + chosen: '' + }) + }, + + onShareAppMessage: (res) => { + return { + title: '业主思维', + path: '/pages/index/index', + imageUrl: "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D450%2C600/sign=e98512f3b5fd5266a77e34109e28bb1d/8d5494eef01f3a2945bbcbd69a25bc315c607cb2.jpg", + success: (res) => { + console.log("转发成功", res); + }, + fail: (res) => { + console.log("转发失败", res); + } + } + }, + onShareTimeline: (res) => { + return { + title: '业主思维', + path: '/pages/index/index', + imageUrl: "https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D450%2C600/sign=e98512f3b5fd5266a77e34109e28bb1d/8d5494eef01f3a2945bbcbd69a25bc315c607cb2.jpg", + success: (res) => { + console.log("转发成功", res); + }, + fail: (res) => { + console.log("转发失败", res); + } + } + }, + + onLoad(){ + wx.request({ + url: 'http://101.201.121.115:8093/user/getuserinfo', //仅为示例,并非真实的接口地址 + data: { + x: '', + y: '' + }, + header: { + 'content-type': 'application/json' // 默认值 + }, + success (res) { + console.log(res.data) + } + }) + wx.getSetting({ + success(res) { + // 校验用户是否已经授权 + if (res.authSetting['scope.userInfo']) { + // 必须是在用户已经授权的情况下调用 + wx.getUserInfo({ + success: function (res) { + console.log(res) + } + }) + }else{ + // 如果未授权则关闭所有页面,跳转至授权登录页 + wx.reLaunch({ + url: '/pages/authorization/authorization' + }) + } + } + }) + } +}) \ No newline at end of file diff --git a/pages/basicInformation/basicInformation.json b/pages/basicInformation/basicInformation.json new file mode 100644 index 0000000..746f4bb --- /dev/null +++ b/pages/basicInformation/basicInformation.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "基础信息", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/basicInformation/basicInformation.wxml b/pages/basicInformation/basicInformation.wxml new file mode 100644 index 0000000..3989573 --- /dev/null +++ b/pages/basicInformation/basicInformation.wxml @@ -0,0 +1,54 @@ + + + + +
+ + switch + + + + radio + + + + + + + checkbox + + + + + + + slider + + + + input + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/pages/basicInformation/basicInformation.wxss b/pages/basicInformation/basicInformation.wxss new file mode 100644 index 0000000..c2adfaa --- /dev/null +++ b/pages/basicInformation/basicInformation.wxss @@ -0,0 +1,7 @@ +.ocr-wrapper { + margin: 40rpx auto; + width: 375rpx; +} +.intro { + margin: 40rpx; +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js deleted file mode 100644 index 68f2382..0000000 --- a/pages/index/index.js +++ /dev/null @@ -1,49 +0,0 @@ -// index.js -// 获取应用实例 -const app = getApp() - -Page({ - data: { - motto: 'Hello World', - userInfo: {}, - hasUserInfo: false, - canIUse: wx.canIUse('button.open-type.getUserInfo'), - canIUseGetUserProfile: false, - canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false - }, - // 事件处理函数 - bindViewTap() { - wx.navigateTo({ - url: '../logs/logs' - }) - }, - onLoad() { - if (wx.getUserProfile) { - this.setData({ - canIUseGetUserProfile: true - }) - } - }, - - getUserProfile(e) { - // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 - wx.getUserProfile({ - desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 - success: (res) => { - console.log(res) - this.setData({ - userInfo: res.userInfo, - hasUserInfo: true - }) - } - }) - }, - getUserInfo(e) { - // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 - console.log(e) - this.setData({ - userInfo: e.detail.userInfo, - hasUserInfo: true - }) - } -}) diff --git a/pages/index/index.json b/pages/index/index.json deleted file mode 100644 index 8835af0..0000000 --- a/pages/index/index.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "usingComponents": {} -} \ No newline at end of file diff --git a/pages/logs/logs.js b/pages/logs/logs.js deleted file mode 100644 index 85f6aac..0000000 --- a/pages/logs/logs.js +++ /dev/null @@ -1,18 +0,0 @@ -// logs.js -const util = require('../../utils/util.js') - -Page({ - data: { - logs: [] - }, - onLoad() { - this.setData({ - logs: (wx.getStorageSync('logs') || []).map(log => { - return { - date: util.formatTime(new Date(log)), - timeStamp: log - } - }) - }) - } -}) diff --git a/pages/logs/logs.json b/pages/logs/logs.json deleted file mode 100644 index 3ee76c1..0000000 --- a/pages/logs/logs.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "navigationBarTitleText": "查看启动日志", - "usingComponents": {} -} \ No newline at end of file diff --git a/pages/logs/logs.wxml b/pages/logs/logs.wxml deleted file mode 100644 index 0b6b645..0000000 --- a/pages/logs/logs.wxml +++ /dev/null @@ -1,6 +0,0 @@ - - - - {{index + 1}}. {{log.date}} - - diff --git a/pages/logs/logs.wxss b/pages/logs/logs.wxss deleted file mode 100644 index 94d4b88..0000000 --- a/pages/logs/logs.wxss +++ /dev/null @@ -1,8 +0,0 @@ -.log-list { - display: flex; - flex-direction: column; - padding: 40rpx; -} -.log-item { - margin: 10rpx; -} diff --git a/pages/questionnaire/questionnaire.js b/pages/questionnaire/questionnaire.js new file mode 100644 index 0000000..3041557 --- /dev/null +++ b/pages/questionnaire/questionnaire.js @@ -0,0 +1,3 @@ +Page({ + +}) \ No newline at end of file diff --git a/pages/questionnaire/questionnaire.json b/pages/questionnaire/questionnaire.json new file mode 100644 index 0000000..4a19850 --- /dev/null +++ b/pages/questionnaire/questionnaire.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "问卷调查", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/questionnaire/questionnaire.wxml b/pages/questionnaire/questionnaire.wxml new file mode 100644 index 0000000..bcc044c --- /dev/null +++ b/pages/questionnaire/questionnaire.wxml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/pages/questionnaire/questionnaire.wxss b/pages/questionnaire/questionnaire.wxss new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e69de29