fix: 解决路由按钮边框显示异常的问题 (#2196)

pull/2202/head
ali-pay 2023-09-06 10:54:24 +08:00 committed by GitHub
parent 4d8118d9ab
commit f0eaee82b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 55 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<el-config-provider :locale="i18nLocale" :button="config" size="default"> <el-config-provider :locale="i18nLocale" :button="config" size="default">
<router-view v-if="isRouterAlive"></router-view> <router-view v-if="isRouterAlive" />
</el-config-provider> </el-config-provider>
</template> </template>
@ -17,17 +17,17 @@ const config = reactive({
autoInsertSpace: false, autoInsertSpace: false,
}); });
const i18nLocale = computed((): any => { const i18nLocale = computed(() => {
if (globalStore.language && globalStore.language == 'zh') return zhCn; if (globalStore.language === 'zh') return zhCn;
if (globalStore.language == 'en') return en; if (globalStore.language === 'en') return en;
return ''; return zhCn;
}); });
let isRouterAlive = ref(true); const isRouterAlive = ref(true);
const reload = () => { const reload = () => {
isRouterAlive.value = false; isRouterAlive.value = false;
nextTick(function () { nextTick(() => {
isRouterAlive.value = true; isRouterAlive.value = true;
}); });
}; };

View File

@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig, Canceler } from 'axios'; import axios, { AxiosRequestConfig, Canceler } from 'axios';
import { isFunction } from '@/utils/is/index'; import { isFunction } from '@vueuse/core';
import qs from 'qs'; import qs from 'qs';
// * 声明一个 Map 用于存储每个请求的标识 和 取消函数 // * 声明一个 Map 用于存储每个请求的标识 和 取消函数
@ -39,7 +39,7 @@ export class AxiosCanceler {
if (pendingMap.has(url)) { if (pendingMap.has(url)) {
// 如果在 pending 中存在当前请求标识,需要取消当前请求,并且移除 // 如果在 pending 中存在当前请求标识,需要取消当前请求,并且移除
const cancel = pendingMap.get(url); const cancel = pendingMap.get(url);
cancel && cancel(); isFunction(cancel) && cancel();
pendingMap.delete(url); pendingMap.delete(url);
} }
} }
@ -49,7 +49,7 @@ export class AxiosCanceler {
*/ */
removeAllPending() { removeAllPending() {
pendingMap.forEach((cancel) => { pendingMap.forEach((cancel) => {
cancel && isFunction(cancel) && cancel(); isFunction(cancel) && cancel();
}); });
pendingMap.clear(); pendingMap.clear();
} }

View File

@ -8,7 +8,7 @@
size="large" size="large"
:key="index" :key="index"
> >
<el-badge :value="button.count" class="item" v-if="button.count > 0" is-dot> <el-badge :value="button.count" v-if="button.count" is-dot>
<span>{{ button.label }}</span> <span>{{ button.label }}</span>
</el-badge> </el-badge>
</el-radio-button> </el-radio-button>
@ -24,13 +24,12 @@ defineOptions({ name: 'RouterButton' });
const props = defineProps({ const props = defineProps({
buttons: { buttons: {
type: Array, type: Array<RouterButton>,
required: true, required: true,
count: Number,
}, },
}); });
const buttonArray: any = computed(() => { const buttonArray = computed(() => {
return props.buttons; return props.buttons;
}); });
@ -44,30 +43,21 @@ const routerToName = (name: string) => {
}; };
const handleChange = (label: string) => { const handleChange = (label: string) => {
buttonArray.value.forEach((btn: RouterButton) => { const btn = buttonArray.value.find((btn) => btn.label === label);
if (btn.label == label) { if (!btn) return;
if (btn.path) { if (btn.path) routerToPath(btn.path);
routerToPath(btn.path); else if (btn.name) routerToName(btn.name);
} else if (btn.name) { activeName.value = btn.label;
routerToName(btn.name);
}
activeName.value = btn.label;
return;
}
});
}; };
onMounted(() => { onMounted(() => {
const nowPath = router.currentRoute.value.path; if (buttonArray.value.length) {
if (buttonArray.value.length > 0) {
let isPathExist = false; let isPathExist = false;
buttonArray.value.forEach((btn: RouterButton) => { const btn = buttonArray.value.find((btn) => btn.path === router.currentRoute.value.path);
if (btn.path == nowPath) { if (btn) {
isPathExist = true; isPathExist = true;
activeName.value = btn.label; activeName.value = btn.label;
return; }
}
});
if (!isPathExist) { if (!isPathExist) {
activeName.value = buttonArray.value[0].label; activeName.value = buttonArray.value[0].label;
} }
@ -77,32 +67,22 @@ onMounted(() => {
<style lang="scss"> <style lang="scss">
.router_card { .router_card {
--el-card-border-radius: 8px;
--el-card-padding: 0; --el-card-padding: 0;
padding: 0px;
padding-bottom: 2px;
padding-top: 2px;
} }
.router_card_button { .router_card_button {
margin-left: 2px;
.el-radio-button__inner { .el-radio-button__inner {
min-width: 100px; min-width: 100px;
height: 100%; height: 100%;
border: 0 !important; background-color: var(--panel-button-active) !important;
box-shadow: none !important;
border: 2px solid transparent !important;
} }
.el-radio-button__original-radio:checked + .el-radio-button__inner { .el-radio-button__original-radio:checked + .el-radio-button__inner {
border-radius: 3px;
color: $primary-color; color: $primary-color;
background-color: var(--panel-button-active); border-color: $primary-color !important;
box-shadow: 0 0 0 2px $primary-color !important; border-radius: 4px;
}
.el-radio-button:first-child .el-radio-button__inner {
border-radius: 3px;
color: $primary-color;
background-color: var(--panel-button-active);
box-shadow: 0 0 0 2px $primary-color !important;
} }
} }
</style> </style>

View File

@ -9,7 +9,7 @@ import '@/styles/style.css';
import directives from '@/directives/index'; import directives from '@/directives/index';
import router from '@/routers/index'; import router from '@/routers/index';
import I18n from '@/lang/index'; import i18n from '@/lang/index';
import pinia from '@/store/index'; import pinia from '@/store/index';
import SvgIcon from './components/svg-icon/svg-icon.vue'; import SvgIcon from './components/svg-icon/svg-icon.vue';
import Components from '@/components'; import Components from '@/components';
@ -21,14 +21,14 @@ const app = createApp(App);
app.component('SvgIcon', SvgIcon); app.component('SvgIcon', SvgIcon);
app.use(ElementPlus); app.use(ElementPlus);
app.use(Fit2CloudPlus, { locale: I18n.global.messages.value[localStorage.getItem('lang') || 'zh'] }); app.use(Fit2CloudPlus, { locale: i18n.global.messages.value[localStorage.getItem('lang') || 'zh'] });
Object.keys(Icons).forEach((key) => { Object.keys(Icons).forEach((key) => {
app.component(key, Icons[key as keyof typeof Icons]); app.component(key, Icons[key as keyof typeof Icons]);
}); });
app.use(router); app.use(router);
app.use(I18n); app.use(i18n);
app.use(pinia); app.use(pinia);
app.use(directives); app.use(directives);
app.use(Components); app.use(Components);

View File

@ -7,11 +7,11 @@ import { routerArray } from '@/routers/router';
* @param {Array} _cache * @param {Array} _cache
* @return void * @return void
* */ * */
let cacheRouter: any[] = []; let cacheRouter: RouteRecordName[] = [];
const filterKeepAlive = (_route: RouteRecordRaw[], _cache: RouteRecordName[]): void => { const filterKeepAlive = (_route: RouteRecordRaw[], _cache: RouteRecordName[]): void => {
_route.forEach((item) => { _route.forEach((item) => {
item.meta?.keepAlive && item.name && _cache.push(item.name); item.meta?.keepAlive && item.name && _cache.push(item.name);
item.children && item.children.length !== 0 && filterKeepAlive(item.children, _cache); item?.children?.length && filterKeepAlive(item.children, _cache);
}); });
}; };

View File

@ -26,4 +26,5 @@ declare interface RouterButton {
label: string; label: string;
path?: string; path?: string;
name?: string; name?: string;
count?: number;
} }