refactor: 自动按需导入 pinia api
This commit is contained in:
parent
5338d12fd3
commit
20cc0885d7
@ -9,7 +9,6 @@ import ThemeSwitch from "@@/components/ThemeSwitch/index.vue"
|
|||||||
import { useDevice } from "@@/composables/useDevice"
|
import { useDevice } from "@@/composables/useDevice"
|
||||||
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
||||||
import { UserFilled } from "@element-plus/icons-vue"
|
import { UserFilled } from "@element-plus/icons-vue"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import { Breadcrumb, Hamburger, Sidebar } from "../index"
|
import { Breadcrumb, Hamburger, Sidebar } from "../index"
|
||||||
|
|
||||||
const { isMobile } = useDevice()
|
const { isMobile } = useDevice()
|
||||||
|
@ -3,7 +3,6 @@ import { useSettingsStore } from "@/pinia/stores/settings"
|
|||||||
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
||||||
import { removeLayoutsConfig } from "@@/utils/cache/local-storage"
|
import { removeLayoutsConfig } from "@@/utils/cache/local-storage"
|
||||||
import { Refresh } from "@element-plus/icons-vue"
|
import { Refresh } from "@element-plus/icons-vue"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import SelectLayoutMode from "./SelectLayoutMode.vue"
|
import SelectLayoutMode from "./SelectLayoutMode.vue"
|
||||||
|
|
||||||
const { isLeft } = useLayoutMode()
|
const { isLeft } = useLayoutMode()
|
||||||
|
@ -4,7 +4,6 @@ import { useDevice } from "@@/composables/useDevice"
|
|||||||
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
||||||
import { useWatermark } from "@@/composables/useWatermark"
|
import { useWatermark } from "@@/composables/useWatermark"
|
||||||
import { getCssVar, setCssVar } from "@@/utils/css"
|
import { getCssVar, setCssVar } from "@@/utils/css"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import { RightPanel, Settings } from "./components"
|
import { RightPanel, Settings } from "./components"
|
||||||
import { useResize } from "./composables/useResize"
|
import { useResize } from "./composables/useResize"
|
||||||
import LeftMode from "./modes/LeftMode.vue"
|
import LeftMode from "./modes/LeftMode.vue"
|
||||||
|
@ -3,7 +3,6 @@ import { useAppStore } from "@/pinia/stores/app"
|
|||||||
import { useSettingsStore } from "@/pinia/stores/settings"
|
import { useSettingsStore } from "@/pinia/stores/settings"
|
||||||
import { useDevice } from "@@/composables/useDevice"
|
import { useDevice } from "@@/composables/useDevice"
|
||||||
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
import { useLayoutMode } from "@@/composables/useLayoutMode"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import { AppMain, NavigationBar, Sidebar, TagsView } from "../components"
|
import { AppMain, NavigationBar, Sidebar, TagsView } from "../components"
|
||||||
|
|
||||||
const { isMobile } = useDevice()
|
const { isMobile } = useDevice()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useAppStore } from "@/pinia/stores/app"
|
import { useAppStore } from "@/pinia/stores/app"
|
||||||
import { useSettingsStore } from "@/pinia/stores/settings"
|
import { useSettingsStore } from "@/pinia/stores/settings"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import { AppMain, Logo, NavigationBar, Sidebar, TagsView } from "../components"
|
import { AppMain, Logo, NavigationBar, Sidebar, TagsView } from "../components"
|
||||||
|
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useSettingsStore } from "@/pinia/stores/settings"
|
import { useSettingsStore } from "@/pinia/stores/settings"
|
||||||
import { storeToRefs } from "pinia"
|
|
||||||
import { AppMain, Logo, NavigationBar, TagsView } from "../components"
|
import { AppMain, Logo, NavigationBar, TagsView } from "../components"
|
||||||
|
|
||||||
const settingsStore = useSettingsStore()
|
const settingsStore = useSettingsStore()
|
||||||
|
@ -1,3 +1 @@
|
|||||||
import { createPinia } from "pinia"
|
|
||||||
|
|
||||||
export const pinia = createPinia()
|
export const pinia = createPinia()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { pinia } from "@/pinia"
|
import { pinia } from "@/pinia"
|
||||||
import { DeviceEnum, SIDEBAR_CLOSED, SIDEBAR_OPENED } from "@@/constants/app-key"
|
import { DeviceEnum, SIDEBAR_CLOSED, SIDEBAR_OPENED } from "@@/constants/app-key"
|
||||||
import { getSidebarStatus, setSidebarStatus } from "@@/utils/cache/local-storage"
|
import { getSidebarStatus, setSidebarStatus } from "@@/utils/cache/local-storage"
|
||||||
import { defineStore } from "pinia"
|
|
||||||
|
|
||||||
interface Sidebar {
|
interface Sidebar {
|
||||||
opened: boolean
|
opened: boolean
|
||||||
|
@ -3,7 +3,6 @@ import { pinia } from "@/pinia"
|
|||||||
import { constantRoutes, dynamicRoutes } from "@/router"
|
import { constantRoutes, dynamicRoutes } from "@/router"
|
||||||
import { routerConfig } from "@/router/config"
|
import { routerConfig } from "@/router/config"
|
||||||
import { flatMultiLevelRoutes } from "@/router/helper"
|
import { flatMultiLevelRoutes } from "@/router/helper"
|
||||||
import { defineStore } from "pinia"
|
|
||||||
|
|
||||||
function hasPermission(roles: string[], route: RouteRecordRaw) {
|
function hasPermission(roles: string[], route: RouteRecordRaw) {
|
||||||
const routeRoles = route.meta?.roles
|
const routeRoles = route.meta?.roles
|
||||||
|
@ -3,7 +3,6 @@ import type { Ref } from "vue"
|
|||||||
import { layoutsConfig } from "@/layouts/config"
|
import { layoutsConfig } from "@/layouts/config"
|
||||||
import { pinia } from "@/pinia"
|
import { pinia } from "@/pinia"
|
||||||
import { setLayoutsConfig } from "@@/utils/cache/local-storage"
|
import { setLayoutsConfig } from "@@/utils/cache/local-storage"
|
||||||
import { defineStore } from "pinia"
|
|
||||||
|
|
||||||
type SettingsStore = {
|
type SettingsStore = {
|
||||||
// 使用映射类型来遍历 LayoutsConfig 对象的键
|
// 使用映射类型来遍历 LayoutsConfig 对象的键
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import type { RouteLocationNormalized } from "vue-router"
|
import type { RouteLocationNormalized } from "vue-router"
|
||||||
import { pinia } from "@/pinia"
|
import { pinia } from "@/pinia"
|
||||||
import { getCachedViews, getVisitedViews, setCachedViews, setVisitedViews } from "@@/utils/cache/local-storage"
|
import { getCachedViews, getVisitedViews, setCachedViews, setVisitedViews } from "@@/utils/cache/local-storage"
|
||||||
import { defineStore } from "pinia"
|
|
||||||
import { useSettingsStore } from "./settings"
|
import { useSettingsStore } from "./settings"
|
||||||
|
|
||||||
export type TagView = Partial<RouteLocationNormalized>
|
export type TagView = Partial<RouteLocationNormalized>
|
||||||
|
@ -3,7 +3,6 @@ import { resetRouter } from "@/router"
|
|||||||
import { routerConfig } from "@/router/config"
|
import { routerConfig } from "@/router/config"
|
||||||
import { getUserInfoApi } from "@@/apis/user"
|
import { getUserInfoApi } from "@@/apis/user"
|
||||||
import { setToken as _setToken, getToken, removeToken } from "@@/utils/cache/cookies"
|
import { setToken as _setToken, getToken, removeToken } from "@@/utils/cache/cookies"
|
||||||
import { defineStore } from "pinia"
|
|
||||||
import { useSettingsStore } from "./settings"
|
import { useSettingsStore } from "./settings"
|
||||||
import { useTagsViewStore } from "./tags-view"
|
import { useTagsViewStore } from "./tags-view"
|
||||||
|
|
||||||
|
12
types/auto/auto-imports.d.ts
vendored
12
types/auto/auto-imports.d.ts
vendored
@ -11,12 +11,16 @@ declare global {
|
|||||||
const ElMessage: typeof import('element-plus/es')['ElMessage']
|
const ElMessage: typeof import('element-plus/es')['ElMessage']
|
||||||
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
|
const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
|
||||||
const ElNotification: typeof import('element-plus/es')['ElNotification']
|
const ElNotification: typeof import('element-plus/es')['ElNotification']
|
||||||
|
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
|
||||||
const computed: typeof import('vue')['computed']
|
const computed: typeof import('vue')['computed']
|
||||||
const createApp: typeof import('vue')['createApp']
|
const createApp: typeof import('vue')['createApp']
|
||||||
|
const createPinia: typeof import('pinia')['createPinia']
|
||||||
const customRef: typeof import('vue')['customRef']
|
const customRef: typeof import('vue')['customRef']
|
||||||
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
|
||||||
const defineComponent: typeof import('vue')['defineComponent']
|
const defineComponent: typeof import('vue')['defineComponent']
|
||||||
|
const defineStore: typeof import('pinia')['defineStore']
|
||||||
const effectScope: typeof import('vue')['effectScope']
|
const effectScope: typeof import('vue')['effectScope']
|
||||||
|
const getActivePinia: typeof import('pinia')['getActivePinia']
|
||||||
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||||
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||||
const h: typeof import('vue')['h']
|
const h: typeof import('vue')['h']
|
||||||
@ -25,6 +29,11 @@ declare global {
|
|||||||
const isReactive: typeof import('vue')['isReactive']
|
const isReactive: typeof import('vue')['isReactive']
|
||||||
const isReadonly: typeof import('vue')['isReadonly']
|
const isReadonly: typeof import('vue')['isReadonly']
|
||||||
const isRef: typeof import('vue')['isRef']
|
const isRef: typeof import('vue')['isRef']
|
||||||
|
const mapActions: typeof import('pinia')['mapActions']
|
||||||
|
const mapGetters: typeof import('pinia')['mapGetters']
|
||||||
|
const mapState: typeof import('pinia')['mapState']
|
||||||
|
const mapStores: typeof import('pinia')['mapStores']
|
||||||
|
const mapWritableState: typeof import('pinia')['mapWritableState']
|
||||||
const markRaw: typeof import('vue')['markRaw']
|
const markRaw: typeof import('vue')['markRaw']
|
||||||
const nextTick: typeof import('vue')['nextTick']
|
const nextTick: typeof import('vue')['nextTick']
|
||||||
const onActivated: typeof import('vue')['onActivated']
|
const onActivated: typeof import('vue')['onActivated']
|
||||||
@ -48,9 +57,12 @@ declare global {
|
|||||||
const readonly: typeof import('vue')['readonly']
|
const readonly: typeof import('vue')['readonly']
|
||||||
const ref: typeof import('vue')['ref']
|
const ref: typeof import('vue')['ref']
|
||||||
const resolveComponent: typeof import('vue')['resolveComponent']
|
const resolveComponent: typeof import('vue')['resolveComponent']
|
||||||
|
const setActivePinia: typeof import('pinia')['setActivePinia']
|
||||||
|
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
|
||||||
const shallowReactive: typeof import('vue')['shallowReactive']
|
const shallowReactive: typeof import('vue')['shallowReactive']
|
||||||
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
const shallowReadonly: typeof import('vue')['shallowReadonly']
|
||||||
const shallowRef: typeof import('vue')['shallowRef']
|
const shallowRef: typeof import('vue')['shallowRef']
|
||||||
|
const storeToRefs: typeof import('pinia')['storeToRefs']
|
||||||
const toRaw: typeof import('vue')['toRaw']
|
const toRaw: typeof import('vue')['toRaw']
|
||||||
const toRef: typeof import('vue')['toRef']
|
const toRef: typeof import('vue')['toRef']
|
||||||
const toRefs: typeof import('vue')['toRefs']
|
const toRefs: typeof import('vue')['toRefs']
|
||||||
|
@ -103,7 +103,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
UnoCSS(),
|
UnoCSS(),
|
||||||
// 自动按需导入 API
|
// 自动按需导入 API
|
||||||
AutoImport({
|
AutoImport({
|
||||||
imports: ["vue", "vue-router"],
|
imports: ["vue", "vue-router", "pinia"],
|
||||||
dts: "types/auto/auto-imports.d.ts",
|
dts: "types/auto/auto-imports.d.ts",
|
||||||
resolvers: [ElementPlusResolver()]
|
resolvers: [ElementPlusResolver()]
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user