This commit is contained in:
qiuyuan 2025-12-30 14:00:43 +08:00
parent bf8c5e1cc1
commit 98ccb19fbe
3 changed files with 113 additions and 53 deletions

View File

@ -201,6 +201,12 @@ const routes: RouteRecordRaw[] = [
component: () =>
import("@/views/admin/account/cost/myMoney/index.vue"),
},
{
path: "myMoneyDetail",
name: "myMoneyDetail",
component: () =>
import("@/views/admin/account/cost/myMoneyDetail/index.vue"),
},
{
path: "voucher",
name: "voucher",

View File

@ -65,12 +65,14 @@
<!-- 账单表格 -->
<a-table
:columns="columns"
:data-source="billData"
:pagination="pagination"
@change="handleTableChange"
:loading="loading"
class="bill-table"
:columns="columns"
:data-source="billData"
:pagination="pagination"
@change="handleTableChange"
:loading="loading"
class="bill-table"
:scroll="{ x: 1200 }"
>
<!-- 流水号列 -->
<template #bodyCell="{ column, record }">

View File

@ -22,15 +22,15 @@ import { h, reactive, computed } from 'vue';
import { useRouter } from 'vue-router';
import {
HomeOutlined,
FolderOpenOutlined,
ConsoleSqlOutlined,
GlobalOutlined,
LaptopOutlined,
MoneyCollectOutlined,
TeamOutlined,
} from '@ant-design/icons-vue';
import type { MenuMode, MenuTheme } from 'ant-design-vue';
import { ItemType } from 'ant-design-vue';
// ItemType 使 Ant Design Vue MenuItem
import type { MenuProps } from 'ant-design-vue';
const router = useRouter();
@ -39,39 +39,40 @@ interface MenuItem {
path: string;
name: string;
icon?: any;
disabled?: boolean; //
children?: Omit<MenuItem, 'icon'>[]; // icon
disabled?: boolean;
visible?: boolean;
children?: Omit<MenuItem, 'icon'>[];
}
const menuItems: MenuItem[] = [
{ path: '/layout/admin/home', name: '总览', icon: HomeOutlined },
{ path: '/layout/admin/instance', name: '容器实例', icon: ConsoleSqlOutlined },
// { path: '/layout/admin/fileStore', name: '', icon: FolderOpenOutlined },
{ path: '/layout/admin/image', name: '镜像', icon: GlobalOutlined },
// { path: '/layout/publicData', name: '', icon: LaptopOutlined },
{ path: '/layout/admin/home', name: '总览', icon: HomeOutlined, visible: true },
{ path: '/layout/admin/instance', name: '容器实例', icon: ConsoleSqlOutlined, visible: true },
{ path: '/layout/admin/image', name: '镜像', icon: GlobalOutlined, visible: true },
{
path: '',
name: '费用',
icon: MoneyCollectOutlined,
visible: true,
children: [
// { path: '/layout/admin/costDetail', name: '' },
{ path: '/layout/admin/myMoney', name: '费用总览' },
{ path: '/layout/admin/myOrder', name: '我的订单' },
{ path: '/layout/admin/flow', name: '账单明细' },
{ path: '/layout/admin/coupon', name: '优惠券(待开发)', disabled: true },
{ path: '/layout/admin/invoice', name: '发票(待开发)', disabled: true },
{ path: '/layout/admin/voucher', name: '代金券(待开发)', disabled: true },
{ path: '/layout/admin/contract', name: '合同(待开发)', disabled: true },
{ path: '/layout/admin/myMoney', name: '费用总览', visible: true, disabled: false },
//
{ path: '/layout/admin/myMoneyDetail', name: '消费明细', visible: false, disabled: false },
{ path: '/layout/admin/myOrder', name: '我的订单', visible: true, disabled: false },
{ path: '/layout/admin/flow', name: '账单明细', visible: true, disabled: false },
{ path: '/layout/admin/coupon', name: '优惠券(待开发)', disabled: true, visible: true },
{ path: '/layout/admin/invoice', name: '发票(待开发)', disabled: true, visible: true },
{ path: '/layout/admin/voucher', name: '代金券(待开发)', disabled: true, visible: true },
{ path: '/layout/admin/contract', name: '合同(待开发)', disabled: true, visible: true },
],
},
{
path: '',
name: '账号',
icon: TeamOutlined,
visible: true,
children: [
{ path: '/layout/admin/security', name: '账号安全' },
{ path: '/layout/admin/history', name: '访问记录' },
// { path: '/controlPanel/security', name: '' },
{ path: '/layout/admin/security', name: '账号安全', visible: true },
{ path: '/layout/admin/history', name: '访问记录', visible: true },
],
},
];
@ -84,60 +85,111 @@ const state = reactive({
openKeys: ['/controlPanel/fee', '/controlPanel/account'],
});
// 使 MenuProps['items']
// MenuItemType
type MenuItemType = NonNullable<MenuProps['items']>[number];
//
function getItem(
label: string,
key: string,
icon?: any,
children?: ItemType[],
children?: MenuItemType[],
type?: 'group',
disabled?: boolean // disabled
): ItemType {
disabled?: boolean
): MenuItemType | null {
return {
key,
icon,
children,
label,
type,
disabled, // disabled
} as ItemType;
disabled,
} as MenuItemType;
}
// menuItems a-menu items
const items = computed(() => {
return menuItems.map((item) => {
if (item.children && item.children.length > 0) {
const childItems = item.children.map((child) =>
getItem(child.name, child.path, undefined, undefined, undefined, child.disabled)
);
return getItem(item.name, item.path, h(item.icon), childItems, undefined, item.disabled);
} else {
return getItem(item.name, item.path, h(item.icon), undefined, undefined, item.disabled);
}
});
return menuItems
.filter(item => item.visible !== false)
.map((item) => {
if (item.children && item.children.length > 0) {
// visible false
const childItems = item.children
.filter(child => child.visible !== false)
.map((child) =>
getItem(
child.name,
child.path,
undefined,
undefined,
undefined,
child.disabled
)
)
.filter(Boolean) as MenuItemType[];
//
if (childItems.length === 0) {
return getItem(
item.name,
item.path,
h(item.icon),
undefined, //
undefined,
item.disabled
);
}
return getItem(
item.name,
item.path,
h(item.icon),
childItems,
undefined,
item.disabled
);
} else {
return getItem(
item.name,
item.path,
h(item.icon),
undefined,
undefined,
item.disabled
);
}
})
.filter(Boolean) as MenuItemType[];
});
const handleMenuSelect = ({ key }: { key: string }) => {
// a-menu select
const targetItem = findMenuItemByKey(menuItems, key);
if (targetItem?.disabled) {
//
const allItems = flattenMenuItems(menuItems);
const targetItem = allItems.find(item => item.path === key);
//
if (targetItem?.disabled || targetItem?.visible === false) {
return;
}
router.push(key);
};
//
function findMenuItemByKey(items: MenuItem[], key: string): MenuItem | undefined {
for (const item of items) {
if (item.path === key) return item;
//
function flattenMenuItems(items: MenuItem[]): MenuItem[] {
let result: MenuItem[] = [];
items.forEach(item => {
result.push(item);
if (item.children) {
const found = findMenuItemByKey(item.children, key);
if (found) return found;
result = result.concat(flattenMenuItems(item.children));
}
}
return undefined;
});
return result;
}
//
const changeMode = (checked: boolean) => {
state.mode = checked ? 'vertical' : 'inline';
};