|
|
|
|
/* eslint-disable */
|
|
|
|
|
// app.ts
|
|
|
|
|
import { request } from './api/request'
|
|
|
|
|
import { parseScene } from './utils/util'
|
|
|
|
|
const licia = require('miniprogram-licia')
|
|
|
|
|
|
|
|
|
|
import plugin from './components/calendar/plugins/index'
|
|
|
|
|
import selectable from './components/calendar/plugins/selectable'
|
|
|
|
|
import solarLunar from './components/calendar/plugins/solarLunar/index'
|
|
|
|
|
import todo from './components/calendar/plugins/todo'
|
|
|
|
|
import week from './components/calendar/plugins/week.js'
|
|
|
|
|
|
|
|
|
|
plugin.use(todo).use(solarLunar).use(selectable).use(week)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
import page from '@/utils/page'
|
|
|
|
|
|
|
|
|
|
App<IAppOption>({
|
|
|
|
|
globalData: {
|
|
|
|
|
// dev
|
|
|
|
|
// appid:wxe9f978b29ff5ab5d
|
|
|
|
|
url: 'https://app.yd.hbraas.com',
|
|
|
|
|
upFileUrl: 'https://app.yd.hbraas.com/',
|
|
|
|
|
imageUrl: 'https://app.yd.hbraas.com/images/',
|
|
|
|
|
|
|
|
|
|
// pro
|
|
|
|
|
// appid:wxfc95e2961d481f58
|
|
|
|
|
// url: 'https://app.yd.hbsaas.com',
|
|
|
|
|
// upFileUrl: 'https://app.yd.hbsaas.com/',
|
|
|
|
|
// imageUrl: 'https://app.yd.hbsaas.com/images/',
|
|
|
|
|
|
|
|
|
|
Timestamp: new Date().getTime(),
|
|
|
|
|
|
|
|
|
|
waitBindDoctorId: '',
|
|
|
|
|
scene: {},
|
|
|
|
|
|
|
|
|
|
loginState: '',
|
|
|
|
|
initLoginInfo: {},
|
|
|
|
|
|
|
|
|
|
anyWhere: false,
|
|
|
|
|
|
|
|
|
|
userInfo: {},
|
|
|
|
|
},
|
|
|
|
|
onLaunch() {
|
|
|
|
|
this.autoUpdate()
|
|
|
|
|
|
|
|
|
|
Page = page as WechatMiniprogram.Page.Constructor
|
|
|
|
|
|
|
|
|
|
wx.ajax = licia.curry(request)({ gUrl: this.globalData.url })
|
|
|
|
|
|
|
|
|
|
wx.setInnerAudioOption({
|
|
|
|
|
obeyMuteSwitch: false,
|
|
|
|
|
mixWithOther: false,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onShow(options) {
|
|
|
|
|
if (options.query.scene) {
|
|
|
|
|
this.globalData.scene = parseScene(options.query.scene) as { workerId: string }
|
|
|
|
|
}
|
|
|
|
|
this.startLogin()
|
|
|
|
|
},
|
|
|
|
|
startLogin(callback?: () => void) {
|
|
|
|
|
wx.login({
|
|
|
|
|
success: (res) => {
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '/app/common/common/wx-login',
|
|
|
|
|
data: {
|
|
|
|
|
code: res.code,
|
|
|
|
|
},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.globalData.loginState = res.token || res.sessionKey
|
|
|
|
|
this.globalData.initLoginInfo = res
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
updateLoginInfo(callback?: () => void) {
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '/app/common/common/user-info',
|
|
|
|
|
data: {},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.globalData.initLoginInfo = res
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
waitLogin({ types = [] as number[] } = {}) {
|
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
const checkLogin = () => {
|
|
|
|
|
if (this.globalData.loginState) {
|
|
|
|
|
if (this.checkLoginTypes(types)) {
|
|
|
|
|
resolve()
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
checkLogin()
|
|
|
|
|
}, 500)
|
|
|
|
|
}
|
|
|
|
|
checkLogin()
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
checkLoginTypes(types: number[]) {
|
|
|
|
|
const { loginIdentity, isRegistered } = this.globalData.initLoginInfo
|
|
|
|
|
|
|
|
|
|
if (!types || types.length === 0) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isRegistered) {
|
|
|
|
|
if (types.includes(1)) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
wx.reLaunch({
|
|
|
|
|
url: '/pages/index/index',
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (loginIdentity && !types.includes(loginIdentity)) {
|
|
|
|
|
const typePageUrl = {
|
|
|
|
|
2: '/pages/index/index',
|
|
|
|
|
3: '/ground/pages/home/index',
|
|
|
|
|
4: '/doctor/pages/home/index',
|
|
|
|
|
}[loginIdentity as 2 | 3 | 4]
|
|
|
|
|
if (typePageUrl) {
|
|
|
|
|
wx.reLaunch({
|
|
|
|
|
url: typePageUrl,
|
|
|
|
|
})
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
},
|
|
|
|
|
mpBehavior(data: { PageName: string }) {
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '/app/common/common/log',
|
|
|
|
|
data: {
|
|
|
|
|
eventType: 'page_view',
|
|
|
|
|
eventName: data.PageName,
|
|
|
|
|
pagePath: data.PageName,
|
|
|
|
|
params: {},
|
|
|
|
|
},
|
|
|
|
|
loading: false,
|
|
|
|
|
showMsg: false,
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
console.log('res: ', res)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUserInfo() {
|
|
|
|
|
return wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '/app/common/common/user-info',
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
autoUpdate: function () {
|
|
|
|
|
var self = this
|
|
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
|
|
const updateManager = wx.getUpdateManager()
|
|
|
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '更新提示',
|
|
|
|
|
content: '检测到新版本,是否下载新版本并重启小程序?',
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
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()
|
|
|
|
|
updateManager.applyUpdate()
|
|
|
|
|
})
|
|
|
|
|
updateManager.onUpdateFailed(function () {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '新版本更新失败',
|
|
|
|
|
content: '您可删除当前小程序,重新打开尝试',
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|