|
|
|
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:wxf9ce8010f1ad24aa
|
|
|
|
url: 'https://m.xd.hbraas.com',
|
|
|
|
upFileUrl: 'https://m.xd.hbraas.com/',
|
|
|
|
imageUrl: 'https://m.xd.hbraas.com/xd/',
|
|
|
|
|
|
|
|
// 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) => {
|
|
|
|
console.log(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,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|