feat(后台管理):,优化景区名称显示
This commit is contained in:
+19
-11
@@ -4,7 +4,7 @@ import {
|
||||
ProFormSelect,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { STATUS_OPTIONS } from '../index';
|
||||
|
||||
interface UpdateFormProps {
|
||||
@@ -16,15 +16,19 @@ interface UpdateFormProps {
|
||||
tourismOptions: any[]; // 从父组件接收景区选项
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
const {
|
||||
onSubmit,
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
waylineOptions,
|
||||
tourismOptions,
|
||||
} = props;
|
||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
onSubmit,
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
waylineOptions,
|
||||
tourismOptions,
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
console.log('UpdateForm values:', values);
|
||||
console.log('UpdateForm tourismOptions:', tourismOptions);
|
||||
console.log('UpdateForm waylineOptions:', waylineOptions);
|
||||
}, [values, tourismOptions, waylineOptions]);
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
@@ -32,7 +36,11 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||
visible={updateModalVisible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
initialValues={values}
|
||||
initialValues={{
|
||||
...values,
|
||||
tourismId: Number(values?.tourismId),
|
||||
waylineId: values?.waylineId,
|
||||
}}
|
||||
onFinish={onSubmit}
|
||||
>
|
||||
<ProForm.Group>
|
||||
|
||||
@@ -100,7 +100,7 @@ const renderStatus = (status: {} | null | undefined) => {
|
||||
|
||||
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.Qrcode>();
|
||||
@@ -137,24 +137,6 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
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('获取航线列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
const fetchTourismList = useCallback(async () => {
|
||||
try {
|
||||
const result = await tourism({
|
||||
@@ -166,6 +148,7 @@ const TableList: React.FC = () => {
|
||||
const options = result.data.map(item => ({
|
||||
label: item.tourismName,
|
||||
value: item.id,
|
||||
info: item
|
||||
}));
|
||||
setTourismOptions(options);
|
||||
}
|
||||
@@ -174,98 +157,160 @@ const TableList: React.FC = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (updateModalVisible || createModalVisible) {
|
||||
fetchTourismList();
|
||||
fetchWaylineOptions();
|
||||
const fetchWaylineOptions = useCallback(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,
|
||||
}));
|
||||
setWaylineOptions(options);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('获取航线列表失败');
|
||||
}
|
||||
}, [updateModalVisible, createModalVisible, fetchTourismList]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchTourismList();
|
||||
fetchWaylineOptions();
|
||||
}, [fetchTourismList, fetchWaylineOptions]);
|
||||
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'id',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: 'CodeID',
|
||||
dataIndex: 'codeId',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '景区ID',
|
||||
title: '景区名称',
|
||||
dataIndex: 'tourismId',
|
||||
width: 160,
|
||||
ellipsis: true,
|
||||
render: (_, entity) => {
|
||||
const tourism = tourismOptions.find(item => item.value === entity.tourismId);
|
||||
return tourism?.label || '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '航线名称',
|
||||
dataIndex: 'waylineId',
|
||||
width: 160,
|
||||
ellipsis: true,
|
||||
render: (waylineId) => {
|
||||
const wayline = waylineOptions.find(item => item.value === waylineId);
|
||||
return wayline?.label || waylineId;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件',
|
||||
dataIndex: 'viewUrl',
|
||||
render: (viewUrl) => <Image src={viewUrl} width={100} />
|
||||
width: 120,
|
||||
render: (viewUrl) => viewUrl ? (
|
||||
<Image
|
||||
src={viewUrl}
|
||||
width={100}
|
||||
style={{ objectFit: 'cover' }}
|
||||
/>
|
||||
) : '-',
|
||||
},
|
||||
{
|
||||
title: '价格',
|
||||
dataIndex: 'price',
|
||||
width: 100,
|
||||
render: (price) => price ? `¥${(Number(price) / 100).toFixed(2)}` : '-',
|
||||
},
|
||||
{
|
||||
title: '设备SN',
|
||||
dataIndex: 'deviceSn',
|
||||
width: 140,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (status) => renderStatus(status),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) =>
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow({
|
||||
...entity,
|
||||
waylineId: entity.waylineId,
|
||||
});
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除景区[${entity.codeId}]?`}
|
||||
onConfirm={async () => {
|
||||
const success = await handleTableAction('delete', entity);
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
width: 120,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link
|
||||
onClick={() => {
|
||||
setCurrentRow(record);
|
||||
handleUpdateModalVisible(true);
|
||||
}}
|
||||
>
|
||||
修改
|
||||
</Link>
|
||||
<Popconfirm
|
||||
title={`确认删除该二维码?`}
|
||||
description="删除后将无法恢复,请谨慎操作"
|
||||
onConfirm={() => handleTableAction('delete', record)}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<PageContainer header={{ title: '二维码管理' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
onFinish={setParams}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
<ProFormSelect
|
||||
name="tourismId"
|
||||
label="景区"
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="waylineId"
|
||||
label="航线"
|
||||
placeholder="请选择航线"
|
||||
options={waylineOptions}
|
||||
showSearch
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
/>
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
headerTitle="二维码列表"
|
||||
request={qrcode}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
request={qrcode}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
@@ -273,16 +318,13 @@ const TableList: React.FC = () => {
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
handleModalVisible(true);
|
||||
}}
|
||||
>
|
||||
<PlusOutlined /> 添加
|
||||
</Button>
|
||||
</>,
|
||||
<Button
|
||||
key="add"
|
||||
type="primary"
|
||||
onClick={() => handleModalVisible(true)}
|
||||
>
|
||||
<PlusOutlined /> 新增二维码
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<ModalForm
|
||||
|
||||
+74
-77
@@ -14,10 +14,13 @@ import styles from '../index.less';
|
||||
import { tourism } from '@/services/orders/api';
|
||||
|
||||
interface UpdateFormProps {
|
||||
onSubmit: (values: Partial<ORDERS.TourismFile>) => Promise<void>;
|
||||
onSubmit: (values: any) => Promise<void>;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
updateModalVisible: boolean;
|
||||
values?: ORDERS.TourismFile;
|
||||
tourismOptions: any[];
|
||||
statusOptions: typeof STATUS_OPTIONS;
|
||||
typeOptions: typeof TYPE_OPTIONS;
|
||||
}
|
||||
|
||||
const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
@@ -25,54 +28,44 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
onVisibleChange,
|
||||
updateModalVisible,
|
||||
values,
|
||||
tourismOptions,
|
||||
statusOptions,
|
||||
typeOptions,
|
||||
}) => {
|
||||
const [imageUrl, setImageUrl] = useState<string>(values?.imageUrl || '');
|
||||
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [updateImageUrl, setUpdateImageUrl] = useState<string>();
|
||||
const [updateImagePath, setUpdateImagePath] = useState<string>();
|
||||
|
||||
// 处理文件上传
|
||||
const handleUpload = async (file: RcFile) => {
|
||||
const hide = message.loading('正在上传');
|
||||
setUploading(true);
|
||||
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 fetchTourismList = useCallback(async () => {
|
||||
try {
|
||||
const result = await tourism({
|
||||
limit: 100,
|
||||
page: 1,
|
||||
});
|
||||
|
||||
if (result.data) {
|
||||
const options = result.data.map(item => ({
|
||||
label: item.tourismName,
|
||||
value: item.id,
|
||||
}));
|
||||
setTourismOptions(options);
|
||||
hide();
|
||||
|
||||
if (result.url && result.path) {
|
||||
message.success('上传成功');
|
||||
setUpdateImageUrl(result.url);
|
||||
setUpdateImagePath(result.path);
|
||||
return true;
|
||||
}
|
||||
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
} catch (error) {
|
||||
message.error('获取景区列表失败');
|
||||
console.error('Upload error:', error);
|
||||
hide();
|
||||
message.error('上传失败:' + (error.message || '未知错误'));
|
||||
return false;
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 在组件挂载和弹窗打开时获取数据
|
||||
useEffect(() => {
|
||||
if (updateModalVisible) {
|
||||
fetchTourismList();
|
||||
}
|
||||
}, [updateModalVisible, fetchTourismList]);
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
@@ -81,13 +74,7 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
initialValues={values}
|
||||
onFinish={async (formValues) => {
|
||||
const submitData = {
|
||||
...formValues,
|
||||
imageUrl: imageUrl || values?.imageUrl,
|
||||
};
|
||||
await onSubmit(submitData);
|
||||
}}
|
||||
onFinish={onSubmit}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormSelect
|
||||
@@ -98,11 +85,6 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '素材类型不为空' }]}
|
||||
@@ -110,7 +92,15 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
name="type"
|
||||
label="素材类型"
|
||||
placeholder="请选择素材类型"
|
||||
options={TYPE_OPTIONS}
|
||||
options={typeOptions}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={statusOptions}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
@@ -124,34 +114,41 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
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}
|
||||
<Upload
|
||||
maxCount={1}
|
||||
accept="image/*"
|
||||
showUploadList={false}
|
||||
disabled={uploading}
|
||||
customRequest={async ({ file, onSuccess, onError }) => {
|
||||
try {
|
||||
if (file instanceof File) {
|
||||
const success = await handleUpload(file as RcFile);
|
||||
if (success) {
|
||||
onSuccess?.('ok');
|
||||
} else {
|
||||
onError?.(new Error('上传失败'));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
onError?.(error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
icon={<UploadOutlined />}
|
||||
loading={uploading}
|
||||
>
|
||||
<Button icon={<UploadOutlined />}>
|
||||
更换素材
|
||||
</Button>
|
||||
</Upload>
|
||||
更新素材
|
||||
</Button>
|
||||
</Upload>
|
||||
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Image
|
||||
src={updateImageUrl || values?.imageUrl}
|
||||
width={200}
|
||||
style={{ objectFit: 'cover' }}
|
||||
/>
|
||||
</div>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
@@ -22,12 +22,18 @@ import styles from './index.less';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// 提取常量
|
||||
export const TYPE_OPTIONS = [
|
||||
{ label: '展示大图', value: 4 },
|
||||
{ label: '拍照引导图', value: 3 },
|
||||
{ label: '拍照角度展示图', value: 2 },
|
||||
{ label: '活动', value: 1 },
|
||||
// 状态常量
|
||||
const STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 0, color: 'success' },
|
||||
{ label: '未启用', value: 1, color: 'error' },
|
||||
] as const;
|
||||
|
||||
// 类型常量
|
||||
const TYPE_OPTIONS = [
|
||||
{ label: '展示大图', value: 4, color: 'blue' },
|
||||
{ label: '拍照引导图', value: 3, color: 'green' },
|
||||
{ label: '拍照角度展示图', value: 2, color: 'cyan' },
|
||||
{ label: '活动', value: 1, color: 'orange' },
|
||||
] as const;
|
||||
|
||||
// 状态映射
|
||||
@@ -95,28 +101,18 @@ const handleDelete = async (tourismFile: ORDERS.TourismFile) => {
|
||||
);
|
||||
};
|
||||
|
||||
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 UploadResponse {
|
||||
id: string;
|
||||
url: string;
|
||||
path: string;
|
||||
name: string;
|
||||
isImg: boolean;
|
||||
contentType: string;
|
||||
size: number;
|
||||
source: string;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
@@ -124,7 +120,8 @@ const TableList: React.FC = () => {
|
||||
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
|
||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||
const [currentRow, setCurrentRow] = useState<ORDERS.TourismFile>();
|
||||
const [file, setFile] = useState<string>();
|
||||
const [createImageUrl, setCreateImageUrl] = useState<string>();
|
||||
const [createImagePath, setCreateImagePath] = useState<string>();
|
||||
const [tourismOptions, setTourismOptions] = useState<{ label: string; value: number; info?: any }[]>([]);
|
||||
|
||||
// 获取景区列表
|
||||
@@ -159,6 +156,30 @@ const TableList: React.FC = () => {
|
||||
fetchTourismList();
|
||||
}, [fetchTourismList]);
|
||||
|
||||
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.url && result.path) {
|
||||
message.success('上传成功');
|
||||
return {
|
||||
url: result.url,
|
||||
path: result.path
|
||||
};
|
||||
}
|
||||
message.error('上传失败:未获取到文件信息');
|
||||
return false;
|
||||
} catch (error) {
|
||||
hide();
|
||||
message.error('上传失败:' + (error.message || '未知错误'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleTableAction = useCallback(async (
|
||||
action: 'add' | 'edit' | 'delete',
|
||||
record?: ORDERS.TourismFile,
|
||||
@@ -167,8 +188,16 @@ const TableList: React.FC = () => {
|
||||
let success = false;
|
||||
switch (action) {
|
||||
case 'add':
|
||||
success = await handleAdd({ ...values, imageUrl: file } as ORDERS.TourismFile);
|
||||
success && setCreateModalVisible(false);
|
||||
if (!createImagePath) {
|
||||
message.error('请上传素材图片');
|
||||
return false;
|
||||
}
|
||||
success = await handleAdd({ ...values, imageUrl: createImagePath } as ORDERS.TourismFile);
|
||||
if (success) {
|
||||
setCreateModalVisible(false);
|
||||
setCreateImageUrl(undefined);
|
||||
setCreateImagePath(undefined);
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
if (record) {
|
||||
@@ -186,7 +215,7 @@ const TableList: React.FC = () => {
|
||||
if (success && actionRef.current) {
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, [file]);
|
||||
}, [createImagePath]);
|
||||
|
||||
const columns: ProColumns<ORDERS.TourismFile>[] = [
|
||||
{
|
||||
@@ -197,8 +226,12 @@ const TableList: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '景区名称',
|
||||
dataIndex: 'tourismName',
|
||||
dataIndex: 'tourismId',
|
||||
ellipsis: true,
|
||||
render: (_, record) => {
|
||||
const option = tourismOptions.find(item => item.value === record.tourismId);
|
||||
return option?.label || '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '素材预览',
|
||||
@@ -228,13 +261,23 @@ const TableList: React.FC = () => {
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: renderStatus,
|
||||
render: (status: number) => {
|
||||
const statusOption = STATUS_OPTIONS.find(item => item.value === Number(status));
|
||||
return statusOption ? (
|
||||
<Tag color={statusOption.color}>{statusOption.label}</Tag>
|
||||
) : '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "类型",
|
||||
dataIndex: 'type',
|
||||
width: 120,
|
||||
render: renderType,
|
||||
render: (type: number) => {
|
||||
const typeOption = TYPE_OPTIONS.find(item => item.value === Number(type));
|
||||
return typeOption ? (
|
||||
<Tag color={typeOption.color}>{typeOption.label}</Tag>
|
||||
) : '-';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
@@ -329,13 +372,7 @@ const TableList: React.FC = () => {
|
||||
<ModalForm
|
||||
title="添加素材"
|
||||
visible={createModalVisible}
|
||||
onVisibleChange={(visible) => {
|
||||
console.log('Modal visible changed:', visible);
|
||||
setCreateModalVisible(visible);
|
||||
if (visible) {
|
||||
fetchTourismList();
|
||||
}
|
||||
}}
|
||||
onVisibleChange={setCreateModalVisible}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={(values) => handleTableAction('add', undefined, values)}
|
||||
>
|
||||
@@ -348,11 +385,6 @@ const TableList: React.FC = () => {
|
||||
placeholder="请选择景区"
|
||||
options={tourismOptions}
|
||||
showSearch
|
||||
fieldProps={{
|
||||
loading: !tourismOptions.length,
|
||||
filterOption: (input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '素材类型不为空' }]}
|
||||
@@ -362,6 +394,15 @@ const TableList: React.FC = () => {
|
||||
placeholder="请选择素材类型"
|
||||
options={TYPE_OPTIONS}
|
||||
/>
|
||||
<ProFormSelect
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
width="md"
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
initialValue={0}
|
||||
/>
|
||||
<ProFormText
|
||||
width="md"
|
||||
name="linkUrl"
|
||||
@@ -376,23 +417,37 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
<Upload
|
||||
maxCount={1}
|
||||
action="/api-file/files-anon"
|
||||
accept="image/*"
|
||||
showUploadList={false}
|
||||
beforeUpload={async (file) => {
|
||||
const result = await handleImport(file);
|
||||
if (result && result.name) {
|
||||
setFile(result.name);
|
||||
customRequest={async ({ file, onSuccess, onError }) => {
|
||||
try {
|
||||
if (file instanceof File) {
|
||||
const result = await handleUpload(file as RcFile);
|
||||
if (result) {
|
||||
setCreateImageUrl(result.url);
|
||||
setCreateImagePath(result.path);
|
||||
onSuccess?.('ok');
|
||||
} else {
|
||||
onError?.(new Error('上传失败'));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
onError?.(error);
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<div className={styles.button_view}>
|
||||
<Button>
|
||||
<UploadOutlined />
|
||||
上传素材
|
||||
</Button>
|
||||
</div>
|
||||
<Button icon={<UploadOutlined />}>上传素材</Button>
|
||||
</Upload>
|
||||
|
||||
{createImageUrl && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<Image
|
||||
src={createImageUrl}
|
||||
width={200}
|
||||
style={{ objectFit: 'cover' }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
|
||||
@@ -402,6 +457,8 @@ const TableList: React.FC = () => {
|
||||
updateModalVisible={updateModalVisible}
|
||||
values={currentRow}
|
||||
tourismOptions={tourismOptions}
|
||||
statusOptions={STATUS_OPTIONS}
|
||||
typeOptions={TYPE_OPTIONS}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -11,6 +11,14 @@ export async function order(params?: { [key: string]: string | number }) {
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
|
||||
export async function updateOrder(data: ORDERS.Order): Promise<API.Result<ORDERS.Order>> {
|
||||
const result = await request<API.Result<ORDERS.Order>>('/api-order/update/order', {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteFile(id: number) {
|
||||
const url = `/api-order/files/${id}`;
|
||||
const result = await request<API.Result<void>>(url, {
|
||||
|
||||
Reference in New Issue
Block a user