docs(business): 生成业务契约文档并重构MES客户端代码
- 创建案例.md文档,包含业务场景清单、业务流程、案例和回归测试三份完整文档 - WMS库房管理系统涵盖入库、出库、库存、检验、盘点等24个业务场景 - MES产线控制系统包含工单、排产、BOM、备料、质检、追溯等23个业务场景 - 工位终端系统支持上线、报工、下线、领料、巡检等15个现场作业场景 - 主链路从合同到成品入库,异常链路处理不合格、数量不符、退料等情况 - 删除MES客户端中的ScanRecord相关代码,精简客户端结构 - 更新客户端初始化逻辑,移除扫描记录相关的依赖注入配置
This commit is contained in:
@@ -1,5 +1,42 @@
|
||||
import request from './request'
|
||||
import { getToken } from './auth'
|
||||
import { confirmAction } from './confirm'
|
||||
|
||||
// 导出前统一确认:告知用户即将导出的数据条数。
|
||||
// count 为 null/undefined 时(无法预知条数)提示“全部”;否则回显具体条数。
|
||||
export async function confirmExport(count, name = '数据') {
|
||||
const msg = (count === null || count === undefined)
|
||||
? `即将导出全部${name},是否继续?`
|
||||
: `即将导出 ${count} 条${name},是否继续?`
|
||||
return confirmAction(msg, '导出确认', { confirmButtonText: '确认导出', cancelButtonText: '取消' })
|
||||
}
|
||||
|
||||
function ymd(d) {
|
||||
const p = (n) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
||||
}
|
||||
|
||||
// effExportParams 归一化导出日期参数,避免后端 normalizeExportRange「只传一端即报错(400)」:
|
||||
// 仅当 params 显式带有 startDate/endDate 键时生效;一端为空则补齐(缺结束=今天,缺起始=结束前推3个月);
|
||||
// 两端都空则保持为空(由后端按各自规则处理,列表与导出用同一份参数,条数才一致)。
|
||||
export function effExportParams(params) {
|
||||
if (!params || (!('startDate' in params) && !('endDate' in params))) return params
|
||||
let s = params.startDate || ''
|
||||
let e = params.endDate || ''
|
||||
if (s && !e) e = ymd(new Date())
|
||||
else if (!s && e) { const d = new Date(e); d.setMonth(d.getMonth() - 3); s = ymd(d) }
|
||||
return { ...params, startDate: s, endDate: e }
|
||||
}
|
||||
|
||||
// countByQuery 用与导出完全相同的筛选参数请求列表接口(pageSize=1)拿精确总数,
|
||||
// 保证「确认框条数」= 实际导出条数(列表与导出共用同一套 where 条件)。
|
||||
async function countByQuery(countUrl, params) {
|
||||
try {
|
||||
const data = await request.get(countUrl, { params: { ...params, page: 1, pageSize: 1 } })
|
||||
const t = data?.total
|
||||
return (t === null || t === undefined) ? null : Number(t)
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
// 下载 xlsx 导出:后端返回 .xlsx 二进制,文件名由后端 Content-Disposition 指定。
|
||||
// 各导出接口:{path}?format=xlsx&<筛选参数>
|
||||
@@ -33,8 +70,18 @@ export function exportXlsx(path, params, fallbackName = '导出.xlsx') {
|
||||
}
|
||||
|
||||
// 带 token 的二进制下载(保底方式:直接构造带 Authorization 的 fetch)
|
||||
export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx') {
|
||||
const qs = new URLSearchParams({ format: 'xlsx', ...params }).toString()
|
||||
// confirm:导出前确认。默认 true=弹确认框但不显示条数(提示“全部”);
|
||||
// 传 { count, name } 直接回显条数;或传 { countUrl, name } 由本函数用相同筛选参数拉取精确条数;
|
||||
// 传 false 可跳过确认(不建议)。
|
||||
export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx', confirm = true) {
|
||||
const eff = effExportParams(params)
|
||||
if (confirm) {
|
||||
const opt = confirm === true ? {} : confirm
|
||||
let count = (opt.count === null || opt.count === undefined) ? null : opt.count
|
||||
if (count === null && opt.countUrl) count = await countByQuery(opt.countUrl, eff)
|
||||
if (!(await confirmExport(count, opt.name))) return null
|
||||
}
|
||||
const qs = new URLSearchParams({ format: 'xlsx', ...eff }).toString()
|
||||
const res = await fetch(`${path}?${qs}`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` }
|
||||
})
|
||||
@@ -64,4 +111,4 @@ export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx'
|
||||
return filename
|
||||
}
|
||||
|
||||
export default { exportXlsx, exportXlsxFetch }
|
||||
export default { exportXlsx, exportXlsxFetch, confirmExport }
|
||||
Reference in New Issue
Block a user