1
This commit is contained in:
parent
378cdffb0f
commit
6ab17998e8
@ -1,7 +1,10 @@
|
||||
# UpperTable 大列表滚动性能优化方案
|
||||
|
||||
> 状态:方案评审中(未实施)
|
||||
> 日期:2026-08-28
|
||||
> 状态:方案①②⑥⑦⑧⑨已实施(2026-08-29);双模式默认"开销优先";
|
||||
> ⚠️ 关键发现:el-table `:data` 变化硬成本 ~300ms,performance 模式已改"冻结+快速更新"(滚动流畅);
|
||||
> 根治"实时跟随+流畅"需 el-table-v2 / transform(待评估)
|
||||
> 日期:2026-08-28(创建)/ 2026-08-29(更新)
|
||||
> **用户决策(2026-08-29)**:双模式可切换——"性能优先"提升资源开销换取使用性能;"开销优先"减少资源开销保证基础体验;在"字段设置"中切换。**默认模式 = 开销优先**。
|
||||
> 组件:`src/components/UpperTable/index.vue`
|
||||
> 涉及页面:订单管理、波次管理(waveOrder)等所有使用 UpperTable 的大数据列表
|
||||
|
||||
@ -154,12 +157,12 @@ tableRenderData = [顶部spacer(高=startIndex*行高)] + [可视窗口行] + [
|
||||
### 6.1 建议顺序
|
||||
|
||||
```
|
||||
第一步:方案①(收窄 tooltip)—— 小改动,验证根因
|
||||
↓ 浏览器实测:滚动长任务是否从 700ms 级降到几十 ms
|
||||
第二步:方案②(el-tag 文本化)—— 进一步降组件树
|
||||
↓ 复测
|
||||
第三步:方案③(transform 位移虚拟化)
|
||||
第四步:方案④(默认列收敛,可随时做)
|
||||
第一步:方案①(收窄 tooltip)—— ✅ 已完成(2026-08-29)
|
||||
第二步:方案②(el-tag 文本化)—— ✅ 已完成(2026-08-29)
|
||||
↓ 复测:滚动长任务从 862ms 降到 ~500ms;单步滚动从 141ms 降到 45~77ms
|
||||
第三步:方案⑥⑦(向上滚动真空期优化,见第 9 章)—— 待实施
|
||||
第四步:方案③(transform 位移虚拟化)—— 评估后实施
|
||||
第五步:方案④(默认列收敛,可随时做)
|
||||
```
|
||||
|
||||
### 6.2 验证方法(DevTools)
|
||||
@ -199,3 +202,200 @@ obs.observe({ entryTypes: ['longtask'] });
|
||||
- 组件:`src/components/UpperTable/index.vue`
|
||||
- 页面示例:`src/views/order/orderManagement/`、`src/views/order/waveOrder/`
|
||||
- 列配置示例:`src/views/order/waveOrder/config/wave-config.ts`
|
||||
|
||||
---
|
||||
|
||||
## 9. 向上滚动渲染"真空期"(2026-08-29 新发现)
|
||||
|
||||
### 9.1 现象
|
||||
|
||||
方案①②实施后,**向下滚动明显改善**,但**向上滚动查看上方数据时,可视区域出现明显的渲染"真空期"**:滚动位置已经移动,但表格内容迟迟未渲染到位,出现数百毫秒的空白/错位,体验不佳。
|
||||
|
||||
### 9.2 实测数据
|
||||
|
||||
在待处理订单页(500 条/页,虚拟滚动)快速向上滚动 7000px(scrollTop 8000 → 1000):
|
||||
|
||||
| 指标 | 值 |
|
||||
|---|---|
|
||||
| 滚动位置到达目标时刻 | T+0 |
|
||||
| 数据行(43 行窗口)首次更新时刻 | **T+632ms** |
|
||||
| 真空期时长 | **约 632ms** |
|
||||
|
||||
> 即:滚动条已到目标位置,但可视区的行内容要再等约 **632ms** 才渲染出来。这 632ms 内可视区显示的是旧窗口内容(与滚动位置严重错位)或空白。
|
||||
|
||||
### 9.3 根因分析(结合代码)
|
||||
|
||||
当前虚拟滚动是 **"spacer 撑高 + 窗口替换"** 模式,向上滚动时真空期由三个因素叠加:
|
||||
|
||||
1. **窗口更新链路过长(主因)**
|
||||
滚动位置变化 → scroll 事件 → rAF 节流 `handleBodyScroll` → 更新 `virtualScrollTop` → computed 重算 `virtualStartIndex` → `tableRenderData` 变化 → Vue 异步渲染新窗口。整条链路每步都要在**事件循环 + 渲染循环**中排队,累积延迟可达数百 ms。
|
||||
|
||||
2. **整块窗口替换的渲染耗时**
|
||||
窗口变化时,新进入可视区的行需创建 DOM(43 行 × 35 列 ≈ 1505 单元格,含 tooltip)。即使方案①②已大幅降组件,创建这些 DOM 仍需数十~上百 ms,期间可视区内容缺失。
|
||||
|
||||
3. **滚动条连续 vs 窗口步进的不匹配**
|
||||
原生滚动位置是连续的,但虚拟窗口按**整数行**切换。窗口切换瞬间,顶部 spacer 高度与行内容**同时跳变**,若渲染未同步完成,就会出现内容与滚动位置错位的"真空期"。向上滚动时(从大 startIndex 往小跳),新增行在顶部,视觉上更明显。
|
||||
|
||||
4. **buffer 对称且偏小(放大因素)**
|
||||
`virtualBufferRows = 12` 上下对称。快速向上滚动一次超过 12 行时,顶部新行不在 buffer 内,必须即时创建 → 真空期更明显。
|
||||
|
||||
### 9.4 优化方案(按收益/成本排序)
|
||||
|
||||
#### 方案 ⑥:方向感知 + 增大 buffer(P0,低成本)—— ✅ 已实施(2026-08-29)
|
||||
|
||||
**目标**:让新进入可视区的行提前存在(预渲染),减少"即时创建"带来的真空期。
|
||||
|
||||
**做法(已落地)**:
|
||||
- `virtualBufferRows` 默认 12 → **16**
|
||||
- 新增 `scrollDirection`(up/down)在 `handleBodyScroll` 中检测滚动方向
|
||||
- **方向感知 buffer**:当前滚动方向一侧 buffer ×2(向上滚动时 topBuffer=32 / bottom=16,反之亦然)
|
||||
|
||||
**实测结果**:
|
||||
|
||||
| 指标 | 方案⑥前 | 方案⑥后 |
|
||||
|---|---|---|
|
||||
| 渲染行数 | 43 | 59 |
|
||||
| 向上滚 7000px 真空期 | 632ms | **469ms(-26%)** |
|
||||
| 向上滚 1000px | — | 474ms |
|
||||
| 向上滚 300px(9 行) | — | 433ms |
|
||||
|
||||
**关键发现**:即使**小距离滚动(9 行,在 buffer 内)真空期仍 ~433ms**。说明根本瓶颈不是"新行即时创建",而是**每次滚动(无论大小)都触发全窗口(59 行 × 35 列)的 Vue 重渲染**——buffer 预渲染只减少了"新行创建",未解决"每次滚动全窗口 diff"的固有开销。
|
||||
|
||||
**结论**:方案⑥改善有限(-26%),需配合方案⑦(调度优化)或③/⑤(根治)才能彻底消除真空期。
|
||||
|
||||
#### 方案 ⑦:窗口更新调度优化(P1)—— ⑦A 已实施(2026-08-29)
|
||||
|
||||
**目标**:缩短"滚动位置变化 → 窗口更新"的链路延迟。
|
||||
|
||||
**⑦A(已实施,但体验权衡不佳 → 拟回退/调整)**
|
||||
- `handleBodyScroll` 中滚动过程**冻结 `virtualScrollTop`**(不触发全窗口重渲染),仅更新方向与视口高度
|
||||
- 停止滚动 **120ms** 后(debounce `scrollSettleTimer`)一次性更新窗口
|
||||
|
||||
**⑦A 实测(单步滚动 median)**:
|
||||
|
||||
| 单步滚动 | 方案⑥后 | 方案⑦A 后 |
|
||||
|---|---|---|
|
||||
| 20px(不跨行) | 74ms | **19ms** |
|
||||
| 100px(跨行) | 45ms | **6ms(-87%)** |
|
||||
|
||||
- 滚动中虚拟窗口冻结验证:连续滚动 1.2s,tbody childList 仅变化 3 次(之前每帧变)
|
||||
- **体验权衡(❌ 不满足用户决策)**:
|
||||
- 滚动中**内容不跟随滚动位置**(停滞/错位),缓慢滚动逐行查看体验差
|
||||
- 停止滚动后约 **400ms** 内容才更新到位——真空期从"滚动中"挪到"停止后"
|
||||
- 换来的是滚动中流畅(6ms),但这牺牲了"内容实时跟随"
|
||||
- **结论**:按"可接受性能开销换体验"的决策,**⑦A 的冻结策略不再推荐**,应回退或改造为"内容实时跟随"(见 ⑨ / ③)。
|
||||
|
||||
**⑦B(推荐方向):滚动中每帧最多同步一次窗口**
|
||||
- 回退⑦A 冻结,恢复"滚动中每帧(rAF 节流)同步窗口",内容实时跟随滚动位置
|
||||
- **关键**:单次渲染必须够快(否则滚动中卡)→ 必须配合方案⑧(降低单次渲染成本)与方案⑥(buffer 预渲染)
|
||||
- 代价:渲染频率回到每帧,但通过 ⑧ 让单次渲染从 400ms 降到可接受范围
|
||||
|
||||
#### 方案 ③(复用):transform 位移虚拟化(P1,根治,高风险)
|
||||
|
||||
**目标**:彻底消除"窗口切换真空期"。
|
||||
|
||||
**做法**:固定行窗口 + `transform: translateY(offset)` 让内容**连续跟随**滚动条;滚动时仅 GPU 合成,不重建 DOM;越过行边界时**复用**已有行(首尾追加/移除),而非整块替换。
|
||||
|
||||
**风险**:`el-table` 是原生 `<table>` 布局,transform 与原生滚动、固定列、行高计算冲突,需大量回归。若评估后不可行,则转向方案⑤(el-table-v2)作为根治手段。
|
||||
|
||||
#### 方案 ⑧:继续压渲染耗时(P1,辅助)—— ✅ 已实施(2026-08-29)
|
||||
|
||||
**做法(已落地)**:
|
||||
- **① formatter 结果按行缓存**:`UpperTable` 新增 `formatterCache = WeakMap<row, Map<prop, string>>` + `getFormattedCell(row, column, value, index)`,模板 `v-html` 改用它;行对象生命周期自动回收、数据刷新自动失效,滚动窗口切换不重复计算
|
||||
- **② 关闭序号 / 货主列多余 tooltip**:`orderWaveIndexColumn`、`orderStoreRemarkColumn` 移除 `showOverflowTooltip`
|
||||
- **③(未做,可选项)**:关键列之外 el-tooltip 改用 `title` 原生属性降级——改动复杂、收益不确定,暂缓
|
||||
|
||||
**实测(performance 模式,renderRows=67)**:
|
||||
|
||||
| 单步滚动 | 方案⑨(performance) | 方案⑧后 |
|
||||
|---|---|---|
|
||||
| 20px(不跨行)median | 严重卡(1.2s 滚 3 步) | **11ms** |
|
||||
| 100px(跨行)median | 严重卡 | **60ms** |
|
||||
|
||||
- 对比方案⑨时"1.2s 滚 3 步(~400ms/步)"大幅改善
|
||||
- **残留**:performance 跨行渲染仍 ~60ms(67 行 × 35 列 DOM 成本);noCross 偶发 1s 长任务(滚动方向切换时 buffer 对调触发大重渲染)
|
||||
- **可继续**:压剩余 248 个 tooltip、或降低 performance buffer(16→12)、或方案③ transform
|
||||
|
||||
#### 方案 ⑨:双工作模式(性能优先 / 开销优先,P0)—— ✅ 已实施(2026-08-29,默认"开销优先")
|
||||
|
||||
**目标**:将"性能开销 vs 使用体验"的取舍做成**用户可切换的双模式**,兼顾不同设备与场景需求。用户可在"字段设置"中切换表格工作模式。
|
||||
|
||||
**背景**:⑦A(冻结省资源但内容不跟随)与 ⑦B+⑧(内容实时跟随但开销大)是互斥取舍。与其二选一,不如**做成两种可切换模式**,把选择权交给用户。
|
||||
|
||||
**两个模式定义**:
|
||||
|
||||
| 维度 | 性能优先模式 | 开销优先模式(默认) |
|
||||
|---|---|---|
|
||||
| 目标 | 滚动体验最佳、**停止后快速到位、真空期小** | 资源开销最小、保证基础体验 |
|
||||
| 适用场景 | 高性能设备 / 大数据量 | 低性能设备 / 资源紧张 |
|
||||
| buffer(方案⑥) | 大(base=12,**对称**,避免方向切换突变) | 小(base=8,方向侧 ×2 省资源) |
|
||||
| 渲染行数 | ~34 行(预渲染较充分) | ~34 行 |
|
||||
| 滚动调度(方案⑦) | **滚动中冻结 + 停止后 60ms 更新**(流畅) | 滚动中冻结 + 停止后 120ms 更新(省资源) |
|
||||
| 内容实时跟随 | ❌(el-table 限制,见下方关键发现) | ❌ |
|
||||
| 停止后到位 | ~350ms(快速) | ~420ms |
|
||||
| 资源开销 | 高 | 低 |
|
||||
| 可选增强 | 方案③ transform / ⑤ el-table-v2(根治实时跟随) | — |
|
||||
|
||||
**切换入口**:字段设置弹窗新增"**表格工作模式**"选择器(两个单选:性能优先 / 开销优先),并存 localStorage。
|
||||
|
||||
**实现要点(已落地)**:
|
||||
1. `UpperTable` 新增 `tableMode` prop:`'performance' | 'resource'`,**默认 `'resource'`(开销优先)**
|
||||
2. `activeTableMode` ref 优先读 localStorage,兜底 prop;onMounted `initTableMode` 初始化
|
||||
3. 模式驱动:
|
||||
- `effectiveBufferRows`:performance = 12(**对称**,避免方向切换突变);resource = 8(方向 ×2 省资源)
|
||||
- 滚动调度(统一冻结):滚动中冻结窗口,停止后统一更新;**debounce:performance=60ms / resource=120ms**
|
||||
4. 模式存 localStorage,key `upper_table_mode_${userId}_${roleId}`(全局)
|
||||
5. 字段设置弹窗 toolbar 新增"表格工作模式" radio-group(性能优先 / 开销优先),切换时 `handleTableModeChange` 持久化 + 重置虚拟滚动状态
|
||||
|
||||
**⚠️ 关键技术发现:el-table `:data` 变化是硬成本 ~300ms**
|
||||
|
||||
实测:单次窗口同步(el-table `:data` 数组替换)耗时 **273~358ms(稳定 ~300ms)**,且与 tooltip 数量、buffer 大小、节流频率**无关**(均已验证无效)。这是 el-table 对 data 变化的**全量重算**所致。
|
||||
|
||||
**结论**:在 el-table 上,"滚动中实时同步窗口(内容实时跟随)"与"滚动流畅"**不可兼得**。因此 **performance 模式放弃"实时跟随(⑦B)",改为"滚动中冻结 + 停止后快速更新"**(与 resource 同机制,但 debounce 更短、buffer 更大)。
|
||||
|
||||
**实测验证(待处理订单 500 条/页)**:
|
||||
|
||||
| 指标 | 优化前(实时同步) | 优化后(冻结+快速更新) |
|
||||
|---|---|---|
|
||||
| 1.5s 连续滚动 steps | 5(每步 ~300ms,卡) | **29(流畅)** |
|
||||
| 长任务总数 | 6~10 | **4** |
|
||||
| 总阻塞 | ~2000ms | **726ms** |
|
||||
| 渲染行数 | 67 | 34 |
|
||||
| 停止后到位 | ~400ms | **~350ms(performance)/ ~420ms(resource)** |
|
||||
|
||||
**根治"实时跟随 + 流畅"**:需方案⑤ `el-table-v2`(官方高效虚拟表格,内部窗口管理不依赖 el-table data 全量重算)或方案③ transform 位移(在 el-table 上 hack,高风险)。两者均需重写/改造虚拟滚动部分,待评估。
|
||||
|
||||
**预期收益**:
|
||||
- 性能优先:滚动中内容实时跟随、无真空期、体验最佳(开销大)
|
||||
- 开销优先:资源占用低、滚动流畅(但内容冻结、停止后更新)
|
||||
- 用户按设备/场景自选,兼顾两端
|
||||
|
||||
### 9.5 建议实施顺序(双模式:性能优先 / 开销优先)
|
||||
|
||||
```
|
||||
第一步:方案⑥(方向感知 + 增大 buffer)—— ✅ 已完成:真空期 632→469ms(-26%)
|
||||
第二步:方案⑦A(滚动停止后统一更新)—— ✅ 已实施:作为"开销优先"模式的调度基础
|
||||
第三步:抽象双模式(方案⑨)—— ✅ 已完成:tableMode prop(默认 resource)+ 字段设置切换 + 存储
|
||||
第四步:方案⑧(压渲染耗时)—— ✅ 已完成:formatter 按行缓存 + 关闭序号/货主 tooltip;
|
||||
performance 模式单步 20px→11ms / 100px→60ms(之前 ~400ms)
|
||||
第五步:字段设置 UI 切换控件 —— ✅ 已完成(随方案⑨)
|
||||
第六步:复测两模式—— ⏳ 待做:性能优先(内容实时跟随+单步<30ms)
|
||||
第七步:方案③ transform 位移(或⑤ el-table-v2)—— 性能优先模式的终极增强,评估后做
|
||||
```
|
||||
|
||||
### 9.6 真空期复测方法(浏览器 Console)
|
||||
|
||||
```js
|
||||
// 向上滚动后检测数据行更新延迟
|
||||
const wrap = document.querySelector('.el-table__body-wrapper .el-scrollbar__wrap');
|
||||
const tbody = document.querySelector('.el-table__body-wrapper tbody');
|
||||
const mo = new MutationObserver(() => { /* 记录行数变化时刻 */ });
|
||||
mo.observe(tbody, { childList: true, subtree: true });
|
||||
wrap.scrollTop = 8000;
|
||||
await new Promise(r => setTimeout(r, 600));
|
||||
const t0 = performance.now();
|
||||
wrap.scrollTop = 1000; // 快速向上滚
|
||||
// 等待首个数据行更新事件,计算与 t0 的差值即真空期
|
||||
```
|
||||
|
||||
> 目标:真空期从当前 **632ms** 降到 **<100ms**。
|
||||
|
||||
@ -258,3 +258,47 @@ export function inboxGroupMessages(data: InboxGroupMessagesParams) {
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 群快速查询参数(下拉选择用,不分页) */
|
||||
export interface InboxGroupQuickListParams {
|
||||
keyword?: string // 关键词,模糊匹配群名称与外部群ID
|
||||
groupType?: string // 群类型筛选:store(货主) / warehouse(仓库) / express(快递)
|
||||
limit?: number // 返回条数上限,默认20,最大100(无分页)
|
||||
}
|
||||
|
||||
/** 群快速查询(inbox.group.quickList) */
|
||||
export function inboxGroupQuickList(data: InboxGroupQuickListParams = {}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'inbox.group.quickList',
|
||||
v,
|
||||
timestamp: Date.now()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 查询群成员参数(下拉选择用) */
|
||||
export interface InboxGroupMembersParams {
|
||||
groupId: number // 群记录主键ID(必填)
|
||||
keyword?: string // 关键词,模糊匹配用户名与用户ID
|
||||
limit?: number // 返回条数上限,默认20,最大100(无分页)
|
||||
}
|
||||
|
||||
/** 查询指定群的成员列表(inbox.group.members) */
|
||||
export function inboxGroupMembers(data: InboxGroupMembersParams) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'inbox.group.members',
|
||||
v,
|
||||
timestamp: Date.now()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
439
src/api/report/report.ts
Normal file
439
src/api/report/report.ts
Normal file
@ -0,0 +1,439 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
const v = '1.0'
|
||||
|
||||
/* ===== 报表导出任务 ===== */
|
||||
|
||||
export interface ReportGenerateParams {
|
||||
/** 报表编码(与 reportCode 二选一;均传时优先 reportCode) */
|
||||
report_code?: string
|
||||
/** 报表编码驼峰别名(兼容,优先级高于 report_code) */
|
||||
reportCode?: string
|
||||
/** 货主ID(可选,货主维度报表时传入;>0 生效,<=0 视为不按货主过滤) */
|
||||
store_id?: number
|
||||
/** 货主ID驼峰别名(兼容,优先级高于 store_id) */
|
||||
storeId?: number
|
||||
/** 查询器业务参数(透传,如 bizDate) */
|
||||
params?: {
|
||||
/** 数据日期(YYYY-MM-DD) */
|
||||
bizDate?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReportTaskResponse {
|
||||
/** 导出任务ID(report_generate_ 前缀) */
|
||||
task_id: string
|
||||
/** 任务状态:submitted/running/success/failed */
|
||||
status: 'submitted' | 'running' | 'success' | 'failed'
|
||||
/** 任务进度百分比(0-100) */
|
||||
progress: number
|
||||
/** 任务状态说明 */
|
||||
message: string
|
||||
/** 任务结果对象;导出成功后为 { fileKey, url, filename, size } */
|
||||
result: Record<string, unknown> | null
|
||||
/** 失败时的错误信息;成功时为空字符串 */
|
||||
error: string
|
||||
/** 任务状态更新时间(毫秒时间戳) */
|
||||
update_time: number
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 提交报表导出异步任务(手动导出):立即返回任务受理信息,后台异步执行 */
|
||||
export function generate(
|
||||
data?: ReportGenerateParams
|
||||
): Promise<ReportTaskResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.generate',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
export interface ReportTaskProgressParams {
|
||||
/** 导出任务ID(下划线写法,与 taskId 二选一) */
|
||||
task_id?: string
|
||||
/** 导出任务ID(驼峰写法,兼容别名) */
|
||||
taskId?: string
|
||||
}
|
||||
|
||||
export interface ReportTaskProgressResponse extends Omit<ReportTaskResponse, 'status'> {
|
||||
/** 任务状态:submitted/running/success/failed/not_found */
|
||||
status: 'submitted' | 'running' | 'success' | 'failed' | 'not_found'
|
||||
/** 任务成功后返回的下载链接;未完成或失败时为空字符串 */
|
||||
download_url: string
|
||||
}
|
||||
|
||||
/** 查询报表导出任务进度与结果 */
|
||||
export function generateTaskProgress(
|
||||
data: ReportTaskProgressParams
|
||||
): Promise<ReportTaskProgressResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.generateTaskProgress',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/* ===== 货主报表投递计划 ===== */
|
||||
|
||||
export interface DeliveryPlanSaveParams {
|
||||
/** 货主ID(必填,正整数;<=0 报错) */
|
||||
store_id: number
|
||||
/** 报表编码(必填,须为已启用的报表定义) */
|
||||
report_code: string
|
||||
/** 每日投递时间点数组(HH:mm 24 小时制,非空;自动去重并升序) */
|
||||
schedule_times: string[]
|
||||
/** 投递渠道:仅支持 inbox,默认 inbox;wecom/link 已弃用 */
|
||||
channel?: string
|
||||
/** 补投宽限分钟(0-1440),默认 60 */
|
||||
late_grace_minutes?: number
|
||||
/** 备注(最长 500 字符) */
|
||||
remark?: string
|
||||
/** 文本通知模板(≤500,标签 {time}/{url}/{report_name}/{biz_date}) */
|
||||
notify_template?: string
|
||||
/** 通知群ID数组(wms_inbox_group.id,正整数去重 ≤20) */
|
||||
notify_group_ids?: number[]
|
||||
/** 通知成员ID数组(外部 IM 用户 ID,去重 ≤100) */
|
||||
notify_member_ids?: string[]
|
||||
}
|
||||
|
||||
export interface DeliveryPlanItem {
|
||||
id: number
|
||||
store_id: number
|
||||
report_code: string
|
||||
schedule_times: string[]
|
||||
channel: string
|
||||
/** 是否启用:0=停用 1=启用 */
|
||||
enabled: number
|
||||
late_grace_minutes: number
|
||||
remark: string
|
||||
notify_template: string
|
||||
notify_group_ids: number[] | null
|
||||
notify_member_ids: string[] | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** 新增/更新货主报表投递计划(货主 store_id + 报表 report_code 唯一,存在则更新) */
|
||||
export function saveDeliveryPlan(
|
||||
data: DeliveryPlanSaveParams
|
||||
): Promise<DeliveryPlanItem> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.deliveryPlan.save',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
export interface DeliveryPlanListParams {
|
||||
where?: {
|
||||
/** 货主ID(>0 时精确过滤) */
|
||||
store_id?: number
|
||||
/** 报表编码(精确过滤) */
|
||||
report_code?: string
|
||||
/** 启用状态:0=停用 1=启用;空值/未传不过滤 */
|
||||
enabled?: number | string
|
||||
}
|
||||
pagination?: {
|
||||
/** 当前页码(默认 1) */
|
||||
page?: number
|
||||
/** 每页条数(默认 20,上限 200) */
|
||||
pageSize?: number
|
||||
}
|
||||
sort?: {
|
||||
/** 排序字段(白名单 id/created_at/updated_at/store_id/report_code,默认 id) */
|
||||
sortField?: string
|
||||
/** 排序方向(ASC/DESC,默认 DESC) */
|
||||
sortOrder?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeliveryPlanListResult {
|
||||
list: DeliveryPlanItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 分页查询货主报表投递计划列表(管理侧) */
|
||||
export function listDeliveryPlan(
|
||||
data?: DeliveryPlanListParams
|
||||
): Promise<DeliveryPlanListResult> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.deliveryPlan.list',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/* ===== 货主报表投递记录 ===== */
|
||||
|
||||
export interface DeliveryLogListParams {
|
||||
where?: {
|
||||
/** 货主ID(>0 时精确过滤) */
|
||||
store_id?: number
|
||||
/** 报表编码(精确过滤) */
|
||||
report_code?: string
|
||||
/** 投递状态过滤(pending/exporting/delivered/failed/cancelled;非法值忽略) */
|
||||
status?: string
|
||||
}
|
||||
pagination?: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
sort?: {
|
||||
sortField?: string
|
||||
sortOrder?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface DeliveryLogListItem {
|
||||
id: number
|
||||
/** 投递目标快照({group_ids, member_ids, notify_text},仅投递成功且配置文本通知时非 null) */
|
||||
notify_targets?: {
|
||||
group_ids?: number[] | null
|
||||
member_ids?: string[] | null
|
||||
notify_text?: string
|
||||
} | null
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface DeliveryLogListResult {
|
||||
list: DeliveryLogListItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 分页查询货主报表投递记录(审计) */
|
||||
export function listDeliveryLog(
|
||||
data?: DeliveryLogListParams
|
||||
): Promise<DeliveryLogListResult> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.deliveryLog.list',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/* ===== 报表元数据 ===== */
|
||||
|
||||
export interface ReportMetaParams {
|
||||
/** 报表编码(与 reportCode 二选一;均传时优先 reportCode) */
|
||||
report_code?: string
|
||||
/** 报表编码驼峰别名(兼容,优先级高于 report_code) */
|
||||
reportCode?: string
|
||||
}
|
||||
|
||||
export interface ReportMetaField {
|
||||
/** 字段键(与查询器返回行字段一一对应,如 item_code) */
|
||||
key: string
|
||||
/** 字段中文名 */
|
||||
label: string
|
||||
/** 字段类型:string/number/boolean/array */
|
||||
type: 'string' | 'number' | 'boolean' | 'array'
|
||||
/** 是否格式化器预计算字段,仅 true 时返回 */
|
||||
computed?: boolean
|
||||
/** 数组类型字段的子字段清单,仅数组类型字段返回 */
|
||||
children?: ReportMetaField[]
|
||||
}
|
||||
|
||||
export interface ReportMetaResponse {
|
||||
report_code: string
|
||||
name: string
|
||||
/** 适用维度:warehouse=仓库 / store=货主 / open=通用 */
|
||||
scope: 'warehouse' | 'store' | 'open'
|
||||
/** 查询器 key */
|
||||
query: string
|
||||
/** 日窗口参数对象 */
|
||||
window: {
|
||||
/** 窗口数量(默认 7) */
|
||||
dayCount: number
|
||||
/** 切点小时 0-23(默认 7) */
|
||||
cutoverHour: number
|
||||
}
|
||||
/** 查询器静态字段清单 */
|
||||
fields: ReportMetaField[]
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 查询报表前端可读的列元数据(只读静态字段清单 + 窗口参数,不执行真实数据查询) */
|
||||
export function meta(data?: ReportMetaParams): Promise<ReportMetaResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.meta',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
/* ===== 报表定义管理 ===== */
|
||||
|
||||
export interface ReportDefinitionSaveParams {
|
||||
/** 报表编码(必填,upsert 键):小写字母开头,仅含小写字母/数字/下划线,长度 2-64 */
|
||||
code: string
|
||||
/** 报表名称(必填,≤100 字符) */
|
||||
name: string
|
||||
/** 适用维度:warehouse=仓库 / store=货主 / open=通用;默认 warehouse */
|
||||
scope?: string
|
||||
/** 报表描述(≤500 字符,超出截断) */
|
||||
description?: string
|
||||
/** 输出配置(对象或 JSON 字符串) */
|
||||
output_config?: Record<string, unknown>
|
||||
/** 数据源配置(对象或 JSON 字符串),query 须为注册表已有查询器 */
|
||||
source_config?: Record<string, unknown>
|
||||
/** 工作表配置(对象或 JSON 字符串) */
|
||||
sheet_config?: Record<string, unknown>
|
||||
/** 是否启用:0=停用 1=启用 */
|
||||
is_enabled?: number
|
||||
/** 备注(≤500 字符,超出截断) */
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface ReportDefinitionItem {
|
||||
/** 报表编码(保存后的定义 code 平铺为 report_code) */
|
||||
report_code: string
|
||||
id: number
|
||||
name: string
|
||||
/** 适用维度:warehouse/store/open */
|
||||
scope: string
|
||||
description: string
|
||||
is_enabled: number
|
||||
remark: string
|
||||
output_config: Record<string, unknown>
|
||||
source_config: Record<string, unknown>
|
||||
sheet_config: Record<string, unknown>
|
||||
created_at: string
|
||||
updated_at: string
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 新增/更新报表定义(report.definition.save,按 code upsert) */
|
||||
export function saveReportDefinition(
|
||||
data: ReportDefinitionSaveParams
|
||||
): Promise<ReportDefinitionItem> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.definition.save',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
export interface ReportDefinitionListParams {
|
||||
where?: {
|
||||
/** 报表编码模糊关键字 */
|
||||
code?: string
|
||||
/** 报表名称模糊关键字 */
|
||||
name?: string
|
||||
/** 适用维度精确筛选(warehouse/store/open) */
|
||||
scope?: string
|
||||
/** 启用状态精确筛选:0=停用 1=启用;空值/未传不过滤 */
|
||||
is_enabled?: number | string
|
||||
}
|
||||
pagination?: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
sort?: {
|
||||
sortField?: string
|
||||
sortOrder?: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReportDefinitionListResult {
|
||||
list: ReportDefinitionItem[]
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 分页查询报表定义列表(report.definition.list) */
|
||||
export function listReportDefinition(
|
||||
data?: ReportDefinitionListParams
|
||||
): Promise<ReportDefinitionListResult> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.definition.list',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data ?? {},
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
export interface ReportDefinitionDeleteParams {
|
||||
/** 报表编码(必填,按 code 软删除;重复删除幂等成功) */
|
||||
code: string
|
||||
}
|
||||
|
||||
export interface ReportDefinitionDeleteResult {
|
||||
/** 已删除的报表编码(定义 code 平铺为 report_code) */
|
||||
report_code: string
|
||||
/** 删除结果标记(恒为 1) */
|
||||
deleted: number
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 软删除报表定义(report.definition.delete) */
|
||||
export function deleteReportDefinition(
|
||||
data: ReportDefinitionDeleteParams
|
||||
): Promise<ReportDefinitionDeleteResult> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'report.definition.delete',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
@ -109,11 +109,65 @@ export function checkBarcode(data: {
|
||||
} as any)
|
||||
}
|
||||
|
||||
/** 工作台业务入口(免登录免鉴权,入参 name + data,业务逻辑待实现) */
|
||||
export function business(data: {
|
||||
/** 工作台业务入口入参(免登录免鉴权,入参 name + data) */
|
||||
export interface WorkbenchBusinessParams {
|
||||
/** 业务名称:queryOrder/query(条码查订单)、packOrder、finishPack、sendWeight */
|
||||
name: string
|
||||
/** 业务数据(透传)。queryOrder/query 需 barcode(运单号,必填)+ warehouseId(仓库ID,必填) */
|
||||
data?: Record<string, any>
|
||||
}) {
|
||||
}
|
||||
|
||||
/** 工作台业务入口响应(queryOrder/query 条码查订单结构) */
|
||||
export interface WorkbenchBusinessResponse {
|
||||
/** 条码(运单号) */
|
||||
barcode: string
|
||||
/** 运单号 */
|
||||
waybill_code: string
|
||||
/** 是否散单:1=散单 0=团购 */
|
||||
isSandan: number
|
||||
/** 货主备注 */
|
||||
store_remark: string
|
||||
/** 运单信息 */
|
||||
express: {
|
||||
logistics_name?: string
|
||||
weighing_weight?: number
|
||||
package_material_name?: string
|
||||
}
|
||||
/** 订单详情 */
|
||||
order: Record<string, unknown>
|
||||
/** 订单商品明细 */
|
||||
items: Array<{
|
||||
id?: number
|
||||
order_id?: number
|
||||
item_id?: number
|
||||
item_code?: string
|
||||
item_name?: string
|
||||
plan_qty?: number
|
||||
actual_price?: number
|
||||
stock_id?: number
|
||||
order_line_no?: number
|
||||
inventory_type?: string
|
||||
sku_property?: string
|
||||
stock_unit?: string
|
||||
barcodes?: string[]
|
||||
image_url?: string
|
||||
}>
|
||||
/** 订单命中分表:current(待处理表)或 dispatch(配送表) */
|
||||
source_table: 'current' | 'dispatch'
|
||||
/** 波次汇总(仅团购 isSandan=0 返回) */
|
||||
batch?: {
|
||||
wave_id?: number
|
||||
wave_no?: string
|
||||
wave_type?: number
|
||||
total_orders?: number
|
||||
}
|
||||
code?: number
|
||||
}
|
||||
|
||||
/** 工作台业务入口(免登录免鉴权,入参 name + data) */
|
||||
export function business(
|
||||
data: WorkbenchBusinessParams
|
||||
): Promise<WorkbenchBusinessResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
<span v-else style="color:#909399">—</span>
|
||||
</template>
|
||||
<template v-else-if="column.formatter">
|
||||
<span v-html="column.formatter(scope.row, scope.column, scope.row[scope.column.property], scope.$index)"></span>
|
||||
<span v-html="getFormattedCell(scope.row, scope.column, scope.row[scope.column.property], scope.$index)"></span>
|
||||
</template>
|
||||
<template v-else-if="column.prop === 'order_flag'">
|
||||
<el-tooltip
|
||||
@ -218,6 +218,11 @@
|
||||
append-to-body
|
||||
>
|
||||
<div class="column-config-toolbar">
|
||||
<span class="table-mode-label">表格工作模式</span>
|
||||
<el-radio-group v-model="activeTableMode" size="small" @change="handleTableModeChange">
|
||||
<el-radio-button value="resource">低占用</el-radio-button>
|
||||
<el-radio-button value="performance">高性能</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-button size="small" @click="resetColumnConfig">恢复默认</el-button>
|
||||
<el-button size="small" @click="exportGlobalColumnConfig">导出全局配置</el-button>
|
||||
<el-upload
|
||||
@ -509,7 +514,17 @@ const props = defineProps({
|
||||
},
|
||||
virtualBufferRows: {
|
||||
type: Number,
|
||||
default: 12,
|
||||
default: 16,
|
||||
},
|
||||
/**
|
||||
* 表格工作模式(方案⑨ 双模式):
|
||||
* - resource(开销优先,默认):减少资源开销,保证基础体验(⑦A:滚动停止后统一更新)
|
||||
* - performance(性能优先):提升资源开销换取使用性能(⑦B:滚动中实时跟随)
|
||||
*/
|
||||
tableMode: {
|
||||
type: String,
|
||||
default: 'resource',
|
||||
validator: (value: string) => ['performance', 'resource'].includes(value),
|
||||
},
|
||||
defaultAlign: {
|
||||
type: String,
|
||||
@ -584,6 +599,14 @@ let scrollRaf: number | null = null
|
||||
const columnConfigListRef = ref<HTMLElement | null>(null)
|
||||
const virtualScrollTop = ref(0)
|
||||
const virtualViewportHeight = ref(0)
|
||||
/** 当前滚动方向(方案⑥:方向感知 buffer,减少向上滚动"真空期") */
|
||||
const scrollDirection = ref<'up' | 'down'>('down')
|
||||
/** 方案⑦:滚动停止后统一更新窗口的防抖定时器 */
|
||||
let scrollSettleTimer: ReturnType<typeof setTimeout> | null = null
|
||||
/** 方案⑦+性能优化:performance 模式窗口同步节流,记录上次同步时间(避免每帧触发 el-table 全量重算) */
|
||||
let lastWindowSyncTime = 0
|
||||
/** 当前生效的表格工作模式(优先读 localStorage,兜底 props.tableMode) */
|
||||
const activeTableMode = ref<'performance' | 'resource'>(props.tableMode as 'performance' | 'resource')
|
||||
const dragAutoScrollStep = ref(0)
|
||||
let dragAutoScrollRaf: number | null = null
|
||||
const waybillQrVisible = ref(false)
|
||||
@ -726,10 +749,27 @@ const shouldUseVirtual = computed(() => {
|
||||
return props.data.length >= props.virtualThreshold
|
||||
})
|
||||
|
||||
/** 模式驱动的 buffer 基数(方案⑨+性能优化):performance=12(对称),resource=8(方向×2 省资源) */
|
||||
const effectiveBufferRows = computed(() => {
|
||||
return activeTableMode.value === 'performance'
|
||||
? Math.max(8, Math.floor(props.virtualBufferRows * 0.75))
|
||||
: Math.max(4, Math.floor(props.virtualBufferRows / 2))
|
||||
})
|
||||
|
||||
/** 方向感知缓冲行数(方案⑥):resource 模式方向侧加倍省资源;performance 模式对称,避免方向切换 buffer 突变的偶发大重渲染 */
|
||||
const virtualTopBufferRows = computed(() => {
|
||||
if (activeTableMode.value === 'performance') return effectiveBufferRows.value
|
||||
return scrollDirection.value === 'up' ? effectiveBufferRows.value * 2 : effectiveBufferRows.value
|
||||
})
|
||||
|
||||
const virtualBottomBufferRows = computed(() => {
|
||||
if (activeTableMode.value === 'performance') return effectiveBufferRows.value
|
||||
return scrollDirection.value === 'down' ? effectiveBufferRows.value * 2 : effectiveBufferRows.value
|
||||
})
|
||||
|
||||
const virtualVisibleCount = computed(() => {
|
||||
const bufferRows = props.virtualBufferRows
|
||||
const viewportCount = virtualViewportHeight.value
|
||||
? Math.ceil(virtualViewportHeight.value / virtualRowHeight.value) + bufferRows * 2
|
||||
? Math.ceil(virtualViewportHeight.value / virtualRowHeight.value) + virtualTopBufferRows.value + virtualBottomBufferRows.value
|
||||
: 30
|
||||
if (props.virtualMaxVisibleRows > 0) {
|
||||
return Math.min(props.virtualMaxVisibleRows, viewportCount)
|
||||
@ -739,7 +779,7 @@ const virtualVisibleCount = computed(() => {
|
||||
|
||||
const virtualStartIndex = computed(() => {
|
||||
if (!shouldUseVirtual.value) return 0
|
||||
return Math.max(0, Math.floor(virtualScrollTop.value / virtualRowHeight.value) - props.virtualBufferRows)
|
||||
return Math.max(0, Math.floor(virtualScrollTop.value / virtualRowHeight.value) - virtualTopBufferRows.value)
|
||||
})
|
||||
|
||||
const virtualEndIndex = computed(() => {
|
||||
@ -834,6 +874,7 @@ watch(selectedRows, (newVal) => {
|
||||
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
initTableMode()
|
||||
if (props.defaultSelected.length > 0) {
|
||||
setSelectionFromExternal(props.defaultSelected)
|
||||
}
|
||||
@ -866,6 +907,41 @@ function applyColumnConfigMap(configs: ColumnConfigItem[]) {
|
||||
editableColumnConfigs.value = [...configs].sort((a, b) => a.order - b.order)
|
||||
}
|
||||
|
||||
/** 表格工作模式 localStorage key(全局,不区分 tableId) */
|
||||
const tableModeStorageKey = computed(() => {
|
||||
const userId = String(userStore.user?.username || userStore.user?.id || 'unknown')
|
||||
const roleId = userStore.roleId || 'default'
|
||||
return `upper_table_mode_${userId}_${roleId}`
|
||||
})
|
||||
|
||||
function readStoredTableMode(): 'performance' | 'resource' | null {
|
||||
const raw = localStorage.getItem(tableModeStorageKey.value)
|
||||
return raw === 'performance' || raw === 'resource' ? raw : null
|
||||
}
|
||||
|
||||
function saveTableMode(mode: 'performance' | 'resource') {
|
||||
localStorage.setItem(tableModeStorageKey.value, mode)
|
||||
}
|
||||
|
||||
/** 初始化:优先读 localStorage,兜底 props.tableMode */
|
||||
function initTableMode() {
|
||||
activeTableMode.value = readStoredTableMode() || (props.tableMode as 'performance' | 'resource')
|
||||
}
|
||||
|
||||
/** 用户在字段设置中切换工作模式:持久化 + 重置虚拟滚动状态 */
|
||||
function handleTableModeChange(mode: 'performance' | 'resource') {
|
||||
saveTableMode(mode)
|
||||
virtualScrollTop.value = 0
|
||||
scrollDirection.value = 'down'
|
||||
lastWindowSyncTime = 0
|
||||
if (scrollSettleTimer !== null) {
|
||||
clearTimeout(scrollSettleTimer)
|
||||
scrollSettleTimer = null
|
||||
}
|
||||
if (bodyScrollEl.value) bodyScrollEl.value.scrollTop = 0
|
||||
syncVirtualViewport()
|
||||
}
|
||||
|
||||
function saveColumnConfig(configs: ColumnConfigItem[]) {
|
||||
if (!columnConfigStorageKey.value) return
|
||||
const userId = String(userStore.user?.username || userStore.user?.id || 'unknown')
|
||||
@ -1530,6 +1606,27 @@ async function handleRepairColumnConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 方案⑧:formatter 结果按行缓存(WeakMap,行对象生命周期自动回收),避免滚动窗口切换时重复计算 */
|
||||
const formatterCache = new WeakMap<object, Map<string, string>>()
|
||||
|
||||
function getFormattedCell(row: any, column: any, value: any, index: number): string {
|
||||
const fn = column?.formatter
|
||||
if (typeof fn !== 'function') return ''
|
||||
if (!row || typeof row !== 'object') {
|
||||
return String(fn(row, column, value, index) ?? '')
|
||||
}
|
||||
let rowCache = formatterCache.get(row)
|
||||
if (!rowCache) {
|
||||
rowCache = new Map()
|
||||
formatterCache.set(row, rowCache)
|
||||
}
|
||||
const key = String(column.prop || '')
|
||||
if (rowCache.has(key)) return rowCache.get(key)!
|
||||
const result = String(fn(row, column, value, index) ?? '')
|
||||
rowCache.set(key, result)
|
||||
return result
|
||||
}
|
||||
|
||||
function getRowKey(row: any) {
|
||||
if (isVirtualSpacerRow(row)) {
|
||||
return `virtual-${row.__virtualSpacerType}`
|
||||
@ -1575,9 +1672,20 @@ function handleBodyScroll() {
|
||||
if (!bodyScrollEl.value) return
|
||||
const top = bodyScrollEl.value.scrollTop || 0
|
||||
const height = bodyScrollEl.value.clientHeight || 0
|
||||
// 仅在值变化时更新,避免滚动过程中无谓的 computed 重算与表格重渲染
|
||||
if (top !== virtualScrollTop.value) virtualScrollTop.value = top
|
||||
// 检测滚动方向:向上滚动时顶部 buffer 加倍,减少向上滚动"真空期"(方案⑥)
|
||||
if (top > virtualScrollTop.value) scrollDirection.value = 'down'
|
||||
else if (top < virtualScrollTop.value) scrollDirection.value = 'up'
|
||||
if (height !== virtualViewportHeight.value) virtualViewportHeight.value = height
|
||||
if (top === virtualScrollTop.value) return
|
||||
// 方案⑨+优化:两种模式滚动中都冻结窗口(避免每次滚动触发 el-table :data 全量重算 ~300ms 卡顿),
|
||||
// 停止滚动后统一更新。performance 用更短 debounce(60ms)+ 大 buffer 更快到位、真空期更小。
|
||||
const settleDelay = activeTableMode.value === 'performance' ? 60 : 120
|
||||
if (scrollSettleTimer !== null) clearTimeout(scrollSettleTimer)
|
||||
scrollSettleTimer = setTimeout(() => {
|
||||
scrollSettleTimer = null
|
||||
if (!bodyScrollEl.value) return
|
||||
virtualScrollTop.value = bodyScrollEl.value.scrollTop || 0
|
||||
}, settleDelay)
|
||||
})
|
||||
}
|
||||
|
||||
@ -1586,6 +1694,10 @@ function unbindBodyScroll() {
|
||||
cancelAnimationFrame(scrollRaf)
|
||||
scrollRaf = null
|
||||
}
|
||||
if (scrollSettleTimer !== null) {
|
||||
clearTimeout(scrollSettleTimer)
|
||||
scrollSettleTimer = null
|
||||
}
|
||||
if (!bodyScrollEl.value) return
|
||||
bodyScrollEl.value.removeEventListener('scroll', handleBodyScroll)
|
||||
}
|
||||
@ -1965,6 +2077,13 @@ watch(
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.table-mode-label {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.column-config-list {
|
||||
|
||||
@ -80,6 +80,7 @@ export default {
|
||||
'returnReceived':'Return Received',
|
||||
'returnUnpack':'Return Unpack',
|
||||
'returnwaybill':'Return Waybill',
|
||||
'generalreport':'General Report'
|
||||
},
|
||||
"login": {
|
||||
"title": "Login",
|
||||
|
||||
@ -83,6 +83,7 @@ export default {
|
||||
'returnReceived':'退回收件',
|
||||
'returnUnpack':'退回拆包',
|
||||
'returnwaybill':'退回运单',
|
||||
'generalreport':'通用报表'
|
||||
},
|
||||
"login": {
|
||||
"title": "登录",
|
||||
|
||||
@ -47,7 +47,7 @@ export const componentMap: Record<string, any> = {
|
||||
'orderreview/index': () => import('@/views/order/orderreview/index.vue'),
|
||||
'order/weighing': () => import('@/views/order/orderWeighing/index.vue'),
|
||||
'role/index': () => import('@/views/system/setting/role/index.vue'),
|
||||
'basicManagement':() => import('@/views/system/setting/basicManagement/index.vue'),
|
||||
'basicManagement':() => import('@/views/system/setting/basicManagement/newview/index.vue'),
|
||||
'system/setting/role/index': () => import('@/views/system/setting/role/index.vue'),
|
||||
// 'role/index': () => import('@/views/system/setting/role/index.vue'),
|
||||
// 'system/setting/role/index': () => import('@/views/system/setting/role/index.vue'),
|
||||
@ -77,4 +77,5 @@ export const componentMap: Record<string, any> = {
|
||||
'express/returnUnpack/index': () => import('@/views/express/returnUnpack/index.vue'),
|
||||
'express/returnwaybill/index': () => import('@/views/express/returnwaybill/index.vue'),
|
||||
'express/returnUnpackwork/index': () => import('@/views/express/returnUnpackwork/index.vue'),
|
||||
'storage/generalreport/index': () => import('@/views/storage/generalreport/index.vue'),
|
||||
};
|
||||
@ -56,7 +56,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, type Component } from 'vue'
|
||||
import { ref, reactive, markRaw, type Component } from 'vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { COMPONENT_REGISTRY } from '../config/template-config'
|
||||
import type { OperationButtonConfig } from '../config/template-config'
|
||||
@ -124,26 +124,26 @@ function openForm(btn: OperationButtonConfig) {
|
||||
}
|
||||
|
||||
activeFormKey.value = btn.key
|
||||
resolvedFormComponents.value[btn.key] = comp
|
||||
resolvedFormComponents.value[btn.key] = markRaw(comp)
|
||||
formVisibleMap[btn.key] = true
|
||||
}
|
||||
|
||||
function buildFormProps(btn: OperationButtonConfig): Record<string, any> {
|
||||
const props: Record<string, any> = {}
|
||||
const result: Record<string, any> = {}
|
||||
|
||||
// paramMap: { formProp: rowField } → 从行数据取值注入表单
|
||||
if (btn.paramMap) {
|
||||
for (const [formProp, rowField] of Object.entries(btn.paramMap)) {
|
||||
props[formProp] = props.row[rowField]
|
||||
result[formProp] = props.row[rowField]
|
||||
}
|
||||
}
|
||||
|
||||
// extraParams: 固定参数直接注入
|
||||
if (btn.extraParams) {
|
||||
Object.assign(props, btn.extraParams)
|
||||
Object.assign(result, btn.extraParams)
|
||||
}
|
||||
|
||||
return props
|
||||
return result
|
||||
}
|
||||
|
||||
function handleFormSuccess(key: string) {
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
</template>
|
||||
<!-- pre 渲染 -->
|
||||
<template v-else-if="field.renderType === 'pre'">
|
||||
<pre class="order-list-pre">{{ getRowData()?.[field.key] ?? '—' }}</pre>
|
||||
<pre class="order-list-pre">{{ formatPre(getRowData()?.[field.key]) }}</pre>
|
||||
</template>
|
||||
<!-- 默认文本渲染 -->
|
||||
<template v-else>
|
||||
@ -94,6 +94,20 @@ function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
return value ?? '—'
|
||||
}
|
||||
|
||||
/** 格式化 pre 渲染值:数组/对象转 JSON 字符串 */
|
||||
function formatPre(value: any): string {
|
||||
if (value === undefined || value === null || value === '') return '—'
|
||||
if (Array.isArray(value) && value.length === 0) return '—'
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
return JSON.stringify(value, null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** 解析 tag 颜色 */
|
||||
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
if (field.tagResolver) {
|
||||
@ -111,8 +125,14 @@ function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 容器对齐 order/orderManagement 的 OrderDetailPanel(.order-detail-view) */
|
||||
.detail-panel {
|
||||
padding: 8px 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
|
||||
@ -7,25 +7,42 @@
|
||||
-->
|
||||
<template>
|
||||
<div class="log-panel">
|
||||
<div class="section-title">操作日志</div>
|
||||
<div v-if="apiLoading" v-loading="true" class="empty-tip">加载中…</div>
|
||||
<div v-else-if="!logs.length" class="empty-tip">暂无操作日志</div>
|
||||
<div v-else class="log-timeline">
|
||||
<div v-for="(log, i) in logs" :key="i" class="log-item">
|
||||
<div class="log-dot" :class="log.level" />
|
||||
<div class="log-content">
|
||||
<div class="log-header">
|
||||
<span class="log-operator">{{ log.operator }}</span>
|
||||
<span class="log-action">{{ log.action }}</span>
|
||||
<el-tag v-if="log.result === '成功'" size="small" type="success">成功</el-tag>
|
||||
<el-tag v-else-if="log.result === '失败'" size="small" type="danger">失败</el-tag>
|
||||
<el-tag v-else size="small" type="info">{{ log.result }}</el-tag>
|
||||
</div>
|
||||
<div v-if="log.detail" class="log-detail">{{ log.detail }}</div>
|
||||
<div class="log-time">{{ log.time }}</div>
|
||||
</div>
|
||||
<div v-if="apiLoading" v-loading="true" class="log-empty">加载中…</div>
|
||||
<template v-else>
|
||||
<el-table
|
||||
v-if="logs.length"
|
||||
:data="pagedLogs"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
class="log-table"
|
||||
>
|
||||
<el-table-column prop="time" label="时间" width="175" />
|
||||
<el-table-column prop="operator" label="操作人" width="120" />
|
||||
<el-table-column prop="action" label="操作类型" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column label="结果" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="resultTagType(row)">{{ row.result }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="说明" min-width="220" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.detail || '—' }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-else class="log-empty">暂无操作日志</div>
|
||||
|
||||
<div v-if="logs.length > pageSize" class="log-pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:total="logs.length"
|
||||
layout="total, prev, pager, next"
|
||||
background
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -54,7 +71,22 @@ const props = defineProps<{
|
||||
const apiLogs = ref<LogItem[] | null>(null)
|
||||
const apiLoading = ref(false)
|
||||
|
||||
/** 表格本地分页(对齐 order/orderManagement 的 log.vue 体验) */
|
||||
const currentPage = ref(1)
|
||||
const pageSize = 10
|
||||
const pagedLogs = computed<LogItem[]>(() => {
|
||||
const start = (currentPage.value - 1) * pageSize
|
||||
return logs.value.slice(start, start + pageSize)
|
||||
})
|
||||
|
||||
function resultTagType(row: LogItem): string {
|
||||
if (row.result === '成功') return 'success'
|
||||
if (row.result === '失败') return 'danger'
|
||||
return 'info'
|
||||
}
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
currentPage.value = 1
|
||||
if (newRow && props.apiMethod) {
|
||||
apiLoading.value = true
|
||||
try {
|
||||
@ -128,100 +160,35 @@ const logs = computed<LogItem[]>(() => {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 对齐 order/orderManagement 的 log.vue(el-table 表格 + 本地分页) */
|
||||
.log-panel {
|
||||
padding: 8px 0;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
.log-table {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.log-empty {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 12px;
|
||||
padding-left: 4px;
|
||||
border-left: 3px solid #409eff;
|
||||
}
|
||||
|
||||
.log-timeline {
|
||||
padding-left: 8px;
|
||||
|
||||
.log-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px dashed #ebeef5;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.log-dot {
|
||||
flex-shrink: 0;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
margin-top: 6px;
|
||||
border-radius: 50%;
|
||||
background: #c0c4cc;
|
||||
|
||||
&.success {
|
||||
background: #67c23a;
|
||||
}
|
||||
|
||||
&.warning {
|
||||
background: #e6a23c;
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: #f56c6c;
|
||||
}
|
||||
|
||||
&.info {
|
||||
background: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.log-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.log-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.log-operator {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.log-action {
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.log-detail {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.log-time {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
.log-pagination {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -630,6 +630,9 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 布局样式对齐 order/orderManagement(order-sub.scss) */
|
||||
@use "../order/orderManagement/styles/order-sub.scss";
|
||||
|
||||
/* ================================================================
|
||||
整体布局
|
||||
================================================================ */
|
||||
@ -669,28 +672,6 @@ onMounted(() => {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.order-sub-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: #f0f2f5;
|
||||
|
||||
:deep(.scan-box-container) {
|
||||
flex: 0 0 220px;
|
||||
flex-shrink: 0;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tab-content-inner {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
@ -698,138 +679,14 @@ onMounted(() => {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
3. 工具栏
|
||||
================================================================ */
|
||||
.toolbar {
|
||||
margin-bottom: 3px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #ebeef5;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: #fff;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
.toolbar-left {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.toolbar-right {
|
||||
flex: 0 0 auto;
|
||||
margin-left: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
4. 分栏区域
|
||||
================================================================ */
|
||||
/* 分栏区域:布局样式由 order/orderManagement/styles/order-sub.scss 提供,此处仅补充模板特有规则 */
|
||||
.split-stack {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
|
||||
:deep(.el-card__header) {
|
||||
padding: 2px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
.upper-wrapper {
|
||||
flex: 1 1 62%;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 详情面板禁用时,表格占满全高 */
|
||||
.upper-wrapper--full {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pane-resizer {
|
||||
flex-shrink: 0;
|
||||
height: 5px;
|
||||
cursor: row-resize;
|
||||
background-color: #f0f2f5;
|
||||
border-top: 1px solid #ebeef5;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
transition: background-color 0.2s;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: #d3d9e3;
|
||||
}
|
||||
}
|
||||
|
||||
.lower-level {
|
||||
flex: 1 1 38%;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.el-card) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.no-selection {
|
||||
flex: 1 1 38%;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
|
||||
.empty-tip p {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
5. 明细面板
|
||||
================================================================ */
|
||||
.detail-header {
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid #e8eef7;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
|
||||
.detail-tab {
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
height: 1px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.detail-container {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
6. 过渡动画
|
||||
================================================================ */
|
||||
|
||||
@ -1607,8 +1607,7 @@ export function applyOrderListCopyActions<T extends { prop: string; formatter?:
|
||||
export const orderStoreRemarkColumn = {
|
||||
prop: 'store_remark',
|
||||
label: '货主',
|
||||
width: '120',
|
||||
showOverflowTooltip: true
|
||||
width: '120'
|
||||
}
|
||||
|
||||
/** 订单列表:波次内序号(接口字段 wave_index) */
|
||||
@ -1616,8 +1615,7 @@ export const orderWaveIndexColumn = {
|
||||
prop: 'wave_index',
|
||||
label: '序号',
|
||||
width: '70',
|
||||
align: 'center',
|
||||
showOverflowTooltip: true
|
||||
align: 'center'
|
||||
}
|
||||
|
||||
export const deliveryColumns = applyOrderListCopyActions([
|
||||
@ -1766,7 +1764,7 @@ export const reviewColums = applyOrderListCopyActions([
|
||||
{ prop: 'delivery_order_code', label: '发货单号', width: '170' },
|
||||
{ prop: 'wave_no', label: '波次号', width: '170' },
|
||||
{ prop: 'order_flag', label: '订单标记', minWidth: '260' },
|
||||
{ prop: 'shop_nick', label: '店铺名称', width: '140', showOverflowTooltip: true },
|
||||
{ prop: 'shop_nick', label: '店铺名称', width: '140' },
|
||||
orderStoreRemarkColumn,
|
||||
{ prop: 'sys_platform_name', label: '平台编码', width: '100' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号', width: '140' },
|
||||
@ -1945,7 +1943,7 @@ export const pendingCloums = [
|
||||
{ prop: 'name', label: '收件人', width: '110' },
|
||||
{ prop: 'mobile', label: '电话', width: '120' },
|
||||
{ prop: 'buyer_message', label: '买家留言', minWidth: '180' },
|
||||
{ prop: 'seller_message', label: '卖家留言', minWidth: '180', showOverflowTooltip: true },
|
||||
{ prop: 'seller_message', label: '卖家留言', minWidth: '180' },
|
||||
{ prop: 'is_urgency', label: '是否紧急', width: '100' },
|
||||
{ prop: 'sync_status', label: '同步状态', width: '100' },
|
||||
{ prop: 'storage_status', label: '储位状态', width: '100' },
|
||||
@ -1965,7 +1963,7 @@ export const pendingCloums = [
|
||||
{ prop: 'create_channel', label: '来源', width: '120' },
|
||||
{ prop: 'source_order_codes', label: '平台交易单号', width: '140', showOverflowTooltip: true },
|
||||
{ prop: 'logistics_name', label: '快递', width: '120' },
|
||||
{ prop: 'remark', label: '留言', width: '160', showOverflowTooltip: true },
|
||||
{ prop: 'remark', label: '留言', width: '160' },
|
||||
]
|
||||
|
||||
/** 列表字段显示名(以待处理订单 pendingCloums 为准,含动态插入列) */
|
||||
|
||||
@ -39,7 +39,9 @@
|
||||
|
||||
<!-- 主内容区容器(对齐 stock/stockManagement 的 main-container) -->
|
||||
<div class="main-container">
|
||||
<component :is="activeComponent" :key="activeTab" />
|
||||
<transition name="tab-fade" mode="out-in">
|
||||
<component :is="activeComponent" :key="activeTab" />
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -55,7 +57,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted, computed, markRaw } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { orderBadgeCount } from '@/api/order.index/orderindex'
|
||||
import ReviewOrder from './reviewOrder.vue'
|
||||
@ -72,7 +74,6 @@ import { safeInvoke } from '@/utils/safe-invoke'
|
||||
import { ORDER_PAGE_CONFIG } from './config/order-common-config'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const settingsStore = useSettingsStore()
|
||||
const singlePage = ORDER_PAGE_CONFIG.singlePage
|
||||
const badgeLoading = ref(false)
|
||||
@ -186,9 +187,12 @@ function refreshBadgeCounts() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步地址栏 tab 与当前页签。
|
||||
* AppMain 使用 route.fullPath 作为 router-view 的 key;首屏缺少 tab 时若 router.replace 补上 ?tab=,
|
||||
* fullPath 变化会整页销毁重建,各子页 onMounted 数据请求会执行两次。缺省「待处理订单」时只更新 activeTab,不写回路由。
|
||||
* 首屏 / 外部导航时从地址栏恢复 tab。
|
||||
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
|
||||
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
|
||||
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
|
||||
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
|
||||
* 非法 / 缺失 tab 时纯本地归位到「待处理订单」,绝不写回路由。
|
||||
*/
|
||||
watch(
|
||||
() => route.query.tab,
|
||||
@ -202,14 +206,6 @@ watch(
|
||||
}
|
||||
|
||||
activeTab.value = 'pendingOrder'
|
||||
if (raw && !validTabs.includes(raw)) {
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: 'pendingOrder'
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
@ -218,19 +214,15 @@ onMounted(() => {
|
||||
loadBadgeCounts()
|
||||
})
|
||||
|
||||
// 切换标签后同步 URL(使用 tab-change:在 v-model 更新之后触发,避免与 tab-click 重入)
|
||||
// 切换标签(使用 tab-change:在 v-model 更新之后触发,避免与 tab-click 重入)
|
||||
const handleTabChange = (tabName: string | number) => {
|
||||
safeInvoke(() => {
|
||||
const name = String(tabName)
|
||||
if (String(route.query.tab ?? '') === name) {
|
||||
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
|
||||
if (activeTab.value === name) {
|
||||
return
|
||||
}
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: name
|
||||
}
|
||||
})
|
||||
activeTab.value = name
|
||||
return loadBadgeCounts()
|
||||
})
|
||||
}
|
||||
@ -388,4 +380,16 @@ const handleTabChange = (tabName: string | number) => {
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 页签切换淡入淡出(对齐 storage/generalreport 的 tab-fade) ===== */
|
||||
.tab-fade-enter-active,
|
||||
.tab-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-fade-enter-from,
|
||||
.tab-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -29,13 +29,15 @@
|
||||
|
||||
<!-- 主内容区容器(对齐 order/orderManagement 的 main-container) -->
|
||||
<div class="main-container">
|
||||
<keep-alive>
|
||||
<component
|
||||
:is="activeComponent"
|
||||
:key="activeTab"
|
||||
v-bind="activeTabProps"
|
||||
/>
|
||||
</keep-alive>
|
||||
<transition name="tab-fade" mode="out-in">
|
||||
<keep-alive>
|
||||
<component
|
||||
:is="activeComponent"
|
||||
:key="activeTab"
|
||||
v-bind="activeTabProps"
|
||||
/>
|
||||
</keep-alive>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -54,7 +56,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed, markRaw } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import GroupWaveBatchListPanel from './GroupWaveBatchListPanel.vue'
|
||||
import SandanWaveBatchListPanel from './SandanWaveBatchListPanel.vue'
|
||||
@ -65,7 +67,6 @@ import { safeInvoke } from '@/utils/safe-invoke'
|
||||
import { WAVE_PAGE_CONFIG } from './config/wave-config'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
@ -133,10 +134,12 @@ const tabs = ref<WaveTabItem[]>([
|
||||
])
|
||||
|
||||
/**
|
||||
* 同步地址栏 tab 与当前页签。
|
||||
* 注意:布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
|
||||
* 若在「无 tab 参数」的首屏强制 router.replace 补上 ?tab=,会改变 fullPath 导致整页销毁重建,
|
||||
* 波次页签子组件会挂载两次并重复请求。缺省团购页签时只更新本地 activeTab,不写回路由。
|
||||
* 首屏 / 外部导航时从地址栏恢复 tab。
|
||||
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
|
||||
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
|
||||
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
|
||||
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
|
||||
* 非法 / 缺失 tab 时纯本地归位到团购波次,绝不写回路由。
|
||||
*/
|
||||
watch(
|
||||
() => route.query.tab,
|
||||
@ -150,14 +153,6 @@ watch(
|
||||
}
|
||||
|
||||
activeTab.value = 'groupWave'
|
||||
if (raw && !validTabs.includes(raw)) {
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: 'groupWave'
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
@ -165,15 +160,11 @@ watch(
|
||||
const handleTabChange = (tabName: string | number) => {
|
||||
safeInvoke(() => {
|
||||
const name = String(tabName)
|
||||
if (String(route.query.tab ?? '') === name) {
|
||||
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
|
||||
if (activeTab.value === name) {
|
||||
return
|
||||
}
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: name
|
||||
}
|
||||
})
|
||||
activeTab.value = name
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@ -309,4 +300,16 @@ const handleTabChange = (tabName: string | number) => {
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 页签切换淡入淡出(对齐 storage/generalreport 的 tab-fade) ===== */
|
||||
.tab-fade-enter-active,
|
||||
.tab-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-fade-enter-from,
|
||||
.tab-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -141,15 +141,17 @@
|
||||
</div>
|
||||
|
||||
<div class="detail-container">
|
||||
<!-- KeepAlive 直子须为组件 vnode(不能是包装 div),:key=activeTab 使各详情 tab 独立缓存,
|
||||
切换时保留组件状态、不重建/不重复请求,避免详情 tab 切换卡顿 -->
|
||||
<KeepAlive>
|
||||
<div class="detail-page order-detail-wrapper">
|
||||
<component
|
||||
:is="activeComponent"
|
||||
:id="currentStockId"
|
||||
type="stock"
|
||||
@refresh="handleRefresh"
|
||||
/>
|
||||
</div>
|
||||
<component
|
||||
:is="activeComponent"
|
||||
:key="activeTab"
|
||||
:id="currentStockId"
|
||||
type="stock"
|
||||
class="detail-page order-detail-wrapper"
|
||||
@refresh="handleRefresh"
|
||||
/>
|
||||
</KeepAlive>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -21,21 +21,24 @@
|
||||
|
||||
<!-- ===== 主内容区容器(对齐 setting/encoding / waveOrder2 的 main-container) ===== -->
|
||||
<div class="main-container">
|
||||
<component :is="tabs.find(t => t.name === activeTab)?.component" :key="activeTab" />
|
||||
<transition name="tab-fade" mode="out-in">
|
||||
<keep-alive>
|
||||
<component :is="tabs.find(t => t.name === activeTab)?.component" :key="activeTab" />
|
||||
</keep-alive>
|
||||
</transition>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, markRaw, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { safeInvoke } from '@/utils/safe-invoke'
|
||||
import StockDetail from '../stock/index.vue'
|
||||
import ComboStock from '../combo_stock/index.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
@ -72,6 +75,14 @@ function resolveDefaultTab(): string {
|
||||
return 'stockDetail'
|
||||
}
|
||||
|
||||
/**
|
||||
* 首屏 / 外部导航时从地址栏恢复 tab(含按 path 推断默认 tab:combo 路径 → 组合商品)。
|
||||
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
|
||||
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
|
||||
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
|
||||
* 此处仅:① 首屏按 URL / path 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
|
||||
* 非法 / 缺失 tab 时纯本地归位到默认 tab,绝不写回路由。
|
||||
*/
|
||||
watch(
|
||||
() => [route.query.tab, route.path] as const,
|
||||
([newTab]) => {
|
||||
@ -84,14 +95,6 @@ watch(
|
||||
}
|
||||
|
||||
activeTab.value = resolveDefaultTab()
|
||||
if (raw && !validTabs.includes(raw)) {
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: resolveDefaultTab()
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
@ -99,15 +102,11 @@ watch(
|
||||
const handleTabChange = (tabName: string | number) => {
|
||||
safeInvoke(() => {
|
||||
const name = String(tabName)
|
||||
if (String(route.query.tab ?? '') === name) {
|
||||
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
|
||||
if (activeTab.value === name) {
|
||||
return
|
||||
}
|
||||
router.replace({
|
||||
query: {
|
||||
...route.query,
|
||||
tab: name
|
||||
}
|
||||
})
|
||||
activeTab.value = name
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@ -215,4 +214,16 @@ const handleTabChange = (tabName: string | number) => {
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ===== 页签切换淡入淡出(对齐 storage/generalreport 的 tab-fade) ===== */
|
||||
.tab-fade-enter-active,
|
||||
.tab-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-fade-enter-from,
|
||||
.tab-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<!--
|
||||
ColumnCellRenderer — 通用表格列渲染器
|
||||
|
||||
根据传入的 ColumnSlotConfig 决定如何渲染单元格:
|
||||
- type='tag' → el-tag(支持 tagResolver / tagType 颜色映射)
|
||||
- type='text' → 纯文本(支持 datetime 格式化)
|
||||
- type='default' → 默认插槽渲染
|
||||
- type='operation' → 操作列(由 OperationCellRenderer 处理)
|
||||
-->
|
||||
<template>
|
||||
<template v-if="!config || config.type === 'default'">
|
||||
<slot />
|
||||
</template>
|
||||
<template v-else-if="config.type === 'tag'">
|
||||
<el-tag size="small" :type="resolvedTagType">
|
||||
{{ displayValue }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ displayValue }}</span>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ColumnSlotConfig } from '../config/template-config'
|
||||
import { TAG_RESOLVERS, translate, formatTime } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ColumnCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 列插槽渲染配置 */
|
||||
config: ColumnSlotConfig | undefined
|
||||
/** 单元格值 */
|
||||
value: any
|
||||
}>()
|
||||
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||||
const displayValue = computed(() => {
|
||||
const v = props.value
|
||||
if (props.config?.translateField) {
|
||||
return translate(props.config.translateField, v)
|
||||
}
|
||||
if (props.config?.format === 'datetime') {
|
||||
return formatTime(v)
|
||||
}
|
||||
return v ?? '—'
|
||||
})
|
||||
|
||||
const resolvedTagType = computed(() => {
|
||||
if (!props.config || props.config.type !== 'tag') return ''
|
||||
const { tagType, tagResolver } = props.config
|
||||
// 优先使用 tagResolver(函数名映射)
|
||||
if (tagResolver && TAG_RESOLVERS[tagResolver]) {
|
||||
return TAG_RESOLVERS[tagResolver](props.value)
|
||||
}
|
||||
// 其次使用 tagType 映射表(用原始值查找)
|
||||
if (tagType && typeof tagType === 'object') {
|
||||
return tagType[String(props.value)] ?? 'info'
|
||||
}
|
||||
// 最后使用固定值
|
||||
return (typeof tagType === 'string' ? tagType : 'info')
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,175 @@
|
||||
<!--
|
||||
OperationCellRenderer — 表格操作列渲染组件
|
||||
|
||||
根据 operationButtons 配置渲染按钮列表。
|
||||
|
||||
支持的行为类型:
|
||||
- actionType='action' → 触发 @operation-action 事件(可选配置 confirmMessage 弹确认框)
|
||||
- actionType='form' → 打开 COMPONENT_REGISTRY 中注册的表单组件
|
||||
|
||||
使用方式:在 index.vue 中通过插槽 column-operation 引入:
|
||||
<OperationCellRenderer
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
-->
|
||||
<template>
|
||||
<div class="operation-cell">
|
||||
<template v-for="btn in buttons" :key="btn.key">
|
||||
<!-- action 按钮:支持确认弹窗 -->
|
||||
<el-button
|
||||
v-if="btn.actionType === 'action'"
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:loading="actionLoadingMap[btn.key]"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="handleActionClick(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- form 按钮:打开表单弹窗 -->
|
||||
<template v-else-if="btn.actionType === 'form'">
|
||||
<el-button
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="openForm(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<component
|
||||
:is="resolvedFormComponents[btn.key]"
|
||||
v-if="resolvedFormComponents[btn.key] && activeFormKey === btn.key"
|
||||
v-model:visible="formVisibleMap[btn.key]"
|
||||
v-bind="buildFormProps(btn)"
|
||||
@success="handleFormSuccess(btn.key)"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, markRaw, type Component } from 'vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { COMPONENT_REGISTRY } from '../config/template-config'
|
||||
import type { OperationButtonConfig } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'OperationCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 操作按钮配置列表(来自 TabPageConfig.operationButtons) */
|
||||
buttons?: OperationButtonConfig[]
|
||||
/** 当前行数据 */
|
||||
row: Record<string, any>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** action 按钮点击事件(key: 按钮标识, row: 行数据) */
|
||||
(e: 'operation-action', key: string, row: Record<string, any>): void
|
||||
}>()
|
||||
|
||||
// ===== form 弹窗管理 =====
|
||||
const activeFormKey = ref('')
|
||||
const formVisibleMap = reactive<Record<string, boolean>>({})
|
||||
const resolvedFormComponents = ref<Record<string, Component>>({})
|
||||
const actionLoadingMap = reactive<Record<string, boolean>>({})
|
||||
|
||||
// ============================================================
|
||||
// action 按钮:支持确认弹窗
|
||||
// ============================================================
|
||||
|
||||
async function handleActionClick(btn: OperationButtonConfig) {
|
||||
if (btn.confirmMessage) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
btn.confirmMessage,
|
||||
btn.confirmTitle || '确认操作',
|
||||
{
|
||||
confirmButtonText: btn.confirmButtonText || '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: (btn.confirmType || 'warning') as any
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return // 取消
|
||||
}
|
||||
}
|
||||
|
||||
actionLoadingMap[btn.key] = true
|
||||
try {
|
||||
emit('operation-action', btn.key, props.row)
|
||||
} finally {
|
||||
actionLoadingMap[btn.key] = false
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// form 按钮:打开表单弹窗
|
||||
// ============================================================
|
||||
|
||||
function openForm(btn: OperationButtonConfig) {
|
||||
if (!btn.formKey) return
|
||||
|
||||
const comp = COMPONENT_REGISTRY[btn.formKey]
|
||||
if (!comp) {
|
||||
console.warn(`[OperationCellRenderer] 未注册的表单组件: ${btn.formKey}`)
|
||||
return
|
||||
}
|
||||
|
||||
activeFormKey.value = btn.key
|
||||
resolvedFormComponents.value[btn.key] = markRaw(comp)
|
||||
formVisibleMap[btn.key] = true
|
||||
}
|
||||
|
||||
function buildFormProps(btn: OperationButtonConfig): Record<string, any> {
|
||||
const result: Record<string, any> = {}
|
||||
|
||||
// paramMap: { formProp: rowField } → 从行数据取值注入表单
|
||||
if (btn.paramMap) {
|
||||
for (const [formProp, rowField] of Object.entries(btn.paramMap)) {
|
||||
result[formProp] = props.row[rowField]
|
||||
}
|
||||
}
|
||||
|
||||
// extraParams: 固定参数直接注入
|
||||
if (btn.extraParams) {
|
||||
Object.assign(result, btn.extraParams)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function handleFormSuccess(key: string) {
|
||||
emit('operation-action', key, props.row)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 按钮禁用判断
|
||||
// ============================================================
|
||||
|
||||
function isDisabled(btn: OperationButtonConfig): boolean {
|
||||
if (btn.disabledOnField) {
|
||||
const val = props.row[btn.disabledOnField]
|
||||
if (val === undefined || val === null || val === '' || val === false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.operation-cell {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
132
src/views/storage/generalreport/components/TabArea.vue
Normal file
132
src/views/storage/generalreport/components/TabArea.vue
Normal file
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<div class="tab-area-wrapper">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-click="handleTabClick"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineOptions({ name: 'TabArea' })
|
||||
|
||||
interface TabItem {
|
||||
name: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
tabs?: TabItem[]
|
||||
defaultActive?: string
|
||||
}>(),
|
||||
{
|
||||
tabs: () => [],
|
||||
defaultActive: ''
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'tab-change', tabName: string): void
|
||||
}>()
|
||||
|
||||
const activeTab = ref(props.defaultActive || props.tabs[0]?.name || '')
|
||||
|
||||
const handleTabClick = (pane: any) => {
|
||||
const name = pane?.name ?? pane?.props?.name ?? ''
|
||||
if (name) {
|
||||
activeTab.value = name
|
||||
emit('tab-change', name)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tab-area-wrapper {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__header.is-top) {
|
||||
padding: 4px 12px 0;
|
||||
background: #f8fbff;
|
||||
border-bottom: 1px solid #e8eef7;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top) {
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
padding: 0 20px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top:hover) {
|
||||
color: #409eff;
|
||||
background-color: rgba(64, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top.is-active) {
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
background: #ffffff;
|
||||
border-color: #e8eef7;
|
||||
border-bottom: 2px solid #ffffff;
|
||||
margin-bottom: -1px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__active-bar) {
|
||||
height: 2px;
|
||||
border-radius: 2px;
|
||||
background-color: #409eff;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__content) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,179 @@
|
||||
<!--
|
||||
DetailPanel — 明细面板(通用)
|
||||
|
||||
根据 detailConfig 配置的 sections 渲染 el-descriptions 分区。
|
||||
支持 text、tag、pre 三种渲染类型。
|
||||
支持 translateField + tagResolver 集中式翻译。
|
||||
支持 apiMethod 自动获取详情数据。
|
||||
-->
|
||||
<template>
|
||||
<div class="detail-panel">
|
||||
<div v-if="!row" class="empty-tip">请从上方列表中选择一项查看明细</div>
|
||||
<template v-else>
|
||||
<div v-for="(section, si) in detailConfig" :key="si" class="section">
|
||||
<div class="section-title">{{ section.title }}</div>
|
||||
<el-descriptions :column="section.columnCount" border size="small" class="detail-descriptions">
|
||||
<el-descriptions-item
|
||||
v-for="(field, fi) in section.fields"
|
||||
:key="fi"
|
||||
:label="field.label"
|
||||
:span="field.span ?? 1"
|
||||
>
|
||||
<!-- tag 渲染 -->
|
||||
<template v-if="field.renderType === 'tag'">
|
||||
<el-tag size="small" :type="resolveTagType(field, getRowData()?.[field.key])">
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- pre 渲染 -->
|
||||
<template v-else-if="field.renderType === 'pre'">
|
||||
<pre class="order-list-pre">{{ formatPre(getRowData()?.[field.key]) }}</pre>
|
||||
</template>
|
||||
<!-- 默认文本渲染 -->
|
||||
<template v-else>
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { TAG_RESOLVERS, translate } from '../template-config'
|
||||
import type { DetailSectionConfig, DetailFieldConfig } from '../template-config'
|
||||
|
||||
defineOptions({ name: 'DetailPanel' })
|
||||
|
||||
const props = defineProps<{
|
||||
row: Record<string, any> | null
|
||||
detailConfig: DetailSectionConfig[]
|
||||
/** 可选的 detail API 方法,传入后自动调用获取完整明细数据 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的增强数据(与 row 合并) */
|
||||
const enrichedData = ref<Record<string, any> | null>(null)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
enrichedData.value = res.data ?? res
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} catch {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 合并 row + API 增强数据 */
|
||||
function getRowData(): Record<string, any> | null {
|
||||
if (!props.row) return null
|
||||
if (enrichedData.value) {
|
||||
return { ...props.row, ...enrichedData.value }
|
||||
}
|
||||
return props.row
|
||||
}
|
||||
|
||||
/** 解析显示值:优先使用 translateField 翻译,否则显示原始值 */
|
||||
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
if (field.translateField) {
|
||||
return translate(field.translateField, value)
|
||||
}
|
||||
return value ?? '—'
|
||||
}
|
||||
|
||||
/** 格式化 pre 渲染值:数组/对象转 JSON 字符串 */
|
||||
function formatPre(value: any): string {
|
||||
if (value === undefined || value === null || value === '') return '—'
|
||||
if (Array.isArray(value) && value.length === 0) return '—'
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
return JSON.stringify(value, null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** 解析 tag 颜色 */
|
||||
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
if (field.tagResolver) {
|
||||
const resolver = TAG_RESOLVERS[field.tagResolver]
|
||||
if (resolver) return resolver(value)
|
||||
}
|
||||
if (field.tagType) {
|
||||
if (typeof field.tagType === 'object') {
|
||||
return field.tagType[String(value)] ?? 'info'
|
||||
}
|
||||
return field.tagType
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 容器对齐 order/orderManagement 的 OrderDetailPanel(.order-detail-view) */
|
||||
.detail-panel {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 10px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #409eff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-descriptions {
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 120px;
|
||||
background: #fafbfc;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.order-list-pre {
|
||||
margin: 0;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
194
src/views/storage/generalreport/config/components/LogPanel.vue
Normal file
194
src/views/storage/generalreport/config/components/LogPanel.vue
Normal file
@ -0,0 +1,194 @@
|
||||
<!--
|
||||
LogPanel — 操作日志面板(通用)
|
||||
|
||||
支持两种数据来源:
|
||||
- apiMethod 传入 → 调用真实接口获取日志
|
||||
- 无 apiMethod → 基于 row 生成模拟日志(开发调试用)
|
||||
-->
|
||||
<template>
|
||||
<div class="log-panel">
|
||||
<div v-if="apiLoading" v-loading="true" class="log-empty">加载中…</div>
|
||||
<template v-else>
|
||||
<el-table
|
||||
v-if="logs.length"
|
||||
:data="pagedLogs"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
class="log-table"
|
||||
>
|
||||
<el-table-column prop="time" label="时间" width="175" />
|
||||
<el-table-column prop="operator" label="操作人" width="120" />
|
||||
<el-table-column prop="action" label="操作类型" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column label="结果" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="resultTagType(row)">{{ row.result }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="说明" min-width="220" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.detail || '—' }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-else class="log-empty">暂无操作日志</div>
|
||||
|
||||
<div v-if="logs.length > pageSize" class="log-pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:total="logs.length"
|
||||
layout="total, prev, pager, next"
|
||||
background
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
defineOptions({ name: 'LogPanel' })
|
||||
|
||||
interface LogItem {
|
||||
operator: string
|
||||
action: string
|
||||
result: string
|
||||
detail?: string
|
||||
time: string
|
||||
level: 'success' | 'info' | 'warning' | 'error'
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前选中行数据(用于生成关联日志) */
|
||||
row: Record<string, any> | null
|
||||
/** 可选的日志 API 方法,传入后自动调用获取真实日志 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的真实日志列表 */
|
||||
const apiLogs = ref<LogItem[] | null>(null)
|
||||
const apiLoading = ref(false)
|
||||
|
||||
/** 表格本地分页(对齐 order/orderManagement 的 log.vue 体验) */
|
||||
const currentPage = ref(1)
|
||||
const pageSize = 10
|
||||
const pagedLogs = computed<LogItem[]>(() => {
|
||||
const start = (currentPage.value - 1) * pageSize
|
||||
return logs.value.slice(start, start + pageSize)
|
||||
})
|
||||
|
||||
function resultTagType(row: LogItem): string {
|
||||
if (row.result === '成功') return 'success'
|
||||
if (row.result === '失败') return 'danger'
|
||||
return 'info'
|
||||
}
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
currentPage.value = 1
|
||||
if (newRow && props.apiMethod) {
|
||||
apiLoading.value = true
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const list = res.data?.list ?? res.data?.logs ?? res.list ?? res.logs ?? []
|
||||
apiLogs.value = Array.isArray(list) ? list.map((item: any) => ({
|
||||
operator: item.operator ?? item.creator ?? '—',
|
||||
action: item.action ?? item.operation ?? '—',
|
||||
result: item.result ?? item.status ?? '—',
|
||||
detail: item.detail ?? item.description ?? '',
|
||||
time: item.time ?? item.create_time ?? '—',
|
||||
level: (item.result === '成功' || item.status === 'success') ? 'success'
|
||||
: (item.result === '失败' || item.status === 'error') ? 'error'
|
||||
: 'info'
|
||||
})) : []
|
||||
} else {
|
||||
apiLogs.value = []
|
||||
}
|
||||
} catch {
|
||||
apiLogs.value = []
|
||||
} finally {
|
||||
apiLoading.value = false
|
||||
}
|
||||
} else {
|
||||
apiLogs.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 基于 row 生成模拟日志(无 apiMethod 时使用) */
|
||||
const mockLogs = computed<LogItem[]>(() => {
|
||||
if (!props.row) return []
|
||||
|
||||
const rowName = props.row.name ?? props.row.code ?? '—'
|
||||
const now = new Date()
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const fmt = (d: Date) =>
|
||||
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
|
||||
return [
|
||||
{
|
||||
operator: '系统',
|
||||
action: `创建了「${rowName}」`,
|
||||
result: '成功',
|
||||
time: fmt(new Date(now.getTime() - 3600000 * 3)),
|
||||
level: 'success'
|
||||
},
|
||||
{
|
||||
operator: props.row.creator ?? '管理员',
|
||||
action: `更新了「${rowName}」`,
|
||||
result: '成功',
|
||||
detail: `修改了状态和相关配置`,
|
||||
time: fmt(new Date(now.getTime() - 3600000)),
|
||||
level: 'success'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/** 最终展示的日志:优先使用 API 日志,否则使用 mock 日志 */
|
||||
const logs = computed<LogItem[]>(() => {
|
||||
if (apiLogs.value !== null) {
|
||||
return apiLogs.value
|
||||
}
|
||||
return mockLogs.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 对齐 order/orderManagement 的 log.vue(el-table 表格 + 本地分页) */
|
||||
.log-panel {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.log-table {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.log-empty {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.log-pagination {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 10px;
|
||||
}
|
||||
</style>
|
||||
1103
src/views/storage/generalreport/config/template-config.ts
Normal file
1103
src/views/storage/generalreport/config/template-config.ts
Normal file
File diff suppressed because it is too large
Load Diff
745
src/views/storage/generalreport/index.vue
Normal file
745
src/views/storage/generalreport/index.vue
Normal file
@ -0,0 +1,745 @@
|
||||
<!--
|
||||
╔══════════════════════════════════════════════════════════════╗
|
||||
║ 【页面模板 v2】— 基于 waveOrder2 架构设计 ║
|
||||
╚══════════════════════════════════════════════════════════════╝
|
||||
|
||||
===== 快速复制使用 =====
|
||||
1. 复制整个 views/mode/ 文件夹 → 重命名为你的页面名(如 views/order/myPage/)
|
||||
2. 修改 defineOptions name(如 'MyPage')
|
||||
3. 编辑 config/template-config.ts:
|
||||
a. 在 FIELD_DICT 中添加页面字段
|
||||
b. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||||
c. 在 TabPageApiConfig 中接入真实接口
|
||||
4. 在 router/map.ts 中添加路由
|
||||
|
||||
===== 页面结构 =====
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ TabArea(多标签页切换,可关闭) │
|
||||
├──────────┬──────────────────────────────────────────────┤
|
||||
│ ScanBox │ OrderToolbarButtonGroup(工具栏按钮组) │
|
||||
│ 筛选面板 │ ┌──────────────────────────────────────────┐│
|
||||
│ │ │ UpperTable(表格) ││
|
||||
│ │ │ - OperationCellRenderer(操作列) ││
|
||||
│ │ ├──────────────────────────────────────────┤│
|
||||
│ │ │ 分隔条(可拖拽) ││
|
||||
│ │ ├──────────────────────────────────────────┤│
|
||||
│ │ │ DetailPanel / LogPanel(明细/日志面板) ││
|
||||
│ │ └──────────────────────────────────────────┘│
|
||||
└──────────┴──────────────────────────────────────────────┘
|
||||
-->
|
||||
<template>
|
||||
<div class="page-wrapper" :style="{ height: containerHeight }">
|
||||
<!-- ===== 多标签模式:显示顶部标签栏 ===== -->
|
||||
<template v-if="PAGE_CONFIG.showTabArea && !PAGE_CONFIG.singlePage">
|
||||
<div class="tab-section">
|
||||
<TabArea
|
||||
:tabs="tabList"
|
||||
:default-active="activeTabName"
|
||||
@tab-change="handleTabChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ===== 主内容区 ===== -->
|
||||
<div class="main-container">
|
||||
<div class="order-sub-container">
|
||||
<!-- 左侧:ScanBox 筛选面板 -->
|
||||
<ScanBox
|
||||
ref="scanBoxRef"
|
||||
:cache-key="currentScanBoxCacheKey"
|
||||
width="220px"
|
||||
:tree-props="{ children: 'children', label: 'label' }"
|
||||
:auto-submit="false"
|
||||
:preset-tree="presetTree"
|
||||
:available-fields="currentScanBoxFields"
|
||||
@condition-change="handleConditionChange"
|
||||
@reset="handleConditionReset"
|
||||
@condition-clear="handleConditionClear"
|
||||
/>
|
||||
|
||||
<!-- 右侧:内容区 -->
|
||||
<div class="main-content">
|
||||
<transition name="tab-fade" mode="out-in">
|
||||
<div :key="activeTabName" class="tab-content-inner">
|
||||
<!-- 工具栏按钮组 -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<OrderToolbarButtonGroup
|
||||
:buttons="currentToolbarButtons"
|
||||
:resolve-disabled="resolveButtonDisabled"
|
||||
:resolve-loading="resolveButtonLoading"
|
||||
:resolve-label="resolveButtonLabel"
|
||||
:layout-key="toolbarLayoutKey"
|
||||
@action="handleToolbarButtonClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 上下分栏区域:详情面板启用时才显示分栏 + 详情 -->
|
||||
<template v-if="PAGE_CONFIG.enableDetailPanel">
|
||||
<div class="split-stack" ref="splitStackRef">
|
||||
<!-- 上半:表格 -->
|
||||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||||
<UpperTable
|
||||
ref="upperTableRef"
|
||||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||||
default-align="center"
|
||||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||||
:column-config-schema-version="1"
|
||||
:table-id="`template-table-${activeTabName}`"
|
||||
:data="listData"
|
||||
:row-key="'id'"
|
||||
:columns="currentColumns"
|
||||
table-size="small"
|
||||
:pagination="pagination"
|
||||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||||
:show-selection="currentTabConfig?.upperTable.showSelection ?? true"
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@row-click="handleRowClick"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadData"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<!-- 动态列插槽:根据 columnSlots 配置自动渲染 -->
|
||||
<template
|
||||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||||
:key="`columnSlots-${colProp}`"
|
||||
#[`column-${colProp}`]="{ row }"
|
||||
>
|
||||
<!-- 操作列:渲染操作按钮 -->
|
||||
<OperationCellRenderer
|
||||
v-if="slotConfig.type === 'operation'"
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
<!-- 其他列:标签/文本渲染 -->
|
||||
<ColumnCellRenderer
|
||||
v-else
|
||||
:config="slotConfig"
|
||||
:value="row[colProp]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #empty>
|
||||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||||
</template>
|
||||
</UpperTable>
|
||||
</div>
|
||||
|
||||
<!-- 分隔条(可拖拽) -->
|
||||
<template v-if="detailVisible">
|
||||
<div
|
||||
class="pane-resizer"
|
||||
title="拖动调整列表与详情区域高度"
|
||||
@mousedown="beginSplitDrag"
|
||||
/>
|
||||
|
||||
<!-- 下半:明细面板 -->
|
||||
<div v-if="selectedRow" class="lower-level" :style="lowerPaneStyle">
|
||||
<div class="detail-header">
|
||||
<el-tabs v-model="activeDetailTab" class="detail-tab">
|
||||
<el-tab-pane
|
||||
v-for="tab in currentDetailTabs"
|
||||
:key="tab.name"
|
||||
:label="tab.label"
|
||||
:name="tab.name"
|
||||
/>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<div class="detail-container">
|
||||
<component
|
||||
:is="activeDetailTabComponent"
|
||||
:row="selectedDetail"
|
||||
:detail-config="currentDetailConfig"
|
||||
:api-method="currentDetailTabApiMethod"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未选中行时的占位 -->
|
||||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||||
<div class="empty-tip">
|
||||
<p>请从上方列表中选择一项查看详情</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 详情面板禁用:表格占满全高 -->
|
||||
<template v-else>
|
||||
<div class="upper-wrapper upper-wrapper--full">
|
||||
<UpperTable
|
||||
ref="upperTableRef"
|
||||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||||
default-align="center"
|
||||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||||
:column-config-schema-version="1"
|
||||
:table-id="`template-table-${activeTabName}`"
|
||||
:data="listData"
|
||||
:row-key="'id'"
|
||||
:columns="currentColumns"
|
||||
table-size="small"
|
||||
:pagination="pagination"
|
||||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||||
:show-selection="currentTabConfig?.upperTable.showSelection ?? false"
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@row-click="handleRowClick"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadData"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<template
|
||||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||||
:key="`columnSlots-${colProp}`"
|
||||
#[`column-${colProp}`]="{ row }"
|
||||
>
|
||||
<OperationCellRenderer
|
||||
v-if="slotConfig.type === 'operation'"
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
<ColumnCellRenderer
|
||||
v-else
|
||||
:config="slotConfig"
|
||||
:value="row[colProp]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #empty>
|
||||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||||
</template>
|
||||
</UpperTable>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 功能按钮表单(pages/ 目录下的组件) ===== -->
|
||||
<DeliveryPlanFormDialog
|
||||
v-model:visible="createPlanVisible"
|
||||
@success="handlePlanSaved"
|
||||
/>
|
||||
<ExportReportDialog
|
||||
v-model:visible="exportReportVisible"
|
||||
:report-code="exportInitialReportCode"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// ============================================================
|
||||
// ★★★ 第一步:修改组件名 ★★★
|
||||
// ============================================================
|
||||
defineOptions({ name: 'GeneralReport' })
|
||||
|
||||
import { ref, computed, onMounted, reactive } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import TabArea from './components/TabArea.vue'
|
||||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||||
import OperationCellRenderer from './components/OperationCellRenderer.vue'
|
||||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||||
import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import {
|
||||
PAGE_CONFIG,
|
||||
tabPages,
|
||||
resolveTabConfig,
|
||||
getTabToolbarButtons,
|
||||
loadStoreOptions,
|
||||
type TabPageConfig,
|
||||
type DetailTabConfig,
|
||||
type ToolbarButtonConfig,
|
||||
} from './config/template-config'
|
||||
import DeliveryPlanFormDialog from './pages/DeliveryPlanFormDialog.vue'
|
||||
import ExportReportDialog from './pages/ExportReportDialog.vue'
|
||||
|
||||
// ============================================================
|
||||
// 容器高度
|
||||
// ============================================================
|
||||
const settingsStore = useSettingsStore()
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
const containerHeight = computed(() =>
|
||||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||||
)
|
||||
|
||||
// ============================================================
|
||||
// 标签页
|
||||
// ============================================================
|
||||
const tabList = computed(() =>
|
||||
tabPages.map((t) => ({ name: t.name, label: t.label }))
|
||||
)
|
||||
const activeTabName = ref(tabPages[0]?.name ?? 'tab1')
|
||||
|
||||
/** 当前激活标签页的完整配置 */
|
||||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||||
const raw = tabPages.find((t) => t.name === activeTabName.value)
|
||||
if (!raw) return undefined
|
||||
return resolveTabConfig(raw)
|
||||
})
|
||||
|
||||
/** 当前 ScanBox 缓存 key */
|
||||
const currentScanBoxCacheKey = computed(
|
||||
() => currentTabConfig.value?.scanBoxCacheKey ?? 'template-default'
|
||||
)
|
||||
|
||||
/** 当前 ScanBox 筛选字段 */
|
||||
const currentScanBoxFields = computed(
|
||||
() => currentTabConfig.value?.scanBoxFields ?? []
|
||||
)
|
||||
|
||||
/** 当前表格列 */
|
||||
const currentColumns = computed(
|
||||
() => currentTabConfig.value?.upperTable.columns ?? []
|
||||
)
|
||||
|
||||
/** 当前列插槽配置 */
|
||||
const currentColumnSlots = computed(
|
||||
() => currentTabConfig.value?.columnSlots ?? {}
|
||||
)
|
||||
|
||||
/** 当前明细面板配置 */
|
||||
const currentDetailConfig = computed(
|
||||
() => currentTabConfig.value?.detailConfig ?? []
|
||||
)
|
||||
|
||||
/** 当前明细标签页列表 */
|
||||
const currentDetailTabs = computed<DetailTabConfig[]>(
|
||||
() => currentTabConfig.value?.detailTabs ?? []
|
||||
)
|
||||
|
||||
/** 当前激活的明细标签页组件 */
|
||||
const activeDetailTabComponent = computed(() => {
|
||||
const tab = currentDetailTabs.value.find(
|
||||
(t) => t.name === activeDetailTab.value
|
||||
)
|
||||
return tab?.component ?? null
|
||||
})
|
||||
|
||||
/** 当前激活明细标签页对应的 API 方法 */
|
||||
const currentDetailTabApiMethod = computed(() => {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg?.api) return undefined
|
||||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||||
if (!tab) return undefined
|
||||
|
||||
let componentCfg: unknown
|
||||
switch (tab.componentKey) {
|
||||
case 'DetailPanel':
|
||||
componentCfg = cfg.api.detail
|
||||
break
|
||||
case 'LogPanel':
|
||||
componentCfg = cfg.api.log
|
||||
break
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (typeof componentCfg === 'function') {
|
||||
return componentCfg
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
// ============================================================
|
||||
// 工具栏按钮系统
|
||||
// ============================================================
|
||||
|
||||
/** 当前标签页的工具栏按钮列表 */
|
||||
const currentToolbarButtons = computed<OrderToolbarButtonConfig[]>(() => {
|
||||
const btns = getTabToolbarButtons(activeTabName.value)
|
||||
return btns.map((btn: ToolbarButtonConfig) => ({
|
||||
key: btn.key,
|
||||
label: btn.label,
|
||||
size: btn.size,
|
||||
type: btn.type,
|
||||
plain: btn.plain,
|
||||
loadingKey: btn.loadingKey,
|
||||
disabledKey: btn.disabledKey,
|
||||
action: btn.action,
|
||||
dynamicLabelKey: btn.dynamicLabelKey,
|
||||
buttonType: btn.buttonType,
|
||||
dropdownOptions: btn.dropdownOptions
|
||||
}))
|
||||
})
|
||||
|
||||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||||
noSelection: selectedRows.value.length === 0
|
||||
}))
|
||||
|
||||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||||
loading: loading.value,
|
||||
exportLoading: false
|
||||
}))
|
||||
|
||||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||||
}))
|
||||
|
||||
const toolbarLayoutKey = computed(() =>
|
||||
JSON.stringify({
|
||||
loading: buttonLoadingMap.value,
|
||||
disabled: buttonDisabledMap.value,
|
||||
labels: buttonLabelMap.value
|
||||
})
|
||||
)
|
||||
|
||||
function resolveButtonLoading(loadingKey?: string) {
|
||||
if (!loadingKey) return false
|
||||
return Boolean(buttonLoadingMap.value[loadingKey])
|
||||
}
|
||||
|
||||
function resolveButtonDisabled(disabledKey?: string) {
|
||||
if (!disabledKey) return false
|
||||
return Boolean(buttonDisabledMap.value[disabledKey])
|
||||
}
|
||||
|
||||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||||
if (!dynamicLabelKey) return defaultLabel
|
||||
return buttonLabelMap.value[dynamicLabelKey] || defaultLabel
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 工具栏动作分发
|
||||
// ============================================================
|
||||
const toolbarActionMap: Record<string, () => void> = {
|
||||
loadData: () => { void loadData() },
|
||||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||||
openCreatePlan: () => { createPlanVisible.value = true },
|
||||
openExportReport: () => { exportReportVisible.value = true },
|
||||
handleExport: () => { console.log('[GeneralReport] 导出(不含明细)', activeTabName.value) },
|
||||
handleExportItem: () => { console.log('[GeneralReport] 导出(含明细)', activeTabName.value) }
|
||||
}
|
||||
|
||||
function handleToolbarButtonClick(action: string) {
|
||||
const handler = toolbarActionMap[action]
|
||||
if (handler) {
|
||||
handler()
|
||||
return
|
||||
}
|
||||
// ★ 在此添加功能按钮分发
|
||||
console.warn('[PageTemplate] 未处理的工具栏动作:', action)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 操作列按钮事件处理
|
||||
// ============================================================
|
||||
async function handleOperationAction(key: string, row: Record<string, any>) {
|
||||
switch (key) {
|
||||
case 'viewDetail':
|
||||
// 已经通过行点击处理
|
||||
break
|
||||
case 'editPlan':
|
||||
// 表单提交成功后触发本事件,刷新列表
|
||||
loadData()
|
||||
break
|
||||
case 'exportThisReport':
|
||||
// 将该报表编码带入导出弹窗
|
||||
exportInitialReportCode.value = row?.report_code ?? ''
|
||||
exportReportVisible.value = true
|
||||
break
|
||||
default:
|
||||
console.warn('[GeneralReport] 未处理的操作按钮:', key)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 弹窗状态
|
||||
// ============================================================
|
||||
const createPlanVisible = ref(false)
|
||||
const exportReportVisible = ref(false)
|
||||
/** 导出弹窗初始报表编码(Tab3 行「导出此报表」带入) */
|
||||
const exportInitialReportCode = ref('')
|
||||
|
||||
function handlePlanSaved() {
|
||||
ElMessage.success('投递计划已保存')
|
||||
loadData()
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ★★★ 第二步:接入真实接口 ★★★
|
||||
// ============================================================
|
||||
const listData = ref<Record<string, any>[]>([])
|
||||
const loading = ref(false)
|
||||
const queryTime = ref(0)
|
||||
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const currentSort = reactive({ prop: '', order: '' })
|
||||
|
||||
const loadData = async () => {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg) return
|
||||
loading.value = true
|
||||
const startTime = performance.now()
|
||||
|
||||
try {
|
||||
if (cfg.api) {
|
||||
// 使用真实接口
|
||||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||||
|
||||
// 导出任务页:report.meta 需报表编码才能查询,未输入时不发请求并给出引导
|
||||
if (activeTabName.value === 'export' && !conditions?.report_code) {
|
||||
listData.value = []
|
||||
pagination.total = 0
|
||||
ElMessage.info('请输入报表编码后查询报表元数据')
|
||||
return
|
||||
}
|
||||
|
||||
const params = cfg.api.buildListParams
|
||||
? cfg.api.buildListParams({
|
||||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||||
conditions,
|
||||
sort: currentSort.prop ? { prop: currentSort.prop, order: currentSort.order } : undefined
|
||||
})
|
||||
: {
|
||||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||||
where: conditions
|
||||
}
|
||||
|
||||
const res = await cfg.api.list(params)
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const parsed = cfg.api.parseListResponse
|
||||
? cfg.api.parseListResponse(res)
|
||||
: { list: res.data?.list ?? res.list ?? [], total: res.data?.pagination?.total ?? res.total ?? 0 }
|
||||
listData.value = parsed.list
|
||||
pagination.total = parsed.total
|
||||
} else {
|
||||
throw new Error(res?.message || '接口返回异常')
|
||||
}
|
||||
} else {
|
||||
// ★ 未配置 API 时使用模拟数据(替换为真实接口后删除)
|
||||
console.log('[PageTemplate] 未配置 API,使用空数据。请在 tabPages 中配置 api 字段。')
|
||||
listData.value = []
|
||||
pagination.total = 0
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('[PageTemplate] 加载列表失败:', e)
|
||||
ElMessage.error(e?.message || '获取列表数据失败')
|
||||
listData.value = []
|
||||
pagination.total = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
queryTime.value = Math.round(performance.now() - startTime)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ScanBox 筛选事件
|
||||
// ============================================================
|
||||
const scanBoxRef = ref<any>(null)
|
||||
const presetTree = ref<any[]>([])
|
||||
|
||||
const handleConditionChange = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
const handleConditionReset = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
const handleConditionClear = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// UpperTable 事件
|
||||
// ============================================================
|
||||
const upperTableRef = ref<any>(null)
|
||||
const selectedRows = ref<Record<string, any>[]>([])
|
||||
|
||||
const handleSortChange = ({ prop, order }: any) => {
|
||||
currentSort.prop = prop
|
||||
currentSort.order = order
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
pagination.currentPage = page
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handlePageSizeChange = (size: number) => {
|
||||
pagination.pageSize = size
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handleSelectionChange = (rows: Record<string, any>[]) => {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 明细面板
|
||||
// ============================================================
|
||||
const detailVisible = ref(PAGE_CONFIG.enableDetailPanel)
|
||||
const selectedRow = ref<Record<string, any> | null>(null)
|
||||
const selectedDetail = ref<Record<string, any> | null>(null)
|
||||
const activeDetailTab = ref('detail')
|
||||
|
||||
const handleRowClick = async (row: Record<string, any>) => {
|
||||
if (!PAGE_CONFIG.enableDetailPanel) return
|
||||
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg) return
|
||||
selectedRow.value = row
|
||||
|
||||
// 根据 DetailPanel 的 api 配置决定数据来源
|
||||
const detailCfg = cfg.api?.detail
|
||||
if (typeof detailCfg === 'function') {
|
||||
try {
|
||||
const detailRes = await detailCfg({ id: row.id, code: row.code })
|
||||
if (detailRes && (detailRes.code === 1 || detailRes.code === 200)) {
|
||||
selectedDetail.value = detailRes.data ?? detailRes
|
||||
} else {
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
} catch {
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
} else {
|
||||
// source='list' 或未配置:直接用行数据
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 标签页切换
|
||||
// ============================================================
|
||||
const handleTabChange = (tabName: string) => {
|
||||
if (activeTabName.value === tabName) return
|
||||
activeTabName.value = tabName
|
||||
pagination.currentPage = 1
|
||||
currentSort.prop = ''
|
||||
currentSort.order = ''
|
||||
selectedRow.value = null
|
||||
selectedDetail.value = null
|
||||
selectedRows.value = []
|
||||
activeDetailTab.value = 'detail'
|
||||
loadData()
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 分栏拖拽
|
||||
// ============================================================
|
||||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } =
|
||||
useVerticalSplitPane({ defaultLowerPercent: 38 })
|
||||
|
||||
const upperPaneFullStyle = computed(() => ({
|
||||
flex: '1 1 auto',
|
||||
minHeight: '0',
|
||||
overflow: 'hidden' as const
|
||||
}))
|
||||
|
||||
// ============================================================
|
||||
// 初始化
|
||||
// ============================================================
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 布局样式对齐 order/orderManagement(order-sub.scss) */
|
||||
@use "../../order/orderManagement/styles/order-sub.scss";
|
||||
|
||||
/* ================================================================
|
||||
整体布局
|
||||
================================================================ */
|
||||
.page-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
1. 顶部多标签页
|
||||
================================================================ */
|
||||
.tab-section {
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-bottom: none;
|
||||
border-radius: 6px 6px 0 0;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
2. 主内容区
|
||||
================================================================ */
|
||||
.main-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-radius: 0 0 6px 6px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tab-content-inner {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* 分栏区域:布局样式由 order/orderManagement/styles/order-sub.scss 提供,此处仅补充模板特有规则 */
|
||||
.split-stack {
|
||||
:deep(.el-card__header) {
|
||||
padding: 2px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
6. 过渡动画
|
||||
================================================================ */
|
||||
.tab-fade-enter-active,
|
||||
.tab-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-fade-enter-from,
|
||||
.tab-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
7. 空状态
|
||||
================================================================ */
|
||||
.empty-tip {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
254
src/views/storage/generalreport/pages/DeliveryPlanFormDialog.vue
Normal file
254
src/views/storage/generalreport/pages/DeliveryPlanFormDialog.vue
Normal file
@ -0,0 +1,254 @@
|
||||
<!--
|
||||
DeliveryPlanFormDialog — 货主报表投递计划 新增/编辑 表单弹窗
|
||||
对接接口:report.deliveryPlan.save(货主 store_id + 报表 report_code 唯一,存在则更新)
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
:title="isEdit ? '编辑投递计划' : '新增投递计划'"
|
||||
width="620px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="110px"
|
||||
size="small"
|
||||
>
|
||||
<el-form-item label="货主" prop="store_id">
|
||||
<el-select
|
||||
v-model="form.store_id"
|
||||
filterable
|
||||
placeholder="请选择货主"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in storeOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="报表编码" prop="report_code">
|
||||
<el-input v-model="form.report_code" placeholder="请输入已启用的报表编码,如 deliveryPlan" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="投递时间" prop="schedule_times">
|
||||
<el-select
|
||||
v-model="form.schedule_times"
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
placeholder="输入 HH:mm 后回车,可添加多个"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="t in form.schedule_times"
|
||||
:key="t"
|
||||
:label="t"
|
||||
:value="t"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">24 小时制时间点(如 08:00),系统会自动去重并升序排列</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="投递渠道" prop="channel">
|
||||
<el-select v-model="form.channel" placeholder="选择投递渠道" style="width: 100%">
|
||||
<el-option label="企业微信" value="wecom" />
|
||||
<el-option label="站内信" value="inbox" />
|
||||
<el-option label="链接" value="link" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="补投宽限(分)" prop="late_grace_minutes">
|
||||
<el-input-number
|
||||
v-model="form.late_grace_minutes"
|
||||
:min="0"
|
||||
:max="1440"
|
||||
:precision="0"
|
||||
controls-position="right"
|
||||
placeholder="默认 60"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<div class="form-tip">0-1440,默认 60;越界值自动夹取</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" maxlength="500" placeholder="最长 500 字符" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">文本通知配置(可选)</el-divider>
|
||||
|
||||
<el-form-item label="通知模板" prop="notify_template">
|
||||
<el-input
|
||||
v-model="form.notify_template"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
maxlength="500"
|
||||
placeholder="支持标签 {time}/{url}/{report_name}/{biz_date}"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="通知群ID" prop="notify_group_ids_text">
|
||||
<el-input
|
||||
v-model="form.notify_group_ids_text"
|
||||
placeholder="多个群ID用英文逗号分隔,如 1,2,3"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="通知成员ID" prop="notify_member_ids_text">
|
||||
<el-input
|
||||
v-model="form.notify_member_ids_text"
|
||||
placeholder="多个成员ID用英文逗号分隔"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { saveDeliveryPlan } from '@/api/report/report'
|
||||
import { storeOptions, loadStoreOptions } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'DeliveryPlanFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 编辑时由行数据注入的初始值 */
|
||||
store_id?: number | string
|
||||
report_code?: string
|
||||
schedule_times?: string[]
|
||||
channel?: string
|
||||
late_grace_minutes?: number
|
||||
remark?: string
|
||||
notify_template?: string
|
||||
notify_group_ids?: number[] | null
|
||||
notify_member_ids?: string[] | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
store_id: undefined as number | undefined,
|
||||
report_code: '',
|
||||
schedule_times: [] as string[],
|
||||
channel: 'wecom',
|
||||
late_grace_minutes: 60,
|
||||
remark: '',
|
||||
notify_template: '',
|
||||
notify_group_ids_text: '',
|
||||
notify_member_ids_text: ''
|
||||
})
|
||||
|
||||
const isEdit = computed(() => Boolean(props.store_id && props.report_code))
|
||||
|
||||
const rules = {
|
||||
store_id: [{ required: true, message: '请输入货主ID', trigger: 'blur' }],
|
||||
report_code: [{ required: true, message: '请输入报表编码', trigger: 'blur' }],
|
||||
schedule_times: [{ required: true, type: 'array', min: 1, message: '至少添加一个投递时间', trigger: 'change' }]
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.store_id = props.store_id !== undefined && props.store_id !== null && props.store_id !== ''
|
||||
? Number(props.store_id)
|
||||
: undefined
|
||||
form.report_code = props.report_code ?? ''
|
||||
form.schedule_times = Array.isArray(props.schedule_times) ? [...props.schedule_times] : []
|
||||
form.channel = props.channel ?? 'wecom'
|
||||
form.late_grace_minutes = props.late_grace_minutes ?? 60
|
||||
form.remark = props.remark ?? ''
|
||||
form.notify_template = props.notify_template ?? ''
|
||||
form.notify_group_ids_text = Array.isArray(props.notify_group_ids) ? props.notify_group_ids.join(',') : ''
|
||||
form.notify_member_ids_text = Array.isArray(props.notify_member_ids) ? props.notify_member_ids.join(',') : ''
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
})
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const groupIds = form.notify_group_ids_text
|
||||
.split(/[,,]/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
.map(Number)
|
||||
.filter((n) => Number.isInteger(n) && n > 0)
|
||||
const memberIds = form.notify_member_ids_text
|
||||
.split(/[,,]/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
await saveDeliveryPlan({
|
||||
store_id: Number(form.store_id),
|
||||
report_code: form.report_code.trim(),
|
||||
schedule_times: form.schedule_times,
|
||||
channel: form.channel,
|
||||
late_grace_minutes: form.late_grace_minutes,
|
||||
remark: form.remark || undefined,
|
||||
...(form.notify_template ? { notify_template: form.notify_template } : {}),
|
||||
...(form.notify_group_ids_text.trim() ? { notify_group_ids: groupIds } : {}),
|
||||
...(form.notify_member_ids_text.trim() ? { notify_member_ids: memberIds } : {})
|
||||
})
|
||||
|
||||
ElMessage.success(isEdit.value ? '投递计划已更新' : '投递计划已创建')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '保存投递计划失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 4px 0 0;
|
||||
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
107
src/views/storage/generalreport/pages/ExampleFormDialog.vue
Normal file
107
src/views/storage/generalreport/pages/ExampleFormDialog.vue
Normal file
@ -0,0 +1,107 @@
|
||||
<!--
|
||||
ExampleFormDialog — 示例表单弹窗(模板)
|
||||
|
||||
功能按钮对应的表单组件放在 pages/ 目录下。
|
||||
|
||||
使用方式:
|
||||
1. 在 template-config.ts 的 COMPONENT_REGISTRY 中注册
|
||||
2. 在 template-config.ts 的 TOOLBAR_BUTTONS 中添加功能按钮,设置 formKey
|
||||
3. index.vue 中通过工具栏按钮触发打开
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="示例操作"
|
||||
width="500px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form ref="formRef" :model="form" label-width="100px" size="small">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input
|
||||
v-model="form.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'ExampleFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 从行数据注入的初始值(由 OperationCellRenderer 的 paramMap 传递) */
|
||||
id?: string | number
|
||||
code?: string
|
||||
name?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.name = props.name ?? ''
|
||||
form.description = ''
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true
|
||||
try {
|
||||
// ★ 替换为真实 API 调用
|
||||
// const res = await yourApi.submit({ id: props.id, ...form })
|
||||
await new Promise((r) => setTimeout(r, 500))
|
||||
|
||||
ElMessage.success('操作成功')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '操作失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 0;
|
||||
}
|
||||
</style>
|
||||
170
src/views/storage/generalreport/pages/ExportReportDialog.vue
Normal file
170
src/views/storage/generalreport/pages/ExportReportDialog.vue
Normal file
@ -0,0 +1,170 @@
|
||||
<!--
|
||||
ExportReportDialog — 报表导出提交弹窗(手动导出)
|
||||
对接接口:report.generate(提交异步导出任务,立即返回 task_id)
|
||||
warehouse_id 由服务端从登录上下文自动注入,前端无需传递。
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="提交报表导出"
|
||||
width="520px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
size="small"
|
||||
>
|
||||
<el-form-item label="报表编码" prop="report_code">
|
||||
<el-input v-model="form.report_code" placeholder="请输入报表编码(须为已启用的报表定义)" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="货主" prop="store_id">
|
||||
<el-select
|
||||
v-model="form.store_id"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="货主维度报表时选择"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in storeOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">可选;>0 生效,<=0 视为不按货主过滤</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据日期" prop="bizDate">
|
||||
<el-date-picker
|
||||
v-model="form.bizDate"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="缺省取服务器当天"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="exportLoading" @click="handleSubmit">
|
||||
提交任务
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<AsyncExportProgressDialog
|
||||
v-model:visible="exportDialogVisible"
|
||||
title="报表导出进度"
|
||||
:loading="exportLoading"
|
||||
:progress-percent="exportProgressPercent"
|
||||
:progress-status="exportProgressStatus"
|
||||
:status-label="exportStatusLabel"
|
||||
:task-id="exportTaskProgress.taskId"
|
||||
:message="exportTaskProgress.message"
|
||||
:error="exportTaskProgress.error"
|
||||
:update-time="exportTaskProgress.updateTime"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch, onMounted } from 'vue'
|
||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||
import { generate, generateTaskProgress } from '@/api/report/report'
|
||||
import { storeOptions, loadStoreOptions } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ExportReportDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 初始报表编码(Tab3 行「导出此报表」带入) */
|
||||
reportCode?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
|
||||
const form = reactive({
|
||||
report_code: '',
|
||||
store_id: undefined as number | undefined,
|
||||
bizDate: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
report_code: [{ required: true, message: '请输入报表编码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 提交导出 + 轮询进度(不传 storageKey → 不写任何本地存储)
|
||||
const {
|
||||
exportLoading,
|
||||
exportDialogVisible,
|
||||
exportTaskProgress,
|
||||
exportProgressPercent,
|
||||
exportProgressStatus,
|
||||
exportStatusLabel,
|
||||
submitExportTask
|
||||
} = useAsyncExportTask({
|
||||
submitExport: (payload) => generate(payload as any),
|
||||
queryProgress: (params) => generateTaskProgress(params as any)
|
||||
})
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.report_code = props.reportCode ?? ''
|
||||
form.store_id = undefined
|
||||
form.bizDate = ''
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
// 提交导出任务;提交后进度在弹窗中展示,完成后自动下载(useAsyncExportTask 内部处理)
|
||||
await submitExportTask({
|
||||
report_code: form.report_code.trim(),
|
||||
...(form.store_id && form.store_id > 0 ? { store_id: form.store_id } : {}),
|
||||
...(form.bizDate ? { params: { bizDate: form.bizDate } } : {})
|
||||
})
|
||||
emit('update:visible', false)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 4px 0 0;
|
||||
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -24,7 +24,7 @@
|
||||
/>
|
||||
|
||||
<el-tabs v-model="activeTab" class="settings-tabs">
|
||||
<el-tab-pane label="配置表单" name="form">
|
||||
<el-tab-pane label="基础设置" name="form">
|
||||
<!-- <p v-if="useMetaForm && normalizedFields.length" class="hint">
|
||||
以下字段来自接口 <code>setting.warehouse.getFieldMeta</code>,修改后点击右上角保存,将调用
|
||||
<code>setting.warehouse.saveSettings</code>。
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<!--
|
||||
ColumnCellRenderer — 通用表格列渲染器
|
||||
|
||||
根据传入的 ColumnSlotConfig 决定如何渲染单元格:
|
||||
- type='tag' → el-tag(支持 tagResolver / tagType 颜色映射)
|
||||
- type='text' → 纯文本(支持 datetime 格式化)
|
||||
- type='default' → 默认插槽渲染
|
||||
- type='operation' → 操作列(由 OperationCellRenderer 处理)
|
||||
-->
|
||||
<template>
|
||||
<template v-if="!config || config.type === 'default'">
|
||||
<slot />
|
||||
</template>
|
||||
<template v-else-if="config.type === 'tag'">
|
||||
<el-tag size="small" :type="resolvedTagType">
|
||||
{{ displayValue }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span>{{ displayValue }}</span>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { ColumnSlotConfig } from '../config/template-config'
|
||||
import { TAG_RESOLVERS, translate, formatTime } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ColumnCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 列插槽渲染配置 */
|
||||
config: ColumnSlotConfig | undefined
|
||||
/** 单元格值 */
|
||||
value: any
|
||||
}>()
|
||||
|
||||
/** 显示文本:translateField 翻译 > format 格式化 > 原始值 */
|
||||
const displayValue = computed(() => {
|
||||
const v = props.value
|
||||
if (props.config?.translateField) {
|
||||
return translate(props.config.translateField, v)
|
||||
}
|
||||
if (props.config?.format === 'datetime') {
|
||||
return formatTime(v)
|
||||
}
|
||||
return v ?? '—'
|
||||
})
|
||||
|
||||
const resolvedTagType = computed(() => {
|
||||
if (!props.config || props.config.type !== 'tag') return ''
|
||||
const { tagType, tagResolver } = props.config
|
||||
// 优先使用 tagResolver(函数名映射)
|
||||
if (tagResolver && TAG_RESOLVERS[tagResolver]) {
|
||||
return TAG_RESOLVERS[tagResolver](props.value)
|
||||
}
|
||||
// 其次使用 tagType 映射表(用原始值查找)
|
||||
if (tagType && typeof tagType === 'object') {
|
||||
return tagType[String(props.value)] ?? 'info'
|
||||
}
|
||||
// 最后使用固定值
|
||||
return (typeof tagType === 'string' ? tagType : 'info')
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,177 @@
|
||||
<!--
|
||||
OperationCellRenderer — 表格操作列渲染组件
|
||||
|
||||
根据 operationButtons 配置渲染按钮列表。
|
||||
|
||||
支持的行为类型:
|
||||
- actionType='action' → 触发 @operation-action 事件(可选配置 confirmMessage 弹确认框)
|
||||
- actionType='form' → 打开 COMPONENT_REGISTRY 中注册的表单组件
|
||||
|
||||
使用方式:在 index.vue 中通过插槽 column-operation 引入:
|
||||
<OperationCellRenderer
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
-->
|
||||
<template>
|
||||
<div class="operation-cell">
|
||||
<template v-for="btn in buttons" :key="btn.key">
|
||||
<!-- action 按钮:支持确认弹窗 -->
|
||||
<el-button
|
||||
v-if="btn.actionType === 'action'"
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:loading="actionLoadingMap[btn.key]"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="handleActionClick(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- form 按钮:打开表单弹窗 -->
|
||||
<template v-else-if="btn.actionType === 'form'">
|
||||
<el-button
|
||||
link
|
||||
:type="btn.type || 'primary'"
|
||||
size="small"
|
||||
:disabled="isDisabled(btn)"
|
||||
@click.stop="openForm(btn)"
|
||||
>
|
||||
{{ btn.label }}
|
||||
</el-button>
|
||||
|
||||
<!-- 表单弹窗(Teleport 到 body,避免在表格 fixed 列 / overflow 容器内渲染异常) -->
|
||||
<Teleport to="body">
|
||||
<component
|
||||
:is="resolvedFormComponents[btn.key]"
|
||||
v-if="resolvedFormComponents[btn.key] && activeFormKey === btn.key"
|
||||
v-model:visible="formVisibleMap[btn.key]"
|
||||
v-bind="buildFormProps(btn)"
|
||||
@success="handleFormSuccess(btn.key)"
|
||||
/>
|
||||
</Teleport>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, markRaw, type Component } from 'vue'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { COMPONENT_REGISTRY } from '../config/template-config'
|
||||
import type { OperationButtonConfig } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'OperationCellRenderer' })
|
||||
|
||||
const props = defineProps<{
|
||||
/** 操作按钮配置列表(来自 TabPageConfig.operationButtons) */
|
||||
buttons?: OperationButtonConfig[]
|
||||
/** 当前行数据 */
|
||||
row: Record<string, any>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** action 按钮点击事件(key: 按钮标识, row: 行数据) */
|
||||
(e: 'operation-action', key: string, row: Record<string, any>): void
|
||||
}>()
|
||||
|
||||
// ===== form 弹窗管理 =====
|
||||
const activeFormKey = ref('')
|
||||
const formVisibleMap = reactive<Record<string, boolean>>({})
|
||||
const resolvedFormComponents = ref<Record<string, Component>>({})
|
||||
const actionLoadingMap = reactive<Record<string, boolean>>({})
|
||||
|
||||
// ============================================================
|
||||
// action 按钮:支持确认弹窗
|
||||
// ============================================================
|
||||
|
||||
async function handleActionClick(btn: OperationButtonConfig) {
|
||||
if (btn.confirmMessage) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
btn.confirmMessage,
|
||||
btn.confirmTitle || '确认操作',
|
||||
{
|
||||
confirmButtonText: btn.confirmButtonText || '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: (btn.confirmType || 'warning') as any
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return // 取消
|
||||
}
|
||||
}
|
||||
|
||||
actionLoadingMap[btn.key] = true
|
||||
try {
|
||||
emit('operation-action', btn.key, props.row)
|
||||
} finally {
|
||||
actionLoadingMap[btn.key] = false
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// form 按钮:打开表单弹窗
|
||||
// ============================================================
|
||||
|
||||
function openForm(btn: OperationButtonConfig) {
|
||||
if (!btn.formKey) return
|
||||
|
||||
const comp = COMPONENT_REGISTRY[btn.formKey]
|
||||
if (!comp) {
|
||||
console.warn(`[OperationCellRenderer] 未注册的表单组件: ${btn.formKey}`)
|
||||
return
|
||||
}
|
||||
|
||||
activeFormKey.value = btn.key
|
||||
resolvedFormComponents.value[btn.key] = markRaw(comp)
|
||||
formVisibleMap[btn.key] = true
|
||||
}
|
||||
|
||||
function buildFormProps(btn: OperationButtonConfig): Record<string, any> {
|
||||
const result: Record<string, any> = {}
|
||||
|
||||
// paramMap: { formProp: rowField } → 从行数据取值注入表单
|
||||
if (btn.paramMap) {
|
||||
for (const [formProp, rowField] of Object.entries(btn.paramMap)) {
|
||||
result[formProp] = props.row[rowField]
|
||||
}
|
||||
}
|
||||
|
||||
// extraParams: 固定参数直接注入
|
||||
if (btn.extraParams) {
|
||||
Object.assign(result, btn.extraParams)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function handleFormSuccess(key: string) {
|
||||
emit('operation-action', key, props.row)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 按钮禁用判断
|
||||
// ============================================================
|
||||
|
||||
function isDisabled(btn: OperationButtonConfig): boolean {
|
||||
if (btn.disabledOnField) {
|
||||
const val = props.row[btn.disabledOnField]
|
||||
if (val === undefined || val === null || val === '' || val === false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.operation-cell {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<div class="tab-area-wrapper">
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
tab-position="top"
|
||||
type="border-card"
|
||||
class="tab-container"
|
||||
@tab-click="handleTabClick"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:name="tab.name"
|
||||
:lazy="false"
|
||||
>
|
||||
<template #label>
|
||||
<span class="custom-tab-label">{{ tab.label }}</span>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
defineOptions({ name: 'TabArea' })
|
||||
|
||||
interface TabItem {
|
||||
name: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
tabs?: TabItem[]
|
||||
defaultActive?: string
|
||||
}>(),
|
||||
{
|
||||
tabs: () => [],
|
||||
defaultActive: ''
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'tab-change', tabName: string): void
|
||||
}>()
|
||||
|
||||
const activeTab = ref(props.defaultActive || props.tabs[0]?.name || '')
|
||||
|
||||
const handleTabClick = (pane: any) => {
|
||||
const name = pane?.name ?? pane?.props?.name ?? ''
|
||||
if (name) {
|
||||
activeTab.value = name
|
||||
emit('tab-change', name)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.tab-area-wrapper {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tab-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
:deep(.el-tabs__header) {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__header.is-top) {
|
||||
padding: 4px 12px 0;
|
||||
background: #f8fbff;
|
||||
border-bottom: 1px solid #e8eef7;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__nav-wrap::after) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top) {
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
padding: 0 20px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top:hover) {
|
||||
color: #409eff;
|
||||
background-color: rgba(64, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
:deep(.el-tabs__item.is-top.is-active) {
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
background: #ffffff;
|
||||
border-color: #e8eef7;
|
||||
border-bottom: 2px solid #ffffff;
|
||||
margin-bottom: -1px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__active-bar) {
|
||||
height: 2px;
|
||||
border-radius: 2px;
|
||||
background-color: #409eff;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
:deep(.el-tabs__content) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-tab-label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,182 @@
|
||||
<!--
|
||||
DetailPanel — 明细面板(通用)
|
||||
|
||||
根据 detailConfig 配置的 sections 渲染 el-descriptions 分区。
|
||||
支持 text、tag、pre 三种渲染类型。
|
||||
支持 translateField + tagResolver 集中式翻译。
|
||||
支持 apiMethod 自动获取详情数据。
|
||||
-->
|
||||
<template>
|
||||
<div class="detail-panel">
|
||||
<div v-if="!row" class="empty-tip">请从上方列表中选择一项查看明细</div>
|
||||
<template v-else>
|
||||
<div v-for="(section, si) in detailConfig" :key="si" class="section">
|
||||
<div class="section-title">{{ section.title }}</div>
|
||||
<el-descriptions :column="section.columnCount" border size="small" class="detail-descriptions">
|
||||
<el-descriptions-item
|
||||
v-for="(field, fi) in section.fields"
|
||||
:key="fi"
|
||||
:label="field.label"
|
||||
:span="field.span ?? 1"
|
||||
>
|
||||
<!-- tag 渲染 -->
|
||||
<template v-if="field.renderType === 'tag'">
|
||||
<el-tag size="small" :type="resolveTagType(field, getRowData()?.[field.key])">
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<!-- pre 渲染 -->
|
||||
<template v-else-if="field.renderType === 'pre'">
|
||||
<pre class="order-list-pre">{{ formatPre(getRowData()?.[field.key]) }}</pre>
|
||||
</template>
|
||||
<!-- 默认文本渲染 -->
|
||||
<template v-else>
|
||||
{{ resolveDisplayValue(field, getRowData()?.[field.key]) }}
|
||||
</template>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { TAG_RESOLVERS, translate, formatTime } from '../template-config'
|
||||
import type { DetailSectionConfig, DetailFieldConfig } from '../template-config'
|
||||
|
||||
defineOptions({ name: 'DetailPanel' })
|
||||
|
||||
const props = defineProps<{
|
||||
row: Record<string, any> | null
|
||||
detailConfig: DetailSectionConfig[]
|
||||
/** 可选的 detail API 方法,传入后自动调用获取完整明细数据 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的增强数据(与 row 合并) */
|
||||
const enrichedData = ref<Record<string, any> | null>(null)
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
if (newRow && props.apiMethod) {
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
enrichedData.value = res.data ?? res
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} catch {
|
||||
enrichedData.value = null
|
||||
}
|
||||
} else {
|
||||
enrichedData.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 合并 row + API 增强数据 */
|
||||
function getRowData(): Record<string, any> | null {
|
||||
if (!props.row) return null
|
||||
if (enrichedData.value) {
|
||||
return { ...props.row, ...enrichedData.value }
|
||||
}
|
||||
return props.row
|
||||
}
|
||||
|
||||
/** 解析显示值:优先使用 translateField 翻译,其次是 datetime 格式化,否则显示原始值 */
|
||||
function resolveDisplayValue(field: DetailFieldConfig, value: any): string {
|
||||
if (field.translateField) {
|
||||
return translate(field.translateField, value)
|
||||
}
|
||||
if (field.format === 'datetime') {
|
||||
return formatTime(value)
|
||||
}
|
||||
return value ?? '—'
|
||||
}
|
||||
|
||||
/** 格式化 pre 渲染值:数组/对象转 JSON 字符串 */
|
||||
function formatPre(value: any): string {
|
||||
if (value === undefined || value === null || value === '') return '—'
|
||||
if (Array.isArray(value) && value.length === 0) return '—'
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
return JSON.stringify(value, null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** 解析 tag 颜色 */
|
||||
function resolveTagType(field: DetailFieldConfig, value: any): string {
|
||||
if (field.tagResolver) {
|
||||
const resolver = TAG_RESOLVERS[field.tagResolver]
|
||||
if (resolver) return resolver(value)
|
||||
}
|
||||
if (field.tagType) {
|
||||
if (typeof field.tagType === 'object') {
|
||||
return field.tagType[String(value)] ?? 'info'
|
||||
}
|
||||
return field.tagType
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 容器对齐 order/orderManagement 的 OrderDetailPanel(.order-detail-view) */
|
||||
.detail-panel {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 10px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #409eff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.detail-descriptions {
|
||||
:deep(.el-descriptions__label) {
|
||||
width: 120px;
|
||||
background: #fafbfc;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.order-list-pre {
|
||||
margin: 0;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,194 @@
|
||||
<!--
|
||||
LogPanel — 操作日志面板(通用)
|
||||
|
||||
支持两种数据来源:
|
||||
- apiMethod 传入 → 调用真实接口获取日志
|
||||
- 无 apiMethod → 基于 row 生成模拟日志(开发调试用)
|
||||
-->
|
||||
<template>
|
||||
<div class="log-panel">
|
||||
<div v-if="apiLoading" v-loading="true" class="log-empty">加载中…</div>
|
||||
<template v-else>
|
||||
<el-table
|
||||
v-if="logs.length"
|
||||
:data="pagedLogs"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
class="log-table"
|
||||
>
|
||||
<el-table-column prop="time" label="时间" width="175" />
|
||||
<el-table-column prop="operator" label="操作人" width="120" />
|
||||
<el-table-column prop="action" label="操作类型" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column label="结果" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="resultTagType(row)">{{ row.result }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="说明" min-width="220" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.detail || '—' }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-else class="log-empty">暂无操作日志</div>
|
||||
|
||||
<div v-if="logs.length > pageSize" class="log-pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:total="logs.length"
|
||||
layout="total, prev, pager, next"
|
||||
background
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
defineOptions({ name: 'LogPanel' })
|
||||
|
||||
interface LogItem {
|
||||
operator: string
|
||||
action: string
|
||||
result: string
|
||||
detail?: string
|
||||
time: string
|
||||
level: 'success' | 'info' | 'warning' | 'error'
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
/** 当前选中行数据(用于生成关联日志) */
|
||||
row: Record<string, any> | null
|
||||
/** 可选的日志 API 方法,传入后自动调用获取真实日志 */
|
||||
apiMethod?: (...args: any[]) => Promise<any>
|
||||
}>()
|
||||
|
||||
/** 通过 API 获取的真实日志列表 */
|
||||
const apiLogs = ref<LogItem[] | null>(null)
|
||||
const apiLoading = ref(false)
|
||||
|
||||
/** 表格本地分页(对齐 order/orderManagement 的 log.vue 体验) */
|
||||
const currentPage = ref(1)
|
||||
const pageSize = 10
|
||||
const pagedLogs = computed<LogItem[]>(() => {
|
||||
const start = (currentPage.value - 1) * pageSize
|
||||
return logs.value.slice(start, start + pageSize)
|
||||
})
|
||||
|
||||
function resultTagType(row: LogItem): string {
|
||||
if (row.result === '成功') return 'success'
|
||||
if (row.result === '失败') return 'danger'
|
||||
return 'info'
|
||||
}
|
||||
|
||||
watch(() => props.row, async (newRow) => {
|
||||
currentPage.value = 1
|
||||
if (newRow && props.apiMethod) {
|
||||
apiLoading.value = true
|
||||
try {
|
||||
const res = await props.apiMethod({
|
||||
id: newRow.id,
|
||||
code: newRow.code,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const list = res.data?.list ?? res.data?.logs ?? res.list ?? res.logs ?? []
|
||||
apiLogs.value = Array.isArray(list) ? list.map((item: any) => ({
|
||||
operator: item.operator ?? item.creator ?? '—',
|
||||
action: item.action ?? item.operation ?? '—',
|
||||
result: item.result ?? item.status ?? '—',
|
||||
detail: item.detail ?? item.description ?? '',
|
||||
time: item.time ?? item.create_time ?? '—',
|
||||
level: (item.result === '成功' || item.status === 'success') ? 'success'
|
||||
: (item.result === '失败' || item.status === 'error') ? 'error'
|
||||
: 'info'
|
||||
})) : []
|
||||
} else {
|
||||
apiLogs.value = []
|
||||
}
|
||||
} catch {
|
||||
apiLogs.value = []
|
||||
} finally {
|
||||
apiLoading.value = false
|
||||
}
|
||||
} else {
|
||||
apiLogs.value = null
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
/** 基于 row 生成模拟日志(无 apiMethod 时使用) */
|
||||
const mockLogs = computed<LogItem[]>(() => {
|
||||
if (!props.row) return []
|
||||
|
||||
const rowName = props.row.name ?? props.row.code ?? '—'
|
||||
const now = new Date()
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const fmt = (d: Date) =>
|
||||
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||
|
||||
return [
|
||||
{
|
||||
operator: '系统',
|
||||
action: `创建了「${rowName}」`,
|
||||
result: '成功',
|
||||
time: fmt(new Date(now.getTime() - 3600000 * 3)),
|
||||
level: 'success'
|
||||
},
|
||||
{
|
||||
operator: props.row.creator ?? '管理员',
|
||||
action: `更新了「${rowName}」`,
|
||||
result: '成功',
|
||||
detail: `修改了状态和相关配置`,
|
||||
time: fmt(new Date(now.getTime() - 3600000)),
|
||||
level: 'success'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
/** 最终展示的日志:优先使用 API 日志,否则使用 mock 日志 */
|
||||
const logs = computed<LogItem[]>(() => {
|
||||
if (apiLogs.value !== null) {
|
||||
return apiLogs.value
|
||||
}
|
||||
return mockLogs.value
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 对齐 order/orderManagement 的 log.vue(el-table 表格 + 本地分页) */
|
||||
.log-panel {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
padding: 10px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.log-table {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.log-empty {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
padding: 40px 0;
|
||||
}
|
||||
|
||||
.log-pagination {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 10px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
855
src/views/system/setting/basicManagement/newview/index.vue
Normal file
855
src/views/system/setting/basicManagement/newview/index.vue
Normal file
@ -0,0 +1,855 @@
|
||||
<!--
|
||||
╔══════════════════════════════════════════════════════════════╗
|
||||
║ 【页面模板 v2】— 基于 waveOrder2 架构设计 ║
|
||||
╚══════════════════════════════════════════════════════════════╝
|
||||
|
||||
===== 快速复制使用 =====
|
||||
1. 复制整个 views/mode/ 文件夹 → 重命名为你的页面名(如 views/order/myPage/)
|
||||
2. 修改 defineOptions name(如 'MyPage')
|
||||
3. 编辑 config/template-config.ts:
|
||||
a. 在 FIELD_DICT 中添加页面字段
|
||||
b. 在 tabPages 中配置标签页(引用 FIELD_DICT 的 key)
|
||||
c. 在 TabPageApiConfig 中接入真实接口
|
||||
4. 在 router/map.ts 中添加路由
|
||||
|
||||
===== 页面结构 =====
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ TabArea(多标签页切换,可关闭) │
|
||||
├──────────┬──────────────────────────────────────────────┤
|
||||
│ ScanBox │ OrderToolbarButtonGroup(工具栏按钮组) │
|
||||
│ 筛选面板 │ ┌──────────────────────────────────────────┐│
|
||||
│ │ │ UpperTable(表格) ││
|
||||
│ │ │ - OperationCellRenderer(操作列) ││
|
||||
│ │ ├──────────────────────────────────────────┤│
|
||||
│ │ │ 分隔条(可拖拽) ││
|
||||
│ │ ├──────────────────────────────────────────┤│
|
||||
│ │ │ DetailPanel / LogPanel(明细/日志面板) ││
|
||||
│ │ └──────────────────────────────────────────┘│
|
||||
└──────────┴──────────────────────────────────────────────┘
|
||||
-->
|
||||
<template>
|
||||
<div class="page-wrapper" :style="{ height: containerHeight }">
|
||||
<!-- ===== 多标签模式:显示顶部标签栏 ===== -->
|
||||
<template v-if="PAGE_CONFIG.showTabArea && !PAGE_CONFIG.singlePage">
|
||||
<div class="tab-section">
|
||||
<TabArea
|
||||
:tabs="tabList"
|
||||
:default-active="activeTabName"
|
||||
@tab-change="handleTabChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- ===== 主内容区 ===== -->
|
||||
<div class="main-container">
|
||||
<!-- 表单页形态:直接渲染表单项页面(不使用 scan-box / upper-table / 明细) -->
|
||||
<div v-if="isFormView" :key="`form-${activeTabName}`" class="form-page-container">
|
||||
<component :is="currentFormPage" />
|
||||
</div>
|
||||
|
||||
<!-- 列表形态:scan-box + upper-table -->
|
||||
<div v-else class="order-sub-container">
|
||||
<!-- 左侧:ScanBox 筛选面板 -->
|
||||
<ScanBox
|
||||
ref="scanBoxRef"
|
||||
:cache-key="currentScanBoxCacheKey"
|
||||
width="220px"
|
||||
:tree-props="{ children: 'children', label: 'label' }"
|
||||
:auto-submit="false"
|
||||
:preset-tree="presetTree"
|
||||
:available-fields="currentScanBoxFields"
|
||||
@condition-change="handleConditionChange"
|
||||
@reset="handleConditionReset"
|
||||
@condition-clear="handleConditionClear"
|
||||
/>
|
||||
|
||||
<!-- 右侧:内容区 -->
|
||||
<div class="main-content">
|
||||
<transition name="tab-fade" mode="out-in">
|
||||
<div :key="activeTabName" class="tab-content-inner">
|
||||
<!-- 工具栏按钮组 -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-left">
|
||||
<OrderToolbarButtonGroup
|
||||
:buttons="currentToolbarButtons"
|
||||
:resolve-disabled="resolveButtonDisabled"
|
||||
:resolve-loading="resolveButtonLoading"
|
||||
:resolve-label="resolveButtonLabel"
|
||||
:layout-key="toolbarLayoutKey"
|
||||
@action="handleToolbarButtonClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 上下分栏区域:详情面板启用时才显示分栏 + 详情 -->
|
||||
<template v-if="PAGE_CONFIG.enableDetailPanel">
|
||||
<div class="split-stack" ref="splitStackRef">
|
||||
<!-- 上半:表格 -->
|
||||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||||
<UpperTable
|
||||
ref="upperTableRef"
|
||||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||||
default-align="center"
|
||||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||||
:column-config-schema-version="1"
|
||||
:table-id="`template-table-${activeTabName}`"
|
||||
:data="listData"
|
||||
:row-key="'id'"
|
||||
:columns="currentColumns"
|
||||
table-size="small"
|
||||
:pagination="pagination"
|
||||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||||
:show-selection="currentTabConfig?.upperTable.showSelection ?? true"
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@row-click="handleRowClick"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadData"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<!-- 动态列插槽:根据 columnSlots 配置自动渲染 -->
|
||||
<template
|
||||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||||
:key="`columnSlots-${colProp}`"
|
||||
#[`column-${colProp}`]="{ row }"
|
||||
>
|
||||
<!-- 操作列:渲染操作按钮 -->
|
||||
<OperationCellRenderer
|
||||
v-if="slotConfig.type === 'operation'"
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
<!-- 其他列:标签/文本渲染 -->
|
||||
<ColumnCellRenderer
|
||||
v-else
|
||||
:config="slotConfig"
|
||||
:value="row[colProp]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #empty>
|
||||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||||
</template>
|
||||
</UpperTable>
|
||||
</div>
|
||||
|
||||
<!-- 分隔条(可拖拽) -->
|
||||
<template v-if="detailVisible">
|
||||
<div
|
||||
class="pane-resizer"
|
||||
title="拖动调整列表与详情区域高度"
|
||||
@mousedown="beginSplitDrag"
|
||||
/>
|
||||
|
||||
<!-- 下半:明细面板 -->
|
||||
<div v-if="selectedRow" class="lower-level" :style="lowerPaneStyle">
|
||||
<div class="detail-header">
|
||||
<el-tabs v-model="activeDetailTab" class="detail-tab">
|
||||
<el-tab-pane
|
||||
v-for="tab in currentDetailTabs"
|
||||
:key="tab.name"
|
||||
:label="tab.label"
|
||||
:name="tab.name"
|
||||
/>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<div class="detail-container">
|
||||
<component
|
||||
:is="activeDetailTabComponent"
|
||||
:row="selectedDetail"
|
||||
:detail-config="currentDetailConfig"
|
||||
:api-method="currentDetailTabApiMethod"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未选中行时的占位 -->
|
||||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||||
<div class="empty-tip">
|
||||
<p>请从上方列表中选择一项查看详情</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 详情面板禁用:表格占满全高 -->
|
||||
<template v-else>
|
||||
<div class="upper-wrapper upper-wrapper--full">
|
||||
<UpperTable
|
||||
ref="upperTableRef"
|
||||
:title="currentTabConfig?.upperTable.title ?? '列表'"
|
||||
default-align="center"
|
||||
:enable-column-config="currentTabConfig?.upperTable.enableColumnConfig ?? true"
|
||||
:column-config-schema-version="1"
|
||||
:table-id="`template-table-${activeTabName}`"
|
||||
:data="listData"
|
||||
:row-key="'id'"
|
||||
:columns="currentColumns"
|
||||
table-size="small"
|
||||
:pagination="pagination"
|
||||
:show-index="currentTabConfig?.upperTable.showIndex ?? true"
|
||||
:show-selection="currentTabConfig?.upperTable.showSelection ?? false"
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
@current-change="handleRowClick"
|
||||
@row-click="handleRowClick"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadData"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<template
|
||||
v-for="(slotConfig, colProp) in currentColumnSlots"
|
||||
:key="`columnSlots-${colProp}`"
|
||||
#[`column-${colProp}`]="{ row }"
|
||||
>
|
||||
<OperationCellRenderer
|
||||
v-if="slotConfig.type === 'operation'"
|
||||
:buttons="currentTabConfig?.operationButtons"
|
||||
:row="row"
|
||||
@operation-action="handleOperationAction"
|
||||
/>
|
||||
<ColumnCellRenderer
|
||||
v-else
|
||||
:config="slotConfig"
|
||||
:value="row[colProp]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #empty>
|
||||
<div class="empty-tip">{{ currentTabConfig?.upperTable.emptyText ?? '暂无数据' }}</div>
|
||||
</template>
|
||||
</UpperTable>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 功能按钮表单(pages/ 目录下的组件) ===== -->
|
||||
<ApiAppFormDialog
|
||||
v-model:visible="apiAppCreateVisible"
|
||||
@success="handleApiAppDialogSuccess"
|
||||
/>
|
||||
<DeliveryPlanFormDialog
|
||||
v-model:visible="createPlanVisible"
|
||||
@success="handlePlanSaved"
|
||||
/>
|
||||
<DefinitionFormDialog
|
||||
v-model:visible="definitionCreateVisible"
|
||||
@success="handleDefinitionSaved"
|
||||
/>
|
||||
<ExportReportDialog
|
||||
v-model:visible="exportReportVisible"
|
||||
:report-code="exportInitialReportCode"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// ============================================================
|
||||
// ★★★ 第一步:修改组件名 ★★★
|
||||
// ============================================================
|
||||
defineOptions({ name: 'BasicManagement' })
|
||||
|
||||
import { ref, computed, onMounted, reactive } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import TabArea from './components/TabArea.vue'
|
||||
import ColumnCellRenderer from './components/ColumnCellRenderer.vue'
|
||||
import OperationCellRenderer from './components/OperationCellRenderer.vue'
|
||||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||||
import type { ToolbarButtonConfig as OrderToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||||
import {
|
||||
PAGE_CONFIG,
|
||||
tabPages,
|
||||
resolveTabConfig,
|
||||
getTabToolbarButtons,
|
||||
loadStoreOptions,
|
||||
type TabPageConfig,
|
||||
type DetailTabConfig,
|
||||
type ToolbarButtonConfig,
|
||||
} from './config/template-config'
|
||||
import { apiAppDelete, apiAppRegenerateSecret } from '@/api/apiapp/apiapp'
|
||||
import { deleteReportDefinition } from '@/api/report/report'
|
||||
import ApiAppFormDialog from './pages/ApiAppFormDialog.vue'
|
||||
import DeliveryPlanFormDialog from './pages/DeliveryPlanFormDialog.vue'
|
||||
import ExportReportDialog from './pages/ExportReportDialog.vue'
|
||||
import DefinitionFormDialog from './pages/DefinitionFormDialog.vue'
|
||||
|
||||
// ============================================================
|
||||
// 容器高度
|
||||
// ============================================================
|
||||
const settingsStore = useSettingsStore()
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
const containerHeight = computed(() =>
|
||||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||||
)
|
||||
|
||||
// ============================================================
|
||||
// 标签页
|
||||
// ============================================================
|
||||
const tabList = computed(() =>
|
||||
tabPages.map((t) => ({ name: t.name, label: t.label }))
|
||||
)
|
||||
const activeTabName = ref(tabPages[0]?.name ?? 'tab1')
|
||||
|
||||
/** 当前激活标签页的完整配置 */
|
||||
const currentTabConfig = computed<TabPageConfig | undefined>(() => {
|
||||
const raw = tabPages.find((t) => t.name === activeTabName.value)
|
||||
if (!raw) return undefined
|
||||
return resolveTabConfig(raw)
|
||||
})
|
||||
|
||||
/** 是否为表单页形态(viewType === 'form') */
|
||||
const isFormView = computed(
|
||||
() => currentTabConfig.value?.viewType === 'form'
|
||||
)
|
||||
|
||||
/** 当前表单页组件 */
|
||||
const currentFormPage = computed(
|
||||
() => currentTabConfig.value?.formPage
|
||||
)
|
||||
|
||||
/** 当前 ScanBox 缓存 key */
|
||||
const currentScanBoxCacheKey = computed(
|
||||
() => currentTabConfig.value?.scanBoxCacheKey ?? 'template-default'
|
||||
)
|
||||
|
||||
/** 当前 ScanBox 筛选字段 */
|
||||
const currentScanBoxFields = computed(
|
||||
() => currentTabConfig.value?.scanBoxFields ?? []
|
||||
)
|
||||
|
||||
/** 当前表格列 */
|
||||
const currentColumns = computed(
|
||||
() => currentTabConfig.value?.upperTable.columns ?? []
|
||||
)
|
||||
|
||||
/** 当前列插槽配置 */
|
||||
const currentColumnSlots = computed(
|
||||
() => currentTabConfig.value?.columnSlots ?? {}
|
||||
)
|
||||
|
||||
/** 当前明细面板配置 */
|
||||
const currentDetailConfig = computed(
|
||||
() => currentTabConfig.value?.detailConfig ?? []
|
||||
)
|
||||
|
||||
/** 当前明细标签页列表 */
|
||||
const currentDetailTabs = computed<DetailTabConfig[]>(
|
||||
() => currentTabConfig.value?.detailTabs ?? []
|
||||
)
|
||||
|
||||
/** 当前激活的明细标签页组件 */
|
||||
const activeDetailTabComponent = computed(() => {
|
||||
const tab = currentDetailTabs.value.find(
|
||||
(t) => t.name === activeDetailTab.value
|
||||
)
|
||||
return tab?.component ?? null
|
||||
})
|
||||
|
||||
/** 当前激活明细标签页对应的 API 方法 */
|
||||
const currentDetailTabApiMethod = computed(() => {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg?.api) return undefined
|
||||
const tab = currentDetailTabs.value.find((t) => t.name === activeDetailTab.value)
|
||||
if (!tab) return undefined
|
||||
|
||||
let componentCfg: unknown
|
||||
switch (tab.componentKey) {
|
||||
case 'DetailPanel':
|
||||
componentCfg = cfg.api.detail
|
||||
break
|
||||
case 'LogPanel':
|
||||
componentCfg = cfg.api.log
|
||||
break
|
||||
default:
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (typeof componentCfg === 'function') {
|
||||
return componentCfg
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
|
||||
// ============================================================
|
||||
// 工具栏按钮系统
|
||||
// ============================================================
|
||||
|
||||
/** 当前标签页的工具栏按钮列表 */
|
||||
const currentToolbarButtons = computed<OrderToolbarButtonConfig[]>(() => {
|
||||
const btns = getTabToolbarButtons(activeTabName.value)
|
||||
return btns.map((btn: ToolbarButtonConfig) => ({
|
||||
key: btn.key,
|
||||
label: btn.label,
|
||||
size: btn.size,
|
||||
type: btn.type,
|
||||
plain: btn.plain,
|
||||
loadingKey: btn.loadingKey,
|
||||
disabledKey: btn.disabledKey,
|
||||
action: btn.action,
|
||||
dynamicLabelKey: btn.dynamicLabelKey,
|
||||
buttonType: btn.buttonType,
|
||||
dropdownOptions: btn.dropdownOptions
|
||||
}))
|
||||
})
|
||||
|
||||
const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||||
noSelection: selectedRows.value.length === 0
|
||||
}))
|
||||
|
||||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||||
loading: loading.value,
|
||||
exportLoading: false
|
||||
}))
|
||||
|
||||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||||
}))
|
||||
|
||||
const toolbarLayoutKey = computed(() =>
|
||||
JSON.stringify({
|
||||
loading: buttonLoadingMap.value,
|
||||
disabled: buttonDisabledMap.value,
|
||||
labels: buttonLabelMap.value
|
||||
})
|
||||
)
|
||||
|
||||
function resolveButtonLoading(loadingKey?: string) {
|
||||
if (!loadingKey) return false
|
||||
return Boolean(buttonLoadingMap.value[loadingKey])
|
||||
}
|
||||
|
||||
function resolveButtonDisabled(disabledKey?: string) {
|
||||
if (!disabledKey) return false
|
||||
return Boolean(buttonDisabledMap.value[disabledKey])
|
||||
}
|
||||
|
||||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||||
if (!dynamicLabelKey) return defaultLabel
|
||||
return buttonLabelMap.value[dynamicLabelKey] || defaultLabel
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 工具栏动作分发
|
||||
// ============================================================
|
||||
const toolbarActionMap: Record<string, () => void> = {
|
||||
loadData: () => { void loadData() },
|
||||
openColumnConfigPanel: () => { upperTableRef.value?.openColumnConfig?.() },
|
||||
toggleDetailVisible: () => { detailVisible.value = !detailVisible.value },
|
||||
openCreateApiApp: () => { apiAppCreateVisible.value = true },
|
||||
openCreatePlan: () => { createPlanVisible.value = true },
|
||||
openCreateDefinition: () => { definitionCreateVisible.value = true },
|
||||
openExportReport: () => { exportReportVisible.value = true },
|
||||
handleExport: () => { console.log('[BasicManagement] 导出(不含明细)', activeTabName.value) },
|
||||
handleExportItem: () => { console.log('[BasicManagement] 导出(含明细)', activeTabName.value) }
|
||||
}
|
||||
|
||||
function handleToolbarButtonClick(action: string) {
|
||||
const handler = toolbarActionMap[action]
|
||||
if (handler) {
|
||||
handler()
|
||||
return
|
||||
}
|
||||
// ★ 在此添加功能按钮分发
|
||||
console.warn('[PageTemplate] 未处理的工具栏动作:', action)
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 操作列按钮事件处理
|
||||
// ============================================================
|
||||
async function handleOperationAction(key: string, row: Record<string, any>) {
|
||||
switch (key) {
|
||||
case 'viewDetail':
|
||||
// 已经通过行点击处理
|
||||
break
|
||||
case 'editApiApp':
|
||||
// 编辑弹窗提交成功后触发,刷新列表
|
||||
loadData()
|
||||
break
|
||||
case 'editPlan':
|
||||
// 投递计划编辑弹窗提交成功后触发,刷新列表
|
||||
loadData()
|
||||
break
|
||||
case 'exportThisReport':
|
||||
// 将该报表编码带入导出弹窗
|
||||
exportInitialReportCode.value = row?.report_code ?? ''
|
||||
exportReportVisible.value = true
|
||||
break
|
||||
case 'regenerateSecret':
|
||||
await handleRegenerateSecret(row)
|
||||
break
|
||||
case 'deleteApiApp':
|
||||
await handleDeleteApiApp(row)
|
||||
break
|
||||
case 'deleteDefinition':
|
||||
await handleDeleteReportDefinition(row)
|
||||
break
|
||||
default:
|
||||
console.warn('[BasicManagement] 未处理的操作按钮:', key)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// API 应用弹窗(创建 / 编辑)
|
||||
// ============================================================
|
||||
const apiAppCreateVisible = ref(false)
|
||||
const createPlanVisible = ref(false)
|
||||
const definitionCreateVisible = ref(false)
|
||||
const exportReportVisible = ref(false)
|
||||
/** 导出弹窗初始报表编码(导出任务行「导出此报表」带入) */
|
||||
const exportInitialReportCode = ref('')
|
||||
|
||||
function handleApiAppDialogSuccess() {
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handlePlanSaved() {
|
||||
ElMessage.success('投递计划已保存')
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handleDefinitionSaved() {
|
||||
ElMessage.success('报表定义已保存')
|
||||
loadData()
|
||||
}
|
||||
|
||||
async function handleRegenerateSecret(row: Record<string, any>) {
|
||||
try {
|
||||
const res: any = await apiAppRegenerateSecret(row.id)
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const newSecret = res.self_app_secret || ''
|
||||
ElMessageBox.alert(`新 AppSecret:${newSecret}`, '密钥已重置 — 请妥善保存', {
|
||||
confirmButtonText: '我已保存',
|
||||
type: 'warning'
|
||||
})
|
||||
loadData()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '重置失败')
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '重置失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteApiApp(row: Record<string, any>) {
|
||||
try {
|
||||
const res: any = await apiAppDelete(row.id)
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
ElMessage.success('已停用')
|
||||
loadData()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '停用失败')
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '停用失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteReportDefinition(row: Record<string, any>) {
|
||||
const code = row?.report_code ?? row?.code
|
||||
if (!code) {
|
||||
ElMessage.warning('缺少报表编码')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res: any = await deleteReportDefinition({ code })
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
ElMessage.success('已删除')
|
||||
loadData()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '删除失败')
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ★★★ 第二步:接入真实接口 ★★★
|
||||
// ============================================================
|
||||
const listData = ref<Record<string, any>[]>([])
|
||||
const loading = ref(false)
|
||||
const queryTime = ref(0)
|
||||
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
})
|
||||
|
||||
const currentSort = reactive({ prop: '', order: '' })
|
||||
|
||||
const loadData = async () => {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg) return
|
||||
// 表单页形态:由 formPage 组件自管理数据,不加载列表
|
||||
if (cfg.viewType === 'form') return
|
||||
loading.value = true
|
||||
const startTime = performance.now()
|
||||
|
||||
try {
|
||||
if (cfg.api) {
|
||||
// 使用真实接口
|
||||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||||
const params = cfg.api.buildListParams
|
||||
? cfg.api.buildListParams({
|
||||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||||
conditions,
|
||||
sort: currentSort.prop ? { prop: currentSort.prop, order: currentSort.order } : undefined
|
||||
})
|
||||
: {
|
||||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||||
where: conditions
|
||||
}
|
||||
|
||||
const res = await cfg.api.list(params)
|
||||
if (res && (res.code === 1 || res.code === 200)) {
|
||||
const parsed = cfg.api.parseListResponse
|
||||
? cfg.api.parseListResponse(res)
|
||||
: { list: res.data?.list ?? res.list ?? [], total: res.data?.pagination?.total ?? res.total ?? 0 }
|
||||
listData.value = parsed.list
|
||||
pagination.total = parsed.total
|
||||
} else {
|
||||
throw new Error(res?.message || '接口返回异常')
|
||||
}
|
||||
} else {
|
||||
// ★ 未配置 API 时使用模拟数据(替换为真实接口后删除)
|
||||
console.log('[PageTemplate] 未配置 API,使用空数据。请在 tabPages 中配置 api 字段。')
|
||||
listData.value = []
|
||||
pagination.total = 0
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('[PageTemplate] 加载列表失败:', e)
|
||||
ElMessage.error(e?.message || '获取列表数据失败')
|
||||
listData.value = []
|
||||
pagination.total = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
queryTime.value = Math.round(performance.now() - startTime)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// ScanBox 筛选事件
|
||||
// ============================================================
|
||||
const scanBoxRef = ref<any>(null)
|
||||
const presetTree = ref<any[]>([])
|
||||
|
||||
const handleConditionChange = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
const handleConditionReset = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
const handleConditionClear = () => {
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// UpperTable 事件
|
||||
// ============================================================
|
||||
const upperTableRef = ref<any>(null)
|
||||
const selectedRows = ref<Record<string, any>[]>([])
|
||||
|
||||
const handleSortChange = ({ prop, order }: any) => {
|
||||
currentSort.prop = prop
|
||||
currentSort.order = order
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
pagination.currentPage = page
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handlePageSizeChange = (size: number) => {
|
||||
pagination.pageSize = size
|
||||
pagination.currentPage = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
const handleSelectionChange = (rows: Record<string, any>[]) => {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 明细面板
|
||||
// ============================================================
|
||||
const detailVisible = ref(PAGE_CONFIG.enableDetailPanel)
|
||||
const selectedRow = ref<Record<string, any> | null>(null)
|
||||
const selectedDetail = ref<Record<string, any> | null>(null)
|
||||
const activeDetailTab = ref('detail')
|
||||
|
||||
const handleRowClick = async (row: Record<string, any>) => {
|
||||
if (!PAGE_CONFIG.enableDetailPanel) return
|
||||
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg) return
|
||||
selectedRow.value = row
|
||||
|
||||
// 根据 DetailPanel 的 api 配置决定数据来源
|
||||
const detailCfg = cfg.api?.detail
|
||||
if (typeof detailCfg === 'function') {
|
||||
try {
|
||||
const detailRes = await detailCfg({ id: row.id, code: row.code })
|
||||
if (detailRes && (detailRes.code === 1 || detailRes.code === 200)) {
|
||||
selectedDetail.value = detailRes.data ?? detailRes
|
||||
} else {
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
} catch {
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
} else {
|
||||
// source='list' 或未配置:直接用行数据
|
||||
selectedDetail.value = { ...row }
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 标签页切换
|
||||
// ============================================================
|
||||
const handleTabChange = (tabName: string) => {
|
||||
if (activeTabName.value === tabName) return
|
||||
activeTabName.value = tabName
|
||||
pagination.currentPage = 1
|
||||
currentSort.prop = ''
|
||||
currentSort.order = ''
|
||||
selectedRow.value = null
|
||||
selectedDetail.value = null
|
||||
selectedRows.value = []
|
||||
activeDetailTab.value = 'detail'
|
||||
if (currentTabConfig.value?.viewType !== 'form') {
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 分栏拖拽
|
||||
// ============================================================
|
||||
const { splitStackRef, beginSplitDrag, lowerPaneStyle, upperPaneStyle } =
|
||||
useVerticalSplitPane({ defaultLowerPercent: 38 })
|
||||
|
||||
const upperPaneFullStyle = computed(() => ({
|
||||
flex: '1 1 auto',
|
||||
minHeight: '0',
|
||||
overflow: 'hidden' as const
|
||||
}))
|
||||
|
||||
// ============================================================
|
||||
// 初始化
|
||||
// ============================================================
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/* 布局样式对齐 order/orderManagement(order-sub.scss) */
|
||||
@use "../../../../order/orderManagement/styles/order-sub.scss";
|
||||
|
||||
/* ================================================================
|
||||
整体布局
|
||||
================================================================ */
|
||||
.page-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
1. 顶部多标签页
|
||||
================================================================ */
|
||||
.tab-section {
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-bottom: none;
|
||||
border-radius: 6px 6px 0 0;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
2. 主内容区
|
||||
================================================================ */
|
||||
.main-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #e8eef7;
|
||||
border-radius: 0 0 6px 6px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 表单页形态:渲染 formPage 组件,填满内容区 */
|
||||
.form-page-container {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.tab-content-inner {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
/* 分栏区域:布局样式由 order/orderManagement/styles/order-sub.scss 提供,此处仅补充模板特有规则 */
|
||||
.split-stack {
|
||||
:deep(.el-card__header) {
|
||||
padding: 2px 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
6. 过渡动画
|
||||
================================================================ */
|
||||
.tab-fade-enter-active,
|
||||
.tab-fade-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-fade-enter-from,
|
||||
.tab-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
7. 空状态
|
||||
================================================================ */
|
||||
.empty-tip {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,350 @@
|
||||
<!--
|
||||
ApiAppFormDialog — API 应用创建/编辑弹窗
|
||||
对接接口:
|
||||
- apiAppCreate:创建 API 应用(创建成功展示 AppKey/AppSecret)
|
||||
- apiAppUpdate:编辑 API 应用
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑 API 应用' : '创建 API 应用'"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
align-center
|
||||
append-to-body
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="120px"
|
||||
label-position="right"
|
||||
>
|
||||
<el-form-item label="应用名称" prop="app_name">
|
||||
<el-input
|
||||
v-model="formData.app_name"
|
||||
placeholder="请输入应用名称"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="速率限制">
|
||||
<el-input-number
|
||||
v-model="formData.rate_limit"
|
||||
:min="1"
|
||||
:max="100000"
|
||||
:precision="0"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<span class="unit-text">次/秒</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="回调 URL">
|
||||
<el-input
|
||||
v-model="formData.callback_url"
|
||||
placeholder="接收推送通知的 URL,如 https://example.com/webhook"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="IP 白名单">
|
||||
<div class="ip-whitelist">
|
||||
<el-tag
|
||||
v-for="(ip, idx) in formData.self_ip_whitelist"
|
||||
:key="idx"
|
||||
closable
|
||||
class="ip-tag"
|
||||
@close="handleRemoveFormIp(idx)"
|
||||
>
|
||||
{{ ip }}
|
||||
</el-tag>
|
||||
<el-input
|
||||
v-if="formIpInputVisible"
|
||||
ref="formIpInputRef"
|
||||
v-model="formIpInputValue"
|
||||
size="small"
|
||||
style="width: 160px"
|
||||
placeholder="IP 或 CIDR"
|
||||
@blur="handleAddFormIp"
|
||||
@keyup.enter="handleAddFormIp"
|
||||
/>
|
||||
<el-button v-else size="small" @click="showFormIpInput">+ 添加 IP</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="isEdit" label="启用状态">
|
||||
<el-switch
|
||||
v-model="formData.is_enabled"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
active-text="启用"
|
||||
inactive-text="停用"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 创建成功后显示密钥信息 -->
|
||||
<template v-if="createdSecret">
|
||||
<el-divider />
|
||||
<el-alert
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="请立即保存以下密钥信息,关闭后 AppSecret 将不再完整显示!"
|
||||
/>
|
||||
<div class="secret-display">
|
||||
<div class="secret-row">
|
||||
<span class="secret-label">AppKey:</span>
|
||||
<code class="secret-value">{{ createdSecret.self_app_key }}</code>
|
||||
<el-button link type="primary" size="small" @click="handleCopy(createdSecret.self_app_key, 'AppKey')">
|
||||
复制
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="secret-row">
|
||||
<span class="secret-label">AppSecret:</span>
|
||||
<code class="secret-value secret-highlight">{{ createdSecret.self_app_secret }}</code>
|
||||
<el-button link type="primary" size="small" @click="handleCopy(createdSecret.self_app_secret, 'AppSecret')">
|
||||
复制
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="handleClosed">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">
|
||||
{{ isEdit ? '保存' : '创建' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { apiAppCreate, apiAppUpdate } from '@/api/apiapp/apiapp'
|
||||
|
||||
defineOptions({ name: 'ApiAppFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 编辑时的行数据注入 */
|
||||
id?: number | string
|
||||
app_name?: string
|
||||
rate_limit?: number
|
||||
callback_url?: string
|
||||
self_ip_whitelist?: string[]
|
||||
is_enabled?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const SUCCESS_CODES = [200, 20000, 1, 0]
|
||||
|
||||
const isEdit = computed(() => props.id !== undefined && props.id !== null && props.id !== '')
|
||||
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (v) => emit('update:visible', v)
|
||||
})
|
||||
|
||||
const formRef = ref<any>()
|
||||
const submitting = ref(false)
|
||||
const createdSecret = ref<any>(null)
|
||||
|
||||
const formData = reactive({
|
||||
app_name: '',
|
||||
rate_limit: 1000,
|
||||
callback_url: '',
|
||||
self_ip_whitelist: [] as string[],
|
||||
is_enabled: 1
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
app_name: [
|
||||
{ required: true, message: '请输入应用名称', trigger: 'blur' },
|
||||
{ max: 200, message: '应用名称不能超过 200 个字符', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
createdSecret.value = null
|
||||
formData.app_name = props.app_name ?? ''
|
||||
formData.rate_limit = props.rate_limit ?? 1000
|
||||
formData.callback_url = props.callback_url ?? ''
|
||||
formData.self_ip_whitelist = props.self_ip_whitelist ? [...props.self_ip_whitelist] : []
|
||||
formData.is_enabled = props.is_enabled ?? 1
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
// 创建成功后用户关闭弹窗时通知父组件刷新列表
|
||||
watch(() => props.visible, (visible, prev) => {
|
||||
if (!visible && prev && createdSecret.value) {
|
||||
emit('success')
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
// ===== IP 白名单(表单内) =====
|
||||
const formIpInputVisible = ref(false)
|
||||
const formIpInputValue = ref('')
|
||||
const formIpInputRef = ref()
|
||||
|
||||
function showFormIpInput() {
|
||||
formIpInputVisible.value = true
|
||||
nextTick(() => {
|
||||
formIpInputRef.value?.focus?.()
|
||||
})
|
||||
}
|
||||
|
||||
function handleAddFormIp() {
|
||||
const val = formIpInputValue.value.trim()
|
||||
if (!val) {
|
||||
formIpInputVisible.value = false
|
||||
return
|
||||
}
|
||||
if (formData.self_ip_whitelist.includes(val)) {
|
||||
ElMessage.warning('该 IP 已存在')
|
||||
formIpInputValue.value = ''
|
||||
formIpInputVisible.value = false
|
||||
return
|
||||
}
|
||||
formData.self_ip_whitelist.push(val)
|
||||
formIpInputValue.value = ''
|
||||
formIpInputVisible.value = false
|
||||
}
|
||||
|
||||
function handleRemoveFormIp(idx: number) {
|
||||
formData.self_ip_whitelist.splice(idx, 1)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = {
|
||||
app_name: formData.app_name,
|
||||
rate_limit: formData.rate_limit,
|
||||
callback_url: formData.callback_url || undefined,
|
||||
self_ip_whitelist: formData.self_ip_whitelist.length > 0 ? formData.self_ip_whitelist : undefined
|
||||
}
|
||||
if (isEdit.value) {
|
||||
const res = await apiAppUpdate({
|
||||
id: Number(props.id),
|
||||
...payload,
|
||||
is_enabled: formData.is_enabled
|
||||
})
|
||||
if (!SUCCESS_CODES.includes(res.code)) {
|
||||
ElMessage.error(res.message || '更新失败')
|
||||
return
|
||||
}
|
||||
ElMessage.success('更新成功')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} else {
|
||||
const res = await apiAppCreate(payload)
|
||||
if (!SUCCESS_CODES.includes(res.code)) {
|
||||
ElMessage.error(res.message || '创建失败')
|
||||
return
|
||||
}
|
||||
createdSecret.value = res
|
||||
ElMessage.success('创建成功!请保存 AppKey 和 AppSecret')
|
||||
// 不关闭,等用户确认密钥后再关闭;关闭时通过 watch 触发刷新
|
||||
}
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '操作失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCopy(text: string, label: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
ElMessage.success(`${label} 已复制到剪贴板`)
|
||||
} catch {
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = text
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.opacity = '0'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
ElMessage.success(`${label} 已复制到剪贴板`)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.unit-text {
|
||||
margin-left: 8px;
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ip-whitelist {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ip-tag {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.secret-display {
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.secret-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.secret-label {
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.secret-value {
|
||||
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||
font-size: 13px;
|
||||
color: #409eff;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.secret-highlight {
|
||||
color: #e6a23c;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,241 @@
|
||||
<!--
|
||||
DefinitionFormDialog — 报表定义(wms_report_definition)新增/编辑 表单弹窗
|
||||
对接接口:report.definition.save(按 code upsert,未传字段不覆盖)
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
:title="isEdit ? '编辑报表定义' : '新增报表定义'"
|
||||
width="680px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="120px"
|
||||
size="small"
|
||||
>
|
||||
<el-form-item label="报表编码" prop="report_code">
|
||||
<el-input
|
||||
v-model="form.report_code"
|
||||
:disabled="isEdit"
|
||||
placeholder="小写字母开头,仅含小写字母/数字/下划线,长度 2-64"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="报表名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入报表名称(≤100 字符)" maxlength="100" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="适用维度" prop="scope">
|
||||
<el-select v-model="form.scope" placeholder="请选择适用维度" style="width: 100%">
|
||||
<el-option label="仓库" value="warehouse" />
|
||||
<el-option label="货主" value="store" />
|
||||
<el-option label="通用" value="open" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="启用状态" prop="is_enabled">
|
||||
<el-switch v-model="form.is_enabled" :active-value="1" :inactive-value="0" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="报表描述" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" :rows="2" maxlength="500" placeholder="最长 500 字符" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" maxlength="500" placeholder="最长 500 字符" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">JSON 配置(可选,支持对象或 JSON 字符串)</el-divider>
|
||||
|
||||
<el-form-item label="输出配置" prop="output_config_text">
|
||||
<el-input
|
||||
v-model="form.output_config_text"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder='如 {"filename":"报表","sheetName":"Sheet1"}'
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据源配置" prop="source_config_text">
|
||||
<el-input
|
||||
v-model="form.source_config_text"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder='如 {"query":"week_inout_7d"}'
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="工作表配置" prop="sheet_config_text">
|
||||
<el-input
|
||||
v-model="form.sheet_config_text"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder='如 {"columns":[]}'
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch, computed } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { saveReportDefinition } from '@/api/report/report'
|
||||
|
||||
defineOptions({ name: 'DefinitionFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 编辑时由行数据注入的初始值(report.definition 响应中 code 平铺为 report_code) */
|
||||
report_code?: string
|
||||
code?: string
|
||||
name?: string
|
||||
scope?: string
|
||||
description?: string
|
||||
is_enabled?: number
|
||||
remark?: string
|
||||
output_config?: any
|
||||
source_config?: any
|
||||
sheet_config?: any
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
report_code: '',
|
||||
name: '',
|
||||
scope: 'warehouse',
|
||||
description: '',
|
||||
is_enabled: 1,
|
||||
remark: '',
|
||||
output_config_text: '',
|
||||
source_config_text: '',
|
||||
sheet_config_text: ''
|
||||
})
|
||||
|
||||
const isEdit = computed(() => Boolean(props.report_code || props.code))
|
||||
|
||||
const rules = {
|
||||
report_code: [
|
||||
{ required: true, message: '请输入报表编码', trigger: 'blur' },
|
||||
{ pattern: /^[a-z][a-z0-9_]{1,63}$/, message: '须以小写字母开头,仅含小写字母/数字/下划线,长度 2-64', trigger: 'blur' }
|
||||
],
|
||||
name: [{ required: true, message: '请输入报表名称', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
/** 将文本解析为对象(失败则原样返回字符串,后端同时支持对象或 JSON 字符串) */
|
||||
function parseJsonOrRaw(text: string): any {
|
||||
const raw = text.trim()
|
||||
if (!raw) return undefined
|
||||
try {
|
||||
return JSON.parse(raw)
|
||||
} catch {
|
||||
return raw
|
||||
}
|
||||
}
|
||||
|
||||
/** 将任意值序列化为可编辑文本(对象 → JSON 字符串,其他 → 字符串) */
|
||||
function toConfigText(v: any): string {
|
||||
if (v === undefined || v === null || v === '') return ''
|
||||
if (typeof v === 'string') {
|
||||
const trimmed = v.trim()
|
||||
if (!trimmed) return ''
|
||||
try {
|
||||
JSON.parse(trimmed) // 已是合法 JSON 字符串则原样展示
|
||||
return trimmed
|
||||
} catch {
|
||||
return v
|
||||
}
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(v, null, 2)
|
||||
} catch {
|
||||
return String(v)
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.report_code = props.report_code ?? props.code ?? ''
|
||||
form.name = props.name ?? ''
|
||||
form.scope = props.scope ?? 'warehouse'
|
||||
form.description = props.description ?? ''
|
||||
form.is_enabled = props.is_enabled ?? 1
|
||||
form.remark = props.remark ?? ''
|
||||
form.output_config_text = toConfigText(props.output_config)
|
||||
form.source_config_text = toConfigText(props.source_config)
|
||||
form.sheet_config_text = toConfigText(props.sheet_config)
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await saveReportDefinition({
|
||||
code: form.report_code.trim(),
|
||||
name: form.name.trim(),
|
||||
...(form.scope ? { scope: form.scope } : {}),
|
||||
...(form.description ? { description: form.description } : {}),
|
||||
...(form.remark ? { remark: form.remark } : {}),
|
||||
is_enabled: form.is_enabled,
|
||||
...(form.output_config_text.trim() ? { output_config: parseJsonOrRaw(form.output_config_text) } : {}),
|
||||
...(form.source_config_text.trim() ? { source_config: parseJsonOrRaw(form.source_config_text) } : {}),
|
||||
...(form.sheet_config_text.trim() ? { sheet_config: parseJsonOrRaw(form.sheet_config_text) } : {})
|
||||
})
|
||||
|
||||
ElMessage.success(isEdit.value ? '报表定义已更新' : '报表定义已创建')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '保存报表定义失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 4px 0 0;
|
||||
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,414 @@
|
||||
<!--
|
||||
DeliveryPlanFormDialog — 货主报表投递计划 新增/编辑 表单弹窗
|
||||
对接接口:report.deliveryPlan.save(货主 store_id + 报表 report_code 唯一,存在则更新)
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
:title="isEdit ? '编辑投递计划' : '新增投递计划'"
|
||||
width="620px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="110px"
|
||||
size="small"
|
||||
>
|
||||
<el-form-item label="货主" prop="store_id">
|
||||
<el-select
|
||||
v-model="form.store_id"
|
||||
filterable
|
||||
placeholder="请选择货主"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in storeOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="报表编码" prop="report_code">
|
||||
<el-input v-model="form.report_code" placeholder="请输入已启用的报表编码,如 deliveryPlan" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="投递时间" prop="schedule_times">
|
||||
<div class="string-array-editor">
|
||||
<div v-if="form.schedule_times.length" class="tag-list">
|
||||
<el-tag
|
||||
v-for="(t, idx) in form.schedule_times"
|
||||
:key="`${t}-${idx}`"
|
||||
closable
|
||||
size="small"
|
||||
@close="removeScheduleTime(idx)"
|
||||
>{{ t }}</el-tag>
|
||||
</div>
|
||||
<div class="tag-input-row">
|
||||
<el-input
|
||||
v-model="scheduleTimeInput"
|
||||
placeholder="输入 HH:mm 后回车添加,如 08:00"
|
||||
maxlength="5"
|
||||
@keyup.enter="addScheduleTime"
|
||||
/>
|
||||
<el-button size="small" :disabled="!scheduleTimeInput.trim()" @click="addScheduleTime">添加</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-tip">24 小时制时间点(如 08:00),系统会自动去重并升序排列</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="投递渠道" prop="channel">
|
||||
<el-select v-model="form.channel" placeholder="选择投递渠道" style="width: 100%">
|
||||
<el-option label="企业微信" value="wecom" />
|
||||
<el-option label="站内信" value="inbox" />
|
||||
<el-option label="链接" value="link" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="补投宽限(分)" prop="late_grace_minutes">
|
||||
<el-input-number
|
||||
v-model="form.late_grace_minutes"
|
||||
:min="0"
|
||||
:max="1440"
|
||||
:precision="0"
|
||||
controls-position="right"
|
||||
placeholder="默认 60"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<div class="form-tip">0-1440,默认 60;越界值自动夹取</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" maxlength="500" placeholder="最长 500 字符" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">文本通知配置(可选)</el-divider>
|
||||
|
||||
<el-form-item label="通知模板" prop="notify_template">
|
||||
<el-input
|
||||
v-model="form.notify_template"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
maxlength="500"
|
||||
placeholder="支持标签 {time}/{url}/{report_name}/{biz_date}"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="通知群ID" prop="notify_group_ids">
|
||||
<el-select
|
||||
v-model="form.notify_group_ids"
|
||||
multiple
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
:remote-method="searchGroups"
|
||||
:loading="groupSearchLoading"
|
||||
placeholder="输入群名称或外部群ID搜索"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="g in groupOptions"
|
||||
:key="g.id"
|
||||
:label="g.label"
|
||||
:value="g.id"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">可搜索选择多个通知群,最多 20 个</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="通知成员ID" prop="notify_member_ids">
|
||||
<el-select
|
||||
v-model="form.notify_member_ids"
|
||||
multiple
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
:remote-method="searchMembers"
|
||||
:loading="memberSearchLoading"
|
||||
placeholder="先选择通知群,再搜索成员"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="m in memberOptions"
|
||||
:key="m.user_id"
|
||||
:label="m.label"
|
||||
:value="m.user_id"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">从已选通知群的成员中搜索选择,最多 100 个</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch, computed, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { saveDeliveryPlan } from '@/api/report/report'
|
||||
import { inboxGroupQuickList, inboxGroupMembers } from '@/api/inbox/inbox'
|
||||
import { storeOptions, loadStoreOptions } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'DeliveryPlanFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 编辑时由行数据注入的初始值 */
|
||||
store_id?: number | string
|
||||
report_code?: string
|
||||
schedule_times?: string[]
|
||||
channel?: string
|
||||
late_grace_minutes?: number
|
||||
remark?: string
|
||||
notify_template?: string
|
||||
notify_group_ids?: number[] | null
|
||||
notify_member_ids?: string[] | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
store_id: undefined as number | undefined,
|
||||
report_code: '',
|
||||
schedule_times: [] as string[],
|
||||
channel: 'wecom',
|
||||
late_grace_minutes: 60,
|
||||
remark: '',
|
||||
notify_template: '',
|
||||
notify_group_ids: [] as number[],
|
||||
notify_member_ids: [] as string[]
|
||||
})
|
||||
|
||||
/** 容错解析数字数组(支持数组 / JSON 字符串 / 逗号分隔字符串) */
|
||||
function normalizeNumberArray(v: any): number[] {
|
||||
if (Array.isArray(v)) return v.map((x) => Number(x)).filter((n) => Number.isInteger(n) && n > 0)
|
||||
if (typeof v === 'string' && v.trim()) {
|
||||
try {
|
||||
const parsed = JSON.parse(v)
|
||||
if (Array.isArray(parsed)) return parsed.map((x: any) => Number(x)).filter((n) => Number.isInteger(n) && n > 0)
|
||||
} catch { /* ignore */ }
|
||||
return v.split(/[,,]/).map((s) => s.trim()).filter(Boolean).map(Number).filter((n) => Number.isInteger(n) && n > 0)
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/** 容错解析字符串数组(支持数组 / JSON 字符串 / 逗号分隔字符串) */
|
||||
function normalizeStringArray(v: any): string[] {
|
||||
if (Array.isArray(v)) return v.map(String).filter((s) => s.trim())
|
||||
if (typeof v === 'string' && v.trim()) {
|
||||
try {
|
||||
const parsed = JSON.parse(v)
|
||||
if (Array.isArray(parsed)) return parsed.map(String).filter((s) => s.trim())
|
||||
} catch { /* ignore */ }
|
||||
return v.split(/[,,]/).map((s) => s.trim()).filter(Boolean)
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/** 投递时间标签输入 */
|
||||
const scheduleTimeInput = ref('')
|
||||
|
||||
/** 通知群远程搜索选项 */
|
||||
const groupOptions = ref<{ id: number; label: string }[]>([])
|
||||
const groupSearchLoading = ref(false)
|
||||
|
||||
/** 通知成员远程搜索选项 */
|
||||
const memberOptions = ref<{ user_id: string; label: string }[]>([])
|
||||
const memberSearchLoading = ref(false)
|
||||
|
||||
const isEdit = computed(() => Boolean(props.store_id && props.report_code))
|
||||
|
||||
const rules = {
|
||||
store_id: [{ required: true, message: '请选择货主', trigger: 'change' }],
|
||||
report_code: [{ required: true, message: '请输入报表编码', trigger: 'blur' }],
|
||||
schedule_times: [{ required: true, type: 'array', min: 1, message: '至少添加一个投递时间', trigger: 'change' }]
|
||||
}
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.store_id = props.store_id !== undefined && props.store_id !== null && props.store_id !== ''
|
||||
? Number(props.store_id)
|
||||
: undefined
|
||||
form.report_code = props.report_code ?? ''
|
||||
form.schedule_times = normalizeStringArray(props.schedule_times)
|
||||
form.channel = props.channel ?? 'wecom'
|
||||
form.late_grace_minutes = props.late_grace_minutes ?? 60
|
||||
form.remark = props.remark ?? ''
|
||||
form.notify_template = props.notify_template ?? ''
|
||||
form.notify_group_ids = normalizeNumberArray(props.notify_group_ids)
|
||||
form.notify_member_ids = normalizeStringArray(props.notify_member_ids)
|
||||
scheduleTimeInput.value = ''
|
||||
groupOptions.value = []
|
||||
memberOptions.value = []
|
||||
formRef.value?.clearValidate?.()
|
||||
// 预加载远程下拉选项(便于编辑回显与首次展开)
|
||||
void searchGroups('')
|
||||
void searchMembers('', true)
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
/** 添加投递时间(HH:mm 校验 + 去重 + 升序) */
|
||||
function addScheduleTime() {
|
||||
const raw = scheduleTimeInput.value.trim()
|
||||
if (!raw) return
|
||||
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(raw)) {
|
||||
ElMessage.warning('请输入正确的 24 小时制时间,如 08:00')
|
||||
return
|
||||
}
|
||||
if (form.schedule_times.includes(raw)) {
|
||||
ElMessage.warning('该时间已存在')
|
||||
return
|
||||
}
|
||||
form.schedule_times.push(raw)
|
||||
form.schedule_times.sort()
|
||||
scheduleTimeInput.value = ''
|
||||
}
|
||||
|
||||
/** 移除投递时间 */
|
||||
function removeScheduleTime(idx: number) {
|
||||
form.schedule_times.splice(idx, 1)
|
||||
}
|
||||
|
||||
/** 群快速查询(远程搜索) */
|
||||
async function searchGroups(keyword: string) {
|
||||
groupSearchLoading.value = true
|
||||
try {
|
||||
const res: any = await inboxGroupQuickList({ keyword, limit: 100 })
|
||||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||||
const data = res.data ?? res
|
||||
groupOptions.value = (data.list ?? []).map((g: any) => ({
|
||||
id: g.id,
|
||||
label: g.group_name ? `${g.group_name}(${g.group_id ?? ''})` : String(g.id)
|
||||
}))
|
||||
} else {
|
||||
groupOptions.value = []
|
||||
}
|
||||
} catch {
|
||||
groupOptions.value = []
|
||||
} finally {
|
||||
groupSearchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 成员查询(远程搜索,传已选群内部主键 id 聚合去重) */
|
||||
async function searchMembers(keyword: string, silent = false) {
|
||||
const groupIds = form.notify_group_ids ?? []
|
||||
if (!groupIds.length) {
|
||||
if (!silent) ElMessage.warning('请先选择通知群')
|
||||
memberOptions.value = []
|
||||
return
|
||||
}
|
||||
memberSearchLoading.value = true
|
||||
try {
|
||||
const merged: { user_id: string; label: string }[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const gid of groupIds) {
|
||||
const res: any = await inboxGroupMembers({ groupId: gid, keyword, limit: 100 })
|
||||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||||
const data = res.data ?? res
|
||||
for (const m of data.list ?? []) {
|
||||
const uid = String(m.user_id ?? '')
|
||||
if (!uid || seen.has(uid)) continue
|
||||
seen.add(uid)
|
||||
merged.push({ user_id: uid, label: m.user_name ? `${m.user_name}(${uid})` : uid })
|
||||
}
|
||||
}
|
||||
}
|
||||
memberOptions.value = merged
|
||||
} catch {
|
||||
memberOptions.value = []
|
||||
} finally {
|
||||
memberSearchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
})
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await saveDeliveryPlan({
|
||||
store_id: Number(form.store_id),
|
||||
report_code: form.report_code.trim(),
|
||||
schedule_times: form.schedule_times,
|
||||
channel: form.channel,
|
||||
late_grace_minutes: form.late_grace_minutes,
|
||||
remark: form.remark || undefined,
|
||||
...(form.notify_template ? { notify_template: form.notify_template } : {}),
|
||||
...(form.notify_group_ids.length ? { notify_group_ids: form.notify_group_ids } : {}),
|
||||
...(form.notify_member_ids.length ? { notify_member_ids: form.notify_member_ids } : {})
|
||||
})
|
||||
|
||||
ElMessage.success(isEdit.value ? '投递计划已更新' : '投递计划已创建')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '保存投递计划失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 4px 0 0;
|
||||
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.string-array-editor {
|
||||
width: 100%;
|
||||
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.tag-input-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,107 @@
|
||||
<!--
|
||||
ExampleFormDialog — 示例表单弹窗(模板)
|
||||
|
||||
功能按钮对应的表单组件放在 pages/ 目录下。
|
||||
|
||||
使用方式:
|
||||
1. 在 template-config.ts 的 COMPONENT_REGISTRY 中注册
|
||||
2. 在 template-config.ts 的 TOOLBAR_BUTTONS 中添加功能按钮,设置 formKey
|
||||
3. index.vue 中通过工具栏按钮触发打开
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="示例操作"
|
||||
width="500px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form ref="formRef" :model="form" label-width="100px" size="small">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input
|
||||
v-model="form.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">
|
||||
确认
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'ExampleFormDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 从行数据注入的初始值(由 OperationCellRenderer 的 paramMap 传递) */
|
||||
id?: string | number
|
||||
code?: string
|
||||
name?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
const submitting = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.name = props.name ?? ''
|
||||
form.description = ''
|
||||
}
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true
|
||||
try {
|
||||
// ★ 替换为真实 API 调用
|
||||
// const res = await yourApi.submit({ id: props.id, ...form })
|
||||
await new Promise((r) => setTimeout(r, 500))
|
||||
|
||||
ElMessage.success('操作成功')
|
||||
emit('update:visible', false)
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '操作失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 0;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,171 @@
|
||||
<!--
|
||||
ExportReportDialog — 报表导出提交弹窗(手动导出)
|
||||
对接接口:report.generate(提交异步导出任务,立即返回 task_id)
|
||||
warehouse_id 由服务端从登录上下文自动注入,前端无需传递。
|
||||
-->
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="提交报表导出"
|
||||
width="520px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<div class="form-body">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
size="small"
|
||||
>
|
||||
<el-form-item label="报表编码" prop="report_code">
|
||||
<el-input v-model="form.report_code" placeholder="请输入报表编码(须为已启用的报表定义)" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="货主" prop="store_id">
|
||||
<el-select
|
||||
v-model="form.store_id"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="货主维度报表时选择"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in storeOptions"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div class="form-tip">可选;>0 生效,<=0 视为不按货主过滤</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据日期" prop="bizDate">
|
||||
<el-date-picker
|
||||
v-model="form.bizDate"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="缺省取服务器当天"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button size="small" @click="handleClosed">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="exportLoading" @click="handleSubmit">
|
||||
提交任务
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<AsyncExportProgressDialog
|
||||
v-model:visible="exportDialogVisible"
|
||||
title="报表导出进度"
|
||||
:loading="exportLoading"
|
||||
:progress-percent="exportProgressPercent"
|
||||
:progress-status="exportProgressStatus"
|
||||
:status-label="exportStatusLabel"
|
||||
:task-id="exportTaskProgress.taskId"
|
||||
:message="exportTaskProgress.message"
|
||||
:error="exportTaskProgress.error"
|
||||
:update-time="exportTaskProgress.updateTime"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch, onMounted } from 'vue'
|
||||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||||
import { generate, generateTaskProgress } from '@/api/report/report'
|
||||
import { storeOptions, loadStoreOptions } from '../config/template-config'
|
||||
|
||||
defineOptions({ name: 'ExportReportDialog' })
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
/** 初始报表编码(导出任务行「导出此报表」带入) */
|
||||
reportCode?: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', v: boolean): void
|
||||
}>()
|
||||
|
||||
const formRef = ref<any>(null)
|
||||
|
||||
const form = reactive({
|
||||
report_code: '',
|
||||
store_id: undefined as number | undefined,
|
||||
bizDate: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
report_code: [{ required: true, message: '请输入报表编码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 提交导出 + 轮询进度(不传 storageKey → 不写任何本地存储)
|
||||
const {
|
||||
exportLoading,
|
||||
exportDialogVisible,
|
||||
exportTaskProgress,
|
||||
exportProgressPercent,
|
||||
exportProgressStatus,
|
||||
exportStatusLabel,
|
||||
submitExportTask
|
||||
} = useAsyncExportTask({
|
||||
submitExport: (payload) => generate(payload as any),
|
||||
queryProgress: (params) => generateTaskProgress(params as any)
|
||||
})
|
||||
|
||||
watch(() => props.visible, (v) => {
|
||||
if (v) {
|
||||
form.report_code = props.reportCode ?? ''
|
||||
form.store_id = undefined
|
||||
form.bizDate = ''
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void loadStoreOptions()
|
||||
})
|
||||
|
||||
function handleClosed() {
|
||||
emit('update:visible', false)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
// 提交导出任务;提交后进度在弹窗中展示,完成后自动下载(useAsyncExportTask 内部处理)
|
||||
await submitExportTask({
|
||||
report_code: form.report_code.trim(),
|
||||
...(form.store_id && form.store_id > 0 ? { store_id: form.store_id } : {}),
|
||||
...(form.bizDate ? { params: { bizDate: form.bizDate } } : {})
|
||||
})
|
||||
emit('update:visible', false)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.form-body {
|
||||
padding: 12px 4px 0 0;
|
||||
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,866 @@
|
||||
<!--
|
||||
WarehouseSettingsForm — 仓库设置「配置表单」页(表单项页面)
|
||||
对接接口:
|
||||
- setting.warehouse.getSettings + getFieldMeta:加载当前仓库配置与字段元信息
|
||||
- setting.warehouse.saveSettings:保存配置
|
||||
该页为表单页形态(不使用 scan-box / upper-table / 明细组件),由 newview 模板以
|
||||
viewType='form' 渲染替换默认的列表结构。
|
||||
-->
|
||||
<template>
|
||||
<div class="warehouse-settings-form" v-loading="pageLoading">
|
||||
<div class="settings-header">
|
||||
<div class="header-text">
|
||||
<span class="title">仓库设置</span>
|
||||
<span v-if="warehouseId != null" class="sub">当前仓库 ID:{{ warehouseId }}</span>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<el-button :loading="pageLoading" @click="loadAll">刷新</el-button>
|
||||
<el-button type="primary" :loading="saving" @click="handleSave">保存</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="loadError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="mb-16"
|
||||
:title="loadError"
|
||||
/>
|
||||
|
||||
<div class="settings-body">
|
||||
<el-form label-width="200px" label-position="right" class="settings-form">
|
||||
<template v-if="displayFields.length">
|
||||
<el-form-item
|
||||
v-for="field in displayFields"
|
||||
:key="field.key"
|
||||
:required="field.required"
|
||||
>
|
||||
<template #label>
|
||||
<span :title="field.description">{{ field.label }}</span>
|
||||
</template>
|
||||
|
||||
<div class="field-block">
|
||||
<el-switch
|
||||
v-if="field.type === 'boolean'"
|
||||
v-model="subjectConfig[field.key]"
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
/>
|
||||
<div v-else-if="field.type === 'string_array'" class="string-array-editor">
|
||||
<div v-if="getStringArrayFieldItems(field.key).length" class="tag-list">
|
||||
<el-tag
|
||||
v-for="(item, idx) in getStringArrayFieldItems(field.key)"
|
||||
:key="`${field.key}-${idx}`"
|
||||
closable
|
||||
size="small"
|
||||
@close="removeStringArrayFieldItem(field.key, idx)"
|
||||
>{{ item }}</el-tag>
|
||||
</div>
|
||||
<div class="tag-input-row">
|
||||
<el-input
|
||||
v-model="stringArrayInputs[field.key]"
|
||||
:placeholder="`输入关键字,回车添加`"
|
||||
maxlength="100"
|
||||
@keyup.enter="addStringArrayFieldItem(field.key)"
|
||||
/>
|
||||
<el-button size="small" :disabled="!stringArrayInputs[field.key]?.trim()" @click="addStringArrayFieldItem(field.key)">添加</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="field.type === 'array'" class="array-editor">
|
||||
<div v-if="field.itemFields && field.itemFields.length" class="array-table">
|
||||
<div class="array-table__head">
|
||||
<div v-for="itemField in field.itemFields" :key="`${field.key}-${itemField.key}-head`" class="array-table__cell">
|
||||
{{ itemField.label }}
|
||||
</div>
|
||||
<div class="array-table__op">操作</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="(item, idx) in getArrayFieldItems(field.key)"
|
||||
:key="`${field.key}-${idx}`"
|
||||
class="array-table__row"
|
||||
>
|
||||
<div v-for="itemField in field.itemFields" :key="`${field.key}-${idx}-${itemField.key}`" class="array-table__cell">
|
||||
<el-switch
|
||||
v-if="itemField.type === 'boolean'"
|
||||
:model-value="getArrayObjectFieldValue(item, itemField.key) as boolean"
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||
/>
|
||||
<el-select
|
||||
v-else-if="itemField.type === 'select'"
|
||||
:model-value="getArrayObjectFieldValue(item, itemField.key)"
|
||||
clearable
|
||||
filterable
|
||||
placeholder="请选择"
|
||||
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in itemField.options || []"
|
||||
:key="`${field.key}-${idx}-${itemField.key}-${String(opt.value)}`"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-color-picker
|
||||
v-else-if="itemField.type === 'color'"
|
||||
:model-value="String(getArrayObjectFieldValue(item, itemField.key) ?? '')"
|
||||
show-alpha
|
||||
:predefine="PREDEFINED_COLORS"
|
||||
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||
/>
|
||||
<el-input-number
|
||||
v-else-if="itemField.type === 'number'"
|
||||
:model-value="getArrayObjectFieldValue(item, itemField.key) as number | undefined"
|
||||
:min="itemField.min"
|
||||
:max="itemField.max"
|
||||
:step="itemField.step ?? 1"
|
||||
:precision="itemField.precision"
|
||||
controls-position="right"
|
||||
placeholder="留空"
|
||||
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||
/>
|
||||
<el-input
|
||||
v-else
|
||||
:model-value="String(getArrayObjectFieldValue(item, itemField.key) ?? '')"
|
||||
clearable
|
||||
placeholder="请输入"
|
||||
:maxlength="itemField.maxLength"
|
||||
:show-word-limit="Boolean(itemField.maxLength)"
|
||||
@update:model-value="onArrayObjectItemInput(field, idx, itemField.key, $event)"
|
||||
/>
|
||||
</div>
|
||||
<div class="array-table__op">
|
||||
<el-button type="danger" plain @click="removeArrayFieldItem(field.key, idx)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div
|
||||
v-for="(item, idx) in getArrayFieldItems(field.key)"
|
||||
:key="`${field.key}-${idx}`"
|
||||
class="array-editor__row"
|
||||
>
|
||||
<el-input
|
||||
:model-value="formatArrayItemText(item)"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
class="field-control"
|
||||
placeholder="可输入文本,或输入 JSON(对象/数组)"
|
||||
@update:model-value="onArrayItemInput(field.key, idx, $event)"
|
||||
/>
|
||||
<el-button type="danger" plain @click="removeArrayFieldItem(field.key, idx)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-button type="primary" plain @click="addArrayFieldItem(field)">新增一项</el-button>
|
||||
</div>
|
||||
<el-select
|
||||
v-else-if="field.type === 'select'"
|
||||
v-model="subjectConfig[field.key]"
|
||||
clearable
|
||||
filterable
|
||||
class="field-control"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="opt in field.options || []"
|
||||
:key="String(opt.value)"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-color-picker
|
||||
v-else-if="field.type === 'color'"
|
||||
v-model="subjectConfig[field.key] as string"
|
||||
class="field-color-control"
|
||||
show-alpha
|
||||
:predefine="PREDEFINED_COLORS"
|
||||
/>
|
||||
<el-input-number
|
||||
v-else-if="field.type === 'number'"
|
||||
v-model="subjectConfig[field.key] as number | undefined"
|
||||
class="field-control"
|
||||
:min="field.min"
|
||||
:max="field.max"
|
||||
:step="field.step ?? 1"
|
||||
:precision="field.precision"
|
||||
controls-position="right"
|
||||
placeholder="未设置则留空"
|
||||
/>
|
||||
<div v-else-if="field.type === 'object' && field.itemFields && field.itemFields.length" class="object-editor">
|
||||
<div
|
||||
v-for="itemKey in field.itemFields"
|
||||
:key="`${field.key}-${itemKey.key}`"
|
||||
class="object-editor__row"
|
||||
>
|
||||
<span class="object-editor__label">{{ itemKey.label }}</span>
|
||||
<el-switch
|
||||
v-if="itemKey.type === 'boolean'"
|
||||
:model-value="getObjectFieldValue(field.key, itemKey.key) as boolean"
|
||||
:active-value="true"
|
||||
:inactive-value="false"
|
||||
@update:model-value="onObjectFieldChange(field.key, itemKey.key, $event)"
|
||||
/>
|
||||
<el-input
|
||||
v-else
|
||||
:model-value="String(getObjectFieldValue(field.key, itemKey.key) ?? '')"
|
||||
size="small"
|
||||
style="width:200px"
|
||||
@update:model-value="onObjectFieldChange(field.key, itemKey.key, $event)"
|
||||
/>
|
||||
<span v-if="itemKey.description" class="object-editor__desc">{{ itemKey.description }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<SpacePicker
|
||||
v-else-if="field.type === 'location'"
|
||||
:model-value="locationFieldValue(field.key)"
|
||||
class="field-control"
|
||||
placeholder="请选择库位"
|
||||
@update:model-value="onLocationFieldChange(field.key, $event)"
|
||||
/>
|
||||
<el-input
|
||||
v-else
|
||||
v-model="subjectConfig[field.key] as string"
|
||||
class="field-control"
|
||||
clearable
|
||||
placeholder="请输入"
|
||||
:maxlength="field.maxLength"
|
||||
:show-word-limit="Boolean(field.maxLength)"
|
||||
/>
|
||||
<div v-if="field.description" class="field-desc">{{ field.description }}</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-empty v-else description="暂无可编辑字段,请检查接口返回" />
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import SpacePicker from '@/components/SpacePicker/index.vue'
|
||||
import {
|
||||
settingWarehouseGetSettings,
|
||||
settingWarehouseGetFieldMeta,
|
||||
settingWarehouseSaveSettings,
|
||||
unwrapSettingWarehousePayload,
|
||||
buildSaveSettingsRequest,
|
||||
normalizeGetSettingsPayload,
|
||||
normalizeSaveSettingsPayload,
|
||||
type SettingWarehouseSettingsPayload
|
||||
} from '@/api/setting.warehouse/settingwarehouse'
|
||||
|
||||
defineOptions({ name: 'WarehouseSettingsForm' })
|
||||
|
||||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||||
const PREDEFINED_COLORS = ['#ff4d4f', '#ff7a45', '#faad14', '#fadb14', '#95de64', '#52c41a']
|
||||
|
||||
type NormalizedField = {
|
||||
key: string
|
||||
label: string
|
||||
type: 'number' | 'string' | 'boolean' | 'select' | 'array' | 'string_array' | 'color' | 'object' | 'location'
|
||||
description?: string
|
||||
required?: boolean
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
precision?: number
|
||||
maxLength?: number
|
||||
default?: unknown
|
||||
defaultValue?: unknown
|
||||
itemFields?: NormalizedField[]
|
||||
options?: { label: string; value: string | number | boolean }[]
|
||||
}
|
||||
|
||||
const FALLBACK_FIELDS: NormalizedField[] = [
|
||||
{ key: 'max_wave_quantity', label: '波次最大订单数', type: 'number', min: 1, precision: 0, description: '自动加团等场景会跳过订单数已达该上限的波次(与波次模块逻辑一致)。' },
|
||||
{ key: 'min_group_order_fetch_quantity', label: '团购判定最小同组订单数', type: 'number', min: 1, precision: 0, description: '抓取团购/散单分组阈值,未配置时后端常用默认值 13。' },
|
||||
{ key: 'max_notice_webhook_count', label: 'Webhook 通知上限', type: 'number', min: 0, precision: 0 },
|
||||
{ key: 'default_express_code', label: '默认快递编码', type: 'string' },
|
||||
{ key: 'default_platform_code', label: '默认平台编码', type: 'string' },
|
||||
{ key: 'group_wave_prefix', label: '团购波次号前缀', type: 'string' },
|
||||
{ key: 'enable_external_express_code', label: '启用外部快递编码', type: 'boolean', description: '开启后允许按外部系统传入的快递编码进行处理(如无匹配仍以业务校验为准);默认关闭。' },
|
||||
{ key: 'sender_name', label: '默认发件人姓名', type: 'string', maxLength: 50 },
|
||||
{ key: 'sender_tel', label: '默认发件人联系电话', type: 'string', maxLength: 20 },
|
||||
{ key: 'province_name', label: '默认发件省份', type: 'string', maxLength: 50 },
|
||||
{ key: 'city_name', label: '默认发件城市', type: 'string', maxLength: 50 },
|
||||
{ key: 'district_name', label: '默认发件区/县', type: 'string', maxLength: 50 },
|
||||
{ key: 'town_name', label: '默认发件镇/街道', type: 'string', maxLength: 50 },
|
||||
{ key: 'address', label: '默认发件详细地址', type: 'string', maxLength: 200 },
|
||||
{ key: 'receiver_address', label: '仓库收货地址', type: 'string', maxLength: 500, description: '退货/退件收件地址,一行文本' },
|
||||
{
|
||||
key: 'auto_outbound_rules',
|
||||
label: '自动出库规则',
|
||||
type: 'object',
|
||||
description: '全部条件满足时自动标记待出库。',
|
||||
itemFields: [
|
||||
{ key: 'enabled', label: '启用自动出库', type: 'boolean', description: '默认关闭' },
|
||||
{ key: 'require_recheck', label: '要求已复核', type: 'boolean', description: 'recheck_status=fin,默认开启' },
|
||||
{ key: 'require_pack', label: '要求已打包', type: 'boolean', description: 'pack_status=fin,默认开启' },
|
||||
{ key: 'require_weigh', label: '要求已称重', type: 'boolean', description: 'weighing_weight>0,默认开启' },
|
||||
{ key: 'require_sync', label: '要求已同步', type: 'boolean', description: 'sync_status=fin,默认开启' },
|
||||
{ key: 'require_print', label: '要求已打印', type: 'boolean', description: 'print_status=fin,默认开启' },
|
||||
{ key: 'require_pick', label: '要求已拣货', type: 'boolean', description: 'pick_status=fin,默认开启' }
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'auto_allocate_express_exclude_remarks',
|
||||
label: '自动分配快递排除备注',
|
||||
type: 'string_array',
|
||||
default: [],
|
||||
required: false,
|
||||
description: '订单备注命中任一关键字时,跳过自动分配快递,默认 [](不排除任何订单)'
|
||||
},
|
||||
{
|
||||
key: 'default_location_id',
|
||||
label: '默认库位ID',
|
||||
type: 'number',
|
||||
min: 0,
|
||||
precision: 0,
|
||||
description: '默认库位(库位ID,未配置时为 null;须属于当前仓库且未删除、已启用)'
|
||||
}
|
||||
]
|
||||
|
||||
function pickStr(obj: Record<string, unknown>, keys: string[]): string | undefined {
|
||||
for (const k of keys) {
|
||||
const v = obj[k]
|
||||
if (v !== undefined && v !== null && String(v).trim() !== '') return String(v)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function parseOptions(raw: unknown): { label: string; value: string | number | boolean }[] {
|
||||
if (!Array.isArray(raw)) return []
|
||||
return raw.map((item) => {
|
||||
if (item !== null && typeof item === 'object') {
|
||||
const o = item as Record<string, unknown>
|
||||
const value = o.value ?? o.key ?? o.id
|
||||
const label = String(o.label ?? o.text ?? o.name ?? value ?? '')
|
||||
return { label, value: value as string | number | boolean }
|
||||
}
|
||||
return { label: String(item), value: item as string | number | boolean }
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeFieldMetaItem(raw: Record<string, unknown>): NormalizedField | null {
|
||||
const key = pickStr(raw, ['key', 'field', 'name', 'prop', 'id'])
|
||||
if (!key) return null
|
||||
const label = pickStr(raw, ['label', 'name', 'title', 'displayName']) || key
|
||||
const description = pickStr(raw, ['description', 'desc', 'help', 'remark'])
|
||||
const required = Boolean(raw.required ?? raw.is_required)
|
||||
|
||||
const rawType = String(pickStr(raw, ['type', 'valueType', 'component', 'inputType']) || 'string').toLowerCase()
|
||||
const options = parseOptions(raw.options ?? raw.enum)
|
||||
let type: NormalizedField['type'] = 'string'
|
||||
if (rawType.includes('int') || rawType.includes('number') || rawType === 'float' || rawType === 'decimal') {
|
||||
type = 'number'
|
||||
} else if (rawType.includes('bool') || rawType === 'switch' || rawType === 'flag') {
|
||||
type = 'boolean'
|
||||
} else if (rawType.includes('color')) {
|
||||
type = 'color'
|
||||
} else if (rawType.includes('array')) {
|
||||
type = rawType === 'string_array' ? 'string_array' : 'array'
|
||||
} else if (rawType.includes('object')) {
|
||||
type = 'object'
|
||||
} else if (rawType.includes('location')) {
|
||||
type = 'location'
|
||||
} else if (rawType === 'select' || rawType === 'enum' || options.length > 0) {
|
||||
type = 'select'
|
||||
}
|
||||
|
||||
const toNumber = (v: unknown) => {
|
||||
const n = typeof v === 'number' ? v : Number(v)
|
||||
return Number.isFinite(n) ? n : undefined
|
||||
}
|
||||
const min = toNumber(raw.min)
|
||||
const max = toNumber(raw.max)
|
||||
const step = toNumber(raw.step)
|
||||
const precision = toNumber(raw.precision)
|
||||
const maxLength = toNumber(raw.maxLength ?? raw.max_length)
|
||||
const defaultValue = raw.default
|
||||
const itemFields = (type === 'array' || type === 'object') ? normalizeArrayItemFields(raw.item_keys ?? raw.item_key) : undefined
|
||||
|
||||
return {
|
||||
key, label, type, description, required, min, max, step, precision, maxLength,
|
||||
defaultValue, itemFields,
|
||||
options: options.length ? options : undefined
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeArrayItemFields(raw: unknown): NormalizedField[] {
|
||||
if (!raw || typeof raw !== 'object') return []
|
||||
if (Array.isArray(raw)) {
|
||||
return raw
|
||||
.map((item) => (item && typeof item === 'object' ? normalizeFieldMetaItem(item as Record<string, unknown>) : null))
|
||||
.filter((x): x is NormalizedField => !!x)
|
||||
.filter((x) => x.type !== 'array')
|
||||
}
|
||||
const obj = raw as Record<string, unknown>
|
||||
const out: NormalizedField[] = []
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (!v || typeof v !== 'object' || Array.isArray(v)) continue
|
||||
const candidate = { key: k, ...(v as Record<string, unknown>) }
|
||||
const normalized = normalizeFieldMetaItem(candidate)
|
||||
if (normalized && normalized.type !== 'array') out.push(normalized)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function normalizeFieldMetaList(list: unknown): NormalizedField[] {
|
||||
if (!Array.isArray(list)) return []
|
||||
const out: NormalizedField[] = []
|
||||
for (const item of list) {
|
||||
if (item && typeof item === 'object') {
|
||||
const n = normalizeFieldMetaItem(item as Record<string, unknown>)
|
||||
if (n) out.push(n)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function cloneSubjectConfig(src: unknown): Record<string, unknown> {
|
||||
if (src && typeof src === 'object' && !Array.isArray(src)) return JSON.parse(JSON.stringify(src))
|
||||
return {}
|
||||
}
|
||||
|
||||
function cloneValue<T>(value: T): T {
|
||||
if (value === null || value === undefined) return value
|
||||
if (typeof value === 'object') {
|
||||
try { return JSON.parse(JSON.stringify(value)) as T } catch { return value }
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function ensureFieldDefaults(target: Record<string, unknown>, fields: NormalizedField[]) {
|
||||
for (const f of fields) {
|
||||
if (f.type === 'object' && f.itemFields?.length) {
|
||||
const current = target[f.key]
|
||||
const obj = current && typeof current === 'object' && !Array.isArray(current)
|
||||
? { ...(current as Record<string, unknown>) } : ({} as Record<string, unknown>)
|
||||
for (const sub of f.itemFields) {
|
||||
if (!(sub.key in obj)) {
|
||||
if (sub.type === 'boolean') obj[sub.key] = sub.defaultValue === true
|
||||
else if (sub.defaultValue !== undefined) obj[sub.key] = cloneValue(sub.defaultValue)
|
||||
}
|
||||
}
|
||||
target[f.key] = obj
|
||||
continue
|
||||
}
|
||||
if (!(f.key in target)) {
|
||||
if (f.defaultValue !== undefined) target[f.key] = cloneValue(f.defaultValue)
|
||||
else if (f.type === 'boolean') target[f.key] = false
|
||||
else if (f.type === 'array' || f.type === 'string_array') target[f.key] = []
|
||||
else if (f.type === 'object') target[f.key] = f.defaultValue !== undefined ? cloneValue(f.defaultValue) : {}
|
||||
else if (f.type === 'number' || f.type === 'select' || f.type === 'location') { /* 不默认写入 */ }
|
||||
else target[f.key] = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getArrayFieldItems(key: string): unknown[] {
|
||||
const current = subjectConfig[key]
|
||||
if (Array.isArray(current)) return current
|
||||
if (current === undefined || current === null || current === '') {
|
||||
subjectConfig[key] = []
|
||||
return subjectConfig[key] as unknown[]
|
||||
}
|
||||
subjectConfig[key] = [current]
|
||||
return subjectConfig[key] as unknown[]
|
||||
}
|
||||
|
||||
function parseArrayItemText(text: string): unknown {
|
||||
const trimmed = text.trim()
|
||||
if (!trimmed) return ''
|
||||
try { return JSON.parse(trimmed) } catch { return text }
|
||||
}
|
||||
|
||||
function formatArrayItemText(value: unknown): string {
|
||||
if (value === null || value === undefined) return ''
|
||||
if (typeof value === 'string') return value
|
||||
try { return JSON.stringify(value) } catch { return String(value) }
|
||||
}
|
||||
|
||||
function updateArrayFieldItem(key: string, index: number, text: string) {
|
||||
const list = [...getArrayFieldItems(key)]
|
||||
list[index] = parseArrayItemText(text)
|
||||
subjectConfig[key] = list
|
||||
}
|
||||
|
||||
function onArrayItemInput(key: string, index: number, val: string | number) {
|
||||
updateArrayFieldItem(key, index, String(val ?? ''))
|
||||
}
|
||||
|
||||
function addArrayFieldItem(field: NormalizedField) {
|
||||
const list = [...getArrayFieldItems(field.key)]
|
||||
let next: unknown = ''
|
||||
if (field.itemFields && field.itemFields.length) next = buildArrayObjectDefault(field.itemFields)
|
||||
else if (Array.isArray(field.defaultValue) && field.defaultValue.length > 0) next = cloneValue(field.defaultValue[0])
|
||||
list.push(next)
|
||||
subjectConfig[field.key] = list
|
||||
}
|
||||
|
||||
function removeArrayFieldItem(key: string, index: number) {
|
||||
const list = [...getArrayFieldItems(key)]
|
||||
list.splice(index, 1)
|
||||
subjectConfig[key] = list
|
||||
}
|
||||
|
||||
function getStringArrayFieldItems(key: string): string[] {
|
||||
const current = subjectConfig[key]
|
||||
if (Array.isArray(current)) return current.filter((v): v is string => typeof v === 'string' && v.trim() !== '')
|
||||
subjectConfig[key] = []
|
||||
return []
|
||||
}
|
||||
|
||||
function addStringArrayFieldItem(key: string) {
|
||||
const input = (stringArrayInputs[key] || '').trim()
|
||||
if (!input) return
|
||||
const list = [...getStringArrayFieldItems(key)]
|
||||
if (!list.includes(input)) {
|
||||
list.push(input)
|
||||
subjectConfig[key] = list
|
||||
}
|
||||
stringArrayInputs[key] = ''
|
||||
}
|
||||
|
||||
function removeStringArrayFieldItem(key: string, index: number) {
|
||||
const list = [...getStringArrayFieldItems(key)]
|
||||
list.splice(index, 1)
|
||||
subjectConfig[key] = list
|
||||
}
|
||||
|
||||
function buildArrayObjectDefault(itemFields: NormalizedField[]): Record<string, unknown> {
|
||||
const out: Record<string, unknown> = {}
|
||||
for (const f of itemFields) {
|
||||
if (f.defaultValue !== undefined) out[f.key] = cloneValue(f.defaultValue)
|
||||
else if (f.type === 'boolean') out[f.key] = false
|
||||
else if (f.type === 'number') out[f.key] = undefined
|
||||
else out[f.key] = ''
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function getArrayObjectFieldValue(item: unknown, childKey: string): unknown {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) return undefined
|
||||
return (item as Record<string, unknown>)[childKey]
|
||||
}
|
||||
|
||||
function onArrayObjectItemInput(field: NormalizedField, index: number, childKey: string, value: string | number | boolean | null | undefined) {
|
||||
const list = [...getArrayFieldItems(field.key)]
|
||||
const current = list[index]
|
||||
const row: Record<string, unknown> = current && typeof current === 'object' && !Array.isArray(current) ? { ...(current as Record<string, unknown>) } : {}
|
||||
row[childKey] = value
|
||||
list[index] = row
|
||||
subjectConfig[field.key] = list
|
||||
}
|
||||
|
||||
function getObjectFieldValue(fieldKey: string, subKey: string): unknown {
|
||||
const obj = subjectConfig[fieldKey]
|
||||
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return undefined
|
||||
return (obj as Record<string, unknown>)[subKey]
|
||||
}
|
||||
|
||||
function onObjectFieldChange(fieldKey: string, subKey: string, value: unknown) {
|
||||
const current = subjectConfig[fieldKey]
|
||||
const obj: Record<string, unknown> = current && typeof current === 'object' && !Array.isArray(current) ? { ...(current as Record<string, unknown>) } : {}
|
||||
obj[subKey] = value
|
||||
subjectConfig[fieldKey] = obj
|
||||
}
|
||||
|
||||
function locationFieldValue(key: string): number | string | null {
|
||||
const value = subjectConfig[key]
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
return value as number | string
|
||||
}
|
||||
|
||||
function onLocationFieldChange(key: string, value: number | string | null) {
|
||||
subjectConfig[key] = value
|
||||
}
|
||||
|
||||
function applySettingsPayload(settingsRes: SettingWarehouseSettingsPayload | Record<string, unknown>) {
|
||||
const normalized = normalizeGetSettingsPayload(settingsRes as Record<string, unknown>)
|
||||
const wid = normalized.warehouse_id
|
||||
warehouseId.value = typeof wid === 'number' && wid > 0 ? wid : null
|
||||
const cfg = cloneSubjectConfig(normalized.subject_config)
|
||||
Object.keys(subjectConfig).forEach((k) => delete subjectConfig[k])
|
||||
Object.assign(subjectConfig, cfg)
|
||||
ensureFieldDefaults(subjectConfig, displayFields.value)
|
||||
if (warehouseId.value != null) cacheWarehouseId.value = warehouseId.value
|
||||
}
|
||||
|
||||
const pageLoading = ref(false)
|
||||
const saving = ref(false)
|
||||
const loadError = ref('')
|
||||
const warehouseId = ref<number | null>(null)
|
||||
const subjectConfig = reactive<Record<string, unknown>>({})
|
||||
const normalizedFields = ref<NormalizedField[]>([])
|
||||
const useMetaForm = ref(true)
|
||||
const cacheWarehouseId = ref<number | undefined>(undefined)
|
||||
const stringArrayInputs = reactive<Record<string, string>>({})
|
||||
|
||||
const displayFields = computed(() =>
|
||||
useMetaForm.value && normalizedFields.value.length ? normalizedFields.value : FALLBACK_FIELDS
|
||||
)
|
||||
|
||||
async function loadAll() {
|
||||
loadError.value = ''
|
||||
pageLoading.value = true
|
||||
try {
|
||||
const [settingsRes, metaRes] = await Promise.all([
|
||||
settingWarehouseGetSettings(),
|
||||
settingWarehouseGetFieldMeta()
|
||||
])
|
||||
if (!settingsRes || !okCode(settingsRes.code)) {
|
||||
throw new Error(settingsRes?.message || '获取仓库设置失败(getSettings)')
|
||||
}
|
||||
const settingsPayload = normalizeGetSettingsPayload(unwrapSettingWarehousePayload(settingsRes as Record<string, unknown>))
|
||||
applySettingsPayload(settingsPayload)
|
||||
const metaPayload = unwrapSettingWarehousePayload(metaRes as Record<string, unknown>)
|
||||
const metaList = metaRes && okCode(metaRes.code) ? metaPayload.list : null
|
||||
const parsed = normalizeFieldMetaList(metaList)
|
||||
normalizedFields.value = parsed
|
||||
useMetaForm.value = parsed.length > 0
|
||||
ensureFieldDefaults(subjectConfig, displayFields.value)
|
||||
if (metaRes && !okCode(metaRes.code)) {
|
||||
ElMessage.warning(metaRes.message || '字段元信息获取失败,已使用默认表单字段')
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : '加载失败'
|
||||
loadError.value = msg
|
||||
ElMessage.error(msg)
|
||||
} finally {
|
||||
pageLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
const payloadConfig = { ...subjectConfig }
|
||||
saving.value = true
|
||||
try {
|
||||
const body = buildSaveSettingsRequest({ subject_config: payloadConfig, cache_warehouse_id: cacheWarehouseId.value })
|
||||
const res = await settingWarehouseSaveSettings(body)
|
||||
if (!res || !okCode(res.code)) {
|
||||
throw new Error(res?.message || '保存失败')
|
||||
}
|
||||
ElMessage.success(res.message || '保存成功')
|
||||
const savePayload = normalizeSaveSettingsPayload(unwrapSettingWarehousePayload(res as Record<string, unknown>))
|
||||
applySettingsPayload(savePayload)
|
||||
const cleared = savePayload.cache_cleared_warehouse_id
|
||||
if (cleared != null) ElMessage.info(`已清理仓库缓存:${cleared}`)
|
||||
} catch (e: unknown) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
loadAll()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.warehouse-settings-form {
|
||||
padding: 12px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.header-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.sub {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.mb-16 {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.settings-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.settings-form {
|
||||
max-width: 720px;
|
||||
}
|
||||
|
||||
.field-block {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.array-editor {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
max-width: 560px;
|
||||
|
||||
.array-table {
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
|
||||
&__head,
|
||||
&__row {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
min-width: max-content;
|
||||
}
|
||||
|
||||
&__head {
|
||||
background: #f8fafc;
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&__row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
&__cell,
|
||||
&__op {
|
||||
padding: 8px;
|
||||
border-right: 1px solid #ebeef5;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
&__cell {
|
||||
flex: 0 0 140px;
|
||||
min-width: 140px;
|
||||
}
|
||||
|
||||
&__cell:last-child,
|
||||
&__op:last-child {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
&__op {
|
||||
flex: 0 0 72px;
|
||||
min-width: 72px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
:deep(.el-input),
|
||||
:deep(.el-select),
|
||||
:deep(.el-input-number),
|
||||
:deep(.el-color-picker) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
|
||||
.el-button {
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.string-array-editor {
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.tag-input-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.object-editor {
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
&__label {
|
||||
flex: 0 0 120px;
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
&__desc {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.field-control {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.field-color-control {
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.field-desc {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.45;
|
||||
max-width: 520px;
|
||||
|
||||
code {
|
||||
font-size: 11px;
|
||||
padding: 0 4px;
|
||||
background: #f4f4f5;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Loading…
x
Reference in New Issue
Block a user