将账本业务页面、表单与审批迁移到 React,并加入旧版对照验收
This commit is contained in:
1 parent
f1a4e69f0d
commit
00dd683116
107 files changed
+31755
-191
No files matched your search
@@ -0,0 +1,263 @@
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import { type LedgerClient } from '../../lib/api';
|
||||
import { Calc, Fees, type MemberRow } from '../../shared';
|
||||
import { Button, Choice, Dialog, Field } from './controls';
|
||||
import { errorText, memberOptions, readForm, type Notice, type Shop } from './settingsModel';
|
||||
|
||||
interface Cost {
|
||||
name: string;
|
||||
amount: string;
|
||||
payer: string;
|
||||
byQuantity: boolean;
|
||||
enabled: boolean;
|
||||
}
|
||||
type Editor = { action: 'add' | 'edit' | 'delete'; kind: string; revision: number; original: Cost };
|
||||
function formCost(form: HTMLFormElement): Cost {
|
||||
const { name, amount, payer, enabled, byQuantity } = readForm(form);
|
||||
return { name, amount, payer, enabled: enabled === 'true', byQuantity: byQuantity === 'true' };
|
||||
}
|
||||
export function Costs({
|
||||
shop,
|
||||
client,
|
||||
members,
|
||||
team,
|
||||
busy,
|
||||
onBusy,
|
||||
dirty,
|
||||
onDirty,
|
||||
onSaved,
|
||||
notice,
|
||||
}: {
|
||||
shop: Shop;
|
||||
client: LedgerClient;
|
||||
members: MemberRow[];
|
||||
team: boolean;
|
||||
busy: boolean;
|
||||
onBusy: (v: boolean) => void;
|
||||
dirty: boolean;
|
||||
onDirty: (v: boolean) => void;
|
||||
onSaved: (shop: Shop) => Promise<void>;
|
||||
notice: Notice;
|
||||
}) {
|
||||
const rows = (
|
||||
Fees as typeof Fees & { presetCatalog: (v?: Record<string, unknown>) => Record<string, Cost> }
|
||||
).presetCatalog(shop.costPresets);
|
||||
const [search, setSearch] = useState('');
|
||||
const [editor, setEditor] = useState<Editor | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
function close() {
|
||||
if (saving || (dirty && !window.confirm('成本修改尚未保存,放弃修改?'))) return;
|
||||
setEditor(null);
|
||||
onDirty(false);
|
||||
setError('');
|
||||
}
|
||||
function open(action: Editor['action'], kind = '') {
|
||||
if (busy || client.busy || client.pending()) return;
|
||||
const original = rows[kind] || { name: '', amount: '0', payer: 'order', enabled: true, byQuantity: false };
|
||||
setEditor({ action, kind: kind || 'custom_' + crypto.randomUUID(), original, revision: shop.revision });
|
||||
onDirty(false);
|
||||
setError('');
|
||||
}
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
if (!editor || saving) return;
|
||||
let committed = false;
|
||||
try {
|
||||
if (busy || client.busy || client.pending()) throw new Error('请先确认当前操作,再保存成本');
|
||||
const value = editor.action === 'delete' ? null : formCost(event.currentTarget);
|
||||
if (value) {
|
||||
value.name = value.name.trim();
|
||||
if (!value.name || value.name.length > 40) throw new Error('成本名称请填写1~40字');
|
||||
if (Calc.cents(value.amount, '成本') > 100000000) throw new Error('成本最多1000000元');
|
||||
}
|
||||
setSaving(true);
|
||||
onBusy(true);
|
||||
setError('');
|
||||
const result = await client.mutate<{ shopSettings: Shop }>('/api/shop-settings', {
|
||||
revision: editor.revision,
|
||||
costPresets: { [editor.kind]: value },
|
||||
});
|
||||
committed = true;
|
||||
setEditor(null);
|
||||
onDirty(false);
|
||||
await onSaved(result.shopSettings);
|
||||
notice(editor.action === 'delete' ? '成本项目已删除' : '成本项目已保存');
|
||||
} catch (err) {
|
||||
const message = committed ? '成本已经保存,请刷新页面核对' : errorText(err);
|
||||
setError(message);
|
||||
notice(message, true);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
onBusy(false);
|
||||
}
|
||||
}
|
||||
const visible = Object.entries(rows).filter(([, row]) =>
|
||||
row.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()),
|
||||
);
|
||||
return (
|
||||
<section id="shop-cost-manager" className="shop-cost-manager">
|
||||
<div className="panel-title">
|
||||
<div>
|
||||
<h3>勾选成本管理</h3>
|
||||
<p className="small muted">自行添加需要的项目。删除后不再用于新单,历史订单成本保留。</p>
|
||||
</div>
|
||||
<Button action="shop-cost-add" className="primary" onClick={() => open('add')}>
|
||||
+ 新增成本
|
||||
</Button>
|
||||
</div>
|
||||
<label className="shop-cost-search">
|
||||
搜索成本
|
||||
<input
|
||||
type="search"
|
||||
id="shop-cost-search"
|
||||
placeholder="输入成本名称"
|
||||
autoComplete="off"
|
||||
value={search}
|
||||
onChange={e => setSearch(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<div id="shop-cost-list">
|
||||
{visible.length ? (
|
||||
<div className="table-wrap">
|
||||
<table className="shop-cost-table">
|
||||
<thead>
|
||||
<tr>
|
||||
{['成本名称', '金额/单价', '付款人', '计费方式', '状态', '操作'].map(text => (
|
||||
<th key={text}>{text}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{visible.map(([kind, row]) => (
|
||||
<tr key={kind} data-cost-row={kind}>
|
||||
<td>
|
||||
<strong>{row.name}</strong>
|
||||
</td>
|
||||
<td>¥{row.amount}</td>
|
||||
<td>
|
||||
{row.payer === 'order'
|
||||
? '订单归属人'
|
||||
: members.find(m => m.member === row.payer)?.label || '待确认'}
|
||||
</td>
|
||||
<td>{row.byQuantity ? '单价 × 数量' : '每单一次'}</td>
|
||||
<td>{row.enabled ? '启用' : '停用'}</td>
|
||||
<td>
|
||||
<div className="actions">
|
||||
<Button
|
||||
action="shop-cost-edit"
|
||||
className="quiet"
|
||||
data-kind={kind}
|
||||
onClick={() => open('edit', kind)}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
<Button
|
||||
action="shop-cost-delete"
|
||||
className="danger"
|
||||
data-kind={kind}
|
||||
onClick={() => open('delete', kind)}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="empty">
|
||||
{Object.keys(rows).length ? '没有匹配的成本项目。' : '还没有勾选成本,点击“新增成本”添加。'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{editor && (
|
||||
<Dialog id="shop-cost-dialog" close={close}>
|
||||
<Button className="dialog-close" action="shop-cost-close" aria-label="关闭成本编辑" onClick={close}>
|
||||
×
|
||||
</Button>
|
||||
<h2>{{ add: '新增成本', delete: '删除成本', edit: '编辑成本' }[editor.action]}</h2>
|
||||
<form
|
||||
id="shop-cost-form"
|
||||
onSubmit={submit}
|
||||
onChange={e => {
|
||||
const value = formCost(e.currentTarget);
|
||||
onDirty((Object.keys(value) as (keyof Cost)[]).some(k => value[k] !== editor.original[k]));
|
||||
}}
|
||||
>
|
||||
{editor.action === 'delete' ? (
|
||||
<>
|
||||
<p>
|
||||
删除“<strong>{editor.original.name}</strong>”?
|
||||
</p>
|
||||
<p className="muted">删除后不会再出现在新单勾选项里,已开订单、成本和流水保留。</p>
|
||||
</>
|
||||
) : (
|
||||
<div className="grid two">
|
||||
<Field
|
||||
label="成本名称"
|
||||
name="name"
|
||||
defaultValue={editor.original.name}
|
||||
required
|
||||
maxLength={40}
|
||||
disabled={saving}
|
||||
/>
|
||||
<Field
|
||||
label="金额/单价(元)"
|
||||
name="amount"
|
||||
type="number"
|
||||
defaultValue={editor.original.amount}
|
||||
required
|
||||
min={0}
|
||||
max={1000000}
|
||||
step="0.01"
|
||||
disabled={saving}
|
||||
/>
|
||||
<Choice
|
||||
label="付款人"
|
||||
name="payer"
|
||||
defaultValue={editor.original.payer}
|
||||
options={[['order', '订单归属人'], ...memberOptions(members, editor.original.payer, team)]}
|
||||
disabled={saving}
|
||||
/>
|
||||
<Choice
|
||||
label="计费方式"
|
||||
name="byQuantity"
|
||||
defaultValue={String(editor.original.byQuantity)}
|
||||
options={[
|
||||
['false', '每单一次'],
|
||||
['true', '单价 × 数量'],
|
||||
]}
|
||||
disabled={saving}
|
||||
/>
|
||||
<Choice
|
||||
label="状态"
|
||||
name="enabled"
|
||||
defaultValue={String(editor.original.enabled)}
|
||||
options={[
|
||||
['true', '启用'],
|
||||
['false', '停用'],
|
||||
]}
|
||||
disabled={saving}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div id="shop-cost-error" role="alert" className={error ? 'error' : undefined}>
|
||||
{error}
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<Button action="shop-cost-close" className="quiet" onClick={close} disabled={saving}>
|
||||
取消
|
||||
</Button>
|
||||
<button type="submit" className={editor.action === 'delete' ? 'danger' : 'primary'} disabled={saving}>
|
||||
{editor.action === 'delete' ? '确认删除' : '保存成本'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Dialog>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,566 @@
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState, type FormEvent } from 'react';
|
||||
import type { ApiError, LedgerClient } from '../../lib/api';
|
||||
import { Button, Choice, Dialog, Field } from './controls';
|
||||
import { errorText, readForm, type LeaveChecks, type Notice } from './settingsModel';
|
||||
|
||||
interface Employee {
|
||||
member: string;
|
||||
label: string;
|
||||
operatorName?: string;
|
||||
loginName: string;
|
||||
role: 'owner' | 'assistant';
|
||||
enabled: boolean;
|
||||
passwordSet: boolean;
|
||||
hasBusinessData: boolean;
|
||||
canDelete: boolean;
|
||||
canDeactivate: boolean;
|
||||
businessUsage: { source: string; label?: string; count: number }[];
|
||||
}
|
||||
interface Directory {
|
||||
revision: number;
|
||||
employees: Employee[];
|
||||
}
|
||||
function directory(data: Directory) {
|
||||
const validMember = (s: string) =>
|
||||
['owner', 'assistant', 'assistant2'].includes(s) ||
|
||||
/^staff_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(s);
|
||||
if (
|
||||
!data ||
|
||||
!Number.isSafeInteger(data.revision) ||
|
||||
data.revision < 0 ||
|
||||
!Array.isArray(data.employees) ||
|
||||
new Set(data.employees.map(r => r?.member)).size !== data.employees.length ||
|
||||
!data.employees.every(
|
||||
r =>
|
||||
r &&
|
||||
validMember(r.member) &&
|
||||
typeof r.label === 'string' &&
|
||||
r.label &&
|
||||
typeof r.loginName === 'string' &&
|
||||
['owner', 'assistant'].includes(r.role) &&
|
||||
(r.role === 'owner') === (r.member === 'owner') &&
|
||||
[r.enabled, r.passwordSet, r.hasBusinessData, r.canDelete, r.canDeactivate].every(
|
||||
v => typeof v === 'boolean',
|
||||
) &&
|
||||
(!r.canDelete || (r.member !== 'owner' && !r.hasBusinessData)) &&
|
||||
(!r.canDeactivate || r.member !== 'owner') &&
|
||||
Array.isArray(r.businessUsage) &&
|
||||
r.businessUsage.every(i => i && typeof i.source === 'string' && Number.isSafeInteger(i.count) && i.count > 0),
|
||||
)
|
||||
) {
|
||||
throw new Error('员工资料未完整返回,请重新读取。');
|
||||
}
|
||||
return data;
|
||||
}
|
||||
function deleteReason(row: Employee) {
|
||||
if (row.member === 'owner') return '店主账号始终保留,不能停用或删除。';
|
||||
if (row.hasBusinessData) return '已有业务记录,不能删除。可停用账号,保留历史订单、付款人与统计。';
|
||||
return row.canDelete ? '未关联业务记录,可以删除。' : '暂不能删除,请重新读取员工资料核对。';
|
||||
}
|
||||
type Kind = 'add' | 'update' | 'deactivate' | 'reactivate' | 'delete';
|
||||
interface Editor {
|
||||
kind: Kind;
|
||||
revision: number;
|
||||
row?: Employee;
|
||||
}
|
||||
interface EmployeeJob {
|
||||
url: string;
|
||||
data: Record<string, unknown>;
|
||||
key: string;
|
||||
user: string;
|
||||
}
|
||||
const statusName = { deactivate: '停用', reactivate: '启用', delete: '删除' };
|
||||
const statusMessage = {
|
||||
deactivate: '停用后立即退出登录,新订单和付款选择中不再出现;历史订单、付款人和统计仍保留。',
|
||||
reactivate: '启用后可以重新登录,并重新出现在新订单和付款人选项中。',
|
||||
delete: '此员工没有业务记录。删除后登录账号和员工资料将移除。',
|
||||
};
|
||||
const phonePattern = /^1[3-9]\d{9}$/;
|
||||
const filtersByClient = new WeakMap<LedgerClient, { search: string; status: string }>();
|
||||
export const Employees = forwardRef<
|
||||
LeaveChecks,
|
||||
{
|
||||
client: LedgerClient;
|
||||
shopDirty: boolean;
|
||||
reloadKey: number;
|
||||
onSaved: () => Promise<unknown>;
|
||||
onAccountChanged: () => void;
|
||||
notice: Notice;
|
||||
}
|
||||
>(function Employees({ client, shopDirty, reloadKey, onSaved, onAccountChanged, notice }, ref) {
|
||||
const [rows, setRows] = useState<Directory | null>(null);
|
||||
const [loading, setLoading] = useState(true),
|
||||
[loadError, setLoadError] = useState('');
|
||||
const [filter, setFilter] = useState(() => filtersByClient.get(client) || { search: '', status: 'all' });
|
||||
const [editor, setEditor] = useState<Editor | null>(null);
|
||||
const [dirty, setDirty] = useState(false),
|
||||
[saving, setSaving] = useState(false);
|
||||
const [pending, setPending] = useState<EmployeeJob | null>(null),
|
||||
[error, setError] = useState(''),
|
||||
[stale, setStale] = useState(false);
|
||||
const requests = useRef(0),
|
||||
alive = useRef(false);
|
||||
const guarded = saving || client.busy || !!client.pending() || !!pending;
|
||||
const load = useCallback(async () => {
|
||||
const id = ++requests.current;
|
||||
setLoading(true);
|
||||
setLoadError('');
|
||||
try {
|
||||
const next = directory(await client.api<Directory>('/api/employees?' + new URLSearchParams(filter)));
|
||||
if (alive.current && id === requests.current) setRows(next);
|
||||
} catch (err) {
|
||||
if (alive.current && id === requests.current) {
|
||||
setRows(null);
|
||||
setLoadError(errorText(err));
|
||||
}
|
||||
} finally {
|
||||
if (alive.current && id === requests.current) setLoading(false);
|
||||
}
|
||||
}, [client, filter]);
|
||||
useEffect(() => {
|
||||
alive.current = true;
|
||||
return () => {
|
||||
alive.current = false;
|
||||
};
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load, reloadKey]);
|
||||
function close(leave = false) {
|
||||
if (saving || pending) {
|
||||
notice('员工操作结果待确认,请先恢复本次员工操作。', true);
|
||||
return false;
|
||||
}
|
||||
const question = leave
|
||||
? '员工资料尚未保存,离开会丢弃填写内容。继续离开?'
|
||||
: '员工资料尚未保存,关闭会丢弃填写内容。继续关闭?';
|
||||
if (dirty && !window.confirm(question)) return false;
|
||||
setEditor(null);
|
||||
setDirty(false);
|
||||
setError('');
|
||||
setStale(false);
|
||||
return true;
|
||||
}
|
||||
useImperativeHandle(ref, () => ({ canLeave: () => close(true), beforeUnload: () => saving || !!pending || dirty }));
|
||||
function open(kind: Kind, row?: Employee) {
|
||||
if (guarded) return;
|
||||
if (shopDirty) {
|
||||
notice('请先保存店铺与打印设置,再修改员工资料。', true);
|
||||
return;
|
||||
}
|
||||
if (!rows) {
|
||||
notice('请先重新读取员工资料。', true);
|
||||
return;
|
||||
}
|
||||
if (!close()) return;
|
||||
setEditor({ kind, row, revision: rows.revision });
|
||||
}
|
||||
function handleError(err: unknown, password = '') {
|
||||
const message = password ? errorText(err).split(password).join('••••') : errorText(err);
|
||||
setError(message);
|
||||
notice(message, true);
|
||||
if ((err as ApiError).status === 409) setStale(true);
|
||||
}
|
||||
async function write(job: EmployeeJob) {
|
||||
setSaving(true);
|
||||
setError('');
|
||||
let completed = false;
|
||||
try {
|
||||
const result = await client.employeeWrite<Directory>(job.url, job.data, job.key, job.user);
|
||||
completed = true;
|
||||
setPending(null);
|
||||
directory(result);
|
||||
if (!alive.current || client.user !== job.user) return;
|
||||
setEditor(null);
|
||||
setDirty(false);
|
||||
await onSaved();
|
||||
if (!alive.current || client.user !== job.user) return;
|
||||
await load();
|
||||
notice('员工资料已保存');
|
||||
} catch (caught) {
|
||||
if (!alive.current) return;
|
||||
const err = caught as ApiError;
|
||||
if (completed) {
|
||||
if (err.status === 401) {
|
||||
notice('密码已修改,请重新登录。');
|
||||
onAccountChanged();
|
||||
return;
|
||||
}
|
||||
handleError(new Error('员工资料已经保存,请刷新页面核对。'));
|
||||
} else if (err.code === 'ACCOUNT_CHANGED') {
|
||||
setPending(null);
|
||||
setDirty(false);
|
||||
setEditor(null);
|
||||
onAccountChanged();
|
||||
} else if (err.completed || (err.confirmed && [400, 401, 403, 404, 409, 413].includes(err.status ?? 0))) {
|
||||
setPending(null);
|
||||
handleError(err, String(job.data.password || ''));
|
||||
} else {
|
||||
// 请求体可能包含明文密码,未知结果仅保存在本组件内存,重试沿用操作号。
|
||||
setPending(job);
|
||||
handleError(new Error('连接中断,员工变更结果待确认。请恢复本次员工操作,原操作号会保留。'));
|
||||
}
|
||||
} finally {
|
||||
if (alive.current) setSaving(false);
|
||||
}
|
||||
}
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
if (!editor || guarded || stale) return;
|
||||
const values = readForm(event.currentTarget),
|
||||
{ kind, row, revision } = editor;
|
||||
try {
|
||||
if (shopDirty) throw new Error('请先保存店铺与打印设置,再修改员工资料。');
|
||||
if (revision !== rows?.revision) throw new Error('员工资料已有变动,请重新打开资料后核对。');
|
||||
let input: Record<string, unknown>;
|
||||
if (kind === 'add' || kind === 'update') {
|
||||
const label = values.label.trim(),
|
||||
operatorName = values.operatorName.trim(),
|
||||
loginName = values.loginName.trim(),
|
||||
password = values.password;
|
||||
if (operatorName.length > 30) throw new Error('经办人名称最多30字。');
|
||||
if (!label || label.length > 30) throw new Error('账号名称请填写1~30字。');
|
||||
if (!loginName || loginName.length > 60 || /[\s<>]/.test(loginName))
|
||||
throw new Error('登录名请填写1~60个字符,不含空白及尖括号。');
|
||||
if ((kind === 'add' || loginName !== row?.loginName) && !phonePattern.test(loginName))
|
||||
throw new Error('请填写11位有效手机号,用于登录。');
|
||||
if ((kind === 'add' || password !== '') && (password.length < 12 || password.length > 500))
|
||||
throw new Error('登录密码须为12~500个字符。');
|
||||
input = {
|
||||
revision,
|
||||
label,
|
||||
operatorName,
|
||||
...(phonePattern.test(loginName) ? { phone: loginName } : { loginName }),
|
||||
...(password ? { password } : {}),
|
||||
};
|
||||
} else {
|
||||
if (values.verified !== 'on') throw new Error('请核对员工并勾选确认。');
|
||||
input = { revision, verified: true };
|
||||
}
|
||||
const url = kind === 'add' ? '/api/employees' : '/api/employees/' + encodeURIComponent(row!.member) + '/' + kind;
|
||||
await write({ url, data: input, key: crypto.randomUUID(), user: client.user });
|
||||
} catch (err) {
|
||||
handleError(err, values.password);
|
||||
}
|
||||
}
|
||||
const row = editor?.row,
|
||||
adding = editor?.kind === 'add',
|
||||
editing = adding || editor?.kind === 'update';
|
||||
const status = editor && !editing ? (editor.kind as keyof typeof statusName) : null;
|
||||
const actions = (
|
||||
<div id="employee-form-error" aria-live="polite">
|
||||
{error && (
|
||||
<div className="error">
|
||||
{error}
|
||||
{pending ? (
|
||||
<Button
|
||||
action="employee-retry"
|
||||
className="danger"
|
||||
disabled={saving || client.busy}
|
||||
onClick={() => write(pending)}
|
||||
>
|
||||
恢复本次员工操作
|
||||
</Button>
|
||||
) : stale ? (
|
||||
<Button action="employee-reload" onClick={load}>
|
||||
读取最新员工列表
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<section className="panel employee-management" id="employee-management-panel">
|
||||
<div className="panel-title">
|
||||
<div>
|
||||
<h2>员工管理</h2>
|
||||
<p className="small muted">新增员工、修改登录资料,或停用离职账号。员工只查看本人业务,店主查看全店。</p>
|
||||
</div>
|
||||
<Button action="employee-add" className="primary" disabled={guarded} onClick={() => open('add')}>
|
||||
新增员工
|
||||
</Button>
|
||||
</div>
|
||||
<form
|
||||
id="employee-search-form"
|
||||
className="employee-filters"
|
||||
onSubmit={e => {
|
||||
e.preventDefault();
|
||||
const data = readForm(e.currentTarget);
|
||||
const next = { search: data.search.trim(), status: data.status };
|
||||
filtersByClient.set(client, next);
|
||||
setFilter(next);
|
||||
}}
|
||||
>
|
||||
<Field
|
||||
label="搜索账号、经办人或手机号"
|
||||
name="search"
|
||||
type="search"
|
||||
maxLength={80}
|
||||
autoComplete="off"
|
||||
defaultValue={filter.search}
|
||||
disabled={guarded}
|
||||
/>
|
||||
<Choice
|
||||
label="账号状态"
|
||||
name="status"
|
||||
options={[
|
||||
['all', '全部状态'],
|
||||
['active', '已启用'],
|
||||
['inactive', '已停用'],
|
||||
]}
|
||||
defaultValue={filter.status}
|
||||
disabled={guarded}
|
||||
/>
|
||||
<button type="submit" disabled={guarded}>
|
||||
搜索
|
||||
</button>
|
||||
<Button action="employee-reload" className="quiet" disabled={guarded} onClick={load}>
|
||||
刷新
|
||||
</Button>
|
||||
</form>
|
||||
<div id="employee-list" aria-live="polite" aria-busy={loading}>
|
||||
{loading ? (
|
||||
<p className="small muted">正在读取员工资料…</p>
|
||||
) : loadError ? (
|
||||
<div className="error">
|
||||
{loadError}{' '}
|
||||
<Button action="employee-reload" disabled={guarded} onClick={load}>
|
||||
重新读取
|
||||
</Button>
|
||||
</div>
|
||||
) : !rows?.employees.length ? (
|
||||
<p className="empty">没有符合条件的员工。</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="employee-table">
|
||||
<thead>
|
||||
<tr>
|
||||
{['账号名称', '经办人名称(开单人)', '手机号/原登录名', '账号状态', '历史记录', '操作'].map(
|
||||
name => (
|
||||
<th key={name}>{name}</th>
|
||||
),
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.employees.map(item => (
|
||||
<tr key={item.member} data-employee={item.member}>
|
||||
<td>
|
||||
<strong>{item.label}</strong>
|
||||
<div className="small muted">{item.member === 'owner' ? '店主' : '员工'}</div>
|
||||
</td>
|
||||
<td>{item.operatorName || item.label}</td>
|
||||
<td>
|
||||
{item.loginName}
|
||||
<div className="small muted">{item.passwordSet ? '已设置密码' : '尚未设置密码'}</div>
|
||||
</td>
|
||||
<td>
|
||||
<span className={'badge ' + (item.enabled ? '' : 'warn')}>
|
||||
{item.enabled ? '已启用' : '已停用'}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<p className="small muted employee-delete-reason">{deleteReason(item)}</p>
|
||||
{!!item.businessUsage.length && (
|
||||
<details>
|
||||
<summary className="small">关联记录</summary>
|
||||
<ul className="small">
|
||||
{item.businessUsage.map(i => (
|
||||
<li key={i.source}>
|
||||
{i.label || i.source}:{i.count} 条
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<div className="actions">
|
||||
<Button
|
||||
action="employee-edit"
|
||||
data-member={item.member}
|
||||
onClick={() => open('update', item)}
|
||||
disabled={guarded}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
{item.canDeactivate ? (
|
||||
<Button
|
||||
action="employee-deactivate"
|
||||
className="quiet"
|
||||
data-member={item.member}
|
||||
disabled={guarded}
|
||||
onClick={() => open('deactivate', item)}
|
||||
>
|
||||
停用
|
||||
</Button>
|
||||
) : item.member !== 'owner' && !item.enabled ? (
|
||||
<Button
|
||||
action="employee-reactivate"
|
||||
data-member={item.member}
|
||||
disabled={guarded}
|
||||
onClick={() => open('reactivate', item)}
|
||||
>
|
||||
启用
|
||||
</Button>
|
||||
) : null}
|
||||
{item.member !== 'owner' && (
|
||||
<Button
|
||||
action="employee-delete"
|
||||
className="quiet"
|
||||
data-member={item.member}
|
||||
disabled={guarded || !item.canDelete}
|
||||
aria-label={'删除' + item.label}
|
||||
title={deleteReason(item)}
|
||||
onClick={() => open('delete', item)}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{editor && (
|
||||
<Dialog id="employee-dialog" labelledBy="employee-dialog-title" close={() => close()}>
|
||||
<Button
|
||||
action="employee-close"
|
||||
aria-label={editing ? '关闭员工资料' : '关闭员工操作'}
|
||||
className="dialog-close"
|
||||
disabled={saving || !!pending}
|
||||
onClick={() => close()}
|
||||
>
|
||||
×
|
||||
</Button>
|
||||
<h2 id="employee-dialog-title">
|
||||
{editing ? (adding ? '新增员工' : '编辑员工') : statusName[status!] + '员工'}
|
||||
</h2>
|
||||
{editing ? (
|
||||
<>
|
||||
{row?.member === 'owner' && (
|
||||
<p className="note">店主账号始终启用,不能删除或停用。修改本人密码后需要重新登录。</p>
|
||||
)}
|
||||
<form
|
||||
id="employee-form"
|
||||
data-revision={editor.revision}
|
||||
data-stale={stale || undefined}
|
||||
onSubmit={submit}
|
||||
onChange={e => {
|
||||
const values = readForm(e.currentTarget);
|
||||
setDirty(
|
||||
!!values.password ||
|
||||
values.label !== (row?.label || '') ||
|
||||
values.operatorName !== (row?.operatorName || '') ||
|
||||
values.loginName !== (row?.loginName || ''),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<fieldset className="employee-form-fields" disabled={guarded || stale}>
|
||||
<div className="grid two">
|
||||
<Field
|
||||
label="账号名称"
|
||||
name="label"
|
||||
required
|
||||
maxLength={30}
|
||||
autoComplete="off"
|
||||
defaultValue={row?.label || ''}
|
||||
/>
|
||||
<Field
|
||||
label="经办人名称(开单人)"
|
||||
name="operatorName"
|
||||
maxLength={30}
|
||||
autoComplete="off"
|
||||
placeholder="例如:客服一;留空沿用账号名称"
|
||||
defaultValue={row?.operatorName || ''}
|
||||
/>
|
||||
<Field
|
||||
label={
|
||||
adding || phonePattern.test(row?.loginName || '')
|
||||
? '手机号(登录账号)'
|
||||
: '原登录名(可改为手机号)'
|
||||
}
|
||||
name="loginName"
|
||||
required
|
||||
maxLength={60}
|
||||
autoComplete="off"
|
||||
spellCheck={false}
|
||||
type={adding ? 'tel' : 'text'}
|
||||
defaultValue={row?.loginName || ''}
|
||||
/>
|
||||
</div>
|
||||
<Field
|
||||
label={adding ? '登录密码(12~500个字符)' : '新密码(留空保留原密码)'}
|
||||
name="password"
|
||||
type="password"
|
||||
required={adding}
|
||||
minLength={12}
|
||||
maxLength={500}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
<p className="small muted">
|
||||
{adding
|
||||
? '账号名称填写实际员工,如娜娜;经办人名称填写开单显示名,如客服一。留空沿用账号名称。手机号和密码用于登录,新增账号使用员工权限。'
|
||||
: '账号名称用于内部识别员工,经办人名称自动带入新单开单人;留空沿用账号名称。原登录名可保留,换登录账号请填写手机号。历史订单开单人、归属与收付款账户保留。重设密码后该账号须重新登录。'}
|
||||
</p>
|
||||
</fieldset>
|
||||
{actions}
|
||||
<div className="form-actions">
|
||||
<Button
|
||||
action="employee-close"
|
||||
className="quiet"
|
||||
disabled={saving || !!pending}
|
||||
onClick={() => close()}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<button type="submit" className="primary" disabled={guarded || stale}>
|
||||
{adding ? '添加员工' : '保存修改'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
) : (
|
||||
status && (
|
||||
<>
|
||||
<p>
|
||||
<strong>{row!.label}</strong> · {row!.loginName}
|
||||
</p>
|
||||
<p className="note">{statusMessage[status]}</p>
|
||||
<form id="employee-status-form" onSubmit={submit} data-stale={stale || undefined}>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required disabled={guarded || stale} />
|
||||
已核对员工,确认{statusName[status]}账号。
|
||||
</label>
|
||||
{actions}
|
||||
<div className="form-actions">
|
||||
<Button
|
||||
action="employee-close"
|
||||
className="quiet"
|
||||
disabled={saving || !!pending}
|
||||
onClick={() => close()}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<button
|
||||
type="submit"
|
||||
className={status === 'delete' ? 'danger' : 'primary'}
|
||||
disabled={guarded || stale}
|
||||
>
|
||||
确认{statusName[status]}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
</Dialog>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,192 @@
|
||||
import { useRef, useState, type FormEvent } from 'react';
|
||||
import { type LedgerClient } from '../../lib/api';
|
||||
import { Button, Field } from './controls';
|
||||
import { errorText, readForm, type Printing, type Notice } from './settingsModel';
|
||||
|
||||
const metrics = [
|
||||
['rows', '表格最少行数', 3, 12],
|
||||
['offsetX', '左右偏移(mm,正数向右)', -30, 30],
|
||||
['offsetY', '上下偏移(mm,正数向下)', -30, 30],
|
||||
['contentTop', '内容距顶部(mm)', 5, 40],
|
||||
['rowHeight', '商品行高(mm)', 7, 16],
|
||||
] as const;
|
||||
export function PrintingPanel({
|
||||
client,
|
||||
printing,
|
||||
revision,
|
||||
orderId,
|
||||
shopDirty,
|
||||
dirty,
|
||||
onDirty,
|
||||
onBusy,
|
||||
refresh,
|
||||
notice,
|
||||
}: {
|
||||
client: LedgerClient;
|
||||
printing: Printing;
|
||||
revision?: number;
|
||||
orderId?: string;
|
||||
shopDirty: boolean;
|
||||
dirty: boolean;
|
||||
onDirty: (v: boolean) => void;
|
||||
onBusy: (v: boolean) => void;
|
||||
refresh: () => Promise<unknown>;
|
||||
notice: Notice;
|
||||
}) {
|
||||
const [saving, setSaving] = useState(false),
|
||||
[saved, setSaved] = useState(false),
|
||||
[error, setError] = useState('');
|
||||
const [version, setVersion] = useState(0);
|
||||
const status = useRef<HTMLParagraphElement>(null);
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const data = readForm(event.currentTarget);
|
||||
let committed = false;
|
||||
try {
|
||||
if (shopDirty) throw new Error('店铺配置尚未保存,请先保存店铺配置,再保存打印设置。');
|
||||
if (saving) return;
|
||||
setError('');
|
||||
setSaving(true);
|
||||
onBusy(true);
|
||||
await client.mutate('/api/printing', { ...data, shopSettingsRevision: revision });
|
||||
committed = true;
|
||||
await refresh();
|
||||
setVersion(v => v + 1);
|
||||
setSaved(true);
|
||||
onDirty(false);
|
||||
notice('打印设置已保存,预览和后续打印使用新设置');
|
||||
} catch (err) {
|
||||
const message = committed ? '打印设置已保存,但最新设置暂未读到。请刷新页面核对。' : errorText(err);
|
||||
setError(message);
|
||||
notice(message, true);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
onBusy(false);
|
||||
}
|
||||
}
|
||||
async function preview() {
|
||||
try {
|
||||
if (shopDirty) throw new Error('店铺配置尚未保存,请先保存再打开预览。');
|
||||
if (saving) throw new Error('打印设置正在保存,请保存完成后再打开预览。');
|
||||
if (dirty) {
|
||||
status.current?.scrollIntoView({ block: 'center' });
|
||||
throw new Error('打印设置已修改但尚未保存,请先点击“保存打印设置”,再打开预览。');
|
||||
}
|
||||
window.open('/print/' + orderId + '?mode=full', '_blank', 'noopener');
|
||||
await client.mutate('/api/orders/' + orderId + '/print', { mode: 'full' });
|
||||
notice('客户打印页已打开;若未出现,请允许此网站打开新窗口');
|
||||
} catch (err) {
|
||||
notice(errorText(err), true);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="split">
|
||||
<section className="panel">
|
||||
<div className="panel-title print-settings-title">
|
||||
<div>
|
||||
<h2>客户打印模板</h2>
|
||||
<p
|
||||
ref={status}
|
||||
id="print-settings-status"
|
||||
className={'small ' + (dirty ? 'danger-text' : 'muted')}
|
||||
aria-live="polite"
|
||||
>
|
||||
{saving
|
||||
? '正在保存打印设置…'
|
||||
: dirty
|
||||
? '修改后未保存,请点击“保存打印设置”。'
|
||||
: saved
|
||||
? '已保存,打印使用当前设置。'
|
||||
: '当前生效设置;修改后请点击保存。'}
|
||||
</p>
|
||||
</div>
|
||||
<button type="submit" form="print-settings" className="primary" disabled={saving || client.busy}>
|
||||
保存打印设置
|
||||
</button>
|
||||
</div>
|
||||
<form
|
||||
id="print-settings"
|
||||
key={version}
|
||||
onSubmit={submit}
|
||||
onChange={e => {
|
||||
const values = readForm(e.currentTarget);
|
||||
onDirty(metrics.some(([key]) => values[key].trim() === '' || Number(values[key]) !== printing[key]));
|
||||
}}
|
||||
>
|
||||
<p className="small muted">店名、单据标题与联系信息在店铺配置中保存。</p>
|
||||
<fieldset className="print-settings-fields" disabled={saving}>
|
||||
<div className="grid two">
|
||||
<Field label="店名" name="store" value={printing.store} maxLength={80} required readOnly />
|
||||
<Field label="单据标题" name="subtitle" value={printing.subtitle} maxLength={80} readOnly />
|
||||
<Field label="客户联系信息(选填)" name="contact" value={printing.contact} maxLength={80} readOnly />
|
||||
{metrics.map(([key, label, min, max]) => (
|
||||
<Field
|
||||
key={key}
|
||||
label={label}
|
||||
name={key}
|
||||
type="number"
|
||||
min={min}
|
||||
max={max}
|
||||
step={key === 'rows' ? undefined : '0.1'}
|
||||
required
|
||||
defaultValue={printing[key]}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div className="form-actions">
|
||||
{orderId && (
|
||||
<Button action="print" data-id={orderId} onClick={preview} disabled={client.busy}>
|
||||
打开最近一单预览
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div id="print-settings-error" aria-live="polite">
|
||||
{error && <div className="error">{error}</div>}
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<section className="panel print-settings-preview">
|
||||
<p className="small muted">填写效果示意;保存后用于实际打印。</p>
|
||||
<div className="print-preview-mini">
|
||||
<div className="paper-mini">
|
||||
<strong id="print-mini-store">{printing.store}</strong>
|
||||
<p id="print-mini-subtitle">{printing.subtitle}</p>
|
||||
<p id="print-mini-contact" hidden={!printing.contact}>
|
||||
{printing.contact}
|
||||
</p>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>商品名称</td>
|
||||
<td>克重</td>
|
||||
<td>成交金额</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>足金手链</td>
|
||||
<td>1.200g</td>
|
||||
<td>1,200.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{'\u3000'}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>合计金额{'\u3000'}¥1,200.00</p>
|
||||
<p>大写:壹仟贰佰元整</p>
|
||||
<p>注意事项 · 珠宝首饰保养须知</p>
|
||||
<p>经办人 ______</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="note">
|
||||
固定241×140mm横版,明细多时自动缩小到一页。打印窗口也选241×140mm,关闭页眉页脚。表格最少行数只用于补空行;套打按实物纸样校准偏移。
|
||||
</div>
|
||||
<p className="small muted">
|
||||
补打沿用同一订单号,不会重复出库或收入。客户预览接口不返回成本、垫资人、利润及内部操作日志。
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
import { useCallback, useEffect, useRef, useState, type FormEvent } from 'react';
|
||||
import { type LedgerClient } from '../../lib/api';
|
||||
import { useClientSnapshot } from '../../lib/useClient';
|
||||
import type { LedgerState, MemberRow, SessionInfo } from '../../shared';
|
||||
import { Button, Field } from './controls';
|
||||
import { errorText, legacyMembers, readForm, type LeaveChecks, type SettingsState, type Shop } from './settingsModel';
|
||||
import { Costs } from './Costs';
|
||||
import { Employees } from './Employees';
|
||||
import { PrintingPanel } from './Printing';
|
||||
import { ShopForm } from './Shop';
|
||||
import './settings.css';
|
||||
|
||||
export interface SettingsProps {
|
||||
client: LedgerClient;
|
||||
state: LedgerState;
|
||||
session: SessionInfo;
|
||||
refreshState: () => Promise<LedgerState>;
|
||||
onAccountChanged: () => void;
|
||||
registerLeaveGuard: (check: () => boolean) => () => void;
|
||||
}
|
||||
export function SettingsPage({
|
||||
client,
|
||||
state: raw,
|
||||
session,
|
||||
refreshState,
|
||||
onAccountChanged,
|
||||
registerLeaveGuard,
|
||||
}: SettingsProps) {
|
||||
const state = raw as SettingsState;
|
||||
const owner = state.user.role === 'owner',
|
||||
demo = state.mode === 'demo';
|
||||
const shop = state.shopSettings as Shop | undefined;
|
||||
const members: MemberRow[] = state.members?.length
|
||||
? state.members
|
||||
: shop?.members?.length
|
||||
? shop.members
|
||||
: legacyMembers;
|
||||
const team = !!(state.user.member || state.members?.some(m => m.member === 'assistant2'));
|
||||
const [shopDirty, setShopDirty] = useState(false),
|
||||
[printDirty, setPrintDirty] = useState(false),
|
||||
[costDirty, setCostDirty] = useState(false);
|
||||
const [shopSaving, setShopSaving] = useState(false),
|
||||
[printSaving, setPrintSaving] = useState(false);
|
||||
const [reloadKey, setReloadKey] = useState(0),
|
||||
[resetKey, setResetKey] = useState(0);
|
||||
const [message, setMessage] = useState({ text: '', error: false });
|
||||
const [serviceBusy, setServiceBusy] = useState(false);
|
||||
const employees = useRef<LeaveChecks>(null);
|
||||
const notice = useCallback((text: string, error = false) => setMessage({ text, error }), []);
|
||||
useClientSnapshot(client);
|
||||
const leave = useCallback(() => {
|
||||
if (employees.current && !employees.current.canLeave()) return false;
|
||||
if (shopSaving || printSaving) {
|
||||
notice('设置正在保存,请稍候。', true);
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
!(shopDirty || printDirty || costDirty) ||
|
||||
window.confirm('店铺或打印设置尚未保存,离开会丢弃这些修改。继续离开?')
|
||||
);
|
||||
}, [shopSaving, printSaving, shopDirty, printDirty, costDirty, notice]);
|
||||
useEffect(() => registerLeaveGuard(leave), [registerLeaveGuard, leave]);
|
||||
useEffect(() => {
|
||||
const unload = (e: BeforeUnloadEvent) => {
|
||||
if (shopSaving || shopDirty || printDirty || costDirty || employees.current?.beforeUnload()) {
|
||||
e.preventDefault();
|
||||
e.returnValue = '';
|
||||
}
|
||||
};
|
||||
window.addEventListener('beforeunload', unload);
|
||||
return () => window.removeEventListener('beforeunload', unload);
|
||||
}, [shopSaving, shopDirty, printDirty, costDirty]);
|
||||
function resetDrafts() {
|
||||
setShopDirty(false);
|
||||
setPrintDirty(false);
|
||||
setCostDirty(false);
|
||||
setResetKey(k => k + 1);
|
||||
}
|
||||
async function savePassword(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const data = readForm(event.currentTarget);
|
||||
try {
|
||||
if (shopDirty || printDirty) throw new Error('请先保存店铺与打印设置,再修改密码。');
|
||||
await client.mutate('/api/password', data);
|
||||
onAccountChanged();
|
||||
} catch (err) {
|
||||
notice(errorText(err), true);
|
||||
}
|
||||
}
|
||||
async function switchDemo(member: string) {
|
||||
if (!leave()) return;
|
||||
try {
|
||||
await client.api('/api/demo-login', { member });
|
||||
onAccountChanged();
|
||||
} catch (err) {
|
||||
notice(errorText(err), true);
|
||||
}
|
||||
}
|
||||
async function service(action: 'backup' | 'sync') {
|
||||
if (serviceBusy) return;
|
||||
if (action === 'backup' ? employees.current && !employees.current.canLeave() : !leave()) return;
|
||||
setServiceBusy(true);
|
||||
try {
|
||||
if (action === 'backup') {
|
||||
const result = await client.api<{ name: string }>('/api/backup', {});
|
||||
const link = document.createElement('a');
|
||||
link.href = '/api/backup/' + result.name;
|
||||
link.download = result.name;
|
||||
link.click();
|
||||
notice('完整备份已生成');
|
||||
} else {
|
||||
const result = await client.api<{ error?: string }>('/api/sync', {});
|
||||
notice(result.error || '同步重试完成,请查看状态', !!result.error);
|
||||
}
|
||||
await refreshState();
|
||||
resetDrafts();
|
||||
} catch (err) {
|
||||
notice(errorText(err), true);
|
||||
} finally {
|
||||
setServiceBusy(false);
|
||||
}
|
||||
}
|
||||
const account = state.user.member || session.user?.member || (owner ? 'owner' : 'assistant');
|
||||
const password = (
|
||||
<section className="panel">
|
||||
<h2>更改当前账号密码</h2>
|
||||
<form id="password-form" onSubmit={savePassword}>
|
||||
<div className="grid two">
|
||||
<Field label="原密码" name="current" type="password" required autoComplete="current-password" />
|
||||
<Field
|
||||
label="新密码(至少12个字符)"
|
||||
name="password"
|
||||
type="password"
|
||||
required
|
||||
minLength={12}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button disabled={client.busy}>修改并重新登录</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
className="settings-page"
|
||||
key={resetKey}
|
||||
onKeyDown={e => {
|
||||
if (
|
||||
e.target instanceof HTMLInputElement &&
|
||||
e.target.type === 'number' &&
|
||||
['ArrowUp', 'ArrowDown'].includes(e.key)
|
||||
)
|
||||
e.preventDefault();
|
||||
}}
|
||||
onWheel={e => {
|
||||
if (e.target instanceof HTMLInputElement && e.target.type === 'number' && document.activeElement === e.target)
|
||||
e.target.blur();
|
||||
}}
|
||||
>
|
||||
{owner && team && (
|
||||
<section className="panel team-settings">
|
||||
<div className="panel-title">
|
||||
<h2>成员与账号</h2>
|
||||
<span className="small muted">当前:{members.find(m => m.member === account)?.label || '待确认'}</span>
|
||||
</div>
|
||||
{demo && (
|
||||
<>
|
||||
<p className="note">三人功能预览·虚构数据,切换身份体验各自订单与账目。</p>
|
||||
<div className="actions">
|
||||
{members
|
||||
.filter(m => m.enabled !== false)
|
||||
.map(m => (
|
||||
<Button key={m.member} action={'demo-' + m.member} onClick={() => switchDemo(m.member)}>
|
||||
切换{m.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<p className="small muted">员工姓名、登录名、密码及启停状态在「员工管理」中维护。</p>
|
||||
</section>
|
||||
)}
|
||||
<div className="page-heading">
|
||||
<div>
|
||||
<div className="eyebrow">{owner ? 'SHOP & PRINT SETTINGS' : 'ACCOUNT'}</div>
|
||||
<h1>{owner ? '店铺与打印设置' : '修改密码'}</h1>
|
||||
<p className="muted">
|
||||
{owner ? '店铺身份、成员和默认值统一配置;打印布局按实际纸张校准。' : '更改本人登录密码,保存后重新登录。'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{owner ? (
|
||||
<>
|
||||
{shop && (
|
||||
<section id="shop-settings-panel" className="panel shop-settings">
|
||||
<ShopForm
|
||||
client={client}
|
||||
shop={shop}
|
||||
today={state.today}
|
||||
members={members}
|
||||
team={team}
|
||||
busy={shopSaving || printSaving}
|
||||
dirty={shopDirty}
|
||||
onDirty={setShopDirty}
|
||||
onBusy={setShopSaving}
|
||||
onSaved={async () => {
|
||||
await refreshState();
|
||||
setReloadKey(k => k + 1);
|
||||
}}
|
||||
notice={notice}
|
||||
/>
|
||||
<Costs
|
||||
client={client}
|
||||
shop={shop}
|
||||
members={members}
|
||||
team={team}
|
||||
busy={shopSaving || printSaving}
|
||||
dirty={costDirty}
|
||||
onDirty={setCostDirty}
|
||||
onBusy={setShopSaving}
|
||||
onSaved={async () => {
|
||||
await refreshState();
|
||||
}}
|
||||
notice={notice}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
<Employees
|
||||
ref={employees}
|
||||
client={client}
|
||||
shopDirty={shopDirty || printDirty}
|
||||
reloadKey={reloadKey}
|
||||
onSaved={refreshState}
|
||||
onAccountChanged={onAccountChanged}
|
||||
notice={notice}
|
||||
/>
|
||||
<PrintingPanel
|
||||
client={client}
|
||||
printing={state.printing}
|
||||
revision={shop?.revision}
|
||||
orderId={state.orders[0]?.id}
|
||||
shopDirty={shopDirty}
|
||||
dirty={printDirty}
|
||||
onDirty={setPrintDirty}
|
||||
onBusy={setPrintSaving}
|
||||
refresh={refreshState}
|
||||
notice={notice}
|
||||
/>
|
||||
<div className="grid two">
|
||||
<section className="panel">
|
||||
<h2>数据库与备份</h2>
|
||||
<p>
|
||||
{state.mode === 'production'
|
||||
? '主账保存在部署服务器的独立SQLite数据库。'
|
||||
: '现在运行在本机试用环境,云端正式数据库尚未部署。'}
|
||||
</p>
|
||||
<p className="small muted">
|
||||
启动时和运行期间每6小时生成完整数据库备份。本机同盘备份不能防电脑损坏,正式部署还需异地备份。
|
||||
</p>
|
||||
{state.backup?.last && <p className="small">本次运行最近备份:{state.backup.last.time}</p>}
|
||||
{state.backup?.error && <p className="error">{state.backup.error}</p>}
|
||||
<Button action="backup" disabled={serviceBusy || client.busy} onClick={() => service('backup')}>
|
||||
生成并下载完整备份
|
||||
</Button>
|
||||
</section>
|
||||
<section className="panel">
|
||||
<h2>飞书查看副本</h2>
|
||||
<p>
|
||||
<span className={'badge ' + (state.sync.enabled ? '' : 'warn')}>
|
||||
{state.sync.enabled ? '已配置' : '尚未连接'}
|
||||
</span>
|
||||
</p>
|
||||
<p className="small muted">
|
||||
使用新账专用表单向同步。修改和复核在本系统完成;同步失败不重开订单、不影响本地账务保存。
|
||||
</p>
|
||||
{state.sync.enabled ? (
|
||||
<>
|
||||
<p>
|
||||
待同步 {state.sync.pending} 项 · 失败 {state.sync.failed} 项
|
||||
</p>
|
||||
{state.sync.error && <p className="error">{state.sync.error}</p>}
|
||||
<Button action="sync" disabled={serviceBusy || client.busy} onClick={() => service('sync')}>
|
||||
立即重试同步
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<p className="note">已预留应用API同步通道。正式连接时再配置新表,未连接原销售表,未试写真实账务。</p>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
{!demo && password}
|
||||
</>
|
||||
) : demo ? (
|
||||
<section className="panel">
|
||||
<p className="muted">演示账号不提供密码修改。</p>
|
||||
</section>
|
||||
) : (
|
||||
password
|
||||
)}
|
||||
{message.text && (
|
||||
<div className={'settings-notice ' + (message.error ? 'error' : '')} role={message.error ? 'alert' : 'status'}>
|
||||
{message.text}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default SettingsPage;
|
||||
@@ -0,0 +1,212 @@
|
||||
import { useState, type FormEvent } from 'react';
|
||||
import type { LedgerClient } from '../../lib/api';
|
||||
import { Calc, type MemberRow } from '../../shared';
|
||||
import { Choice, Field } from './controls';
|
||||
import { errorText, memberOptions, readForm, type Shop, type Notice } from './settingsModel';
|
||||
|
||||
function shopValues(shop: Shop, today: string) {
|
||||
const month = today.slice(0, 7);
|
||||
const [year, n] = month.split('-').map(Number);
|
||||
const next = (n === 12 ? year + 1 : year) + '-' + String(n === 12 ? 1 : n + 1).padStart(2, '0');
|
||||
return {
|
||||
storeName: shop.storeName,
|
||||
receiptSubtitle: shop.receiptSubtitle || '',
|
||||
contact: shop.contact || '',
|
||||
creditCardRatePermille: String(shop.creditCardRatePermille),
|
||||
profitSharePercent: String(shop.profitSharePercent),
|
||||
profitShareEffectiveMonth: shop.profitShareEffectiveMonth >= month ? shop.profitShareEffectiveMonth : next,
|
||||
...shop.feeDefaults,
|
||||
};
|
||||
}
|
||||
export function ShopForm({
|
||||
client,
|
||||
shop,
|
||||
today,
|
||||
members,
|
||||
team,
|
||||
busy,
|
||||
dirty,
|
||||
onDirty,
|
||||
onBusy,
|
||||
onSaved,
|
||||
notice,
|
||||
}: {
|
||||
client: LedgerClient;
|
||||
shop: Shop;
|
||||
today: string;
|
||||
members: MemberRow[];
|
||||
team: boolean;
|
||||
busy: boolean;
|
||||
dirty: boolean;
|
||||
onDirty: (v: boolean) => void;
|
||||
onBusy: (v: boolean) => void;
|
||||
onSaved: (result: Shop) => Promise<void>;
|
||||
notice: Notice;
|
||||
}) {
|
||||
const baseline = shopValues(shop, today);
|
||||
const [error, setError] = useState('');
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [version, setVersion] = useState(0);
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const values = readForm(event.currentTarget);
|
||||
let committed = false;
|
||||
try {
|
||||
if (busy || client.busy || client.pending()) throw new Error('请先等当前操作完成,再保存店铺配置。');
|
||||
const integer = (key: string, max: number, title: string) => {
|
||||
if (!/^\d+$/.test(values[key]) || Number(values[key]) > max)
|
||||
throw new Error(title + '请填写0~' + max + '之间的整数。');
|
||||
return Number(values[key]);
|
||||
};
|
||||
if (!values.storeName.trim() || values.storeName.trim().length > 80) throw new Error('店名请填写1~80字。');
|
||||
for (const key of ['certificate', 'packaging', 'shipping'])
|
||||
if (Calc.cents(values[key], '默认费用') > 100000000) throw new Error('默认费用最多1000000元。');
|
||||
if (!members.some(m => m.member === values.packagingPayer)) throw new Error('请选择包装默认付款人。');
|
||||
if (
|
||||
!/^\d{4}-(0[1-9]|1[0-2])$/.test(values.profitShareEffectiveMonth) ||
|
||||
values.profitShareEffectiveMonth < today.slice(0, 7)
|
||||
)
|
||||
throw new Error('分成生效月份请选择本月或以后。');
|
||||
const data = {
|
||||
revision: shop.revision,
|
||||
storeName: values.storeName.trim(),
|
||||
receiptSubtitle: values.receiptSubtitle.trim(),
|
||||
contact: values.contact.trim(),
|
||||
creditCardRatePermille: integer('creditCardRatePermille', 1000, '信用卡费率'),
|
||||
...(values.profitSharePercent !== baseline.profitSharePercent ||
|
||||
values.profitShareEffectiveMonth !== baseline.profitShareEffectiveMonth
|
||||
? {
|
||||
profitSharePercent: integer('profitSharePercent', 100, '利润分成比例'),
|
||||
profitShareEffectiveMonth: values.profitShareEffectiveMonth,
|
||||
}
|
||||
: {}),
|
||||
feeDefaults: {
|
||||
certificate: values.certificate,
|
||||
packaging: values.packaging,
|
||||
shipping: values.shipping,
|
||||
packagingPayer: values.packagingPayer,
|
||||
},
|
||||
};
|
||||
setSaving(true);
|
||||
onBusy(true);
|
||||
setError('');
|
||||
const result = await client.mutate<{ shopSettings: Shop }>('/api/shop-settings', data);
|
||||
committed = true;
|
||||
await onSaved(result.shopSettings);
|
||||
onDirty(false);
|
||||
setSaved(true);
|
||||
setVersion(v => v + 1);
|
||||
notice('店铺配置已保存');
|
||||
} catch (err) {
|
||||
const message = committed ? '店铺配置已保存,页面更新未完成,请刷新后核对。' : errorText(err);
|
||||
setError(
|
||||
message +
|
||||
((err as { status?: number }).status === 409 ? ' 已填写内容已保留,请刷新读取最新配置后再修改。' : ''),
|
||||
);
|
||||
notice(message, true);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
onBusy(false);
|
||||
}
|
||||
}
|
||||
const money = { type: 'number', required: true, min: 0, max: 1000000, step: '0.01' };
|
||||
return (
|
||||
<>
|
||||
<div className="panel-title">
|
||||
<div>
|
||||
<h2>店铺配置</h2>
|
||||
<p id="shop-settings-status" aria-live="polite" className={'small ' + (dirty ? 'danger-text' : 'muted')}>
|
||||
{saving
|
||||
? '正在保存店铺配置…'
|
||||
: dirty
|
||||
? '修改尚未保存。'
|
||||
: saved
|
||||
? '已保存,后续开单与登录使用当前配置。'
|
||||
: '当前生效配置;仅店主可以修改。'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<form
|
||||
id="shop-settings-form"
|
||||
key={version}
|
||||
data-revision={shop.revision}
|
||||
onSubmit={submit}
|
||||
onChange={event => {
|
||||
const values = readForm(event.currentTarget);
|
||||
onDirty(Object.entries(baseline).some(([key, v]) => String(v ?? '') !== values[key]));
|
||||
}}
|
||||
>
|
||||
<fieldset className="shop-settings-fields" disabled={saving}>
|
||||
<div className="grid three">
|
||||
<Field label="店名" name="storeName" defaultValue={baseline.storeName} required maxLength={80} />
|
||||
<Field label="单据标题" name="receiptSubtitle" defaultValue={baseline.receiptSubtitle} maxLength={80} />
|
||||
<Field
|
||||
label="联系电话/客户联系信息(选填)"
|
||||
name="contact"
|
||||
defaultValue={baseline.contact}
|
||||
maxLength={80}
|
||||
/>
|
||||
</div>
|
||||
<h3>开单默认费用</h3>
|
||||
<div className="grid four">
|
||||
<Field label="证书成本(元)" name="certificate" defaultValue={baseline.certificate} {...money} />
|
||||
<Field label="包装成本(元)" name="packaging" defaultValue={baseline.packaging} {...money} />
|
||||
<Field label="整单快递成本(元)" name="shipping" defaultValue={baseline.shipping} {...money} />
|
||||
<Choice
|
||||
label="包装默认付款人"
|
||||
name="packagingPayer"
|
||||
defaultValue={baseline.packagingPayer}
|
||||
options={memberOptions(members, baseline.packagingPayer, team)}
|
||||
/>
|
||||
</div>
|
||||
<p className="small muted">
|
||||
默认费用只用于新增项目。已有订单、模板和草稿里已经填写的费用及付款人按原值保留,开单时仍可按实际修改。
|
||||
</p>
|
||||
<h3>手续费与利润分成</h3>
|
||||
<div className="grid three">
|
||||
<Field
|
||||
label="信用卡手续费率(‰)"
|
||||
name="creditCardRatePermille"
|
||||
defaultValue={baseline.creditCardRatePermille}
|
||||
type="number"
|
||||
min={0}
|
||||
max={1000}
|
||||
step={1}
|
||||
required
|
||||
/>
|
||||
<Field
|
||||
label="助理利润分成比例(%)"
|
||||
name="profitSharePercent"
|
||||
defaultValue={baseline.profitSharePercent}
|
||||
type="number"
|
||||
min={0}
|
||||
max={100}
|
||||
step={1}
|
||||
required
|
||||
/>
|
||||
<Field
|
||||
label="分成生效月份"
|
||||
name="profitShareEffectiveMonth"
|
||||
defaultValue={baseline.profitShareEffectiveMonth}
|
||||
type="month"
|
||||
min={today.slice(0, 7)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<p className="small muted">
|
||||
新建订单使用当前信用卡费率;修改旧单沿用原费率。分成按生效月份统计,历史月份保留原口径。
|
||||
</p>
|
||||
</fieldset>
|
||||
<div id="shop-settings-error" className={error ? 'error' : undefined} aria-live="polite">
|
||||
{error}
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button className="primary" type="submit" disabled={busy || client.busy || !!client.pending()}>
|
||||
保存店铺配置
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useLayoutEffect, useRef } from 'react';
|
||||
import type { ButtonHTMLAttributes, InputHTMLAttributes, ReactNode, SelectHTMLAttributes } from 'react';
|
||||
export function Field({ label, ...props }: InputHTMLAttributes<HTMLInputElement> & { label: string }) {
|
||||
return (
|
||||
<label>
|
||||
{label}
|
||||
<input type="text" {...props} />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
export function Choice({
|
||||
label,
|
||||
options,
|
||||
...props
|
||||
}: SelectHTMLAttributes<HTMLSelectElement> & { label: string; options: readonly (readonly [string, string])[] }) {
|
||||
return (
|
||||
<label>
|
||||
{label}
|
||||
<select {...props}>
|
||||
{options.map(([value, name]) => (
|
||||
<option key={value} value={value}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
export function Button({ action, ...props }: ButtonHTMLAttributes<HTMLButtonElement> & { action: string }) {
|
||||
return <button type="button" data-action={action} {...props} />;
|
||||
}
|
||||
export function Dialog({
|
||||
id,
|
||||
labelledBy,
|
||||
close,
|
||||
children,
|
||||
}: {
|
||||
id: string;
|
||||
labelledBy?: string;
|
||||
close: () => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
const node = ref.current!;
|
||||
node.showModal();
|
||||
node.querySelector<HTMLInputElement>('input:not([type=checkbox])')?.focus();
|
||||
return () => node.close();
|
||||
}, []);
|
||||
return (
|
||||
<dialog
|
||||
ref={ref}
|
||||
id={id}
|
||||
aria-labelledby={labelledBy}
|
||||
onCancel={event => {
|
||||
event.preventDefault();
|
||||
close();
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
.settings-page {
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 18px;
|
||||
line-height: 1.55;
|
||||
color: #243d34;
|
||||
}
|
||||
.settings-page .panel {
|
||||
min-width: 0;
|
||||
padding: clamp(16px, 2vw, 28px);
|
||||
border: 1px solid #d9e4df;
|
||||
border-radius: 12px;
|
||||
background: #fff;
|
||||
}
|
||||
.settings-page .team-settings {
|
||||
order: 0;
|
||||
}
|
||||
.settings-page .panel-title,
|
||||
.settings-page .form-actions,
|
||||
.settings-page .actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.settings-page .actions,
|
||||
.settings-page .form-actions {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.settings-page .form-actions {
|
||||
margin-top: 14px;
|
||||
}
|
||||
.settings-page h1,
|
||||
.settings-page h2,
|
||||
.settings-page h3 {
|
||||
color: #193c2e;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.settings-page h1 {
|
||||
font-size: clamp(24px, 3vw, 34px);
|
||||
}
|
||||
.settings-page h2 {
|
||||
font-size: 20px;
|
||||
}
|
||||
.settings-page h3 {
|
||||
font-size: 16px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.settings-page p {
|
||||
margin: 6px 0 12px;
|
||||
}
|
||||
.settings-page .small {
|
||||
font-size: 13px;
|
||||
}
|
||||
.settings-page .muted,
|
||||
.settings-page .eyebrow {
|
||||
color: #536b61;
|
||||
}
|
||||
.settings-page .eyebrow {
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
.settings-page .note,
|
||||
.settings-page .badge {
|
||||
background: #edf5f0;
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
}
|
||||
.settings-page .badge {
|
||||
padding: 3px 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.settings-page .warn {
|
||||
background: #fbf0db;
|
||||
}
|
||||
.settings-page .danger-text,
|
||||
.settings-page .error {
|
||||
color: #982f28;
|
||||
}
|
||||
.settings-page fieldset {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
.settings-page label {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.settings-page label.check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.settings-page input:not([type='checkbox']),
|
||||
.settings-page select {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
min-height: 38px;
|
||||
border: 1px solid #bdcec4;
|
||||
border-radius: 6px;
|
||||
padding: 6px 9px;
|
||||
background: white;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.settings-page input:read-only {
|
||||
background: #f6f8f6;
|
||||
}
|
||||
.settings-page button {
|
||||
border: 1px solid #b7c9be;
|
||||
color: inherit;
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
padding: 7px 12px;
|
||||
border-radius: 6px;
|
||||
font: inherit;
|
||||
}
|
||||
.settings-page button.primary {
|
||||
background: #23583d;
|
||||
color: white;
|
||||
border-color: transparent;
|
||||
}
|
||||
.settings-page button.danger {
|
||||
color: #982f28;
|
||||
border-color: #d8a8a0;
|
||||
}
|
||||
.settings-page button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: default;
|
||||
}
|
||||
.settings-page :is(button, input, select, summary):focus-visible {
|
||||
outline: 2px solid #377951;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.settings-page .grid,
|
||||
.settings-page .split,
|
||||
.settings-page .employee-filters {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
.settings-page .two,
|
||||
.settings-page .split {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.settings-page .three {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
.settings-page .four {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
.settings-page .employee-filters {
|
||||
grid-template-columns: minmax(130px, 2fr) minmax(120px, 1fr) auto auto;
|
||||
align-items: end;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.settings-page .table-wrap {
|
||||
overflow: auto;
|
||||
max-width: 100%;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.settings-page table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.settings-page td,
|
||||
.settings-page th {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #dbe5df;
|
||||
}
|
||||
.settings-page th {
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
color: #4c6658;
|
||||
}
|
||||
.settings-page .empty {
|
||||
padding: 12px;
|
||||
color: #52685d;
|
||||
}
|
||||
.settings-page .shop-cost-manager {
|
||||
border-top: 1px solid #e3e9e3;
|
||||
margin-top: 22px;
|
||||
padding-top: 14px;
|
||||
}
|
||||
.settings-page .shop-cost-search {
|
||||
max-width: 320px;
|
||||
}
|
||||
.settings-page .paper-mini {
|
||||
background: #fcfaf4;
|
||||
border: 1px solid #d8d2c2;
|
||||
padding: 16px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.settings-page .paper-mini td {
|
||||
border: 1px solid #ccc6b6;
|
||||
font-size: 12px;
|
||||
}
|
||||
.settings-page dialog {
|
||||
width: min(550px, calc(100vw - 32px));
|
||||
max-height: 88dvh;
|
||||
overflow: auto;
|
||||
box-sizing: border-box;
|
||||
padding: 24px;
|
||||
border: 1px solid #cbdbd0;
|
||||
border-radius: 12px;
|
||||
color: inherit;
|
||||
box-shadow: 0 25px 65px #11281940;
|
||||
}
|
||||
.settings-page dialog::backdrop {
|
||||
background: #132a1e66;
|
||||
}
|
||||
.settings-page .dialog-close {
|
||||
float: right;
|
||||
}
|
||||
.settings-page .settings-notice {
|
||||
position: fixed;
|
||||
bottom: 18px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 10;
|
||||
max-width: 90vw;
|
||||
pointer-events: none;
|
||||
background: #ecf4ef;
|
||||
color: #234d33;
|
||||
border: 1px solid #bacfc1;
|
||||
border-radius: 8px;
|
||||
padding: 10px 15px;
|
||||
}
|
||||
.settings-page .settings-notice.error {
|
||||
color: #8f302a;
|
||||
background: #fff4f1;
|
||||
}
|
||||
@media (max-width: 850px) {
|
||||
.settings-page .three,
|
||||
.settings-page .four {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.settings-page .split {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.settings-page .two,
|
||||
.settings-page .three,
|
||||
.settings-page .four {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.settings-page .employee-filters {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
.settings-page dialog {
|
||||
padding: 16px;
|
||||
}
|
||||
.settings-page .employee-table,
|
||||
.settings-page .shop-cost-table {
|
||||
min-width: 620px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import type { LedgerState, MemberRow } from '../../shared';
|
||||
|
||||
export interface Shop {
|
||||
revision: number;
|
||||
storeName: string;
|
||||
receiptSubtitle: string;
|
||||
contact: string;
|
||||
feeDefaults: { certificate: string; packaging: string; shipping: string; packagingPayer: string };
|
||||
creditCardRatePermille: number;
|
||||
profitSharePercent: number;
|
||||
profitShareEffectiveMonth: string;
|
||||
costPresets?: Record<string, unknown>;
|
||||
members: MemberRow[];
|
||||
}
|
||||
export interface Printing {
|
||||
store: string;
|
||||
subtitle: string;
|
||||
contact: string;
|
||||
rows: number;
|
||||
offsetX: number;
|
||||
offsetY: number;
|
||||
contentTop: number;
|
||||
rowHeight: number;
|
||||
}
|
||||
export interface SettingsState extends LedgerState {
|
||||
printing: Printing;
|
||||
orders: { id: string }[];
|
||||
backup?: { last?: { time: string }; error?: string };
|
||||
sync: { enabled: boolean; pending: number; failed: number; error?: string };
|
||||
}
|
||||
export type Notice = (text: string, error?: boolean) => void;
|
||||
export interface LeaveChecks {
|
||||
canLeave(): boolean;
|
||||
beforeUnload(): boolean;
|
||||
}
|
||||
export const legacyMembers = [
|
||||
{ member: 'owner', label: '麦麦' },
|
||||
{ member: 'assistant', label: '娜娜' },
|
||||
{ member: 'assistant2', label: '小昊' },
|
||||
];
|
||||
export function memberOptions(members: MemberRow[], selected = '', team = true): [string, string][] {
|
||||
const active = members.filter(m => (team || m.member !== 'assistant2') && m.enabled !== false);
|
||||
const values: [string, string][] = active.map(m => [m.member, m.label]);
|
||||
const historical = members.find(m => m.member === selected && m.enabled === false);
|
||||
if (historical && active.length) values.push([historical.member, historical.label + '(已停用 · 原记录)']);
|
||||
return values;
|
||||
}
|
||||
export function errorText(error: unknown) {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
export function readForm(form: HTMLFormElement): Record<string, string> {
|
||||
return Object.fromEntries(Array.from(new FormData(form), ([key, value]) => [key, String(value)]));
|
||||
}
|
||||
Reference in new issue
Block a user