diff --git a/web-admin/scripts/quota-statistics.test.ts b/web-admin/scripts/quota-statistics.test.ts index eacb6020e..6d62e958c 100644 --- a/web-admin/scripts/quota-statistics.test.ts +++ b/web-admin/scripts/quota-statistics.test.ts @@ -261,3 +261,31 @@ test('statistics API maps each view to the server endpoint and preserves respons ) assert.deepEqual(calls[1].options.params, { certType: 'transport', pageSize: 20 }) }) + +import * as statisticsLabels from '../src/views/pl/quota-statistics/labels' +test('contract type tags translate all server values and legacy framework', () => { + const template = parse( + readFileSync( + new URL('../src/views/pl/quota-statistics/StatisticsPanel.vue', import.meta.url), + 'utf8' + ) + ).descriptor.template!.content + const expression = template.match( + /v-else-if="column.prop === 'contractType'"[^>]*>\s*\{\{([\s\S]*?)\}\}/ + )![1] + const renderLabel = new Function( + 'row', + ...Object.keys(statisticsLabels), + `return (${expression})` + ) + for (const [contractType, label] of Object.entries({ + sale: '销售合同', + purchase: '采购合同', + framework_sale: '框架销售合同', + framework_purchase: '框架采购合同', + framework: '框架合同', + '': '—' + })) { + assert.equal(renderLabel({ contractType }, ...Object.values(statisticsLabels)), label) + } +}) diff --git a/web-admin/src/views/pl/quota-statistics/StatisticsPanel.vue b/web-admin/src/views/pl/quota-statistics/StatisticsPanel.vue index dcfb0902d..b8d6491f5 100644 --- a/web-admin/src/views/pl/quota-statistics/StatisticsPanel.vue +++ b/web-admin/src/views/pl/quota-statistics/StatisticsPanel.vue @@ -113,11 +113,7 @@ :type="row.status === 'active' ? 'success' : 'info'" >{{ statusLabel(row.status) }}{{ - row.contractType === 'purchase' - ? '采购合同' - : row.contractType === 'sales' - ? '销售合同' - : row.contractType || '—' + contractTypeLabel(row.contractType) }}{{ row[column.prop] ?? '—' }} @@ -161,7 +157,7 @@ import ContractScopeDialog from '../quota-cert/ContractScopeDialog.vue' import StatisticsDetail from './StatisticsDetail.vue' import { createStatisticsLoader } from './loader' - import { statusLabel } from './labels' + import { statusLabel, contractTypeLabel } from './labels' const props = withDefaults( defineProps<{ mode: 'contract' | 'certificate' diff --git a/web-admin/src/views/pl/quota-statistics/labels.ts b/web-admin/src/views/pl/quota-statistics/labels.ts index 192baf5ba..0566013f7 100644 --- a/web-admin/src/views/pl/quota-statistics/labels.ts +++ b/web-admin/src/views/pl/quota-statistics/labels.ts @@ -12,3 +12,14 @@ export const statusLabel = (value: string) => consumed: '已核销', cancelled: '已取消' })[value] || value + +export const contractTypeLabel = (value?: string | null) => + ({ + sale: '销售合同', + purchase: '采购合同', + framework_sale: '框架销售合同', + framework_purchase: '框架采购合同', + framework: '框架合同' + })[value || ''] || + value || + '—'