import dayjs from 'dayjs' import licia from 'miniprogram-licia' import component from '@/utils/component' import relativeTime from '@/utils/dayjs/relativeTime.js' import page from '@/utils/page' import { request } from '@/utils/request' import { parseScene } from './utils/util' require('/utils/dayjs/day-zh-cn.js') dayjs.locale('zh-cn') // 全局使用 dayjs.extend(relativeTime) App({ globalData: { // 测试号 wx2b0bb13edf717c1d // dev // appid:wxf9ce8010f1ad24aa // url: 'https://m.xd.hbraas.com', // upFileUrl: 'https://m.xd.hbraas.com/', // imageUrl: 'https://m.xd.hbraas.com/xd/', // pro // appid:wx71ac9c27c3c3e3f4 url: 'https://m.xd.hbsaas.com', upFileUrl: 'https://m.xd.hbsaas.com/', imageUrl: 'https://m.xd.hbsaas.com/api/xd/', loginState: '', isLogin: 0, isNewReg: 0, loginType: 0, anyWhere: false, scene: {}, backPath: '', zdUserInfo: {}, 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: '已删除', }, liveSubscribe: { sub: false, tmplIds: [], }, }, onLaunch() { Page = page as WechatMiniprogram.Page.Constructor Component = component as WechatMiniprogram.Component.Constructor wx.ajax = licia.curry(request)({ gUrl: this.globalData.url }) this.startLogin() wx.setInnerAudioOption({ obeyMuteSwitch: false, mixWithOther: false, }) }, onShow(options) { if (options.query.scene) { this.globalData.scene = parseScene(options.query.scene) } else if (options.query.proMethodId) { this.globalData.scene.proMethodId = options.query.proMethodId } }, startLogin(callback) { wx.login({ success: (res) => { wx.ajax({ method: 'GET', url: '?r=xd/user/init-login', data: { code: res.code, }, }).then((res: any) => { this.globalData.loginState = res.loginState this.globalData.isLogin = res.isLogin this.globalData.isNewReg = res.isNewReg this.globalData.loginType = res.loginType if (callback) { callback() } }) }, }) }, updateLoginInfo(callback?: (any) => void) { wx.ajax({ method: 'GET', url: '?r=xd/user/get-account-info', data: {}, }).then((res) => { this.globalData.isLogin = res.isLogin this.globalData.loginType = res.loginType this.globalData.isNewReg = res.isNewReg if (callback) { callback(res) } }) }, waitLogin({ type = [0] } = { type: 'any' }) { return new Promise((resolve) => { const checkLogin = () => { if (this.globalData.loginState) { if (this.checkLoginType(type as pageType[] | 'any')) { resolve() } return } setTimeout(() => { checkLogin() }, 500) } checkLogin() }) }, checkLoginType(type, backPath = '') { const { loginType, isLogin, isNewReg } = this.globalData if (backPath) { this.globalData.backPath = backPath } if (type === 'any') { return true } if (isLogin !== 1) { if (type.includes(0) && [0, 1, 2].includes(loginType)) { return true } if ([0, 1].includes(loginType)) { wx.reLaunch({ url: '/patient/pages/login/index', }) return false } if (loginType === 2) { wx.reLaunch({ url: '/pages/login/index', }) return false } return false } if (isNewReg !== 1) { const typePageUrl = { 1: '/patient/pages/enterInfo/index', 2: '/pages/login/index', }[loginType as 1 | 2] wx.reLaunch({ url: typePageUrl, fail(err) { console.log(err) }, }) return false } if (!type.includes(loginType)) { const typePageUrl = { 1: '/patient/pages/index/index', 2: '/pages/home/index', }[loginType as 1 | 2] wx.reLaunch({ url: typePageUrl, }) return false } return true }, getUserInfo(type: 0 | 1 | 2): Promise { const url = { 2: '?r=xd/doctor/index/get-doctor', }[type] return wx.ajax({ method: 'GET', url, data: {}, }) as Promise }, mpBehavior(data: { doctor?: boolean, PageName: string }) { let url = '?r=zd/mp-behavior/add' if (data.doctor) { url = '?r=zd/doctor/mp-behavior/add' delete data.doctor } wx.ajax({ method: 'POST', url, data, loading: false, showMsg: false, }).then((res) => { console.log('res: ', res) }) }, oldMpBehavior(data) { wx.ajax({ method: 'POST', url: '?r=xd/doctor/index/operate-action-submit', data, loading: false, showMsg: false, }) }, getMenuInfo(self) { const menuButtonInfo = wx.getMenuButtonBoundingClientRect() self.setData({ menuButtonInfo, }) }, // zd相关函数 zdMpBehavior(data: { PageName: string, doctor?: boolean }) { const { loginType } = this.globalData if (loginType === 0) return let url = '?r=zd/mp-behavior/add' if (data.doctor) { url = '?r=zd/doctor/mp-behavior/add' } delete data.doctor wx.ajax({ method: 'POST', url, data, loading: false, showMsg: false, }).then((res) => { console.log('res: ', res) }) }, zdGetTheme() { return new Promise((resolve) => { resolve('PATIENT') }) }, zdWaitLogin({ isReg = true, loginPage = false, pub = false } = { isReg: true, loginPage: false, pub: false }) { let time: number const regFun = (resolve) => { if (this.zdVerifySys(pub)) { if (this.globalData.loginType === 1) { this.zdRegistrationVerification(() => resolve(), loginPage) } else { resolve() } } } const unRegFun = (resolve) => { if (!this.zdVerifySys(pub)) return resolve() } return new Promise((resolve: (value?) => void) => { if (isReg) { if (Object.keys(this.globalData.zdUserInfo).length) { regFun(resolve) return } time = setInterval(() => { if (Object.keys(this.globalData.zdUserInfo).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) }) }, zdRegistrationVerification(callback: () => void, loginPage = false) { // 1-空白用户,2-注册用户,3-疾病患者,4-用药患者 const { PatientId, AuditStatus, isFollow, UserType } = this.globalData.zdUserInfo 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: '/patient/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' } const navUrl = { enterInfo: '/patient/pages/enterInfo/index', noCert: '/patient/pages/enterInfo/index', reject: '/patient/pages/enterInfo/index', pending: '/patient/pages/enterInfo/index', nopending: '/patient/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() }, zdVerifySys(pub = false) { // 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: '/patient/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 }, zdPermissionVerification(grade = 1, registChannel = 0, backPage = null, regBusinessId = '') { const { isLogin, isNewReg } = this.globalData const that = this this.globalData.registChannel = registChannel this.globalData.regBusinessId = regBusinessId let isReject = false return new Promise((resolve, reject) => { if (grade > 1) { if (!isLogin) { wx.reLaunch({ url: '/patient/pages/login/index', }) isReject = true } else if (!isNewReg) { wx.reLaunch({ url: '/patient/pages/enterInfo/index', }) isReject = true } } if (isReject) { that.globalData.backPage = backPage reject(new Error('非登录用户拦截')) return } resolve(null) }) }, getZdUserInfo(self, update = false, callback = (_zdUserInfo) => {}) { if (this.globalData.zdUserInfo?.UserId && !update) { self?.setData({ zdUserInfo: this.globalData.zdUserInfo, }) callback(this.globalData.zdUserInfo) 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.zdUserInfo = res self?.setData({ zdUserInfo: res, }) const { doctorId, inviteChan, proMethodId } = 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, }, }).then(() => { this.globalData.scene = {} this.getZdUserInfo(self, update, callback) }) } if (proMethodId) { wx.ajax({ method: 'POST', url: '?r=zd/account/set-user-promotion-method', showMsg: false, data: { promotionMethodId: proMethodId, }, }) } callback(res) }) }, })