app.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // app.ts
  2. import api from "./api/index";
  3. App<IAppOption>({
  4. globalData: {},
  5. onLaunch() {
  6. // 登录
  7. const nowTime = Date.now() - (wx.getStorageSync("tokenTime") || 0) >= 86400000 * 7;
  8. console.log(nowTime);
  9. (!wx.getStorageSync("token") || nowTime) && this.wLogin();
  10. // 获取用户信息
  11. this.getUser({
  12. data: {},
  13. success: (res: any) => {
  14. console.log(res);
  15. if (!res.RESULT) return wx.showToast({
  16. "title": "视频正在生成中,请耐心等待"
  17. })
  18. if (res.UPLOAD_FACE && res.SAVE_USER_INFO) {
  19. // 已经录过脸并且用户信息已经上传,跳转视频下载页
  20. return wx.reLaunch({
  21. url: "/pages/downloadPage/index"
  22. })
  23. }
  24. }
  25. })
  26. // 获取用户手机号
  27. this.globalData.phone = wx.getStorageSync("userphone") || "";
  28. // 获取授权内容
  29. wx.getSetting({
  30. success: res => {
  31. this.globalData.setting = res ? res.authSetting : {}
  32. }
  33. });
  34. this.globalData.SystemInfo = wx.getSystemInfoSync();
  35. this.globalData.FileSystemManager = wx.getFileSystemManager();
  36. },
  37. wLogin() {
  38. wx.login({
  39. fail: err => {
  40. console.log(err)
  41. },
  42. success: res => {
  43. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  44. this.login({
  45. data: {
  46. code: res.code
  47. },
  48. success: (res: any) => {
  49. wx.setStorageSync("token", res.token);
  50. wx.setStorageSync("tokenTime", Date.now());
  51. }
  52. })
  53. },
  54. })
  55. },
  56. ...api
  57. })