简化了 pinia 的定义和导入方式;
This commit is contained in:
parent
e68652fe4c
commit
4a2591a590
14
src/App.vue
14
src/App.vue
|
|
@ -1,9 +1,9 @@
|
|||
<template>
|
||||
<el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
|
||||
<router-view v-show="setLockScreen" />
|
||||
<LockScreen v-if="themeConfig.isLockScreen" />
|
||||
<LockScreen v-if="storesThemeConfig.themeConfig.isLockScreen" />
|
||||
<Setings ref="setingsRef" v-show="setLockScreen" />
|
||||
<CloseFull v-if="!themeConfig.isLockScreen" />
|
||||
<CloseFull v-if="!storesThemeConfig.themeConfig.isLockScreen" />
|
||||
<Upgrade v-if="getVersion" />
|
||||
<Sponsors />
|
||||
</el-config-provider>
|
||||
|
|
@ -13,9 +13,8 @@
|
|||
import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/tagsViewRoutes';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import other from '/@/utils/other';
|
||||
import { Local, Session } from '/@/utils/storage';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
|
|
@ -32,15 +31,12 @@ const Sponsors = defineAsyncComponent(() => import('/@/layout/sponsors/index.vue
|
|||
const { messages, locale } = useI18n();
|
||||
const setingsRef = ref();
|
||||
const route = useRoute();
|
||||
const stores = useTagsViewRoutes();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
|
||||
// 设置锁屏时组件显示隐藏
|
||||
const setLockScreen = computed(() => {
|
||||
// 防止锁屏后,刷新出现不相关界面
|
||||
// https://gitee.com/lyt-top/vue-next-admin/issues/I6AF8P
|
||||
return themeConfig.value.isLockScreen ? themeConfig.value.lockScreenTime > 1 : themeConfig.value.lockScreenTime >= 0;
|
||||
return storesThemeConfig.themeConfig.isLockScreen ? storesThemeConfig.themeConfig.lockScreenTime > 1 : storesThemeConfig.themeConfig.lockScreenTime >= 0;
|
||||
});
|
||||
// 获取版本号
|
||||
const getVersion = computed(() => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
import { createI18n } from 'vue-i18n';
|
||||
import pinia from '/@/stores/index';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/themeConfig';
|
||||
|
||||
// 定义语言国际化内容
|
||||
|
||||
|
|
@ -14,9 +12,9 @@ import { useThemeConfig } from '/@/stores/themeConfig';
|
|||
*/
|
||||
|
||||
// element plus 自带国际化
|
||||
import enLocale from 'element-plus/lib/locale/lang/en';
|
||||
import zhcnLocale from 'element-plus/lib/locale/lang/zh-cn';
|
||||
import zhtwLocale from 'element-plus/lib/locale/lang/zh-tw';
|
||||
import enLocale from 'element-plus/es/locale/lang/en';
|
||||
import zhcnLocale from 'element-plus/es/locale/lang/zh-cn';
|
||||
import zhtwLocale from 'element-plus/es/locale/lang/zh-tw';
|
||||
|
||||
// 定义变量内容
|
||||
const messages = {};
|
||||
|
|
@ -50,10 +48,6 @@ for (const key in itemize) {
|
|||
};
|
||||
}
|
||||
|
||||
// 读取 pinia 默认语言
|
||||
const stores = useThemeConfig(pinia);
|
||||
const { themeConfig } = storeToRefs(stores);
|
||||
|
||||
// 导出语言国际化
|
||||
// https://vue-i18n.intlify.dev/guide/essentials/fallback.html#explicit-fallback-with-one-locale
|
||||
export const i18n = createI18n({
|
||||
|
|
@ -62,7 +56,7 @@ export const i18n = createI18n({
|
|||
missingWarn: false,
|
||||
silentFallbackWarn: true,
|
||||
fallbackWarn: false,
|
||||
locale: themeConfig.value.globalI18n,
|
||||
locale: stores.themeConfig.globalI18n,
|
||||
fallbackLocale: zhcnLocale.name,
|
||||
messages,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
<script setup lang="ts" name="layoutAside">
|
||||
import { defineAsyncComponent, reactive, computed, watch, onBeforeMount, ref } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import stores from '/@/stores/routesList';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import storesTagsViewRoutes from '/@/stores/tagsViewRoutes';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
|
||||
// 引入组件
|
||||
|
|
@ -23,9 +23,6 @@ const Vertical = defineAsyncComponent(() => import('/@/layout/navMenu/vertical.v
|
|||
|
||||
// 定义变量内容
|
||||
const layoutAsideScrollbarRef = ref();
|
||||
const stores = useRoutesList();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const storesTagsViewRoutes = useTagsViewRoutes();
|
||||
const { routesList } = storeToRefs(stores);
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
|
||||
|
|
|
|||
|
|
@ -7,12 +7,11 @@
|
|||
<script setup lang="ts" name="layoutHeader">
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import storesTagsViewRoutes from '/@/stores/tagsViewRoutes';
|
||||
|
||||
// 引入组件
|
||||
const NavBarsIndex = defineAsyncComponent(() => import('/@/layout/navBars/index.vue'));
|
||||
|
||||
// 定义变量内容
|
||||
const storesTagsViewRoutes = useTagsViewRoutes();
|
||||
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
import { defineAsyncComponent, onMounted, computed, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesTagsViewRoutes from '/@/stores/tagsViewRoutes';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
|
||||
// 引入组件
|
||||
|
|
@ -28,8 +28,6 @@ const LayoutFooter = defineAsyncComponent(() => import('/@/layout/footer/index.v
|
|||
// 定义变量内容
|
||||
const layoutMainScrollbarRef = ref();
|
||||
const route = useRoute();
|
||||
const storesTagsViewRoutes = useTagsViewRoutes();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<script setup lang="ts" name="layout">
|
||||
import { onBeforeMount, onUnmounted, defineAsyncComponent } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { Local } from '/@/utils/storage';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
|
||||
|
|
@ -18,7 +18,6 @@ const layouts: any = {
|
|||
};
|
||||
|
||||
// 定义变量内容
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
|
||||
// 窗口大小改变时(适配移动端)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
import { defineAsyncComponent, watch, onMounted, nextTick, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
|
||||
// 引入组件
|
||||
|
|
@ -26,7 +26,6 @@ const LayoutMain = defineAsyncComponent(() => import('/@/layout/component/main.v
|
|||
const layoutScrollbarRef = ref<RefType>('');
|
||||
const layoutMainRef = ref<InstanceType<typeof LayoutMain>>();
|
||||
const route = useRoute();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
|
||||
// 重置滚动条高度
|
||||
|
|
|
|||
|
|
@ -8,14 +8,13 @@
|
|||
<script setup lang="ts" name="layoutNavBars">
|
||||
import { defineAsyncComponent, computed } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
|
||||
// 引入组件
|
||||
const BreadcrumbIndex = defineAsyncComponent(() => import('/@/layout/navBars/topBar/index.vue'));
|
||||
const TagsView = defineAsyncComponent(() => import('/@/layout/navBars/tagsView/tagsView.vue'));
|
||||
|
||||
// 定义变量内容
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
|
||||
// 是否显示 tagsView
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ import { useRoute, useRouter, onBeforeRouteUpdate } from 'vue-router';
|
|||
import Sortable from 'sortablejs';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import { useKeepALiveNames } from '/@/stores/keepAliveNames';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import storesTagsViewRoutes from '/@/stores/tagsViewRoutes';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import storesKeepALiveNames from '/@/stores/keepAliveNames';
|
||||
import storesRoutesList from '/@/stores/routesList';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { isObjectValueEqual } from '/@/utils/arrayOperation';
|
||||
import other from '/@/utils/other';
|
||||
|
|
@ -69,14 +69,9 @@ const tagsRefs = ref<RefType>([]);
|
|||
const scrollbarRef = ref();
|
||||
const contextmenuRef = ref();
|
||||
const tagsUlRef = ref();
|
||||
const stores = useTagsViewRoutes();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const storesTagsViewRoutes = useTagsViewRoutes();
|
||||
const storesRoutesList = useRoutesList();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { tagsViewRoutes } = storeToRefs(storesTagsViewRoutes);
|
||||
const { routesList } = storeToRefs(storesRoutesList);
|
||||
const storesKeepALiveNames = useKeepALiveNames();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const state = reactive<TagsViewState>({
|
||||
|
|
@ -314,7 +309,7 @@ const openCurrenFullscreen = async (path: string) => {
|
|||
const item = state.tagsViewList.find((v: RouteItem) => (getThemeConfig.value.isShareTagsView ? v.path === path : v.url === path));
|
||||
if (item.meta.isDynamic) await router.push({ name: item.name, params: item.params });
|
||||
else await router.push({ name: item.name, query: item.query });
|
||||
stores.setCurrenFullscreen(true);
|
||||
storesTagsViewRoutes.setCurrenFullscreen(true);
|
||||
};
|
||||
// 当前项右键菜单点击,拿 `当前点击的路由路径` 对比 `tagsView 路由数组`,取当前点击项的详细路由信息
|
||||
// 防止 tagsView 非当前页演示时,操作异常
|
||||
|
|
|
|||
|
|
@ -29,12 +29,10 @@ import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router';
|
|||
import { Local } from '/@/utils/storage';
|
||||
import other from '/@/utils/other';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/routesList';
|
||||
|
||||
// 定义变量内容
|
||||
const stores = useRoutesList();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { routesList } = storeToRefs(stores);
|
||||
const route = useRoute();
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@
|
|||
|
||||
<script setup lang="ts" name="layoutCloseFull">
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import stores from '/@/stores/tagsViewRoutes';
|
||||
|
||||
// 定义变量内容
|
||||
const stores = useTagsViewRoutes();
|
||||
const { isTagsViewCurrenFull } = storeToRefs(stores);
|
||||
|
||||
// 关闭当前全屏
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
import { defineAsyncComponent, computed, reactive, onMounted, onUnmounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/routesList';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
|
||||
// 引入组件
|
||||
|
|
@ -22,8 +22,6 @@ const Logo = defineAsyncComponent(() => import('/@/layout/logo/index.vue'));
|
|||
const Horizontal = defineAsyncComponent(() => import('/@/layout/navMenu/horizontal.vue'));
|
||||
|
||||
// 定义变量内容
|
||||
const stores = useRoutesList();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { routesList } = storeToRefs(stores);
|
||||
const route = useRoute();
|
||||
|
|
|
|||
|
|
@ -32,10 +32,9 @@ import { reactive, ref, nextTick } from 'vue';
|
|||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import storesTagsViewRoutes from '/@/stores/tagsViewRoutes';
|
||||
|
||||
// 定义变量内容
|
||||
const storesTagsViewRoutes = useTagsViewRoutes();
|
||||
const { tagsViewRoutes } = storeToRefs(storesTagsViewRoutes);
|
||||
const layoutMenuAutocompleteRef = ref();
|
||||
const { t } = useI18n();
|
||||
|
|
|
|||
|
|
@ -434,7 +434,7 @@ import { nextTick, onUnmounted, onMounted, computed, reactive } from 'vue';
|
|||
import { ElMessage } from 'element-plus';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { useChangeColor } from '/@/utils/theme';
|
||||
import { verifyAndSpace } from '/@/utils/toolsValidate';
|
||||
import { Local } from '/@/utils/storage';
|
||||
|
|
@ -445,7 +445,6 @@ import mittBus from '/@/utils/mitt';
|
|||
|
||||
// 定义变量内容
|
||||
const { locale } = useI18n();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { copyText } = commonFunction();
|
||||
const { getLightColor, getDarkColor } = useChangeColor();
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ import screenfull from 'screenfull';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import other from '/@/utils/other';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
import { Session, Local } from '/@/utils/storage';
|
||||
|
|
@ -108,7 +108,6 @@ const userNewsBadgeRef = ref();
|
|||
const { locale, t } = useI18n();
|
||||
const router = useRouter();
|
||||
const stores = useUserInfo();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { userInfos } = storeToRefs(stores);
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const searchRef = ref();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
import { defineAsyncComponent, reactive, computed, onMounted, watch } from 'vue';
|
||||
import { useRoute, onBeforeRouteUpdate, RouteRecordRaw } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import other from '/@/utils/other';
|
||||
|
||||
// 引入组件
|
||||
|
|
@ -50,7 +50,6 @@ const props = defineProps({
|
|||
});
|
||||
|
||||
// 定义变量内容
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const route = useRoute();
|
||||
const state = reactive({
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
import { defineAsyncComponent, computed, reactive, onBeforeMount, onUnmounted, nextTick, watch, onMounted } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useKeepALiveNames } from '/@/stores/keepAliveNames';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesKeepAliveNames from '/@/stores/keepAliveNames';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
|
||||
|
|
@ -28,8 +28,6 @@ const Iframes = defineAsyncComponent(() => import('/@/layout/routerView/iframes.
|
|||
// 定义变量内容
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const storesKeepAliveNames = useKeepALiveNames();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { keepAliveNames, cachedViews } = storeToRefs(storesKeepAliveNames);
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const state = reactive<ParentViewState>({
|
||||
|
|
|
|||
|
|
@ -35,12 +35,11 @@
|
|||
import { reactive, computed, onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { Local } from '/@/utils/storage';
|
||||
|
||||
// 定义变量内容
|
||||
const { t } = useI18n();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const state = reactive({
|
||||
isUpgrade: false,
|
||||
|
|
|
|||
13
src/main.ts
13
src/main.ts
|
|
@ -1,9 +1,9 @@
|
|||
import { createApp } from 'vue';
|
||||
import pinia from '/@/stores/index';
|
||||
import pinia from '/@/stores/pinia';
|
||||
import App from '/@/App.vue';
|
||||
import router from '/@/router';
|
||||
import { directive } from '/@/directive/index';
|
||||
import { i18n } from '/@/i18n/index';
|
||||
import { directive } from '/@/directive';
|
||||
import { i18n } from '/@/i18n';
|
||||
import other from '/@/utils/other';
|
||||
|
||||
import ElementPlus from 'element-plus';
|
||||
|
|
@ -15,4 +15,9 @@ const app = createApp(App);
|
|||
directive(app);
|
||||
other.elSvg(app);
|
||||
|
||||
app.use(pinia).use(router).use(ElementPlus).use(i18n).use(VueGridLayout).mount('#app');
|
||||
app.use(pinia)
|
||||
.use(router)
|
||||
.use(ElementPlus)
|
||||
.use(i18n)
|
||||
.use(VueGridLayout)
|
||||
.mount('#app');
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import pinia from '/@/stores/index';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { useRequestOldRoutes } from '/@/stores/requestOldRoutes';
|
||||
import storeRequestOldRoutes from '/@/stores/requestOldRoutes';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
import { dynamicRoutes, notFoundAndNoPower } from '/@/router/route';
|
||||
import { formatTwoStageRoutes, formatFlatteningRoutes, router } from '/@/router/index';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import { useMenuApi } from '/@/api/menu/index';
|
||||
import storesRoutesList from '/@/stores/routesList';
|
||||
import storesTagsView from '/@/stores/tagsViewRoutes';
|
||||
import { useMenuApi } from '/@/api/menu';
|
||||
|
||||
// 后端控制路由
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...lay
|
|||
* 后端控制路由:初始化方法,防止刷新时路由丢失
|
||||
* @method NextLoading 界面 loading 动画开始执行
|
||||
* @method useUserInfo().setUserInfos() 触发初始化用户信息 pinia
|
||||
* @method useRequestOldRoutes().setRequestOldRoutes() 存储接口原始路由(未处理component),根据需求选择使用
|
||||
* @method storeRequestOldRoutes.setRequestOldRoutes() 存储接口原始路由(未处理component),根据需求选择使用
|
||||
* @method setAddRoute 添加动态路由
|
||||
* @method setFilterMenuAndCacheTagsViewRoutes 设置路由到 pinia routesList 中(已处理成多级嵌套路由)及缓存多级嵌套数组处理后的一维数组
|
||||
*/
|
||||
|
|
@ -47,7 +46,7 @@ export async function initBackEndControlRoutes() {
|
|||
// https://gitee.com/lyt-top/vue-next-admin/issues/I64HVO
|
||||
if (res.data.length <= 0) return Promise.resolve(true);
|
||||
// 存储接口原始路由(未处理component),根据需求选择使用
|
||||
useRequestOldRoutes().setRequestOldRoutes(JSON.parse(JSON.stringify(res.data)));
|
||||
storeRequestOldRoutes.setRequestOldRoutes(JSON.parse(JSON.stringify(res.data)));
|
||||
// 处理路由(component),替换 dynamicRoutes(/@/router/route)第一个顶级 children 的路由
|
||||
dynamicRoutes[0].children = await backEndComponent(res.data);
|
||||
// 添加动态路由
|
||||
|
|
@ -62,7 +61,6 @@ export async function initBackEndControlRoutes() {
|
|||
* @description 用于 tagsView、菜单搜索中:未过滤隐藏的(isHide)
|
||||
*/
|
||||
export async function setFilterMenuAndCacheTagsViewRoutes() {
|
||||
const storesRoutesList = useRoutesList(pinia);
|
||||
storesRoutesList.setRoutesList(dynamicRoutes[0].children as any);
|
||||
setCacheTagsViewRoutes();
|
||||
}
|
||||
|
|
@ -72,7 +70,6 @@ export async function setFilterMenuAndCacheTagsViewRoutes() {
|
|||
* @description 用于 tagsView、菜单搜索中:未过滤隐藏的(isHide)
|
||||
*/
|
||||
export function setCacheTagsViewRoutes() {
|
||||
const storesTagsView = useTagsViewRoutes(pinia);
|
||||
storesTagsView.setTagsViewRoutes(formatTwoStageRoutes(formatFlatteningRoutes(dynamicRoutes))[0].children);
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +105,7 @@ export async function setAddRoute() {
|
|||
*/
|
||||
export function getBackEndControlRoutes() {
|
||||
// 模拟 admin 与 test
|
||||
const stores = useUserInfo(pinia);
|
||||
const stores = useUserInfo();
|
||||
const { userInfos } = storeToRefs(stores);
|
||||
const auth = userInfos.value.roles[0];
|
||||
// 管理员 admin
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ import { RouteRecordRaw } from 'vue-router';
|
|||
import { storeToRefs } from 'pinia';
|
||||
import { formatTwoStageRoutes, formatFlatteningRoutes, router } from '/@/router/index';
|
||||
import { dynamicRoutes, notFoundAndNoPower } from '/@/router/route';
|
||||
import pinia from '/@/stores/index';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { useUserInfo } from '/@/stores/userInfo';
|
||||
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import storesTagsView from '/@/stores/tagsViewRoutes';
|
||||
import storesRoutesList from '/@/stores/routesList';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
|
||||
// 前端控制路由
|
||||
|
|
@ -25,7 +24,7 @@ export async function initFrontEndControlRoutes() {
|
|||
if (!Session.get('token')) return false;
|
||||
// 触发初始化用户信息 pinia
|
||||
// https://gitee.com/lyt-top/vue-next-admin/issues/I5F1HP
|
||||
await useUserInfo(pinia).setUserInfos();
|
||||
await useUserInfo().setUserInfos();
|
||||
// 无登录权限时,添加判断
|
||||
// https://gitee.com/lyt-top/vue-next-admin/issues/I64HVO
|
||||
if (useUserInfo().userInfos.roles.length <= 0) return Promise.resolve(true);
|
||||
|
|
@ -81,7 +80,7 @@ export function setFilterRouteEnd() {
|
|||
* @returns 返回有当前用户权限标识的路由数组
|
||||
*/
|
||||
export function setFilterRoute(chil: any) {
|
||||
const stores = useUserInfo(pinia);
|
||||
const stores = useUserInfo();
|
||||
const { userInfos } = storeToRefs(stores);
|
||||
let filterRoute: any = [];
|
||||
chil.forEach((route: any) => {
|
||||
|
|
@ -102,8 +101,7 @@ export function setFilterRoute(chil: any) {
|
|||
*/
|
||||
export function setCacheTagsViewRoutes() {
|
||||
// 获取有权限的路由,否则 tagsView、菜单搜索中无权限的路由也将显示
|
||||
const stores = useUserInfo(pinia);
|
||||
const storesTagsView = useTagsViewRoutes(pinia);
|
||||
const stores = useUserInfo();
|
||||
const { userInfos } = storeToRefs(stores);
|
||||
let rolesRoutes = setFilterHasRolesMenu(dynamicRoutes, userInfos.value.roles);
|
||||
// 添加到 pinia setTagsViewRoutes 中
|
||||
|
|
@ -116,8 +114,7 @@ export function setCacheTagsViewRoutes() {
|
|||
* @description 用于 tagsView、菜单搜索中:未过滤隐藏的(isHide)
|
||||
*/
|
||||
export function setFilterMenuAndCacheTagsViewRoutes() {
|
||||
const stores = useUserInfo(pinia);
|
||||
const storesRoutesList = useRoutesList(pinia);
|
||||
const stores = useUserInfo();
|
||||
const { userInfos } = storeToRefs(stores);
|
||||
storesRoutesList.setRoutesList(setFilterHasRolesMenu(dynamicRoutes[0].children, userInfos.value.roles));
|
||||
setCacheTagsViewRoutes();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
import NProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
import pinia from '/@/stores/index';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useKeepALiveNames } from '/@/stores/keepAliveNames';
|
||||
import { useRoutesList } from '/@/stores/routesList';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/keepAliveNames';
|
||||
import storesRoutesList from '/@/stores/routesList';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { staticRoutes, notFoundAndNoPower } from '/@/router/route';
|
||||
import { initFrontEndControlRoutes } from '/@/router/frontEnd';
|
||||
|
|
@ -21,7 +20,6 @@ import { initBackEndControlRoutes } from '/@/router/backEnd';
|
|||
*/
|
||||
|
||||
// 读取 `/src/stores/themeConfig.ts` 是否开启后端控制路由配置
|
||||
const storesThemeConfig = useThemeConfig(pinia);
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const { isRequestRoutes } = themeConfig.value;
|
||||
|
||||
|
|
@ -82,7 +80,6 @@ export function formatTwoStageRoutes(arr: any) {
|
|||
// 路径:/@/layout/routerView/parent.vue
|
||||
if (newArr[0].meta.isKeepAlive && v.meta.isKeepAlive) {
|
||||
cacheList.push(v.name);
|
||||
const stores = useKeepALiveNames(pinia);
|
||||
stores.setCacheKeepAlive(cacheList);
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +104,6 @@ router.beforeEach(async (to, from, next) => {
|
|||
next('/home');
|
||||
NProgress.done();
|
||||
} else {
|
||||
const storesRoutesList = useRoutesList(pinia);
|
||||
const { routesList } = storeToRefs(storesRoutesList);
|
||||
if (routesList.value.length === 0) {
|
||||
if (isRequestRoutes) {
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
// https://pinia.vuejs.org/
|
||||
import { createPinia } from 'pinia';
|
||||
|
||||
// 创建
|
||||
const pinia = createPinia();
|
||||
|
||||
// 导出
|
||||
export default pinia;
|
||||
|
|
@ -8,7 +8,7 @@ import { defineStore } from 'pinia';
|
|||
* @methods delOthersCachedViews 右键菜单`关闭其它`,删除要缓存的路由 names(关闭 Tagsview)
|
||||
* @methods delAllCachedViews 右键菜单`全部关闭`,删除要缓存的路由 names(关闭 Tagsview)
|
||||
*/
|
||||
export const useKeepALiveNames = defineStore('keepALiveNames', {
|
||||
let define = defineStore('keepALiveNames', {
|
||||
state: (): KeepAliveNamesState => ({
|
||||
keepAliveNames: [],
|
||||
cachedViews: [],
|
||||
|
|
@ -33,3 +33,5 @@ export const useKeepALiveNames = defineStore('keepALiveNames', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default define()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import {createPinia, setActivePinia} from 'pinia'
|
||||
|
||||
let pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
|
||||
export default pinia
|
||||
|
|
@ -4,7 +4,7 @@ import { defineStore } from 'pinia';
|
|||
* 后端返回原始路由(未处理时)
|
||||
* @methods setCacheKeepAlive 设置接口原始路由数据
|
||||
*/
|
||||
export const useRequestOldRoutes = defineStore('requestOldRoutes', {
|
||||
let define = defineStore('requestOldRoutes', {
|
||||
state: (): RequestOldRoutesState => ({
|
||||
requestOldRoutes: [],
|
||||
}),
|
||||
|
|
@ -14,3 +14,5 @@ export const useRequestOldRoutes = defineStore('requestOldRoutes', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default define()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { defineStore } from 'pinia';
|
|||
* @methods setColumnsMenuHover 设置分栏布局菜单鼠标移入 boolean
|
||||
* @methods setColumnsNavHover 设置分栏布局最左侧导航鼠标移入 boolean
|
||||
*/
|
||||
export const useRoutesList = defineStore('routesList', {
|
||||
let define = defineStore('routesList', {
|
||||
state: (): RoutesListState => ({
|
||||
routesList: [],
|
||||
isColumnsMenuHover: false,
|
||||
|
|
@ -24,3 +24,5 @@ export const useRoutesList = defineStore('routesList', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default define()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { Session } from '/@/utils/storage';
|
|||
* @methods setTagsViewRoutes 设置 TagsView 路由列表
|
||||
* @methods setCurrenFullscreen 设置开启/关闭全屏时的 boolean 状态
|
||||
*/
|
||||
export const useTagsViewRoutes = defineStore('tagsViewRoutes', {
|
||||
let define = defineStore('tagsViewRoutes', {
|
||||
state: (): TagsViewRoutesState => ({
|
||||
tagsViewRoutes: [],
|
||||
isTagsViewCurrenFull: false,
|
||||
|
|
@ -21,3 +21,5 @@ export const useTagsViewRoutes = defineStore('tagsViewRoutes', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default define()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { defineStore } from 'pinia';
|
|||
* 1、需要每次都清理 `window.localStorage` 浏览器永久缓存
|
||||
* 2、或者点击布局配置最底部 `一键恢复默认` 按钮即可看到效果
|
||||
*/
|
||||
export const useThemeConfig = defineStore('themeConfig', {
|
||||
let define = defineStore('themeConfig', {
|
||||
state: (): ThemeConfigState => ({
|
||||
themeConfig: {
|
||||
// 是否开启布局配置抽屉
|
||||
|
|
@ -154,3 +154,5 @@ export const useThemeConfig = defineStore('themeConfig', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default define()
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ import { nextTick, defineAsyncComponent } from 'vue';
|
|||
import type { App } from 'vue';
|
||||
import * as svg from '@element-plus/icons-vue';
|
||||
import router from '/@/router/index';
|
||||
import pinia from '/@/stores/index';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import stores from '/@/stores/themeConfig';
|
||||
import { i18n } from '/@/i18n/index';
|
||||
import { Local } from '/@/utils/storage';
|
||||
import { verifyUrl } from '/@/utils/toolsValidate';
|
||||
|
|
@ -30,7 +29,6 @@ export function elSvg(app: App) {
|
|||
* @method const title = useTitle(); ==> title()
|
||||
*/
|
||||
export function useTitle() {
|
||||
const stores = useThemeConfig(pinia);
|
||||
const { themeConfig } = storeToRefs(stores);
|
||||
nextTick(() => {
|
||||
let webTitle = '';
|
||||
|
|
@ -101,7 +99,6 @@ export const lazyImg = (el: string, arr: EmptyArrayType) => {
|
|||
* @returns 返回 `window.localStorage` 中读取的缓存值 `globalComponentSize`
|
||||
*/
|
||||
export const globalComponentSize = (): string => {
|
||||
const stores = useThemeConfig(pinia);
|
||||
const { themeConfig } = storeToRefs(stores);
|
||||
return Local.get('themeConfig')?.globalComponentSize || themeConfig.value?.globalComponentSize;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ import { ElMessage } from 'element-plus';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import Cookies from 'js-cookie';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { initFrontEndControlRoutes } from '/@/router/frontEnd';
|
||||
import { initBackEndControlRoutes } from '/@/router/backEnd';
|
||||
import { Session } from '/@/utils/storage';
|
||||
|
|
@ -71,7 +71,6 @@ import { NextLoading } from '/@/utils/loading';
|
|||
|
||||
// 定义变量内容
|
||||
const { t } = useI18n();
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
<script setup lang="ts" name="loginIndex">
|
||||
import { defineAsyncComponent, onMounted, reactive, computed } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useThemeConfig } from '/@/stores/themeConfig';
|
||||
import storesThemeConfig from '/@/stores/themeConfig';
|
||||
import { NextLoading } from '/@/utils/loading';
|
||||
import logoMini from '/@/assets/logo-mini.svg';
|
||||
import loginMain from '/@/assets/login-main.svg';
|
||||
|
|
@ -57,7 +57,6 @@ const Mobile = defineAsyncComponent(() => import('/@/views/login/component/mobil
|
|||
const Scan = defineAsyncComponent(() => import('/@/views/login/component/scan.vue'));
|
||||
|
||||
// 定义变量内容
|
||||
const storesThemeConfig = useThemeConfig();
|
||||
const { themeConfig } = storeToRefs(storesThemeConfig);
|
||||
const state = reactive({
|
||||
tabsActiveName: 'account',
|
||||
|
|
|
|||
Loading…
Reference in New Issue