app.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. (!wx.getStorageSync("token") || nowTime) && this.wLogin();
  9. // 获取用户信息
  10. this.getUser({
  11. data: {},
  12. success: (res: any) => {
  13. if(!res) return;
  14. if (res.UPLOAD_FACE && res.SAVE_USER_INFO) {
  15. // 已经录过脸并且用户信息已经上传,跳转视频下载页
  16. return wx.reLaunch({
  17. url: "/pages/downloadPage/index"
  18. })
  19. }
  20. }
  21. })
  22. // 获取用户手机号
  23. this.globalData.phone = wx.getStorageSync("userphone") || "";
  24. // 获取授权内容
  25. wx.getSetting({
  26. success: res => {
  27. this.globalData.setting = res ? res.authSetting : {}
  28. }
  29. });
  30. this.globalData.SystemInfo = wx.getSystemInfoSync();
  31. this.globalData.FileSystemManager = wx.getFileSystemManager();
  32. console.log(this.globalData.SystemInfo.SDKVersion);
  33. },
  34. wLogin() {
  35. wx.login({
  36. fail: err => {
  37. console.log(err)
  38. },
  39. success: res => {
  40. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  41. this.login({
  42. data: {
  43. code: res.code
  44. },
  45. success: (res: any) => {
  46. wx.setStorageSync("token", res.token);
  47. wx.setStorageSync("tokenTime", Date.now());
  48. }
  49. })
  50. },
  51. })
  52. },
  53. ...api
  54. })