App.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script>
  2. import { mapMutations, mapActions, mapGetters } from "vuex";
  3. // 这个导入在小程序环境中是不需要的,因为小程序环境已经有全局的 setTimeout 函数
  4. // import { setTimeout } from "timers";
  5. import { getUser, wxLoginFn } from "@/utils/auth";
  6. import {
  7. TOKEN_STORAGE_KEY,
  8. LEGACY_TOKEN_STORAGE_KEY,
  9. } from "@/constant/storageKeys";
  10. export default {
  11. // 全端,数据共享,还可以解决页面初始化模板访问不到值得问题
  12. // 有坑 分包里的页面访问不到
  13. globalData: {},
  14. onLaunch () {
  15. const legacyToken = uni.getStorageSync(LEGACY_TOKEN_STORAGE_KEY);
  16. const currentToken = uni.getStorageSync(TOKEN_STORAGE_KEY);
  17. if (!currentToken && legacyToken) {
  18. uni.setStorageSync(TOKEN_STORAGE_KEY, legacyToken);
  19. uni.removeStorageSync(LEGACY_TOKEN_STORAGE_KEY);
  20. }
  21. // this.getAllOptions()
  22. // 删除缓存
  23. if (process.env.NODE_ENV == "production") {
  24. uni.removeStorageSync("shopUser");
  25. }
  26. // #ifdef MP-WEIXIN
  27. // wxLoginFn()
  28. // uni.clearStorage()
  29. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
  30. uni.setStorageSync("account", extConfig.account);
  31. // #endif
  32. // #ifdef H5
  33. // H5开发环境无法微信授权,使用固定的用户 shish 2020.4.30
  34. if (process.env.NODE_ENV == "development") {
  35. uni.setStorageSync(
  36. TOKEN_STORAGE_KEY,
  37. "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfMTI1NDM0MzEifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLm1hbGwuaHVhbWwuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5tYWxsLmh1YW1sLmNvbSIsImp0aSI6IjBfMTI1NDM0MzEiLCJpYXQiOjE1ODgyMzAwMjgsIm5iZiI6MTU4ODIzMDAyOCwiZXhwIjoxNTk2ODcwMDI4LCJ1bmlxdWVJZCI6IjEyNTQzNDMxIiwic291cmNlSWQiOjB9.Tmw2h9pucpyctvtB--i0dg-zTcVMIJZ1PtnWTLLwEEo"
  38. );
  39. uni.setStorageSync("account", "12358");
  40. }
  41. // #endif
  42. },
  43. onHide () { },
  44. onError (err) {
  45. console.error(err, "错误捕获");
  46. },
  47. methods: {
  48. isLogin () {
  49. let token = uni.getStorageSync(TOKEN_STORAGE_KEY);
  50. if (!token) {
  51. uni.reLaunch({
  52. url: "/pages/page/login/index"
  53. });
  54. }
  55. }
  56. }
  57. };
  58. </script>
  59. <style lang="scss">
  60. //没有scss变量方法的,主要引入 这样打包的时候就不会所有的组件都打包进去
  61. @import "./static/iconfont/iconfont.css";
  62. @import "./static/css/uni2.css";
  63. @import "./static/css/base.scss";
  64. @import "./static/css/common.scss";
  65. @import "./static/css/reset.scss";
  66. page {
  67. height: 100%;
  68. }
  69. </style>