// app.ts import { api_getOpenId } from "./api/new"; const config = require("./config"); App({ globalData: { top: 0, baseUrl: config?.baseUrl, appId: "", deviceNum: "", isLogin: false, userInfo: {} as any, }, onLaunch() { this.setAppId(); wx.setStorageSync("traceId", this.getRandomKey()); wx.login({ success: async (res) => { await api_getOpenId({ code: res.code, appId: this.globalData.appId, }).then((result: any) => { wx.setStorageSync("openId", result.data.data); }); }, }); }, getRandomKey() { return "" + new Date().getTime() + Math.floor(Math.random() * 1000000); }, setAppId() { const accountInfo = wx.getAccountInfoSync(); this.globalData.appId = accountInfo.miniProgram.appId; const deviceInfo = wx.getDeviceInfo(); const deviceNum = deviceInfo.brand + "-" + deviceInfo.model + "-" + deviceInfo.platform + "-" + deviceInfo.system; this.globalData.deviceNum = deviceNum; const systemInfo = wx.getWindowInfo(); this.globalData.top = systemInfo.windowHeight - 180; }, });