门店端子账号管理界面调整
CI / verify (pull_request) Has been cancelled

This commit is contained in:
2026-07-15 18:01:19 +08:00
parent d6ac4b5e1c
commit e7d39f7390
3 changed files with 768 additions and 157 deletions
+103 -25
View File
@@ -13,9 +13,12 @@ export default function SelectStorePage() {
const navigate = useNavigate();
const { applySession, store, authenticated } = useStoreSession();
const [stores, setStores] = useState<ShopStoreOption[]>(store?.stores ?? []);
const [loading, setLoading] = useState(false);
const [loadingId, setLoadingId] = useState<string | null>(null);
const [msg, setMsg] = useState('');
const currentStoreId = store?.storeId || '';
const canGoBack = Boolean(currentStoreId);
useEffect(() => {
if (!authenticated) {
navigate('/login', { replace: true });
@@ -27,7 +30,12 @@ export default function SelectStorePage() {
}, [authenticated, navigate]);
async function onSelect(storeId: string) {
setLoading(true);
if (loadingId) return;
if (storeId === currentStoreId) {
navigate('/', { replace: true });
return;
}
setLoadingId(storeId);
setMsg('');
try {
const session = await selectStore(storeId);
@@ -36,7 +44,7 @@ export default function SelectStorePage() {
} catch (e) {
setMsg(e instanceof Error ? e.message : '选店失败');
} finally {
setLoading(false);
setLoadingId(null);
}
}
@@ -48,31 +56,101 @@ export default function SelectStorePage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [stores.length]);
function statusLabel(status: string) {
if (status === 'OPEN') return '营业中';
if (status === 'PAUSED') return '暂停营业';
return status || '门店';
}
return (
<div className="shop-select-store-page">
<header className="shop-select-store-header">
<h1></h1>
<p></p>
<header className="shop-subpage-header">
{canGoBack ? (
<button
type="button"
className="shop-subpage-back"
onClick={() => navigate('/mine')}
aria-label="返回"
>
<span className="material-symbols-outlined">arrow_back</span>
</button>
) : (
<span className="shop-subpage-header-spacer" />
)}
<h1 className="app-page-title"></h1>
<span className="shop-subpage-header-spacer" />
</header>
{msg ? <p className="shop-select-store-msg">{msg}</p> : null}
<ul className="shop-select-store-list">
{stores.map((item) => (
<li key={item.storeId}>
<button
type="button"
className="shop-select-store-item"
disabled={loading}
onClick={() => void onSelect(item.storeId)}
>
<span className="shop-select-store-name">{item.name}</span>
<span className="shop-select-store-meta">
{[item.district, item.address].filter(Boolean).join(' · ') || item.status}
</span>
</button>
</li>
))}
</ul>
{!stores.length && !msg ? <p className="shop-select-store-empty"></p> : null}
<div className="shop-subpage-content">
<section className="shop-subpage-hero">
<div className="shop-subpage-hero-icon">
<span className="material-symbols-outlined shop-fill-icon">store</span>
</div>
<div>
<h2 className="shop-subpage-hero-title"></h2>
<p className="shop-subpage-hero-desc">
{stores.length || '多'}
</p>
</div>
</section>
{msg ? (
<p className="shop-subpage-msg" role="alert">
{msg}
</p>
) : null}
<section>
<h3 className="shop-subpage-section-title"></h3>
<ul className="shop-select-store-list">
{stores.map((item) => {
const active = item.storeId === currentStoreId;
const busy = loadingId === item.storeId;
return (
<li key={item.storeId}>
<button
type="button"
className={`shop-select-store-item${active ? ' is-active' : ''}`}
disabled={Boolean(loadingId)}
onClick={() => void onSelect(item.storeId)}
>
<div className="shop-select-store-item-icon">
<span className="material-symbols-outlined shop-fill-icon">storefront</span>
</div>
<div className="shop-select-store-item-body">
<div className="shop-select-store-item-top">
<span className="shop-select-store-name">{item.name}</span>
{active ? (
<span className="shop-select-store-badge"></span>
) : (
<span className="shop-select-store-status">{statusLabel(item.status)}</span>
)}
</div>
<span className="shop-select-store-meta">
{[item.district, item.address].filter(Boolean).join(' · ') ||
statusLabel(item.status)}
</span>
</div>
<span className="shop-select-store-item-action">
{busy ? (
'进入中…'
) : (
<span className="material-symbols-outlined">chevron_right</span>
)}
</span>
</button>
</li>
);
})}
</ul>
{!stores.length && !msg ? (
<div className="shop-subpage-empty">
<span className="material-symbols-outlined">store</span>
<p></p>
</div>
) : null}
</section>
</div>
</div>
);
}
+238 -64
View File
@@ -16,6 +16,11 @@ type StaffItem = {
type StoreOption = { storeId: string; name: string };
function maskPhone(phone: string) {
if (!phone || phone.length < 7) return phone;
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
export default function StaffPage() {
const navigate = useNavigate();
const { store } = useStoreSession();
@@ -24,6 +29,7 @@ export default function StaffPage() {
const [ownedStores, setOwnedStores] = useState<StoreOption[]>([]);
const [msg, setMsg] = useState('');
const [showForm, setShowForm] = useState(false);
const [submitting, setSubmitting] = useState(false);
const [form, setForm] = useState({ phone: '', name: '', storeIds: [] as string[] });
async function reload() {
@@ -44,13 +50,24 @@ export default function StaffPage() {
}, [navigate, profile?.isPrimary]);
async function createStaff() {
const phone = form.phone.trim();
const name = form.name.trim();
if (!/^1[3-9]\d{9}$/.test(phone)) {
setMsg('请输入正确的手机号');
return;
}
if (!name) {
setMsg('请填写姓名');
return;
}
setMsg('');
setSubmitting(true);
try {
await request('SHOP_H5', '/shop/staff', {
method: 'POST',
body: JSON.stringify({
phone: form.phone.trim(),
name: form.name.trim(),
phone,
name,
storeIds: form.storeIds.length ? form.storeIds : ownedStores.map((s) => s.storeId),
}),
});
@@ -59,6 +76,8 @@ export default function StaffPage() {
await reload();
} catch (e) {
setMsg(e instanceof Error ? e.message : '创建失败');
} finally {
setSubmitting(false);
}
}
@@ -76,78 +95,233 @@ export default function StaffPage() {
}
function toggleStoreId(storeId: string) {
setForm((prev) => ({
...prev,
storeIds: prev.storeIds.includes(storeId)
setForm((prev) => {
const allIds = ownedStores.map((s) => s.storeId);
// 空数组表示「全部」;取消某一家时转为「除该店外的全部」
if (prev.storeIds.length === 0) {
return { ...prev, storeIds: allIds.filter((id) => id !== storeId) };
}
const next = prev.storeIds.includes(storeId)
? prev.storeIds.filter((id) => id !== storeId)
: [...prev.storeIds, storeId],
}));
: [...prev.storeIds, storeId];
// 又选回全部时,恢复默认空数组语义
if (next.length === allIds.length) {
return { ...prev, storeIds: [] };
}
return { ...prev, storeIds: next };
});
}
const selectedCount =
form.storeIds.length === 0 ? ownedStores.length : form.storeIds.length;
return (
<div className="shop-staff-page">
<header className="shop-staff-header">
<button type="button" className="shop-staff-back" onClick={() => navigate('/mine')}>
</button>
<h1></h1>
<button type="button" className="shop-staff-add" onClick={() => setShowForm((v) => !v)}>
{showForm ? '取消' : '添加'}
<header className="shop-subpage-header">
<button
type="button"
className="shop-subpage-back"
onClick={() => {
if (showForm) {
setShowForm(false);
setMsg('');
return;
}
navigate('/mine');
}}
aria-label="返回"
>
<span className="material-symbols-outlined">arrow_back</span>
</button>
<h1 className="app-page-title">{showForm ? '添加子账号' : '子账号管理'}</h1>
{!showForm ? (
<button
type="button"
className="shop-subpage-header-action"
onClick={() => {
setShowForm(true);
setMsg('');
}}
>
<span className="material-symbols-outlined">person_add</span>
</button>
) : (
<span className="shop-subpage-header-spacer" />
)}
</header>
{msg ? <p className="shop-staff-msg">{msg}</p> : null}
{showForm ? (
<div className="shop-staff-form">
<input
placeholder="手机号"
value={form.phone}
onChange={(e) => setForm((f) => ({ ...f, phone: e.target.value }))}
/>
<input
placeholder="姓名"
value={form.name}
onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
/>
<p className="shop-staff-form-label"></p>
<div className="shop-staff-store-picks">
{ownedStores.map((s) => (
<label key={s.storeId}>
<input
type="checkbox"
checked={form.storeIds.includes(s.storeId) || form.storeIds.length === 0}
onChange={() => toggleStoreId(s.storeId)}
/>
{s.name}
</label>
))}
</div>
<button type="button" onClick={() => void createStaff()}>
</button>
</div>
) : null}
<ul className="shop-staff-list">
{list.map((item) => (
<li key={item.id} className="shop-staff-item">
<div>
<strong>{item.name}</strong>
<span>{item.phone}</span>
<span>
{STORE_STAFF_ROLE_LABELS[item.staffRole] ?? item.staffRole} ·{' '}
{item.status === 'ACTIVE' ? '启用' : '停用'}
</span>
<span>{item.stores.map((s) => s.name).join('、')}</span>
<div className="shop-subpage-content">
{!showForm ? (
<section className="shop-subpage-hero shop-subpage-hero--compact">
<div className="shop-subpage-hero-icon">
<span className="material-symbols-outlined shop-fill-icon">group</span>
</div>
<button type="button" onClick={() => void toggleStatus(item)}>
{item.status === 'ACTIVE' ? '停用' : '启用'}
<div>
<h2 className="shop-subpage-hero-title"></h2>
<p className="shop-subpage-hero-desc">
{list.length} ·
</p>
</div>
</section>
) : null}
{msg ? (
<p className="shop-subpage-msg" role="alert">
{msg}
</p>
) : null}
{showForm ? (
<section className="shop-staff-form-card">
<div className="shop-staff-form-field">
<label className="shop-staff-form-label" htmlFor="staff-phone">
</label>
<div className="shop-staff-form-input-wrap">
<span className="material-symbols-outlined">smartphone</span>
<input
id="staff-phone"
type="tel"
inputMode="numeric"
maxLength={11}
placeholder="员工登录手机号"
value={form.phone}
onChange={(e) =>
setForm((f) => ({ ...f, phone: e.target.value.replace(/\D/g, '').slice(0, 11) }))
}
/>
</div>
</div>
<div className="shop-staff-form-field">
<label className="shop-staff-form-label" htmlFor="staff-name">
</label>
<div className="shop-staff-form-input-wrap">
<span className="material-symbols-outlined">badge</span>
<input
id="staff-name"
type="text"
placeholder="员工姓名"
value={form.name}
onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
/>
</div>
</div>
<div className="shop-staff-form-field">
<p className="shop-staff-form-label">
<span className="shop-staff-form-hint">
{form.storeIds.length === 0
? `(默认全部 ${ownedStores.length} 家)`
: `(已选 ${selectedCount} 家)`}
</span>
</p>
<div className="shop-staff-store-picks">
{ownedStores.map((s) => {
const checked =
form.storeIds.length === 0 || form.storeIds.includes(s.storeId);
return (
<label
key={s.storeId}
className={`shop-staff-store-pick${checked ? ' is-checked' : ''}`}
>
<input
type="checkbox"
checked={checked}
onChange={() => toggleStoreId(s.storeId)}
/>
<span className="material-symbols-outlined shop-fill-icon">storefront</span>
<span className="shop-staff-store-pick-name">{s.name}</span>
{checked ? (
<span className="material-symbols-outlined shop-staff-store-pick-check">
check_circle
</span>
) : null}
</label>
);
})}
</div>
</div>
<button
type="button"
className="shop-staff-submit"
disabled={submitting}
onClick={() => void createStaff()}
>
{submitting ? '创建中…' : '创建子账号'}
</button>
</li>
))}
</ul>
{!list.length ? <p className="shop-staff-empty"></p> : null}
<button
type="button"
className="shop-staff-cancel"
disabled={submitting}
onClick={() => {
setShowForm(false);
setMsg('');
}}
>
</button>
</section>
) : (
<section>
<div className="shop-home-records-head">
<h3 className="shop-home-records-title"></h3>
</div>
<ul className="shop-staff-list">
{list.map((item) => {
const active = item.status === 'ACTIVE';
const initial = (item.name || item.phone || '?').slice(0, 1);
return (
<li key={item.id} className="shop-staff-item">
<div className="shop-staff-avatar">{initial}</div>
<div className="shop-staff-item-body">
<div className="shop-staff-item-top">
<strong>{item.name || '未命名'}</strong>
<span
className={`shop-staff-status-badge${active ? ' is-active' : ' is-disabled'}`}
>
{active ? '启用' : '停用'}
</span>
</div>
<p className="shop-staff-item-meta">{maskPhone(item.phone)}</p>
<p className="shop-staff-item-meta">
{STORE_STAFF_ROLE_LABELS[item.staffRole] ?? item.staffRole}
{item.stores.length
? ` · ${item.stores.map((s) => s.name).join('、')}`
: ''}
</p>
</div>
<button
type="button"
className={`shop-staff-toggle${active ? '' : ' is-enable'}`}
onClick={() => void toggleStatus(item)}
>
{active ? '停用' : '启用'}
</button>
</li>
);
})}
</ul>
{!list.length ? (
<div className="shop-subpage-empty">
<span className="material-symbols-outlined">person_off</span>
<p></p>
<button
type="button"
className="shop-staff-empty-add"
onClick={() => setShowForm(true)}
>
</button>
</div>
) : null}
</section>
)}
</div>
</div>
);
}