小程序用户改用门店登录

This commit is contained in:
liu
2026-08-20 13:46:04 +08:00
parent 6d9f02d831
commit c1d490134e
251 changed files with 689 additions and 2727 deletions
-23
View File
@@ -1,23 +0,0 @@
import createAxios from '@/utils/request';
export interface MiniUserBindParams {
store_id?: number;
}
/** 绑定门店 */
export async function bindMiniUser(id: number, data: MiniUserBindParams) {
return createAxios({
url: `/customer/miniUser/${id}/bind`,
method: 'put',
data,
});
}
/** 启用/停用小程序用户 */
export async function toggleMiniUserStatus(id: number, status: number) {
return createAxios({
url: `/customer/miniUser/${id}/status`,
method: 'put',
data: { status },
});
}
+1 -1
View File
@@ -1,7 +1,7 @@
import createAxios from '@/utils/request';
import type IStore from '@/domain/iStore.ts';
/** 门店下拉选项(小程序用户绑定、订单筛选用) */
/** 门店下拉选项(订单/账单/通知等筛选用) */
export async function getStoreOptions() {
return createAxios<IStore[]>({
url: '/customer/store/options',
-2
View File
@@ -88,8 +88,6 @@ export interface IDashboardArchives {
products: number;
/** 合作供应商 */
suppliers: number;
/** 小程序用户 */
users: number;
}
/** 仪表盘分析页聚合数据(GET /dashboard/analysis */
-19
View File
@@ -1,19 +0,0 @@
import type IStore from '@/domain/iStore.ts';
/** 小程序用户 */
export default interface IMiniUser {
id?: number;
nickname?: string;
phone?: string;
avatar?: string;
store_id?: number;
store?: IStore;
status?: number;
last_login_at?: string;
created_at?: string;
}
export const MINI_USER_STATUS_MAP: Record<number, { text: string; color: string }> = {
0: { text: '停用', color: 'error' },
1: { text: '正常', color: 'success' },
};
+2 -2
View File
@@ -1,7 +1,7 @@
/** 通知(user_id=0 为全员广播) */
/** 通知(store_id=0 为全员广播) */
export default interface INotice {
id?: number;
user_id?: number;
store_id?: number;
/** order订单 price价格 system系统 */
type?: string;
title?: string;
-2
View File
@@ -3,7 +3,6 @@ export default interface IPayment {
id?: number;
payment_no?: string;
store_id?: number;
user_id?: number;
/** 支付金额(= 关联账单总金额合计) */
amount?: string;
/** 支付方式:1微信 2支付宝 3对公汇款 */
@@ -22,7 +21,6 @@ export default interface IPayment {
created_at?: string;
/** 列表/详情接口附带 */
store?: { id: number; name: string; contact?: string; phone?: string } | null;
user?: { id: number; nickname: string } | null;
auditor?: { id: number; nickname: string } | null;
bills_count?: number;
}
+8
View File
@@ -6,6 +6,14 @@ export default interface IStore {
name?: string;
/** 门店编码 */
code?: string;
/** 登录账号(小程序端 账号+密码 登录) */
username?: string;
/** 登录密码(创建必填,编辑留空不修改;接口永不回显) */
password?: string;
/** 头像 */
avatar?: string;
/** 最后登录时间 */
last_login_at?: string | null;
/** 客户等级ID(决定商品价格) */
level_id?: number;
level?: ICustomerLevel;
-1
View File
@@ -53,5 +53,4 @@ export default {
"dashboard.analysis.archivesStores": "Active Stores",
"dashboard.analysis.archivesProducts": "On-sale Products",
"dashboard.analysis.archivesSuppliers": "Suppliers",
"dashboard.analysis.archivesUsers": "Mini-app Users",
};
-1
View File
@@ -53,5 +53,4 @@ export default {
"dashboard.analysis.archivesStores": "在营门店",
"dashboard.analysis.archivesProducts": "在售商品",
"dashboard.analysis.archivesSuppliers": "合作供应商",
"dashboard.analysis.archivesUsers": "小程序用户",
};
-225
View File
@@ -1,225 +0,0 @@
import React, { useEffect, useRef, useState } from 'react';
import {
Button,
Form,
message,
Modal,
Popconfirm,
Select,
Space,
Tag,
Typography,
} from 'antd';
import XinTable from '@/components/XinTable';
import type {
XinTableColumn,
XinTableInstance,
XinTableProps,
} from '@/components/XinTable/typings.ts';
import type IMiniUser from '@/domain/iMiniUser.ts';
import { MINI_USER_STATUS_MAP } from '@/domain/iMiniUser.ts';
import type IStore from '@/domain/iStore.ts';
import { getStoreOptions } from '@/api/customer/store.ts';
import { bindMiniUser, toggleMiniUserStatus } from '@/api/customer/miniUser.ts';
import AuthButton from '@/components/AuthButton';
const { Title, Text } = Typography;
interface BindFormValues {
store_id: number;
}
/**
* 小程序用户管理(用户由小程序登录自动生成,后台只做绑定与状态管理)
*/
const MiniUserPage: React.FC = () => {
const tableRef = useRef<XinTableInstance<IMiniUser>>(null);
const [stores, setStores] = useState<IStore[]>([]);
// 绑定弹窗
const [bindOpen, setBindOpen] = useState(false);
const [bindTarget, setBindTarget] = useState<IMiniUser | null>(null);
const [bindLoading, setBindLoading] = useState(false);
const [bindForm] = Form.useForm<BindFormValues>();
useEffect(() => {
getStoreOptions().then((res) => setStores(res.data.data ?? []));
}, []);
const openBind = (record: IMiniUser) => {
setBindTarget(record);
bindForm.setFieldsValue({
store_id: record.store_id || undefined,
});
setBindOpen(true);
};
const handleBind = async (values: BindFormValues) => {
if (!bindTarget?.id) {
return;
}
setBindLoading(true);
try {
await bindMiniUser(bindTarget.id, {
store_id: values.store_id,
});
message.success('绑定成功');
setBindOpen(false);
await tableRef.current?.reload();
} finally {
setBindLoading(false);
}
};
const handleToggleStatus = async (record: IMiniUser) => {
await toggleMiniUserStatus(record.id!, record.status === 1 ? 0 : 1);
message.success(record.status === 1 ? '已停用' : '已启用');
await tableRef.current?.reload();
};
const columns: XinTableColumn<IMiniUser>[] = [
{
title: 'ID',
dataIndex: 'id',
hideInSearch: true,
width: 70,
align: 'center',
},
{
title: '昵称',
dataIndex: 'nickname',
valueType: 'text',
hideInSearch: true,
render: (_, record) => (
<Space size={8}>
{record.avatar ? (
<img src={record.avatar} alt="" className="h-6 w-6 rounded-full" />
) : null}
<span>{record.nickname || '-'}</span>
</Space>
),
},
{
title: '手机号',
dataIndex: 'phone',
valueType: 'text',
hideInSearch: true,
render: (_, record) => record.phone || <Text type="secondary"></Text>,
},
{
title: '绑定门店',
dataIndex: 'store_id',
hideInSearch: true,
render: (_, record) => {
return <Tag color="blue">{record.store?.name ?? `门店#${record.store_id}`}</Tag>;
},
},
{
title: '状态',
dataIndex: 'status',
valueType: 'select',
fieldProps: {
options: [
{ value: 1, label: '正常' },
{ value: 0, label: '停用' },
],
},
render: (_, record) => {
const item = MINI_USER_STATUS_MAP[record.status ?? 1];
return <Tag color={item?.color}>{item?.text}</Tag>;
},
align: 'center',
},
{
title: '最后登录',
dataIndex: 'last_login_at',
hideInSearch: true,
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) => [
<AuthButton key="bind" auth="customer.miniUser.bind">
<Button size="small" color="blue" variant="outlined" onClick={() => openBind(record)}>
</Button>
</AuthButton>,
<AuthButton key="status" auth="customer.miniUser.update">
<Popconfirm
title={record.status === 1 ? '确定停用该账号?' : '确定启用该账号?'}
description={record.status === 1 ? '停用后该用户将无法登录小程序' : undefined}
onConfirm={() => handleToggleStatus(record)}
>
<Button size="small" danger={record.status === 1}>
{record.status === 1 ? '停用' : '启用'}
</Button>
</Popconfirm>
</AuthButton>,
];
const tableProps: XinTableProps<IMiniUser> = {
api: '/customer/miniUser',
columns,
rowKey: 'id',
accessName: 'customer.miniUser',
tableRef,
operateRender,
// 无新增/编辑表单
formProps: false,
};
return (
<>
<div className="mb-5">
<Title level={3}></Title>
<Text type="secondary">
</Text>
</div>
<XinTable<IMiniUser> {...tableProps} />
<Modal
title={`绑定主体 · ${bindTarget?.nickname || ''}`}
open={bindOpen}
onCancel={() => setBindOpen(false)}
onOk={() => bindForm.submit()}
confirmLoading={bindLoading}
okText="确认绑定"
destroyOnHidden
>
<Form<BindFormValues>
form={bindForm}
layout="vertical"
onFinish={handleBind}
className="mt-4"
>
<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>
</Form>
</Modal>
</>
);
};
export default MiniUserPage;
+26 -11
View File
@@ -1,16 +1,30 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { Tag, Typography } from 'antd';
import XinTable from '@/components/XinTable';
import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings.ts';
import type INotice from '@/domain/iNotice.ts';
import { NOTICE_READ_MAP, NOTICE_TYPE_MAP } from '@/domain/iNotice.ts';
import type IStore from '@/domain/iStore.ts';
import { getStoreOptions } from '@/api/customer/store.ts';
const { Title, Text } = Typography;
/**
* 通知管理(user_id=0 为全员广播)
* 通知管理(store_id=0 为全员广播)
*/
const NoticePage: React.FC = () => {
const [stores, setStores] = useState<IStore[]>([]);
useEffect(() => {
getStoreOptions().then((res) => setStores(res.data.data ?? []));
}, []);
const storeNameMap = new Map(stores.map((s) => [s.id, s.name]));
const storeOptions = [
{ label: '全员广播', value: 0 },
...stores.map((s) => ({ label: s.name ?? '', value: s.id ?? 0 })),
];
const columns: XinTableColumn<INotice>[] = [
{
title: 'ID',
@@ -48,21 +62,22 @@ const NoticePage: React.FC = () => {
},
{
title: '接收对象',
dataIndex: 'user_id',
valueType: 'digit',
hideInTable: false,
dataIndex: 'store_id',
valueType: 'select',
hideInSearch: true,
initialValue: 0,
fieldProps: {
min: 0,
precision: 0,
placeholder: '留空或 0 = 全员广播',
options: storeOptions,
showSearch: true,
optionFilterProp: 'label',
placeholder: '默认全员广播',
},
align: 'center',
render: (_, record) =>
record.user_id === 0 ? (
record.store_id === 0 ? (
<Tag color="gold">广</Tag>
) : (
<Tag>{`用户 #${record.user_id}`}</Tag>
<Tag>{storeNameMap.get(record.store_id) ?? `门店 #${record.store_id}`}</Tag>
),
},
{
@@ -119,7 +134,7 @@ const NoticePage: React.FC = () => {
<div className="mb-5">
<Title level={3}></Title>
<Text type="secondary">
0 广
广
</Text>
</div>
<XinTable<INotice> {...tableProps} />
+23 -1
View File
@@ -43,6 +43,28 @@ const StorePage: React.FC = () => {
valueType: 'text',
hideInForm: true
},
{
title: '登录账号',
dataIndex: 'username',
valueType: 'text',
required: true,
rules: [
{ required: true, message: '请输入登录账号' },
{ min: 4, max: 20, message: '账号长度为 4~20 个字符' },
],
fieldProps: { placeholder: '小程序端登录账号' },
},
{
title: '登录密码',
dataIndex: 'password',
valueType: 'password',
hideInTable: true,
hideInSearch: true,
rules: [
{ min: 6, max: 20, message: '密码长度为 6~20 位' },
],
fieldProps: { placeholder: '创建必填;编辑留空则不修改' },
},
{
title: '客户等级',
dataIndex: 'level_id',
@@ -141,7 +163,7 @@ const StorePage: React.FC = () => {
<>
<div className="mb-5">
<Title level={3}></Title>
<Text type="secondary"></Text>
<Text type="secondary">/</Text>
</div>
<XinTable<IStore> {...tableProps} />
</>
+4 -14
View File
@@ -17,7 +17,6 @@ import {
ShopOutlined,
ShoppingCartOutlined,
TruckOutlined,
UserOutlined,
WalletOutlined,
} from "@ant-design/icons";
import ReactECharts from "echarts-for-react";
@@ -55,7 +54,7 @@ const EMPTY: IDashboardAnalysis = {
top_stores: [],
recon: { bills: [], pending_payment: { count: 0, amount: 0 } },
latest_orders: [],
archives: { stores: 0, products: 0, suppliers: 0, users: 0 },
archives: { stores: 0, products: 0, suppliers: 0 },
};
/** 环比涨跌(红涨绿跌);上期为0无基准时显示 — */
@@ -597,7 +596,7 @@ const Index: React.FC = () => {
</Col>
{/* ===== 基础档案 ===== */}
<Col xxl={6} lg={12} xs={24}>
<Col xxl={8} lg={12} xs={24}>
<Card variant={"borderless"}>
<Statistic
title={t("dashboard.analysis.archivesStores")}
@@ -606,7 +605,7 @@ const Index: React.FC = () => {
/>
</Card>
</Col>
<Col xxl={6} lg={12} xs={24}>
<Col xxl={8} lg={12} xs={24}>
<Card variant={"borderless"}>
<Statistic
title={t("dashboard.analysis.archivesProducts")}
@@ -615,7 +614,7 @@ const Index: React.FC = () => {
/>
</Card>
</Col>
<Col xxl={6} lg={12} xs={24}>
<Col xxl={8} lg={12} xs={24}>
<Card variant={"borderless"}>
<Statistic
title={t("dashboard.analysis.archivesSuppliers")}
@@ -624,15 +623,6 @@ const Index: React.FC = () => {
/>
</Card>
</Col>
<Col xxl={6} lg={12} xs={24}>
<Card variant={"borderless"}>
<Statistic
title={t("dashboard.analysis.archivesUsers")}
value={archives.users}
prefix={<UserOutlined style={{ color: token.colorInfo }} />}
/>
</Card>
</Col>
</Row>
</Spin>
);
-9
View File
@@ -211,14 +211,6 @@ const PaymentPage: React.FC = () => {
return <Tag color={item?.color}>{item?.text}</Tag>;
},
},
{
title: '提交人',
dataIndex: 'user',
hideInForm: true,
hideInSearch: true,
align: 'center',
render: (_, record) => record.user?.nickname ?? '-',
},
{
title: '提交时间',
dataIndex: 'created_at',
@@ -310,7 +302,6 @@ const PaymentPage: React.FC = () => {
{PAYMENT_STATUS_MAP[detail.payment.status ?? 0]?.text}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="提交人">{detail.payment.user?.nickname ?? '-'}</Descriptions.Item>
<Descriptions.Item label="提交时间">{detail.payment.created_at}</Descriptions.Item>
<Descriptions.Item label="审核人">{detail.payment.auditor?.nickname ?? '-'}</Descriptions.Item>
<Descriptions.Item label="审核时间">{detail.payment.audited_at ?? '-'}</Descriptions.Item>