From 78f894957ad91c24c07abbdbfd0130df9cd990f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E4=BA=9A=E7=94=B7?= Date: Mon, 18 Oct 2021 17:39:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=92=8C=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=9A=84=E5=AE=8C=E5=96=84=EF=BC=8C=E6=88=91?= =?UTF-8?q?=E7=9A=84=E9=A1=B5=E9=9D=A2=E9=9C=80=E8=A6=81=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/common.js | 29 ++++- assets/js/http/http.js | 14 +-- pages/home/home.js | 8 +- pages/home/home.wxml | 10 +- pages/login/login.js | 20 +-- pages/login/login.wxml | 2 +- pages/mine/mine.js | 178 ++++++++++++++------------- pages/phonePassword/phonePassword.js | 14 ++- pages/setPassword/setPassword.js | 2 +- 9 files changed, 150 insertions(+), 127 deletions(-) diff --git a/assets/js/common.js b/assets/js/common.js index 4779f12..41030c0 100644 --- a/assets/js/common.js +++ b/assets/js/common.js @@ -1,25 +1,42 @@ export function wxBind(callback){ // 获取openid进行手机号和微信的绑定 + let count = 1 wx.login({ success (res) { - if (res.code) { - //发起网络请求 + if (res.code && count === 1) { wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session', data: { - appid: 'wx24914e866df035fb', - secret: '0d2830f26f57722716249f2b2236f409', + appid: 'wx322b63d1e6ff4765', + secret: '7d3dd94092bb50981d0a8ded849601a0', js_code: res.code, grant_type: 'authorization_code' }, success (res) { // 成功拿到openId // 微信和该账号绑定 - callback(res) + if(count === 1){ // 回调会莫名回调两次,未知原因 + callback(res) + } + count++ } }) } else { - console.log('授权失败!' + res.errMsg) + console.log('授权失败!' + res.message) } } }) +} +// 检验是否登录 +export function isLogin(callback){ + wx.getStorage({ + key: 'X-Access-Token', + success(res){ + callback() + }, + fail(){ + wx.navigateTo({ + url: '../login/login', + }) + } + }) } \ No newline at end of file diff --git a/assets/js/http/http.js b/assets/js/http/http.js index fc947d1..22b3f25 100644 --- a/assets/js/http/http.js +++ b/assets/js/http/http.js @@ -22,7 +22,6 @@ const http = (method, url, data, header= headerDefault) => { header: header, data: data, success: res => { - console.log(res) wx.hideLoading(); if (res.statusCode === 200) { // 接口请求错误的时候提示 @@ -37,15 +36,14 @@ const http = (method, url, data, header= headerDefault) => { // 200: 服务端业务处理正常结束 resolve(res.data) } else { - console.error(res.data); reject(res.data); wx.hideLoading(); - wx.showToast({ - title: "登录失效,请重新登录", - icon: "none", - duration: 1500, - mask: true - }); + // wx.showToast({ + // title: "登录失效,请重新登录", + // icon: "none", + // duration: 1500, + // mask: true + // }); // wx.navigateTo({ // url: '/pages/login/login', // }) diff --git a/pages/home/home.js b/pages/home/home.js index 16d410a..bcb6198 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -17,10 +17,10 @@ Page({ { path: '../../assets/images/ziliao.png', text: '资料网员' }, ], titleList: [ - '会议提醒', - '文件提醒', - '邮寄提醒', - '催款提醒', + '会议通知', + '文件通知', + '邮寄通知', + '催款通知', ], index: 0, list: [], // 消息列表 diff --git a/pages/home/home.wxml b/pages/home/home.wxml index fe83ece..c697b87 100644 --- a/pages/home/home.wxml +++ b/pages/home/home.wxml @@ -19,13 +19,13 @@ - + 类型 - 会议提醒 - 文件提醒 - 邮寄提醒 - 催款提醒 + 会议通知 + 文件通知 + 邮寄通知 + 催款通知 diff --git a/pages/login/login.js b/pages/login/login.js index a54a65c..50dda4e 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -80,10 +80,11 @@ Page({ }, // 微信登录 wxLogin(){ + const that = this wxBind((res)=>{ let params = { openId: res.data.openid, - rsaPublicKey: this.data.rsaPublicKey + rsaPublicKey: that.data.rsaPublicKey } UserApi.wxLogin(params).then(res=>{ if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp) @@ -96,11 +97,7 @@ Page({ url: '../home/home', }) }else{ // 首次登录不能直接用微信快捷登录 - wx.showToast({ - title: '暂未授权手机号', - duration: 2000, - icon: "none", - }) + } }) }) @@ -120,6 +117,7 @@ Page({ key: 'userInfo', data: res.result.userInfo }) + // 第一次登录系统,需要设置密码 if(res.message === "updatePassword") { // 存临时token wx.setStorage({ @@ -136,8 +134,11 @@ Page({ key: 'X-Access-Token', data: res.result.token }) - // 绑定微信 - this.wxBind() + // 如果绑定过微信就不再进行绑定 + if(!res.result.userInfo.openId){ + // 绑定微信 + this.wxBindPhone() + } // 跳转首页 wx.switchTab({ url: '../home/home', @@ -167,7 +168,8 @@ Page({ }) }, // 绑定微信 - wxBind(){ + wxBindPhone(){ + const that = this wxBind((res)=>{ let params = { openId: res.data.openid, diff --git a/pages/login/login.wxml b/pages/login/login.wxml index ca2b763..b244027 100644 --- a/pages/login/login.wxml +++ b/pages/login/login.wxml @@ -17,7 +17,7 @@ - + 手机密码登录 忘记密码? diff --git a/pages/mine/mine.js b/pages/mine/mine.js index 90abb37..8644f4d 100644 --- a/pages/mine/mine.js +++ b/pages/mine/mine.js @@ -1,6 +1,8 @@ // pages/mine/mine.js import UserApi from '../../assets/js/http/userApi' -import http from '../../assets/js/http/http' +import { + isLogin +} from '../../assets/js/common' Page({ /** @@ -13,121 +15,121 @@ Page({ rsaPublicKey: '', }, // 个人信息 - mineInfo(){ - wx.navigateTo({ - url: '../mineInfo/mineInfo', + mineInfo() { + isLogin(() => { + wx.navigateTo({ + url: '../mineInfo/mineInfo', + }) }) }, // 修改密码 - upDateInfo(){ - wx.navigateTo({ - url: '../upDateInfo/upDateInfo', + upDateInfo() { + isLogin(() => { + wx.navigateTo({ + url: '../upDateInfo/upDateInfo', + }) }) }, // 解除绑定 - unBind(){ - wx.showModal({ - cancelColor: '取消', - content: '确定解绑并退出登录?', - confirmColor: '#069F99', - success (res) { - if (res.confirm) { - UserApi.wxUnbind().then(res=>{ - if(res.success){ - wx.clearStorage() - wx.redirectTo({ - url: '../login/login', - }) - }else{ - wx.clearStorage() - wx.redirectTo({ - url: '../login/login', - }) - } - }) - } else if (res.cancel) {} - } + unBind() { + isLogin(() => { + wx.showModal({ + cancelColor: '取消', + content: '确定解绑并退出登录?', + confirmColor: '#069F99', + success(res) { + if (res.confirm) { + UserApi.wxUnbind().then(res => { + if (res.success) { + wx.clearStorage() + wx.redirectTo({ + url: '../login/login', + }) + } else { + wx.clearStorage() + wx.redirectTo({ + url: '../login/login', + }) + } + }) + } else if (res.cancel) {} + } + }) }) }, // 扫码签到 - scanCode(){ - // wx.scanCode({ - // onlyFromCamera: false, - // scanType: [], - // success: (result) => { - // console.log(result) - // }, - // fail: (res) => { - // console.log(result) - // }, - // complete: (res) => { - // console.log(result) - // }, + scanCode() { + // isLogin(() => { + // wx.scanCode({ + // onlyFromCamera: false, + // scanType: [], + // success: (result) => { + // console.log(result) + // }, + // fail: (res) => { + // console.log(result) + // }, + // complete: (res) => { + // console.log(result) + // }, + // }) + // 成功扫码的回调 1448213074467938306,1448107789464113154 + UserApi.scanCode({ + meetingId: '1448213074467938306' + }).then(res => { + if (res.success) { + let result = JSON.stringify(res.result) + wx.navigateTo({ + url: `../scanSign/scanSign?signed=1&meeting=${result}`, + }) + } else { + let result = JSON.stringify(res.result) + // 未查到报名信息 + wx.navigateTo({ + url: `../scanSign/scanSign?signed=0&meeting=${result}`, + }) + } + }) // }) - // 成功扫码的回调 1448213074467938306,1448107789464113154 - UserApi.scanCode({meetingId: '1448213074467938306'}).then(res=>{ - if(res.success){ - let result = JSON.stringify(res.result) - wx.navigateTo({ - url: `../scanSign/scanSign?signed=1&meeting=${result}`, - }) - }else{ - let result = JSON.stringify(res.result) - // 未查到报名信息 - wx.navigateTo({ - url: `../scanSign/scanSign?signed=0&meeting=${result}`, - }) - } - }) }, // 我的资料 - mineData(){ - wx.navigateTo({ - url: '../mineData/mineData', + mineData() { + isLogin(()=>{ + wx.navigateTo({ + url: '../mineData/mineData', + }) }) }, // 我的合同 - mineContract(){ - wx.navigateTo({ - url: '../mineContract/mineContract', + mineContract() { + isLogin(()=>{ + wx.navigateTo({ + url: '../mineContract/mineContract', + }) }) }, // 去登录 - goLogin(){ + goLogin() { wx.navigateTo({ url: '../login/login', }) }, // 退出登录 - logout(){ + logout() { wx.showModal({ - cancelColor: '取消', content: '确定退出登录?', confirmColor: '#069F99', - success (res) { + success(res) { if (res.confirm) { - UserApi.logout().then(res=>{ - if(res.success){ - wx.clearStorage() - wx.redirectTo({ - url: '../login/login', - }) - }else{ - wx.clearStorage() - wx.redirectTo({ - url: '../login/login', - }) - } + UserApi.logout().then(res => { + wx.clearStorage() + wx.redirectTo({ + url: '../login/login', + }) }) - } else if (res.cancel) {} + } } }) - }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - }, /** * 生命周期函数--监听页面显示 @@ -138,11 +140,11 @@ Page({ this.setData({ token }) - if(userInfo){ + if (userInfo) { this.setData({ name: userInfo.name, phone: userInfo.phone.substr(0, 3) + '-' + userInfo.phone.substr(3, 4) + '-' + userInfo.phone.substr(7, 4) }) } } -}) +}) \ No newline at end of file diff --git a/pages/phonePassword/phonePassword.js b/pages/phonePassword/phonePassword.js index a08b809..62500b8 100644 --- a/pages/phonePassword/phonePassword.js +++ b/pages/phonePassword/phonePassword.js @@ -13,9 +13,9 @@ Page({ form: { currdatetime: '', requestCodeSuccess: true, - randCodeImage: '', // 验证码 - rsaPublicKey: '', // 公钥 + randCodeImage: '' // 验证码 }, + rsaPublicKey: '', // 公钥 flag: false }, @@ -108,8 +108,11 @@ Page({ if(this.data.flag){ UserApi.passWordLogin(params).then(res => { if(res.success){ - // 微信绑定 - this.wxBind() + // 如果绑定过微信就不再进行绑定 + if(!res.result.userInfo.openId){ + // 绑定微信 + this.wxBindPhone() + } // 存token和userInfo wx.setStorage({ key: 'X-Access-Token', @@ -137,7 +140,8 @@ Page({ }, // 绑定微信 - wxBind(){ + wxBindPhone(){ + const that = this // 获取openid进行手机号和微信的绑定 wxBind((res)=>{ let params = { diff --git a/pages/setPassword/setPassword.js b/pages/setPassword/setPassword.js index f0e31a1..d973ecb 100644 --- a/pages/setPassword/setPassword.js +++ b/pages/setPassword/setPassword.js @@ -101,6 +101,7 @@ Page({ }, // 绑定微信 wxBind(){ + const that = this wxBind((res)=>{ // 微信和该账号绑定 let params = { @@ -130,7 +131,6 @@ Page({ that.setData({ password: res.data }) - console.log(that.data.password) } }) }