app.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // app.ts
  2. import { api_getOpenId } from "./api/new";
  3. const config = require("./config");
  4. App<IAppOption>({
  5. globalData: {
  6. top: 0,
  7. baseUrl: config?.baseUrl,
  8. appId: "",
  9. deviceNum: "",
  10. isLogin: false,
  11. userInfo: {} as any,
  12. },
  13. onLaunch() {
  14. this.setAppId();
  15. wx.setStorageSync("traceId", this.getRandomKey());
  16. wx.login({
  17. success: async (res) => {
  18. await api_getOpenId({
  19. code: res.code,
  20. appId: this.globalData.appId,
  21. }).then((result: any) => {
  22. wx.setStorageSync("openId", result.data.data);
  23. });
  24. },
  25. });
  26. },
  27. getRandomKey() {
  28. return "" + new Date().getTime() + Math.floor(Math.random() * 1000000);
  29. },
  30. setAppId() {
  31. const accountInfo = wx.getAccountInfoSync();
  32. this.globalData.appId = accountInfo.miniProgram.appId;
  33. const deviceInfo = wx.getDeviceInfo();
  34. const deviceNum =
  35. deviceInfo.brand +
  36. "-" +
  37. deviceInfo.model +
  38. "-" +
  39. deviceInfo.platform +
  40. "-" +
  41. deviceInfo.system;
  42. this.globalData.deviceNum = deviceNum;
  43. const systemInfo = wx.getWindowInfo();
  44. this.globalData.top = systemInfo.windowHeight - 180;
  45. },
  46. });