style(客户账号): 手机号/用户名登录切换对齐配送系统
This commit is contained in:
@@ -202,6 +202,12 @@ export const customers: MessageDict = {
|
||||
'account.username': 'Username',
|
||||
'account.phone': 'Phone',
|
||||
'account.passwordOptional': 'Initial password (optional)',
|
||||
'account.modePhone': 'Phone login',
|
||||
'account.modeUsername': 'Username login',
|
||||
'account.phoneInvalid': 'Enter a valid 11-digit phone',
|
||||
'account.usernameRequired': 'Enter a username',
|
||||
'account.usernameNotPhone': 'Username cannot be a phone number',
|
||||
'account.password': 'Initial password (optional)',
|
||||
'account.create': 'Create login account',
|
||||
'account.created': 'Account created',
|
||||
'account.createdWithPassword': 'Account created. Initial password: {password}',
|
||||
|
||||
@@ -203,6 +203,12 @@ export const customers: MessageDict = {
|
||||
'account.username': 'Nama pengguna',
|
||||
'account.phone': 'Telepon',
|
||||
'account.passwordOptional': 'Kata sandi awal (opsional)',
|
||||
'account.modePhone': 'Login telepon',
|
||||
'account.modeUsername': 'Login nama pengguna',
|
||||
'account.phoneInvalid': 'Masukkan nomor telepon 11 digit',
|
||||
'account.usernameRequired': 'Masukkan nama pengguna',
|
||||
'account.usernameNotPhone': 'Nama pengguna tidak boleh nomor telepon',
|
||||
'account.password': 'Kata sandi awal (opsional)',
|
||||
'account.create': 'Buat akun login',
|
||||
'account.created': 'Akun dibuat',
|
||||
'account.createdWithPassword': 'Akun dibuat. Kata sandi awal: {password}',
|
||||
|
||||
@@ -202,6 +202,12 @@ export const customers: MessageDict = {
|
||||
'account.username': '登录名',
|
||||
'account.phone': '手机号',
|
||||
'account.passwordOptional': '初始密码(选填)',
|
||||
'account.modePhone': '手机号登录',
|
||||
'account.modeUsername': '用户名登录',
|
||||
'account.phoneInvalid': '请填写11位手机号',
|
||||
'account.usernameRequired': '请填写用户名',
|
||||
'account.usernameNotPhone': '用户名不能是手机号',
|
||||
'account.password': '初始密码(选填)',
|
||||
'account.create': '开通登录账号',
|
||||
'account.created': '账号已开通',
|
||||
'account.createdWithPassword': '账号已开通,初始密码:{password}',
|
||||
|
||||
@@ -848,7 +848,7 @@ export const CustomerManagement: React.FC = () => {
|
||||
const [accountCustomer, setAccountCustomer] = useState<Customer | null>(null);
|
||||
const [accountInfo, setAccountInfo] = useState<CustomerOrderAccount | null>(null);
|
||||
const [accountSaving, setAccountSaving] = useState(false);
|
||||
const [accountForm, setAccountForm] = useState({ phone: '', username: '', password: '' });
|
||||
const [accountForm, setAccountForm] = useState({ mode: 'phone' as 'phone' | 'username', phone: '', username: '', password: '' });
|
||||
const [savingCustomer, setSavingCustomer] = useState(false);
|
||||
const savingCustomerRef = useRef(false);
|
||||
|
||||
@@ -1345,9 +1345,15 @@ export const CustomerManagement: React.FC = () => {
|
||||
|
||||
const openAccountModal = async (customer: Customer) => {
|
||||
const phone = String(customer.contact_phone || '').trim();
|
||||
const phoneLogin = /^1[3-9]\d{9}$/.test(phone);
|
||||
setAccountCustomer(customer);
|
||||
setAccountInfo(null);
|
||||
setAccountForm({ phone, username: phone, password: '' });
|
||||
setAccountForm({
|
||||
mode: phoneLogin ? 'phone' : 'username',
|
||||
phone: phoneLogin ? phone : '',
|
||||
username: '',
|
||||
password: '',
|
||||
});
|
||||
try {
|
||||
const { data } = await listCustomerOrderAccountsApi([customer.customer_code]);
|
||||
setAccountInfo(data?.[customer.customer_code] || null);
|
||||
@@ -1357,9 +1363,28 @@ export const CustomerManagement: React.FC = () => {
|
||||
};
|
||||
const createAccount = async () => {
|
||||
if (!accountCustomer) return;
|
||||
const password = accountForm.password.trim() || undefined;
|
||||
const phoneMode = accountForm.mode === 'phone';
|
||||
const phone = accountForm.phone.trim();
|
||||
const username = accountForm.username.trim();
|
||||
if (phoneMode) {
|
||||
if (!/^1[3-9]\d{9}$/.test(phone)) {
|
||||
notify.error(t('customers.account.phoneInvalid'));
|
||||
return;
|
||||
}
|
||||
} else if (!username) {
|
||||
notify.error(t('customers.account.usernameRequired'));
|
||||
return;
|
||||
} else if (/^1[3-9]\d{9}$/.test(username)) {
|
||||
notify.error(t('customers.account.usernameNotPhone'));
|
||||
return;
|
||||
}
|
||||
setAccountSaving(true);
|
||||
try {
|
||||
const { data } = await createCustomerOrderLoginAccountApi(accountCustomer.customer_code, accountForm);
|
||||
const { data } = await createCustomerOrderLoginAccountApi(
|
||||
accountCustomer.customer_code,
|
||||
phoneMode ? { phone, username: phone, password } : { username, password }
|
||||
);
|
||||
notify.success(
|
||||
data.default_password
|
||||
? t('customers.account.createdWithPassword', { password: data.default_password })
|
||||
@@ -2708,9 +2733,53 @@ export const CustomerManagement: React.FC = () => {
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<input className="app-input w-full" placeholder={t('customers.account.phone')} value={accountForm.phone} onChange={(e) => setAccountForm((f) => ({ ...f, phone: e.target.value }))} />
|
||||
<input className="app-input w-full" placeholder={t('customers.account.username')} value={accountForm.username} onChange={(e) => setAccountForm((f) => ({ ...f, username: e.target.value }))} />
|
||||
<input className="app-input w-full" type="password" placeholder={t('customers.account.passwordOptional')} value={accountForm.password} onChange={(e) => setAccountForm((f) => ({ ...f, password: e.target.value }))} />
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAccountForm((prev) => ({ ...prev, mode: 'phone' }))}
|
||||
className={`px-3 py-2 text-sm rounded-lg border ${
|
||||
accountForm.mode === 'phone'
|
||||
? 'border-emerald-600 bg-emerald-600 text-white'
|
||||
: 'border-slate-200 app-foreground'
|
||||
}`}
|
||||
>
|
||||
{t('customers.account.modePhone')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAccountForm((prev) => ({ ...prev, mode: 'username' }))}
|
||||
className={`px-3 py-2 text-sm rounded-lg border ${
|
||||
accountForm.mode === 'username'
|
||||
? 'border-emerald-600 bg-emerald-600 text-white'
|
||||
: 'border-slate-200 app-foreground'
|
||||
}`}
|
||||
>
|
||||
{t('customers.account.modeUsername')}
|
||||
</button>
|
||||
</div>
|
||||
{accountForm.mode === 'phone' ? (
|
||||
<input
|
||||
className="app-input w-full"
|
||||
inputMode="numeric"
|
||||
placeholder={t('customers.account.phone')}
|
||||
value={accountForm.phone}
|
||||
onChange={(e) => setAccountForm((prev) => ({ ...prev, phone: e.target.value }))}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className="app-input w-full"
|
||||
placeholder={t('customers.account.username')}
|
||||
value={accountForm.username}
|
||||
onChange={(e) => setAccountForm((prev) => ({ ...prev, username: e.target.value }))}
|
||||
/>
|
||||
)}
|
||||
<input
|
||||
className="app-input w-full"
|
||||
type="password"
|
||||
placeholder={t('customers.account.passwordOptional')}
|
||||
value={accountForm.password}
|
||||
onChange={(e) => setAccountForm((prev) => ({ ...prev, password: e.target.value }))}
|
||||
/>
|
||||
<button type="button" className="app-button-primary w-full" disabled={accountSaving} onClick={() => void createAccount()}>
|
||||
{t('customers.account.create')}
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user