feat: 保存运输证件、报销付款和开发流程的当前实现。

补齐证书齐备、证件折算、移动用证和合同绑定,并带上报销批量发放、付款备注以及个人开发流程升级,便于继续讨论已安排计划的调整规则。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-04 21:42:33 +08:00
1 parent 7325a0aa52
commit 8e9536332a
202 files changed
+19200 -2054

No files matched your search

+9 -2
View File
@@ -63,8 +63,11 @@ export function getProductUnitLabel(
getLabel: (dictType: string, value: string) => string,
unit: string | null | undefined
): string {
if (!unit) return '—'
return getLabel('crm_product_unit', unit) || unit
const raw = String(unit || '').trim()
if (!raw) return '—'
const fromDict = getLabel('crm_product_unit', raw)
if (fromDict && fromDict !== raw && fromDict !== '—') return fromDict
return PRODUCT_UNIT_VALUE_TO_LABEL[raw] || fromDict || raw
}
/** CRM 计量单位「吨」的字典值及历史直存文案 */
@@ -87,6 +90,10 @@ const PRODUCT_UNIT_LABEL_TO_VALUE: Record<string, string> = {
台: 'unit'
}
const PRODUCT_UNIT_VALUE_TO_LABEL: Record<string, string> = Object.fromEntries(
Object.entries(PRODUCT_UNIT_LABEL_TO_VALUE).map(([label, value]) => [value, label])
)
/**
* 表单写入 / 提交用:统一为 crm_product_unit 字典值。
* 空值默认 dun;历史直存「吨」等中文标签映射为对应 value。
@@ -0,0 +1,26 @@
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { SX_SEAL_URL, YD_SEAL_URL, rewriteContractSealSources } from './contract-seal-assets.ts'
describe('rewriteContractSealSources', () => {
it('points saved seal images at the small public files', () => {
const html = [
'<img src="/src/assets/images/yz.png" alt="印章" />',
'<img src="https://w.shanxiachem.com/src/assets/images/yd.png" alt="印章" />',
'<img src="/assets/yz-Ab12cd.png" alt="印章" />',
'<img src="/logo.gif" alt="logo" />'
].join('')
const out = rewriteContractSealSources(html)
assert.equal(out.includes('/src/assets/images/yz.png'), false)
assert.equal(out.includes('/src/assets/images/yd.png'), false)
assert.equal(out.includes('/assets/yz-Ab12cd.png'), false)
assert.equal(out.includes(`src="${SX_SEAL_URL}"`), true)
assert.equal(out.includes(`src="${YD_SEAL_URL}"`), true)
assert.equal(out.includes('/logo.gif'), true)
})
it('leaves the small seal url unchanged', () => {
const html = `<img src="${SX_SEAL_URL}" alt="印章" /><p>正文</p>`
assert.equal(rewriteContractSealSources(html), html)
})
})
@@ -0,0 +1,20 @@
/** 富文本里的印章小图。页面只显示约 140px,源图宽 280px,避免再解码 2MB 原图。 */
export const SX_SEAL_URL = '/seals/yz.png'
export const YD_SEAL_URL = '/seals/yd.png'
const SX_FILE = /(?:^|\/)yz(?:-[A-Za-z0-9_-]+)?\.png(?:[?#].*)?$/i
const YD_FILE = /(?:^|\/)yd(?:-[A-Za-z0-9_-]+)?\.png(?:[?#].*)?$/i
const IMG_SRC_RE = /(<img\b[^>]*\bsrc=["'])([^"']+)(["'])/gi
const isSmallSeal = (src: string, url: string) => src === url || src.endsWith(url)
/** 已保存模板里的原图、绝对地址和打包哈希文件名,打开编辑器前换成小图。 */
export const rewriteContractSealSources = (html: string): string => {
if (!html) return html
return html.replace(IMG_SRC_RE, (full, prefix: string, src: string, suffix: string) => {
if (isSmallSeal(src, SX_SEAL_URL) || isSmallSeal(src, YD_SEAL_URL)) return full
if (SX_FILE.test(src)) return `${prefix}${SX_SEAL_URL}${suffix}`
if (YD_FILE.test(src)) return `${prefix}${YD_SEAL_URL}${suffix}`
return full
})
}
+10 -2
View File
@@ -6,6 +6,13 @@ import axios, { type AxiosRequestConfig, type InternalAxiosRequestConfig } from
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/store/modules/user'
declare module 'axios' {
interface AxiosRequestConfig {
/** 为 true 时不弹出全局错误,由调用方自行提示 */
skipErrorMessage?: boolean
}
}
export interface BxApiResponse<T = unknown> {
code: number
msg: string
@@ -63,7 +70,8 @@ const bxAxios = axios.create({
})
/** FastAPI @router.get("/") 集合根须带尾斜杠,否则 307 重定向到绝对 URL 会丢 Authorization */
const BX_COLLECTION_ROOT = /^\/(transport\/(order|plan|freight)|reimburses|advances|payments|workflows|expense-items)$/
const BX_COLLECTION_ROOT =
/^\/(transport\/(order|plan|freight)|reimburses|advances|payments|workflows|expense-items)$/
function normalizeBxUrl(url?: string): string | undefined {
if (!url || url.endsWith('/')) return url
@@ -147,7 +155,7 @@ bxAxios.interceptors.response.use(
if (err.response?.status === 401) {
const userStore = useUserStore()
await userStore.logOut()
} else {
} else if (!err.config?.skipErrorMessage) {
const detail = err.response?.data?.detail || err.response?.data?.msg
const message =
typeof detail === 'string'
@@ -1,8 +1,10 @@
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
alignStopProductUnitToContract,
allowedPackageSpecsForStopProduct,
collectContractProductRows
collectContractProductRows,
stopProductUnitLocked
} from './pl-plan-contract-product'
const hydrochloricAcid = collectContractProductRows([
@@ -48,3 +50,33 @@ describe('allowedPackageSpecsForStopProduct', () => {
)
})
})
describe('stop product unit from contract', () => {
const lines = [
{ id: 'line-1', productId: 'acid', unit: '吨' },
{ id: 'line-1', productId: 'acid', unit: '' }
]
it('locks the unit only after a contract line is bound', () => {
assert.equal(stopProductUnitLocked({ contractProductId: '' }), false)
assert.equal(stopProductUnitLocked({ contractProductId: 'line-1' }), true)
})
it('rewrites a different unit to the contract unit', () => {
const row = { contractProductId: 'line-1', unit: 'kg' }
assert.equal(alignStopProductUnitToContract(row, lines), true)
assert.equal(row.unit, 'dun')
})
it('treats 吨 and dun as the same unit', () => {
const row = { contractProductId: 'line-1', unit: 'dun' }
assert.equal(alignStopProductUnitToContract(row, lines), false)
assert.equal(row.unit, 'dun')
})
it('leaves an unbound row unit unchanged', () => {
const row = { contractProductId: '', unit: 'kg' }
assert.equal(alignStopProductUnitToContract(row, lines), false)
assert.equal(row.unit, 'kg')
})
})
@@ -1,4 +1,5 @@
import { resolvePackageSpecsFromPayload } from '@/utils/crm-package-spec'
import { normalizeProductUnitValue } from '@/utils/crm-product-display'
/** 从合同明细行收集 CRM productId */
export function collectContractProductIds(
@@ -45,6 +46,7 @@ export type ContractLineChoice = {
contractId: string
contractNo: string
label: string
unit: string
}
/** 同一产品在当前合同里的明细行,供历史行原位补合同编号。 */
@@ -68,6 +70,7 @@ export function contractLineChoicesForProduct(
id,
contractId,
contractNo,
unit: String(row.unit || '').trim() ? normalizeProductUnitValue(row.unit) : '',
label: specs.length ? `${contractNo} ${specs.join('、')}` : contractNo
})
}
@@ -212,6 +215,42 @@ export function allowedPackageSpecsForStopProduct(
return packageSpecsForProduct(boundRows, pid)
}
/** 已绑定合同产品行时,单位跟合同走,不能再改。 */
export function stopProductUnitLocked(row: { contractProductId?: string | null }): boolean {
return Boolean(String(row.contractProductId || '').trim())
}
/** 合同明细上的单位。同一明细被按包装拆成多行时,取第一条有单位的记录。 */
export function boundContractProductUnit(
rows: ContractProductRowLite[] | null | undefined,
contractProductId?: string | null
): string {
const boundId = String(contractProductId || '').trim()
if (!boundId) return ''
for (const row of rows || []) {
if (String(row.id || '').trim() !== boundId) continue
const unit = String(row.unit || '').trim()
if (unit) return normalizeProductUnitValue(unit)
}
return ''
}
/**
* 把已绑定行的单位改成合同单位。
* 返回 true 表示本次改写了单位,调用方应提示按合同单位核对数量。
*/
export function alignStopProductUnitToContract(
row: { contractProductId?: string | null; unit?: string | null },
rows: ContractProductRowLite[] | null | undefined
): boolean {
if (!stopProductUnitLocked(row)) return false
const contractUnit = boundContractProductUnit(rows, row.contractProductId)
if (!contractUnit) return false
if (normalizeProductUnitValue(row.unit) === contractUnit) return false
row.unit = contractUnit
return true
}
export function isPackageAllowedForContractProduct(
rows: ContractProductRowLite[] | null | undefined,
productId: string,
+2
View File
@@ -45,6 +45,8 @@ export interface PlanStopProductFormRow {
contractId?: string
contractProductId?: string
contractNo?: string
/** 打开旧单时单位曾与合同不一致,提示按合同单位核对数量。不提交。 */
contractUnitNote?: string
}
/** 段次查看/归档:装货段取 inbound,送货段取 outbound */
@@ -0,0 +1,19 @@
/** 已标记证书齐备时,只保留服务端仍要拦住的来源问题,不再用本地两证缺口补一条拦截。 */
export function toxicArrangeBlockMessage(
quota: { quotaCertWaived?: boolean; arrangeBlockMessage?: string } | null | undefined,
unboundMessage: string
) {
const serverMessage = (quota?.arrangeBlockMessage || '').trim()
if (quota?.quotaCertWaived) return serverMessage
return serverMessage || unboundMessage
}
export function certReadyErrorText(error: unknown, fallback: string) {
const detail = (error as { response?: { data?: { detail?: unknown } } })?.response?.data?.detail
return typeof detail === 'string' && detail.trim() ? detail : fallback
}
export function formatCertReadyTime(value?: string | null) {
if (!value) return '—'
return value.replace('T', ' ').slice(0, 16)
}
@@ -3,7 +3,8 @@ import { describe, it } from 'node:test'
import {
applyColumnWidthDelta,
applyRowHeightDelta,
clampColumnWidthsToMax
clampColumnWidthsToMax,
isInsideEdgeBand
} from './tinymce-table-edge-resize.ts'
describe('applyColumnWidthDelta', () => {
@@ -35,6 +36,14 @@ describe('clampColumnWidthsToMax', () => {
})
})
describe('isInsideEdgeBand', () => {
it('stays false until the pointer is inside the edge band', () => {
assert.equal(isInsideEdgeBand(9, true, 8), false)
assert.equal(isInsideEdgeBand(8, false, 8), false)
assert.equal(isInsideEdgeBand(8, true, 8), true)
})
})
describe('applyRowHeightDelta', () => {
it('keeps row height at or above 20px', () => {
assert.equal(applyRowHeightDelta(30, 10), 40)
@@ -11,6 +11,13 @@ export const MIN_ROW_PX = 20
export const A4_CONTENT_WIDTH_PX = 680
const EDGE_PX = 8
/** 只有指针已经进入边线热区,才需要继续判断列号。列号要扫整张表。 */
export const isInsideEdgeBand = (
distanceToEdge: number,
insideCrossAxis: boolean,
edgePx = EDGE_PX
): boolean => insideCrossAxis && distanceToEdge <= edgePx
const HANDLE_PX = 8
const LAYER_ID = 'sx-edge-resize-layer'
const HANDLE_CLASS = 'sx-edge-resize-handle'
@@ -233,6 +240,7 @@ const handleMeta = new WeakMap<
export const setupTableEdgeResize = (editor: any): void => {
let state: DragState | null = null
let layer: HTMLElement | null = null
let hover: { cell: HTMLTableCellElement; kind: 'col' | 'row' } | null = null
const docOf = (): Document | null => (editor.getDoc?.() as Document | null) ?? null
const bodyOf = (): HTMLElement | null => (editor.getBody?.() as HTMLElement | null) ?? null
@@ -300,17 +308,26 @@ export const setupTableEdgeResize = (editor: any): void => {
const fromBottom = Math.abs(event.clientY - rect.bottom)
const insideY = event.clientY >= rect.top - EDGE_PX && event.clientY <= rect.bottom + EDGE_PX
const insideX = event.clientX >= rect.left - EDGE_PX && event.clientX <= rect.right + EDGE_PX
const canCol = row.rowIndex === 0 && (cell.colSpan || 1) === 1 && fromRight <= EDGE_PX && insideY
const canRow = columnOrigin(table, cell) === 0 && fromBottom <= EDGE_PX && insideX
const nearRight = isInsideEdgeBand(fromRight, insideY)
const nearBottom = isInsideEdgeBand(fromBottom, insideX)
if (!nearRight && !nearBottom) return null
const canCol = nearRight && row.rowIndex === 0 && (cell.colSpan || 1) === 1
const canRow = nearBottom && columnOrigin(table, cell) === 0
if (canCol && canRow) return { cell, kind: fromRight <= fromBottom ? 'col' : 'row' }
if (canCol) return { cell, kind: 'col' }
if (canRow) return { cell, kind: 'row' }
return null
}
const clearHover = () => {
if (!hover && !layer?.childElementCount) return
hover = null
clearHandle()
}
const onMouseMove = (event: MouseEvent) => {
if (isReadonly(editor)) {
clearHandle()
clearHover()
return
}
if (state) {
@@ -331,9 +348,11 @@ export const setupTableEdgeResize = (editor: any): void => {
if (target?.classList?.contains(HANDLE_CLASS)) return
const edge = edgeCell(event)
if (!edge) {
clearHandle()
clearHover()
return
}
if (hover && hover.cell === edge.cell && hover.kind === edge.kind) return
hover = { cell: edge.cell, kind: edge.kind }
placeHandle(edge.cell, edge.kind)
}
@@ -400,6 +419,7 @@ export const setupTableEdgeResize = (editor: any): void => {
layer?.remove()
layer = null
state = null
hover = null
}
editor.on('BeforeGetContent', () => {
-11
View File
@@ -134,14 +134,3 @@ export const refreshFilterCollapse = (): void => {
})
}
export const setupFilterCollapseObserver = (): MutationObserver => {
refreshFilterCollapse()
const observer = new MutationObserver(() => {
refreshFilterCollapse()
})
observer.observe(document.body, {
childList: true,
subtree: true
})
return observer
}