/** * 【库存盘点】配置文件 — 基于 views/mode 模板 v2 * * ===== 接口来源 ===== * 全部接口来自「库存盘点模块」(module folder = stock.check),封装在 * `src/api/stock.check/stock.check.ts`: * * 列表 stock.check.list → 本文件 tabPages[].api.list * 详情 stock.check.detail → CheckItemsPanel(明细面板自行拉取) * 新建 stock.check.create → pages/CheckFormDialog.vue * 加明细 stock.check.addDetail → pages/CheckStockPickerDialog.vue * 上报 stock.check.report → CheckItemsPanel(行内 / 批量上报,覆盖式) * 记录列表 stock.check.recordList → CheckRecordsPanel(作业记录页签) * 记录删除 stock.check.recordDelete → CheckRecordsPanel(仅 approved/checking 可删) * 提交 stock.check.submit → index.vue 操作列 * 审核 stock.check.audit → index.vue 操作列(通过 / 驳回) * 完成 stock.check.finish → index.vue 操作列 * 取消 stock.check.cancel → index.vue 操作列 * 导出 stock.check.export → index.vue(useAsyncExportTask + 进度弹窗) * 导出进度 stock.check.exportTaskProgress → 同上 * * ===== 状态机(主表 status)===== * created ──submit──> submitted ──audit(approve)──> approved ──report(首次)──> checking ──finish──> completed * │ │ (终态) * │ └──audit(reject)──> rejected ──addDetail/submit 可再来──┐ * └──cancel──> cancelled(终态) │ * ↑──────────────── submit 仅 created/rejected ──────────────────────────┘ * * 注意:warehouse_id 由服务端从登录上下文(ctx.user.store_id)注入,前端一律不传。 * * ===== 核心设计(沿用模板)===== * 1. FIELD_DICT — 全局字段预设表(唯一真相来源) * 2. VALUE_MAPS — 值翻译映射表(select options 和 tag 翻译共用) * 3. TAG_RESOLVERS — 状态文字颜色解析器 * 4. 各标签页通过 key 引用所需字段(scanBoxFieldKeys / tableColumnKeys) * 5. resolveTabConfig() — 加载时将 key 列表展开为完整配置 */ import { ref, isRef, type Component } from 'vue' import DetailPanel from './components/DetailPanel.vue' import CheckItemsPanel from './components/CheckItemsPanel.vue' import CheckRecordsPanel from './components/CheckRecordsPanel.vue' import { stockCheckList, stockCheckExport, stockCheckExportTaskProgress, type StockCheckStatus } from '@/api/stock.check/stock.check' import { loadStores } from '@/api/index/index' // ============================================================ // 〇、全局页面配置 // ============================================================ export const PAGE_CONFIG = { /** 是否显示顶部多标签栏(本页为单页签,通过 ScanBox 的「状态」筛选,不显示标签栏) */ showTabArea: false, /** 单页模式:不显示标签栏,仅一个标签页内容 */ singlePage: true, /** 是否启用详情面板(底部分栏 + 显示/隐藏详情按钮),false 时表格占满全高 */ enableDetailPanel: true } // ============================================================ // 〇-A、组件注册表 — 所有可复用组件在此注册 // ============================================================ export const COMPONENT_REGISTRY: Record = { /** 盘点单信息(描述列表) */ DetailPanel, /** 盘点明细(明细行表格 + 实盘上报) */ CheckItemsPanel, /** 作业记录(recordList + recordDelete) */ CheckRecordsPanel } // ============================================================ // 〇-A1、货主下拉选项(ScanBox 筛选与「新建盘点」表单共用) // ============================================================ /** 货主下拉选项(value 为货主ID;对齐 storage/generalreport 的 index.loadStores) */ export const storeOptions = ref<{ value: number; label: string }[]>([]) let storeOptionsLoading = false /** 加载货主下拉选项(已加载则复用) */ export async function loadStoreOptions(): Promise<{ value: number; label: string }[]> { if (storeOptions.value.length) return storeOptions.value if (storeOptionsLoading) return storeOptions.value storeOptionsLoading = true try { const res: any = await loadStores() if (res && (res.code === 200 || res.code === 1)) { const raw: any[] = res.stores ?? res.data?.stores ?? res.data?.list ?? [] storeOptions.value = normalizeStoreOptions(raw) } } catch (e) { console.error('[stockcheck] 加载货主列表失败', e) } finally { storeOptionsLoading = false } return storeOptions.value } /** 兼容 { value,label } / { id,store_remask } / { store_id,store_name } 等形态 */ function normalizeStoreOptions(stores: any[]): { value: number; label: string }[] { if (!Array.isArray(stores)) return [] const out: { value: number; label: string }[] = [] const seen = new Set() for (const s of stores) { const value = Number(s?.value ?? s?.id ?? s?.store_id) if (!Number.isFinite(value) || value <= 0 || seen.has(value)) continue seen.add(value) const label = (s?.label != null && String(s.label).trim()) || (s?.store_remask != null && String(s.store_remask).trim()) || (s?.name != null && String(s.name).trim()) || (s?.store_name != null && String(s.store_name).trim()) || String(value) out.push({ value, label: String(label) }) } return out } // ============================================================ // 〇-B、SCANBOX_GROUPS — ScanBox 分组名称 // ============================================================ export const SCANBOX_GROUPS = { basic: '基础信息', process: '流程状态', time: '时间范围', custom: '自定义字段' } as const // ============================================================ // 一、FIELD_DICT — 全局字段预设表(唯一真相来源) // ============================================================ // 每个字段拥有: // label — 唯一翻译文本 // scanBox — ScanBox 渲染配置(type/options/group) // table — 表格列配置(minWidth/fixed/align/sortable) // slot — 单元格渲染配置(tag/tagResolver/translateField) // detailLabel — 明细面板中的标签文本(可选,默认用 label) // filterParamMap — ScanBox 筛选值 → API 传参值映射 export interface FieldDefinition { key: string label: string scanBox: { type: 'text' | 'select' | 'daterange' | 'number' group?: string /** 支持数组或 ref(ref 由 resolveTabConfig 解包,保证选项异步加载后仍响应式) */ options?: { label: string; value: any }[] | any } | null table: { minWidth?: number width?: number fixed?: 'left' | 'right' | boolean align?: 'left' | 'center' | 'right' sortable?: boolean showOverflowTooltip?: boolean copyAction?: 'copy' | 'copyQr' copyValue?: (row: any) => any } | null slot: { type: 'tag' | 'text' | 'default' | 'operation' tagType?: string | Record tagResolver?: string translateField?: string /** 时间/日期列格式化:datetime=YYYY-MM-DD HH:mm:ss,date=YYYY-MM-DD */ format?: 'datetime' | 'date' } | null detailLabel?: string filterParamMap?: Record } // ============================================================ // VALUE_MAPS — 值翻译映射(select options 和 tag 翻译共用) // ============================================================ export const VALUE_MAPS: Record> = { /** 盘点主表状态 */ status: { created: '待提交', submitted: '待审核', rejected: '已驳回', approved: '待盘点', checking: '盘点中', completed: '已完成', cancelled: '已取消' }, /** 主表明细进度 detail_status */ detail_status: { none_checked: '未盘点', partial_checked: '部分盘点', all_checked: '已盘完' }, /** 盘点范围 type */ type: { all: '全盘', store: '按货主', goods: '按商品', location: '按库位' }, /** 盘点方式 mode */ mode: { open: '明盘', blind: '盲盘' }, /** 明细行状态(stock.check.detail 的 rows[].status:checked=有作业记录 / unchecked=未盘) */ check_item_status: { unchecked: '未盘', checked: '已盘点' } } /** 从 VALUE_MAPS 衍生 options(value 取映射的原始 key,保证回传后端的是英文枚举) */ export function getOptions(field: string): { label: string; value: string }[] { const map = VALUE_MAPS[field] if (!map) return [] return Object.entries(map).map(([value, label]) => ({ label, value })) } /** 翻译 value → label */ export function translate(field: string, value: any): string { const map = VALUE_MAPS[field] if (!map) return value === undefined || value === null || value === '' ? '—' : String(value) return map[String(value)] ?? String(value ?? '—') } /** * 把后端各种时间形态归一化为 Date,识别不了返回 null。 * * 兼容(后端各模块并不统一,盘点实测是时间戳): * - 数字/纯数字串:秒(10 位) / 毫秒(13 位) / 微秒(16 位) / 纳秒(19 位),含小数串(如 '1759075200.123') * - 紧凑串:'20260929'(YYYYMMDD)/ '20260929120000'(YYYYMMDDHHmmss) * - 日期时间串:'2026-09-29'、'2026-09-29 12:00:00'、ISO * - Date 实例 */ function toDate(value: any): Date | null { if (value === undefined || value === null || value === '') return null if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value const text = String(value).trim() // 紧凑日期串(PHP 常见):8 位 = YYYYMMDD,14 位 = YYYYMMDDHHmmss if (/^\d{8}$/.test(text)) { const d = new Date(`${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}T00:00:00`) return Number.isNaN(d.getTime()) ? null : d } if (/^\d{14}$/.test(text)) { const d = new Date( `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}T${text.slice(8, 10)}:${text.slice(10, 12)}:${text.slice(12, 14)}` ) return Number.isNaN(d.getTime()) ? null : d } // 时间戳(整数或小数) if (/^-?\d+(\.\d+)?$/.test(text)) { let num = Number(text) if (!Number.isFinite(num) || num <= 0) return null // 数量级归一到毫秒:> 1e14 视为微秒/纳秒逐级缩小;< 1e10 视为秒 while (num > 1e14) num /= 1000 if (num < 1e10) num *= 1000 const d = new Date(num) return Number.isNaN(d.getTime()) ? null : d } const d = new Date(text) return Number.isNaN(d.getTime()) ? null : d } /** 格式化时间 → YYYY-MM-DD HH:mm:ss(时间戳/日期串,空值或无法识别返回 —) */ export function formatTime(value: any): string { if (value === undefined || value === null || value === '') return '—' const d = toDate(value) if (!d) return String(value) const pad = (n: number) => String(n).padStart(2, '0') return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` } /** 格式化日期 → YYYY-MM-DD(时间戳/日期串,空值返回 —) */ export function formatDate(value: any): string { if (value === undefined || value === null || value === '') return '—' const d = toDate(value) if (!d) return String(value) const pad = (n: number) => String(n).padStart(2, '0') return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` } /** 业务成功判定:与 utils/request 的 SUCCESS_CODES(200/20000/1/0)对齐 */ export function isCheckApiSuccess(res: any): boolean { if (!res || typeof res !== 'object') return false return [200, 20000, 1, 0].includes(Number(res.code)) } // ============================================================ // TAG_RESOLVERS — 状态文字颜色解析器 // ============================================================ // 颜色规则:未开始=info(灰) 待xx/进行中=warning(黄) 已完成=success(绿) 驳回/异常=danger(红) export const TAG_RESOLVERS: Record string> = { /** 盘点主表状态 */ resolveCheckStatusTag(v) { switch (String(v ?? '')) { case 'created': return 'info' case 'submitted': return 'warning' case 'rejected': return 'danger' case 'approved': return 'primary' case 'checking': return 'warning' case 'completed': return 'success' case 'cancelled': return 'info' default: return 'info' } }, /** 明细盘点进度 detail_status */ resolveCheckDetailStatusTag(v) { switch (String(v ?? '')) { case 'all_checked': return 'success' case 'partial_checked': return 'warning' case 'none_checked': return 'info' default: return 'info' } }, /** 明细行状态 */ resolveCheckItemStatusTag(v) { return String(v ?? '') === 'checked' ? 'success' : 'info' } } // ============================================================ // 二、FIELD_DICT 实例 — 在此定义页面所需的所有字段 // ============================================================ export const FIELD_DICT: Record = { /** 关键字(对盘点单号 / 盘点名称模糊匹配,对应 where.keyword) */ keyword: { key: 'keyword', label: '盘点单号/名称', scanBox: { type: 'text', group: SCANBOX_GROUPS.basic }, table: null, slot: null }, /** 货主筛选(value 为货主ID,对应 where.store_id) */ store_id: { key: 'store_id', label: '货主', scanBox: { type: 'select', group: SCANBOX_GROUPS.basic, options: storeOptions }, table: { minWidth: 90, align: 'center' }, slot: null, detailLabel: '货主ID' }, check_no: { key: 'check_no', label: '盘点单号', scanBox: null, table: { minWidth: 170, fixed: 'left', copyAction: 'copy', showOverflowTooltip: true }, slot: null }, title: { key: 'title', label: '盘点名称', scanBox: null, table: { minWidth: 150, showOverflowTooltip: true }, slot: null }, type: { key: 'type', label: '盘点范围', scanBox: null, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagType: 'info', translateField: 'type' } }, mode: { key: 'mode', label: '盘点方式', scanBox: null, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagType: 'info', translateField: 'mode' } }, status: { key: 'status', label: '盘点状态', // 状态作为 ScanBox 筛选(可选、默认全部);value 为英文枚举,直接作为 where.status 回传 scanBox: { type: 'select', group: SCANBOX_GROUPS.process, options: getOptions('status') }, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveCheckStatusTag', translateField: 'status' } }, detail_status: { key: 'detail_status', label: '盘点进度', scanBox: null, table: { minWidth: 100, align: 'center' }, slot: { type: 'tag', tagResolver: 'resolveCheckDetailStatusTag', translateField: 'detail_status' } }, total_items: { key: 'total_items', label: '明细行数', scanBox: null, table: { minWidth: 90, align: 'center' }, slot: null }, checked_items: { key: 'checked_items', label: '已盘行数', scanBox: null, table: { minWidth: 90, align: 'center' }, slot: null }, diff_items: { key: 'diff_items', label: '差异行数', scanBox: null, table: { minWidth: 90, align: 'center' }, slot: null }, check_date: { key: 'check_date', label: '盘点日期', scanBox: null, table: { minWidth: 110, align: 'center' }, // 后端返回时间戳,需按「日期」展示(YYYY-MM-DD) slot: { type: 'text', format: 'date' } }, creator_name: { key: 'creator_name', label: '创建人', scanBox: null, table: { minWidth: 100 }, slot: null }, created_at: { key: 'created_at', label: '创建时间', scanBox: null, table: { minWidth: 165 }, slot: { type: 'text', format: 'datetime' } }, start_time: { key: 'start_time', label: '开始时间', scanBox: null, table: null, // 仅详情面板展示,后端返回时间戳 slot: { type: 'text', format: 'datetime' } }, end_time: { key: 'end_time', label: '结束时间', scanBox: null, table: null, // 仅详情面板展示,后端返回时间戳 slot: { type: 'text', format: 'datetime' } }, remark: { key: 'remark', label: '备注', scanBox: null, table: null, slot: null }, /** 操作列(虚拟字段,仅用于表格列渲染) */ operation: { key: 'operation', label: '操作', scanBox: null, table: { minWidth: 240, fixed: 'right', align: 'center' }, slot: { type: 'operation' } } } // ============================================================ // 三、ColumnSlotConfig — 列单元格渲染配置 // ============================================================ export interface ColumnSlotConfig { type: 'tag' | 'text' | 'default' | 'operation' tagType?: string | Record tagResolver?: string translateField?: string /** 时间/日期列格式化:datetime=YYYY-MM-DD HH:mm:ss,date=YYYY-MM-DD */ format?: 'datetime' | 'date' } // ============================================================ // 三-A、OperationButtonConfig — 操作列按钮配置 // ============================================================ export interface OperationButtonConfig { key: string label: string type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | '' actionType: 'form' | 'action' formKey?: string formTitle?: string formWidth?: string paramMap?: Record extraParams?: Record disabledOnField?: string /** 按行数据决定是否渲染该按钮(返回 false 隐藏;用于按 status 显示可用动作) */ visibleWhen?: (row: Record) => boolean confirmMessage?: string confirmTitle?: string confirmType?: 'warning' | 'danger' | 'info' confirmButtonText?: string } // ============================================================ // 四、DetailFieldConfig / DetailSectionConfig — 明细面板配置 // ============================================================ export interface DetailFieldConfig { key: string label?: string span?: number renderType?: 'text' | 'tag' | 'pre' tagType?: string | Record tagResolver?: string translateField?: string /** 时间/日期格式化(与表格列同一套:datetime / date) */ format?: 'datetime' | 'date' } export interface DetailSectionConfig { title: string columnCount: number fields: DetailFieldConfig[] } export interface DetailTabConfig { name: string label: string componentKey: string component?: Component } // ============================================================ // 五、TabPageApiConfig — 标签页接口插槽配置 // ============================================================ export type ApiMethod = (...args: any[]) => Promise export type ApiSource = 'api' | 'list' export type ComponentApiConfig = { source: 'list' } | ApiMethod export interface TabPageApiConfig { /** 列表查询接口 */ list: ApiMethod /** 明细面板接口(可选,不配则用 row 数据) */ detail?: ComponentApiConfig /** 操作日志接口(可选) */ log?: ComponentApiConfig /** 导出接口(可选) */ export?: ApiMethod /** 导出进度查询接口(可选) */ exportProgress?: ApiMethod /** ScanBox 下拉选项数据源接口(可选) */ scanBoxOptions?: Record /** 工具栏按钮 → API 方法映射(可选) */ toolbar?: Record /** 列表响应解析器 */ parseListResponse?: (res: any) => { list: any[]; total: number } /** 构建列表请求参数 */ buildListParams?: (params: { pagination: { page: number; pageSize: number } conditions: Record sort?: { prop: string; order: string } }) => Record } // ============================================================ // 六、TabPageRawConfig — 标签页声明配置(仅用 key 引用) // ============================================================ export interface TabPageRawConfig { name: string label: string scanBoxCacheKey: string /** ScanBox 需要的字段 key 列表(从 FIELD_DICT 中查找) */ scanBoxFieldKeys: string[] /** 表格需要的列 key 列表(从 FIELD_DICT 中查找) */ tableColumnKeys: string[] upperTableDefaults: { title: string enableColumnConfig?: boolean showIndex?: boolean showSelection?: boolean emptyText?: string } /** 明细面板标签页配置 */ detailTabs?: { name: string; label: string; componentKey: string }[] /** 明细面板分区配置(字段 key 列表,resolveTabConfig 展开) */ detailSections: { title: string columnCount: number fieldKeys: string[] }[] /** 接口配置(有 api 时启用真实接口) */ api?: TabPageApiConfig /** 操作列按钮配置(需 tableColumnKeys 包含 'operation') */ operationButtons?: OperationButtonConfig[] } // ============================================================ // 七、TabPageConfig — 展开后的完整配置(给 index.vue 使用) // ============================================================ export interface TabPageConfig { name: string label: string scanBoxCacheKey: string scanBoxFields: Record[] upperTable: { title: string enableColumnConfig: boolean showIndex: boolean showSelection: boolean emptyText: string columns: Record[] } columnSlots: Record detailConfig: DetailSectionConfig[] detailTabs: DetailTabConfig[] api?: TabPageApiConfig operationButtons?: OperationButtonConfig[] } // ============================================================ // 八、resolveTabConfig — 加载时将 RawConfig 展开为完整配置 // ============================================================ export function resolveTabConfig(raw: TabPageRawConfig): TabPageConfig { // 展开 ScanBox 字段 const scanBoxFields: Record[] = [] for (const key of raw.scanBoxFieldKeys) { const def = FIELD_DICT[key] if (!def || !def.scanBox) continue scanBoxFields.push({ label: def.label, value: def.key, type: def.scanBox.type, // options 允许传 ref(异步加载的货主下拉),解包后仍受 currentTabConfig 依赖追踪 options: def.scanBox.options ? (isRef(def.scanBox.options) ? def.scanBox.options.value : [...def.scanBox.options]) : undefined, group: def.scanBox.group, required: (def.scanBox as any).required }) } // 展开表格列 const columns: Record[] = [] for (const key of raw.tableColumnKeys) { const def = FIELD_DICT[key] if (!def || !def.table) continue columns.push({ prop: def.key, label: def.label, ...def.table }) } // 展开列插槽 const columnSlots: Record = {} for (const key of raw.tableColumnKeys) { const def = FIELD_DICT[key] if (!def || !def.slot) continue columnSlots[def.key] = { ...def.slot } } // 展开明细面板配置 const detailConfig: DetailSectionConfig[] = raw.detailSections.map((sec) => ({ title: sec.title, columnCount: sec.columnCount, fields: sec.fieldKeys .map((key): DetailFieldConfig | null => { const def = FIELD_DICT[key] if (!def) return null return { key: def.key, label: def.detailLabel ?? def.label, translateField: def.slot?.translateField, tagResolver: def.slot?.tagResolver, tagType: def.slot?.tagType, format: def.slot?.format, renderType: def.slot?.type === 'tag' ? 'tag' : 'text' } }) .filter((f): f is DetailFieldConfig => f !== null) })) // 展开明细标签页(解析 componentKey → Component) const detailTabs: DetailTabConfig[] = raw.detailTabs ? raw.detailTabs.map((tab) => ({ name: tab.name, label: tab.label, componentKey: tab.componentKey, component: COMPONENT_REGISTRY[tab.componentKey] })) : [{ name: 'detail', label: '明细', componentKey: 'DetailPanel', component: COMPONENT_REGISTRY['DetailPanel'] }] return { name: raw.name, label: raw.label, scanBoxCacheKey: raw.scanBoxCacheKey, scanBoxFields, upperTable: { title: raw.upperTableDefaults.title, enableColumnConfig: raw.upperTableDefaults.enableColumnConfig ?? true, showIndex: raw.upperTableDefaults.showIndex ?? true, showSelection: raw.upperTableDefaults.showSelection ?? true, emptyText: raw.upperTableDefaults.emptyText ?? '暂无数据', columns }, columnSlots, detailConfig, detailTabs, api: raw.api, operationButtons: raw.operationButtons } } // ============================================================ // 九、buildWhereConditions — 将 ScanBox 条件转为 API where 参数 // ============================================================ export function buildWhereConditions(rawConditions: Record): Record { const where: Record = {} for (const [key, cond] of Object.entries(rawConditions || {})) { let value: any = undefined if (cond && typeof cond === 'object' && 'operator' in cond) { value = (cond as any).value } else if (cond !== undefined && cond !== null && cond !== '') { value = Array.isArray(cond) ? cond[0] ?? '' : cond } if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) { continue } const def = FIELD_DICT[key] if (def?.filterParamMap) { const mapped = def.filterParamMap[String(value)] if (mapped !== undefined) { where[key] = mapped continue } } where[key] = value } return where } // ============================================================ // 十、工具栏按钮系统 // ============================================================ // 按钮分为三类: // common — 公共按钮(刷新、导出) // function — 功能按钮(打开表单/确认窗口) // basic — 基础操作(字段设置、隐藏详情) export interface ToolbarButtonConfig { key: string label: string category: 'common' | 'function' | 'basic' size?: '' | 'default' | 'small' | 'large' type?: '' | 'primary' | 'success' | 'warning' | 'info' | 'danger' plain?: boolean loadingKey?: string disabledKey?: string action: string dynamicLabelKey?: string onlyForTabs?: string[] buttonType?: 'default' | 'dropdown' dropdownOptions?: Array<{ label: string; action: string; divided?: boolean }> formKey?: string } export const TOOLBAR_BUTTONS: Record = { // ===== 公共按钮 ===== refresh: { key: 'refresh', label: '刷新', category: 'common', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadData' }, // ===== 功能按钮 ===== create: { key: 'create', label: '新建盘点', category: 'function', type: 'primary', plain: false, size: 'small', action: 'openCreateCheck' }, export: { key: 'export', label: '导出', category: 'function', type: 'primary', plain: true, size: 'small', loadingKey: 'exportLoading', action: 'handleExport' }, // ===== 基础操作 ===== columnConfig: { key: 'columnConfig', label: '字段设置', category: 'basic', size: 'small', action: 'openColumnConfigPanel' }, toggleDetail: { key: 'toggleDetail', label: '显示详情', category: 'basic', dynamicLabelKey: 'detailToggleLabel', size: 'small', action: 'toggleDetailVisible' } } /** 按标签页名称获取工具栏按钮列表(自动根据 PAGE_CONFIG 过滤) */ export function getTabToolbarButtons(tabName: string): ToolbarButtonConfig[] { return Object.values(TOOLBAR_BUTTONS).filter((btn) => { if (btn.onlyForTabs && !btn.onlyForTabs.includes(tabName)) return false // 详情面板禁用时,隐藏「显示/隐藏详情」按钮 if (!PAGE_CONFIG.enableDetailPanel && btn.key === 'toggleDetail') return false return true }) } // ============================================================ // 十一、批量操作配置(可选,接入 BatchOperationForm 时使用) // ============================================================ export interface BatchOperationConfig { action: string title: string confirmText: string confirmType?: 'warning' | 'error' | 'info' | 'success' confirmButtonText: string successText: string failText: string apiMethod: (...args: any[]) => Promise payloadKey?: string idField?: string | string[] payloadBuilder?: (rows: Record[]) => Record useProgress?: boolean progressApiMethod?: (...args: any[]) => Promise } /** ★ 在此配置批量操作 */ export const BATCH_OPERATION_CONFIGS: Record = {} // ============================================================ // 十二、标签页注册表 — 库存盘点(按状态分组) // ============================================================ /** 表格列(各状态页签一致) */ const TABLE_COLUMN_KEYS = [ 'check_no', 'title', 'type', 'mode', 'status', 'detail_status', 'total_items', 'checked_items', 'diff_items', 'check_date', 'creator_name', 'created_at', 'operation' ] /** 明细面板分区(「盘点单信息」tab) */ const DETAIL_SECTIONS = [ { title: '基本信息', columnCount: 3, fieldKeys: ['check_no', 'title', 'type', 'mode', 'status', 'detail_status', 'store_id'] }, { title: '进度信息', columnCount: 3, fieldKeys: ['total_items', 'checked_items', 'diff_items', 'creator_name', 'check_date'] }, { title: '时间信息', columnCount: 2, fieldKeys: ['start_time', 'end_time', 'created_at'] }, { title: '备注', columnCount: 1, fieldKeys: ['remark'] } ] const DETAIL_TABS = [ { name: 'detail', label: '盘点单信息', componentKey: 'DetailPanel' }, { name: 'items', label: '盘点明细', componentKey: 'CheckItemsPanel' }, { name: 'records', label: '作业记录', componentKey: 'CheckRecordsPanel' } ] /** created/rejected:可加明细、可提交、可取消 */ const EDITABLE_STATUSES: StockCheckStatus[] = ['created', 'rejected'] /** approved/checking:可上报实盘、可完成 */ const RUNNING_STATUSES: StockCheckStatus[] = ['approved', 'checking'] /** 操作列按钮:按行状态显隐(可见即代表后端允许该动作) */ const OPERATION_BUTTONS: OperationButtonConfig[] = [ { key: 'addItems', label: '添加商品', actionType: 'action', type: 'primary', visibleWhen: (row) => EDITABLE_STATUSES.includes(row?.status) }, { key: 'submitCheck', label: '提交审核', actionType: 'action', type: 'primary', confirmMessage: '提交后进入审核流程,期间不可再增删盘点商品。确定提交?', confirmTitle: '提交审核', confirmType: 'warning', confirmButtonText: '确定提交', visibleWhen: (row) => EDITABLE_STATUSES.includes(row?.status) }, { key: 'auditPass', label: '审核通过', actionType: 'action', type: 'primary', confirmMessage: '审核通过后即可开始盘点作业。确定通过?', confirmTitle: '审核通过', confirmType: 'info', confirmButtonText: '确定通过', visibleWhen: (row) => row?.status === 'submitted' }, { key: 'auditReject', label: '驳回', actionType: 'action', type: 'danger', visibleWhen: (row) => row?.status === 'submitted' }, { key: 'finishCheck', label: '完成盘点', actionType: 'action', type: 'success', confirmMessage: '完成盘点后不再允许修改实盘数量。确定完成?(存在未盘明细时后端会拒绝)', confirmTitle: '完成盘点', confirmType: 'warning', confirmButtonText: '确定完成', visibleWhen: (row) => RUNNING_STATUSES.includes(row?.status) }, { key: 'cancelCheck', label: '取消', actionType: 'action', type: 'danger', confirmMessage: '取消后不可恢复,确定取消该盘点单?', confirmTitle: '取消盘点单', confirmType: 'warning', confirmButtonText: '确定取消', visibleWhen: (row) => ['created', 'submitted', 'rejected'].includes(String(row?.status)) }, { key: 'exportCheck', label: '导出', actionType: 'action', type: 'primary', visibleWhen: () => true } ] /** 生成页签配置(单页签:statuses 传空数组,状态筛选交给 ScanBox) */ function buildCheckTab( name: string, label: string, statuses: StockCheckStatus[] ): TabPageRawConfig { return { name, label, scanBoxCacheKey: `stock-check-${name}`, // 筛选:盘点单号/名称(where.keyword)、盘点状态(where.status)、货主(where.store_id) scanBoxFieldKeys: ['keyword', 'status', 'store_id'], tableColumnKeys: TABLE_COLUMN_KEYS, upperTableDefaults: { title: '盘点单列表', showSelection: true, emptyText: '暂无盘点单' }, detailTabs: DETAIL_TABS, detailSections: DETAIL_SECTIONS, api: { list: stockCheckList, // 列表行已含全部主表字段,「盘点单信息」直接用行数据(明细行由「盘点明细」面板单独拉取) detail: { source: 'list' }, export: stockCheckExport, exportProgress: stockCheckExportTaskProgress, parseListResponse(res: any) { const data = res?.data ?? res ?? {} const list = Array.isArray(data.rows) ? data.rows : Array.isArray(data.list) ? data.list : [] const total = Number(data.total ?? data.pagination?.total ?? list.length) return { list, total: Number.isFinite(total) ? total : list.length } }, buildListParams({ pagination, conditions }) { return { pagination: { page: pagination.page, pageSize: pagination.pageSize }, where: { ...buildWhereConditions(conditions), // statuses 非空时固定状态(列表接口 status 支持数组);单页签传空数组 → 由 ScanBox 控制 ...(statuses.length ? { status: [...statuses] } : {}) } } } }, operationButtons: OPERATION_BUTTONS } } /** * 单页签列表:全部盘点单共用一个列表,状态筛选交给 ScanBox 的「盘点状态」。 * 如需恢复成按状态分页签,直接多调几次 buildCheckTab 即可,例如: * buildCheckTab('todo', '待提交', ['created', 'rejected']) */ export const tabPages: TabPageRawConfig[] = [ buildCheckTab('all', '盘点单', []) ] // ============================================================ // 十三、向后兼容导出 // ============================================================ export const templateTabs = tabPages.map((t) => ({ name: t.name, label: t.label, scanBoxCacheKey: t.scanBoxCacheKey }))