<template><div></div></template>
<script lang="ts">
import { defineComponent, onMounted } from 'vue' // reactive ref,
import { userStore } from '@/store/modules/user'
import router from '@/router'
// import Storage from 'web-storage-cache'

import {
	USER_APPLICATION_ID,
	USER_APPLICATION_TYPE,
	RBAC_ACCESS_TOKEN_KEY,
} from '@/global/cacheKey'

export default defineComponent({
	setup() {
		const useUserStore = userStore()
		// const localStorage = new Storage()

		const init = async () => {
			if (router.currentRoute.value && router.currentRoute.value.query) {
				const { accessToken, processAppId, AuthorizationAppType } =
					router.currentRoute.value.query
				let token = new String(accessToken).replace('Bearer ', '')
				let applicationId = processAppId ? new String(processAppId) : ''
				let authorizationAppType = AuthorizationAppType
					? new String(AuthorizationAppType)
					: ''
				useUserStore.setToken(token as string)
				window.localStorage.setItem(RBAC_ACCESS_TOKEN_KEY, token)

				// localStorage.set(USER_APPLICATION_ID, applicationId)

				window.localStorage.setItem(
					USER_APPLICATION_ID,
					applicationId as string
				)
				window.localStorage.setItem(
					USER_APPLICATION_TYPE,
					authorizationAppType as string
				)
				// 获取菜单权限key
				await useUserStore.getAuthoritiesList(token)
			} else {
			}
		}

		onMounted(init)
		return {}
	},
})
</script>
