| 1 | import React, { ForwardedRef, forwardRef, memo, useMemo } from 'react'; |
| 2 | import VideoCoverSeting from '@/views/publish/children/videoPage/components/VideoCoverSeting'; |
| 3 | import { Input, Tooltip } from 'antd'; |
| 4 | import { ExclamationCircleOutlined } from '@ant-design/icons'; |
| 5 | import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore'; |
| 6 | import { useShallow } from 'zustand/react/shallow'; |
| 7 | import { ScheduledTimeSelect } from './VideoPubSetModal/components/VideoPubSetModalCommon'; |
| 8 | import { |
| 9 | AccountPlatInfoMap, |
| 10 | IAccountPlatInfo, |
| 11 | } from '../../../../account/comment'; |
| 12 | import { PlatType } from '../../../../../../commont/AccountEnum'; |
| 13 | import AICreateTitle from '../../../components/AICreateTitle/AICreateTitle'; |
| 14 | import { AiCreateType } from '../../../../../api/types/tools'; |
| 15 | |
| 16 | const { TextArea } = Input; |
| 17 | |
| 18 | export interface ICommonPubSettingRef {} |
| 19 | |
| 20 | export interface ICommonPubSettingProps {} |
| 21 | |
| 22 | // 通用参数设置组件 |
| 23 | const CommonPubSetting = memo( |
| 24 | forwardRef( |
| 25 | ({}: ICommonPubSettingProps, ref: ForwardedRef<ICommonPubSettingRef>) => { |
| 26 | const { |
| 27 | setPubParams, |
| 28 | videoListChoose, |
| 29 | setVideoCoverFirst, |
| 30 | commonPubParams, |
| 31 | } = useVideoPageStore( |
| 32 | useShallow((state) => ({ |
| 33 | setPubParams: state.setPubParams, |
| 34 | videoListChoose: state.videoListChoose, |
| 35 | setVideoCoverFirst: state.setVideoCoverFirst, |
| 36 | commonPubParams: state.commonPubParams, |
| 37 | })), |
| 38 | ); |
| 39 | |
| 40 | // 获取选择的账户的所有相关平台 |
| 41 | const getChoosedAccountPlatList = useMemo(() => { |
| 42 | const platMap = new Map<PlatType, IAccountPlatInfo>(); |
| 43 | videoListChoose.map((v) => { |
| 44 | if (v.account) { |
| 45 | platMap.set( |
| 46 | v.account.type, |
| 47 | AccountPlatInfoMap.get(v.account.type)!, |
| 48 | ); |
| 49 | } |
| 50 | }); |
| 51 | return Array.from(platMap.values()); |
| 52 | }, [videoListChoose]); |
| 53 | |
| 54 | // 所有平台通用发布参数的最大值获取,做为默认值 |
| 55 | const getPlatCommonParamsMax = useMemo(() => { |
| 56 | const platList = Array.from(AccountPlatInfoMap.values()); |
| 57 | |
| 58 | const maxValue = (getValue: (v: any) => number) => |
| 59 | Math.max(...platList.map((v) => getValue(v) || -Infinity)); |
| 60 | |
| 61 | return { |
| 62 | maxDate: maxValue((v) => v.commonPubParamsConfig.timingMax?.maxDate), |
| 63 | timeOffset: maxValue( |
| 64 | (v) => v.commonPubParamsConfig.timingMax?.timeOffset, |
| 65 | ), |
| 66 | titleMax: maxValue((v) => v.commonPubParamsConfig.titleMax), |
| 67 | }; |
| 68 | }, [AccountPlatInfoMap]); |
| 69 | |
| 70 | return ( |
| 71 | <div className="commonPubSetting"> |
| 72 | <h1>通用发布设置</h1> |
| 73 | <p className="commonPubSetting-tip"> |
| 74 | 通用设置中的参数将会应用于所有账号 |
| 75 | </p> |
| 76 | <h2>通用封面</h2> |
| 77 | <VideoCoverSeting |
| 78 | videoFile={videoListChoose.find((v) => v.video)?.video} |
| 79 | value={commonPubParams.cover} |
| 80 | saveImgId="common" |
| 81 | onClose={() => { |
| 82 | setPubParams({ |
| 83 | cover: undefined, |
| 84 | }); |
| 85 | setVideoCoverFirst(true); |
| 86 | }} |
| 87 | onChoosed={(imgFile) => { |
| 88 | setPubParams({ |
| 89 | cover: imgFile, |
| 90 | }); |
| 91 | }} |
| 92 | /> |
| 93 | <p className="commonPubSetting-tip"> |
| 94 | 支持常用图片格式上传,暂不支持 GIF,上传后图片将按平台要求自动裁剪 |
| 95 | </p> |
| 96 | <p className="commonPubSetting-tip"> |
| 97 | 未上传任何图片的情况下,默认选择视频第一帧。 |
| 98 | </p> |
| 99 | |
| 100 | <h2> |
| 101 | 标题 |
| 102 | <Tooltip |
| 103 | title={ |
| 104 | <div> |
| 105 | {Array.from(AccountPlatInfoMap.values()).map((platInfo) => { |
| 106 | const titleMax = platInfo.commonPubParamsConfig.titleMax; |
| 107 | return ( |
| 108 | <p key={platInfo.name}> |
| 109 | <b>{platInfo.name}</b> |
| 110 | {!titleMax |
| 111 | ? `没有标题参数` |
| 112 | : `标题字数限制${titleMax}字`} |
| 113 | </p> |
| 114 | ); |
| 115 | })} |
| 116 | </div> |
| 117 | } |
| 118 | > |
| 119 | <ExclamationCircleOutlined /> |
| 120 | </Tooltip> |
| 121 | </h2> |
| 122 | <Input |
| 123 | showCount |
| 124 | value={commonPubParams.title} |
| 125 | maxLength={Math.min( |
| 126 | getPlatCommonParamsMax.titleMax, |
| 127 | ...getChoosedAccountPlatList.map( |
| 128 | (v) => v.commonPubParamsConfig.titleMax || 30, |
| 129 | ), |
| 130 | )} |
| 131 | placeholder="请输入视频标题" |
| 132 | variant="filled" |
| 133 | onChange={(e) => { |
| 134 | setPubParams({ |
| 135 | title: e.target.value, |
| 136 | }); |
| 137 | }} |
| 138 | /> |
| 139 | <AICreateTitle |
| 140 | type={AiCreateType.TITLE} |
| 141 | tips="在通用发布参数会选择第一个视频作为生成标题的对象" |
| 142 | onAiCreateFinish={(text) => { |
| 143 | setPubParams({ |
| 144 | title: text, |
| 145 | }); |
| 146 | }} |
| 147 | videoFile={videoListChoose[0]?.video} |
| 148 | max={Math.min( |
| 149 | getPlatCommonParamsMax.titleMax, |
| 150 | ...getChoosedAccountPlatList.map( |
| 151 | (v) => v.commonPubParamsConfig.titleMax || 30, |
| 152 | ), |
| 153 | )} |
| 154 | /> |
| 155 | |
| 156 | <h2>描述</h2> |
| 157 | <TextArea |
| 158 | placeholder="请输入视频描述" |
| 159 | variant="filled" |
| 160 | showCount |
| 161 | maxLength={500} |
| 162 | value={commonPubParams.describe} |
| 163 | style={{ height: 200, resize: 'none' }} |
| 164 | onChange={(e) => { |
| 165 | setPubParams({ |
| 166 | describe: e.target.value, |
| 167 | }); |
| 168 | }} |
| 169 | /> |
| 170 | <AICreateTitle |
| 171 | type={AiCreateType.DESC} |
| 172 | tips="在通用发布参数会选择第一个视频作为生成描述的对象" |
| 173 | onAiCreateFinish={(text) => { |
| 174 | setPubParams({ |
| 175 | describe: text, |
| 176 | }); |
| 177 | }} |
| 178 | videoFile={videoListChoose[0]?.video} |
| 179 | max={500} |
| 180 | /> |
| 181 | <p className="commonPubSetting-tip"> |
| 182 | 描述中可带话题,以‘#’开头、‘空格’结尾, |
| 183 | <Tooltip title="更多详情中单独设置的话题和描述中带的话题都是有效的,发布时将合并去重处理"> |
| 184 | <span style={{ color: 'rgb(250, 173, 20)' }}> |
| 185 | <ExclamationCircleOutlined style={{ marginRight: '3px' }} /> |
| 186 | 发布时 |
| 187 | </span> |
| 188 | </Tooltip> |
| 189 | 将根据平台自动处理 如:这是一段文字描述#最美中国 #夏日穿搭 |
| 190 | </p> |
| 191 | |
| 192 | <h2> |
| 193 | 定时发布 |
| 194 | <Tooltip |
| 195 | styles={{ |
| 196 | root: { |
| 197 | maxWidth: 'none', |
| 198 | }, |
| 199 | }} |
| 200 | title={ |
| 201 | <div> |
| 202 | {Array.from(AccountPlatInfoMap.values()).map((platInfo) => { |
| 203 | const timingMax = platInfo.commonPubParamsConfig.timingMax; |
| 204 | return ( |
| 205 | <p key={platInfo.name}> |
| 206 | <b>{platInfo.name}</b> |
| 207 | {!timingMax |
| 208 | ? `没有定时发布参数;` |
| 209 | : `支持${timingMax.timeOffset}分钟后及${timingMax.maxDate}天内的定时发布;`} |
| 210 | </p> |
| 211 | ); |
| 212 | })} |
| 213 | </div> |
| 214 | } |
| 215 | > |
| 216 | <ExclamationCircleOutlined /> |
| 217 | </Tooltip> |
| 218 | </h2> |
| 219 | <ScheduledTimeSelect |
| 220 | maxDate={Math.min( |
| 221 | getPlatCommonParamsMax.maxDate, |
| 222 | ...getChoosedAccountPlatList.map( |
| 223 | (v) => v.commonPubParamsConfig.timingMax?.maxDate || Infinity, |
| 224 | ), |
| 225 | )} |
| 226 | timeOffset={Math.min( |
| 227 | getPlatCommonParamsMax.timeOffset, |
| 228 | ...getChoosedAccountPlatList.map( |
| 229 | (v) => |
| 230 | v.commonPubParamsConfig.timingMax?.timeOffset || Infinity, |
| 231 | ), |
| 232 | )} |
| 233 | onChange={(e) => { |
| 234 | setPubParams({ |
| 235 | timingTime: e ? e.toDate() : undefined, |
| 236 | }); |
| 237 | }} |
| 238 | /> |
| 239 | </div> |
| 240 | ); |
| 241 | }, |
| 242 | ), |
| 243 | ); |
| 244 | CommonPubSetting.displayName = 'CommonPubSetting'; |
| 245 | |
| 246 | export default CommonPubSetting; |
| 247 |