import React, { useEffect, useState } from 'react'; import { Space, Table, Button, Input, Select, DatePicker, Tabs, message, Typography, Spin } from 'antd'; import type { TableProps } from 'antd'; import dayjs, { Dayjs } from 'dayjs'; import styles from './index.module.css'; import PunlishPlanModal from './components/publishPlanModal'; const { RangePicker } = DatePicker; import { useAccountOptions } from '@src/views/publishContent/weGZH/hooks/useAccountOptions'; import { useGzhPlanList, GzhPlanDataType, GzhPlanType } from '@src/views/publishContent/weGZH/hooks/useGzhPlanList'; import http from '@src/http'; import { deleteGzhPlanApi, saveGzhPlanApi } from '@src/http/api'; import PunlishPlanDetailModal from './components/PunlishPlanDetailModal'; const TableHeight = window.innerHeight - 380; const WeGZHContent: React.FC = () => { const [planType, setPlanType] = useState(GzhPlanType.自动回复); // 状态管理 const [selectedAccount, setSelectedAccount] = useState(); const [videoTitle, setVideoTitle] = useState(''); const [selectedPublisher, setSelectedPublisher] = useState(); const [dateRange, setDateRange] = useState<[Dayjs | null, Dayjs | null]>(); const [isShowAddPunlishPlan, setIsShowAddPunlishPlan] = useState(false); const [actionType, setActionType] = useState<'add' | 'edit'>('add'); const [editPlanData, setEditPlanData] = useState(); const [selectVideoType, setSelectVideoType] = useState(); const [isSubmiting, setIsSubmiting] = useState(false); const [isLoading, setIsLoading] = useState(false); const { accountOptions, getAccountList } = useAccountOptions(); const { gzhPlanList, getGzhPlanList, totalSize } = useGzhPlanList(); const [pageNum, setPageNum] = useState(1); const [isShowAddPunlishDetailPlan, setIsShowAddPunlishDetailPlan] = useState(false); // 表格列配置 const columns: TableProps['columns'] = [ { title: '公众号名称', dataIndex: 'accountName', key: 'accountName', width: 160, }, { title: '发布方式', dataIndex: 'publishStage', key: 'publishStage', width: 120, render: (_, record) => { return record.publishStage === 0 ? '平台发布' : '用户获取路径'; } }, { title: '视频选取方式', dataIndex: 'selectVideoType', key: 'selectVideoType', width: 120, render: (_, record) => { return record.selectVideoType === 0 ? '手动选取' : '自动选取'; } }, { title: '发布场景', dataIndex: 'scene', key: 'scene', width: 120, render: (_, record) => { return record.scene === 0 ? '关注回复' : '自动回复'; } }, { title: '视频数量', dataIndex: 'videoCount', key: 'videoCount', width: 100, }, { title: '视频标题', dataIndex: 'title', key: 'title', ellipsis: true, render: (_, record) => { return record?.videoList?.map(video => { return {video.customTitle || video.title} }) } }, { title: '计划创建时间', dataIndex: 'createTimestamp', key: 'createTimestamp', width: 200, render: (_, record) => { return record.createTimestamp ? dayjs(record.createTimestamp).format('YYYY-MM-DD HH:mm:ss') : ''; } }, { title: '操作', key: 'action', fixed: 'right', render: (_, record) => ( ), }, ]; const cloumns2: TableProps['columns'] = columns.filter(item => item.title !== '发布场景'); const deletePlan = async (record: GzhPlanDataType) => { setIsLoading(true); const res = await http.post(deleteGzhPlanApi, { id: record.id, }).catch(err => { message.error(err?.msg || '删除失败'); }) if (res?.code === 0) { message.success('删除成功'); getGzhPlanList({ type: planType, pageNum: 1, pageSize: 10, selectVideoType: selectVideoType, }); } else { message.error(res?.msg || '删除失败'); } setIsLoading(false); } const editPlan = (record: GzhPlanDataType) => { setEditPlanData(record); setActionType('edit'); setIsShowAddPunlishPlan(true); }; const editPlanDetail = (record: GzhPlanDataType) => { setEditPlanData(record); setActionType('edit'); setIsShowAddPunlishDetailPlan(true); } const addPunlishPlan = () => { setActionType('add'); setEditPlanData(undefined); setIsShowAddPunlishPlan(true); } const handleAddPunlishPlan = async (params: GzhPlanDataType) => { setIsSubmiting(true); if (params.type !== planType) { setPlanType(params.type as GzhPlanType); } const res = await http.post(saveGzhPlanApi, params) .catch(err => { message.error(err.msg); }) .finally(() => { setIsSubmiting(false); }); if (res?.code === 0) { message.success('发布计划创建成功'); getGzhPlanList({ type: params.type, pageNum: 1, pageSize: 10, }); setIsShowAddPunlishPlan(false); } else { message.error(res?.msg); } } useEffect(() => { setSelectedAccount(undefined); setVideoTitle(''); setSelectedPublisher(undefined); setSelectVideoType(undefined); setDateRange(undefined); setPageNum(1); getAccountList({ accountType: planType }); getGzhPlanList({ type: planType, pageNum: 1, pageSize: 10, }); }, [planType]); const handleSearch = () => { getGzhPlanList({ pageNum: 1, pageSize: 10, title: videoTitle, type: planType, accountId: selectedAccount ? parseInt(selectedAccount) : undefined, publishStage: selectedPublisher, selectVideoType: selectVideoType, createTimestampStart: dateRange?.[0]?.unix() ? dateRange[0].unix() * 1000 : undefined, createTimestampEnd: dateRange?.[1]?.unix() ? dateRange[1].unix() * 1000 : undefined, }); } return (
公众号内容
{/* 搜索区域 */}
{ planType === GzhPlanType.自动回复 ? '公众号名称' : '服务号名称' }: setVideoTitle(e.target.value)} />
发布方式:
{ setDateRange(dates || undefined); }} />
setPlanType(key as GzhPlanType)} tabBarExtraContent={ { right: }} /> {/* 表格区域 */} record.id} className={styles.antTable} columns={planType === GzhPlanType.自动回复 ? columns : cloumns2} dataSource={gzhPlanList} scroll={{ x: 'max-content', y: TableHeight }} pagination={{ total: totalSize, pageSize: 10, current: pageNum, showTotal: (total) => `共 ${total} 条`, onChange: (page) => getGzhPlanList({ pageNum: page, pageSize: 10, title: videoTitle, type: planType, selectVideoType: selectVideoType, accountId: selectedAccount ? parseInt(selectedAccount) : undefined, publishStage: selectedPublisher, createTimestampStart: dateRange?.[0]?.unix() ? dateRange[0].unix() * 1000 : undefined, createTimestampEnd: dateRange?.[1]?.unix() ? dateRange[1].unix() * 1000 : undefined, }), }} /> { setEditPlanData(undefined); setIsShowAddPunlishPlan(false); }} onOk={handleAddPunlishPlan} actionType={actionType} editPlanData={editPlanData} isSubmiting={isSubmiting} planType={ planType} /> { setEditPlanData(undefined); setIsShowAddPunlishDetailPlan(false); }} planData={editPlanData as GzhPlanDataType} /> ); }; export default WeGZHContent;