fix: user模块升级为ts (#348)

This commit is contained in:
dayou 2024-07-16 14:32:28 +08:00 committed by GitHub
parent 09866663f2
commit 7ff691471b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 9 deletions

View File

@ -27,7 +27,6 @@
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useStore } from 'vuex'
import { useEditStore } from '@/management/stores/edit'
import skinPresets from '@/management/config/skinPresets.js'

View File

@ -65,7 +65,7 @@ const remoteMethod = async (query: string) => {
if (res.code === CODE_MAP.SUCCESS) {
selectOptions.value = res.data.map((item: any) => {
//
const currentUser = item.username === userStore.userInfo.username
const currentUser = item.username === userStore.userInfo?.username
return {
value: item.userId,
label: item.username,

View File

@ -5,7 +5,6 @@ import {
type NavigationGuardNext
} from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import { useStore, type Store } from 'vuex'
import { SurveyPermissions } from '@/management/utils/types/workSpace'
import { analysisTypeMap } from '@/management/config/analysisConfig'
import { ElMessage } from 'element-plus'

View File

@ -1,22 +1,27 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { ref } from 'vue'
type IUserInfo = {
username: string
token: string
}
const USER_INFO_KEY = 'surveyUserInfo'
export const useUserStore = defineStore('user', () => {
const userInfo = ref({
const userInfo = ref<IUserInfo | null>({
username: '',
token: ''
})
const hasLogined = ref(false)
const loginTime = ref(null)
const loginTime = ref<number | null>(null)
const initialized = ref(false)
const init = () => {
const localData = localStorage.getItem(USER_INFO_KEY)
if (localData) {
try {
const { userInfo: info, loginTime } = JSON.parse(localData)
if (Date.now() - loginTime > 7 * 3600000) {
const { userInfo: info, loginTime: time } = JSON.parse(localData)
if (Date.now() - time > 7 * 3600000) {
localStorage.removeItem(USER_INFO_KEY)
} else {
login(info)
@ -27,7 +32,7 @@ export const useUserStore = defineStore('user', () => {
}
initialized.value = true
}
const login = (data) => {
const login = (data: IUserInfo) => {
userInfo.value = data
hasLogined.value = true
loginTime.value = Date.now()
@ -47,3 +52,4 @@ export const useUserStore = defineStore('user', () => {
return { userInfo, hasLogined, loginTime, initialized, init, login, logout }
})