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'; const dayjs = require('dayjs'); const licia = require('miniprogram-licia'); 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, loginType: 0, scene: null, backPath: '', }, onLaunch() { Page = page as WechatMiniprogram.Page.Constructor; Component = component as WechatMiniprogram.Component.Constructor; wx.ajax = licia.curry(request)({ gUrl: this.globalData.url }); wx.login({ success: (res) => { console.log(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.loginType = res.loginType; }); }, }); wx.setInnerAudioOption({ obeyMuteSwitch: false, mixWithOther: false, }); }, onShow(options) { if (options.query.scene) { this.globalData.scene = parseScene(options.query.scene); } }, waitLogin({ type = 0 } = { type: 'any' }) { return new Promise((resolve) => { const checkLogin = () => { if (this.globalData.loginState) { if (this.checkLoginType(type)) { resolve(); } return; } setTimeout(() => { checkLogin(); }, 500); }; checkLogin(); }); }, checkLoginType(type: 0 | 1 | 2 | 'any') { const { loginType, isLogin } = this.globalData; if (type === 'any') { return true; } if (isLogin !== 1) { if (type === 0) { return true; } wx.reLaunch({ url: '/pages/login/index', }); return false; } if (loginType !== 2) { wx.reLaunch({ url: '/pages/login/index', }); 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) { wx.ajax({ method: 'POST', url: '?r=xd/doctor/index/operate-action-submit', data: data, loading: false, showMsg: false, }); }, getMenuInfo(self) { const menuButtonInfo = wx.getMenuButtonBoundingClientRect(); self.setData({ menuButtonInfo, }); }, });