新版界面(React + TypeScript + Vite + Ant Design):登录页与开单页

共用计算经构建插件直接导入 public/ 下的 UMD 源文件;请求客户端沿用旧界面的重试、
同一操作号自动确认、恢复原操作与账号切换约定;附 vitest 单元与组件测试。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
黄健铭andClaude Opus 5.5 committed 2026-12-04 18:58:31 -08:00
1 parent bdffbcab85
commit ec5889075f
39 files changed
+8772

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
// 共用计算模块的唯一入口:与旧界面、服务端读取同一份源文件(../public/*.js),不复制业务算法。
import LedgerCalc from '@public/calculations.js';
import CreditCardFees from '@public/credit-card-fees.js';
import FeeEstimates from '@public/fee-estimates.js';
import OrderFormula from '@public/order-formula.js';
import OrderTemplates from '@public/order-templates.js';
import OrderCopy from '@public/order-copy.js';
import OrderEntryModel from '@public/order-entry-model.js';
export const Calc = LedgerCalc;
export const Cards = CreditCardFees;
export const Fees = FeeEstimates;
export const Formula = OrderFormula;
export const Templates = OrderTemplates;
export const Copy = OrderCopy;
export const Model = OrderEntryModel;
export type * from './types';
+340
View File
@@ -0,0 +1,340 @@
// 共用 UMD 模块(../public/*.js)与服务端接口的类型描述。只描述新版界面用到的部分。
export interface MemberRow {
member: string;
label: string;
enabled?: boolean;
operatorName?: string;
}
export interface SessionUser {
id: string;
name: string;
role: 'owner' | 'assistant';
member: string;
operatorName?: string;
label?: string;
}
export interface SessionInfo {
user: SessionUser | null;
setup: boolean;
mode: 'trial' | 'demo' | 'production';
today: string;
brand?: { storeName?: string };
loginOptions?: { member: string; label: string }[];
}
export interface PocketRow {
key: string;
name?: string;
countUnit?: 'pair' | null;
active?: boolean;
}
export interface LedgerState {
today: string;
mode: string;
user: SessionUser;
members?: MemberRow[];
shopSettings?: {
storeName?: string;
members?: MemberRow[];
feeDefaults?: Record<string, string>;
costPresets?: Record<string, unknown>;
creditCardRatePermille?: number;
};
pockets?: string[];
pocketCatalog?: PocketRow[];
accounts?: string[];
printing?: { store?: string };
}
export interface ChargeState {
id: string;
type: string;
customName: string;
amount: string;
prices: Record<string, string>;
costRemoved?: boolean;
}
export interface PurchaseState {
materialMode: 'gram' | 'total';
materialRate: string;
material: string;
materialPayer: string;
laborMode: 'gram' | 'total';
laborRate: string;
labor: string;
laborPayer: string;
accessories: string;
other: string;
dataMode: string;
preferredMode: string;
dataUnit: string;
total: string;
originalTotal: string;
}
export interface PoolState {
source: 'manual' | 'pool';
poolId: string;
dataPoolId: string;
dataSource: string;
preferredSource: string;
defaultDate: boolean;
allowed: boolean;
options: { value: string; label: string }[];
help?: string;
payerText?: string;
personal?: boolean;
preview: { amount: number | null } | null;
}
export interface LineView {
calculation: string;
materialFormula: string;
laborFormula: string;
materialOriginal: string;
poolNote: string;
saleCents?: number | null;
purchase?: { total: number | null; parts: Record<string, number | null> } | null;
}
export interface LineState {
legacy: boolean;
historicalPocket: boolean;
nameType: string;
customName: string;
pricingMode: 'auto' | 'manual';
unit: 'g' | '件';
quantity: string;
goldPrice: string;
laborMode: 'gram' | 'piece';
laborRate: string;
pieces: string;
priceNote: string;
baseSale: string;
sale: string;
pocket: string;
stockCount: string;
payer: string;
cost: string;
charges: ChargeState[];
purchase: PurchaseState | null;
pool: PoolState | null;
view: LineView;
}
export interface FeeRowState {
key: string;
note: string;
amount: string;
payer: string;
sourceName: string;
edited: boolean;
status: string;
lineNumber?: number;
automatic?: unknown;
}
export interface PresetState {
configured: boolean;
checked: Record<string, boolean>;
quantity: Record<string, string>;
}
export interface PaymentState {
method: string;
recipient: string;
nonCardRecipient: string;
cardLocked: boolean;
}
export interface OrderForm {
copy_kind: string;
id: string;
revision: string | number;
paper_date: string;
paper_number: string;
rounding_mode: 'yuan' | 'cent';
memberLocked: boolean;
member: string;
date: string;
customer: string;
customer_type: '' | 'new' | 'returning';
customerTypeRequired: boolean;
salesperson: string;
payment: PaymentState;
credit_card_fee_payer: string;
fees_date: string;
feeCostMode: string;
discount: string;
note: string;
internal_note: string;
presets: PresetState | null;
feeRows: FeeRowState[];
lines: LineState[];
}
/** 与旧页面 collectDraft() 相同结构,即 /api/orders/issue 的请求体。 */
export interface OrderDraft {
id?: string;
revision?: number;
date: string;
customer: string;
salesperson: string;
internal_note: string;
payment_account: string;
rounding_mode: 'yuan' | 'cent';
discount: string;
lines: Record<string, unknown>[];
fee_items: Record<string, unknown>[];
[key: string]: unknown;
}
export interface FormSummary {
total: number | null;
totalText: string;
roundingHint: string;
card: { rate: number; amount: number | null; amountText: string; formula: string } | null;
feesText: string;
presetNotes: Record<string, string>;
}
export interface MaterialPools {
rows: unknown[];
rolling?: { enabled?: boolean; cutover?: string };
current?: unknown;
}
export interface QuoteState {
input: unknown;
result: unknown;
error: string;
}
export interface SyncContext {
st: LedgerState;
session?: SessionInfo | null;
uuid: () => string;
materialPools?: MaterialPools | null;
quote?: QuoteState | null;
}
export interface LineVisibility {
customName: boolean;
goldPrice: boolean;
laborMode: boolean;
laborRate: boolean;
pieces: boolean;
priceNote: boolean;
baseSale: boolean;
stockCount: boolean;
stockCountOptional: boolean;
materialRate: boolean;
materialMode: boolean;
materialPayer: boolean;
materialReadOnly: boolean;
laborRateInput: boolean;
laborReadOnly: boolean;
poolAllowed: boolean;
extraCosts: boolean;
}
export interface PresetCatalogItem {
kind: string;
name: string;
price: string;
payer: string;
byQuantity?: boolean;
shipping?: boolean;
}
export interface LedgerCalcApi {
cents(value: unknown, name?: string): number;
isSilver(name: string): boolean;
sale(line: unknown): { sale: number; baseSale: number; chargesTotal: number; charges: unknown[] };
orderTotal(
lines: number[],
discount?: number,
mode?: 'yuan' | 'cent',
): { total: number; unroundedTotal: number; rounding_adjustment: number; rounding_mode: string; subtotal: number };
purchaseCosts(line: unknown): { total: number | null; parts: Record<string, number | null> };
costLabels: Record<string, string>;
}
export interface CreditCardFeesApi {
isAccount(account: string): boolean;
amount(cents: number, rate?: number): number;
normalizeAccount(account: string): string;
ratePermille: number;
}
export interface FeeEstimatesApi {
presets(values?: unknown): Record<string, { amount: string; payer: string }>;
checkboxCategory(name: string): string;
normalize(name: string): string;
}
export interface OrderFormulaApi {
parseBatch(
input: string,
options: { roundingMode: string },
): {
items: { line: Record<string, string> & { charges: { amount: string }[] }; subtotal: number }[];
lines: (Record<string, string> & { charges: { name: string; amount: string }[] })[];
subtotal: number;
total: number;
roundingMode: string;
mismatch: boolean;
warnings: string[];
};
}
export interface OrderTemplatesApi {
fromDraft(draft: unknown, options: { pocketKeys: string[]; newId?: () => string }): unknown;
apply(
preset: unknown,
options: { today: string; salesperson: string; pocketKeys: string[]; newId?: () => string },
): Record<string, unknown> & { member?: string; salesperson?: string };
}
export interface OrderEntryModelApi {
productNames: string[];
chargeNames: string[];
yuan(cents: number | null | undefined): string;
grams(mg: number): string;
orderAmount(value: number | null, mode: string): string;
teamMode(st: LedgerState): boolean;
currentMember(st: LedgerState, session?: SessionInfo | null): string;
memberKeys(st: LedgerState): string[];
memberName(st: LedgerState, member: string): string;
memberOptions(st: LedgerState, assistantFirst?: boolean, options?: { selected?: string }): [string, string][];
defaultSalesperson(st: LedgerState, session?: SessionInfo | null): string;
activePocketKeys(st: LedgerState): string[];
pocketOptions(st: LedgerState, selected?: string, historical?: boolean): [string, string, boolean?][];
pocketCountsEnabled(st: LedgerState, key: string): boolean;
creditCardAvailable(st: LedgerState): boolean;
newCharge(c: Record<string, unknown>, uuid: () => string): ChargeState;
changeChargeType(charge: ChargeState, type: string): ChargeState;
setChargeAmount(charge: ChargeState, amount: string): ChargeState;
setLineField(line: LineState, field: string, value: string): LineState;
setPurchaseField(line: LineState, field: string, value: string): LineState;
setPoolSource(line: LineState, source: 'manual' | 'pool'): LineState;
lineVisibility(line: LineState, st: LedgerState): LineVisibility;
poolQuoteInput(form: OrderForm, ctx: SyncContext): { date: string; member: string; entries: unknown[] };
feeSourceText(row: FeeRowState): string;
editFeeRow(form: OrderForm, index: number, field: 'amount' | 'payer' | 'note', value: string): OrderForm;
addManualFee(form: OrderForm, st: LedgerState, uuid: () => string): OrderForm;
removeFeeRow(form: OrderForm, index: number): OrderForm;
restoreChargeCost(form: OrderForm, lineIndex: number, chargeIndex: number): OrderForm;
togglePreset(form: OrderForm, kind: string, checked: boolean, st: LedgerState, uuid: () => string): OrderForm;
setPresetQuantity(form: OrderForm, kind: string, value: string): OrderForm;
presetCatalogView(form: OrderForm, st: LedgerState): PresetCatalogItem[];
paymentMethods(st: LedgerState): string[];
recipientOptions(st: LedgerState, payment: PaymentState): [string, string][];
readPaymentAccount(form: OrderForm): string;
changeMember(form: OrderForm, member: string, st: LedgerState): OrderForm;
isBlankDraft(draft: unknown): boolean;
newForm(ctx: SyncContext, draft?: unknown): OrderForm;
addLine(form: OrderForm, ctx: SyncContext): OrderForm;
removeLine(form: OrderForm, index: number): OrderForm;
addCharge(form: OrderForm, lineIndex: number, uuid: () => string): OrderForm;
updateLine(form: OrderForm, index: number, line: LineState): OrderForm;
collectDraft(form: OrderForm, st: LedgerState): OrderDraft;
syncForm(form: OrderForm, ctx: SyncContext): { form: OrderForm; draft: OrderDraft; summary: FormSummary };
validateFormFields(form: OrderForm, st: LedgerState): void;
validateIssueDraft(draft: OrderDraft, st: LedgerState): OrderDraft;
draftInputs(order: unknown): Record<string, unknown>;
filterNoteTags(tags: string[], text: string): string[];
insertNoteTag(text: string, tag: string): string;
}
export interface OrderEntryModelApi {
isFormulaBlank(line: LineState): boolean;
applyFormulaLines(
form: OrderForm,
lines: Record<string, unknown>[],
ctx: SyncContext,
): { form: OrderForm; filled: number[] };
}
export interface OrderCopyApi {
hasDraftContent(draft: unknown, options: { today: string; salesperson: string }): boolean;
}
+29
View File
@@ -0,0 +1,29 @@
// ../public/ 下的共用 UMD 文件经 vite.config.ts 的 sharedUmd 插件变为 ES 默认导出。
declare module '@public/calculations.js' {
const api: import('./types').LedgerCalcApi;
export default api;
}
declare module '@public/credit-card-fees.js' {
const api: import('./types').CreditCardFeesApi;
export default api;
}
declare module '@public/fee-estimates.js' {
const api: import('./types').FeeEstimatesApi;
export default api;
}
declare module '@public/order-formula.js' {
const api: import('./types').OrderFormulaApi;
export default api;
}
declare module '@public/order-templates.js' {
const api: import('./types').OrderTemplatesApi;
export default api;
}
declare module '@public/order-entry-model.js' {
const api: import('./types').OrderEntryModelApi;
export default api;
}
declare module '@public/order-copy.js' {
const api: import('./types').OrderCopyApi;
export default api;
}