feat: 二维码新增或者编辑绑定景区素材
This commit is contained in:
@@ -51,7 +51,7 @@ const QrcodeForm: React.FC<QrcodeFormProps> = ({ open, title, initialValues, onO
|
||||
<ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入名称' }]} />
|
||||
<ProFormText name="url" label="地址" />
|
||||
<ProFormSelect name="type" label="类型" valueEnum={{ 1: '类型一', 2: '类型二' }} />
|
||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
|
||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '禁用', 0: '启用' }} initialValue={1} />
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import { Modal, Popconfirm, Space, Tag, message, Button } from 'antd';
|
||||
import { ProTable, type ActionType } from '@ant-design/pro-components';
|
||||
import { GradientButton } from '@/components/ui';
|
||||
@@ -23,11 +23,10 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
const [previewImage, setPreviewImage] = useState<string>('');
|
||||
|
||||
// 模板ID -> 模板名称(通过接口懒加载)
|
||||
const templateNameMapRef = useRef<Record<string, string>>({});
|
||||
const templateNameMapRef = useRef<Record<string, string>>({});
|
||||
const templateInflightRef = useRef<Record<string, Promise<any>>>({});
|
||||
const [tplTick, setTplTick] = useState(0); // 用于触发渲染
|
||||
|
||||
const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${tourismName})` : ''}`, [tourismName]);
|
||||
const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${tourismName})` : ''}`, [tourismName]);
|
||||
|
||||
const ensureTemplateName = (tplId?: string) => {
|
||||
if (!tplId) return '-';
|
||||
@@ -117,8 +116,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
return (
|
||||
<img
|
||||
src={url}
|
||||
alt="二维码"
|
||||
style={{ width: 60, height: 60, cursor: 'pointer', objectFit: 'contain' }}
|
||||
alt="二维码" style={{ width: 60, height: 60, cursor: 'pointer', objectFit: 'contain' }}
|
||||
onClick={() => {
|
||||
setPreviewImage(url);
|
||||
setPreviewOpen(true);
|
||||
@@ -143,7 +141,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '启用' : '禁用'}</Tag>,
|
||||
render: (v: number) => <Tag color={v === 0 ? 'green' : 'red'}>{v === 0 ? '启用' : '禁用'}</Tag>,
|
||||
},
|
||||
{
|
||||
title: '模板名称',
|
||||
@@ -188,13 +186,20 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
render: (_: any, record: QrcodeItem) => (
|
||||
<Space>
|
||||
<a
|
||||
onClick={() => {
|
||||
setCurrent(record);
|
||||
setEditOpen(true);
|
||||
}}
|
||||
onClick={async () => {
|
||||
try {
|
||||
const plans = await ordersApi.getPackagePlanByCode(record.codeId as any);
|
||||
const plan: any = Array.isArray(plans) && plans.length > 0 ? plans[0] : {};
|
||||
const tourismFileIds = plan.tourismFileIds ? String(plan.tourismFileIds).split(',').filter(Boolean).map((x: any) => Number(x)) : [];
|
||||
setCurrent({ ...record, vlogCount: plan.vlogCount, videoCount: plan.videoCount, photoCount: plan.photoCount, tourismFileIds });
|
||||
} catch {
|
||||
setCurrent(record);
|
||||
}
|
||||
setEditOpen(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>
|
||||
</a>
|
||||
<Popconfirm
|
||||
title={`确认删除二维码【${record.name}】?`}
|
||||
onConfirm={async () => {
|
||||
@@ -241,8 +246,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
{/* 新增/编辑表单:仅在打开时才挂载,避免列表页触发内部副作用 */}
|
||||
{createOpen && (
|
||||
<QrcodeTourismForm
|
||||
title="新增二维码"
|
||||
open={createOpen}
|
||||
title="新增二维码" open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('提交中...');
|
||||
@@ -271,8 +275,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
|
||||
{editOpen && (
|
||||
<QrcodeTourismForm
|
||||
title="编辑二维码"
|
||||
open={editOpen}
|
||||
title="编辑二维码" open={editOpen}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('提交中...');
|
||||
@@ -296,6 +299,7 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
defaultTourismId={tourismId}
|
||||
initialValues={current}
|
||||
/>
|
||||
)}
|
||||
@@ -310,4 +314,6 @@ const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, t
|
||||
);
|
||||
};
|
||||
|
||||
export default QrcodeListModal;
|
||||
export default QrcodeListModal;
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface QrcodeTourismFormProps {
|
||||
const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, initialValues, onOpenChange, onFinish, defaultTourismId }) => {
|
||||
// 统一默认值,解决新增/编辑缺省字段问题
|
||||
const DEFAULTS: Partial<QrcodeItem> = {
|
||||
status: 0, // 状态:0=禁用 1=启用
|
||||
status: 0, // 状态:0=启用1=禁用
|
||||
enableVideoEdit: 0, // 是否开启一键成片:0=否 1=是
|
||||
isTest: 0, // 是否测试二维码:0=否 1=是
|
||||
qrcodeType: 1, // 二维码类型:1=游客扫码 2=临时扫码 3=自定义
|
||||
@@ -157,7 +157,7 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
|
||||
<ProFormDigit
|
||||
name="price"
|
||||
label="价格(元)"
|
||||
label="价格(分)"
|
||||
min={0}
|
||||
rules={[{ required: true, message: '请输入价格' }]}
|
||||
fieldProps={{ precision: 0 }}
|
||||
@@ -170,8 +170,8 @@ 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 }}
|
||||
/>
|
||||
@@ -344,3 +344,4 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
|
||||
};
|
||||
|
||||
export default QrcodeTourismForm;
|
||||
|
||||
|
||||
@@ -277,17 +277,11 @@ export const ordersApi = {
|
||||
const res = await request('/api-order/coupon/update-expired', { method: 'POST' });
|
||||
return (res as any).data || res;
|
||||
},
|
||||
getPackagePlanByCode: async (codeId: string) => {
|
||||
const res = await request('/api-order/package/byCode/' + codeId, { method: 'GET' });
|
||||
const list = ((res as any)?.data ?? (res as any)) as any[];
|
||||
return Array.isArray(list) ? list : [];
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user