初始提交:OCI 面板前端(含 GenAI 网关一期)

This commit is contained in:
Wang Defa
2026-07-09 15:31:29 +08:00
commit db45a669e3
135 changed files with 25220 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
const TOKEN_KEY = 'oci-portal.token'
const EXPIRES_KEY = 'oci-portal.expiresAt'
export const useAuthStore = defineStore('auth', () => {
const token = ref(localStorage.getItem(TOKEN_KEY) ?? '')
const expiresAt = ref(localStorage.getItem(EXPIRES_KEY) ?? '')
const isAuthed = computed(() => {
if (!token.value) return false
if (!expiresAt.value) return true
return new Date(expiresAt.value).getTime() > Date.now()
})
function setSession(newToken: string, newExpiresAt: string) {
token.value = newToken
expiresAt.value = newExpiresAt
localStorage.setItem(TOKEN_KEY, newToken)
localStorage.setItem(EXPIRES_KEY, newExpiresAt)
}
function logout() {
token.value = ''
expiresAt.value = ''
localStorage.removeItem(TOKEN_KEY)
localStorage.removeItem(EXPIRES_KEY)
}
return { token, expiresAt, isAuthed, setSession, logout }
})