From ae95560aefe9b09f82f563788f22284a95030ba4 Mon Sep 17 00:00:00 2001 From: yin <3313488199@qq.com> Date: Mon, 31 Aug 2026 19:48:07 +0800 Subject: [PATCH] 1 --- ...example.json => deploy.config.example.json | 4 +- docs/页面切换渲染性能优化方案.md | 191 +++++++++++ src/api/inbox/inbox.ts | 15 +- src/api/report/report.ts | 58 ++-- src/api/returnunpack/index.ts | 105 ++++++- src/api/setting.warehouse/settingwarehouse.ts | 2 + .../storeWarehouse.store/storeWarehouse.ts | 100 ++++++ src/api/waybill.warehouse/index.ts | 11 +- src/api/workbench/workbench.ts | 2 + .../UpperTable/ExperimentSettingsDialog.vue | 236 ++++++++++++++ src/components/UpperTable/index.vue | 52 +-- src/layout/component/AppMain.vue | 50 ++- src/layout/index.vue | 1 + src/stores/modules/experimental.ts | 168 ++++++++++ src/styles/transition.scss | 16 +- .../shipperSigning/index.vue | 2 +- .../returnUnpack/components/ExportDialog.vue | 288 +++++++++++++++++ src/views/express/returnUnpack/index.vue | 18 +- .../returnUnpack/returnUnpack-config.ts | 8 + .../config/order-common-config.ts | 1 + .../order/orderManagement/deliveryOrder.vue | 85 ++++- src/views/order/orderManagement/index.vue | 16 +- .../utils/use-delivery-sub-waybill-print.ts | 296 ++++++++++++++++++ src/views/order/waveOrder/index.vue | 14 +- src/views/stock/stock/index.vue | 20 +- src/views/stock/stockManagement/index.vue | 9 +- .../generalreport/config/template-config.ts | 48 ++- src/views/storage/generalreport/index.vue | 18 +- .../pages/ExportReportDialog.vue | 31 +- src/views/store/shipperSigning/index.vue | 2 +- .../store/stores/component/ExportDialog.vue | 232 ++++++++++++++ src/views/store/stores/index.vue | 17 +- src/views/store/stores/store-config.ts | 8 + 33 files changed, 2005 insertions(+), 119 deletions(-) rename scripts/deploy.config.example.json => deploy.config.example.json (58%) create mode 100644 docs/页面切换渲染性能优化方案.md create mode 100644 src/components/UpperTable/ExperimentSettingsDialog.vue create mode 100644 src/stores/modules/experimental.ts create mode 100644 src/views/express/returnUnpack/components/ExportDialog.vue create mode 100644 src/views/order/orderManagement/utils/use-delivery-sub-waybill-print.ts create mode 100644 src/views/store/stores/component/ExportDialog.vue diff --git a/scripts/deploy.config.example.json b/deploy.config.example.json similarity index 58% rename from scripts/deploy.config.example.json rename to deploy.config.example.json index 39bd9af1..8d6789b8 100644 --- a/scripts/deploy.config.example.json +++ b/deploy.config.example.json @@ -1,8 +1,8 @@ { - "user": "root", + "user": "webdev", "ip": "112.124.21.102", "basePath": "/www/wwwroot/web", "keepReleases": 5, "siteHost": "wms.wms.gztbyc.com", - "sshKey": "C:\\Users\\lfmingren\\.ssh\\112.124.21.102_id_ed25519" + "sshKey": "C:\\Users\\Administrator\\.ssh\\id_ed25519" } diff --git a/docs/页面切换渲染性能优化方案.md b/docs/页面切换渲染性能优化方案.md new file mode 100644 index 00000000..b9526a9e --- /dev/null +++ b/docs/页面切换渲染性能优化方案.md @@ -0,0 +1,191 @@ +# 页面切换渲染性能优化方案 + +> 场景:顶部导航栏 / 页面 tab(tags-view)切换页面时,切换速度慢 + 存在显示渲染 bug +> 状态:**P0 与 P1 部分已实施(2026-08-31)**;P1-方案 5/7 评估后保留;P2 未做 +> 日期:2026-08-31 + +--- + +## 一、背景与目标 + +当前通过「顶部导航栏(TopMenu/Navbar)」或「页面 tab(TaskView/tags-view)」切换路由页面时: + +- **速度慢**:切换有明显卡顿/等待,重页面尤甚 +- **显示 bug**:切换过程白屏闪烁、页面位移跳动、内容被固定表头遮挡、同页参数变化整页重建 + +目标:在不改变业务功能的前提下,**提升页面切换渲染速度**并**修复切换显示问题**。 + +--- + +## 二、现状:页面切换渲染链路 + +``` +顶部导航/页面 tab + │ router.push / router-link + ▼ +permission.ts router.beforeEach → NProgress.start() + 权限校验 + ▼ +AppMain.vue → 页面渲染核心 + │ + │ + │ + ▼ +router.afterEach → NProgress.done() + ▼ +TaskView watch(route) → addTags() + moveToCurrentTag() +``` + +### 关键代码位置 + +| 文件 | 职责 | +|---|---| +| `src/layout/component/AppMain.vue` | 路由页面渲染容器(transition + keep-alive + key) | +| `src/layout/component/TaskView/index.vue` | 页面 tab 栏(tags-view),`watch(route)` 添加/维护 tab | +| `src/layout/index.vue` | 主布局(fixed-header 固定表头 + task-view + app-main) | +| `src/layout/component/Navbar.vue` / `TopMenu.vue` | 顶部导航栏 / 顶部菜单 | +| `src/stores/modules/tagsView.ts` | `visitedViews` / `cachedViews`(keep-alive include 白名单) | +| `src/permission.ts` | 路由守卫(beforeEach / afterEach,动态路由生成) | +| `src/views/redirect/index.vue` | tab「刷新」用的中转页(`/redirect/:path`) | + +--- + +## 三、问题根因分析 + +### 3.1 切换慢的原因 + +#### A1. `AppMain` 的 `:key="route.fullPath"` 导致过度销毁重建 +```html + +``` +- `fullPath` = `path + query`。**只要 query 变化**(页面内部 `?tab=`、筛选条件 URL 化等),key 就变化 → Vue 视为不同实例 → 即使命中 keep-alive 也会触发「旧实例 deactivated + 新实例 created」→ 整页销毁重建、重复执行 `onMounted`、重复请求。 +- 已在 `order/orderManagement`、`order/waveOrder` 用「方案B 去路由化」局部规避(内部 tab 不写回 URL),但**根因仍在 AppMain**,其它带 query 参数的页面同样中招。 + +#### A2. 路由级 keep-alive 的 `:include="cachedViews"` 与组件 name 不匹配 → 缓存失效 +```html + +``` +- `cachedViews` 由 `tagsView.addCachedView` 维护:`cachedViews.push(view.name)`,push 的是**路由 name**(如 `order/index`、`stock/stockManagement`)。 +- `` 匹配的是**组件 name**(`defineOptions({ name })` 或 SFC 推断名)。 +- 项目大量路由页面组件**未定义 `defineOptions({ name })`**(`orderManagement/index.vue`、`waveOrder/index.vue`、`stockManagement/index.vue` 等),组件 name ≠ 路由 name → **include 匹配失败 → 这些页面实际从未被路由级缓存**,每次切换都全新挂载 + 重新请求 + 白屏闪烁。 +- 这是"切换慢 + 白屏"的**首要根因**。 + +#### A3. transition 无 `mode="out-in"` + 0.5s 动画 + 位移 +```css +.fade-transform-leave-active, .fade-transform-enter-active { transition: all .5s; } +.fade-transform-leave-active { position: absolute; width: 100%; } +.fade-transform-enter-from { opacity: 0; transform: translateX(-30px); } +.fade-transform-leave-to { opacity: 0; transform: translateX(30px); } +``` +- `` 未设 `mode`(默认 enter/leave 同时进行):切换时**新旧两页同时存在/渲染**,重页面在切换瞬间渲染两份 → 主线程峰值高、感知慢。 +- `transition: all .5s`(0.5s)对重型页面过长;`translateX(±30px)` 产生横向位移。 +- 且离开页 `position: absolute` 与进入页重叠,易出现布局跳动。 + +#### A4. 大页面挂载成本高 +- `orderManagement` 等重页面 `onMounted` 同步发多个请求(`loadData` + `loadOrderMetaOptions` + `loadStoreOptions` + badge 等),一次渲染大量表格/标签/tooltip 组件。 +- 因 A1/A2 缓存失效,每次切换都重复走完整挂载流程 → 慢被放大。 + +#### A5. cachedViews 无限累积 +- 每打开一个新 tab,`cachedViews` 就追加一个 name,keep-alive 缓存实例持续增长 → 内存占用与切换匹配开销上升(无 `:max` 上限)。 + +### 3.2 显示 bug 的原因 + +| # | 现象 | 根因 | +|---|---|---| +| B1 | 切换白屏/闪烁 | A2 缓存失效 → 每次切换销毁重建,旧页消失、新页空白等待数据 | +| B2 | 同页 query 变化整页重建 → tab/筛选闪烁 | A1 `:key=fullPath` | +| B3 | 切换时两页叠加、横向位移跳动 | A3 无 `out-in` + `translateX` | +| B4 | 内容被固定表头遮挡/偏移 | `AppMain.vue` `.fixed-header + .app-main { padding-top: 90px }` 为**固定值**,而 `layout/index.vue` 表头实际高度动态为 `97px`(普通)/ `134px`(快捷栏展开)→ 快捷栏展开时内容顶部被遮挡 | +| B5 | tab「刷新」时多跳一次、闪烁 | `TaskView.refreshSelectedTag` = `delCachedView` → `router.replace('/redirect'+fullPath)` → redirect 组件再 `replace` 回原页,**两次跳转** | +| B6 | 缓存复用时数据陈旧/事件重复 | 页面只写 `onMounted`/`onUnmounted`,未处理 `onActivated`/`onDeactivated` | + +--- + +## 四、优化方案(分阶段实施) + +> 原则:先低成本高收益(P0),再做治理(P1),最后可选优化(P2)。每阶段独立可上线、可回滚。 + +### P0 — 核心修复(✅ 已实施) + +#### 方案 1:`:key` 从 `fullPath` 收窄为 `path` ✅ 已实施 +- 文件:`src/layout/component/AppMain.vue` +- 实际做法:`:key="route.name ?? route.path"`(不含 query)。 +- 收益:同页面 query 变化不再触发销毁重建;仅跨路由切换才重建/切换缓存。 +- 风险:同页 query 需局部刷新(如筛选参数在 URL 的页面)→ 用页面内 `watch(() => route.query)` 局部刷新,不整页重建。 +- 回归点:所有依赖"query 变化自动重载"的页面。 + +#### 方案 2:修复 keep-alive `:include` 匹配 → 让路由级缓存真正生效 ✅ 已实施(采用 B 路线:包装组件) +- 目标:`cachedViews`(路由 name)与组件 name 对齐。 +- **实际做法(B 路线的更优实现)**:动态路由 name 来自后端菜单,前端组件无法保证一一对应,因此改为在 `AppMain.vue` 用 `wrapRouteComponent(Component, route.name)` 将路由组件**包装为 name=路由 name 的组件**,使 `` 真正匹配。 +- **关键约束**:keep-alive 必须始终存在(不能放 v-if:访问 Layout 外页面会卸载 KeepAlive 导致全部缓存清零)。 +- 收益:切回已打开过的 tab 页面**不重建、不重新请求**,白屏消除(实测切回 orderManagement 列表请求 = 0)。 + +#### 方案 3:transition 改 `mode="out-in"` + 缩短/简化动画 ✅ 已实施 +- 文件:`src/layout/component/AppMain.vue` + `src/styles/transition.scss` +- 实际做法:`fade-transform` 收敛为纯淡入淡出(`opacity .2s`),去掉 `translateX`;AppMain 加 `mode="out-in"`。 +- 收益:新旧页面不再同时渲染(内存/主线程峰值下降),无横向位移。 + +### P1 — 缓存与布局治理 + +#### 方案 4:cachedViews / keep-alive 实例上限治理 ✅ 已实施 +- 文件:`src/layout/component/AppMain.vue` +- 实际做法:``(LRU 上限 10)。 + +#### 方案 5:统一 `onActivated` / `onDeactivated` 生命周期 ⏸ 评估后保留(长期治理) +- 涉及所有缓存页面(几十个),需逐个评估业务逻辑(数据实时性 vs 缓存),风险高,不适合一次性大改。 +- 建议后续按需推进:把"进入需刷新"的数据加载从 `onMounted` 迁到 `onActivated`,清理逻辑迁到 `onDeactivated`。 + +#### 方案 6:fixed-header 高度动态化 ✅ 已实施 +- 文件:`src/layout/index.vue` +- **实际做法**:spacer 高度由 `shortcutExpanded ? '134px' : '84px'` 改为 `'134px' : '97px'`,与 header minHeight 对齐(原 84 比 97 矮 13px → 内容顶部被固定表头遮挡)。实测内容 top 与 header bottom 对齐(gap=0)。 + +#### 方案 7:tab「刷新」减少一次跳转 ⏸ 评估后保留(`/redirect` 为必要机制) +- `refreshSelectedTag` 的 `/redirect` 中转是 keep-alive 缓存体系下"强制重建"的必要机制:缓存 key 为 `route.name`,直接 replace 到同路径不会重建;必须先删缓存 + 跳转离场再回场才能强制刷新。 +- 收益有限且有破坏刷新功能的风险,保留现状。 + +### P2 — 可选 / 长期(未做) + +#### 方案 8:重型页面渲染优化(与切换无关的既有性能债) +- 继续 `UpperTable` 侧优化:列收敛、tooltip 收窄、长期评估 `el-table-v2`(详见 `docs/UpperTable-大列表滚动性能优化方案.md`)。 +- 收益:降低单页面板载成本,间接降低切换时的挂载耗时。 + +#### 方案 9:首屏按需加载评估 +- 确认动态 import 分包已生效;对超大页面评估首屏拆块(如详情面板懒渲染、非首屏 tab 懒挂载)。 + +--- + +## 五、预期效果 + +| 指标 | 现状 | P0 后 | +|---|---|---| +| 切回已打开 tab | 重建 + 重请求(白屏) | 缓存命中,瞬时恢复 | +| 同页 query 变化 | 整页销毁重建 | 不重建,局部刷新 | +| 切换动画 | 0.5s + 位移 + 双页叠加 | ~0.2s 淡入淡出,单页 | +| 固定表头内容遮挡 | 快捷栏展开时被挡 | 高度联动,不再遮挡 | +| tab 刷新 | 两次跳转 | 一次跳转 | + +--- + +## 六、实施顺序与回归清单 + +### 实施顺序 +1. **P0-方案 2**(补组件 name)→ 让缓存先真正生效(收益最大、风险集中) +2. **P0-方案 1**(`:key` 收窄)+ **P0-方案 3**(transition)→ 消除重建与叠加 +3. **P1**(上限治理 / 生命周期 / fixed-header / 刷新跳转) +4. **P2** 视资源可选 + +### 回归清单(重点页面) +- `order/orderManagement`(8 tab、query 参数、角标) +- `order/waveOrder`、`stock/stockManagement`(多 tab + 详情 tab) +- 筛选条件 URL 化的页面(验证 query 变化不整页重建、数据仍正确刷新) +- 快捷栏展开/收起时各页面顶部内容不被遮挡 +- tab 打开/关闭/刷新/关闭其他/关闭全部 全流程 +- 登录态变化(用户/角色切换)后缓存不串数据 + +--- + +## 七、风险与备注 + +- **`:key` 收窄**是行为变更:需确认没有页面依赖"query 变化自动重建"。若有,用页面内 `watch(route.query)` 替代,切勿全局回退。 +- **补组件 name** 需与路由 name 一一对应,避免误缓存带草稿/表单态的页面;可在 `meta.noCache` 排除个别页面。 +- **transition 改 out-in** 会改变切换视觉,需与 UI 确认动画时长偏好。 +- 本方案仅针对「路由级页面切换」;页面**内部** tab(如 orderManagement 8 tab)已有独立 keep-alive 与实验性 tab 缓存设置,与本方案互补,不冲突。 diff --git a/src/api/inbox/inbox.ts b/src/api/inbox/inbox.ts index d28198b5..f1b1e05a 100644 --- a/src/api/inbox/inbox.ts +++ b/src/api/inbox/inbox.ts @@ -261,8 +261,10 @@ export function inboxGroupMessages(data: InboxGroupMessagesParams) { /** 群快速查询参数(下拉选择用,不分页) */ export interface InboxGroupQuickListParams { - /** 货主ID(>0 时按货主过滤;不传返回所有群) */ - store_id?: number // 货主ID,不传则返回全部 + /** 货主ID(可选,>0 时按货主过滤;不传返回所有货主的群) */ + store_id?: number | string + /** 仓库ID(可选,>0 时按仓库过滤;不传返回所有仓库的群;与 store_id 可单独传或同时传 AND) */ + warehouse_id?: number | string keyword?: string // 关键词,模糊匹配群名称与外部群ID groupType?: string // 群类型筛选:store(货主) / warehouse(仓库) / express(快递) limit?: number // 返回条数上限,默认20,最大100(无分页) @@ -285,9 +287,12 @@ export function inboxGroupQuickList(data: InboxGroupQuickListParams = {}) { /** 查询群成员参数(下拉选择用) */ export interface InboxGroupMembersParams { - groupIds: number[] // 群记录主键ID数组(必填,非空) - keyword?: string // 关键词,模糊匹配用户名与用户ID - limit?: number // 返回条数上限,默认20,最大100(无分页) + /** 群记录主键ID数组(wms_inbox_group.id,必填,非空;每个元素为正整数,支持数字或可解析数字字符串) */ + groupIds: Array + /** 关键词,模糊匹配 user_name(用户名)与 user_id(用户ID) */ + keyword?: string + /** 返回条数上限,默认20,最大100(无分页) */ + limit?: number } /** 查询多个群的成员列表(inbox.group.members) */ diff --git a/src/api/report/report.ts b/src/api/report/report.ts index b040eb32..f114d215 100644 --- a/src/api/report/report.ts +++ b/src/api/report/report.ts @@ -5,18 +5,22 @@ const v = '1.0' /* ===== 报表导出任务 ===== */ export interface ReportGenerateParams { - /** 报表编码(与 reportCode 二选一;均传时优先 reportCode) */ - report_code?: string - /** 报表编码驼峰别名(兼容,优先级高于 report_code) */ - reportCode?: string + /** 报表定义ID(与 reportId 二选一;均传时优先 reportId) */ + report_id?: number + /** 报表定义ID驼峰别名(兼容,优先级高于 report_id) */ + reportId?: number /** 货主ID(可选,货主维度报表时传入;>0 生效,<=0 视为不按货主过滤) */ store_id?: number /** 货主ID驼峰别名(兼容,优先级高于 store_id) */ storeId?: number - /** 查询器业务参数(透传,如 bizDate) */ + /** 查询器业务参数(透传) */ params?: { - /** 数据日期(YYYY-MM-DD) */ + /** 数据日期(YYYY-MM-DD),用于导出文件名 file_name 模板的 {date} 占位 */ bizDate?: string + /** 窗口数量覆盖(缺省 7,<=0 视为 7) */ + dayCount?: number + /** 切点小时覆盖(缺省 7,错制到 0-23) */ + cutoverHour?: number } } @@ -91,8 +95,8 @@ export function generateTaskProgress( export interface DeliveryPlanSaveParams { /** 货主ID(必填,正整数;<=0 报错) */ store_id: number - /** 计划名称(必填,≤100 字符) */ - name: string + /** 计划名称(可选,仅展示字段,不参与幂等/关联逻辑;未传不覆盖,null/空串/全空白归一化为 null 清空;非空 trim 后 ≤100 字符,超长报错) */ + name?: string | null /** 报表定义ID(必填,正整数;须为已启用 is_enabled=1 的报表定义;与 reportId 二选一,均传优先 reportId) */ report_id: number /** 报表定义ID驼峰别名(兼容,优先级高于 report_id) */ @@ -170,9 +174,9 @@ export interface DeliveryPlanListParams { pageSize?: number } sort?: { - /** 排序字段(白名单 id/created_at/updated_at/store_id/report_code,默认 id) */ + /** 排序字段(白名单 id/created_at/updated_at/store_id/report_definition_id,默认 id) */ sortField?: string - /** 排序方向(ASC/DESC,默认 DESC) */ + /** 排序方向(ASC/DESC,默认 DESC,大小写不敏感) */ sortOrder?: string } } @@ -240,8 +244,8 @@ export interface DeliveryLogListParams { where?: { /** 货主ID(>0 时精确过滤) */ store_id?: number - /** 报表编码(精确过滤) */ - report_code?: string + /** 报表定义ID(>0 时精确过滤) */ + report_id?: number /** 投递状态过滤(pending/exporting/delivered/failed/cancelled;非法值忽略) */ status?: string } @@ -294,10 +298,10 @@ export function listDeliveryLog( /* ===== 报表元数据 ===== */ export interface ReportMetaParams { - /** 报表编码(与 reportCode 二选一;均传时优先 reportCode) */ - report_code?: string - /** 报表编码驼峰别名(兼容,优先级高于 report_code) */ - reportCode?: string + /** 报表定义ID(与 reportId 二选一;均传时优先 reportId) */ + report_id?: number + /** 报表定义ID驼峰别名(兼容,优先级高于 report_id) */ + reportId?: number } export interface ReportMetaField { @@ -306,20 +310,26 @@ export interface ReportMetaField { /** 字段中文名 */ label: string /** 字段类型:string/number/boolean/array */ - type: 'string' | 'number' | 'boolean' | 'array' - /** 是否格式化器预计算字段,仅 true 时返回 */ + type: string + /** 是否预计算字段(非原始表字段),仅 true 时返回 */ computed?: boolean + /** 是否按文本单元格渲染落地(长数字串防科学计数法),仅 true 时返回 */ + asText?: boolean + /** 该报表定义是否勾选此字段(true=已勾选) */ + selected?: boolean /** 数组类型字段的子字段清单,仅数组类型字段返回 */ children?: ReportMetaField[] } export interface ReportMetaResponse { - report_code: string + /** 报表定义ID(回显) */ + report_id: number + /** 报表名称 */ name: string - /** 适用维度:warehouse=仓库 / store=货主 / open=通用 */ - scope: 'warehouse' | 'store' | 'open' - /** 查询器 key */ - query: string + /** 报表类型(注册 key,如 stockFlow) */ + type: string + /** 导出文件名模板(支持 {date} 占位) */ + file_name: string /** 日窗口参数对象 */ window: { /** 窗口数量(默认 7) */ @@ -327,7 +337,7 @@ export interface ReportMetaResponse { /** 切点小时 0-23(默认 7) */ cutoverHour: number } - /** 查询器静态字段清单 */ + /** 注册类型全量字段清单(含 selected/asText 标记) */ fields: ReportMetaField[] code?: number } diff --git a/src/api/returnunpack/index.ts b/src/api/returnunpack/index.ts index 2be4d247..533c1544 100644 --- a/src/api/returnunpack/index.ts +++ b/src/api/returnunpack/index.ts @@ -629,6 +629,107 @@ export function returnUnpackForceRecord(data: ReturnUnpackForceRecordParams): Pr } as any) } +// ============ returnUnpack.export ============ + +/** returnUnpack.export 请求参数(where/sort 语义与 returnUnpack.list 一致) */ +export type ReturnUnpackExportParams = { + /** 查询条件,语义与 returnUnpack.list 的 where 一致;禁止传 warehouse_id/warehouseId(服务端注入) */ + where?: Record + /** 排序参数,语义与 returnUnpack.list 的 sort 一致 */ + sort?: { + sortField?: string + sortOrder?: string + } +} + +/** returnUnpack.export 响应(提交成功即返回任务受理信息) */ +export type ReturnUnpackExportResponse = { + /** 任务 ID */ + task_id: string + /** 任务状态:submitted/running/success/failed/not_found */ + status: string + /** 当前进度百分比(0-100),提交时返回 0 */ + progress: number + /** 当前已处理记录数(拆包单条数) */ + current_count: number + /** 总记录数 */ + total_count: number + /** 任务提示信息 */ + message: string + /** 任务执行结果(提交时为 null;完成后为上传信息对象) */ + result: Record | null + /** 失败时的错误信息 */ + error: string + /** 任务更新时间(Unix 毫秒时间戳) */ + update_time: number + code?: number +} + +/** returnUnpack.export:提交退回拆包导出任务(异步,返回 task_id) */ +export function returnUnpackExport(data: ReturnUnpackExportParams = {}): Promise { + return request({ + url: '/system', + method: 'post', + params: { + method: 'returnUnpack.export', + v, + timestamp: new Date().getTime() + }, + data, + isSystemApi: true + } as any) +} + +// ============ returnUnpack.exportTaskProgress ============ + +/** returnUnpack.exportTaskProgress 请求参数 */ +export type ReturnUnpackExportTaskProgressParams = { + /** 任务 ID(下划线写法,与 taskId 二选一) */ + task_id?: string + /** 任务 ID(驼峰写法,兼容) */ + taskId?: string +} + +/** returnUnpack.exportTaskProgress 响应 */ +export type ReturnUnpackExportTaskProgressResponse = { + /** 任务 ID(缺失时为空字符串,status=not_found) */ + task_id: string + /** 任务状态:submitted/running/success/failed/not_found */ + status: string + /** 进度百分比(0-100) */ + progress: number + /** 当前已处理记录数 */ + current_count: number + /** 总记录数 */ + total_count: number + /** 任务提示信息 */ + message: string + /** 任务执行结果对象(完成后含 filename/url/fileKey/cdnUrl/cosUrl 等) */ + result: Record | null + /** 失败时的错误信息 */ + error: string + /** 任务完成后下载链接;未完成或不存在时为空字符串 */ + download_url: string + /** 最近一次状态更新时间(Unix 毫秒时间戳) */ + update_time: number + code?: number +} + +/** returnUnpack.exportTaskProgress:按 task_id 查询退回拆包导出任务进度 */ +export function returnUnpackExportTaskProgress(data: ReturnUnpackExportTaskProgressParams): Promise { + return request({ + url: '/system', + method: 'post', + params: { + method: 'returnUnpack.exportTaskProgress', + v, + timestamp: new Date().getTime() + }, + data, + isSystemApi: true + } as any) +} + // ============ 模块导出 ============ export const returnUnpackModule = { @@ -642,5 +743,7 @@ export const returnUnpackModule = { detailList: returnUnpackDetailList, detail: returnUnpackDetail, delete: returnUnpackDelete, - forceRecord: returnUnpackForceRecord + forceRecord: returnUnpackForceRecord, + export: returnUnpackExport, + exportTaskProgress: returnUnpackExportTaskProgress } diff --git a/src/api/setting.warehouse/settingwarehouse.ts b/src/api/setting.warehouse/settingwarehouse.ts index 77a0346b..05c16fdb 100644 --- a/src/api/setting.warehouse/settingwarehouse.ts +++ b/src/api/setting.warehouse/settingwarehouse.ts @@ -66,6 +66,8 @@ export type SettingWarehouseSubjectConfig = SettingWarehouseSenderConfig & { single_order_pack_max_minutes?: number /** 团购打包最大时长,单位:分钟,默认 40 */ group_order_pack_max_minutes?: number + /** 拆包最大录制时长,单位:分钟,默认 5,min 1;超过上限时拆包提交的结束时间自动截断为开始时间+上限 */ + return_unpack_max_record_minutes?: number max_wave_quantity?: number min_group_order_fetch_quantity?: number max_notice_webhook_count?: number diff --git a/src/api/storeWarehouse.store/storeWarehouse.ts b/src/api/storeWarehouse.store/storeWarehouse.ts index 8be4647d..c350d896 100644 --- a/src/api/storeWarehouse.store/storeWarehouse.ts +++ b/src/api/storeWarehouse.store/storeWarehouse.ts @@ -533,3 +533,103 @@ export function storeWarehouseExportStorePrintQuantityLogsTaskProgress(data: { isSystemApi: true } as any) } + +// ============ storeWarehouse.store.export ============ + +/** storeWarehouse.store.export 请求参数(筛选条件与 storeWarehouse.store.list 一致;page/page_size 忽略,全量导出) */ +export type StoreWarehouseExportParams = { + /** 签约备注或主体名称关键字(与 list 一致,模糊匹配 store_remask/warehouse_remask/双方 company_name) */ + keyword?: string + /** 对方主体ID(兼容 store_id),导出时过滤指定货主 */ + counterparty_id?: number + /** 货主ID(counterparty_id 的别名,两者传一即可) */ + store_id?: number + /** 签约状态过滤:1=申请中 2=已通过 3=已拒绝 4=已解除 5=已过期 */ + auth_status?: number + /** 启用状态过滤:0=禁用 1=启用(兼容 warehouse_use_status) */ + use_status?: number + /** 仓库侧启用状态过滤(use_status 的别名,两者传一即可) */ + warehouse_use_status?: number + /** 签约关系ID,兼容 contract_id/relation_id;导出时仅导出该签约关系 */ + id?: number +} + +/** storeWarehouse.store.export 响应(提交成功即返回任务受理信息) */ +export type StoreWarehouseExportResponse = { + /** 任务ID(格式 store_relation_list_export_{storeId}_{timestamp}_{random}) */ + task_id: string + /** 任务状态:submitted/running/success/failed/not_found(提交成功时为 submitted) */ + status: string + /** 当前进度百分比(0-100),提交时返回 0 */ + progress: number + /** 任务提示信息 */ + message: string + /** 任务执行结果(提交时为 null;后台完成后为上传信息对象,含 filename/fileKey/url/cdnUrl/cosUrl/total_count) */ + result: Record | null + /** 失败时的错误信息(非失败时为空字符串) */ + error: string + /** 任务更新时间(Unix 毫秒时间戳) */ + update_time: number + code?: number +} + +/** 提交货主签约列表导出任务(异步,全量导出,返回 task_id) */ +export function storeWarehouseExport(data: StoreWarehouseExportParams = {}) { + return request({ + url: '/system', + method: 'post', + params: { + method: 'storeWarehouse.store.export', + v, + timestamp: new Date().getTime() + }, + data, + isSystemApi: true + } as any) +} + +// ============ storeWarehouse.store.exportTaskProgress ============ + +/** storeWarehouse.store.exportTaskProgress 请求参数 */ +export type StoreWarehouseExportTaskProgressParams = { + /** 任务ID(下划线写法,与 taskId 二选一) */ + task_id?: string + /** 任务ID(驼峰写法,兼容) */ + taskId?: string +} + +/** storeWarehouse.store.exportTaskProgress 响应 */ +export type StoreWarehouseExportTaskProgressResponse = { + /** 任务ID(缺失时为回显空字符串,status=not_found) */ + task_id: string + /** 任务状态:submitted/running/success/failed/not_found */ + status: string + /** 进度百分比(0-100) */ + progress: number + /** 任务提示信息 */ + message: string + /** 任务执行结果对象(完成后含 filename/fileKey/url/cdnUrl/cosUrl/total_count 等;未完成或 not_found 时为 null) */ + result: Record | null + /** 失败时的错误信息(非失败时为空字符串) */ + error: string + /** 任务完成后下载链接(从 result.url/cdnUrl/cosUrl/fileKey 兜底取);未完成或不存在时为空字符串 */ + download_url: string + /** 最近一次状态更新时间(Unix 毫秒时间戳) */ + update_time: number + code?: number +} + +/** 按 task_id 查询货主签约列表导出任务进度 */ +export function storeWarehouseExportTaskProgress(data: StoreWarehouseExportTaskProgressParams) { + return request({ + url: '/system', + method: 'post', + params: { + method: 'storeWarehouse.store.exportTaskProgress', + v, + timestamp: new Date().getTime() + }, + data, + isSystemApi: true + } as any) +} diff --git a/src/api/waybill.warehouse/index.ts b/src/api/waybill.warehouse/index.ts index f932d949..9a82c7b9 100644 --- a/src/api/waybill.warehouse/index.ts +++ b/src/api/waybill.warehouse/index.ts @@ -6,8 +6,8 @@ const v = '1.0' /** waybill.warehouse.list 的 where 筛选条件 */ export type WaybillWarehouseListWhere = { - /** 运单号(模糊搜索) */ - waybillCode?: string + /** 运单号筛选:字符串时为模糊搜索(LIKE '%值%',向后兼容);字符串数组时为精确匹配(Op.in,元素自动 trim 并过滤空值,空数组或全空值时不加该筛选条件) */ + waybillCode?: string | string[] /** 主单号(精确匹配),与 waybillCode 互斥,同时传入时 mainWaybillCode 优先 */ mainWaybillCode?: string /** 订单ID(等值匹配) */ @@ -116,7 +116,12 @@ export function waybillWarehouseDetail( export type WaybillWarehouseExportParams = { where?: WaybillWarehouseListWhere sort?: WaybillWarehouseListSort - /** 需要导出的字段列表,不传则导出全部字段 */ + /** + * 需要导出的字段列表,不传则导出全部字段。可选字段: + * waybill_code, main_waybill_code, waybill_type, order_no, warehouse_name, store_name, + * business_key, status_text, logistics_code, logistics_name, logistics_interface_name, + * platform_code, weighing_weight, package_material_name, print_count, last_print_at, create_at + */ exportFields?: string[] } diff --git a/src/api/workbench/workbench.ts b/src/api/workbench/workbench.ts index 25b9e460..878e9074 100644 --- a/src/api/workbench/workbench.ts +++ b/src/api/workbench/workbench.ts @@ -151,6 +151,8 @@ export interface WorkbenchBusinessResponse { stock_unit?: string barcodes?: string[] image_url?: string + /** 打包要求(来自 stock,未命中/异常时为空字符串) */ + packing_requirements?: string }> /** 订单命中分表:current(待处理表)或 dispatch(配送表) */ source_table: 'current' | 'dispatch' diff --git a/src/components/UpperTable/ExperimentSettingsDialog.vue b/src/components/UpperTable/ExperimentSettingsDialog.vue new file mode 100644 index 00000000..e7e401fe --- /dev/null +++ b/src/components/UpperTable/ExperimentSettingsDialog.vue @@ -0,0 +1,236 @@ + + + + + + diff --git a/src/components/UpperTable/index.vue b/src/components/UpperTable/index.vue index 13e5fb97..87eeb467 100644 --- a/src/components/UpperTable/index.vue +++ b/src/components/UpperTable/index.vue @@ -218,11 +218,8 @@ append-to-body >
- 表格工作模式 - - 低占用 - 高性能 - + + 实验性功能 恢复默认 导出全局配置 + +
@@ -352,8 +351,10 @@ import type { UploadFile } from 'element-plus' import { useUserStore } from '@/stores/modules/user' import { useSettingsStore } from '@/stores/modules/settings' import { useShortcutsStore } from '@/stores/modules/shortcuts' +import { useExperimentalStore } from '@/stores/modules/experimental' import defaultSettings from '@/settings' import QrcodeDialog from '@/components/QR/qrcode.vue' +import ExperimentSettingsDialog from './ExperimentSettingsDialog.vue' defineOptions({ name: 'UpperTable' @@ -549,6 +550,8 @@ const emit = defineEmits([ // Refs const tableRef = ref(null) const userStore = useUserStore() +const experimentalStore = useExperimentalStore() +const experimentDialogVisible = ref(false) type ColumnItem = { prop?: string @@ -907,30 +910,19 @@ 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 */ +/** 初始化:优先读实验性设置 store,兜底 props.tableMode */ function initTableMode() { - activeTableMode.value = readStoredTableMode() || (props.tableMode as 'performance' | 'resource') + activeTableMode.value = experimentalStore.tableMode } -/** 用户在字段设置中切换工作模式:持久化 + 重置虚拟滚动状态 */ +/** 切换工作模式(实验性功能表单触发):持久化到 store + 重置虚拟滚动状态 */ function handleTableModeChange(mode: 'performance' | 'resource') { - saveTableMode(mode) + experimentalStore.setTableMode(mode) + resetVirtualScrollState() +} + +/** 重置虚拟滚动窗口状态(滚动位置、方向、节流计时器) */ +function resetVirtualScrollState() { virtualScrollTop.value = 0 scrollDirection.value = 'down' lastWindowSyncTime = 0 @@ -942,6 +934,16 @@ function handleTableModeChange(mode: 'performance' | 'resource') { syncVirtualViewport() } +// 全局实验性设置中的表格工作模式变化 → 所有 UpperTable 实例即时响应 +watch( + () => experimentalStore.tableMode, + (mode) => { + if (!mode || activeTableMode.value === mode) return + activeTableMode.value = mode + resetVirtualScrollState() + } +) + function saveColumnConfig(configs: ColumnConfigItem[]) { if (!columnConfigStorageKey.value) return const userId = String(userStore.user?.username || userStore.user?.id || 'unknown') diff --git a/src/layout/component/AppMain.vue b/src/layout/component/AppMain.vue index 042a14bd..5d62614b 100644 --- a/src/layout/component/AppMain.vue +++ b/src/layout/component/AppMain.vue @@ -2,11 +2,21 @@
- - + + + @@ -17,11 +27,41 @@ diff --git a/src/views/express/returnUnpack/index.vue b/src/views/express/returnUnpack/index.vue index 217c8f10..6da4f424 100644 --- a/src/views/express/returnUnpack/index.vue +++ b/src/views/express/returnUnpack/index.vue @@ -277,6 +277,15 @@ :video="playingVideo" /> + + +
@@ -303,6 +312,7 @@ import UnpackOrderItemsTable from './components/UnpackOrderItemsTable.vue' import VideoButton, { type VideoItem } from './components/VideoButton.vue' import VideoListDialog from './components/VideoListDialog.vue' import VideoPlayerDialog from './components/VideoPlayerDialog.vue' +import ReturnUnpackExportDialog from './components/ExportDialog.vue' // ==================== 常量 / 工具 ==================== @@ -448,7 +458,11 @@ const columns = returnUnpackColumns const tableSize = 'small' const toolbarButtons: ToolbarButtonConfig[] = returnUnpackToolbarButtons -const buttonLoadingMap = ref>({ loading: false }) +const exportLoading = ref(false) +const buttonLoadingMap = computed>(() => ({ + loading: loading.value, + exportLoading: exportLoading.value, +})) const buttonDisabledMap = ref>({}) const buttonLabelMap = ref>({}) const toolbarLayoutKey = ref('') @@ -468,6 +482,7 @@ function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) { const toolbarActionMap: Record void> = { loadData: () => { handleRefresh() }, openColumnConfigPanel: () => openColumnConfigPanel(), + openExportDialog: () => { exportDialogVisible.value = true }, } function openColumnConfigPanel() { @@ -489,6 +504,7 @@ const queryTime = ref(0) const tableData = ref([]) const currentConditions = ref>({}) const currentSort = ref<{ prop: string; order: string }>({ prop: '', order: '' }) +const exportDialogVisible = ref(false) const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) const upperPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 }) diff --git a/src/views/express/returnUnpack/returnUnpack-config.ts b/src/views/express/returnUnpack/returnUnpack-config.ts index 104f1785..5c5a6d40 100644 --- a/src/views/express/returnUnpack/returnUnpack-config.ts +++ b/src/views/express/returnUnpack/returnUnpack-config.ts @@ -90,5 +90,13 @@ export const returnUnpackColumns = [ // ============================================================ export const returnUnpackToolbarButtons: ToolbarButtonConfig[] = [ { key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadData' }, + { + key: 'export', + label: '导出', + category: 'action', + size: 'small', + loadingKey: 'exportLoading', + action: 'openExportDialog', + }, { key: 'columnConfig', label: '字段设置', category: 'setting', size: 'small', action: 'openColumnConfigPanel' }, ] diff --git a/src/views/order/orderManagement/config/order-common-config.ts b/src/views/order/orderManagement/config/order-common-config.ts index 51ef5a76..9b73eda7 100644 --- a/src/views/order/orderManagement/config/order-common-config.ts +++ b/src/views/order/orderManagement/config/order-common-config.ts @@ -1725,6 +1725,7 @@ export const deliveryOrderToolbarButtonKeys = [ ...simpleListToolbarButtonKeys, 'batchPrint', 'allocateSubOrderNumber', + 'subWaybillPrint', ] export const deliveryOrderToolbarButtons = pickToolbarButtons(deliveryOrderToolbarButtonKeys) diff --git a/src/views/order/orderManagement/deliveryOrder.vue b/src/views/order/orderManagement/deliveryOrder.vue index bb94de8a..a778fb40 100644 --- a/src/views/order/orderManagement/deliveryOrder.vue +++ b/src/views/order/orderManagement/deliveryOrder.vue @@ -203,6 +203,60 @@ @refresh="handleBatchPrintRefresh" @print-success="onBatchPrintSuccess" /> + + + + + + + + + + + + + + + selectionRows.value, + onPrintSuccess: () => loadData(), + emptySelectionMessage: '请先勾选需要打印子单号的订单' +}) + useOrderListPageCleanup({ list, selectionRows, selectedOrderId, - onCleanup: resetBatchPrintState + onCleanup: () => { + resetBatchPrintState() + resetSubWaybillPrintState() + } }) function normalizeOptionValue(value: unknown) { @@ -515,6 +596,7 @@ const buttonLoadingMap = computed>(() => ({ exportLoading: exportLoading.value, exportSelectionLoading: exportSelectionLoading.value, batchPrintLoading: batchPrintLoading.value, + subWaybillPrintLoading: subWaybillPrintLoading.value, allocateSubOrderNumberLoading: allocateSubOrderNumberLoading.value })) @@ -548,6 +630,7 @@ const { actionMap: toolbarActionMap } = createSimpleListToolbarController({ }) toolbarActionMap.handleBatchPrint = handleBatchPrint +toolbarActionMap.handleSubWaybillPrint = handleSubWaybillPrint // 分配子单号 const allocateSubOrderNumberDialogVisible = ref(false) diff --git a/src/views/order/orderManagement/index.vue b/src/views/order/orderManagement/index.vue index 854391a0..849493bf 100644 --- a/src/views/order/orderManagement/index.vue +++ b/src/views/order/orderManagement/index.vue @@ -40,7 +40,15 @@
- + + + + +
@@ -59,6 +67,7 @@ import { ref, watch, onMounted, computed, markRaw } from 'vue' import { useRoute } from 'vue-router' import { useSettingsStore } from '@/stores/modules/settings' +import { useExperimentalStore } from '@/stores/modules/experimental' import { orderBadgeCount } from '@/api/order.index/orderindex' import ReviewOrder from './reviewOrder.vue' import PendingOrder from './pendingOrder.vue' @@ -75,6 +84,11 @@ import { ORDER_PAGE_CONFIG } from './config/order-common-config' const route = useRoute() const settingsStore = useSettingsStore() +const experimentalStore = useExperimentalStore() +/** tab 缓存开关(实验性设置,默认开) */ +const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled) +/** tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */ +const tabCacheMax = computed(() => experimentalStore.tabCacheMax) const singlePage = ORDER_PAGE_CONFIG.singlePage const badgeLoading = ref(false) const workbenchDialogVisible = ref(false) diff --git a/src/views/order/orderManagement/utils/use-delivery-sub-waybill-print.ts b/src/views/order/orderManagement/utils/use-delivery-sub-waybill-print.ts new file mode 100644 index 00000000..94eb26f4 --- /dev/null +++ b/src/views/order/orderManagement/utils/use-delivery-sub-waybill-print.ts @@ -0,0 +1,296 @@ +import { ref } from 'vue' +import { ElMessage } from 'element-plus' +import { + getPrintDataByWaybillCodes, + type WavePlatformPrintDataPayload +} from '@/api/order.print/orderprint' +import { unwrapWavePlatformPrintPayload } from '@/views/order/waveOrder/config/wave-config' +import { orderDeliveryOrder } from '@/api/order.deliveryOrder/orderdeliveryOrder' +import { + isOrderIndexApiSuccess, + parseOrderDetailPayload, + normalizeOrderExpressList +} from '../utils/order-index-helpers' +import { useUserStore } from '@/stores/modules/user' + +type DeliverySubWaybillPrintRequestMeta = { + waybill_codes: string[] + order_ids: Array + /** 仓库 ID(弹窗打印/解锁需要) */ + warehouse_id?: number +} + +/** 运单号选择项(来源于 order.deliveryOrder.detail 的运单信息) */ +export type WaybillPrintOption = { + waybill_code: string + order_id: number | string + logistics_name: string + logistics_code: string + sys_logistics_name: string + business_key: string + is_main: boolean +} + +type UseDeliveryOrderSubWaybillPrintOptions = { + getSelectionRows: () => any[] + onPrintSuccess?: () => void + emptySelectionMessage?: string +} + +function isPrintApiSuccess(code: unknown) { + return code === undefined || code === null || code === 1 || code === 200 || code === 0 +} + +/** 从勾选的配送订单行收集订单 ID(row.id,正整数去重) */ +function collectOrderIds(rows: any[]): number[] { + const ids: number[] = [] + const seen = new Set() + for (const row of rows || []) { + const id = Number(row?.id) + if (Number.isInteger(id) && id > 0 && !seen.has(id)) { + seen.add(id) + ids.push(id) + } + } + return ids +} + +/** 按用户勾选的运单号过滤 waveGroups 中的 orders(order 需含 waybill_code/waybill_no/express_code;无法匹配时保留原样避免误伤) */ +function filterWaveGroupsByWaybills( + waveGroups: unknown[] | undefined, + selectedSet: Set +): unknown[] | undefined { + if (!Array.isArray(waveGroups) || !selectedSet.size) return waveGroups + + // 只有 waveGroups 内 order 带运单号字段时才过滤,避免结构不匹配导致打印丢失 + const hasWaybillField = waveGroups.some((wave: any) => + Array.isArray(wave?.platforms) + ? wave.platforms.some((p: any) => + Array.isArray(p?.orders) + ? p.orders.some( + (o: any) => o && (o.waybill_code || o.waybill_no || o.express_code) + ) + : false + ) + : false + ) + if (!hasWaybillField) return waveGroups + + return waveGroups + .map((wave: any) => { + if (!wave || typeof wave !== 'object') return wave + const platforms = Array.isArray(wave.platforms) + ? wave.platforms + .map((p: any) => { + if (!p || typeof p !== 'object') return p + const orders = Array.isArray(p.orders) + ? p.orders.filter((o: any) => { + if (!o || typeof o !== 'object') return false + const code = String( + o.waybill_code ?? o.waybill_no ?? o.express_code ?? '' + ).trim() + return selectedSet.has(code) + }) + : p.orders + return { ...p, orders } + }) + .filter((p: any) => p && (!Array.isArray(p.orders) || p.orders.length > 0)) + : wave.platforms + return { ...wave, platforms } + }) + .filter( + (wave: any) => wave && (!Array.isArray(wave.platforms) || wave.platforms.length > 0) + ) +} + +/** + * 配送订单「子单号打印」专用逻辑: + * 1. 勾选配送订单行 → 取订单 ID(row.id) + * 2. order.deliveryOrder.detail 获取该发货单号的运单号列表(配送模型,含子单/运单信息) + * 3. 用户选择要打印的运单号 + * 4. order.print.getPrintDataByWaybillCodes 按选中的运单号获取打印数据 + * 5. print.send / print.getList 弹窗内发送打印 / 打印台列表 + */ +export function useDeliveryOrderSubWaybillPrint(options: UseDeliveryOrderSubWaybillPrintOptions) { + const userStore = useUserStore() + const dialogVisible = ref(false) + const loading = ref(false) + const errorMessage = ref('') + const payload = ref(null) + const requestMeta = ref(null) + + // 运单号选择对话框 + const selectDialogVisible = ref(false) + const selectLoading = ref(false) + const waybillOptions = ref([]) + const selectedWaybills = ref([]) + const selectErrorMessage = ref('') + /** 当前选中的仓库 ID(弹窗打印/解锁需要) */ + const currentWarehouseId = ref(0) + + function resetState() { + payload.value = null + requestMeta.value = null + errorMessage.value = '' + waybillOptions.value = [] + selectedWaybills.value = [] + selectErrorMessage.value = '' + } + + /** 点击「子单号打印」:收集订单 ID → order.deliveryOrder.detail 获取运单号列表 → 打开选择对话框 */ + async function handlePrint() { + const rows = options.getSelectionRows() + if (!rows.length) { + ElMessage.warning(options.emptySelectionMessage || '请先勾选需要打印子单号的订单') + return + } + if (selectLoading.value || loading.value) return + + const orderIds = collectOrderIds(rows) + if (!orderIds.length) { + ElMessage.warning('当前勾选记录缺少可用的订单 ID') + return + } + + // 仓库 ID:优先取勾选行,其次当前登录用户上下文(与批量打印一致) + const warehouseId = Number( + rows[0]?.warehouse_id ?? userStore.user?.warehouse_id ?? userStore.user?.store_id + ) + currentWarehouseId.value = Number.isFinite(warehouseId) && warehouseId > 0 ? warehouseId : 0 + + selectLoading.value = true + selectErrorMessage.value = '' + waybillOptions.value = [] + selectedWaybills.value = [] + + try { + const list: WaybillPrintOption[] = [] + const seen = new Set() + for (const id of orderIds) { + const res: any = await orderDeliveryOrder.detail({ id, ids: [id], tableType: 'dispatch' }) + if (!isOrderIndexApiSuccess(res)) continue + const data = parseOrderDetailPayload(res) + for (const item of normalizeOrderExpressList(data)) { + const code = item?.waybill_code + if (!code || seen.has(code)) continue + seen.add(code) + list.push({ + waybill_code: code, + order_id: id, + logistics_name: item?.logistics_name || item?.sys_logistics_name || '', + logistics_code: item?.logistics_code || item?.sys_logistics_code || '', + sys_logistics_name: item?.sys_logistics_name || '', + business_key: String(item?.business_key ?? ''), + is_main: item?.is_main ?? false + }) + } + } + if (!list.length) { + throw new Error('未从选中订单获取到运单号,请确认订单已分配快递号') + } + waybillOptions.value = list + selectDialogVisible.value = true + } catch (error: any) { + selectErrorMessage.value = error?.message || '获取运单号列表失败' + ElMessage.error(selectErrorMessage.value) + } finally { + selectLoading.value = false + } + } + + /** 选择对话框勾选变化 */ + function onSelectChange(rows: WaybillPrintOption[]) { + selectedWaybills.value = rows || [] + } + + /** 确认选中的运单号 → 按运单号获取打印数据并打开预览弹窗 */ + async function confirmPrintWaybills() { + const codes = selectedWaybills.value.map((i) => i.waybill_code).filter(Boolean) + if (!codes.length) { + ElMessage.warning('请先选择要打印的运单号') + return + } + if (loading.value) return + + const orderIds = waybillOptions.value.map((i) => i.order_id) + loading.value = true + errorMessage.value = '' + payload.value = null + try { + const res: any = await getPrintDataByWaybillCodes({ waybill_codes: codes }) + if (!isPrintApiSuccess(res?.code)) { + throw new Error(res?.message || '获取打印数据失败') + } + const rawPayload = unwrapWavePlatformPrintPayload(res) + // 仅保留用户勾选的运单号对应的面单,避免后端按订单返回主单+子单多张被同时打印 + rawPayload.waveGroups = filterWaveGroupsByWaybills( + rawPayload.waveGroups, + new Set(codes) + ) + payload.value = rawPayload + requestMeta.value = { + waybill_codes: codes, + order_ids: orderIds, + warehouse_id: currentWarehouseId.value || undefined + } + selectDialogVisible.value = false + selectedWaybills.value = [] + dialogVisible.value = true + ElMessage.success(res?.message || `已获取 ${codes.length} 个运单的打印数据`) + } catch (error: any) { + payload.value = null + errorMessage.value = error?.message || '获取打印数据失败' + dialogVisible.value = true + ElMessage.error(errorMessage.value) + } finally { + loading.value = false + } + } + + /** 关闭选择对话框 */ + function closeSelectDialog() { + selectDialogVisible.value = false + selectedWaybills.value = [] + } + + async function handleRefresh() { + const meta = requestMeta.value + if (!meta || !meta.waybill_codes.length) return + try { + const res: any = await getPrintDataByWaybillCodes({ waybill_codes: meta.waybill_codes }) + if (!isPrintApiSuccess(res?.code)) { + throw new Error(res?.message || '刷新打印数据失败') + } + payload.value = unwrapWavePlatformPrintPayload(res) + errorMessage.value = '' + } catch (error: any) { + payload.value = null + errorMessage.value = error?.message || '刷新打印数据失败' + ElMessage.error(errorMessage.value) + } + } + + function onPrintSuccess() { + options.onPrintSuccess?.() + } + + return { + dialogVisible, + loading, + errorMessage, + payload, + requestMeta, + resetState, + handlePrint, + handleRefresh, + onPrintSuccess, + selectDialogVisible, + selectLoading, + waybillOptions, + selectedWaybills, + selectErrorMessage, + onSelectChange, + confirmPrintWaybills, + closeSelectDialog + } +} diff --git a/src/views/order/waveOrder/index.vue b/src/views/order/waveOrder/index.vue index 24b45b82..dafcdb37 100644 --- a/src/views/order/waveOrder/index.vue +++ b/src/views/order/waveOrder/index.vue @@ -30,13 +30,19 @@
- + +
@@ -58,6 +64,7 @@ import { ref, watch, computed, markRaw } from 'vue' import { useRoute } from 'vue-router' import { useSettingsStore } from '@/stores/modules/settings' +import { useExperimentalStore } from '@/stores/modules/experimental' import GroupWaveBatchListPanel from './GroupWaveBatchListPanel.vue' import SandanWaveBatchListPanel from './SandanWaveBatchListPanel.vue' import FallbackOrderListPanel from './FallbackOrderListPanel.vue' @@ -68,6 +75,11 @@ import { WAVE_PAGE_CONFIG } from './config/wave-config' const route = useRoute() const settingsStore = useSettingsStore() +const experimentalStore = useExperimentalStore() +/** tab 缓存开关(实验性设置,默认开) */ +const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled) +/** tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */ +const tabCacheMax = computed(() => experimentalStore.tabCacheMax) const shortcutExpanded = computed(() => settingsStore.shortcutExpanded) const singlePage = WAVE_PAGE_CONFIG.singlePage diff --git a/src/views/stock/stock/index.vue b/src/views/stock/stock/index.vue index d58626a1..c5a3f38e 100644 --- a/src/views/stock/stock/index.vue +++ b/src/views/stock/stock/index.vue @@ -142,8 +142,9 @@
- + 切换时保留组件状态、不重建/不重复请求,避免详情 tab 切换卡顿。 + 缓存策略由「实验性功能」设置控制(tabCacheEnabled / tabCacheMax)。 --> + +
@@ -255,6 +265,7 @@ import type { StockWarehouseListSort } from '@/api/stock/stock' import * as indexApi from '@/api/index/index' // Store import { useUserStore } from '@/stores/modules/user' +import { useExperimentalStore } from '@/stores/modules/experimental' import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane' // Utils @@ -264,6 +275,11 @@ import { safeInvoke } from '@/utils/safe-invoke' // import { labelInner } from 'echarts/types/src/label/labelStyle.js' const userStore = useUserStore() +const experimentalStore = useExperimentalStore() +/** 详情 tab 缓存开关(实验性设置,默认开) */ +const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled) +/** 详情 tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */ +const tabCacheMax = computed(() => experimentalStore.tabCacheMax) const hasPermission = (perm: string) => { return userStore.checkPermission(perm) } diff --git a/src/views/stock/stockManagement/index.vue b/src/views/stock/stockManagement/index.vue index 896c5790..98cff6f1 100644 --- a/src/views/stock/stockManagement/index.vue +++ b/src/views/stock/stockManagement/index.vue @@ -22,9 +22,10 @@
- + +
@@ -34,12 +35,18 @@ import { computed, markRaw, ref, watch } from 'vue' import { useRoute } from 'vue-router' import { useSettingsStore } from '@/stores/modules/settings' +import { useExperimentalStore } from '@/stores/modules/experimental' import { safeInvoke } from '@/utils/safe-invoke' import StockDetail from '../stock/index.vue' import ComboStock from '../combo_stock/index.vue' const route = useRoute() const settingsStore = useSettingsStore() +const experimentalStore = useExperimentalStore() +/** tab 缓存开关(实验性设置,默认开) */ +const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled) +/** tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */ +const tabCacheMax = computed(() => experimentalStore.tabCacheMax) const shortcutExpanded = computed(() => settingsStore.shortcutExpanded) const containerHeight = computed(() => diff --git a/src/views/storage/generalreport/config/template-config.ts b/src/views/storage/generalreport/config/template-config.ts index ed28b4ba..d2c31b39 100644 --- a/src/views/storage/generalreport/config/template-config.ts +++ b/src/views/storage/generalreport/config/template-config.ts @@ -331,6 +331,24 @@ export const FIELD_DICT: Record = { slot: null, detailLabel: '关联报表' }, + /** 报表定义(report.meta 查询用,下拉选择报表定义启用项;value=报表定义ID) */ + report_id: { + key: 'report_id', + label: '报表', + scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: reportDefinitionOptions as any }, + table: { minWidth: 120, showOverflowTooltip: true }, + slot: null, + detailLabel: '报表' + }, + /** 导出文件名模板(支持 {date} 占位) */ + file_name: { + key: 'file_name', + label: '导出文件名', + scanBox: null, + table: { minWidth: 180, showOverflowTooltip: true }, + slot: null, + detailLabel: '导出文件名' + }, /** 每日投递时间点(HH:mm 数组) */ schedule_times: { key: 'schedule_times', @@ -1048,12 +1066,12 @@ export const tabPages: TabPageRawConfig[] = [ name: 'export', label: '导出任务', scanBoxCacheKey: 'generalreport-export', - scanBoxFieldKeys: ['report_code'], - tableColumnKeys: ['report_code', 'name', 'scope', 'query', 'day_count', 'cutover_hour', 'operation'], + scanBoxFieldKeys: ['report_id'], + tableColumnKeys: ['report_id', 'name', 'type', 'file_name', 'day_count', 'cutover_hour', 'operation'], upperTableDefaults: { title: '报表定义(report.meta)', showSelection: false, - emptyText: '请输入报表编码查询报表元数据' + emptyText: '请选择报表查询报表元数据' }, detailTabs: [ { name: 'detail', label: '报表详情', componentKey: 'DetailPanel' } @@ -1062,7 +1080,7 @@ export const tabPages: TabPageRawConfig[] = [ { title: '报表信息', columnCount: 3, - fieldKeys: ['report_code', 'name', 'scope', 'query', 'day_count', 'cutover_hour'] + fieldKeys: ['report_id', 'name', 'type', 'file_name', 'day_count', 'cutover_hour'] }, { title: '可导出字段', @@ -1077,7 +1095,7 @@ export const tabPages: TabPageRawConfig[] = [ return { list: res?.data?.list ?? [], total: res?.data?.total ?? 0 } }, buildListParams({ conditions }) { - return { report_code: conditions?.report_code } + return { report_id: conditions?.report_id } } }, operationButtons: [ @@ -1103,23 +1121,23 @@ export const templateTabs = tabPages.map((t) => ({ name: t.name, label: t.label, // ExportReportDialog 内使用 useAsyncExportTask 处理(不写任何本地存储)。 // ============================================================ /** - * 按报表编码调用 report.meta 查询报表元数据,包装为列表行(Tab3 的 api.list)。 - * 未传报表编码时返回空列表。 + * 按报表定义ID调用 report.meta 查询报表元数据,包装为列表行(Tab3 的 api.list)。 + * 未传报表定义ID时返回空列表。 */ -export async function queryReportMetaList(params?: { report_code?: string }): Promise { - const code = params?.report_code - if (!code) { +export async function queryReportMetaList(params?: { report_id?: number }): Promise { + const id = params?.report_id + if (!id) { return { code: 1, data: { list: [], total: 0 } } } try { - const res: any = await meta({ report_code: code }) + const res: any = await meta({ report_id: id }) const payload = res?.data ?? res - if (payload && payload.report_code) { + if (payload && payload.report_id) { const row = { - report_code: payload.report_code, + report_id: payload.report_id, name: payload.name, - scope: payload.scope, - query: payload.query, + type: payload.type, + file_name: payload.file_name, day_count: payload.window?.dayCount, cutover_hour: payload.window?.cutoverHour, fields: payload.fields ?? [] diff --git a/src/views/storage/generalreport/index.vue b/src/views/storage/generalreport/index.vue index aa6ce96d..4c0a02fd 100644 --- a/src/views/storage/generalreport/index.vue +++ b/src/views/storage/generalreport/index.vue @@ -235,7 +235,7 @@ /> @@ -263,6 +263,7 @@ import { resolveTabConfig, getTabToolbarButtons, loadStoreOptions, + loadReportDefinitions, type TabPageConfig, type DetailTabConfig, type ToolbarButtonConfig, @@ -451,8 +452,8 @@ async function handleOperationAction(key: string, row: Record) { loadData() break case 'exportThisReport': - // 将该报表编码带入导出弹窗 - exportInitialReportCode.value = row?.report_code ?? '' + // 将该报表定义ID带入导出弹窗 + exportInitialReportId.value = Number(row?.report_id ?? row?.id) || 0 exportReportVisible.value = true break default: @@ -465,8 +466,8 @@ async function handleOperationAction(key: string, row: Record) { // ============================================================ const createPlanVisible = ref(false) const exportReportVisible = ref(false) -/** 导出弹窗初始报表编码(Tab3 行「导出此报表」带入) */ -const exportInitialReportCode = ref('') +/** 导出弹窗初始报表定义ID(Tab3 行「导出此报表」带入) */ +const exportInitialReportId = ref(0) function handlePlanSaved() { ElMessage.success('投递计划已保存') @@ -499,11 +500,11 @@ const loadData = async () => { // 使用真实接口 const conditions = scanBoxRef.value?.getConditions?.() || {} - // 导出任务页:report.meta 需报表编码才能查询,未输入时不发请求并给出引导 - if (activeTabName.value === 'export' && !conditions?.report_code) { + // 导出任务页:report.meta 需报表定义ID才能查询,未选择时不发请求并给出引导 + if (activeTabName.value === 'export' && !conditions?.report_id) { listData.value = [] pagination.total = 0 - ElMessage.info('请输入报表编码后查询报表元数据') + ElMessage.info('请选择报表后查询报表元数据') return } @@ -659,6 +660,7 @@ const upperPaneFullStyle = computed(() => ({ // ============================================================ onMounted(() => { void loadStoreOptions() + void loadReportDefinitions() loadData() }) diff --git a/src/views/storage/generalreport/pages/ExportReportDialog.vue b/src/views/storage/generalreport/pages/ExportReportDialog.vue index 3203f6e5..8ef25a4c 100644 --- a/src/views/storage/generalreport/pages/ExportReportDialog.vue +++ b/src/views/storage/generalreport/pages/ExportReportDialog.vue @@ -21,8 +21,20 @@ label-width="100px" size="small" > - - + + + + @@ -82,14 +94,14 @@ 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' +import { storeOptions, loadStoreOptions, reportDefinitionOptions, loadReportDefinitions } from '../config/template-config' defineOptions({ name: 'ExportReportDialog' }) const props = defineProps<{ visible: boolean - /** 初始报表编码(Tab3 行「导出此报表」带入) */ - reportCode?: string + /** 初始报表定义ID(Tab3 行「导出此报表」带入) */ + reportId?: number }>() const emit = defineEmits<{ @@ -99,13 +111,13 @@ const emit = defineEmits<{ const formRef = ref(null) const form = reactive({ - report_code: '', + report_id: undefined as number | undefined, store_id: undefined as number | undefined, bizDate: '' }) const rules = { - report_code: [{ required: true, message: '请输入报表编码', trigger: 'blur' }] + report_id: [{ required: true, message: '请选择报表定义', trigger: 'change' }] } // 提交导出 + 轮询进度(不传 storageKey → 不写任何本地存储) @@ -124,7 +136,7 @@ const { watch(() => props.visible, (v) => { if (v) { - form.report_code = props.reportCode ?? '' + form.report_id = props.reportId ?? undefined form.store_id = undefined form.bizDate = '' formRef.value?.clearValidate?.() @@ -133,6 +145,7 @@ watch(() => props.visible, (v) => { onMounted(() => { void loadStoreOptions() + void loadReportDefinitions() }) function handleClosed() { @@ -148,7 +161,7 @@ async function handleSubmit() { // 提交导出任务;提交后进度在弹窗中展示,完成后自动下载(useAsyncExportTask 内部处理) await submitExportTask({ - report_code: form.report_code.trim(), + report_id: form.report_id, ...(form.store_id && form.store_id > 0 ? { store_id: form.store_id } : {}), ...(form.bizDate ? { params: { bizDate: form.bizDate } } : {}) }) diff --git a/src/views/store/shipperSigning/index.vue b/src/views/store/shipperSigning/index.vue index d2c023b8..1aca58e7 100644 --- a/src/views/store/shipperSigning/index.vue +++ b/src/views/store/shipperSigning/index.vue @@ -192,7 +192,7 @@ + + diff --git a/src/views/store/stores/index.vue b/src/views/store/stores/index.vue index a19da79d..330da8e6 100644 --- a/src/views/store/stores/index.vue +++ b/src/views/store/stores/index.vue @@ -992,6 +992,14 @@ @update:visible="exportDialogVisible = $event" /> + + + ({ - loading: loading.value + loading: loading.value, + listExportLoading: listExportLoading.value })) const buttonDisabledMap = computed(() => ({})) @@ -1229,6 +1239,9 @@ const toolbarActionMap: Record void> = { void loadList() }, openOpenAccountDialog: () => openOpenAccountDialog(), + openExportDialog: () => { + listExportDialogVisible.value = true + }, toggleBalance: () => toggleBalance(), toggleDetailVisible: () => toggleDetailVisible() } @@ -1246,6 +1259,8 @@ const availableFields = reactive(defaultAvailableFields) const presetTree = ref(defaultPresetTree) const currentCondition = ref({ use_status: 1 }) +const listExportDialogVisible = ref(false) +const listExportLoading = ref(false) async function loadList() { loading.value = true diff --git a/src/views/store/stores/store-config.ts b/src/views/store/stores/store-config.ts index 3dd02608..7a0dcd71 100644 --- a/src/views/store/stores/store-config.ts +++ b/src/views/store/stores/store-config.ts @@ -245,6 +245,14 @@ export const presetTree: any[] = [] /** 货主列表主工具栏按钮(action 与 stores/index.vue 内 toolbarActionMap 键一致) */ export const storeToolbarButtons: ToolbarButtonConfig[] = [ { key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadList' }, + { + key: 'export', + label: '导出', + category: 'action', + size: 'small', + loadingKey: 'listExportLoading', + action: 'openExportDialog' + }, { key: 'toggleBalance', label: '显示余额',