|
|
|
@ -17,349 +17,82 @@ App<IAppOption>({
@@ -17,349 +17,82 @@ App<IAppOption>({
|
|
|
|
|
globalData: { |
|
|
|
|
// dev
|
|
|
|
|
// appid:wxa4ece062e60e93a5
|
|
|
|
|
url: 'https://m.zd.hbraas.com', |
|
|
|
|
upFileUrl: 'https://m.zd.hbraas.com/', |
|
|
|
|
imageUrl: "https://m.wtx.hbraas.com/GeneB/", |
|
|
|
|
url: 'https://m.wtx.hbraas.com', |
|
|
|
|
upFileUrl: 'https://m.wtx.hbraas.com/', |
|
|
|
|
imageUrl: 'https://m.wtx.hbraas.com/GeneB/', |
|
|
|
|
|
|
|
|
|
// pro
|
|
|
|
|
// appid:wx96f45ca4f1fa36ec
|
|
|
|
|
// url: 'https://m.zd.hbsaas.com',
|
|
|
|
|
// upFileUrl: 'https://m.zd.hbsaas.com/',
|
|
|
|
|
// imageUrl: 'https://m.zd.hbsaas.com/zd/',
|
|
|
|
|
//
|
|
|
|
|
//login
|
|
|
|
|
registrationSource: 0, |
|
|
|
|
registChannel: 0, |
|
|
|
|
regBusinessId: '', |
|
|
|
|
IsAliQiWei: 0, |
|
|
|
|
// url: 'https://m.wtx.hbsaas.com',
|
|
|
|
|
// upFileUrl: 'https://m.wtx.hbsaas.com/',
|
|
|
|
|
// imageUrl: 'https://m.wtx.hbsaas.com/GeneB/',
|
|
|
|
|
Timestamp: new Date().getTime(), |
|
|
|
|
|
|
|
|
|
scene: {}, |
|
|
|
|
listeners: [], |
|
|
|
|
|
|
|
|
|
Timestamp: new Date().getTime(), |
|
|
|
|
loginState: '', |
|
|
|
|
isLogin: 0, // 0 未登录 1 已登录
|
|
|
|
|
isReg: '0', |
|
|
|
|
WorkerId: '', |
|
|
|
|
loginType: '', // 1:患者 2:医生
|
|
|
|
|
isReg: 0, |
|
|
|
|
userId: '', |
|
|
|
|
guestPrivacyAgree: false, |
|
|
|
|
|
|
|
|
|
first: true, |
|
|
|
|
// anyWhere: true,
|
|
|
|
|
anyWhere: false, |
|
|
|
|
|
|
|
|
|
userInfo: {}, |
|
|
|
|
}, |
|
|
|
|
onLaunch() { |
|
|
|
|
// if (options.path) {
|
|
|
|
|
// this.globalData.anyWhere = true;
|
|
|
|
|
// }
|
|
|
|
|
this.autoUpdate() |
|
|
|
|
|
|
|
|
|
Page = page as WechatMiniprogram.Page.Constructor |
|
|
|
|
|
|
|
|
|
wx.ajax = licia.curry(request)({ gUrl: this.globalData.url }) |
|
|
|
|
|
|
|
|
|
this.autoUpdate() |
|
|
|
|
|
|
|
|
|
wx.setInnerAudioOption({ |
|
|
|
|
obeyMuteSwitch: false, |
|
|
|
|
mixWithOther: false, |
|
|
|
|
}) |
|
|
|
|
wx.login({ |
|
|
|
|
success: (res) => { |
|
|
|
|
console.log('code',res) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
onShow(options) { |
|
|
|
|
if (options.query.scene) { |
|
|
|
|
this.globalData.anyWhere = false |
|
|
|
|
this.globalData.scene = parseScene(options.query.scene) as { workerId: string } |
|
|
|
|
} |
|
|
|
|
// this.startLogin()
|
|
|
|
|
this.startLogin() |
|
|
|
|
}, |
|
|
|
|
startLogin() { |
|
|
|
|
const that = this |
|
|
|
|
wx.login({ |
|
|
|
|
success(res) { |
|
|
|
|
success: (res) => { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '?r=zd/user/init-login', |
|
|
|
|
url: '?r=wtx/user/init-login', |
|
|
|
|
data: { |
|
|
|
|
code: res.code, |
|
|
|
|
}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
that.globalData.loginState = res.loginState |
|
|
|
|
that.globalData.isReg = res.isReg |
|
|
|
|
that.globalData.isLogin = res.isLogin |
|
|
|
|
that.globalData.loginType = res.loginType |
|
|
|
|
if (!Object.keys(that.globalData.scene)?.length) { |
|
|
|
|
that.globalData.anyWhere = res.anyWhere |
|
|
|
|
} |
|
|
|
|
if (wx.getLaunchOptionsSync()?.query?.activity === 'NRDL') { |
|
|
|
|
that.clickPush() |
|
|
|
|
} |
|
|
|
|
that.getUserInfo() |
|
|
|
|
this.globalData.loginState = res.loginState |
|
|
|
|
this.globalData.isReg = res.isReg |
|
|
|
|
this.globalData.isLogin = res.isLogin |
|
|
|
|
this.globalData.userId = res.userId |
|
|
|
|
this.globalData.guestPrivacyAgree = res.guestPrivacyAgree |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
waitLogin({ isReg = true, loginPage = false } = { isReg: true, loginPage: false }) { |
|
|
|
|
waitLogin() { |
|
|
|
|
let time: number |
|
|
|
|
const regFun = (resolve) => { |
|
|
|
|
if (this.verifySys()) { |
|
|
|
|
if (this.globalData.loginType === 1) { |
|
|
|
|
this.registrationVerification(() => resolve(), loginPage) |
|
|
|
|
} else { |
|
|
|
|
resolve() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const unRegFun = (resolve) => { |
|
|
|
|
if (!this.verifySys(isReg)) return |
|
|
|
|
resolve() |
|
|
|
|
} |
|
|
|
|
return new Promise((resolve: (value?) => void) => { |
|
|
|
|
if (isReg) { |
|
|
|
|
if (Object.keys(this.globalData.userInfo).length) { |
|
|
|
|
regFun(resolve) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
time = setInterval(() => { |
|
|
|
|
if (Object.keys(this.globalData.userInfo).length) { |
|
|
|
|
clearInterval(time) |
|
|
|
|
regFun(resolve) |
|
|
|
|
} |
|
|
|
|
}, 500) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
this.globalData.anyWhere = true |
|
|
|
|
if (this.globalData.loginState) { |
|
|
|
|
unRegFun(resolve) |
|
|
|
|
resolve() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
time = setInterval(() => { |
|
|
|
|
if (this.globalData.loginState) { |
|
|
|
|
clearInterval(time) |
|
|
|
|
unRegFun(resolve) |
|
|
|
|
resolve() |
|
|
|
|
} |
|
|
|
|
}, 500) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
registrationVerification(callback: () => void, loginPage = false) { |
|
|
|
|
// 1-空白用户,2-注册用户,3-疾病患者,4-用药患者
|
|
|
|
|
const { PatientId, AuditStatus, isFollow, UserType } = this.globalData.userInfo |
|
|
|
|
const { anyWhere, first } = this.globalData |
|
|
|
|
|
|
|
|
|
if (loginPage || (anyWhere && first)) { |
|
|
|
|
callback() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (UserType == 4) { |
|
|
|
|
this.globalData.first = false |
|
|
|
|
callback() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (UserType == 1) { |
|
|
|
|
this.globalData.registChannel = 0 |
|
|
|
|
this.globalData.first = false |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/login/index', |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let urlKey = '' |
|
|
|
|
if (!PatientId) { |
|
|
|
|
urlKey = 'enterInfo' |
|
|
|
|
} else if (AuditStatus == 0) { |
|
|
|
|
urlKey = 'noCert' |
|
|
|
|
} else if (AuditStatus == 1) { |
|
|
|
|
urlKey = isFollow ? 'nopending' : 'pending' |
|
|
|
|
} else if (AuditStatus == 2) { |
|
|
|
|
urlKey = 'reject' |
|
|
|
|
} |
|
|
|
|
let navUrl = { |
|
|
|
|
enterInfo: '/pages/enterInfo/index', |
|
|
|
|
noCert: '/pages/enterInfo/index', |
|
|
|
|
reject: '/pages/enterInfo/index', |
|
|
|
|
pending: '/pages/enterInfo/index', |
|
|
|
|
nopending: '/pages/enterInfo/index', |
|
|
|
|
}[urlKey] |
|
|
|
|
|
|
|
|
|
if (navUrl && first) { |
|
|
|
|
this.globalData.registChannel = 0 |
|
|
|
|
this.globalData.first = false |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: navUrl, |
|
|
|
|
}) |
|
|
|
|
this.globalData.first = false |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.globalData.first = false |
|
|
|
|
callback() |
|
|
|
|
}, |
|
|
|
|
verifySys() { |
|
|
|
|
// 1:患者 2:医生
|
|
|
|
|
const { loginType, isLogin, anyWhere } = this.globalData |
|
|
|
|
const pages = getCurrentPages() |
|
|
|
|
const currentPage = pages[pages.length - 1] |
|
|
|
|
const url = currentPage.route |
|
|
|
|
const options = currentPage.options |
|
|
|
|
const ignorePath = ['pages/start/index'] |
|
|
|
|
|
|
|
|
|
// 未登录用户
|
|
|
|
|
if (!isLogin) { |
|
|
|
|
// 医生端页面重定向到医生端登录页
|
|
|
|
|
if (url.includes('doctor/pages')) { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/doctor/pages/d_login/index', |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
// 患者端随便看看
|
|
|
|
|
if (anyWhere) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/login/index', |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
if (ignorePath.includes(url)) return true |
|
|
|
|
|
|
|
|
|
if (loginType === 1) { |
|
|
|
|
if (url.includes('doctor/pages')) { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/index/index', |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} else { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (loginType === 2) { |
|
|
|
|
if (url.includes('doctor/pages')) { |
|
|
|
|
return true |
|
|
|
|
} else { |
|
|
|
|
const params = Object.entries(options) |
|
|
|
|
.map(([key, value]) => `${key}=${value}`) |
|
|
|
|
.join('&') |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/doctor/pages/d_trans/index?path=' + encodeURIComponent(`/${url}?${params}`), |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
}, |
|
|
|
|
permissionVerification(grade = 1, registChannel = 0, backPage = null, regBusinessId = '') { |
|
|
|
|
// 1-空白用户,2-注册用户,3-疾病患者,4-用药患者
|
|
|
|
|
const { PatientId, AuditStatus, isFollow, UserType } = this.globalData.userInfo |
|
|
|
|
const that = this |
|
|
|
|
this.globalData.registChannel = registChannel |
|
|
|
|
this.globalData.regBusinessId = regBusinessId |
|
|
|
|
let isReject = false |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
if (grade == 2 && Number(UserType) < 2) { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/login/index', |
|
|
|
|
}) |
|
|
|
|
isReject = true |
|
|
|
|
} |
|
|
|
|
if (grade == 3 && Number(UserType) < 3) { |
|
|
|
|
if (UserType == 1) { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/login/index', |
|
|
|
|
}) |
|
|
|
|
isReject = true |
|
|
|
|
} |
|
|
|
|
if (UserType == 2) { |
|
|
|
|
let urlKey = '' |
|
|
|
|
if (!PatientId) { |
|
|
|
|
urlKey = 'enterInfo' |
|
|
|
|
} else if (AuditStatus == 0) { |
|
|
|
|
urlKey = 'noCert' |
|
|
|
|
} else if (AuditStatus == 1) { |
|
|
|
|
if (backPage && (backPage as string).includes('liveResult')) { |
|
|
|
|
urlKey = 'liveResult' |
|
|
|
|
} else { |
|
|
|
|
urlKey = isFollow ? 'nopending' : 'pending' |
|
|
|
|
} |
|
|
|
|
} else if (AuditStatus == 2) { |
|
|
|
|
urlKey = 'reject' |
|
|
|
|
} |
|
|
|
|
let navUrl = { |
|
|
|
|
enterInfo: '/pages/enterInfo/index', |
|
|
|
|
noCert: '/pages/enterInfo/index', |
|
|
|
|
reject: '/pages/enterInfo/index', |
|
|
|
|
pending: '/pages/enterInfo/index', |
|
|
|
|
nopending: '/pages/enterInfo/index', |
|
|
|
|
liveResult: backPage, |
|
|
|
|
}[urlKey] |
|
|
|
|
if (urlKey == 'liveResult') { |
|
|
|
|
wx.navigateTo({ |
|
|
|
|
url: navUrl as string, |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: navUrl as string, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
isReject = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (grade == 4 && Number(UserType) < 4) { |
|
|
|
|
wx.reLaunch({ |
|
|
|
|
url: '/pages/vipLogin/index', |
|
|
|
|
}) |
|
|
|
|
isReject = true |
|
|
|
|
} |
|
|
|
|
if (isReject) { |
|
|
|
|
that.globalData.backPage = backPage |
|
|
|
|
reject(null) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
resolve(null) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
getUserInfo(self, update = false, callback = (_userInfo) => {}) { |
|
|
|
|
if (this.globalData.userInfo?.UserId && !update) { |
|
|
|
|
self?.setData({ |
|
|
|
|
userInfo: this.globalData.userInfo, |
|
|
|
|
}) |
|
|
|
|
callback(this.globalData.userInfo) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '?r=zd/account/info', |
|
|
|
|
showMsg: false, |
|
|
|
|
}).then((res) => { |
|
|
|
|
res.UserType = res.UserType || 1 |
|
|
|
|
if (res.UserType > 2) { |
|
|
|
|
this.globalData.anyWhere = false |
|
|
|
|
} |
|
|
|
|
this.globalData.userInfo = res |
|
|
|
|
this.triggerListeners() |
|
|
|
|
self?.setData({ |
|
|
|
|
userInfo: res, |
|
|
|
|
}) |
|
|
|
|
const { doctorId, inviteChan } = this.globalData.scene |
|
|
|
|
if (doctorId && res.InviteDoctorId != doctorId && this.globalData.isLogin && res.PatientId) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '?r=zd/account/update-doctor', |
|
|
|
|
data: { |
|
|
|
|
inviteDoctorId: doctorId, |
|
|
|
|
inviteChannel: inviteChan, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
callback(res) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
mpBehavior(data: { PageName: string; doctor?: boolean }) { |
|
|
|
|
let url = '?r=zd/mp-behavior/add' |
|
|
|
|
if (data.doctor) { |
|
|
|
@ -377,117 +110,12 @@ App<IAppOption>({
@@ -377,117 +110,12 @@ App<IAppOption>({
|
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 更新用户信息
|
|
|
|
|
async updateUserInfo(encryptedData, iv) { |
|
|
|
|
let loginState = this.globalData.loginState |
|
|
|
|
const encodeEncryptedData = encodeURIComponent(encryptedData) |
|
|
|
|
const encodeIv = encodeURIComponent(iv) |
|
|
|
|
const { |
|
|
|
|
data: { code, msg }, |
|
|
|
|
} = await wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '?r=eyecare/user/update-wx-user-info', |
|
|
|
|
data: { |
|
|
|
|
loginState, |
|
|
|
|
encryptedData: encodeEncryptedData, |
|
|
|
|
iv: encodeIv, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
if (code !== 0) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
duration: 1500, |
|
|
|
|
title: msg, |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
return code |
|
|
|
|
}, |
|
|
|
|
getCode() { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
wx.login({ |
|
|
|
|
success: (res) => { |
|
|
|
|
resolve(res.code) |
|
|
|
|
}, |
|
|
|
|
fail: () => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
duration: 10000, |
|
|
|
|
title: '发生错误请重试', |
|
|
|
|
icon: 'none', |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
// 微信登录
|
|
|
|
|
doLogin() { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
wx.showLoading({ |
|
|
|
|
title: '加载中...', |
|
|
|
|
mask: true, |
|
|
|
|
}) |
|
|
|
|
this.getCode().then((code) => { |
|
|
|
|
wx.ajax({ |
|
|
|
|
url: '?r=eyecare/user/init-login', |
|
|
|
|
data: { |
|
|
|
|
code, |
|
|
|
|
}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
if (res.data.code === 0) { |
|
|
|
|
resolve(res) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
clickPush() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: 'POST', |
|
|
|
|
url: '?r=zd/nrdl/add-push-click-record', |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
watch: function (key, method) { |
|
|
|
|
var obj = this.globalData |
|
|
|
|
//加个前缀生成隐藏变量,防止死循环发生
|
|
|
|
|
let ori = obj[key] //obj[key]这个不能放在Object.defineProperty里
|
|
|
|
|
if (ori) { |
|
|
|
|
//处理已经声明的变量,绑定处理
|
|
|
|
|
method(ori) |
|
|
|
|
} |
|
|
|
|
Object.defineProperty(obj, key, { |
|
|
|
|
configurable: true, |
|
|
|
|
enumerable: true, |
|
|
|
|
set: function (value) { |
|
|
|
|
this['_' + key] = value |
|
|
|
|
console.log('是否会被执行2') |
|
|
|
|
method(value) |
|
|
|
|
}, |
|
|
|
|
get: function () { |
|
|
|
|
// 在其它界面调用key值的时候,这里就会执行。
|
|
|
|
|
if (typeof this['_' + key] == 'undefined') { |
|
|
|
|
if (ori) { |
|
|
|
|
//这里读取数据的时候隐藏变量和 globalData设置不一样,所以要做同步处理
|
|
|
|
|
this['_' + key] = ori |
|
|
|
|
return ori |
|
|
|
|
} else { |
|
|
|
|
return undefined |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return this['_' + key] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
getUserInfo() { |
|
|
|
|
return wx.ajax({ |
|
|
|
|
method: 'GET', |
|
|
|
|
url: '?r=wtx/user/userinfo', |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
// 注册监听器函数的方法
|
|
|
|
|
registerListener: function (listener: () => {}) { |
|
|
|
|
this.globalData.listeners.push(listener) |
|
|
|
|
}, |
|
|
|
|
// 触发监听器函数的方法
|
|
|
|
|
triggerListeners: function () { |
|
|
|
|
var listeners = this.globalData.listeners |
|
|
|
|
for (var i = 0; i < listeners.length; i++) { |
|
|
|
|
listeners[i]() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
autoUpdate: function () { |
|
|
|
|
var self = this |
|
|
|
|
// 获取小程序更新机制兼容
|
|
|
|
@ -547,25 +175,4 @@ App<IAppOption>({
@@ -547,25 +175,4 @@ App<IAppOption>({
|
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
getTheme() { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
const checkUserType = () => { |
|
|
|
|
const userInfo = this.globalData.userInfo |
|
|
|
|
if (userInfo.UserType) { |
|
|
|
|
// resolve(userInfo.UserType >= 4 ? 'DRUG' : 'PATIENT')
|
|
|
|
|
resolve('PATIENT') |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const tryResolve = () => { |
|
|
|
|
if (!checkUserType()) { |
|
|
|
|
setTimeout(tryResolve, 30) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tryResolve() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|