You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
633 lines
17 KiB
633 lines
17 KiB
/* eslint-disable */ |
|
// app.ts |
|
import { request } from './api/request' |
|
import { parseScene } from './utils/util' |
|
const licia = require('miniprogram-licia') |
|
|
|
const dayjs = require('dayjs') |
|
require('/utils/dayjs/day-zh-cn.js') |
|
const relativeTime = require('/utils/dayjs/relativeTime.js') |
|
dayjs.locale('zh-cn') // 全局使用 |
|
dayjs.extend(relativeTime) |
|
|
|
// page |
|
import page from '@/utils/page' |
|
|
|
App<IAppOption>({ |
|
globalData: { |
|
// dev |
|
// appid:wxc3cdb3c4d4f62cea |
|
url: 'https://m.igg4.hbraas.com', |
|
upFileUrl: 'https://m.igg4.hbraas.com/', |
|
imageUrl: 'https://m.igg4.hbraas.com/igg4/', |
|
|
|
// appid:wx9404bbbdaf52c276 |
|
// url: 'https://m.zd.hbraas.com', |
|
// upFileUrl: 'https://m.zd.hbraas.com/', |
|
// imageUrl: 'https://m.zd.hbraas.com/zd/', |
|
|
|
// pro |
|
// appid:wx96f45ca4f1fa36ec |
|
// url: 'https://m.igg4.hbsaas.com', |
|
// upFileUrl: 'https://m.igg4.hbsaas.com/', |
|
// imageUrl: 'https://m.igg4.hbsaas.com/igg4/', |
|
//login |
|
registrationSource: 0, |
|
registChannel: 0, |
|
regBusinessId: '', |
|
IsAliQiWei: 0, |
|
|
|
scene: {}, |
|
listeners: [], |
|
|
|
Timestamp: new Date().getTime(), |
|
loginState: '', |
|
isLogin: 0, // 0 未登录 1 已登录 |
|
isReg: '0', |
|
WorkerId: '', |
|
loginType: '', // 1:患者 2:医生 |
|
|
|
first: true, |
|
anyWhere: false, |
|
|
|
doctorUnReadCount: 0, |
|
|
|
userInfo: {}, |
|
DiagnoseType: [ |
|
{ |
|
id: 1, |
|
name: 'Ⅰ型 眼肌无力,可伴闭眼无力,其它肌群肌力正常', |
|
}, |
|
{ |
|
id: 2, |
|
name: 'Ⅱa 型 主要累及四肢肌或(和)躯干肌,可有较轻的咽喉肌受累', |
|
}, |
|
{ |
|
id: 3, |
|
name: 'Ⅱb 型 主要累及咽喉肌或(和)呼吸肌,可有轻度或相同的四肢肌或(和)躯干肌受累', |
|
}, |
|
{ |
|
id: 4, |
|
name: 'Ⅲa 型 主要累及四肢肌或(和)躯干肌,可有较轻的咽喉肌受累', |
|
}, |
|
{ |
|
id: 5, |
|
name: 'Ⅲb 型 主要累及咽喉肌或(和)呼吸肌,可有轻度或相同的四肢肌或(和)躯干肌受累', |
|
}, |
|
{ |
|
id: 6, |
|
name: 'Ⅳa 型 主要累及四肢肌或(和)躯干肌受累,可有较轻的咽喉肌受累', |
|
}, |
|
{ |
|
id: 7, |
|
name: 'Ⅳb 型 主要累及咽喉肌或(和)呼吸肌,可有轻度或相同的四肢肌或(和)躯干肌受累', |
|
}, |
|
{ |
|
id: 8, |
|
name: 'Ⅴ型 气管插管,伴或不伴机械通气(除外术后常规使用);仅鼻饲而不进行气管插管的病例为Ⅳb 型', |
|
}, |
|
{ |
|
id: 9, |
|
name: '其它', |
|
}, |
|
], |
|
storyStatus: { |
|
1: '已提交待审核', |
|
2: '审核未通过', |
|
3: '审核通过待校正', |
|
4: '校正完成', |
|
5: '已发布', |
|
100: '审核未通过', |
|
}, |
|
liveStatus: { |
|
1: '待开始', |
|
2: '会议中', |
|
3: '已结束', |
|
99: '取消', |
|
100: '已删除', |
|
}, |
|
activityStatus: { |
|
1: '待开始', |
|
2: '进行中', |
|
3: '已结束', |
|
99: '取消', |
|
100: '已删除', |
|
}, |
|
}, |
|
onLaunch() { |
|
// if (options.path) { |
|
// this.globalData.anyWhere = true; |
|
// } |
|
Page = page as WechatMiniprogram.Page.Constructor |
|
|
|
wx.ajax = licia.curry(request)({ gUrl: this.globalData.url }) |
|
|
|
this.autoUpdate() |
|
|
|
wx.setInnerAudioOption({ |
|
obeyMuteSwitch: false, |
|
mixWithOther: false, |
|
}) |
|
}, |
|
onShow(options) { |
|
if (options.query.scene) { |
|
this.globalData.anyWhere = false |
|
this.globalData.scene = parseScene(options.query.scene) as { workerId: string } |
|
} |
|
this.startLogin() |
|
}, |
|
startLogin(): Promise<void> { |
|
const that = this |
|
return new Promise((resolve) => { |
|
wx.login({ |
|
success(res) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/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 |
|
} |
|
that.getUserInfo(null, true, () => { |
|
resolve() |
|
}) |
|
}) |
|
}, |
|
}) |
|
}) |
|
}, |
|
waitLogin({ isReg = true, loginPage = false, pub = false } = { isReg: true, loginPage: false, pub: false }) { |
|
let time: number |
|
const regFun = (resolve) => { |
|
if (this.verifySys(pub)) { |
|
if (this.globalData.loginType === 1) { |
|
this.registrationVerification(() => resolve(), loginPage) |
|
} else { |
|
resolve() |
|
} |
|
} |
|
} |
|
const unRegFun = (resolve) => { |
|
if (!this.verifySys(pub)) 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) |
|
return |
|
} |
|
time = setInterval(() => { |
|
if (this.globalData.loginState) { |
|
clearInterval(time) |
|
unRegFun(resolve) |
|
} |
|
}, 500) |
|
}) |
|
}, |
|
registrationVerification(callback: () => void, loginPage = false) { |
|
// 1-空白用户,2-注册用户,3-疾病患者,4-用药患者 |
|
const { PatientId, 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 |
|
} |
|
|
|
// UserType == 2: 已注册用户,无需审核直接成为疾病患者 |
|
if (!PatientId) { |
|
const navUrl = '/pages/enterInfo/index' |
|
if (first) { |
|
this.globalData.registChannel = 0 |
|
this.globalData.first = false |
|
wx.reLaunch({ |
|
url: navUrl, |
|
}) |
|
return |
|
} |
|
} |
|
|
|
this.globalData.first = false |
|
callback() |
|
}, |
|
verifySys(pub = false) { |
|
// 1:患者 2:医生 |
|
const { loginType, isLogin, anyWhere } = this.globalData |
|
console.log("DEBUGPRINT[229]: app.ts:246: loginType=", loginType) |
|
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 && !pub) { |
|
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 { 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) { |
|
// 已注册用户无需审核,直接引导完善信息 |
|
const navUrl = '/pages/enterInfo/index' |
|
wx.reLaunch({ |
|
url: navUrl, |
|
}) |
|
isReject = true |
|
} |
|
} |
|
if (grade == 4 && Number(UserType) < 4) { |
|
wx.reLaunch({ |
|
url: '/gift/pages/vipCert/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=igg4/account/info', |
|
showMsg: false, |
|
}).then(async (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, recDoctorId: recommendDoctorId } = this.globalData.scene |
|
if ( |
|
doctorId && |
|
res.InviteDoctorId != doctorId && |
|
this.globalData.isLogin && |
|
res.PatientId && |
|
!recommendDoctorId |
|
) { |
|
await wx.ajax({ |
|
method: 'POST', |
|
url: '?r=igg4/account/update-doctor', |
|
data: { |
|
inviteDoctorId: doctorId, |
|
inviteChannel: 1, |
|
}, |
|
}) |
|
this.globalData.scene.doctorId = '' |
|
const updatedRes = await wx.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/account/info', |
|
showMsg: false, |
|
}) |
|
updatedRes.UserType = updatedRes.UserType || 1 |
|
this.globalData.userInfo = updatedRes |
|
this.triggerListeners() |
|
self?.setData({ |
|
userInfo: updatedRes, |
|
}) |
|
res = updatedRes |
|
} |
|
if (recommendDoctorId && doctorId) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=igg4/doctor-recommend/add-record', |
|
data: { |
|
recommendDoctorId: doctorId, |
|
beRecommendDoctorId: recommendDoctorId, |
|
}, |
|
}) |
|
this.globalData.scene.recDoctorId = '' |
|
this.globalData.scene.doctorId = '' |
|
} |
|
callback(res) |
|
}) |
|
}, |
|
mpBehavior(data: { PageName: string; doctor?: boolean }) { |
|
// let url = '?r=igg4/mp-behavior/add' |
|
// if (data.doctor) { |
|
// url = '?r=igg4/doctor/mp-behavior/add' |
|
// } |
|
// delete data.doctor |
|
// wx.ajax({ |
|
// method: 'POST', |
|
// url, |
|
// data: data, |
|
// loading: false, |
|
// showMsg: false, |
|
// }).then((res) => { |
|
// console.log('res: ', res) |
|
// }) |
|
}, |
|
|
|
// 更新用户信息 |
|
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) |
|
} |
|
}) |
|
}) |
|
}) |
|
}, |
|
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] |
|
} |
|
}, |
|
}) |
|
}, |
|
// 注册监听器函数的方法 |
|
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 |
|
// 获取小程序更新机制兼容 |
|
if (wx.canIUse('getUpdateManager')) { |
|
const updateManager = wx.getUpdateManager() |
|
//1. 检查小程序是否有新版本发布 |
|
updateManager.onCheckForUpdate(function (res) { |
|
// 请求完新版本信息的回调 |
|
if (res.hasUpdate) { |
|
//检测到新版本,需要更新,给出提示 |
|
wx.showModal({ |
|
title: '更新提示', |
|
content: '检测到新版本,是否下载新版本并重启小程序?', |
|
success: function (res) { |
|
if (res.confirm) { |
|
//2. 用户确定下载更新小程序,小程序下载及更新静默进行 |
|
self.downLoadAndUpdate(updateManager) |
|
} else if (res.cancel) { |
|
//用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了 |
|
wx.showModal({ |
|
title: '温馨提示~', |
|
content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~', |
|
showCancel: false, //隐藏取消按钮 |
|
confirmText: '确定更新', //只保留确定更新按钮 |
|
success: function (res) { |
|
if (res.confirm) { |
|
//下载新版本,并重新应用 |
|
self.downLoadAndUpdate(updateManager) |
|
} |
|
}, |
|
}) |
|
} |
|
}, |
|
}) |
|
} |
|
}) |
|
} else { |
|
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示 |
|
wx.showModal({ |
|
title: '提示', |
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。', |
|
}) |
|
} |
|
}, |
|
downLoadAndUpdate: function (updateManager) { |
|
//静默下载更新小程序新版本 |
|
updateManager.onUpdateReady(function () { |
|
wx.hideLoading() |
|
//新的版本已经下载好,调用 applyUpdate 应用新版本并重启 |
|
updateManager.applyUpdate() |
|
}) |
|
updateManager.onUpdateFailed(function () { |
|
// 新的版本下载失败 |
|
wx.showModal({ |
|
title: '新版本更新失败', |
|
content: '您可删除当前小程序,重新打开尝试', |
|
}) |
|
}) |
|
}, |
|
setTabbarNoticeMessage() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=igg4/doctor/message-interact/get-unread-count', |
|
data: {}, |
|
}).then((res: any) => { |
|
this.globalData.doctorUnReadCount = res || 0 |
|
const pages = getCurrentPages() |
|
const currentPage = pages[pages.length - 1] |
|
if (currentPage) { |
|
const tabbar = (currentPage as any).selectComponent('#doctor-tabbar') |
|
if (tabbar) { |
|
tabbar.setData({ unReadCount: this.globalData.doctorUnReadCount }) |
|
} |
|
} |
|
}) |
|
}, |
|
getTheme() { |
|
return new Promise((resolve) => { |
|
const checkUserType = () => { |
|
const userInfo = this.globalData.userInfo |
|
if (userInfo.UserType) { |
|
resolve(userInfo.UserType >= 4 ? 'DRUG' : 'PATIENT') |
|
return true |
|
} |
|
return false |
|
} |
|
|
|
const tryResolve = () => { |
|
if (!checkUserType()) { |
|
setTimeout(tryResolve, 30) |
|
} |
|
} |
|
|
|
tryResolve() |
|
}) |
|
}, |
|
})
|
|
|