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, api(name, config){return client.api(name,config)}, callApi(options){return client.callApi(options)}, user(){ return client.user}, syncUser(options){return client.syncUser(options)}, onLaunch: function (options) { 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() } }) } }, onShow(){ if(client.user_id&&client.user_id!=2) client.getTidingInfo(); }, onPageNotFound(res) { console.log("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; } 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:imageUrl||"", path } } });