Skip to content

Let's use AI to Earn!

feat(日历): 删除任务、修改任务时间接入API,删除任务完成

gaoSir745f6441d5d8
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d5762304..d8deff2c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="fix: 快手授权修改完成,改为任务">
+ <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/app/[lng]/accounts/add/accountAdd.module.scss" beforeDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/add/page.tsx" beforeDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AddAccountModal/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/AddAccountModal/index.tsx" 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/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.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/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -92,7 +94,7 @@
<workItem from="1751981060502" duration="18325000" />
<workItem from="1752112076161" duration="3845000" />
<workItem from="1752118620733" duration="566000" />
- <workItem from="1752130881346" duration="8746000" />
+ <workItem from="1752130881346" duration="11328000" />
</task>
<task id="LOCAL-00001" summary="feat(CalendarTiming): 优化发布记录列表展示&#10;- 调整日历记录项的样式和布局&#10;- 优化 RecordCore组件,添加平台图标和时间显示&#10;- 修改 CalendarTimingItem 组件,移除不必要的 Fragment&#10;-调整 index.tsx 中的日期格式化逻辑">
<option name="closed" value="true" />
@@ -166,7 +168,15 @@
<option name="project" value="LOCAL" />
<updated>1752145461148</updated>
</task>
- <option name="localTasksCounter" value="10" />
+ <task id="LOCAL-00010" summary="feat: 删除不需要的文件">
+ <option name="closed" value="true" />
+ <created>1752146202309</created>
+ <option name="number" value="00010" />
+ <option name="presentableId" value="LOCAL-00010" />
+ <option name="project" value="LOCAL" />
+ <updated>1752146202309</updated>
+ </task>
+ <option name="localTasksCounter" value="11" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -195,6 +205,7 @@
<MESSAGE value="fix: 修复ts报错问题" />
<MESSAGE value="fix(日历): 解决一个诡异的bug,日历,拖动发布记录时,拖到比当前时间小的日历正常显示,拖到比当前时间大的日历时间会盖住发布记录。" />
<MESSAGE value="fix: 快手授权修改完成,改为任务" />
- <option name="LAST_COMMIT_MESSAGE" value="fix: 快手授权修改完成,改为任务" />
+ <MESSAGE value="feat: 删除不需要的文件" />
+ <option name="LAST_COMMIT_MESSAGE" value="feat: 删除不需要的文件" />
</component>
</project>
\ No newline at end of file
diff --git a/src/api/plat/publish.ts b/src/api/plat/publish.ts
index e8356de1..e8db2619 100644
--- a/src/api/plat/publish.ts
+++ b/src/api/plat/publish.ts
@@ -2,13 +2,14 @@
import { request } from "@/utils/request";
import {
GetPublishListParams,
- PublishParams, PublishRecordItem
+ PublishParams,
+ PublishRecordItem,
} from "@/api/plat/types/publish.types";
import { parseTopicString } from "@/utils";
// 创建发布
export const apiCreatePublish = (data: PublishParams) => {
- const { topics, cleanedString } = parseTopicString(data.desc || '');
+ const { topics, cleanedString } = parseTopicString(data.desc || "");
data.topics = [...new Set(data.topics?.concat(topics))];
data.desc = cleanedString;
@@ -27,3 +28,23 @@ export const getPublishList = (data: GetPublishListParams) => {
data,
});
};
+
+// 修改发布任务时间
+export const updatePublishRecordTimeApi = (data: {
+ id: string;
+ publishTime: string;
+}) => {
+ return request({
+ url: "/plat/publish/updateTaskTime",
+ method: "POST",
+ data,
+ });
+};
+
+// 删除发布任务
+export const deletePublishRecordApi = (id: string) => {
+ return request({
+ url: `/plat/publish/delete/${id}`,
+ method: "DELETE",
+ });
+};
diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx
index bf3de7b0..7a5f69fa 100644
--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx
+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx
@@ -1,4 +1,11 @@
-import { ForwardedRef, forwardRef, memo, useMemo } from "react";
+import {
+ ForwardedRef,
+ forwardRef,
+ memo,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { Button, Dropdown, Image, Popover, Tag } from "antd";
import { useCalendarTiming } from "@/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming";
import { useShallow } from "zustand/react/shallow";
@@ -21,6 +28,8 @@ import {
import AvatarPlat from "@/components/AvatarPlat";
import { useAccountStore } from "@/store/account";
import type { MenuProps } from "antd";
+import { TooltipRef } from "antd/lib/tooltip";
+import { deletePublishRecordApi } from "@/api/plat/publish";
export interface IRecordCoreRef {}
@@ -64,16 +73,21 @@ const RecordCore = memo(
{ publishRecord }: IRecordCoreProps,
ref: ForwardedRef<IRecordCoreRef>,
) => {
- const { calendarCallWidth } = useCalendarTiming(
- useShallow((state) => ({
- calendarCallWidth: state.calendarCallWidth,
- })),
- );
+ const { calendarCallWidth, setListLoading, getPubRecord } =
+ useCalendarTiming(
+ useShallow((state) => ({
+ calendarCallWidth: state.calendarCallWidth,
+ setListLoading: state.setListLoading,
+ getPubRecord: state.getPubRecord,
+ })),
+ );
const { accountUidMap } = useAccountStore(
useShallow((state) => ({
accountUidMap: state.accountUidMap,
})),
);
+ const [popoverOpen, setPopoverOpen] = useState(false);
+ const popoverRef = useRef<TooltipRef>(null);
const dropdownItems: MenuProps["items"] = [
{
key: "2",
@@ -83,6 +97,12 @@ const RecordCore = memo(
key: "3",
danger: true,
label: "删除",
+ onClick: async () => {
+ setPopoverOpen(false);
+ setListLoading(true);
+ await deletePublishRecordApi(publishRecord.id);
+ getPubRecord();
+ },
},
];
@@ -100,8 +120,11 @@ const RecordCore = memo(
return (
<Popover
+ ref={popoverRef}
placement="right"
rootClassName={styles.recordPopover}
+ open={popoverOpen}
+ onOpenChange={(e) => setPopoverOpen(e)}
content={
<div className={styles.recordDetails}>
<div className="recordDetails-top">
diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss
index e569c66d..6581e7c9 100644
--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss
+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/calendarTimingItem.module.scss
@@ -3,7 +3,7 @@
padding: 10px;
display: flex;
flex-direction: column;
- height: 200px;
+ min-height: 200px;
font-weight: 600;
:global {
.calendarTimingItem-top {
diff --git a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx b/src/app/[lng]/accounts/components/CalendarTiming/index.tsx
index 5575dd00..d117a0e6 100644
--- a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx
+++ b/src/app/[lng]/accounts/components/CalendarTiming/index.tsx
@@ -26,8 +26,6 @@ import { useShallow } from "zustand/react/shallow";
import { HTML5Backend } from "react-dnd-html5-backend";
import { DndProvider } from "react-dnd";
import { useCalendarTiming } from "@/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming";
-import { getPublishList } from "@/api/plat/publish";
-import { PublishRecordItem } from "@/api/plat/types/publish.types";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
@@ -61,20 +59,26 @@ const CalendarTiming = memo(
accountList: state.accountList,
})),
);
- const { setCalendarCallWidth } = useCalendarTiming(
+ const {
+ setCalendarCallWidth,
+ listLoading,
+ recordMap,
+ setCalendarRef,
+ getPubRecord,
+ } = useCalendarTiming(
useShallow((state) => ({
setCalendarCallWidth: state.setCalendarCallWidth,
+ listLoading: state.listLoading,
+ recordMap: state.recordMap,
+ getPubRecord: state.getPubRecord,
+ setCalendarRef: state.setCalendarRef,
})),
);
const calendarTimingItemCallEl = useRef<HTMLDivElement | null>(null);
const publishDialogRef = useRef<IPublishDialogRef>(null);
- const [listLoading, setListLoading] = useState(false);
- // 发布记录数据,key=年月日,value=发布记录
- const [recordMap, setRecordMap] = useState<
- Map<string, PublishRecordItem[]>
- >(new Map());
useEffect(() => {
+ setCalendarRef(calendarRef.current!);
window.addEventListener("resize", handleResize);
getPubRecord();
@@ -89,48 +93,6 @@ const CalendarTiming = memo(
return () => window.removeEventListener("resize", handleResize);
}, []);
- // 获取发布记录数据
- 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);
- });
- // 对每一天的记录按照 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);
- };
-
// 处理窗口大小变化
const handleResize = () => {
setTimeout(() => {
diff --git a/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts b/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts
index 8cb05a6e..0cbd529f 100644
--- a/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts
+++ b/src/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming.ts
@@ -1,14 +1,27 @@
import { create } from "zustand";
import { combine } from "zustand/middleware";
import lodash from "lodash";
+import { PublishRecordItem } from "@/api/plat/types/publish.types";
+import dayjs from "dayjs";
+import { getPublishList } from "@/api/plat/publish";
+import FullCalendar from "@fullcalendar/react";
export interface ICalendarTimingStore {
// 日历单元格宽度
calendarCallWidth: number;
+ // 发布记录数据,key=年月日,value=发布记录
+ recordMap: Map<string, PublishRecordItem[]>;
+ // 请求发布记录loading
+ listLoading: boolean;
+ // 当前日历ref
+ calendarRef?: FullCalendar;
}
const store: ICalendarTimingStore = {
calendarCallWidth: 0,
+ recordMap: new Map(),
+ listLoading: false,
+ calendarRef: undefined,
};
const getStore = () => {
@@ -25,6 +38,55 @@ export const useCalendarTiming = create(
setCalendarCallWidth(calendarCallWidth: number) {
set({ calendarCallWidth });
},
+ setRecordMap(recordMap: Map<string, PublishRecordItem[]>) {
+ set({ recordMap });
+ },
+ setListLoading(listLoading: boolean) {
+ set({ listLoading });
+ },
+ setCalendarRef(calendarRef: FullCalendar) {
+ set({ calendarRef });
+ },
+
+ // 获取发布记录数据
+ async getPubRecord() {
+ methods.setListLoading(true);
+ const date = dayjs(get().calendarRef?.getApi().getDate());
+ const startOfMonth = date.startOf("month");
+ const endOfMonth = date.endOf("month");
+
+ const res = await getPublishList({
+ time: [startOfMonth.utc().format(), endOfMonth.utc().format()],
+ });
+ methods.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);
+ });
+ // 对每一天的记录按照 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);
+ }
+ });
+ methods.setRecordMap(recordMap);
+ },
clear() {
set({