feat: 二维码新增或者编辑绑定景区素材
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer, ProTable } from '@ant-design/pro-components';
|
||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import QrcodeForm, { QrcodeItem } from './components/QrcodeForm';
|
||||
|
||||
const QrcodePage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '名称', dataIndex: 'name' },
|
||||
{ title: '链接', dataIndex: 'url', ellipsis: true },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
|
||||
{
|
||||
title: '操作', key: 'action',
|
||||
render: (_: any, record: QrcodeItem) => (
|
||||
<Space>
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||
<Popconfirm title={`确认删除二维码[${record.name}]?`} onConfirm={async () => {
|
||||
const hide = message.loading('删除中...');
|
||||
try {
|
||||
await ordersApi.deleteQrcode(record.id!);
|
||||
message.success('删除成功');
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
} finally { hide(); }
|
||||
}}>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '二维码管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
onTenantChanged={() => { /* 仅触发表格刷新 */ }}
|
||||
onFinish={async (values) => setParams(values)}
|
||||
/>
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
||||
<GlassCard>
|
||||
<ProTable<QrcodeItem>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.qrcodeList({ ...(p as any), ...params })}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<QrcodeForm
|
||||
title="新增二维码"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode(values);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
|
||||
<QrcodeForm
|
||||
title="编辑二维码"
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default QrcodePage;
|
||||
|
||||
+4
-3
@@ -28,9 +28,9 @@ export interface QrcodeItem {
|
||||
vlogCount?: number;
|
||||
videoCount?: number;
|
||||
photoCount?: number;
|
||||
tourismFileIds?: number[];
|
||||
}
|
||||
|
||||
export interface QrcodeFormProps {
|
||||
export interface QrcodeFormProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
initialValues?: Partial<QrcodeItem>;
|
||||
@@ -56,4 +56,5 @@ const QrcodeForm: React.FC<QrcodeFormProps> = ({ open, title, initialValues, onO
|
||||
);
|
||||
};
|
||||
|
||||
export default QrcodeForm;
|
||||
export default QrcodeItem;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ProTable, type ActionType } from '@ant-design/pro-components';
|
||||
import { GradientButton } from '@/components/ui';
|
||||
import { PlusOutlined, CopyOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { QrcodeItem } from '../../Qrcode/components/QrcodeForm';
|
||||
import { QrcodeItem } from './QrcodeItem';
|
||||
import QrcodeTourismForm from './QrcodeTourismForm';
|
||||
|
||||
export interface QrcodeListModalProps {
|
||||
@@ -22,7 +22,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
const [previewOpen, setPreviewOpen] = useState(false);
|
||||
const [previewImage, setPreviewImage] = useState<string>('');
|
||||
|
||||
// 模板ID(templateId 字符串) -> 模板名称(通过接口懒加载)
|
||||
// 模板ID -> 模板名称(通过接口懒加载)
|
||||
const templateNameMapRef = useRef<Record<string, string>>({});
|
||||
const templateInflightRef = useRef<Record<string, Promise<any>>>({});
|
||||
const [tplTick, setTplTick] = useState(0); // 用于触发渲染
|
||||
@@ -143,7 +143,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (v: number) => <Tag color={v === 0 ? 'green' : 'red'}>{v === 0 ? '启用' : '未启用'}</Tag>,
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '启用' : '禁用'}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '模板名称',
|
||||
@@ -155,7 +155,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
title: '一键成片',
|
||||
dataIndex: 'enableVideoEdit',
|
||||
width: 100,
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '开启' : '否'}</Tag>,
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '测试二维码',
|
||||
@@ -168,13 +168,13 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
dataIndex: 'qrcodeType',
|
||||
width: 120,
|
||||
render: (v: number) => {
|
||||
if (v === 1) return <Tag color="blue">游客下单</Tag>;
|
||||
if (v === 2) return <Tag color="green">定时巡查</Tag>;
|
||||
return <Tag color="#000000">其他</Tag>;
|
||||
if (v === 1) return <Tag color="blue">游客扫码</Tag>;
|
||||
if (v === 2) return <Tag color="green">临时扫码</Tag>;
|
||||
return <Tag color="#000000">自定义</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '仅显一键成片',
|
||||
title: '仅显示一键成片',
|
||||
dataIndex: 'showVideoEditOnly',
|
||||
width: 130,
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||
@@ -238,49 +238,67 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
{/* 新增二维码 */}
|
||||
<QrcodeTourismForm
|
||||
title="新增二维码"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode({ ...values, tourismId });
|
||||
message.success('新增成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
defaultTourismId={tourismId}
|
||||
/>
|
||||
{/* 新增/编辑表单:仅在打开时才挂载,避免列表页触发内部副作用 */}
|
||||
{createOpen && (
|
||||
<QrcodeTourismForm
|
||||
title="新增二维码"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('提交中...');
|
||||
try {
|
||||
const { vlogCount, videoCount, photoCount, tourismFileIds, ...qrRest } = values as any;
|
||||
await ordersApi.saveOrUpdateQrcodePlan({
|
||||
qrCode: { ...qrRest, tourismId },
|
||||
vlogCount,
|
||||
videoCount,
|
||||
photoCount,
|
||||
tourismFileIds,
|
||||
});
|
||||
message.success('修改成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
defaultTourismId={tourismId}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 编辑二维码 */}
|
||||
<QrcodeTourismForm
|
||||
title="编辑二维码"
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{editOpen && (
|
||||
<QrcodeTourismForm
|
||||
title="编辑二维码"
|
||||
open={editOpen}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('提交中...');
|
||||
try {
|
||||
const merged: any = { ...(current as any), ...values };
|
||||
const { vlogCount, videoCount, photoCount, tourismFileIds, ...qrRest } = merged;
|
||||
await ordersApi.saveOrUpdateQrcodePlan({
|
||||
qrCode: qrRest,
|
||||
vlogCount,
|
||||
videoCount,
|
||||
photoCount,
|
||||
tourismFileIds,
|
||||
});
|
||||
message.success('修改成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
initialValues={current}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 二维码预览 */}
|
||||
<Modal title="二维码预览" open={previewOpen} onCancel={() => setPreviewOpen(false)} footer={null} width={600} centered destroyOnClose>
|
||||
@@ -292,5 +310,4 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
);
|
||||
};
|
||||
|
||||
export default QrcodeListModal;
|
||||
|
||||
export default QrcodeListModal;
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { deviceApi } from '@/services/device';
|
||||
import { miniAppApi } from '@/services/miniapp';
|
||||
import type { QrcodeItem } from '../../Qrcode/components/QrcodeForm';
|
||||
import type { QrcodeItem } from './QrcodeItem';
|
||||
|
||||
export interface QrcodeTourismFormProps {
|
||||
open: boolean;
|
||||
@@ -15,13 +15,13 @@ export interface QrcodeTourismFormProps {
|
||||
}
|
||||
|
||||
const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, initialValues, onOpenChange, onFinish, defaultTourismId }) => {
|
||||
// 统一默认值(用于新增与编辑缺省字段的兜底)
|
||||
// 统一默认值,解决新增/编辑缺省字段的问题
|
||||
const DEFAULTS: Partial<QrcodeItem> = {
|
||||
status: 0, // 启用:0,未启用:1(与列表渲染保持一致)
|
||||
enableVideoEdit: 0, // 开启一键成片:否=0,是=1
|
||||
isTest: 0, // 测试二维码:否=0,是=1
|
||||
qrcodeType: 1, // 二维码类型:1=游客下单,2=定时巡查,3=其他
|
||||
showVideoEditOnly: 0, // 只显示一键成片:否=0,是=1(默认:否)
|
||||
status: 0, // 状态:0=禁用,1=启用
|
||||
enableVideoEdit: 0, // 是否开启一键成片:0=否 1=是
|
||||
isTest: 0, // 是否测试二维码:0=否 1=是
|
||||
qrcodeType: 1, // 二维码类型:1=游客扫码 2=临时扫码 3=自定义
|
||||
showVideoEditOnly: 0, // 是否仅显示一键成片:0=否 1=是
|
||||
materialCount: 1,
|
||||
vlogCount: 0,
|
||||
videoCount: 0,
|
||||
@@ -30,9 +30,36 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
|
||||
// 过滤 initialValues 中的 undefined,避免覆盖默认值
|
||||
const sanitizedInitial: Partial<QrcodeItem> = initialValues
|
||||
? Object.fromEntries(Object.entries(initialValues).filter(([, v]) => v !== undefined))
|
||||
? (Object.fromEntries(Object.entries(initialValues).filter(([, v]) => v !== undefined)) as any)
|
||||
: {};
|
||||
|
||||
// 景区ID,用于素材查询
|
||||
const tourismIdForFetch = (sanitizedInitial as any)?.tourismId ?? defaultTourismId;
|
||||
|
||||
// 景区素材
|
||||
const [tourismFiles, setTourismFiles] = useState<any[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
// 仅在弹窗打开时才加载景区素材,避免在列表页无意义调用接口
|
||||
if (!open) return;
|
||||
if (!tourismIdForFetch) {
|
||||
setTourismFiles([]);
|
||||
return;
|
||||
}
|
||||
let canceled = false;
|
||||
(async () => {
|
||||
try {
|
||||
const { data = [] } = await ordersApi.tourismFileByTourism(tourismIdForFetch as any);
|
||||
if (!canceled) setTourismFiles(Array.isArray(data) ? data : []);
|
||||
} catch {
|
||||
if (!canceled) setTourismFiles([]);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
canceled = true;
|
||||
};
|
||||
}, [open, tourismIdForFetch]);
|
||||
|
||||
return (
|
||||
<ModalForm<QrcodeItem>
|
||||
title={title}
|
||||
@@ -64,25 +91,30 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
labelWrap
|
||||
colProps={{ span: 12 }}
|
||||
>
|
||||
{/* 收款商户(必填,置顶显示) */}
|
||||
{/* 小程序商户(仅显示支持支付的类型) */}
|
||||
<ProFormSelect
|
||||
name="tenantId"
|
||||
label="收款商户"
|
||||
label="小程序商户"
|
||||
showSearch
|
||||
rules={[{ required: true, message: '请选择收款商户' }]}
|
||||
placeholder="请选择收款商户"
|
||||
rules={[{ required: true, message: '请选择小程序商户' }]}
|
||||
placeholder="请选择小程序商户"
|
||||
request={async () => {
|
||||
// 后端筛选不生效时,前端兜底过滤 type=PAY
|
||||
// 只取 type=PAY 的商户
|
||||
const { data = [] } = await miniAppApi.list({ page: 1, limit: 1000 });
|
||||
const filtered = (data || []).filter((m: any) => String(m?.type || '').toUpperCase() === 'PAY');
|
||||
// 名称显示 subMchName(若无则回退到 tenantId)
|
||||
return filtered.map((m: any) => ({ label: m.subMchName || m.tenantId, value: m.tenantId }));
|
||||
}}
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
{/* 基础信息 */}
|
||||
<ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入二维码名称' }]} placeholder="请输入二维码名称" colProps={{ span: 12 }} />
|
||||
{/* 基本信息 */}
|
||||
<ProFormText
|
||||
name="name"
|
||||
label="名称"
|
||||
rules={[{ required: true, message: '请输入二维码名称' }]}
|
||||
placeholder="请输入二维码名称"
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
<ProFormSelect
|
||||
name="waylineId"
|
||||
@@ -114,11 +146,11 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
|
||||
<ProFormDigit
|
||||
name="price"
|
||||
label="价格(分)"
|
||||
label="价格(元)"
|
||||
min={0}
|
||||
rules={[{ required: true, message: '请输入价格(分)' }]}
|
||||
rules={[{ required: true, message: '请输入价格' }]}
|
||||
fieldProps={{ precision: 0 }}
|
||||
placeholder="请输入价格(分)"
|
||||
placeholder="请输入价格"
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
@@ -127,42 +159,36 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
label="状态"
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
options={[
|
||||
{ label: '启用', value: 0 },
|
||||
{ label: '未启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
]}
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
{/* 视频模板(可选) */}
|
||||
<ProFormSelect
|
||||
name="templateId"
|
||||
label="视频模板"
|
||||
showSearch
|
||||
rules={[{ required: true, message: '请选择视频模板' }]}
|
||||
allowClear
|
||||
placeholder="请选择视频模板"
|
||||
request={async () => {
|
||||
const { data = [] } = await ordersApi.getVideoTemplateList({ current: 1, pageSize: 1000 });
|
||||
return (data || []).map((t: any) => ({
|
||||
label: t?.templateName || t?.name || t?.templateId || String(t?.id ?? ''),
|
||||
value: String(t?.templateId ?? t?.id ?? ''),
|
||||
}));
|
||||
try {
|
||||
const api: any = ordersApi as any;
|
||||
const resp = api.getVideoTemplateList ? await api.getVideoTemplateList({ current: 1, pageSize: 1000 }) : { data: [] };
|
||||
const { data = [] } = (resp || {}) as any;
|
||||
return (data || []).map((t: any) => ({ label: t?.templateName || t?.name || String(t?.templateId ?? t?.id), value: String(t?.templateId ?? t?.id) }));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}}
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
<ProFormDigit
|
||||
name="materialCount"
|
||||
label="素材数量"
|
||||
min={1}
|
||||
rules={[{ required: true, message: '请输入素材数量' }]}
|
||||
fieldProps={{ precision: 0 }}
|
||||
placeholder="请输入素材数量"
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
{/* 其他设置 */}
|
||||
{/* 功能开关 */}
|
||||
<ProFormSelect
|
||||
name="enableVideoEdit"
|
||||
label="开启一键成片"
|
||||
label="一键成片"
|
||||
options={[
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
@@ -182,15 +208,15 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
name="qrcodeType"
|
||||
label="二维码类型"
|
||||
options={[
|
||||
{ label: '游客下单', value: 1 },
|
||||
{ label: '定时巡查', value: 2 },
|
||||
{ label: '其他', value: 3 },
|
||||
{ label: '游客扫码', value: 1 },
|
||||
{ label: '临时扫码', value: 2 },
|
||||
{ label: '自定义', value: 3 },
|
||||
]}
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="showVideoEditOnly"
|
||||
label="只显示一键成片"
|
||||
label="仅显示一键成片"
|
||||
options={[
|
||||
{ label: '否', value: 0 },
|
||||
{ label: '是', value: 1 },
|
||||
@@ -198,10 +224,112 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
{/* 数量统计 */}
|
||||
{/* 统计项 */}
|
||||
<ProFormDigit name="vlogCount" label="Vlog数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||
<ProFormDigit name="videoCount" label="视频数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||
<ProFormDigit name="photoCount" label="照片数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||
<ProFormDigit name="photoCount" label="图片数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||
|
||||
<ProFormDigit
|
||||
name="materialCount"
|
||||
label="素材数量"
|
||||
min={1}
|
||||
rules={[{ required: true, message: '请输入素材数量' }]}
|
||||
fieldProps={{ precision: 0 }}
|
||||
placeholder="请输入素材数量"
|
||||
colProps={{ span: 12 }}
|
||||
/>
|
||||
|
||||
{/* 注册一个隐藏字段以提交素材ID数组 */}
|
||||
<ProForm.Item name="tourismFileIds" hidden>
|
||||
<div />
|
||||
</ProForm.Item>
|
||||
|
||||
{/* 景区素材(移除查询条件;支持多选;无上限;保留“全部选择/取消全选”) */}
|
||||
<ProForm.Item label="景区素材" shouldUpdate>
|
||||
{({ getFieldValue, setFieldsValue }) => {
|
||||
const selected: number[] = getFieldValue('tourismFileIds') || [];
|
||||
const typeName = (t: any) => (t === 2 ? '视频' : t === 1 ? '图片' : '其他');
|
||||
if (!tourismIdForFetch) {
|
||||
return <div style={{ color: '#999' }}>请选择景区后加载素材</div>;
|
||||
}
|
||||
|
||||
// 不再提供筛选与上限;全量展示可选择
|
||||
const list = tourismFiles || [];
|
||||
|
||||
const onToggle = (id: number) => {
|
||||
const exists = selected.includes(id);
|
||||
setFieldsValue?.({ tourismFileIds: exists ? selected.filter((x) => x !== id) : [...selected, id] });
|
||||
};
|
||||
|
||||
const selectAll = () => {
|
||||
const ids = (list.map((f: any) => f?.id).filter(Boolean) as number[]);
|
||||
const next = Array.from(new Set(ids));
|
||||
setFieldsValue?.({ tourismFileIds: next });
|
||||
};
|
||||
|
||||
const clearAll = () => setFieldsValue?.({ tourismFileIds: [] });
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* 仅保留“全部选择 / 取消全选” */}
|
||||
<div style={{ display: 'flex', gap: 12, alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ flex: 1 }} />
|
||||
<button type="button" onClick={selectAll} style={{ padding: '4px 10px', border: '1px solid #1677ff', background: '#1677ff', color: '#fff', borderRadius: 4, cursor: 'pointer' }}>全部选择</button>
|
||||
<button type="button" onClick={clearAll} style={{ padding: '4px 10px', border: '1px solid #d9d9d9', background: '#fff', color: '#333', borderRadius: 4, cursor: 'pointer' }}>取消全选</button>
|
||||
</div>
|
||||
|
||||
{/* 统计信息 */}
|
||||
<div style={{ marginBottom: 8, fontSize: 12, color: '#666' }}>
|
||||
已选 {selected.length} 个;共 {list.length} 个
|
||||
</div>
|
||||
|
||||
{/* 网格容器:自适应列 + 滚动 */}
|
||||
<div style={{ maxHeight: 420, overflow: 'auto', padding: 8, background: '#fafafa', border: '1px solid #f0f0f0', borderRadius: 6 }}>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))', gap: 12 }}>
|
||||
{list.map((f: any) => {
|
||||
const id = f?.id;
|
||||
const url = f?.imageUrl || f?.linkUrl || f?.url;
|
||||
const isSel = selected.includes(id);
|
||||
return (
|
||||
<div
|
||||
key={id}
|
||||
onClick={() => onToggle(id)}
|
||||
style={{
|
||||
borderWidth: 2,
|
||||
borderStyle: 'solid',
|
||||
borderColor: isSel ? '#1677ff' : '#f0f0f0',
|
||||
borderRadius: 6,
|
||||
cursor: 'pointer',
|
||||
background: '#fff',
|
||||
boxShadow: isSel ? '0 0 0 2px rgba(22,119,255,0.1) inset' : 'none',
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<div style={{ position: 'relative', width: '100%', aspectRatio: '4 / 3', background: '#fafafa', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
{url ? (
|
||||
<img src={url} alt={'素材-' + id} style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
||||
) : (
|
||||
<div style={{ fontSize: 12, color: '#999' }}>无图片</div>
|
||||
)}
|
||||
{isSel ? (
|
||||
<div style={{ position: 'absolute', top: 6, right: 6, width: 18, height: 18, borderRadius: '50%', background: '#1677ff' }} />
|
||||
) : null}
|
||||
</div>
|
||||
<div style={{ padding: '6px 8px', fontSize: 12, color: '#555', display: 'flex', justifyContent: 'space-between' }}>
|
||||
<span>ID:{id}</span>
|
||||
<span style={{ color: '#888' }}>{typeName(f?.type)}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</ProForm.Item>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user