feat(后台管理):新增航线管理,优化平台管理个页面的新增修改等功能
This commit is contained in:
@@ -43,6 +43,11 @@
|
||||
target: 'http://119.45.169.13:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-device/': {
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
test: {
|
||||
'/api/': {
|
||||
|
||||
@@ -47,6 +47,15 @@
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/device',
|
||||
routes: [
|
||||
{
|
||||
path: '/device/wayline.html',
|
||||
component: './device/Wayline',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/orders',
|
||||
routes: [
|
||||
|
||||
@@ -49,4 +49,5 @@ export default {
|
||||
'menu.editor.flow': '流程编辑器',
|
||||
'menu.editor.mind': '脑图编辑器',
|
||||
'menu.editor.koni': '拓扑编辑器',
|
||||
'menu.首页': '首页',
|
||||
};
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { UploadOutlined } from '@ant-design/icons';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Form, message, Upload } from 'antd';
|
||||
import { RcFile } from 'antd/lib/upload';
|
||||
import { useState } from 'react';
|
||||
import styles from '../index.less';
|
||||
import { TOURISM_OPTIONS, TYPE_OPTIONS, WORKSPACE_OPTIONS } from '../index';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.TourismFile>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onSubmit: (values: Partial<DEVICE.Wayline>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: DEVICE.Wayline;
|
||||
onUpload: (fileInfo: FileResponse) => void;
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在导入');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
message.success('上传素材成功');
|
||||
return result;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传素材失败');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props;
|
||||
const [hasNewFile, setHasNewFile] = useState(false);
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改航线"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
onVisibleChange(visible);
|
||||
if (!visible) {
|
||||
setHasNewFile(false);
|
||||
}
|
||||
}}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (formValues) => {
|
||||
// 只提交已修改的字段
|
||||
const changedValues: Partial<DEVICE.Wayline> = {};
|
||||
Object.keys(formValues).forEach(key => {
|
||||
if (formValues[key] !== values?.[key]) {
|
||||
changedValues[key] = formValues[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(changedValues).length === 0 && !hasNewFile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
await onSubmit(changedValues);
|
||||
}}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="name"
|
||||
label="航线名称"
|
||||
placeholder="请输入航线名称"
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
placeholder="请选择工作区"
|
||||
options={WORKSPACE_OPTIONS}
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
/>
|
||||
|
||||
<div style={{ width: '328px' }}>
|
||||
<div style={{ marginBottom: 8 }}>航线文件:</div>
|
||||
{values?.fileUrl && !hasNewFile && (
|
||||
<div style={{ marginBottom: 8 }}>
|
||||
当前文件:{values.name}
|
||||
</div>
|
||||
)}
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result) {
|
||||
onUpload(result);
|
||||
setHasNewFile(true);
|
||||
message.success('文件上传成功');
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
{hasNewFile ? '重新上传' : '上传文件'}
|
||||
</Button>
|
||||
</Upload>
|
||||
{hasNewFile && <div style={{ marginTop: 8, color: '#52c41a' }}>已上传新文件</div>}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -0,0 +1 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -0,0 +1,385 @@
|
||||
import { deleteWayline, saveOrUpdateWayline, wayline } from '@/services/device/api';
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { PlusOutlined, UploadOutlined } 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, Tag, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 状态映射
|
||||
const statusColorMap = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
};
|
||||
|
||||
// 提取常量
|
||||
export const WORKSPACE_OPTIONS = [
|
||||
{ label: '工作区1', value: 1 },
|
||||
{ label: '工作区2', value: 2 },
|
||||
// ... 根据实际需求添加更多选项
|
||||
] as const;
|
||||
|
||||
// 统一错误处理
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理函数优化
|
||||
const handleAdd = async (fields: DEVICE.Wayline) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateWayline({ ...fields }),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: DEVICE.Wayline, fields: Partial<DEVICE.Wayline>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateWayline({
|
||||
id: original.id,
|
||||
...fields
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = async (tourismFile: DEVICE.Wayline) => {
|
||||
return handleApiRequest(
|
||||
() => deleteWayline(tourismFile.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
return handleApiRequest(
|
||||
async () => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return await importImage(formData);
|
||||
},
|
||||
'正在上传',
|
||||
'上传素材成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染函数
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const renderType = (type: {} | null | undefined) => {
|
||||
const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={typeInfo.color}>{typeInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
interface FileResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
// ... 其他字段
|
||||
}
|
||||
|
||||
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<DEVICE.Wayline>();
|
||||
const [fileInfo, setFileInfo] = useState<FileResponse>();
|
||||
const formRef = useRef();
|
||||
|
||||
const handleFileUpload = async (file: RcFile) => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
if (result) {
|
||||
setFileInfo(result);
|
||||
formRef.current?.setFieldsValue({
|
||||
waylineId: result.id,
|
||||
name: result.name
|
||||
});
|
||||
message.success('文件上传成功');
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('文件上传失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: DEVICE.Wayline,
|
||||
values?: Partial<DEVICE.Wayline>
|
||||
) => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
if (!fileInfo) {
|
||||
message.error('请上传航线文件');
|
||||
return;
|
||||
}
|
||||
success = await handleAdd({
|
||||
...values,
|
||||
fileUrl: fileInfo.url,
|
||||
waylineId: fileInfo.id,
|
||||
name: values.name || fileInfo.name
|
||||
} as DEVICE.Wayline);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
const updateData = {
|
||||
...values,
|
||||
...(fileInfo ? {
|
||||
fileUrl: fileInfo.url,
|
||||
waylineId: fileInfo.id
|
||||
} : {})
|
||||
};
|
||||
success = await handleEdit(record, updateData);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, [fileInfo]);
|
||||
|
||||
const columns: ProColumns<DEVICE.Wayline>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: '航线名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '航线id',
|
||||
dataIndex: 'waylineId',
|
||||
},
|
||||
{
|
||||
title: '地区ID',
|
||||
dataIndex: 'workspaceId',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '航线文件',
|
||||
dataIndex: 'fileUrl',
|
||||
render: (fileUrl, record) => fileUrl ? (
|
||||
<a
|
||||
href={fileUrl}
|
||||
download={record.name}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
const link = document.createElement('a');
|
||||
link.href = fileUrl;
|
||||
link.download = record.name || 'wayline.kmz';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}}
|
||||
>
|
||||
下载文件
|
||||
</a>
|
||||
) : '-'
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除素材[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleTableAction('delete', 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<DEVICE.Wayline>
|
||||
rowKey="id"
|
||||
headerTitle="航线列表"
|
||||
request={wayline}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
type="primary"
|
||||
key="add"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加航线"
|
||||
visible={createModalVisible}
|
||||
formRef={formRef}
|
||||
onVisibleChange={(visible) => {
|
||||
handleModalVisible(visible);
|
||||
if (!visible) {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
onCancel: () => {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
onFinish={async (values) => {
|
||||
if (!fileInfo) {
|
||||
message.error('请上传航线文件');
|
||||
return false;
|
||||
}
|
||||
return handleTableAction('add', undefined, values);
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '航线名称不能为空' }]}
|
||||
width="md"
|
||||
name="name"
|
||||
label="航线名称"
|
||||
placeholder="请输入航线名称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '工作区不能为空' }]}
|
||||
width="md"
|
||||
name="workspaceId"
|
||||
label="工作区"
|
||||
placeholder="请选择工作区"
|
||||
options={WORKSPACE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
hidden
|
||||
name="waylineId"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<div style={{ width: '328px', marginBottom: 24 }}>
|
||||
<div style={{ marginBottom: 8 }}>航线文件:</div>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
accept=".kmz,.kml"
|
||||
showUploadList={false}
|
||||
beforeUpload={handleFileUpload}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
{fileInfo ? '重新上传' : '上传文件'}
|
||||
</Button>
|
||||
</Upload>
|
||||
{fileInfo && (
|
||||
<div style={{ marginTop: 8, color: '#52c41a' }}>
|
||||
已上传:{fileInfo.name}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={(values) => handleTableAction('edit', currentRow, values)}
|
||||
onVisibleChange={(visible) => {
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
setFileInfo(undefined);
|
||||
}
|
||||
}}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
onUpload={setFileInfo}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
+69
@@ -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,293 @@
|
||||
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, Tag } 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 statusColorMap = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
|
||||
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
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',
|
||||
render: (status) => renderStatus(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: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<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' },
|
||||
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
|
||||
{ label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
</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;
|
||||
+87
-38
@@ -1,66 +1,115 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.HomeCarousel>;
|
||||
import { Button, Upload } from 'antd';
|
||||
import { UploadOutlined } from '@ant-design/icons';
|
||||
import React from 'react';
|
||||
import { TYPE_OPTIONS } from '../index';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import styles from '../index.less';
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
onSubmit: (values: Partial<ORDERS.HomeCarousel>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.HomeCarousel;
|
||||
onUpload: (fileUrl: string) => void;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values, onUpload } = props;
|
||||
|
||||
// 导入处理函数
|
||||
const handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
if (result && result.name) {
|
||||
message.success('上传素材成功');
|
||||
onUpload(result.name);
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传素材失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="更新轮播"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
title="修改素材"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (formValues) => {
|
||||
// 只提交已修改的字段
|
||||
const changedValues: Partial<ORDERS.HomeCarousel> = {};
|
||||
Object.keys(formValues).forEach(key => {
|
||||
if (formValues[key] !== values?.[key]) {
|
||||
changedValues[key] = formValues[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(changedValues).length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
await onSubmit(changedValues);
|
||||
}}
|
||||
initialValues={values}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '名称不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="输入标题"
|
||||
placeholder="请输入标题"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '素材地址不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="imageUrl"
|
||||
label="素材地址"
|
||||
placeholder="输入地址"
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '链接页面不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="redirectUrl"
|
||||
label="链接地址"
|
||||
placeholder="输入链接"
|
||||
label="链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="type"
|
||||
label="类型"
|
||||
placeholder="请选择类型"
|
||||
options={TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述"
|
||||
/>
|
||||
|
||||
{/* 添加图片上传组件 */}
|
||||
<div style={{ marginBottom: 24 }}>
|
||||
<div style={{ marginBottom: 8 }}>当前图片:</div>
|
||||
<Image src={values?.imageUrl} width={100} style={{ marginBottom: 16 }} />
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={handleImport}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
更新素材
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {deleteHomeCarousel, saveOrUpdateHomeCarousel, homeCarousel } from '@/services/orders/api';
|
||||
import { deleteHomeCarousel, saveOrUpdateHomeCarousel, homeCarousel } from '@/services/orders/api';
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
@@ -11,86 +11,21 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import Upload, { RcFile } from 'antd/lib/upload';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: ORDERS.HomeCarousel) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await saveOrUpdateHomeCarousel({ ...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;
|
||||
}
|
||||
};
|
||||
// 提取常量
|
||||
export const TYPE_OPTIONS = [
|
||||
{ label: '首页轮播', value: 0 },
|
||||
{ label: '活动', value: 1 },
|
||||
{ label: '其他', value: 2 },
|
||||
] as const;
|
||||
|
||||
const handleEdit = async (fields: ORDERS.HomeCarousel) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateHomeCarousel({ ...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.HomeCarousel) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteHomeCarousel(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 handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在导入');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
message.success('上传素材成功');
|
||||
return result;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传素材失败');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// 类型颜色映射
|
||||
const typeColorMap = {
|
||||
0: { color: 'yellow', text: '首页轮播' },
|
||||
@@ -98,21 +33,118 @@ const typeColorMap = {
|
||||
2: { color: 'red', text: '其他' },
|
||||
};
|
||||
|
||||
// 类型渲染标签
|
||||
// 统一错误处理
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理函数优化
|
||||
const handleAdd = async (fields: ORDERS.HomeCarousel) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateHomeCarousel({ ...fields }),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: ORDERS.HomeCarousel, fields: Partial<ORDERS.HomeCarousel>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateHomeCarousel({
|
||||
id: original.id,
|
||||
...fields
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = async (carousel: ORDERS.HomeCarousel) => {
|
||||
return handleApiRequest(
|
||||
() => deleteHomeCarousel(carousel.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
return handleApiRequest(
|
||||
async () => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return await importImage(formData);
|
||||
},
|
||||
'正在上传',
|
||||
'上传素材成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染函数
|
||||
const renderType = (type: {} | null | undefined) => {
|
||||
const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={typeInfo.color}>{typeInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
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.HomeCarousel>();
|
||||
const [file, setFile] = useState();
|
||||
// const setImage = (imageUrl: string) => {
|
||||
// setFile({ ...file, imageUrl});
|
||||
// }
|
||||
const [file, setFile] = useState<string>();
|
||||
const [updateFile, setUpdateFile] = useState<string>();
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.HomeCarousel,
|
||||
values?: Partial<ORDERS.HomeCarousel>
|
||||
) => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
success = await handleAdd({ ...values, imageUrl: file } as ORDERS.HomeCarousel);
|
||||
success && handleModalVisible(false);
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
const updateData = {
|
||||
...values,
|
||||
...(updateFile ? { imageUrl: updateFile } : {})
|
||||
};
|
||||
success = await handleEdit(record, updateData);
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
setUpdateFile(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, [file, updateFile]);
|
||||
|
||||
const columns: ProColumns<ORDERS.HomeCarousel>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -134,7 +166,7 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
render: (type) => renderType(type),
|
||||
render: renderType,
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
@@ -152,30 +184,24 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除素材[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
render: (_, entity) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除素材[${entity.id}]?`}
|
||||
onConfirm={() => handleTableAction('delete', entity)}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -190,7 +216,7 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.HomeCarousel>
|
||||
<ProTable<ORDERS.HomeCarousel>
|
||||
rowKey="id"
|
||||
headerTitle="素材列表"
|
||||
request={homeCarousel}
|
||||
@@ -203,112 +229,84 @@ const TableList: React.FC = () => {
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
<Button
|
||||
type="primary"
|
||||
key="add"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加素材"
|
||||
// layout="horizontal"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
|
||||
values.imageUrl = file
|
||||
const success = await handleAdd(values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
onFinish={(values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[{ required: true, message: '标题不为空' }]}
|
||||
width="md"
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入标题"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="redirectUrl"
|
||||
label="链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="type"
|
||||
label="类型"
|
||||
placeholder="请选择类型"
|
||||
options={TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述"
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={(values) => handleTableAction('edit', currentRow, values)}
|
||||
onVisibleChange={(visible) => {
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
setUpdateFile(undefined);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '标题不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入标题"
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
onUpload={setUpdateFile}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="redirectUrl"
|
||||
label="链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="type"
|
||||
label="类型"
|
||||
placeholder="请选择类型"
|
||||
options={[
|
||||
{ label: '首页轮播', value: 0 },
|
||||
{ label: '活动', value: 1 },
|
||||
{ label: '其他', value: 2 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述 "
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
import { STATUS_OPTIONS } from '../constants';
|
||||
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: { orderStatus: number }) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Order;
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
onSubmit,
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
}) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改订单状态"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
}}
|
||||
initialValues={values}
|
||||
onFinish={async (formValues) => {
|
||||
await onSubmit(formValues);
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择订单状态' }]}
|
||||
width="md"
|
||||
name="orderStatus"
|
||||
label="订单状态"
|
||||
placeholder="请选择订单状态"
|
||||
options={STATUS_OPTIONS}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
@@ -0,0 +1,31 @@
|
||||
// 抽离常量配置
|
||||
export const ORDER_STATUS = {
|
||||
UNPAID: 0,
|
||||
PAID_QUEUING: 1,
|
||||
CANCELLED: 2,
|
||||
COMPLETED: 3,
|
||||
SERVING: 4,
|
||||
UPLOADING: 5,
|
||||
UPLOAD_COMPLETED: 6,
|
||||
REFUNDING: 7,
|
||||
REFUNDED: 8,
|
||||
REFUND_FAILED: 9,
|
||||
} as const;
|
||||
|
||||
export const STATUS_CONFIG = {
|
||||
[ORDER_STATUS.UNPAID]: { color: 'yellow', text: '待支付' },
|
||||
[ORDER_STATUS.PAID_QUEUING]: { color: 'orange', text: '已支付排队中' },
|
||||
[ORDER_STATUS.CANCELLED]: { color: 'gray', text: '已取消' },
|
||||
[ORDER_STATUS.COMPLETED]: { color: 'red', text: '设备执行完成' },
|
||||
[ORDER_STATUS.SERVING]: { color: 'lightblue', text: '正在服务中' },
|
||||
[ORDER_STATUS.UPLOADING]: { color: 'pink', text: '素材上传中' },
|
||||
[ORDER_STATUS.UPLOAD_COMPLETED]: { color: 'green', text: '素材上传完成' },
|
||||
[ORDER_STATUS.REFUNDING]: { color: 'darkgray', text: '退款中' },
|
||||
[ORDER_STATUS.REFUNDED]: { color: 'cyan', text: '已退款' },
|
||||
[ORDER_STATUS.REFUND_FAILED]: { color: 'purple', text: '退款失败' },
|
||||
} as const;
|
||||
|
||||
export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG).map(([value, config]) => ({
|
||||
label: config.text,
|
||||
value: Number(value),
|
||||
}));
|
||||
@@ -1,113 +1,153 @@
|
||||
import { order } from '@/services/orders/api';
|
||||
import { order, updateOrder } from '@/services/orders/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm, Tag } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Typography, Space, Tag, message } from 'antd';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import { STATUS_CONFIG, STATUS_OPTIONS } from './constants';
|
||||
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 statusColorMap = {
|
||||
0: { color: 'yellow', text: '待支付' },
|
||||
1: { color: 'orange', text: '已支付排队中' },
|
||||
2: { color: 'gray', text: '已取消' },
|
||||
3: { color: 'red', text: '设备执行完成' },
|
||||
4: { color: 'lightblue', text: '正在服务中' },
|
||||
5: { color: 'pink', text: '素材上传中' },
|
||||
6: { color: 'green', text: '素材上传完成' },
|
||||
7: { color: 'darkgray', text: '退款中' },
|
||||
8: { color: 'cyan', text: '已退款' },
|
||||
9: { color: 'purple', text: '退款失败' }
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Order>();
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = useCallback((status: number) => {
|
||||
const statusInfo = STATUS_CONFIG[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
}, []);
|
||||
|
||||
// 处理修改操作
|
||||
const handleEdit = useCallback(async (fields: { orderStatus: number }) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
if (!currentRow) return false;
|
||||
|
||||
const result = await updateOrder({
|
||||
id: currentRow.id,
|
||||
orderStatus: fields.orderStatus,
|
||||
});
|
||||
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('修改失败,请重试');
|
||||
return false;
|
||||
}
|
||||
}, [currentRow]);
|
||||
|
||||
const columns: ProColumns<ORDERS.Order>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: '订单ID',
|
||||
dataIndex: 'id',
|
||||
copyable: true,
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '订单编号',
|
||||
dataIndex: 'orderNo',
|
||||
copyable: true,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '二维码ID',
|
||||
dataIndex: 'codeId',
|
||||
copyable: true,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '设备编号',
|
||||
dataIndex: 'deviceSn',
|
||||
copyable: true,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'orderStatus',
|
||||
render: (status) => renderStatus(status),
|
||||
render: (status) => renderStatus(status as number),
|
||||
width: 120,
|
||||
filters: STATUS_OPTIONS,
|
||||
filterMultiple: false,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '支付时间',
|
||||
dataIndex: 'payTime',
|
||||
valueType: 'dateTime',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
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>,
|
||||
width: 80,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改状态
|
||||
</Link>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<PageContainer header={{ title: '订单管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
span={8}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
<ProFormText
|
||||
name="orderNo"
|
||||
label="订单编号"
|
||||
placeholder="请输入订单编号"
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="orderStatus"
|
||||
label="订单状态"
|
||||
placeholder="请选择订单状态"
|
||||
options={STATUS_OPTIONS}
|
||||
allowClear
|
||||
/>
|
||||
</QueryFilter>
|
||||
|
||||
<ProTable<ORDERS.Order>
|
||||
rowKey="id"
|
||||
headerTitle="任务列表"
|
||||
headerTitle="订单列表"
|
||||
request={order}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
@@ -116,7 +156,27 @@ const TableList: React.FC = () => {
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
defaultPageSize: 10,
|
||||
pageSizeOptions: ['10', '20', '50'],
|
||||
}}
|
||||
dateFormatter="string"
|
||||
toolbar={{
|
||||
actions: [],
|
||||
}}
|
||||
/>
|
||||
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
const success = await handleEdit(values);
|
||||
if (success) {
|
||||
setUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}
|
||||
}}
|
||||
onVisibleChange={setUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
+100
-40
@@ -1,65 +1,125 @@
|
||||
import { wayline } from '@/services/device/api';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.Tourism>;
|
||||
import { message } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { TOURISM_OPTIONS, DEVICE_OPTIONS, STATUS_OPTIONS } from '../index';
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
onSubmit: (values: Partial<ORDERS.Qrcode>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Tourism;
|
||||
values?: ORDERS.Qrcode;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values } = props;
|
||||
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
|
||||
|
||||
// 获取航线列表
|
||||
const fetchWaylineOptions = async () => {
|
||||
try {
|
||||
const result = await wayline({
|
||||
current: 1,
|
||||
pageSize: 100,
|
||||
});
|
||||
if (result?.data) {
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: item.name,
|
||||
value: item.waylineId,
|
||||
wayline: item,
|
||||
}));
|
||||
setWaylineOptions(options);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取航线列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 在弹窗显示时获取航线列表
|
||||
useEffect(() => {
|
||||
if (updateModalVisible) {
|
||||
fetchWaylineOptions();
|
||||
}
|
||||
}, [updateModalVisible]);
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改二维码"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
initialValues={{
|
||||
...values,
|
||||
waylineId: values?.waylineId,
|
||||
status: values?.status, // 确保状态值被正确初始化
|
||||
}}
|
||||
onFinish={async (formValues) => {
|
||||
const changedValues: Partial<ORDERS.Qrcode> = {};
|
||||
Object.keys(formValues).forEach(key => {
|
||||
if (formValues[key] !== values?.[key]) {
|
||||
changedValues[key] = formValues[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(changedValues).length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
await onSubmit(changedValues);
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '名称不为空',
|
||||
},
|
||||
]}
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismName"
|
||||
label="名称"
|
||||
placeholder="输入名称"
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
placeholder="请选择航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
fieldProps={{
|
||||
loading: waylineOptions.length === 0,
|
||||
showSearch: true,
|
||||
onChange: (value, option: any) => {
|
||||
// 可以在这里处理航线选择后的联动逻辑
|
||||
console.log('选择的航线:', option);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={TOURISM_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择景区' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '地址不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismAddress"
|
||||
label="地址"
|
||||
placeholder="输入地址"
|
||||
name="price"
|
||||
label="景点打卡价格"
|
||||
placeholder="输入价格(单位:分)"
|
||||
rules={[{ required: true, message: '请输入价格' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '手机号不为空',
|
||||
},
|
||||
]}
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismPhone"
|
||||
label="手机号"
|
||||
placeholder="输入手机号"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
placeholder="请选择设备编号"
|
||||
options={DEVICE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择设备编号' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
@@ -11,66 +11,77 @@ import {
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import { wayline } from '@/services/device/api';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: ORDERS.Qrcode) => {
|
||||
const hide = message.loading('正在添加');
|
||||
export const STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 0 },
|
||||
{ label: '未启用', value: 1 },
|
||||
] as const;
|
||||
|
||||
export const TOURISM_OPTIONS = [
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
] as const;
|
||||
|
||||
export const DEVICE_OPTIONS = [
|
||||
{ label: '7CTDM6F00B744S', value: '7CTDM6F00B744S' },
|
||||
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
|
||||
{ label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' },
|
||||
] as const;
|
||||
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await saveOrUpdateQrcode({ ...fields });
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加成功');
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('添加失败');
|
||||
message.error(`${successMessage}失败`);
|
||||
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 handleAdd = async (fields: ORDERS.Qrcode) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({ ...fields }),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: ORDERS.Qrcode, fields: Partial<ORDERS.Qrcode>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
id: original.id, // 保留原始ID
|
||||
...fields // 只包含修改的字段
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
return handleApiRequest(
|
||||
() => deleteQrcode(qrcode.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 状态颜色映射
|
||||
@@ -93,6 +104,67 @@ const TableList: React.FC = () => {
|
||||
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
|
||||
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
|
||||
const formRef = useRef();
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.Qrcode,
|
||||
values?: Partial<ORDERS.Qrcode>
|
||||
) => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
success = await handleAdd(values as ORDERS.Qrcode);
|
||||
success && handleModalVisible(false);
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
success = await handleEdit(record, values || {});
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, []);
|
||||
|
||||
const fetchWaylineOptions = async () => {
|
||||
console.log('Fetching wayline options...');
|
||||
try {
|
||||
const result = await wayline({ current: 1, pageSize: 100 });
|
||||
console.log('Wayline result:', result);
|
||||
if (result?.data) {
|
||||
const options = result.data.map((item: any) => ({
|
||||
label: `${item.name}`,
|
||||
value: item.waylineId,
|
||||
wayline: item
|
||||
}));
|
||||
setWaylineOptions(options);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取航线列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
console.log('Modal visible changed:', updateModalVisible);
|
||||
if (updateModalVisible) {
|
||||
fetchWaylineOptions();
|
||||
}
|
||||
}, [updateModalVisible]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('Current wayline options:', waylineOptions);
|
||||
}, [waylineOptions]);
|
||||
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -140,7 +212,10 @@ const TableList: React.FC = () => {
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
setCurrentRow({
|
||||
...entity,
|
||||
waylineId: entity.waylineId,
|
||||
});
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
@@ -149,12 +224,7 @@ const TableList: React.FC = () => {
|
||||
<Popconfirm
|
||||
title={`确认删除景区[${entity.codeId}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
const success = await handleTableAction('delete', entity);
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
@@ -201,88 +271,66 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
<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();
|
||||
}
|
||||
}
|
||||
}}
|
||||
onFinish={async (values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '景区不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<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' },
|
||||
{ label: '8UUXN2A00A00LR', value: '8UUXN2A00A00LR' },
|
||||
{ label: '5YSZMBS0030BJ8', value: '5YSZMBS0030BJ8' },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
placeholder="请选择航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={TOURISM_OPTIONS}
|
||||
rules={[{ required: true, message: '景区不为空' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="price"
|
||||
label="景点打卡价格"
|
||||
placeholder="输入价格(单位:分)"
|
||||
rules={[{ required: true, message: '价格不为空' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
placeholder="请选择设备编号"
|
||||
options={DEVICE_OPTIONS}
|
||||
rules={[{ required: true, message: '设备不为空' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
initialValue={0}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</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();
|
||||
}
|
||||
}
|
||||
console.log('提交的修改值:', values);
|
||||
return handleTableAction('edit', currentRow, values);
|
||||
}}
|
||||
onVisibleChange={(visible) => {
|
||||
console.log('修改弹窗可见性变化:', visible);
|
||||
handleUpdateModalVisible(visible);
|
||||
if (!visible) {
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// 将常量配置提取到单独文件
|
||||
export const STATUS_CONFIG = {
|
||||
7: { color: 'yellow', text: '退款申请中' },
|
||||
8: { color: 'green', text: '已退款' },
|
||||
9: { color: 'red', text: '退款失败' },
|
||||
} as const;
|
||||
|
||||
export const STATE_CONFIG = {
|
||||
0: { color: 'yellow', text: '待审核' },
|
||||
1: { color: 'green', text: '已通过' },
|
||||
2: { color: 'red', text: '已拒绝' },
|
||||
} as const;
|
||||
@@ -7,64 +7,59 @@ import {
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Tag, Space, message } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
import { STATUS_CONFIG, STATE_CONFIG } from './constants';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import type { RefundItem } from './types';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleEdit = async (fields: ORDERS.Refund) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await updateRefund({ ...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 statusColorMap = {
|
||||
7: { color: 'yellow', text: '退款申请中' },
|
||||
8: { color: 'green', text: '已退款' },
|
||||
9: { color: 'red', text: '退款失败' },
|
||||
|
||||
};
|
||||
|
||||
// 状态颜色映射
|
||||
const stateColorMap = {
|
||||
0: { color: 'yellow', text: '待审核' },
|
||||
1: { color: 'green', text: '已通过' },
|
||||
2: { color: 'red', text: '已拒绝' },
|
||||
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderState = (state: {} | null | undefined) => {
|
||||
const stateInfo = stateColorMap[state] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={stateInfo.color}>{stateInfo.text}</Tag>;
|
||||
// 将渲染标签的函数移到组件外部
|
||||
const renderTag = (value: number, config: typeof STATUS_CONFIG | typeof STATE_CONFIG) => {
|
||||
const info = config[value] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={info.color}>{info.text}</Tag>;
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
// 1. 所有 hooks 放在组件最顶部
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.Refund>();
|
||||
const columns: ProColumns<ORDERS.Refund>[] = [
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
||||
|
||||
// 2. 处理编辑的回调函数
|
||||
const handleEdit = useCallback(async (fields: RefundItem) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await updateRefund({ ...fields });
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('审核成功');
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('审核失败');
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 3. 处理表单提交的回调函数
|
||||
const handleSubmit = useCallback(async (values: Partial<RefundItem>) => {
|
||||
if (!currentRow) return;
|
||||
|
||||
const success = await handleEdit({ ...currentRow, ...values });
|
||||
if (success) {
|
||||
setUpdateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}, [currentRow, handleEdit]);
|
||||
|
||||
// 4. 定义表格列
|
||||
const columns: ProColumns<RefundItem>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
@@ -80,20 +75,22 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '订单金额',
|
||||
dataIndex: 'orderAmount',
|
||||
valueType: 'money',
|
||||
},
|
||||
{
|
||||
title: '退款金额',
|
||||
dataIndex: 'refundAmount',
|
||||
valueType: 'money',
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
dataIndex: 'status',
|
||||
render: (status) => renderStatus(status),
|
||||
render: (status) => renderTag(status as number, STATUS_CONFIG),
|
||||
},
|
||||
{
|
||||
title: '退款状态',
|
||||
dataIndex: 'state',
|
||||
render: (state) => renderState(state),
|
||||
render: (state) => renderTag(state as number, STATE_CONFIG),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
@@ -103,22 +100,23 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
render: (_, entity) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(entity);
|
||||
handleUpdateModalVisible(true);
|
||||
setUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<PageContainer header={{ subTitle: '退款管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
@@ -128,9 +126,10 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Refund>
|
||||
|
||||
<ProTable<RefundItem>
|
||||
rowKey="id"
|
||||
headerTitle="任务列表"
|
||||
headerTitle="退款列表"
|
||||
request={refund}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
@@ -141,24 +140,13 @@ const TableList: React.FC = () => {
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
|
||||
<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}
|
||||
/>
|
||||
onSubmit={handleSubmit}
|
||||
onVisibleChange={setUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface RefundItem {
|
||||
id: string;
|
||||
refundNo: string;
|
||||
orderAmount: number;
|
||||
refundAmount: number;
|
||||
status: number;
|
||||
state: number;
|
||||
createTime: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
+24
-28
@@ -3,59 +3,55 @@ import {
|
||||
ProForm,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Form } from 'antd';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.Tourism>;
|
||||
import React from 'react';
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
onSubmit: (values: Partial<ORDERS.Tourism>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Tourism;
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
const { onSubmit, onVisibleChange, updateModalVisible, values } = props;
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改景区"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (formValues) => {
|
||||
// 只提交已修改的字段
|
||||
const changedValues: Partial<ORDERS.Tourism> = {};
|
||||
Object.keys(formValues).forEach(key => {
|
||||
if (formValues[key] !== values?.[key]) {
|
||||
changedValues[key] = formValues[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(changedValues).length === 0) {
|
||||
return true; // 如果没有修改任何字段,直接关闭
|
||||
}
|
||||
|
||||
await onSubmit(changedValues);
|
||||
}}
|
||||
initialValues={values}
|
||||
>
|
||||
<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="手机号"
|
||||
|
||||
@@ -11,72 +11,97 @@ import {
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm, Button, Space } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import React, { useRef, useState, useCallback } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在添加');
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await saveOrUpdateTourism({ ...fields });
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加用户成功');
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
} else {
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('添加用户失败');
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = async (fields: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateTourism({ ...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 handleAdd = async (fields: ORDERS.Tourism) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateTourism({ ...fields }),
|
||||
'正在添加',
|
||||
'添加景区成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: ORDERS.Tourism, fields: Partial<ORDERS.Tourism>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateTourism({
|
||||
id: original.id, // 保留原始ID
|
||||
...fields // 只包含修改的字段
|
||||
}),
|
||||
'正在更新',
|
||||
'修改景区成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = async (tourism: ORDERS.Tourism) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteTourism(tourism.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;
|
||||
}
|
||||
return handleApiRequest(
|
||||
() => deleteTourism(tourism.id),
|
||||
'正在删除',
|
||||
'删除景区成功'
|
||||
);
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||
// 1. 先定义所有的 hooks
|
||||
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.Tourism>();
|
||||
|
||||
// 2. 然后定义 handleTableAction
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.Tourism,
|
||||
values?: Partial<ORDERS.Tourism>
|
||||
) => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
success = await handleAdd(values as ORDERS.Tourism);
|
||||
success && handleModalVisible(false);
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
success = await handleEdit(record, values || {});
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, []); // 添加依赖数组
|
||||
|
||||
const columns: ProColumns<ORDERS.Tourism>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
@@ -126,18 +151,11 @@ const TableList: React.FC = () => {
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除景区[${entity.tourismName}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
onConfirm={() => handleTableAction('delete', entity)}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</Space>
|
||||
},
|
||||
];
|
||||
|
||||
@@ -179,20 +197,10 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
<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();
|
||||
}
|
||||
}
|
||||
}}
|
||||
onFinish={(values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
@@ -234,19 +242,7 @@ const TableList: React.FC = () => {
|
||||
</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);
|
||||
}
|
||||
}}
|
||||
onSubmit={(values) => handleTableAction('edit', currentRow, values)}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
|
||||
+109
-100
@@ -6,115 +6,124 @@ import {
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, Form, message, Upload } from 'antd';
|
||||
import { RcFile } from 'antd/lib/upload';
|
||||
import { useState } from 'react';
|
||||
import { Button, Upload, Image, message } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useState } from 'react';
|
||||
import { TOURISM_OPTIONS, TYPE_OPTIONS } from '../constants';
|
||||
import styles from '../index.less';
|
||||
|
||||
export type FormValueType = Partial<ORDERS.TourismFile>;
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onVisibleChange: (flag: boolean) => void;
|
||||
onSubmit: (values: FormValueType) => Promise<void>;
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: Partial<ORDERS.TourismFile>) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.Tourism;
|
||||
};
|
||||
values?: ORDERS.TourismFile;
|
||||
tourismOptions: { label: string; value: number; }[];
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
onSubmit,
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
tourismOptions,
|
||||
}) => {
|
||||
const [imageUrl, setImageUrl] = useState<string>(values?.imageUrl || '');
|
||||
|
||||
const handleUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
if (result.name) {
|
||||
setImageUrl(result.name);
|
||||
message.success('上传成功');
|
||||
}
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传失败');
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在导入');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
message.success('上传素材成功');
|
||||
return result;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传素材失败');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const [form] = Form.useForm();
|
||||
const [file, setFile] = useState();
|
||||
return (
|
||||
<ModalForm
|
||||
title="更新素材"
|
||||
form={form}
|
||||
visible={props.updateModalVisible}
|
||||
onFinish={props.onSubmit}
|
||||
onVisibleChange={props.onVisibleChange}
|
||||
title="修改素材"
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
initialValues={values}
|
||||
onFinish={async (formValues) => {
|
||||
const submitData = {
|
||||
...formValues,
|
||||
imageUrl: imageUrl || values?.imageUrl,
|
||||
};
|
||||
await onSubmit(submitData);
|
||||
}}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '景区不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖', value: 35 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '素材类型不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="type"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '展示大图', value: 4 },
|
||||
{ label: '拍照引导图', value: 3 },
|
||||
{ label: '拍照角度展示图', value: 2 },
|
||||
{ label: '活动', value: 1 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
label="素材链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述 "
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '景区不能为空' }]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '素材类型不能为空' }]}
|
||||
width="md"
|
||||
name="type"
|
||||
label="素材类型"
|
||||
placeholder="请选择素材类型"
|
||||
options={TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
label="素材链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
options={[
|
||||
{ label: '启用', value: 0 },
|
||||
{ label: '未启用', value: 1 },
|
||||
]}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
|
||||
<div className={styles.imageUpload}>
|
||||
{imageUrl || values?.imageUrl ? (
|
||||
<Image
|
||||
src={imageUrl || values?.imageUrl}
|
||||
width={200}
|
||||
className={styles.preview}
|
||||
/>
|
||||
) : null}
|
||||
<Upload
|
||||
maxCount={1}
|
||||
showUploadList={false}
|
||||
beforeUpload={handleUpload}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
更换素材
|
||||
</Button>
|
||||
</Upload>
|
||||
</div>
|
||||
</Upload>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1 +1,15 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
|
||||
.imageUpload {
|
||||
width: 100%;
|
||||
margin-top: 16px;
|
||||
|
||||
.preview {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.button_view {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {deleteTourismFile, saveOrUpdateTourismFile, tourismFile } from '@/services/orders/api';
|
||||
import { deleteTourismFile, saveOrUpdateTourismFile, tourismFile, tourism } from '@/services/orders/api';
|
||||
import { importImage } from '@/services/system/api';
|
||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
@@ -11,102 +11,28 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Typography, Popconfirm, Space, message, Image, Button, Tag, Upload } from 'antd';
|
||||
import type { RcFile } from 'antd/lib/upload';
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import Upload, { RcFile } from 'antd/lib/upload';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
const handleAdd = async (fields: ORDERS.TourismFile) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const result = await saveOrUpdateTourismFile({ ...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;
|
||||
}
|
||||
};
|
||||
// 提取常量
|
||||
export const TYPE_OPTIONS = [
|
||||
{ label: '展示大图', value: 4 },
|
||||
{ label: '拍照引导图', value: 3 },
|
||||
{ label: '拍照角度展示图', value: 2 },
|
||||
{ label: '活动', value: 1 },
|
||||
] as const;
|
||||
|
||||
const handleEdit = async (fields: ORDERS.TourismFile) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const result = await saveOrUpdateTourismFile({ ...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.TourismFile) => {
|
||||
const hide = message.loading('正在删除');
|
||||
try {
|
||||
const result = await deleteTourismFile(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 handleImport = async (file: RcFile) => {
|
||||
const hide = message.loading('正在导入');
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const result = await importImage(formData);
|
||||
hide();
|
||||
message.success('上传素材成功');
|
||||
return result;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传素材失败');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// 状态颜色映射
|
||||
// 状态映射
|
||||
const statusColorMap = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
|
||||
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
// 状态颜色映射
|
||||
const typeColorMap = {
|
||||
0: { color: 'yellow', text: '待审核' },
|
||||
1: { color: 'green', text: '活动' },
|
||||
@@ -115,31 +41,151 @@ const typeColorMap = {
|
||||
4: { color: 'green', text: '大图' },
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
// 统一错误处理
|
||||
const handleApiRequest = async (
|
||||
apiCall: () => Promise<any>,
|
||||
loadingMessage: string,
|
||||
successMessage: string,
|
||||
) => {
|
||||
const hide = message.loading(loadingMessage);
|
||||
try {
|
||||
const result = await apiCall();
|
||||
hide();
|
||||
if (result.resp_code === 0) {
|
||||
message.success(successMessage);
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg);
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error(`${successMessage}失败`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理函数优化
|
||||
const handleAdd = async (fields: ORDERS.TourismFile) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateTourismFile({ ...fields }),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleEdit = async (original: ORDERS.TourismFile, fields: Partial<ORDERS.TourismFile>) => {
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateTourismFile({
|
||||
id: original.id,
|
||||
...fields
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleDelete = async (tourismFile: ORDERS.TourismFile) => {
|
||||
return handleApiRequest(
|
||||
() => deleteTourismFile(tourismFile.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleImport = async (file: RcFile) => {
|
||||
return handleApiRequest(
|
||||
async () => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return await importImage(formData);
|
||||
},
|
||||
'正在上传',
|
||||
'上传素材成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染函数
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const renderType = (type: {} | null | undefined) => {
|
||||
const typeInfo = typeColorMap[type] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={typeInfo.color}>{typeInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
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.TourismFile>();
|
||||
const [file, setFile] = useState();
|
||||
// const setImage = (imageUrl: string) => {
|
||||
// setFile({ ...file, imageUrl});
|
||||
// }
|
||||
const [file, setFile] = useState<string>();
|
||||
const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; }[]>([]);
|
||||
|
||||
// 获取景区列表
|
||||
const fetchTourismList = useCallback(async () => {
|
||||
try {
|
||||
const result = await tourism({
|
||||
pageSize: 100,
|
||||
current: 1,
|
||||
});
|
||||
if (result.resp_code === 0 && result.data) {
|
||||
const options = result.data.records?.map(item => ({
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
})) || [];
|
||||
setTourismOptions(options);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取景区列表失败');
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 在组件挂载时获取景区列表
|
||||
useEffect(() => {
|
||||
fetchTourismList();
|
||||
}, [fetchTourismList]);
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.TourismFile,
|
||||
values?: Partial<ORDERS.TourismFile>
|
||||
) => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
success = await handleAdd({ ...values, imageUrl: file } as ORDERS.TourismFile);
|
||||
success && handleModalVisible(false);
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
success = await handleEdit(record, values || {});
|
||||
if (success) {
|
||||
handleUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
success = await handleDelete(record!);
|
||||
break;
|
||||
}
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, [file]);
|
||||
|
||||
const columns: ProColumns<ORDERS.TourismFile>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: '景区ID',
|
||||
title: '景区名称',
|
||||
dataIndex: 'tourismId',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '素材',
|
||||
@@ -185,7 +231,7 @@ const TableList: React.FC = () => {
|
||||
<Popconfirm
|
||||
title={`确认删除素材[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleDelete(entity);
|
||||
const success = await handleTableAction('delete', entity);
|
||||
if (success) {
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
@@ -200,7 +246,7 @@ const TableList: React.FC = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<PageContainer header={{ title: '景区素材管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
@@ -210,7 +256,7 @@ const TableList: React.FC = () => {
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.TourismFile>
|
||||
<ProTable<ORDERS.TourismFile>
|
||||
rowKey="id"
|
||||
headerTitle="素材列表"
|
||||
request={tourismFile}
|
||||
@@ -237,112 +283,72 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加素材"
|
||||
// layout="horizontal"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={handleModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => {
|
||||
|
||||
values.imageUrl = file
|
||||
const success = await handleAdd(values);
|
||||
if (success) {
|
||||
handleModalVisible(false);
|
||||
if (actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}
|
||||
}}
|
||||
onFinish={(values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '景区不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '北塘古镇', value: 33 },
|
||||
{ label: '海丝首港', value: 32 },
|
||||
{ label: '武汉东湖牡丹园', value: 35 },
|
||||
{ label: '武汉东湖樱花园', value: 36 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '景区不为空' }]}
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '素材类型不为空' }]}
|
||||
width="md"
|
||||
name="type"
|
||||
label="素材类型"
|
||||
placeholder="请选择素材类型"
|
||||
options={TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
label="素材链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述"
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
<UpdateForm
|
||||
onSubmit={(values) => handleTableAction('edit', currentRow, values)}
|
||||
onVisibleChange={handleUpdateModalVisible}
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
tourismOptions={tourismOptions}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '素材类型不为空',
|
||||
},
|
||||
]}
|
||||
width="md"
|
||||
name="type"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={[
|
||||
{ label: '展示大图', value: 4 },
|
||||
{ label: '拍照引导图', value: 3 },
|
||||
{ label: '拍照角度展示图', value: 2 },
|
||||
{ label: '活动', value: 1 },
|
||||
// 添加更多选项...
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
label="素材链接url"
|
||||
placeholder="输入url"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="description"
|
||||
label="素材描述"
|
||||
placeholder="输入描述 "
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
import { request } from 'umi';
|
||||
|
||||
|
||||
export async function wayline(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<DEVICE.Wayline>>('/api-device/wayline', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function saveOrUpdateWayline(data: ORDERS.Tourism): Promise<API.Result<DEVICE.Wayline>> {
|
||||
const result = await request<API.Result<DEVICE.Wayline>>('/api-device/wayline', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteWayline(id: number) {
|
||||
const url = `/api-device/wayline/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
// API 更新时间:
|
||||
// API 唯一标识:
|
||||
import * as api from './api';
|
||||
export default {
|
||||
api,
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
|
||||
declare namespace DEVICE {
|
||||
|
||||
type Wayline = {
|
||||
id: number;
|
||||
name: string;
|
||||
waylineId: string;
|
||||
droneModelKey: string;
|
||||
payloadModelKeys: string;
|
||||
workspaceId: string;
|
||||
sign: string;
|
||||
favorited: string;
|
||||
templateTypes: string;
|
||||
userName:string;
|
||||
createTime?: string;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -146,3 +146,13 @@ export async function updateRefund(data: ORDERS.Refund): Promise<API.Result<ORDE
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getTourismList(params?: { pageSize?: number; current?: number }) {
|
||||
return request<API.Response<API.Tourism[]>>('/api-order/tourism', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
pageSize: params?.pageSize || 100,
|
||||
current: params?.current || 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -93,4 +93,18 @@ declare namespace ORDERS {
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace API {
|
||||
interface Tourism {
|
||||
id: number;
|
||||
name: string;
|
||||
// ... 其他景区相关字段
|
||||
}
|
||||
|
||||
interface Response<T> {
|
||||
resp_code: number;
|
||||
resp_msg: string;
|
||||
data: T;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user