第6项:统一业务控件、主题与移动布局,保留原生输入和焦点契约
This commit is contained in:
1 parent
ff8b05973a
commit
c6ad648d7e
74 files changed
+3564
-2443
No files matched your search
@@ -17,25 +17,14 @@ interface CheckProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'
|
||||
value?: boolean;
|
||||
update: (v: boolean) => void;
|
||||
}
|
||||
export interface LockPayment {
|
||||
method: string;
|
||||
recipient: string;
|
||||
payer: string;
|
||||
verified: boolean;
|
||||
amount: string;
|
||||
}
|
||||
export interface SavedPayment {
|
||||
account?: string;
|
||||
credit_card_fee_payer?: string;
|
||||
verified?: boolean;
|
||||
amount?: string;
|
||||
}
|
||||
import type { LockPayment } from './formValues';
|
||||
interface PaymentProps {
|
||||
state: LedgerState;
|
||||
payment: LockPayment;
|
||||
change: (p: LockPayment) => void;
|
||||
}
|
||||
import { Model, Cards, Calc } from '../../shared';
|
||||
import { Model, Cards } from '../../shared';
|
||||
import { LedgerButton, LedgerInput, LedgerSelect } from '../../components/BusinessControls';
|
||||
|
||||
export function Field({
|
||||
label,
|
||||
@@ -50,7 +39,7 @@ export function Field({
|
||||
return (
|
||||
<label hidden={hidden}>
|
||||
{label}
|
||||
<input
|
||||
<LedgerInput
|
||||
type={type}
|
||||
name={name}
|
||||
value={value ?? ''}
|
||||
@@ -68,7 +57,12 @@ export function Choice({ label, name, value, options, update, children, hidden,
|
||||
return (
|
||||
<label hidden={hidden}>
|
||||
{label}
|
||||
<select name={name} value={value ?? ''} {...props} onChange={update ? e => update(e.target.value) : undefined}>
|
||||
<LedgerSelect
|
||||
name={name}
|
||||
value={value ?? ''}
|
||||
{...props}
|
||||
onChange={update ? e => update(e.target.value) : undefined}
|
||||
>
|
||||
{options.map(v => {
|
||||
const [k, title, disabled] = typeof v === 'string' ? [v, v] : v;
|
||||
return (
|
||||
@@ -77,7 +71,7 @@ export function Choice({ label, name, value, options, update, children, hidden,
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
</LedgerSelect>
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
@@ -85,16 +79,16 @@ export function Choice({ label, name, value, options, update, children, hidden,
|
||||
export function Check({ name, value, update, children, hidden, ...props }: CheckProps) {
|
||||
return (
|
||||
<label className="check" hidden={hidden}>
|
||||
<input type="checkbox" name={name} checked={!!value} onChange={e => update(e.target.checked)} {...props} />
|
||||
<LedgerInput type="checkbox" name={name} checked={!!value} onChange={e => update(e.target.checked)} {...props} />
|
||||
{children}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
export function Act({ name, onClick, children, className = '', ...props }: ButtonHTMLAttributes<HTMLButtonElement>) {
|
||||
return (
|
||||
<button type="button" className={className} data-action={name} onClick={onClick} {...props}>
|
||||
<LedgerButton type="button" className={className} data-action={name} onClick={onClick} {...props}>
|
||||
{children}
|
||||
</button>
|
||||
</LedgerButton>
|
||||
);
|
||||
}
|
||||
export function Heading({
|
||||
@@ -246,7 +240,7 @@ export function CardPreview({
|
||||
<div className="credit-card-fields">
|
||||
<label>
|
||||
手续费(元,自动)
|
||||
<input
|
||||
<LedgerInput
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
@@ -284,53 +278,3 @@ export function CardPreview({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export function amountPreview(raw: string) {
|
||||
try {
|
||||
return Calc.cents(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export function safeEstimate<T>(fn: () => T): { result: T; error?: undefined } | { result?: undefined; error: string } {
|
||||
try {
|
||||
return { result: fn() };
|
||||
} catch (error) {
|
||||
return { error: error instanceof Error ? error.message : String(error) };
|
||||
}
|
||||
}
|
||||
export function readDraft<T>(key: string, valid: (v: unknown) => v is T): T | null {
|
||||
try {
|
||||
const value: unknown = JSON.parse(localStorage.getItem(key) || 'null');
|
||||
return valid(value) ? value : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export function saleCharges(charges: ChargeState[]) {
|
||||
return charges.map(r => ({
|
||||
id: r.id,
|
||||
nameType: r.type,
|
||||
customName: r.customName,
|
||||
name: r.type === '其他' ? r.customName : r.type,
|
||||
amount: r.amount,
|
||||
chargePrices: r.prices,
|
||||
...(r.costRemoved ? { costRemoved: true } : {}),
|
||||
}));
|
||||
}
|
||||
export function initialPayment(state: LedgerState, p: SavedPayment | undefined, member: string): LockPayment {
|
||||
const id = Model.accountIdentity(state, p?.account || '');
|
||||
return {
|
||||
method: id?.channel || '微信',
|
||||
recipient: Model.memberAccountPrefix(id?.member || (Model.teamMode(state) ? member : 'assistant')),
|
||||
payer: p?.credit_card_fee_payer || 'owner',
|
||||
verified: !!p?.verified,
|
||||
amount: p?.amount ?? '',
|
||||
};
|
||||
}
|
||||
export function paymentPayload(payment: LockPayment) {
|
||||
return {
|
||||
account: Cards.normalizeAccount((payment.method === '信用卡' ? '麦麦' : payment.recipient) + payment.method),
|
||||
credit_card_fee_payer: payment.payer,
|
||||
verified: payment.verified,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user