app.ts 772 B

123456789101112131415161718192021222324252627282930313233
  1. // app.ts
  2. import api from "./api/index";
  3. App<IAppOption>({
  4. globalData: {},
  5. onLaunch() {
  6. // 登录
  7. !wx.getStorageSync("token") && this.wLogin();
  8. // 获取授权内容
  9. wx.getSetting({
  10. success: res =>{
  11. this.globalData.setting = res? res.authSetting : {}
  12. }
  13. });
  14. this.globalData.SystemInfo = wx.getSystemInfoSync();
  15. this.globalData.FileSystemManager = wx.getFileSystemManager();
  16. },
  17. wLogin(){
  18. wx.login({
  19. success: res => {
  20. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  21. this.login({
  22. data: {
  23. code: res.code
  24. },
  25. success: (res: any) => {
  26. wx.setStorageSync("token", res.token);
  27. }
  28. })
  29. },
  30. })
  31. },
  32. ...api
  33. })