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.
110 lines
2.9 KiB
110 lines
2.9 KiB
3 weeks 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
|
||
|
// appid:wxbdf6f933281b1eb4
|
||
|
url: 'https://m.shizhong.hbraas.com',
|
||
|
upFileUrl: 'https://m.shizhong.hbraas.com/',
|
||
|
imageUrl: 'https://m.shizhong.hbraas.com/api/shizhong/',
|
||
|
// pro
|
||
|
// appid:wxa4a28b299df7d921
|
||
|
// url: 'https://m.shizhong.hbsaas.com',
|
||
|
// upFileUrl: 'https://m.shizhong.hbsaas.com/',
|
||
|
// imageUrl: 'https://m.shizhong.hbsaas.com/api/shizhong/',
|
||
|
|
||
|
loginState: '',
|
||
|
isLogin: 0,
|
||
|
isAnswer: '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) => {
|
||
|
wx.ajax({
|
||
|
method: 'GET',
|
||
|
url: '?r=shizhong/user/init-login',
|
||
|
data: {
|
||
|
code: res.code,
|
||
|
},
|
||
|
}).then((res) => {
|
||
|
this.globalData.loginState = res.loginState;
|
||
|
this.globalData.isLogin = res.isLogin || 999;
|
||
|
});
|
||
|
},
|
||
|
});
|
||
|
|
||
|
wx.setInnerAudioOption({
|
||
|
obeyMuteSwitch: false,
|
||
|
mixWithOther: false,
|
||
|
});
|
||
|
},
|
||
|
onShow(options) {
|
||
|
if (options.query.scene) {
|
||
|
this.globalData.scene = parseScene(options.query.scene);
|
||
|
}
|
||
|
},
|
||
|
waitLogin(waitLoginState = false, requireLogin = false, bakcPath = '') {
|
||
|
let time: number;
|
||
|
return new Promise((resolve) => {
|
||
|
time = setInterval(() => {
|
||
|
const { isLogin, loginState } = this.globalData;
|
||
|
if (loginState) {
|
||
|
clearInterval(time);
|
||
|
if (waitLoginState) {
|
||
|
resolve(true);
|
||
|
} else if (isLogin === 0 || !isLogin) {
|
||
|
this.globalData.backPath = bakcPath;
|
||
|
wx.reLaunch({ url: '/pages/login/index' });
|
||
|
} else if (requireLogin && isLogin === 999) {
|
||
|
this.globalData.backPath = bakcPath;
|
||
|
wx.reLaunch({ url: '/pages/login/index' });
|
||
|
} else {
|
||
|
resolve(true);
|
||
|
}
|
||
|
}
|
||
|
}, 500);
|
||
|
});
|
||
|
},
|
||
|
getUserInfo(self: WechatMiniprogram.Page.Instance<any, any>, callback?: (res: any) => void) {
|
||
|
wx.ajax({
|
||
|
method: 'GET',
|
||
|
url: '?r=shizhong/account/get-info',
|
||
|
data: {},
|
||
|
}).then((res) => {
|
||
|
if (self) {
|
||
|
self.setData({
|
||
|
userInfo: res,
|
||
|
});
|
||
|
}
|
||
|
callback?.(res);
|
||
|
});
|
||
|
},
|
||
|
getMenuInfo(self) {
|
||
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
|
||
|
self.setData({
|
||
|
menuButtonInfo,
|
||
|
});
|
||
|
},
|
||
|
});
|