信达小程序
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.

136 lines
3.1 KiB

5 months ago
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<IAppOption>({
globalData: {
// 测试号 wx2b0bb13edf717c1d
// dev
5 months ago
// appid:wxf9ce8010f1ad24aa
url: 'https://m.xd.hbraas.com',
upFileUrl: 'https://m.xd.hbraas.com/',
imageUrl: 'https://m.xd.hbraas.com/xd/',
5 months ago
5 months ago
// pro
4 months ago
// appid:wx71ac9c27c3c3e3f4
// url: 'https://m.xd.hbsaas.com',
// upFileUrl: 'https://m.xd.hbsaas.com/',
// imageUrl: 'https://m.xd.hbsaas.com/api/xd/',
5 months ago
loginState: '',
isLogin: 0,
5 months ago
loginType: 0,
5 months ago
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) => {
5 months ago
wx.ajax({
method: 'GET',
url: '?r=xd/user/init-login',
data: {
code: res.code,
},
5 months ago
}).then((res: any) => {
5 months ago
this.globalData.loginState = res.loginState;
5 months ago
this.globalData.isLogin = res.isLogin;
this.globalData.loginType = res.loginType;
5 months ago
});
5 months ago
},
});
wx.setInnerAudioOption({
obeyMuteSwitch: false,
mixWithOther: false,
});
},
onShow(options) {
if (options.query.scene) {
this.globalData.scene = parseScene(options.query.scene);
}
},
5 months ago
waitLogin({ type = 0 } = { type: 'any' }) {
5 months ago
return new Promise((resolve) => {
5 months ago
const checkLogin = () => {
if (this.globalData.loginState) {
if (this.checkLoginType(type)) {
resolve();
5 months ago
}
5 months ago
return;
5 months ago
}
5 months ago
setTimeout(() => {
checkLogin();
}, 500);
};
checkLogin();
5 months ago
});
},
5 months ago
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;
}
5 months ago
if (loginType !== 2) {
5 months ago
wx.reLaunch({
5 months ago
url: '/pages/login/index',
5 months ago
});
4 months ago
return false;
5 months ago
}
return true;
},
getUserInfo(type: 0 | 1 | 2): Promise<never> {
const url = {
2: '?r=xd/doctor/index/get-doctor',
}[type];
return wx.ajax({
5 months ago
method: 'GET',
5 months ago
url,
5 months ago
data: {},
5 months ago
}) as Promise<never>;
},
mpBehavior(data) {
wx.ajax({
method: 'POST',
url: '?r=xd/doctor/index/operate-action-submit',
data,
5 months ago
loading: false,
showMsg: false,
5 months ago
});
},
getMenuInfo(self) {
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
self.setData({
menuButtonInfo,
});
},
});