feat: 合同付款预警迁移到agent页面
This commit is contained in:
1 parent
ef6bc42c20
commit
4ce2defef0
49 files changed
+1052
-423
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* features/contract-payment/utils/contractPaymentChat.utils.test.ts
|
||||
* 用途:锁定合同付款预警 Chat 深链 query 的解析与回写规则。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
buildContractPaymentChatQuery,
|
||||
parseContractPaymentChatQuery,
|
||||
} from './contractPaymentChat.utils';
|
||||
|
||||
describe('parseContractPaymentChatQuery', () => {
|
||||
it('accepts ledger / review / batches and a positive contractId', () => {
|
||||
expect(parseContractPaymentChatQuery('review', '12')).toEqual({
|
||||
view: 'review',
|
||||
contractId: 12,
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to ledger for unknown view and ignores invalid contractId', () => {
|
||||
expect(parseContractPaymentChatQuery('unknown', 'abc')).toEqual({
|
||||
view: 'ledger',
|
||||
contractId: null,
|
||||
});
|
||||
expect(parseContractPaymentChatQuery(undefined, '0')).toEqual({
|
||||
view: 'ledger',
|
||||
contractId: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildContractPaymentChatQuery', () => {
|
||||
it('always writes view and omits contractId on list pages', () => {
|
||||
expect(buildContractPaymentChatQuery('batches', null)).toEqual({ view: 'batches' });
|
||||
});
|
||||
|
||||
it('keeps the current tab when drilling into a contract', () => {
|
||||
expect(buildContractPaymentChatQuery('review', 9)).toEqual({
|
||||
view: 'review',
|
||||
contractId: '9',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* features/contract-payment/utils/contractPaymentChat.utils.ts
|
||||
* 用途:解析合同付款预警 Chat 的 view / contractId 查询参数。
|
||||
* 依赖:contract-payment/constants。
|
||||
* 逻辑:旧工作台重定向与 Chat Tab 共用;非法 view 回退台账。
|
||||
*/
|
||||
import { CONTRACT_PAYMENT_VIEWS, type ContractPaymentView } from '../constants';
|
||||
|
||||
export interface ContractPaymentChatQuery {
|
||||
view: ContractPaymentView;
|
||||
contractId: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把路由 query 归一成 Chat 台账视图。
|
||||
* 核心逻辑:只接受 ledger / review / batches;contractId 必须是正整数才进入详情下钻。
|
||||
* @param rawView - 路由 query.view
|
||||
* @param rawContractId - 路由 query.contractId
|
||||
* @returns 可安全写入 Tab 与详情状态的查询对象
|
||||
*/
|
||||
export function parseContractPaymentChatQuery(
|
||||
rawView: unknown,
|
||||
rawContractId: unknown,
|
||||
): ContractPaymentChatQuery {
|
||||
const view = CONTRACT_PAYMENT_VIEWS.includes(String(rawView) as ContractPaymentView)
|
||||
? String(rawView) as ContractPaymentView
|
||||
: 'ledger';
|
||||
const parsed = Number(rawContractId);
|
||||
const contractId = Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
||||
return { view, contractId };
|
||||
}
|
||||
|
||||
/**
|
||||
* 把台账视图写回 Chat 路由 query,便于刷新与旧工作台重定向共用同一深链。
|
||||
* 核心逻辑:始终带 view;仅在下钻详情时带 contractId,避免空 query 污染地址栏。
|
||||
* @param view - 当前 Tab
|
||||
* @param contractId - 详情合同 ID;列表态传 null
|
||||
*/
|
||||
export function buildContractPaymentChatQuery(
|
||||
view: ContractPaymentView,
|
||||
contractId: number | null,
|
||||
): Record<string, string> {
|
||||
const query: Record<string, string> = { view };
|
||||
if (contractId) query.contractId = String(contractId);
|
||||
return query;
|
||||
}
|
||||
Reference in new issue
Block a user