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.

225 lines
5.8 KiB

1 month ago
/* 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')
1 month ago
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/',
1 month ago
// pro
// appid:wxfc95e2961d481f58
2 weeks ago
// url: 'https://app.yd.hbsaas.com',
// upFileUrl: 'https://app.yd.hbsaas.com/',
// imageUrl: 'https://app.yd.hbsaas.com/images/',
1 month ago
Timestamp: new Date().getTime(),
waitBindDoctorId: '',
scene: {},
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()
1 month ago
},
startLogin(callback?: () => void) {
wx.login({
success: (res) => {
wx.ajax({
method: 'POST',
url: '/app/common/common/wx-login',
1 month ago
data: {
code: res.code,
},
needToken: false, // 登录接口不需要 token
1 month ago
}).then((res) => {
this.globalData.initLoginInfo = res
if (callback) {
callback()
}
})
},
})
},
updateLoginInfo(callback?: () => void) {
wx.ajax({
method: 'GET',
url: '/app/common/common/user-info',
1 month ago
data: {},
}).then((res) => {
this.globalData.initLoginInfo = res
if (callback) {
callback()
}
})
},
waitLogin({ types = [] as number[] } = {}) {
1 month ago
return new Promise((resolve) => {
const checkLogin = () => {
if (Object.keys(this.globalData.initLoginInfo).length > 0) {
if (this.checkLoginTypes(types)) {
1 month ago
resolve()
}
return
}
setTimeout(() => {
checkLogin()
}, 500)
}
checkLogin()
})
},
checkLoginTypes(types: number[]) {
console.log('types: ', types)
const { loginIdentity, isLogin } = this.globalData.initLoginInfo
1 month ago
if (!types || types.length === 0) {
1 month ago
return true
}
if (types.includes(loginIdentity) && loginIdentity === 1) {
return true
}
if (!isLogin) {
const typeRegPageUrl = {
2: '/pages/register/index',
3: '/ground/pages/register/index',
4: '/doctor/pages/register/index',
}[loginIdentity as 2 | 3 | 4]
1 month ago
wx.reLaunch({
url: typeRegPageUrl || '/pages/statr/index',
1 month ago
})
return false
}
if (loginIdentity && !types.includes(loginIdentity)) {
1 month ago
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
}
1 month ago
}
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: {},
},
1 month ago
loading: false,
showMsg: false,
}).then((res) => {
console.log('res: ', res)
})
},
getUserInfo() {
1 month ago
return wx.ajax({
method: 'GET',
url: '/app/common/common/user-info',
1 month ago
})
},
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: '确定更新',
1 month ago
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: '您可删除当前小程序,重新打开尝试',
})
})
},
})