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

433 lines
11 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
4 months ago
// 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
4 months ago
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: '',
4 months ago
zdUserInfo: {},
5 months ago
},
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
});
},
4 months ago
getMenuInfo(self) {
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
self.setData({
menuButtonInfo,
});
},
// zd相关函数
4 months ago
zdMpBehavior(data: { PageName: string; doctor?: boolean }) {
let url = '?r=xd/mp-behavior/add';
if (data.doctor) {
4 months ago
url = '?r=zd/doctor/mp-behavior/add';
4 months ago
}
delete data.doctor;
wx.ajax({
method: 'POST',
url,
data,
loading: false,
showMsg: false,
}).then((res) => {
console.log('res: ', res);
});
},
4 months ago
zdGetTheme() {
return new Promise((resolve) => {
const checkUserType = () => {
const zdUserInfo = this.globalData.zdUserInfo;
if (zdUserInfo.UserType) {
// resolve(zdUserInfo.UserType >= 4 ? 'DRUG' : 'PATIENT')
resolve('PATIENT');
return true;
}
return false;
};
const tryResolve = () => {
if (!checkUserType()) {
setTimeout(tryResolve, 30);
}
};
tryResolve();
});
},
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';
}
let 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 = '') {
// 1-空白用户,2-注册用户,3-疾病患者,4-用药患者
const { PatientId, AuditStatus, isFollow, UserType } = this.globalData.zdUserInfo;
const that = this;
this.globalData.registChannel = registChannel;
this.globalData.regBusinessId = regBusinessId;
let isReject = false;
return new Promise((resolve, reject) => {
if (grade == 2 && Number(UserType) < 2) {
wx.reLaunch({
url: '/patient/pages/login/index',
});
isReject = true;
}
if (grade == 3 && Number(UserType) < 3) {
if (UserType == 1) {
wx.reLaunch({
url: '/patient/pages/login/index',
});
isReject = true;
}
if (UserType == 2) {
let urlKey = '';
if (!PatientId) {
urlKey = 'enterInfo';
} else if (AuditStatus == 0) {
urlKey = 'noCert';
} else if (AuditStatus == 1) {
if (backPage && (backPage as string).includes('liveResult')) {
urlKey = 'liveResult';
} else {
urlKey = isFollow ? 'nopending' : 'pending';
}
} else if (AuditStatus == 2) {
urlKey = 'reject';
}
let 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',
liveResult: backPage,
}[urlKey];
if (urlKey == 'liveResult') {
wx.navigateTo({
url: navUrl as string,
});
} else {
wx.reLaunch({
url: navUrl as string,
});
}
isReject = true;
}
}
if (grade == 4 && Number(UserType) < 4) {
wx.reLaunch({
url: '/patient/pages/vipLogin/index',
});
isReject = true;
}
if (isReject) {
that.globalData.backPage = backPage;
reject(null);
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 } = 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,
},
});
}
callback(res);
});
},
5 months ago
});