<script lang="ts">
import {clearToken, fetchToken} from "./utils/auth";
import {body} from "@/utils/https";
import {groupByKey} from "@/utils/common";

export default <any>{
  globalData: {
    token: "",
    user: {
    },
    isLogin: false,
    last:{},
    device: {},
    deviceId:null,
    manualLogout:false
  },
  onLaunch() {
    uni.getSystemInfo({
      success: (res) => {
        this.globalData.device = res;
      },
    });
    setTimeout(()=>{
      console.log("onLaunch clean token")
      clearToken()
    })

    body(`/dict/list`).then((res: any) => {
      if (res) {
        let dicts = res.map((k:any) => {
          let {code, name, value, color} = k;
          return {code, name, value, color}
        })
        let dictMap = groupByKey(dicts, "code");
        uni.setStorage({key: 'dict', data: dictMap})
      }
    })

    this.globalData.token = fetchToken();
  },
  onPageNotFound() {
    uni.switchTab({
      url: "/pages/index/index",
    });
  },
};
</script>
<style lang="scss">
@import '@climblee/uv-ui/index.scss';
@import './custom.scss';
</style>
