diff --git a/src/api/index.ts b/src/api/index.ts
index 89b8ba34..4ec94ee3 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -1,6 +1,6 @@
import axios from 'axios'
import router from '@/router'
-import store from '@/store'
+import { useAuthStore } from '@/stores'
// 创建axios实例
const api = axios.create({
@@ -9,10 +9,12 @@ const api = axios.create({
// 添加请求拦截器
api.interceptors.request.use(config => {
+ // 认证 Store
+ const authStore = useAuthStore()
// 在请求头中添加token
- const token = store.state.auth.token
- if (token) config.headers.Authorization = `Bearer ${token}`
-
+ if (authStore.token) {
+ config.headers.Authorization = `Bearer ${authStore.token}`
+ }
return config
})
@@ -26,8 +28,10 @@ api.interceptors.response.use(
// 请求超时
return Promise.reject(new Error(error))
} else if (error.response.status === 403) {
+ // 认证 Store
+ const authStore = useAuthStore()
// 清除登录状态信息
- store.dispatch('auth/logout')
+ authStore.logout()
// token验证失败,跳转到登录页面
router.push('/login')
}
diff --git a/src/components/cards/MediaCard.vue b/src/components/cards/MediaCard.vue
index e6f677f0..d42e96cf 100644
--- a/src/components/cards/MediaCard.vue
+++ b/src/components/cards/MediaCard.vue
@@ -11,6 +11,7 @@ import noImage from '@images/no-image.jpeg'
import tmdbImage from '@images/logos/tmdb.png'
import doubanImage from '@images/logos/douban-black.png'
import bangumiImage from '@images/logos/bangumi.png'
+import { useUserStore } from '@/stores'
// 输入参数
const props = defineProps({
@@ -22,7 +23,8 @@ const props = defineProps({
// 从 provide 中获取全局设置
const globalSettings: any = inject('globalSettings')
-const store = useStore()
+// 用户 Store
+const userStore = useUserStore()
// 提示框
const $toast = useToast()
@@ -340,7 +342,7 @@ async function getMediaSeasons() {
// 查询订阅弹窗规则
async function queryDefaultSubscribeConfig() {
// 非管理员不显示
- if (!store.state.auth.superUser) return false
+ if (!userStore.superUser) return false
try {
let subscribe_config_url = ''
if (props.media?.type === '电影') subscribe_config_url = 'system/setting/DefaultMovieSubscribeConfig'
diff --git a/src/components/cards/UserCard.vue b/src/components/cards/UserCard.vue
index d3c515aa..6ddeaded 100644
--- a/src/components/cards/UserCard.vue
+++ b/src/components/cards/UserCard.vue
@@ -1,7 +1,7 @@
diff --git a/src/main.ts b/src/main.ts
index 301425e4..8e479c98 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -8,7 +8,7 @@ import '@/plugins/webfontloader'
import { createApp } from 'vue'
import vuetify from '@/plugins/vuetify'
import router from '@/router'
-import store from '@/store'
+import pinia from '@/stores/index'
// 3. 全局组件
import App from '@/App.vue'
@@ -65,10 +65,13 @@ async function initializeApp() {
// 注册全局组件
initializeApp().then(() => {
- // 优先注册框架
+ // 1. 注册 UI 框架
app.use(vuetify)
- // 注册全局组件
+ // 2. 注册状态管理与路由
+ app.use(pinia).use(router)
+
+ // 3. 注册全局组件
app
.component('VAceEditor', VAceEditor)
.component('VApexChart', VueApexCharts)
@@ -84,10 +87,8 @@ initializeApp().then(() => {
.component('VCronField', CronField)
.component('VPathField', PathField)
- // 注册插件
+ // 4. 注册其他插件
app
- .use(router)
- .use(store)
.use(PerfectScrollbarPlugin)
.use(ToastPlugin, {
position: 'bottom-right',
diff --git a/src/pages/appcenter.vue b/src/pages/appcenter.vue
index 6647ff93..d19d0256 100644
--- a/src/pages/appcenter.vue
+++ b/src/pages/appcenter.vue
@@ -1,11 +1,11 @@