fix: user模块升级为ts ()

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
web/src/management
pages
edit/modules/settingModule/skin
list/components
router
stores

View File

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

View File

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

View File

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

View File

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