feat[通用模块]:getViewUrlByName在文件存储中fileName,小程序二维码生成并上传逻辑完善,二维码管理后台功能实现以及其他逻辑优化
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm } from 'antd';
|
||||
import { Typography, message, Popconfirm, Image } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
@@ -47,6 +47,11 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'size',
|
||||
valueType: 'digit',
|
||||
},
|
||||
{
|
||||
title: '文件预览',
|
||||
dataIndex: 'url',
|
||||
render: (url) => <Image src={url} width={100} />
|
||||
},
|
||||
{
|
||||
title: '媒体类型',
|
||||
dataIndex: 'contentType',
|
||||
|
||||
@@ -72,7 +72,7 @@ const TableList: React.FC = () => {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '文件类型',
|
||||
title: '媒体类型',
|
||||
dataIndex: 'fileType',
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
@@ -1,38 +1,84 @@
|
||||
import { qrcode } from '@/services/orders/api';
|
||||
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 } from 'antd';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// const handleDelete = async (deletefile: FILES.File) => {
|
||||
// const hide = message.loading('正在删除');
|
||||
// try {
|
||||
// const result = await deleteFile(deletefile.id);
|
||||
// hide();
|
||||
// if (result.resp_code === 0) {
|
||||
// message.success('删除File成功');
|
||||
// return true;
|
||||
// } else {
|
||||
// message.error(result.resp_msg);
|
||||
// return false;
|
||||
// }
|
||||
// } catch (error) {
|
||||
// hide();
|
||||
// message.error('删除File失败');
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
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',
|
||||
@@ -51,12 +97,13 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'tourismId',
|
||||
},
|
||||
{
|
||||
title: '文件路径',
|
||||
dataIndex: 'path',
|
||||
title: '文件',
|
||||
dataIndex: 'viewUrl',
|
||||
render: (viewUrl) => <Image src={viewUrl} width={100} />
|
||||
},
|
||||
{
|
||||
title: '文件ID',
|
||||
dataIndex: 'fileId',
|
||||
title: '价格',
|
||||
dataIndex: 'price',
|
||||
},
|
||||
{
|
||||
title: '设备SN',
|
||||
@@ -74,19 +121,30 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) => <Popconfirm
|
||||
title={`确认删除文件[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
// const success = await handleDelete(entity);
|
||||
// if (success) {
|
||||
// if (actionRef.current) {
|
||||
// actionRef.current.reload();
|
||||
// }
|
||||
// }
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>,
|
||||
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>
|
||||
},
|
||||
];
|
||||
|
||||
@@ -101,7 +159,7 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
headerTitle="二维码列表"
|
||||
request={qrcode}
|
||||
@@ -113,6 +171,102 @@ const TableList: React.FC = () => {
|
||||
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>
|
||||
);
|
||||
|
||||
@@ -60,4 +60,20 @@ export async function qrcode(params?: { [key: string]: string | number }) {
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function deleteQrcode(id: number) {
|
||||
const url = `/api-order/qrcode/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function saveOrUpdateQrcode(data: ORDERS.Qrcode): Promise<API.Result<ORDERS.Qrcode>> {
|
||||
const result = await request<API.Result<ORDERS.Qrcode>>('/api-order/qrcode', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@@ -45,6 +45,7 @@ declare namespace ORDERS {
|
||||
tourismId: string;
|
||||
path: string;
|
||||
fileId: string;
|
||||
price: string;
|
||||
deviceSn: string;
|
||||
createTime?: string;
|
||||
status: number;
|
||||
|
||||
Reference in New Issue
Block a user