diff --git a/src/app.json b/src/app.json index 3c4d93e..e06653b 100644 --- a/src/app.json +++ b/src/app.json @@ -3,6 +3,7 @@ "pages": [ "pages/home/index", "pages/login/index", + "pages/switchLogin/index", "pages/my/index", "pages/topic/index", "pages/collection/index", diff --git a/src/app.ts b/src/app.ts index 653c521..c84fdd6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -30,12 +30,9 @@ App({ loginState: '', isLogin: 0, - doctorId: null, + isAnswer: '0', scene: null, - - needDeal: '', - caseNav: '0', }, onLaunch() { Page = page as WechatMiniprogram.Page.Constructor; @@ -68,26 +65,19 @@ App({ this.globalData.scene = parseScene(options.query.scene); } }, - waitLogin(waitLoginState = false) { + waitLogin(waitLoginState = false, requireLogin = false) { let time: number; - return new Promise((resolve, reject) => { + const { isLogin } = this.globalData; + return new Promise((resolve) => { time = setInterval(() => { if (this.globalData.loginState) { clearInterval(time); if (waitLoginState) { resolve(true); - } else if (this.globalData.isLogin === 0) { - wx.reLaunch({ url: '/module1/pages/login/index' }); - } else if (this.globalData.doctorId === null) { - this.getApplyDoctor().then((applyDoctorInfo) => { - if (applyDoctorInfo.AuditStatus === 0) { - wx.reLaunch({ url: '/module1/pages/setInfoResult/index' }); - reject(new Error('还在审核中')); - } else { - wx.reLaunch({ url: '/module1/pages/setInfo/index' }); - reject(new Error('还不是医生')); - } - }); + } else if (isLogin === 0) { + wx.reLaunch({ url: '/pages/login/index' }); + } else if (requireLogin && isLogin === 999) { + wx.reLaunch({ url: '/pages/login/index' }); } else { resolve(true); } @@ -95,21 +85,17 @@ App({ }, 500); }); }, - getApplyDoctor() { - return wx.ajax({ - method: 'GET', - url: '?r=takeda/reg/get-apply-doctor', - }); - }, getUserInfo(self: WechatMiniprogram.Page.Instance, callback?: (res: any) => void) { wx.ajax({ method: 'GET', - url: '?r=shizhong/account/info', + url: '?r=shizhong/account/get-info', data: {}, }).then((res) => { - self.setData({ - userInfo: res, - }); + if (self) { + self.setData({ + userInfo: res, + }); + } callback?.(res); }); }, diff --git a/src/components/global-toast/index.ts b/src/components/global-toast/index.ts index de9b15a..ab42e7e 100644 --- a/src/components/global-toast/index.ts +++ b/src/components/global-toast/index.ts @@ -14,6 +14,10 @@ Component({ type: Number, value: 0, }, + params: { + type: Object, + value: {}, + }, }, /** @@ -26,7 +30,7 @@ Component({ */ methods: { handleClose() { - this.triggerEvent("close"); + this.triggerEvent('close'); }, }, }); diff --git a/src/components/global-toast/index.wxml b/src/components/global-toast/index.wxml index 7e2ff6f..e091afc 100644 --- a/src/components/global-toast/index.wxml +++ b/src/components/global-toast/index.wxml @@ -1,7 +1,7 @@ - + 关注适中健康微信公众号 - + 长按识别二维码关注 diff --git a/src/pages/home/index.ts b/src/pages/home/index.ts index 913ee0c..06ad7e5 100644 --- a/src/pages/home/index.ts +++ b/src/pages/home/index.ts @@ -1,11 +1,13 @@ -const _app = getApp(); +const app = getApp(); Page({ data: {}, - onLoad() {}, + onLoad() { + app.waitLogin().then(() => {}); + }, handleDetail() { wx.navigateTo({ - url: "/pages/classify/index", + url: '/pages/classify/index', }); }, }); diff --git a/src/pages/login/index.ts b/src/pages/login/index.ts index 49394a1..b15babf 100644 --- a/src/pages/login/index.ts +++ b/src/pages/login/index.ts @@ -87,13 +87,12 @@ Page({ mobile, code, }, - }).then((res) => { - this.submitCallback(res); + }).then(() => { + this.submitCallback(); }); }, handleWxSubmit(e: any) { const { protool } = this.data; - const { iv, encryptedData } = e.detail; if (!protool) { wx.showToast({ icon: 'none', @@ -101,6 +100,7 @@ Page({ }); return; } + const { iv, encryptedData } = e.detail; if (iv && encryptedData) { wx.ajax({ method: 'POST', @@ -109,18 +109,22 @@ Page({ iv: encodeURIComponent(iv), encryptedData: encodeURIComponent(encryptedData), }, - }).then((res) => { - this.submitCallback(res); + }).then(() => { + this.submitCallback(); }); } }, - submitCallback(res) { + submitCallback() { app.globalData.isLogin = 1; - app.globalData.doctorId = res.doctorId; - app.waitLogin().then(() => { - wx.reLaunch({ - url: '/pages/home/index', - }); + app.getUserInfo(null, (res) => { + app.globalData.isAnswer = res.isAnswer; + if (res.isAnswer === '0') { + this.setData({ + show: true, + }); + } else { + wx.reLaunch({ url: '/pages/home/index' }); + } }); }, handleProtool() { @@ -131,11 +135,21 @@ Page({ handleNavProtool() { wx.navigateTo({ url: `/pages/protocol/index` }); }, - - handleTopic() {}, + handleTopic() { + wx.reLaunch({ + url: '/pages/topic/index', + }); + }, handleCancelTopic() { - this.setData({ - show: false, + app.globalData.isAnswer = '1'; + wx.reLaunch({ + url: '/pages/home/index', + }); + }, + handleVisitor() { + app.globalData.isLogin = 999; + wx.reLaunch({ + url: '/pages/home/index', }); }, }); diff --git a/src/pages/login/index.wxml b/src/pages/login/index.wxml index ec787b4..f9fe17d 100644 --- a/src/pages/login/index.wxml +++ b/src/pages/login/index.wxml @@ -29,11 +29,15 @@ 《用户隐私协议》 登录 - - + + 游客访问 diff --git a/src/pages/my/index.ts b/src/pages/my/index.ts index b0f762e..d21c468 100644 --- a/src/pages/my/index.ts +++ b/src/pages/my/index.ts @@ -1,14 +1,43 @@ -const _app = getApp(); +const app = getApp(); Page({ data: { toastShow: false, toastType: 1, + + userInfo: {}, + }, + onLoad() { + app.waitLogin(true).then(() => { + app.getUserInfo(this); + }); }, - onLoad() {}, handleCollection() { wx.navigateTo({ - url: "/pages/collection/index", + url: '/pages/collection/index', + }); + }, + handleLogin() { + wx.navigateTo({ + url: '/pages/login/index', + }); + }, + handleLoginOut() { + wx.showModal({ + title: '是否确认退出登录?', + success: (res) => { + if (res.confirm) { + wx.ajax({ + method: 'POST', + url: '?r=shizhong/account/logout', + data: {}, + }).then(() => { + app.globalData.isLogin = 0; + app.globalData.isAnswer = '0'; + app.waitLogin(); + }); + } + }, }); }, handleOffice() { diff --git a/src/pages/my/index.wxml b/src/pages/my/index.wxml index 5757310..d6c2d1a 100644 --- a/src/pages/my/index.wxml +++ b/src/pages/my/index.wxml @@ -1,20 +1,21 @@ - -