fix[用户中心]:用户头像查询逻辑优化

This commit is contained in:
2025-02-17 18:09:10 +08:00
parent 4b29eea3ac
commit c00d064ad8
8 changed files with 368 additions and 11 deletions
@@ -0,0 +1,69 @@
import {
ModalForm,
ProForm,
ProFormText,
} from '@ant-design/pro-components';
import { Form } from 'antd';
export type FormValueType = Partial<ORDERS.Tourism>;
export type UpdateFormProps = {
onVisibleChange: (flag: boolean) => void;
onSubmit: (values: FormValueType) => Promise<void>;
updateModalVisible: boolean;
values?: ORDERS.Tourism;
};
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const [form] = Form.useForm();
return (
<ModalForm
title="修改二维码"
form={form}
visible={props.updateModalVisible}
onFinish={props.onSubmit}
onVisibleChange={props.onVisibleChange}
>
<ProForm.Group>
<ProFormText
rules={[
{
required: true,
message: '名称不为空',
},
]}
width="md"
name="tourismName"
label="名称"
placeholder="输入名称"
/>
<ProFormText
rules={[
{
required: true,
message: '地址不为空',
},
]}
width="md"
name="tourismAddress"
label="地址"
placeholder="输入地址"
/>
<ProFormText
rules={[
{
required: true,
message: '手机号不为空',
},
]}
width="md"
name="tourismPhone"
label="手机号"
placeholder="输入手机号"
/>
</ProForm.Group>
</ModalForm>
);
};
export default UpdateForm;
@@ -0,0 +1 @@
@import (reference) '~antd/es/style/themes/index';
@@ -0,0 +1,275 @@
import { deleteQrcode, qrcode, saveOrUpdateQrcode } from '@/services/orders/api';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
ModalForm,
PageContainer,
ProForm,
ProFormSelect,
ProFormText,
ProTable,
QueryFilter,
} from '@ant-design/pro-components';
import { Typography, Popconfirm, Space, message, Image, Button } from 'antd';
import React, { useRef, useState } from 'react';
import UpdateForm from './components/UpdateForm';
const { Link } = Typography;
const handleAdd = async (fields: ORDERS.Qrcode) => {
const hide = message.loading('正在添加');
try {
const result = await saveOrUpdateQrcode({ ...fields });
hide();
if (result.resp_code === 0) {
message.success('添加成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('添加失败');
return false;
}
};
const handleEdit = async (fields: ORDERS.Qrcode) => {
const hide = message.loading('正在更新');
try {
const result = await saveOrUpdateQrcode({ ...fields });
hide();
if (result.resp_code === 0) {
message.success('修改成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('修改失败');
return false;
}
};
const handleDelete = async (qrcode: ORDERS.Qrcode) => {
const hide = message.loading('正在删除');
try {
const result = await deleteQrcode(qrcode.id);
hide();
if (result.resp_code === 0) {
message.success('删除成功');
return true;
} else {
message.error(result.resp_msg);
return false;
}
} catch (error) {
hide();
message.error('删除失败');
return false;
}
};
const TableList: React.FC = () => {
const actionRef = useRef<ActionType>();
const [params, setParams] = useState<Record<string, string | number>>({ });
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
const columns: ProColumns<ORDERS.Qrcode>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
},
{
title: 'ID',
dataIndex: 'id',
},
{
title: 'CodeID',
dataIndex: 'codeId',
},
{
title: '景区ID',
dataIndex: 'tourismId',
},
{
title: '文件',
dataIndex: 'viewUrl',
render: (viewUrl) => <Image src={viewUrl} width={100} />
},
{
title: '价格',
dataIndex: 'price',
},
{
title: '设备SN',
dataIndex: 'deviceSn',
},
{
title: '状态',
dataIndex: 'status',
},
{
title: '创建时间',
dataIndex: 'createTime',
valueType: 'dateTime',
},
{
title: '操作',
key: 'action',
render: (_, entity) =>
<Space>
<Link
onClick={() => {
setCurrentRow(entity);
handleUpdateModalVisible(true);
}}
>
修改
</Link>
<Popconfirm
title={`确认删除景区[${entity.codeId}]?`}
onConfirm={async () => {
const success = await handleDelete(entity);
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
<Link>删除</Link>
</Popconfirm>
</Space>
},
];
return (
<PageContainer header={{ subTitle: '管理任务' }}>
<QueryFilter
defaultCollapsed
split
span={6}
className="query-filter"
onFinish={async (values) => setParams(values)}
>
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
</QueryFilter>
<ProTable<ORDERS.Qrcode>
rowKey="id"
headerTitle="二维码列表"
request={qrcode}
actionRef={actionRef}
columns={columns}
search={false}
params={params}
pagination={{
showSizeChanger: true,
showQuickJumper: true,
}}
toolBarRender={() => [
<>
<Button
type="primary"
onClick={() => {
handleModalVisible(true);
}}
>
<PlusOutlined /> 添加
</Button>
</>,
]}
/>
<ModalForm
title="添加二维码"
// layout="horizontal"
visible={createModalVisible}
onVisibleChange={handleModalVisible}
modalProps={{ destroyOnClose: true }}
onFinish={async (values) => {
const success = await handleAdd(values);
if (success) {
handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
<ProForm.Group>
<ProFormSelect
rules={[
{
required: true,
message: '景区不为空',
},
]}
width="md"
name="tourismId"
label="景区"
placeholder="请选择景区"
options={[
{ label: '北塘古镇', value: 33 },
{ label: '海丝首港', value: 32 },
{ label: '景区C', value: 2 },
// 添加更多选项...
]}
/>
<ProFormText
rules={[
{
required: true,
message: '价格不为空',
},
]}
width="md"
name="price"
label="景点打卡价格"
placeholder="输入价格(单位:分)"
/>
<ProFormSelect
rules={[
{
required: true,
message: '设备不为空',
},
]}
width="md"
name="deviceSn"
label="设备编号"
placeholder="输入设备编号"
options={[
{ label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' },
// 添加更多选项...
]}
/>
</ProForm.Group>
</ModalForm>
<UpdateForm
onSubmit={async (values) => {
if (currentRow) {
const success = await handleEdit({ ...currentRow, ...values });
if (success) {
handleUpdateModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
setCurrentRow(undefined);
}
}}
onVisibleChange={handleUpdateModalVisible}
updateModalVisible={updateModalVisible}
values={currentRow}
/>
</PageContainer>
);
};
export default TableList;