<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
import { getUser, wxLoginFn } from "@/utils/auth";
import {
  TOKEN_STORAGE_KEY,
  LEGACY_TOKEN_STORAGE_KEY,
} from "@/constant/storageKeys";
import { tryReLaunchFromScanEnter } from "@/utils/launchScene";
export default {
  globalData: {
    lastLaunchKey: "",
  },
  onLaunch () {
    const legacyToken = uni.getStorageSync(LEGACY_TOKEN_STORAGE_KEY);
    const currentToken = uni.getStorageSync(TOKEN_STORAGE_KEY);
    if (!currentToken && legacyToken) {
      uni.setStorageSync(TOKEN_STORAGE_KEY, legacyToken);
      uni.removeStorageSync(LEGACY_TOKEN_STORAGE_KEY);
    }

    if (process.env.NODE_ENV == "production") {
      uni.removeStorageSync("shopUser");
    }
    // #ifdef MP-WEIXIN
    const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    uni.setStorageSync("account", extConfig.account);
    // #endif

    // #ifdef H5
    // if (process.env.NODE_ENV == "development") {
    //   uni.setStorageSync(
    //     TOKEN_STORAGE_KEY,
    //     "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfMTI1NDM0MzEifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLm1hbGwuaHVhbWwuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5tYWxsLmh1YW1sLmNvbSIsImp0aSI6IjBfMTI1NDM0MzEiLCJpYXQiOjE1ODgyMzAwMjgsIm5iZiI6MTU4ODIzMDAyOCwiZXhwIjoxNTk2ODcwMDI4LCJ1bmlxdWVJZCI6IjEyNTQzNDMxIiwic291cmNlSWQiOjB9.Tmw2h9pucpyctvtB--i0dg-zTcVMIJZ1PtnWTLLwEEo"
    //   );
    //   uni.setStorageSync("account", "12358");
    // }
    // #endif
  },
  onShow () {
    // #ifdef MP-WEIXIN
    // 热启动扫太阳码：页面栈可能保留，onLoad 不执行；在此 reLaunch 展开 scene 并清栈
    tryReLaunchFromScanEnter(this.globalData);
    // #endif
  },
  onHide () { },
  onError (err) {
    console.error(err, "错误捕获");
  },
  methods: {
    isLogin () {
      let token = uni.getStorageSync(TOKEN_STORAGE_KEY);
      if (!token) {
        uni.reLaunch({
          url: "/pages/page/login/index"
        });
      }
    }
  }
};
</script>

<style lang="scss">
//没有scss变量方法的，主要引入 这样打包的时候就不会所有的组件都打包进去
@import "./static/iconfont/iconfont.css";
@import "./static/css/uni2.css";
@import "./static/css/base.scss";
@import "./static/css/common.scss";
@import "./static/css/reset.scss";
page {
  height: 100%;
}
</style>
