Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(日历): 发布记录初步渲染
gaoSirefb434fd47cd
diff --git a/.idea/workspace.xml b/.idea/workspace.xmlindex 78c45b68..1f9b930f 100644--- a/.idea/workspace.xml+++ b/.idea/workspace.xml@@ -4,16 +4,16 @@<option name="autoReloadType" value="SELECTIVE" /></component><component name="ChangeListManager">- <list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="feat(日历): 日历-日期选择逻辑开发完成">- <change afterPath="$PROJECT_DIR$/src/api/plat/types/kwai.types.ts" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/api/plat/types/publish.types.ts" afterDir="false" />+ <list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="feat(日历): 发布记录列表接入"><change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />- <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/api/plat/types/kwai.type.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/plat/publish.ts" afterDir="false" />- <change beforePath="$PROJECT_DIR$/src/api/publish.ts" beforeDir="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/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx" afterDir="false" /><change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx" 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/calendarTiming.utils.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils.ts" 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/config/platConfig.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/config/platConfig.ts" afterDir="false" /></list><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" />@@ -134,7 +134,7 @@<workItem from="1751806982109" duration="7000" /><workItem from="1751853979086" duration="990000" /><workItem from="1751875610327" duration="15028000" />- <workItem from="1751969152766" duration="1525000" />+ <workItem from="1751969152766" duration="3947000" /></task><task id="LOCAL-00001" summary="feat: 日历完善"><option name="closed" value="true" />@@ -336,7 +336,15 @@<option name="project" value="LOCAL" /><updated>1751962787283</updated></task>- <option name="localTasksCounter" value="26" />+ <task id="LOCAL-00026" summary="feat(日历): 发布记录列表接入">+ <option name="closed" value="true" />+ <created>1751970702181</created>+ <option name="number" value="00026" />+ <option name="presentableId" value="LOCAL-00026" />+ <option name="project" value="LOCAL" />+ <updated>1751970702181</updated>+ </task>+ <option name="localTasksCounter" value="27" /><servers /></component><component name="TypeScriptGeneratedFilesManager">@@ -393,6 +401,7 @@<MESSAGE value="fix: 修复类型错误,更改next配置" /><MESSAGE value="feat(demo): 添加定时测试demo,修复添加账号switch case语法错误问题" /><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/types/publish.types.ts b/src/api/plat/types/publish.types.tsindex e960fc35..7109d0f4 100644--- a/src/api/plat/types/publish.types.ts+++ b/src/api/plat/types/publish.types.ts@@ -36,6 +36,7 @@ export interface GetPublishListParams {pageSize: number;}+// 发布记录item数据export interface PublishRecordItem {dataId: string;id: string;diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsxindex 6e584d6b..03e214f6 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview.tsx@@ -1,6 +1,7 @@import type { CSSProperties, FC } from "react";import { memo, useEffect, useState } from "react";import RecordCore from "@/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore";+import { PublishRecordItem } from "@/api/plat/types/publish.types";const styles: CSSProperties = {display: "inline-block",@@ -9,10 +10,12 @@ const styles: CSSProperties = {transition: "0.3s",};-export interface BoxDragPreviewProps {}+export interface BoxDragPreviewProps {+ publishRecord: PublishRecordItem;+}export const BoxDragPreview: FC<BoxDragPreviewProps> = memo(- function BoxDragPreview({}) {+ function BoxDragPreview({ publishRecord }) {const [tickTock, setTickTock] = useState(false);useEffect(@@ -25,7 +28,7 @@ export const BoxDragPreview: FC<BoxDragPreviewProps> = memo(return (<div style={styles}>- <RecordCore />+ <RecordCore publishRecord={publishRecord} /></div>);},diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsxindex 4203a69b..2f31712a 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord.tsx@@ -3,14 +3,23 @@ import styles from "./calendarRecord.module.scss";import { DragSourceMonitor, useDrag } from "react-dnd";import { getEmptyImage } from "react-dnd-html5-backend";import RecordCore from "@/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore";+import {+ PublishRecordItem,+ PublishStatus,+} from "@/api/plat/types/publish.types";export interface ICalendarRecordRef {}-export interface ICalendarRecordProps {}+export interface ICalendarRecordProps {+ publishRecord: PublishRecordItem;+}const CalendarRecord = memo(forwardRef(- ({}: ICalendarRecordProps, ref: ForwardedRef<ICalendarRecordRef>) => {+ (+ { publishRecord }: ICalendarRecordProps,+ ref: ForwardedRef<ICalendarRecordRef>,+ ) => {const [{ opacity }, drag, preview] = useDrag(() => ({type: "box",@@ -34,12 +43,14 @@ const CalendarRecord = memo(<divstyle={{ opacity: opacity }}ref={(node) => {- drag(node);+ if (publishRecord.status === PublishStatus.UNPUBLISH) {+ drag(node);+ }}}className={styles.calendarRecord}role="DraggableBox">- <RecordCore />+ <RecordCore publishRecord={publishRecord} /></div>);},diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsxindex 0b7ee135..e7b28ed6 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarTimingItem.tsx@@ -8,6 +8,7 @@ import { useDrop } from "react-dnd";import CalendarRecord from "@/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CalendarRecord";import { CustomDragLayer } from "@/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer";import dayjs from "dayjs";+import { PublishRecordItem } from "@/api/plat/types/publish.types";export interface ICalendarTimingItemRef {}@@ -15,12 +16,14 @@ export interface ICalendarTimingItemProps {arg: DayCellContentArg;onClickPub: (date: string) => void;loading: boolean;+ // 发布记录数据+ records?: PublishRecordItem[];}const CalendarTimingItem = memo(forwardRef((- { arg, onClickPub, loading }: ICalendarTimingItemProps,+ { arg, onClickPub, loading, records }: ICalendarTimingItemProps,ref: ForwardedRef<ICalendarTimingItemRef>,) => {const { t } = useTransClient("account");@@ -93,29 +96,39 @@ const CalendarTimingItem = memo(<Skeleton.Button active={true} block={true} size="small" /></>) : (- <>+ <div className="calendarTimingItem-con">{argDate >= nowDate && (- <div className="calendarTimingItem-con">- <Button- size="small"- type="dashed"- onClick={() => {- const days = dayjs(arg.date)- .set("hour", 16)- .set("minute", 12);- onClickPub(days.format());- }}- >- <div className="calendarTimingItem-con-btn1">04:12 PM</div>- <div className="calendarTimingItem-con-btn2">- {t("addPost")}- </div>- </Button>- <CustomDragLayer snapToGrid={false} />- <CalendarRecord />- </div>+ <Button+ size="small"+ type="dashed"+ onClick={() => {+ const days = dayjs(arg.date)+ .set("hour", 16)+ .set("minute", 12);+ onClickPub(days.format());+ }}+ >+ <div className="calendarTimingItem-con-btn1">04:12 PM</div>+ <div className="calendarTimingItem-con-btn2">+ {t("addPost")}+ </div>+ </Button>)}- </>++ {records &&+ records.map((v) => {+ return (+ <>+ <CustomDragLayer+ key={v.id + "1"}+ publishRecord={v}+ snapToGrid={false}+ />+ <CalendarRecord key={v.id + "2"} publishRecord={v} />+ </>+ );+ })}+ </div>)}</div>);diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsxindex b7f7d939..dcd758db 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/CustomDragLayer.tsx@@ -2,6 +2,7 @@ import type { CSSProperties, FC } from "react";import type { XYCoord } from "react-dnd";import { useDragLayer } from "react-dnd";import { BoxDragPreview } from "@/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/BoxDragPreview";+import { PublishRecordItem } from "@/api/plat/types/publish.types";function snapToGrid(x: number, y: number): [number, number] {const snappedX = Math.round(x / 32) * 32;@@ -49,6 +50,7 @@ function getItemStyles(export interface CustomDragLayerProps {snapToGrid: boolean;+ publishRecord: PublishRecordItem;}export const CustomDragLayer: FC<CustomDragLayerProps> = (props) => {@@ -69,7 +71,7 @@ export const CustomDragLayer: FC<CustomDragLayerProps> = (props) => {<divstyle={getItemStyles(initialOffset, currentOffset, props.snapToGrid)}>- <BoxDragPreview />+ <BoxDragPreview publishRecord={props.publishRecord} /></div></div>);diff --git a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsxindex 314703ca..37ba8e3f 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/CalendarTimingItem/RecordCore.tsx@@ -2,21 +2,31 @@ import { ForwardedRef, forwardRef, memo } from "react";import { Button } from "antd";import { useCalendarTiming } from "@/app/[lng]/accounts/components/CalendarTiming/useCalendarTiming";import { useShallow } from "zustand/react/shallow";+import { PublishRecordItem } from "@/api/plat/types/publish.types";export interface IRecordCoreRef {}-export interface IRecordCoreProps {}+export interface IRecordCoreProps {+ publishRecord: PublishRecordItem;+}const RecordCore = memo(- forwardRef(({}: IRecordCoreProps, ref: ForwardedRef<IRecordCoreRef>) => {- const { calendarCallWidth } = useCalendarTiming(- useShallow((state) => ({- calendarCallWidth: state.calendarCallWidth,- })),- );+ forwardRef(+ (+ { publishRecord }: IRecordCoreProps,+ ref: ForwardedRef<IRecordCoreRef>,+ ) => {+ const { calendarCallWidth } = useCalendarTiming(+ useShallow((state) => ({+ calendarCallWidth: state.calendarCallWidth,+ })),+ );- return <Button style={{ width: calendarCallWidth + "px" }}>123456</Button>;- }),+ return (+ <Button style={{ width: calendarCallWidth + "px" }}>123456</Button>+ );+ },+ ),);export default RecordCore;diff --git a/src/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils.ts b/src/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils.tsindex 4b4ba5d1..d52b9301 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils.ts+++ b/src/app/[lng]/accounts/components/CalendarTiming/calendarTiming.utils.ts@@ -37,5 +37,3 @@ export function getTransitionClassNames(direction: "left" | "right" | "fade") {};}}--diff --git a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx b/src/app/[lng]/accounts/components/CalendarTiming/index.tsxindex 8adc0761..04297b2d 100644--- a/src/app/[lng]/accounts/components/CalendarTiming/index.tsx+++ b/src/app/[lng]/accounts/components/CalendarTiming/index.tsx@@ -27,6 +27,8 @@ 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";export interface ICalendarTimingRef {}export interface ICalendarTimingProps {}@@ -64,6 +66,10 @@ const CalendarTiming = memo(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(() => {window.addEventListener("resize", handleResize);@@ -89,8 +95,33 @@ const CalendarTiming = memo(filter: {},});setListLoading(false);- console.log(res);- console.log("发布记录");+ 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 = [];+ 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);};// 处理窗口大小变化@@ -187,6 +218,9 @@ const CalendarTiming = memo(dayCellContent={(arg) => {return (<CalendarTimingItem+ records={recordMap.get(+ dayjs(arg.date).format("YYYY-MM-DD"),+ )}loading={listLoading}arg={arg}onClickPub={(date) => {