mirror of https://github.com/certd/certd
perf: 优化菜单
parent
d6b91b38f0
commit
1f4f15757d
|
@ -4,6 +4,7 @@ import _ from "lodash-es";
|
||||||
import BScroll from "better-scroll";
|
import BScroll from "better-scroll";
|
||||||
import "./index.less";
|
import "./index.less";
|
||||||
import { utils } from "@fast-crud/fast-crud";
|
import { utils } from "@fast-crud/fast-crud";
|
||||||
|
import { routerUtils } from "/@/utils/util.router";
|
||||||
|
|
||||||
function useBetterScroll(enabled = true) {
|
function useBetterScroll(enabled = true) {
|
||||||
const bsRef = ref(null);
|
const bsRef = ref(null);
|
||||||
|
@ -70,27 +71,8 @@ export default defineComponent({
|
||||||
scroll: {}
|
scroll: {}
|
||||||
},
|
},
|
||||||
setup(props, ctx) {
|
setup(props, ctx) {
|
||||||
async function open(path: any) {
|
async function onSelect(item: any) {
|
||||||
if (path == null) {
|
await routerUtils.open(item.key);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
||||||
window.open(path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const navigationResult = await router.push(path);
|
|
||||||
if (navigationResult) {
|
|
||||||
// 导航被阻止
|
|
||||||
} else {
|
|
||||||
// 导航成功 (包括重新导航的情况)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("导航失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function onSelect(item: any) {
|
|
||||||
open(item.key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fsIcon = resolveComponent("FsIcon");
|
const fsIcon = resolveComponent("FsIcon");
|
||||||
|
|
|
@ -17,7 +17,17 @@
|
||||||
<MenuUnfoldOutlined v-if="asideCollapsed" />
|
<MenuUnfoldOutlined v-if="asideCollapsed" />
|
||||||
<MenuFoldOutlined v-else />
|
<MenuFoldOutlined v-else />
|
||||||
</div>
|
</div>
|
||||||
<fs-menu class="header-menu" mode="horizontal" :expand-selected="false" :selectable="false" :menus="frameworkMenus" />
|
<!-- <fs-menu class="header-menu" mode="horizontal" :expand-selected="false" :selectable="false" :menus="frameworkMenus" />-->
|
||||||
|
<div
|
||||||
|
v-for="menu of resourceStore.authedTopMenus"
|
||||||
|
class="top-menu flex-center header-btn"
|
||||||
|
:class="{ current: resourceStore.currentTopMenu === menu }"
|
||||||
|
:style="{ color: resourceStore.currentTopMenu === menu ? token.colorPrimary : '' }"
|
||||||
|
@click="menuClick(menu)"
|
||||||
|
>
|
||||||
|
<fs-icon :icon="menu.meta.icon"></fs-icon>
|
||||||
|
<span class="ml-5">{{ menu.title }} </span>
|
||||||
|
</div>
|
||||||
<tutorial-button class="flex-center header-btn" />
|
<tutorial-button class="flex-center header-btn" />
|
||||||
<vip-button class="flex-center header-btn" mode="nav" />
|
<vip-button class="flex-center header-btn" mode="nav" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,7 +42,7 @@
|
||||||
<!-- Button-->
|
<!-- Button-->
|
||||||
<!-- </button>-->
|
<!-- </button>-->
|
||||||
<fs-menu
|
<fs-menu
|
||||||
v-if="settingStore?.siteEnv?.agent?.enabled === false && !settingStore.isComm"
|
v-if="!settingStore?.isAgent && !settingStore.isComm"
|
||||||
class="header-menu"
|
class="header-menu"
|
||||||
mode="horizontal"
|
mode="horizontal"
|
||||||
:expand-selected="false"
|
:expand-selected="false"
|
||||||
|
@ -107,6 +117,8 @@ import VipButton from "/@/components/vip-button/index.vue";
|
||||||
import TutorialButton from "/@/components/tutorial/index.vue";
|
import TutorialButton from "/@/components/tutorial/index.vue";
|
||||||
import { useUserStore } from "/@/store/modules/user";
|
import { useUserStore } from "/@/store/modules/user";
|
||||||
import { useSettingStore } from "/@/store/modules/settings";
|
import { useSettingStore } from "/@/store/modules/settings";
|
||||||
|
import { routerUtils } from "/@/utils/util.router";
|
||||||
|
import { theme } from "ant-design-vue";
|
||||||
|
|
||||||
const resourceStore = useResourceStore();
|
const resourceStore = useResourceStore();
|
||||||
const frameworkMenus = computed(() => {
|
const frameworkMenus = computed(() => {
|
||||||
|
@ -150,6 +162,13 @@ const siteInfo = computed(() => {
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await settingStore.checkUrlBound();
|
await settingStore.checkUrlBound();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function menuClick(menu) {
|
||||||
|
routerUtils.open(menu.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { useToken } = theme;
|
||||||
|
const { token } = useToken();
|
||||||
</script>
|
</script>
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@import "../style/theme/index.less";
|
@import "../style/theme/index.less";
|
||||||
|
@ -208,7 +227,7 @@ onMounted(async () => {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
& > * {
|
& > * {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0 10px;
|
padding: 0 15px;
|
||||||
}
|
}
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
@ -219,7 +238,11 @@ onMounted(async () => {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
//border-bottom: 1px solid rgba(255, 255, 255, 0);
|
//border-bottom: 1px solid rgba(255, 255, 255, 0);
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #fff;
|
background-color: rgba(0, 0, 0, 0.06);
|
||||||
|
}
|
||||||
|
&.current {
|
||||||
|
//color: #1890ff;
|
||||||
|
//background-color: hsla(0, 0%, 100%, 0.5) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ export const frameworkResource = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//...crudResources,
|
//...crudResources,
|
||||||
...certdResources
|
...certdResources,
|
||||||
|
...sysResources
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -78,8 +78,7 @@ export const certdResources = [
|
||||||
auth: true,
|
auth: true,
|
||||||
isMenu: false
|
isMenu: false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
...sysResources
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -4,11 +4,10 @@ import { frameworkMenus, headerMenus, filterMenus, findMenus } from "/src/router
|
||||||
import _ from "lodash-es";
|
import _ from "lodash-es";
|
||||||
import { mitter } from "/src/utils/util.mitt";
|
import { mitter } from "/src/utils/util.mitt";
|
||||||
//监听注销事件
|
//监听注销事件
|
||||||
// mitter.on("app.logout", () => {
|
mitter.on("app.logout", () => {
|
||||||
// debugger;
|
const resourceStore = useResourceStore();
|
||||||
// const resourceStore = useResourceStore();
|
resourceStore.clear();
|
||||||
// resourceStore.clear();
|
});
|
||||||
// });
|
|
||||||
//
|
//
|
||||||
// mitter.on("app.login", () => {
|
// mitter.on("app.login", () => {
|
||||||
// const resourceStore = useResourceStore();
|
// const resourceStore = useResourceStore();
|
||||||
|
@ -54,11 +53,17 @@ export const useResourceStore = defineStore({
|
||||||
},
|
},
|
||||||
getFrameworkMenus() {
|
getFrameworkMenus() {
|
||||||
return this.authedTopMenus;
|
return this.authedTopMenus;
|
||||||
|
// const menus = _.cloneDeep(this.authedTopMenus);
|
||||||
|
// for (const menu of menus) {
|
||||||
|
// delete menu.children;
|
||||||
|
// }
|
||||||
|
// return menus;
|
||||||
}
|
}
|
||||||
} as any,
|
} as any,
|
||||||
actions: {
|
actions: {
|
||||||
clear() {
|
clear() {
|
||||||
this.inited = false;
|
this.inited = false;
|
||||||
|
this.currentTopMenu = undefined;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 初始化资源
|
* 初始化资源
|
||||||
|
@ -80,21 +85,22 @@ export const useResourceStore = defineStore({
|
||||||
this.headerMenus = headerMenus;
|
this.headerMenus = headerMenus;
|
||||||
},
|
},
|
||||||
setCurrentTopMenu(topMenu?: any) {
|
setCurrentTopMenu(topMenu?: any) {
|
||||||
if (this.frameworkMenus.length === 0) {
|
if (this.topMenus.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (topMenu == null) {
|
if (topMenu == null) {
|
||||||
topMenu = this.frameworkMenus[0];
|
topMenu = this.topMenus[0];
|
||||||
}
|
}
|
||||||
this.currentTopMenu = topMenu;
|
this.currentTopMenu = topMenu;
|
||||||
},
|
},
|
||||||
setCurrentTopMenuByCurrentRoute(matched: any) {
|
setCurrentTopMenuByCurrentRoute(matched: any) {
|
||||||
const menuHeader = this.frameworkMenus;
|
const menuHeader = this.authedTopMenus;
|
||||||
if (matched?.length <= 1) {
|
if (matched?.length <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findFromTree(tree: any, find: any) {
|
function findFromTree(tree: any, find: any) {
|
||||||
|
tree = tree || [];
|
||||||
const results: Array<any> = [];
|
const results: Array<any> = [];
|
||||||
for (const item of tree) {
|
for (const item of tree) {
|
||||||
if (find(item)) {
|
if (find(item)) {
|
||||||
|
|
|
@ -3,10 +3,12 @@ import * as sites from "./util.site";
|
||||||
import * as storages from "./util.storage";
|
import * as storages from "./util.storage";
|
||||||
import commons from "./util.common";
|
import commons from "./util.common";
|
||||||
import * as mitt from "./util.mitt";
|
import * as mitt from "./util.mitt";
|
||||||
|
import router from "/util.router";
|
||||||
export const util = {
|
export const util = {
|
||||||
...envs,
|
...envs,
|
||||||
...sites,
|
...sites,
|
||||||
...storages,
|
...storages,
|
||||||
...commons,
|
...commons,
|
||||||
...mitt
|
...mitt,
|
||||||
|
...router
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import router from "/@/router";
|
||||||
|
|
||||||
|
async function open(path: any) {
|
||||||
|
if (path == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (path.startsWith("http://") || path.startsWith("https://")) {
|
||||||
|
window.open(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const navigationResult = await router.push(path);
|
||||||
|
if (navigationResult) {
|
||||||
|
// 导航被阻止
|
||||||
|
} else {
|
||||||
|
// 导航成功 (包括重新导航的情况)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("导航失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const routerUtils = {
|
||||||
|
open
|
||||||
|
};
|
Loading…
Reference in New Issue