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.

139 lines
3.9 KiB

import config from "./config";
import { client } from "./js/client";
wx.cloud.init({
traceUser: true,
env: "educoder"
});
App({
globalData: {
versionCode: config.versionCode,
debug: config.debug
},
client,
openapi({name, data, success, fail, complete}){
return wx.cloud.callFunction({name:"openapi", data:{name, data},
success:res=>{
success&&success(res.result);
}, fail, complete});
},
realTimeLog:global.realTimeLog,
api(name, config) { return client.api(name, config) },
callApi(options) { return client.callApi(options) },
user() { return client.user },
syncUser(options) { return client.syncUser(options) },
updateUserInfo(info){return client.updateUserInfo(info)},
onLaunch: function (options) {
if(options.scene==1129){
this.api("accounts.login")(global.accountManager.testAccount)
.then(res=>{
let account = { ...res, ...global.accountManager.testAccount};
global.accountManager.setCurrentAccount(account);
});
wx.reportMonitor('1', 1);
}
const db = wx.cloud.database();
if (options.referrerInfo && options.referrerInfo.appId) {
let { appId, extraData } = options.referrerInfo;
let { scene, path } = options;
db.collection("referrer_info")
.add({
data: {
appId, extraData, scene, path,
createdAt: db.serverDate()
}
})
}
this.api("users.system_update")().then(res => {
if (res.system_update) {
let { subject = "升级服务通知", system_score} = res;
if(!system_score){
let {end_time} = res;
if(end_time){
const {getFormatDatetime} = require('./js/utils');
system_score = "为了给大家提供更优质的体验,平台正在对系统进行升级,期间系统响应会有一定延迟。系统将于"+getFormatDatetime(new Date(end_time))+"恢复正常。敬请谅解";
}else{
system_score = "为了给大家提供更优质的体验,平台正在对系统进行升级,期间系统响应会有一定延迟,敬请谅解";
}
}
wx.showModal({
title: subject,
content: system_score,
showCancel: false
})
}
}).catch(e=>{});
},
onShow() {
if (client.user_id && client.user_id != 2)
client.getTidingInfo();
},
onPageNotFound(res) {
this.realTimeLog.error("page not find!! redirect", res);
this.reLaunch({ url: "{main}" });
},
showError(e, duration = 1500) {
wx.showToast({
title: e.message,
icon: "none",
duration
})
},
showMsg(res, duration = 1500) {
wx.showToast({
title: res.message, duration
})
},
getPageUrl(url, root = "/") {
return url.replace(/{(.*)}/, function (match, name) {
for (var u of __wxConfig.pages) {
if (u.endsWith("/" + name))
return root + u;
}
for (var u of config.pages) {
if (u.endsWith("/" + name))
return root + u;
}
return match;
});
},
reLaunch({ url, success, fail, complete }) {
wx.reLaunch({ url: this.getPageUrl(url), success, fail, complete })
},
redirectTo({ url, success, fail, complete }) {
wx.redirectTo({ url: this.getPageUrl(url), success, fail, complete })
},
navigateTo({ url, success, fail, complete }) {
wx.navigateTo({ url: this.getPageUrl(url), success, fail, complete })
},
shareApp({ imageUrl, path, title }) {
return {
title: title || "EduCoder教学",
imageUrl,
path
}
}
});
function getCurrentPath() {
let pages = getCurrentPages();
return pages[pages.length - 1].route;
}
function toAbsPath(current, path) {
if (path.startsWith("/"))
current = ".";
else
current = current + "/../";
path = current + path;
while (path.indexOf("..") != -1) {
path = path.replace(/[^\/]*\/\.\.\//g, "")
}
while (path.indexOf(".") != -1) {
path = path.replace(/\.\//, "");
}
return path;
}