fix(一键成片):功能逻辑优化,模板管理等前后端功能实现
This commit is contained in:
@@ -112,6 +112,10 @@
|
||||
path: '/orders/profit-sharing/statistics.html',
|
||||
component: './orders/ProfitSharing/Statistics',
|
||||
},
|
||||
{
|
||||
path: '/orders/videoTemplate.html',
|
||||
component: './orders/VideoTemplate',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSubmit: (values: ORDERS.Qrcode) => Promise<boolean>;
|
||||
templateOptions: any[];
|
||||
tourismOptions: any[];
|
||||
waylineOptions: any[];
|
||||
deviceOptions: any[];
|
||||
}
|
||||
|
||||
const CreateForm: React.FC<CreateFormProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
onSubmit,
|
||||
templateOptions,
|
||||
tourismOptions,
|
||||
waylineOptions,
|
||||
deviceOptions,
|
||||
}) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="新增二维码"
|
||||
visible={visible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={onSubmit}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="name"
|
||||
label="名称"
|
||||
rules={[{ required: true, message: '请输入名称' }]}
|
||||
placeholder="请输入二维码名称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
options={tourismOptions}
|
||||
rules={[{ required: true, message: '请选择景区' }]}
|
||||
placeholder="请选择景区"
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
}}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
placeholder="请选择航线"
|
||||
showSearch
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备"
|
||||
options={deviceOptions}
|
||||
rules={[{ required: true, message: '请选择设备' }]}
|
||||
placeholder="请选择设备"
|
||||
showSearch
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="price"
|
||||
label="价格(分)"
|
||||
rules={[{ required: true, message: '请输入价格' }]}
|
||||
min={0}
|
||||
placeholder="请输入价格"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
options={[
|
||||
{ label: '启用', value: 0 },
|
||||
{ label: '未启用', value: 1 },
|
||||
]}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
placeholder="请选择状态"
|
||||
initialValue={0}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="templateId"
|
||||
label="视频模板"
|
||||
options={templateOptions}
|
||||
rules={[{ required: true, message: '请选择视频模板' }]}
|
||||
placeholder="请选择视频模板"
|
||||
showSearch
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="payeeType"
|
||||
label="分账账号类型"
|
||||
options={[
|
||||
{ label: '商户ID', value: 'MERCHANT_ID' },
|
||||
{ label: '个人openid', value: 'PERSONAL_OPENID' },
|
||||
]}
|
||||
placeholder="请选择分账账号类型"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="payeeAccount"
|
||||
label="分账账号"
|
||||
placeholder="请输入分账账号"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="profitRate"
|
||||
label="分账比例(%)"
|
||||
min={0}
|
||||
max={100}
|
||||
placeholder="请输入分账比例"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateForm;
|
||||
+83
-81
@@ -1,3 +1,4 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
@@ -5,36 +6,31 @@ import {
|
||||
ProFormText,
|
||||
ProFormDigit,
|
||||
} from '@ant-design/pro-components';
|
||||
import React, { useEffect } from 'react';
|
||||
import { STATUS_OPTIONS, PAYEE_TYPE_OPTIONS } from '../index';
|
||||
import { Form, Space } from 'antd';
|
||||
import styles from './index.less';
|
||||
|
||||
export type UpdateFormProps = {
|
||||
onSubmit: (values: ORDERS.Qrcode) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
interface UpdateFormProps {
|
||||
updateModalVisible: boolean;
|
||||
values: Partial<ORDERS.Qrcode>;
|
||||
waylineOptions: any[];
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSubmit: (values: Partial<ORDERS.Qrcode>) => Promise<boolean>;
|
||||
values?: ORDERS.Qrcode;
|
||||
templateOptions: any[];
|
||||
tourismOptions: any[];
|
||||
deviceOptions: any[]; // 添加设备选项属性
|
||||
};
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const {
|
||||
updateModalVisible,
|
||||
onVisibleChange,
|
||||
onSubmit,
|
||||
values,
|
||||
waylineOptions,
|
||||
tourismOptions,
|
||||
deviceOptions, // 解构设备选项
|
||||
} = props;
|
||||
|
||||
useEffect(() => {
|
||||
console.log('UpdateForm values:', values);
|
||||
console.log('UpdateForm tourismOptions:', tourismOptions);
|
||||
console.log('UpdateForm waylineOptions:', waylineOptions);
|
||||
}, [values, tourismOptions, waylineOptions]);
|
||||
waylineOptions: any[];
|
||||
deviceOptions: any[];
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
updateModalVisible,
|
||||
onVisibleChange,
|
||||
onSubmit,
|
||||
values,
|
||||
templateOptions,
|
||||
tourismOptions,
|
||||
waylineOptions,
|
||||
deviceOptions,
|
||||
}) => {
|
||||
return (
|
||||
<ModalForm
|
||||
title="修改二维码"
|
||||
@@ -49,20 +45,8 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
width="md"
|
||||
name="name"
|
||||
label="名称"
|
||||
placeholder="请输入二维码名称"
|
||||
rules={[{ required: true, message: '请输入名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
fieldProps={{
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
}}
|
||||
placeholder="请输入二维码名称"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
@@ -70,81 +54,99 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
label="景区"
|
||||
options={tourismOptions}
|
||||
rules={[{ required: true, message: '请选择景区' }]}
|
||||
placeholder="请选择景区"
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormText
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="price"
|
||||
label="景点打卡价格"
|
||||
rules={[{ required: true, message: '价格不能为空' }]}
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
placeholder="请选择航线"
|
||||
showSearch
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
label="设备"
|
||||
options={deviceOptions}
|
||||
rules={[{ required: true, message: '设备不能为空' }]}
|
||||
fieldProps={{
|
||||
loading: !deviceOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: deviceOptions.length === 0 ? '暂无设备数据' : undefined,
|
||||
}}
|
||||
rules={[{ required: true, message: '请选择设备' }]}
|
||||
placeholder="请选择设备"
|
||||
showSearch
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="price"
|
||||
label="价格(分)"
|
||||
rules={[{ required: true, message: '请输入价格' }]}
|
||||
min={0}
|
||||
placeholder="请输入价格"
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
options={[
|
||||
{ label: '启用', value: 0 },
|
||||
{ label: '未启用', value: 1 },
|
||||
]}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
placeholder="请选择状态"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group title="分账配置">
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="templateId"
|
||||
label="视频模板"
|
||||
options={templateOptions}
|
||||
rules={[{ required: true, message: '请选择视频模板' }]}
|
||||
placeholder="请选择视频模板"
|
||||
showSearch
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="payeeType"
|
||||
label="分账账号类型"
|
||||
options={[
|
||||
{ label: '商户ID', value: 'MERCHANT_ID' },
|
||||
{ label: '个人openid', value: 'PERSONAL_OPENID' },
|
||||
]}
|
||||
placeholder="请选择分账账号类型"
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="payeeAccount"
|
||||
label="分账账号"
|
||||
placeholder="请输入分账接收账号"
|
||||
rules={[{ required: true, message: '请输入分账账号' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="payeeType"
|
||||
label="账号类型"
|
||||
options={PAYEE_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择账号类型' }]}
|
||||
placeholder="请输入分账账号"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="profitRate"
|
||||
label="分账比例"
|
||||
label="分账比例(%)"
|
||||
min={0}
|
||||
max={100}
|
||||
fieldProps={{
|
||||
precision: 2,
|
||||
suffix: '%',
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请输入分账比例' },
|
||||
{ type: 'number', min: 0, max: 100, message: '比例必须在0-100之间' },
|
||||
]}
|
||||
placeholder="请输入分账比例"
|
||||
/>
|
||||
{values?.payeeStatus === 2 && (
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="payeeFailReason"
|
||||
label="验证失败原因"
|
||||
disabled
|
||||
/>
|
||||
)}
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
.formSection {
|
||||
margin-bottom: 24px;
|
||||
|
||||
.sectionTitle {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
margin-bottom: 16px;
|
||||
padding-left: 8px;
|
||||
border-left: 3px solid #1890ff;
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.ant-form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList } from '@/services/orders/api';
|
||||
import { deleteQrcode, qrcode, saveOrUpdateQrcode, getTourismList, getVideoTemplateList } from '@/services/orders/api';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
@@ -16,6 +16,7 @@ import { Typography, Popconfirm, Space, message, Image, Button, Tag } from 'antd
|
||||
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import { wayline, device } from '@/services/device/api';
|
||||
import CreateForm from './components/CreateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
@@ -65,47 +66,6 @@ const handleApiRequest = async (
|
||||
}
|
||||
};
|
||||
|
||||
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) => {
|
||||
return handleApiRequest(
|
||||
() => deleteQrcode(qrcode.id),
|
||||
'正在删除',
|
||||
'删除成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 状态颜色映射
|
||||
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>>({});
|
||||
@@ -115,8 +75,46 @@ const TableList: React.FC = () => {
|
||||
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
|
||||
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
||||
const [deviceOptions, setDeviceOptions] = useState<any[]>([]);
|
||||
const [templateOptions, setTemplateOptions] = useState<any[]>([]);
|
||||
const formRef = useRef();
|
||||
|
||||
// 将 renderStatus 函数移到组件内部
|
||||
const renderStatus = (status: number) => {
|
||||
const statusColorMap = {
|
||||
0: { color: 'green', text: '启用' },
|
||||
1: { color: 'red', text: '未启用' },
|
||||
};
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
// 处理添加
|
||||
const handleAdd = async (fields: ORDERS.Qrcode) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
...fields,
|
||||
templateName: template?.label,
|
||||
}),
|
||||
'正在添加',
|
||||
'添加成功'
|
||||
);
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
const handleEdit = async (original: ORDERS.Qrcode, fields: Partial<ORDERS.Qrcode>) => {
|
||||
const template = templateOptions.find(item => item.value === fields.templateId);
|
||||
return handleApiRequest(
|
||||
() => saveOrUpdateQrcode({
|
||||
id: original.id,
|
||||
...fields,
|
||||
templateName: template?.label,
|
||||
}),
|
||||
'正在更新',
|
||||
'修改成功'
|
||||
);
|
||||
};
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.Qrcode,
|
||||
@@ -144,7 +142,7 @@ const TableList: React.FC = () => {
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, []);
|
||||
}, [templateOptions]);
|
||||
|
||||
const fetchTourismList = useCallback(async () => {
|
||||
try {
|
||||
@@ -201,11 +199,32 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const fetchTemplateOptions = useCallback(async () => {
|
||||
try {
|
||||
const result = await getVideoTemplateList({
|
||||
page: 1,
|
||||
limit: 100,
|
||||
status: 1, // 只获取启用的模板
|
||||
});
|
||||
if (result.data?.data) {
|
||||
const options = result.data.data.map(item => ({
|
||||
label: item.templateName,
|
||||
value: item.templateId,
|
||||
info: item,
|
||||
}));
|
||||
setTemplateOptions(options);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取模板列表失败');
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchTourismList();
|
||||
fetchWaylineOptions();
|
||||
fetchDeviceList();
|
||||
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList]);
|
||||
fetchTemplateOptions();
|
||||
}, [fetchTourismList, fetchWaylineOptions, fetchDeviceList, fetchTemplateOptions]);
|
||||
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
@@ -280,7 +299,7 @@ const TableList: React.FC = () => {
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (status) => renderStatus(status),
|
||||
render: (status) => renderStatus(status as number),
|
||||
},
|
||||
{
|
||||
title: '分账账号',
|
||||
@@ -323,6 +342,16 @@ const TableList: React.FC = () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '模板名称',
|
||||
dataIndex: 'templateId',
|
||||
width: 180,
|
||||
ellipsis: true,
|
||||
render: (_, record) => {
|
||||
const template = templateOptions.find(item => item.value === record.templateId);
|
||||
return template?.label || '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
@@ -421,121 +450,22 @@ const TableList: React.FC = () => {
|
||||
overflow: 'auto',
|
||||
}}
|
||||
/>
|
||||
<ModalForm
|
||||
title="添加二维码"
|
||||
visible={createModalVisible}
|
||||
<CreateForm
|
||||
onSubmit={async (values) => handleTableAction('add', undefined, values)}
|
||||
onVisibleChange={(visible) => {
|
||||
handleModalVisible(visible);
|
||||
if (visible) {
|
||||
fetchDeviceList();
|
||||
fetchTourismList();
|
||||
fetchTemplateOptions();
|
||||
}
|
||||
}}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={async (values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="name"
|
||||
label="名称"
|
||||
placeholder="请输入二维码名称"
|
||||
rules={[{ required: true, message: '请输入名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
placeholder="请选择航线"
|
||||
options={waylineOptions}
|
||||
rules={[{ required: true, message: '请选择航线' }]}
|
||||
fieldProps={{
|
||||
loading: !waylineOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
rules={[{ required: true, message: '请选择景区' }]}
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="price"
|
||||
label="景点打卡价格"
|
||||
placeholder="输入价格(单位:分)"
|
||||
rules={[{ required: true, message: '价格不为空' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="deviceSn"
|
||||
label="设备编号"
|
||||
placeholder="请选择设备"
|
||||
options={deviceOptions}
|
||||
rules={[{ required: true, message: '设备不能为空' }]}
|
||||
fieldProps={{
|
||||
loading: !deviceOptions.length,
|
||||
showSearch: true,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
notFoundContent: deviceOptions.length === 0 ? '暂无设备数据' : undefined,
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
initialValue={0}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group title="分账配置">
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="payeeAccount"
|
||||
label="分账账号"
|
||||
placeholder="请输入分账接收账号"
|
||||
rules={[{ required: true, message: '请输入分账账号' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
width="md"
|
||||
name="payeeType"
|
||||
label="账号类型"
|
||||
options={PAYEE_TYPE_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择账号类型' }]}
|
||||
/>
|
||||
<ProFormDigit
|
||||
width="md"
|
||||
name="profitRate"
|
||||
label="分账比例"
|
||||
min={0}
|
||||
max={100}
|
||||
fieldProps={{
|
||||
precision: 2,
|
||||
suffix: '%',
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请输入分账比例' },
|
||||
{ type: 'number', min: 0, max: 100, message: '比例必须在0-100之间' },
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
visible={createModalVisible}
|
||||
templateOptions={templateOptions}
|
||||
tourismOptions={tourismOptions}
|
||||
waylineOptions={waylineOptions}
|
||||
deviceOptions={deviceOptions}
|
||||
/>
|
||||
<UpdateForm
|
||||
onSubmit={async (values) => {
|
||||
return handleTableAction('edit', currentRow, values);
|
||||
@@ -545,6 +475,7 @@ const TableList: React.FC = () => {
|
||||
if (visible) {
|
||||
fetchDeviceList();
|
||||
fetchTourismList();
|
||||
fetchTemplateOptions();
|
||||
}
|
||||
if (!visible) {
|
||||
setCurrentRow(undefined);
|
||||
@@ -555,6 +486,7 @@ const TableList: React.FC = () => {
|
||||
waylineOptions={waylineOptions}
|
||||
tourismOptions={tourismOptions}
|
||||
deviceOptions={deviceOptions}
|
||||
templateOptions={templateOptions}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import { saveVideoTemplate } from '@/services/orders/api';
|
||||
import { STATUS_OPTIONS } from '../index';
|
||||
import styles from './index.less';
|
||||
|
||||
interface CreateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
const CreateForm: React.FC<CreateFormProps> = (props) => {
|
||||
const { visible, onVisibleChange, onSuccess } = props;
|
||||
|
||||
const handleAdd = async (values: ORDERS.VideoTemplate) => {
|
||||
try {
|
||||
const result = await saveVideoTemplate(values);
|
||||
if (result.resp_code === 0) {
|
||||
message.success('添加成功');
|
||||
onSuccess();
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg || '添加失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('添加失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="新增视频模板"
|
||||
width={800}
|
||||
visible={visible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={handleAdd}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
className: styles.customModal,
|
||||
}}
|
||||
>
|
||||
<ProForm.Group title="基本信息" className={styles.formGroup}>
|
||||
<ProFormText
|
||||
name="templateId"
|
||||
label="模板ID"
|
||||
width="md"
|
||||
placeholder="请输入模板ID"
|
||||
rules={[{ required: true, message: '请输入模板ID' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="templateName"
|
||||
label="模板名称"
|
||||
width="md"
|
||||
placeholder="请输入模板名称"
|
||||
rules={[{ required: true, message: '请输入模板名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
width="md"
|
||||
options={STATUS_OPTIONS}
|
||||
initialValue={1}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group title="详细配置" className={styles.formGroup}>
|
||||
<ProFormTextArea
|
||||
name="description"
|
||||
label="模板描述"
|
||||
width="xl"
|
||||
placeholder="请输入模板描述"
|
||||
fieldProps={{
|
||||
rows: 4,
|
||||
maxLength: 200,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="config"
|
||||
label="模板配置"
|
||||
width="xl"
|
||||
placeholder="请输入JSON格式的模板配置"
|
||||
fieldProps={{
|
||||
rows: 8,
|
||||
maxLength: 2000,
|
||||
showCount: true,
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请输入模板配置' },
|
||||
{
|
||||
validator: async (_, value) => {
|
||||
if (value) {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
} catch (error) {
|
||||
throw new Error('请输入有效的JSON格式');
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateForm;
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import { updateVideoTemplate } from '@/services/orders/api';
|
||||
import { STATUS_OPTIONS } from '../index';
|
||||
import styles from './index.less';
|
||||
|
||||
interface UpdateFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onSuccess: () => void;
|
||||
values?: ORDERS.VideoTemplate;
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const { visible, onVisibleChange, onSuccess, values } = props;
|
||||
|
||||
const handleUpdate = async (formValues: ORDERS.VideoTemplate) => {
|
||||
try {
|
||||
const result = await updateVideoTemplate({
|
||||
...formValues,
|
||||
id: values?.id,
|
||||
});
|
||||
if (result.resp_code === 0) {
|
||||
message.success('修改成功');
|
||||
onSuccess();
|
||||
return true;
|
||||
}
|
||||
message.error(result.resp_msg || '修改失败');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title="编辑视频模板"
|
||||
width={800}
|
||||
visible={visible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={handleUpdate}
|
||||
initialValues={values}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
className: styles.customModal,
|
||||
}}
|
||||
>
|
||||
<ProForm.Group title="基本信息" className={styles.formGroup}>
|
||||
<ProFormText
|
||||
name="templateId"
|
||||
label="模板ID"
|
||||
width="md"
|
||||
placeholder="请输入模板ID"
|
||||
rules={[{ required: true, message: '请输入模板ID' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="templateName"
|
||||
label="模板名称"
|
||||
width="md"
|
||||
placeholder="请输入模板名称"
|
||||
rules={[{ required: true, message: '请输入模板名称' }]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
width="md"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group title="详细配置" className={styles.formGroup}>
|
||||
<ProFormTextArea
|
||||
name="description"
|
||||
label="模板描述"
|
||||
width="xl"
|
||||
placeholder="请输入模板描述"
|
||||
fieldProps={{
|
||||
rows: 4,
|
||||
maxLength: 200,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="config"
|
||||
label="模板配置"
|
||||
width="xl"
|
||||
placeholder="请输入JSON格式的模板配置"
|
||||
fieldProps={{
|
||||
rows: 8,
|
||||
maxLength: 2000,
|
||||
showCount: true,
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请输入模板配置' },
|
||||
{
|
||||
validator: async (_, value) => {
|
||||
if (value) {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
} catch (error) {
|
||||
throw new Error('请输入有效的JSON格式');
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateForm;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
.customModal {
|
||||
:global {
|
||||
.ant-modal-body {
|
||||
padding: 24px 24px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.formGroup {
|
||||
:global {
|
||||
.ant-form-group-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
color: rgba(0, 0, 0, 0.85);
|
||||
line-height: 24px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.ant-form-item {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.ant-form-item-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
ModalForm,
|
||||
PageContainer,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
ProFormSelect,
|
||||
ProTable,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Button, message, Space, Tag, Typography, Modal } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { getVideoTemplateList, saveVideoTemplate, updateVideoTemplate, deleteVideoTemplate, updateVideoTemplateStatus } from '@/services/orders/api';
|
||||
import CreateForm from './components/CreateForm';
|
||||
import UpdateForm from './components/UpdateForm';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
export const STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
] as const;
|
||||
|
||||
const VideoTemplateList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.VideoTemplate>();
|
||||
|
||||
// 处理API请求
|
||||
const handleRequest = async (params: any) => {
|
||||
const { current, pageSize, ...rest } = params;
|
||||
const result = await getVideoTemplateList({
|
||||
page: current,
|
||||
limit: pageSize,
|
||||
...rest,
|
||||
});
|
||||
return {
|
||||
data: result.data?.data || [],
|
||||
success: result.resp_code === 0,
|
||||
total: result.data?.count || 0,
|
||||
};
|
||||
};
|
||||
|
||||
// 处理删除
|
||||
const handleDelete = async (id: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该模板吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
const result = await deleteVideoTemplate(id);
|
||||
if (result.resp_code === 0) {
|
||||
message.success('删除成功');
|
||||
actionRef.current?.reload();
|
||||
} else {
|
||||
message.error(result.resp_msg || '删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 处理状态更新
|
||||
const handleStatusChange = async (id: number, status: number) => {
|
||||
try {
|
||||
const result = await updateVideoTemplateStatus(id, status);
|
||||
if (result.resp_code === 0) {
|
||||
message.success('状态更新成功');
|
||||
actionRef.current?.reload();
|
||||
} else {
|
||||
message.error(result.resp_msg || '状态更新失败');
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('状态更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
const columns: ProColumns<ORDERS.VideoTemplate>[] = [
|
||||
{
|
||||
title: '模板ID',
|
||||
dataIndex: 'templateId',
|
||||
width: 180,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '模板名称',
|
||||
dataIndex: 'templateName',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
width: 200,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (_, record) => (
|
||||
<Tag color={record.status === 1 ? 'success' : 'default'}>
|
||||
{record.status === 1 ? '启用' : '禁用'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
width: 180,
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
width: 180,
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link onClick={() => {
|
||||
setCurrentRow(record);
|
||||
setUpdateModalVisible(true);
|
||||
}}>
|
||||
编辑
|
||||
</Link>
|
||||
<Link onClick={() => handleStatusChange(record.id, record.status === 1 ? 0 : 1)}>
|
||||
{record.status === 1 ? '禁用' : '启用'}
|
||||
</Link>
|
||||
<Link onClick={() => handleDelete(record.id)}>
|
||||
删除
|
||||
</Link>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ProTable<ORDERS.VideoTemplate>
|
||||
headerTitle="视频模板列表"
|
||||
actionRef={actionRef}
|
||||
rowKey="id"
|
||||
search={{
|
||||
labelWidth: 120,
|
||||
defaultCollapsed: false,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
type="primary"
|
||||
key="create"
|
||||
onClick={() => setCreateModalVisible(true)}
|
||||
>
|
||||
<PlusOutlined /> 新增模板
|
||||
</Button>,
|
||||
]}
|
||||
request={handleRequest}
|
||||
columns={columns}
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showQuickJumper: true,
|
||||
showSizeChanger: true,
|
||||
}}
|
||||
/>
|
||||
|
||||
<CreateForm
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
onSuccess={() => {
|
||||
setCreateModalVisible(false);
|
||||
actionRef.current?.reload();
|
||||
}}
|
||||
/>
|
||||
|
||||
<UpdateForm
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
if (!visible) {
|
||||
setCurrentRow(undefined);
|
||||
}
|
||||
setUpdateModalVisible(visible);
|
||||
}}
|
||||
onSuccess={() => {
|
||||
setUpdateModalVisible(false);
|
||||
setCurrentRow(undefined);
|
||||
actionRef.current?.reload();
|
||||
}}
|
||||
values={currentRow}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoTemplateList;
|
||||
@@ -217,3 +217,45 @@ export async function getProfitSharingStatistics(params: {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取视频模板列表 */
|
||||
export async function getVideoTemplateList(params: {
|
||||
page: number;
|
||||
limit: number;
|
||||
[key: string]: any;
|
||||
}) {
|
||||
return request('/api-order/video/template/list', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 添加视频模板 */
|
||||
export async function saveVideoTemplate(data: ORDERS.VideoTemplate) {
|
||||
return request('/api-order/video/template', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/** 更新视频模板 */
|
||||
export async function updateVideoTemplate(data: ORDERS.VideoTemplate) {
|
||||
return request('/api-order/video/template', {
|
||||
method: 'PUT',
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
/** 删除视频模板 */
|
||||
export async function deleteVideoTemplate(id: number) {
|
||||
return request(`/api-order/video/template/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
/** 更新视频模板状态 */
|
||||
export async function updateVideoTemplateStatus(id: number, status: number) {
|
||||
return request(`/api-order/video/template/${id}/status/${status}`, {
|
||||
method: 'PUT',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ declare namespace ORDERS {
|
||||
profitRate?: number;
|
||||
payeeStatus?: number;
|
||||
payeeFailReason?: string;
|
||||
templateId: string;
|
||||
}
|
||||
|
||||
type HomeCarousel = {
|
||||
@@ -167,6 +168,20 @@ declare namespace ORDERS {
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
interface VideoTemplate {
|
||||
id: number;
|
||||
templateId: string;
|
||||
templateName: string;
|
||||
description?: string;
|
||||
status: number;
|
||||
config: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
tenantId?: number;
|
||||
company?: string;
|
||||
isDel?: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace API {
|
||||
|
||||
Reference in New Issue
Block a user