App.tsx
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { useEffect, useMemo, useState } from 'react';
import { busEvents, downloadChannelRop } from '@uj/contracts';
import {
SubAppProvider,
downloadCenter,
readInitialPage,
shortName,
subappBus,
} from '@uj/platform-sdk';
import { UEmpty, UPageTransition, pageDirection, type UPageTransitionDirection } from '@uj/ui';
import { usedcarClient } from './api/core/client';
import Dashboard from './pages/Dashboard';
import Leads from './pages/Leads';
import LeadDetail from './pages/Leads/LeadDetail';
import Assessment from './pages/Assessment';
import AssessmentDetail from './pages/Assessment/AssessmentDetail';
import EvaluatePage from './pages/Assessment/EvaluatePage';
import Operation from './pages/Operation';
import ContractDetail from './pages/Operation/ContractDetail';
import ContractEdit from './pages/Operation/ContractEdit';
import Vehicles from './pages/Vehicles';
import VehicleDetail from './pages/Vehicles/VehicleDetail';
import Delivery from './pages/Delivery';
import DeliveryDetail from './pages/Delivery/DeliveryDetail';
import Ledger from './pages/Ledger';
import Handover from './pages/Handover';
import Reports from './pages/Reports';
import Condition from './pages/Condition';
import ConditionDetail from './pages/Condition/ConditionDetail';
import CustomerGroup from './pages/CustomerGroup';
import GroupCodeEditor from './pages/CustomerGroup/GroupCodeEditor';
import type { PageParams, RouteDef } from './routes';
import { matchRoute } from './routes';
/**
* 页面表:主壳给的 subPath(形如 dashboard)在这里换成组件与路径参数。
* 11 条与 scripts/usedcar-menu-complete.sql 中 menu_type=2 的 route 末段逐一对应
* (付款管理已迁至 finance 子系统,见 scripts/finance-menu-migration.sql),
* 顺序沿用菜单 sort(1..11);新增页面 = 加一行 + 建一个页面目录。
*/
const ROUTES: RouteDef[] = [
{ path: 'dashboard', Page: Dashboard },
{ path: 'leads', Page: Leads },
{ path: 'leads/:id', Page: LeadDetail },
{ path: 'assessment', Page: Assessment },
{ path: 'assessment/:evalOrderNo', Page: AssessmentDetail },
{ path: 'assessment/evaluate/:scene/:evalOrderNo', Page: EvaluatePage },
{ path: 'operation', Page: Operation },
{ path: 'operation/contract/:id', Page: ContractDetail },
{ path: 'operation/contract-edit/:id/:contractNo', Page: ContractEdit },
{ path: 'vehicles', Page: Vehicles },
{ path: 'vehicles/:id', Page: VehicleDetail },
{ path: 'vehicles/:id/:mode', Page: VehicleDetail },
{ path: 'delivery', Page: Delivery },
{ path: 'delivery/:id/:deliveryOrderId', Page: DeliveryDetail },
{ path: 'ledger', Page: Ledger },
{ path: 'handover', Page: Handover },
{ path: 'reports', Page: Reports },
{ path: 'condition', Page: Condition },
{ path: 'condition/:id', Page: ConditionDetail },
{ path: 'customer-group', Page: CustomerGroup },
{ path: 'customer-group/live-code/create', Page: GroupCodeEditor },
{ path: 'customer-group/live-code/:mode/:id', Page: GroupCodeEditor },
];
function renderPage(subPath: string) {
const matched = matchRoute(ROUTES, subPath);
// 创建/修改群活码是从一客一群页内跳转的二级页面。保留兜底识别,避免主壳在热更新
// 菜单页面时短暂持有旧路由表,导致用户落到“没有匹配页面”。
if (!matched && subPath.startsWith('customer-group/live-code/')) {
const [, , mode, id] = subPath.split('/');
return <GroupCodeEditor params={{ mode, ...(id ? { id } : {}) }} />;
}
if (!matched) {
return <UEmpty description={`没有匹配「${subPath}」的页面,请从菜单进入`} />;
}
const { Page, params } = matched;
return <Page params={params as PageParams} />;
}
interface PageState {
subPath: string;
direction: UPageTransitionDirection;
}
function UsedcarApp() {
const [state, setState] = useState<PageState>(() => ({
subPath: readInitialPage(),
direction: 'forward',
}));
const { subPath, direction } = state;
useEffect(() => {
const bus = subappBus();
if (!bus) return;
const events = busEvents(shortName());
const onNavigate = (...args: unknown[]) => {
const next = String(args[0] ?? '');
setState((prev) => ({ subPath: next, direction: pageDirection(prev.subPath, next) }));
};
const onLogout = () => setState({ subPath: '', direction: 'forward' });
bus.$on(events.navigate, onNavigate);
bus.$on(events.logout, onLogout);
// 异步导出的编排接口(dj.api.common.*)走 ROP 主网关。ROP 凭据/客户端在本子应用,
// 下载引擎在主壳——把 postRop 适配成 RemoteRequestFn 注册为 rop 通道。
// url 即 ROP method 名,data 即业务参数,与 postRop(method, data) 一一对应。
downloadCenter.registerChannel(downloadChannelRop(shortName()), (req) =>
usedcarClient.postRop(req.url, (req.data ?? {}) as Record<string, unknown>),
);
bus.$emit(events.ready);
return () => {
bus.$off(events.navigate, onNavigate);
bus.$off(events.logout, onLogout);
};
}, []);
const page = useMemo(() => renderPage(subPath), [subPath]);
return (
<UPageTransition pageKey={subPath} direction={direction}>
{page}
</UPageTransition>
);
}
export function App() {
return (
<SubAppProvider>
<div className="uj-scope uj-usedcar-app">{UsedcarApp()}</div>
</SubAppProvider>
);
}