Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(发布弹框): 发布API接入完成
gaoSirddca6721815a
diff --git a/.idea/workspace.xml b/.idea/workspace.xmlindex 2e420d99..07931109 100644--- a/.idea/workspace.xml+++ b/.idea/workspace.xml@@ -4,19 +4,15 @@<option name="autoReloadType" value="SELECTIVE" /></component><component name="ChangeListManager">- <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat: 发布记录展示添加状态展示">- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />+ <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(发布弹框): 上传图片和上传视频完成"><change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/api/plat/publish.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/plat/publish.ts" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/api/plat/types/publish.types.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/plat/types/publish.types.ts" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/api/tools.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/tools.ts" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/index.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsx" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/components/PublishDialog/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/index.tsx" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/components/PublishDialog/publishDialog.type.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/publishDialog.type.ts" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/constant.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/constant.ts" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/utils/FetchService/FetchService.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/FetchService/FetchService.ts" afterDir="false" /></list><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" />@@ -94,7 +90,7 @@<option name="presentableId" value="Default" /><updated>1751977665735</updated><workItem from="1751977666787" duration="3372000" />- <workItem from="1751981060502" duration="13055000" />+ <workItem from="1751981060502" duration="18108000" /></task><task id="LOCAL-00001" summary="feat(CalendarTiming): 优化发布记录列表展示 - 调整日历记录项的样式和布局 - 优化 RecordCore组件,添加平台图标和时间显示 - 修改 CalendarTimingItem 组件,移除不必要的 Fragment -调整 index.tsx 中的日期格式化逻辑"><option name="closed" value="true" />@@ -128,7 +124,15 @@<option name="project" value="LOCAL" /><updated>1752049408523</updated></task>- <option name="localTasksCounter" value="5" />+ <task id="LOCAL-00005" summary="feat(发布弹框): 上传图片和上传视频完成">+ <option name="closed" value="true" />+ <created>1752057751552</created>+ <option name="number" value="00005" />+ <option name="presentableId" value="LOCAL-00005" />+ <option name="project" value="LOCAL" />+ <updated>1752057751552</updated>+ </task>+ <option name="localTasksCounter" value="6" /><servers /></component><component name="TypeScriptGeneratedFilesManager">@@ -141,6 +145,7 @@<MESSAGE value="feat(CalendarTiming): 优化发布记录列表展示 - 调整日历记录项的样式和布局 - 优化 RecordCore组件,添加平台图标和时间显示 - 调整 index.tsx 中的日期格式化逻辑" /><MESSAGE value="fix: platInfo添加一些非空判断" /><MESSAGE value="feat: 发布记录展示添加状态展示" />- <option name="LAST_COMMIT_MESSAGE" value="feat: 发布记录展示添加状态展示" />+ <MESSAGE value="feat(发布弹框): 上传图片和上传视频完成" />+ <option name="LAST_COMMIT_MESSAGE" value="feat(发布弹框): 上传图片和上传视频完成" /></component></project>\ No newline at end of filediff --git a/src/api/plat/publish.ts b/src/api/plat/publish.tsindex 4432c1b1..e8356de1 100644--- a/src/api/plat/publish.ts+++ b/src/api/plat/publish.ts@@ -2,8 +2,7 @@import { request } from "@/utils/request";import {GetPublishListParams,- PublishListResponse,- PublishParams,+ PublishParams, PublishRecordItem} from "@/api/plat/types/publish.types";import { parseTopicString } from "@/utils";@@ -22,7 +21,7 @@ export const apiCreatePublish = (data: PublishParams) => {// 查询发布列表export const getPublishList = (data: GetPublishListParams) => {- return request<PublishListResponse>({+ return request<PublishRecordItem[]>({url: "/plat/publish/getList",method: "POST",data,diff --git a/src/api/plat/types/publish.types.ts b/src/api/plat/types/publish.types.tsindex c38f134a..c2e09348 100644--- a/src/api/plat/types/publish.types.ts+++ b/src/api/plat/types/publish.types.ts@@ -29,15 +29,11 @@ export interface PublishParams {// 查询发布列表入参export interface GetPublishListParams {- filter?: {- accountId?: string;- accountType?: PlatType;- type?: PubType;- status?: PublishStatus;- time?: [Date, Date];- };- pageNo: number;- pageSize: number;+ accountId?: string;+ accountType?: PlatType;+ type?: PubType;+ status?: PublishStatus;+ time?: [string, string];}// 发布记录item数据@@ -59,9 +55,3 @@ export interface PublishRecordItem {errorMsg: string;option: any;}--// 发布记录返回值-export interface PublishListResponse {- totalCount: number;- list: PublishRecordItem[];-}diff --git a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx b/src/app/[lng]/accounts/components/CalendarTiming/index.tsxindex b3027c5c..5575dd00 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/index.tsx@@ -29,6 +29,9 @@ import { useCalendarTiming } from "@/app/[lng]/accounts/components/CalendarTiminimport { getPublishList } from "@/api/plat/publish";import { PublishRecordItem } from "@/api/plat/types/publish.types";import dayjs from "dayjs";+import utc from "dayjs/plugin/utc";++dayjs.extend(utc);export interface ICalendarTimingRef {}export interface ICalendarTimingProps {}@@ -87,41 +90,45 @@ const CalendarTiming = memo(}, []);// 获取发布记录数据- const getPubRecord = async () => {- setListLoading(true);- const res = await getPublishList({- pageNo: 1,- pageSize: 500,- filter: {},- });- setListLoading(false);- if (!res) return;- const recordMap = new Map<string, PublishRecordItem[]>();- // 将数据分拣到对应天中- res?.data.list.map((v) => {- const days = dayjs(v.publishTime);- const timeStr = days.format("YYYY-MM-DD");- let list = recordMap.get(timeStr);- if (!list) {- list = [];+ const getPubRecord = () => {+ setTimeout(async () => {+ setListLoading(true);+ const date = dayjs(calendarRef.current?.getApi().getDate());+ const startOfMonth = date.startOf("month");+ const endOfMonth = date.endOf("month");++ const res = await getPublishList({+ time: [startOfMonth.utc().format(), endOfMonth.utc().format()],+ });+ setListLoading(false);+ if (!res) return;+ const recordMap = new Map<string, PublishRecordItem[]>();+ // 将数据分拣到对应天中+ res?.data.map((v) => {+ const days = dayjs(v.publishTime);+ const timeStr = days.format("YYYY-MM-DD");+ let list = recordMap.get(timeStr);+ if (!list) {+ list = [];+ recordMap.set(timeStr, list);+ }+ list.push(v);recordMap.set(timeStr, list);- }- list.push(v);- recordMap.set(timeStr, list);- });- // 对每一天的记录按照 publishTime 时间从早到晚排序- recordMap.forEach((v, k) => {- let list = recordMap.get(k);- if (list) {- list = list.sort(- (a, b) =>- new Date(a.publishTime).getTime() -- new Date(b.publishTime).getTime(),- );- recordMap.set(k, list);- }- });- setRecordMap(recordMap);+ });+ // 对每一天的记录按照 publishTime 时间从早到晚排序+ recordMap.forEach((v, k) => {+ let list = recordMap.get(k);+ if (list) {+ list = list.sort(+ (a, b) =>+ new Date(a.publishTime).getTime() -+ new Date(b.publishTime).getTime(),+ );+ recordMap.set(k, list);+ }+ });+ setRecordMap(recordMap);+ }, 10);};// 处理窗口大小变化@@ -149,6 +156,7 @@ const CalendarTiming = memo(setTimeout(() => {calendarRef.current?.getApi().prev();setAnimating(false);+ getPubRecord();}, 300);};const handleNext = () => {@@ -156,15 +164,16 @@ const CalendarTiming = memo(setTimeout(() => {calendarRef.current?.getApi().next();setAnimating(false);+ getPubRecord();}, 300);};-// 点击Today按钮时const handleToday = () => {triggerAnimation("fade");setTimeout(() => {calendarRef.current?.getApi().today();setAnimating(false);+ getPubRecord();}, 300);};@@ -174,6 +183,9 @@ const CalendarTiming = memo(ref={publishDialogRef}open={publishDialogOpen}onClose={() => setPublishDialogOpen(false)}+ onPubSuccess={() => {+ getPubRecord();+ }}accounts={accountList}/>diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsxindex 62a62664..5993e39b 100644--- a/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx@@ -57,14 +57,23 @@ const PubParmasTextareaUpload = memo(setUploadCount(1);setUploadProgress(0);setUploadLoading(true);- const uploadRes = await toolsApi.uploadFileTemp(+ // 上传视频+ const uploadVideoRes = await toolsApi.uploadFileTemp(video.file,(prog) => {- setUploadProgress(prog);+ setUploadProgress(prog === 100 ? 99 : prog);},);+ setUploadProgress(100);+ // 上传封面+ const uploadCoverRes = await toolsApi.uploadFileTemp(+ video.cover.file,+ );+setUploadLoading(false);- video["videoOssUrl"] = `${OSS_URL}${uploadRes}`;+ video["ossUrl"] = `${OSS_URL}${uploadVideoRes}`;+ video.cover["ossUrl"] = `${OSS_URL}${uploadCoverRes}`;+onVideoUpdateFinish(video);},[onVideoUpdateFinish],@@ -83,7 +92,7 @@ const PubParmasTextareaUpload = memo(const uploadImgCore = async (image: IImgFile): Promise<IImgFile> => {const uploadRes = await toolsApi.uploadFileTemp(image.file);uploadFinishCount++;- image["videoOssUrl"] = `${OSS_URL}${uploadRes}`;+ image["ossUrl"] = `${OSS_URL}${uploadRes}`;setUploadProgress(Math.floor((uploadFinishCount / fileList.length) * 100),);diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsxindex 9d04ed5b..ee593058 100644--- a/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsx+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/VideoCoverSeting.tsx@@ -19,6 +19,8 @@ import {IVideoFile,} from "@/components/PublishDialog/publishDialog.type";import ImgChoose from "@/components/PublishDialog/compoents/Choose/ImgChoose";+import { toolsApi } from "@/api/tools";+import { OSS_URL } from "@/constant";export interface IVideoCoverSetingRef {}@@ -55,6 +57,7 @@ const VideoCoverSeting = memo(const cropperImg = useRef<HTMLImageElement>(null);const [videoCoverLoading, setVideoCoverLoading] = useState(false);const [sliderVal, setSliderVal] = useState(0);+ const [uploadLoing, setUploadLoing] = useState(false);useEffect(() => {if (!videoCoverSetingModal) return;@@ -115,17 +118,35 @@ const VideoCoverSeting = memo(maskClosable={false}open={videoCoverSetingModal}onCancel={close}- onOk={async () => {- const canvas = cropper.current!.getCroppedCanvas();- canvas.toBlob(async function (blob) {- const cover = await formatImg({- blob: blob!,- path: `${saveImgId}.${imgFile?.file.type.split("/")[1]}`,- });- onChoosed(cover);- close();- }, "image/png");- }}+ footer={+ <>+ <Button onClick={close}>取消</Button>+ <Button+ loading={uploadLoing}+ type="primary"+ onClick={async () => {+ setUploadLoing(true);+ const canvas = cropper.current!.getCroppedCanvas();+ canvas.toBlob(async function (blob) {+ const cover = await formatImg({+ blob: blob!,+ path: `${saveImgId}.${imgFile?.file.type.split("/")[1]}`,+ });+ // 上传封面+ const uploadCoverRes = await toolsApi.uploadFileTemp(+ cover.file,+ );+ cover["ossUrl"] = `${OSS_URL}${uploadCoverRes}`;+ setUploadLoing(false);+ onChoosed(cover);+ close();+ }, "image/png");+ }}+ >+ 确定+ </Button>+ </>+ }><Spin spinning={videoCoverLoading}><div className={styles.videoCoverSetingModal}>diff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsxindex 7aaf2231..b5a8b3cc 100644--- a/src/components/PublishDialog/index.tsx+++ b/src/components/PublishDialog/index.tsx@@ -39,7 +39,7 @@ export interface IPublishDialogProps {open: boolean;onClose: () => void;accounts: SocialAccount[];- // 发布成功+ // 发布成功事件onPubSuccess?: () => void;}@@ -87,6 +87,7 @@ const PublishDialog = memo(})),);const { errParamsMap } = usePubParamsVerify(pubListChoosed);+ const [createLoading, setCreateLoading] = useState(false);useEffect(() => {if (open) {@@ -131,12 +132,13 @@ const PublishDialog = memo(}, [errParamsMap]);const pubClick = useCallback(async () => {+ setCreateLoading(true);const publishTime = dayjs(pubTime ? pubTime : dayjs().add(6, "minute")).utc().format();for (const item of pubListChoosed) {- await apiCreatePublish({+ const res = await apiCreatePublish({topics: [],flowId: item.account.uid,type: PubType.VIDEO,@@ -144,9 +146,8 @@ const PublishDialog = memo(desc: item.params.des,accountId: item.account.account,accountType: item.account.type,- videoUrl:- "https://v2-zj-bjcm.kwaicdn.com/upic/2025/06/24/09/BMjAyNTA2MjQwOTI3MjlfNDQwMjk3NjY1Nl8xNjc1OTkwOTUzNzBfMl8z_b_Bea472124f75ea09e1483d87c112ede39.mp4?tag=1-1751887066-unknown-0-uqpbdciha7-0f5473b4478e400b&provider=self&clientCacheKey=3xcwhdmk5jcyv8y_b.mp4&di=dfa08272&bp=14944&x-ks-ptid=167599095370&Aecs=172.17.4.195&ocid=100001260&tt=b&ss=vpm",- coverUrl: "https://education.yikart.cn/images/swiper/swiper1.png",+ videoUrl: item.params.video?.ossUrl,+ coverUrl: item.params.video?.cover.ossUrl,publishTime,option: {isAutoPublish: true,@@ -159,7 +160,12 @@ const PublishDialog = memo(},},});+ if (res?.code !== 0) {+ return setCreateLoading(false);+ }}+ onClose();+ setCreateLoading(false);if (onPubSuccess) onPubSuccess();}, [pubListChoosed]);@@ -342,6 +348,7 @@ const PublishDialog = memo(<Buttonsize="large"type="primary"+ loading={createLoading}onClick={() => {for (const [key, errVideoItem] of errParamsMap) {if (errVideoItem) {diff --git a/src/components/PublishDialog/publishDialog.type.ts b/src/components/PublishDialog/publishDialog.type.tsindex a7514feb..780b20a1 100644--- a/src/components/PublishDialog/publishDialog.type.ts+++ b/src/components/PublishDialog/publishDialog.type.ts@@ -14,7 +14,7 @@ export interface IImgFile {// 图片高度height: number;// 前端上传到oss后的url- videoOssUrl: string;+ ossUrl: string;}export interface IVideoFile {@@ -23,7 +23,7 @@ export interface IVideoFile {// 前端临时路径,注意不要存到数据库videoUrl: string;// 前端上传到oss后的url- videoOssUrl: string;+ ossUrl: string;filename: string;// 视频宽度width: number;