refactor: pinia整合优化重构
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
import { createPinia } from "pinia";
|
||||
const store = createPinia();
|
||||
export { store };
|
||||
// 导入首页模块
|
||||
import useUserStore from './modules/user'
|
||||
import useAppStore from './modules/app'
|
||||
import usePermissionStore from './modules/permission'
|
||||
import useSettingStore from './modules/settings'
|
||||
import useTagsViewStore from './modules/tagsView'
|
||||
|
||||
const useStore = () => ({
|
||||
user: useUserStore(),
|
||||
app: useAppStore(),
|
||||
permission: usePermissionStore(),
|
||||
setting: useSettingStore(),
|
||||
tagsView: useTagsViewStore()
|
||||
|
||||
})
|
||||
|
||||
export default useStore
|
||||
@@ -1,10 +1,9 @@
|
||||
import {AppState} from "@/store/interface";
|
||||
import {localStorage} from "@/utils/storage";
|
||||
import {store} from "@/store";
|
||||
import {defineStore} from "pinia";
|
||||
import { getLanguage } from '@/lang/index'
|
||||
|
||||
export const useAppStore = defineStore({
|
||||
const useAppStore = defineStore({
|
||||
id: "app",
|
||||
state: (): AppState => ({
|
||||
device: 'desktop',
|
||||
@@ -44,6 +43,4 @@ export const useAppStore = defineStore({
|
||||
}
|
||||
})
|
||||
|
||||
export function useAppStoreHook() {
|
||||
return useAppStore(store);
|
||||
}
|
||||
export default useAppStore;
|
||||
@@ -3,7 +3,6 @@ import {RouteRecordRaw} from 'vue-router'
|
||||
import {constantRoutes} from '@/router'
|
||||
import {listRoutes} from "@/api/system/menu";
|
||||
import {defineStore} from "pinia";
|
||||
import {store} from "@/store";
|
||||
|
||||
const modules = import.meta.glob("../../views/**/**.vue");
|
||||
export const Layout = () => import( '@/layout/index.vue')
|
||||
@@ -48,7 +47,7 @@ export const filterAsyncRoutes = (routes: RouteRecordRaw[], roles: string[]) =>
|
||||
}
|
||||
|
||||
|
||||
export const usePermissionStore = defineStore({
|
||||
const usePermissionStore = defineStore({
|
||||
id: "permission",
|
||||
state: (): PermissionState => ({
|
||||
routes: [],
|
||||
@@ -74,6 +73,6 @@ export const usePermissionStore = defineStore({
|
||||
}
|
||||
})
|
||||
|
||||
export function usePermissionStoreHook() {
|
||||
return usePermissionStore(store);
|
||||
}
|
||||
|
||||
|
||||
export default usePermissionStore;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {store} from "@/store";
|
||||
import {SettingState} from "@/store/interface";
|
||||
import defaultSettings from '../../settings'
|
||||
import {localStorage} from "@/utils/storage";
|
||||
@@ -43,7 +42,4 @@ export const useSettingStore = defineStore({
|
||||
}
|
||||
})
|
||||
|
||||
export function useSettingStoreHook() {
|
||||
return useSettingStore(store);
|
||||
}
|
||||
|
||||
export default useSettingStore;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {store} from "@/store";
|
||||
import {TagsViewState} from "@/store/interface";
|
||||
import { defineStore } from "pinia";
|
||||
import { TagsViewState } from "@/store/interface";
|
||||
|
||||
const useTagsViewStore = defineStore({
|
||||
id: "tagsView",
|
||||
@@ -112,7 +111,7 @@ const useTagsViewStore = defineStore({
|
||||
return true
|
||||
}
|
||||
|
||||
const cacheIndex = this.cachedViews.indexOf(item.name as string)
|
||||
const cacheIndex = this.cachedViews.indexOf(item.name as string)
|
||||
if (cacheIndex > -1) {
|
||||
this.cachedViews.splice(cacheIndex, 1)
|
||||
}
|
||||
@@ -173,8 +172,4 @@ const useTagsViewStore = defineStore({
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
export function useTagsViewStoreHook() {
|
||||
return useTagsViewStore(store);
|
||||
}
|
||||
|
||||
export default useTagsViewStore;
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { store } from "@/store";
|
||||
import {UserState} from "@/store/interface";
|
||||
import {localStorage} from "@/utils/storage";
|
||||
import {getUserInfo, login, logout} from "@/api/login";
|
||||
import {resetRouter} from "@/router";
|
||||
|
||||
const getDefaultState = () => {
|
||||
return {
|
||||
token: localStorage.get('token'),
|
||||
nickname: '',
|
||||
avatar: '',
|
||||
roles: [],
|
||||
perms: []
|
||||
}
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
const useUserStore = defineStore({
|
||||
id:"user",
|
||||
state: ():UserState=>({
|
||||
token: localStorage.get('token') || '',
|
||||
@@ -113,7 +102,4 @@ export const useUserStore = defineStore({
|
||||
}
|
||||
})
|
||||
|
||||
export function useUserStoreHook() {
|
||||
return useUserStore(store);
|
||||
}
|
||||
|
||||
export default useUserStore;
|
||||
Reference in New Issue
Block a user