完成气站标准资源全页管理改造
This commit is contained in:
@@ -1,41 +1,6 @@
|
||||
import { DEFAULT_LAYOUT } from '../base';
|
||||
import type { AppRouteRecordRaw } from '../types';
|
||||
|
||||
const resourcePage = () => import('@/views/shared/ResourcePage.vue');
|
||||
|
||||
function child(
|
||||
domain: string,
|
||||
path: string,
|
||||
title: string,
|
||||
resource: string,
|
||||
menuCode: string,
|
||||
meta: Record<string, unknown> = {},
|
||||
): AppRouteRecordRaw {
|
||||
return {
|
||||
path,
|
||||
name: `${domain}-${path}`,
|
||||
component: resourcePage,
|
||||
meta: { title, resource, requiresAuth: true, menuCode, ...meta },
|
||||
};
|
||||
}
|
||||
|
||||
function group(
|
||||
path: string,
|
||||
name: string,
|
||||
title: string,
|
||||
icon: string,
|
||||
order: number,
|
||||
children: AppRouteRecordRaw[],
|
||||
): AppRouteRecordRaw {
|
||||
return {
|
||||
path: `/${path}`,
|
||||
name,
|
||||
component: DEFAULT_LAYOUT,
|
||||
redirect: `/${path}/${children[0].path}`,
|
||||
meta: { title, requiresAuth: true, icon, order, menuCode: name },
|
||||
children,
|
||||
};
|
||||
}
|
||||
import { child, group, resourceRecordPage } from './resource-route-builder';
|
||||
|
||||
const routes: AppRouteRecordRaw[] = [
|
||||
{
|
||||
@@ -54,7 +19,11 @@ const routes: AppRouteRecordRaw[] = [
|
||||
child('delivery', 'accounts', '配送点账户', '/delivery_account', 'delivery_basic', { hideInMenu: true, activeMenu: 'delivery-points' }),
|
||||
]),
|
||||
group('staff', 'staff', '工作人员管理', 'icon-user-group', 30, [
|
||||
child('staff', 'add', '新增工作人员', '/staff_account', 'staff_add', { createMode: true }),
|
||||
{
|
||||
...child('staff', 'add', '新增工作人员', '/staff_account', 'staff_add', { createMode: true }),
|
||||
component: resourceRecordPage,
|
||||
meta: { title: '新增工作人员', resource: '/staff_account', requiresAuth: true, menuCode: 'staff_add', createMode: true, recordMode: 'create', listRouteName: 'staff-installers' },
|
||||
},
|
||||
child('staff', 'installers', '安装人员', '/staff_account', 'staff_installer', { staffType: 'installer' }),
|
||||
child('staff', 'delivery', '配送人员', '/staff_account', 'staff_delivery', { staffType: 'delivery' }),
|
||||
child('staff', 'operations', '运维人员', '/staff_account', 'staff_operations', { staffType: 'operations' }),
|
||||
@@ -71,15 +40,19 @@ const routes: AppRouteRecordRaw[] = [
|
||||
child('contract', 'products-candidates', '合同可选气瓶', '/product_info', 'gasorder_contract', { hideInMenu: true, activeMenu: 'contract-contracts' }),
|
||||
]),
|
||||
group('gasorder', 'gasorder', '燃气配送订单', 'icon-list', 60, [
|
||||
child('gasorder', 'create', '创建订单', '/gasorder_basic', 'gasorder_create', { createMode: true }),
|
||||
{
|
||||
...child('gasorder', 'create', '创建订单', '/gasorder_basic', 'gasorder_create', { createMode: true }),
|
||||
component: resourceRecordPage,
|
||||
meta: { title: '创建订单', resource: '/gasorder_basic', requiresAuth: true, menuCode: 'gasorder_create', createMode: true, recordMode: 'create', listRouteName: 'gasorder-orders' },
|
||||
},
|
||||
child('gasorder', 'orders', '配送订单', '/gasorder_basic', 'gasorder_basic'),
|
||||
]),
|
||||
group('finance', 'finance', '财务管理', 'icon-bar-chart', 70, [
|
||||
child('finance', 'wallet', '钱包', '/wallet_basic', 'wallet_basic'),
|
||||
child('finance', 'banks', '银行卡', '/wallet_bank', 'wallet_bank'),
|
||||
child('finance', 'payments', '支付记录', '/wallet_payment', 'wallet_payment'),
|
||||
child('finance', 'payments', '支付记录', '/payment_order', 'payment_order'),
|
||||
child('finance', 'records', '钱包流水', '/wallet_record', 'wallet_record'),
|
||||
child('finance', 'refunds', '退款记录', '/wallet_refund', 'wallet_refund'),
|
||||
child('finance', 'refunds', '退款记录', '/payment_refund', 'payment_refund'),
|
||||
child('finance', 'withdrawals', '提现申请', '/wallet_apply_cash', 'wallet_apply_cash'),
|
||||
child('finance', 'settlements', '财务结算', '/fin_settlement', 'fin_settlement'),
|
||||
child('finance', 'reconciliations', '财务对账', '/fin_reconciliation', 'fin_reconciliation'),
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* 功能:为气站标准资源构造列表菜单与新建、详情、编辑隐藏路由。
|
||||
* 版本:v1.0.0
|
||||
*/
|
||||
import { assertResourcePageRules } from '@/api/resource-page-rules';
|
||||
import { getResource, resources } from '@/api/resources';
|
||||
import { DEFAULT_LAYOUT } from '../base';
|
||||
import type { AppRouteRecordRaw } from '../types';
|
||||
|
||||
const resourcePage = () => import('@/views/shared/ResourcePage.vue');
|
||||
export const resourceRecordPage = () =>
|
||||
import('@/views/resource/ResourceRecordPage.vue');
|
||||
|
||||
assertResourcePageRules(resources);
|
||||
|
||||
export function child(
|
||||
domain: string,
|
||||
path: string,
|
||||
title: string,
|
||||
resource: string,
|
||||
menuCode: string,
|
||||
meta: Record<string, unknown> = {},
|
||||
): AppRouteRecordRaw {
|
||||
return {
|
||||
path,
|
||||
name: `${domain}-${path}`,
|
||||
component: resourcePage,
|
||||
meta: {
|
||||
title,
|
||||
resource,
|
||||
requiresAuth: true,
|
||||
menuCode,
|
||||
...meta,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function group(
|
||||
path: string,
|
||||
name: string,
|
||||
title: string,
|
||||
icon: string,
|
||||
order: number,
|
||||
children: AppRouteRecordRaw[],
|
||||
): AppRouteRecordRaw {
|
||||
return {
|
||||
path: `/${path}`,
|
||||
name,
|
||||
component: DEFAULT_LAYOUT,
|
||||
redirect: `/${path}/${children[0].path}`,
|
||||
meta: { title, requiresAuth: true, icon, order, menuCode: name },
|
||||
children: expandResourceChildren(children),
|
||||
};
|
||||
}
|
||||
|
||||
/** 为一个列表路由生成隐藏的新建、详情和编辑子页面。 */
|
||||
function expandResourceChildren(children: AppRouteRecordRaw[]) {
|
||||
return children.flatMap((route) => {
|
||||
const resource = String(route.meta?.resource ?? '');
|
||||
if (!resource || route.meta?.createMode) return [route];
|
||||
const definition = getResource(resource);
|
||||
if (definition.pageKind !== 'list') return [route];
|
||||
const listRouteName = String(route.name);
|
||||
const activeMenu = String(route.meta?.activeMenu ?? route.name);
|
||||
const makeRecordRoute = (
|
||||
mode: 'create' | 'detail' | 'edit',
|
||||
suffix: string,
|
||||
titlePrefix: string,
|
||||
): AppRouteRecordRaw => ({
|
||||
path: `${route.path}/${suffix}`,
|
||||
name: `${listRouteName}-${mode}`,
|
||||
component: resourceRecordPage,
|
||||
meta: {
|
||||
...route.meta,
|
||||
requiresAuth: true,
|
||||
title: `${titlePrefix}${definition.title}`,
|
||||
hideInMenu: true,
|
||||
activeMenu,
|
||||
listRouteName,
|
||||
recordMode: mode,
|
||||
},
|
||||
});
|
||||
return [
|
||||
route,
|
||||
...(definition.canCreate
|
||||
? [makeRecordRoute('create', 'new', '新建')]
|
||||
: []),
|
||||
makeRecordRoute('detail', ':identity', ''),
|
||||
...(definition.canEdit
|
||||
? [makeRecordRoute('edit', ':identity/edit', '编辑')]
|
||||
: []),
|
||||
];
|
||||
});
|
||||
}
|
||||
2
frontend/gas_admin/src/router/typings.d.ts
vendored
2
frontend/gas_admin/src/router/typings.d.ts
vendored
@@ -5,6 +5,8 @@ declare module 'vue-router' {
|
||||
roles?: string[]; // Controls roles that have access to the page
|
||||
menuCode?: string; // Server-assigned menu domain required by this route
|
||||
staffType?: 'installer' | 'delivery' | 'operations';
|
||||
listRouteName?: string; // 独立记录页返回的列表路由名称
|
||||
recordMode?: 'create' | 'detail' | 'edit'; // 独立记录页模式
|
||||
createMode?: boolean;
|
||||
requiresAuth: boolean; // Whether login is required to access the current page (every route must declare)
|
||||
icon?: string; // The icon show in the side menu
|
||||
|
||||
Reference in New Issue
Block a user