小程序登录优化

This commit is contained in:
liu
2026-08-10 08:55:22 +08:00
parent c6f69c5c55
commit df7631c7a9
25 changed files with 954 additions and 549 deletions
+1 -4
View File
@@ -1,13 +1,10 @@
import createAxios from '@/utils/request';
export interface MiniUserBindParams {
/** 1门店 2供应商 */
type: number;
store_id?: number;
supplier_id?: number;
}
/** 绑定门店/供应商 */
/** 绑定门店 */
export async function bindMiniUser(id: number, data: MiniUserBindParams) {
return createAxios({
url: `/customer/miniUser/${id}/bind`,
-11
View File
@@ -1,5 +1,4 @@
import type IStore from '@/domain/iStore.ts';
import type ISupplier from '@/domain/iSupplier.ts';
/** 小程序用户 */
export default interface IMiniUser {
@@ -7,23 +6,13 @@ export default interface IMiniUser {
nickname?: string;
phone?: string;
avatar?: string;
/** 0待绑定 1门店 2供应商 */
type?: number;
store_id?: number;
supplier_id?: number;
store?: IStore;
supplier?: ISupplier;
status?: number;
last_login_at?: string;
created_at?: string;
}
export const MINI_USER_TYPE_MAP: Record<number, { text: string; color: string }> = {
0: { text: '待绑定', color: 'default' },
1: { text: '门店', color: 'blue' },
2: { text: '供应商', color: 'purple' },
};
export const MINI_USER_STATUS_MAP: Record<number, { text: string; color: string }> = {
0: { text: '停用', color: 'error' },
1: { text: '正常', color: 'success' },
+25 -94
View File
@@ -5,7 +5,6 @@ import {
message,
Modal,
Popconfirm,
Radio,
Select,
Space,
Tag,
@@ -18,20 +17,16 @@ import type {
XinTableProps,
} from '@/components/XinTable/typings.ts';
import type IMiniUser from '@/domain/iMiniUser.ts';
import { MINI_USER_STATUS_MAP, MINI_USER_TYPE_MAP } from '@/domain/iMiniUser.ts';
import { MINI_USER_STATUS_MAP } from '@/domain/iMiniUser.ts';
import type IStore from '@/domain/iStore.ts';
import type ISupplier from '@/domain/iSupplier.ts';
import { getStoreOptions } from '@/api/customer/store.ts';
import { getSupplierOptions } from '@/api/customer/supplier.ts';
import { bindMiniUser, toggleMiniUserStatus } from '@/api/customer/miniUser.ts';
import AuthButton from '@/components/AuthButton';
const { Title, Text } = Typography;
interface BindFormValues {
type: number;
store_id?: number;
supplier_id?: number;
store_id: number;
}
/**
@@ -40,7 +35,6 @@ interface BindFormValues {
const MiniUserPage: React.FC = () => {
const tableRef = useRef<XinTableInstance<IMiniUser>>(null);
const [stores, setStores] = useState<IStore[]>([]);
const [suppliers, setSuppliers] = useState<ISupplier[]>([]);
// 绑定弹窗
const [bindOpen, setBindOpen] = useState(false);
@@ -50,15 +44,12 @@ const MiniUserPage: React.FC = () => {
useEffect(() => {
getStoreOptions().then((res) => setStores(res.data.data ?? []));
getSupplierOptions().then((res) => setSuppliers(res.data.data ?? []));
}, []);
const openBind = (record: IMiniUser) => {
setBindTarget(record);
bindForm.setFieldsValue({
type: record.type && record.type > 0 ? record.type : undefined,
store_id: record.store_id || undefined,
supplier_id: record.supplier_id || undefined,
});
setBindOpen(true);
};
@@ -70,9 +61,7 @@ const MiniUserPage: React.FC = () => {
setBindLoading(true);
try {
await bindMiniUser(bindTarget.id, {
type: values.type,
store_id: values.type === 1 ? values.store_id : undefined,
supplier_id: values.type === 2 ? values.supplier_id : undefined,
store_id: values.store_id,
});
message.success('绑定成功');
setBindOpen(false);
@@ -118,36 +107,11 @@ const MiniUserPage: React.FC = () => {
render: (_, record) => record.phone || <Text type="secondary"></Text>,
},
{
title: '用户类型',
dataIndex: 'type',
valueType: 'select',
fieldProps: {
options: [
{ value: 0, label: '待绑定' },
{ value: 1, label: '门店' },
{ value: 2, label: '供应商' },
],
},
render: (_, record) => {
const item = MINI_USER_TYPE_MAP[record.type ?? 0];
return <Tag color={item?.color}>{item?.text}</Tag>;
},
align: 'center',
},
{
title: '绑定主体',
dataIndex: 'bound_name',
title: '绑定门店',
dataIndex: 'store_id',
hideInSearch: true,
render: (_, record) => {
if (record.type === 1) {
return <Tag color="blue">{record.store?.name ?? `门店#${record.store_id}`}</Tag>;
}
if (record.type === 2) {
return (
<Tag color="purple">{record.supplier?.name ?? `供应商#${record.supplier_id}`}</Tag>
);
}
return <Text type="secondary"></Text>;
return <Tag color="blue">{record.store?.name ?? `门店#${record.store_id}`}</Tag>;
},
},
{
@@ -173,6 +137,12 @@ const MiniUserPage: React.FC = () => {
align: 'center',
render: (_, record) => record.last_login_at ?? <Text type="secondary"></Text>,
},
{
title: '注册时间',
dataIndex: 'created_at',
hideInSearch: true,
align: 'center',
},
];
const operateRender: XinTableProps<IMiniUser>['operateRender'] = (record) => [
@@ -210,7 +180,7 @@ const MiniUserPage: React.FC = () => {
<div className="mb-5">
<Title level={3}></Title>
<Text type="secondary">
/
</Text>
</div>
<XinTable<IMiniUser> {...tableProps} />
@@ -231,60 +201,21 @@ const MiniUserPage: React.FC = () => {
className="mt-4"
>
<Form.Item
label="用户类型"
name="type"
rules={[{ required: true, message: '请选择用户类型' }]}
label="绑定门店"
name="store_id"
rules={[{ required: true, message: '请选择门店' }]}
>
<Radio.Group
options={[
{ label: '门店', value: 1 },
{ label: '供应商', value: 2 },
]}
optionType="button"
buttonStyle="solid"
<Select
showSearch={{
optionFilterProp: 'label'
}}
placeholder="选择门店"
options={stores.map((s) => ({
label: `${s.name}${s.code}`,
value: s.id,
}))}
/>
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.type !== cur.type}>
{({ getFieldValue }) => {
const type = getFieldValue('type');
if (type === 1) {
return (
<Form.Item
label="绑定门店"
name="store_id"
rules={[{ required: true, message: '请选择门店' }]}
>
<Select
showSearch
optionFilterProp="label"
placeholder="选择门店"
options={stores.map((s) => ({
label: `${s.name}${s.code}`,
value: s.id,
}))}
/>
</Form.Item>
);
}
if (type === 2) {
return (
<Form.Item
label="绑定供应商"
name="supplier_id"
rules={[{ required: true, message: '请选择供应商' }]}
>
<Select
showSearch
optionFilterProp="label"
placeholder="选择供应商"
options={suppliers.map((s) => ({ label: s.name, value: s.id }))}
/>
</Form.Item>
);
}
return null;
}}
</Form.Item>
</Form>
</Modal>
</>
+11 -10
View File
@@ -41,8 +41,7 @@ const StorePage: React.FC = () => {
title: '门店编码',
dataIndex: 'code',
valueType: 'text',
required: true,
rules: [{ required: true, message: '请输入门店编码' }],
hideInForm: true
},
{
title: '客户等级',
@@ -70,6 +69,14 @@ const StorePage: React.FC = () => {
valueType: 'text',
hideInSearch: true,
},
{
title: '门店地址',
dataIndex: 'address',
valueType: 'textarea',
hideInSearch: true,
fieldProps: { rows: 1 },
colProps: { span: 24 }
},
{
title: '回款周期(天)',
dataIndex: 'payment_cycle_days',
@@ -95,14 +102,6 @@ const StorePage: React.FC = () => {
return <Tag color={item?.color}>{item?.text}</Tag>;
},
},
{
title: '门店地址',
dataIndex: 'address',
valueType: 'textarea',
hideInSearch: true,
hideInTable: true,
fieldProps: { rows: 2 },
},
{
title: '备注',
dataIndex: 'remark',
@@ -110,6 +109,7 @@ const StorePage: React.FC = () => {
hideInSearch: true,
hideInTable: true,
fieldProps: { rows: 2 },
colProps: { span: 24 }
},
];
@@ -121,6 +121,7 @@ const StorePage: React.FC = () => {
formProps: {
grid: true,
colProps: { span: 12 },
rowProps: { gutter: 20 },
layout: 'vertical',
},
modalProps: { width: 720 },