123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // app.ts
- import api from "./api/index";
- App<IAppOption>({
- globalData: {},
- onLaunch() {
- // 登录
- const nowTime = Date.now() - (wx.getStorageSync("tokenTime") || 0) >= 86400000 * 7;
- console.log(nowTime);
- (!wx.getStorageSync("token") || nowTime) && this.wLogin();
- // 获取用户信息
- this.getUser({
- data: {},
- success: (res: any) => {
- console.log(res);
- if (!res.RESULT) return wx.showToast({
- "title": "视频正在生成中,请耐心等待"
- })
- if (res.UPLOAD_FACE && res.SAVE_USER_INFO) {
- // 已经录过脸并且用户信息已经上传,跳转视频下载页
- return wx.reLaunch({
- url: "/pages/downloadPage/index"
- })
- }
- }
- })
- // 获取用户手机号
- this.globalData.phone = wx.getStorageSync("userphone") || "";
- // 获取授权内容
- wx.getSetting({
- success: res => {
- this.globalData.setting = res ? res.authSetting : {}
- }
- });
- this.globalData.SystemInfo = wx.getSystemInfoSync();
- this.globalData.FileSystemManager = wx.getFileSystemManager();
- },
- wLogin() {
- wx.login({
- fail: err => {
- console.log(err)
- },
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- this.login({
- data: {
- code: res.code
- },
- success: (res: any) => {
- wx.setStorageSync("token", res.token);
- wx.setStorageSync("tokenTime", Date.now());
- }
- })
- },
- })
- },
- ...api
- })
|