12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- // app.ts
- import api from "./api/index";
- App<IAppOption>({
- globalData: {},
- onLaunch() {
- // 登录
- const nowTime = Date.now() - (wx.getStorageSync("tokenTime") || 0) >= 86400000 * 7;
- (!wx.getStorageSync("token") || nowTime) && this.wLogin();
- // 获取用户信息
- this.getUser({
- data: {},
- success: (res: any) => {
- if(!res) return;
- 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();
- console.log(this.globalData.SystemInfo.SDKVersion);
- },
- 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
- })
|