Skip to content

Let's use AI to Earn!

feat: 发布弹框整体设计

gaoSir609489f6c8e8
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 76b61d55..d06b9662 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,23 +4,18 @@
<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/components/PublishDialog/compoents/PlatParamsSetting/index.tsx" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.type.ts" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.utils.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$/src/app/[lng]/publish/components/Choose/ImgChoose.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/publish/components/Choose/ImgChoose.tsx" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/publish/components/Choose/VideoChoose.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/publish/components/Choose/VideoChoose.tsx" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/publish/components/Choose/videoChoose.util.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/publish/components/Choose/videoChoose.util.ts" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/publish/imagePage/useImagePageStore.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/publish/imagePage/useImagePageStore.ts" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.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/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/index.tsx" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/plats/BilibParams.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/plats/KwaiParams.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/plats/plats.type.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/PublishDialog/publishDialog.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/publishDialog.module.scss" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/usePublishDialog.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/usePublishDialog.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -54,27 +49,27 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
- <component name="PropertiesComponent"><![CDATA[{
- "keyToString": {
- "ASKED_ADD_EXTERNAL_FILES": "true",
- "ASKED_MARK_IGNORED_FILES_AS_EXCLUDED": "true",
- "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "git-widget-placeholder": "master",
- "ignore.virus.scanning.warn.message": "true",
- "last_opened_file_path": "E:/project-dev/web/艺咖/aitoearn-web/src/components/PublishDialog/compoents/PubParmasTextarea",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "run.code.analysis.last.selected.profile": "pProject Default",
- "settings.editor.selected.configurable": "editor.reader.mode",
- "ts.external.directory.path": "E:\\project-dev\\web\\艺咖\\aitoearn-web\\node_modules\\typescript\\lib",
- "vue.rearranger.settings.migration": "true"
+ <component name="PropertiesComponent">{
+ &quot;keyToString&quot;: {
+ &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
+ &quot;ASKED_MARK_IGNORED_FILES_AS_EXCLUDED&quot;: &quot;true&quot;,
+ &quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
+ &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
+ &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
+ &quot;git-widget-placeholder&quot;: &quot;master&quot;,
+ &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
+ &quot;last_opened_file_path&quot;: &quot;E:/project-dev/web/艺咖/aitoearn-web/src/components/PublishDialog/compoents/PubParmasTextarea/components&quot;,
+ &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
+ &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
+ &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
+ &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
+ &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
+ &quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
+ &quot;settings.editor.selected.configurable&quot;: &quot;editor.reader.mode&quot;,
+ &quot;ts.external.directory.path&quot;: &quot;E:\\project-dev\\web\\艺咖\\aitoearn-web\\node_modules\\typescript\\lib&quot;,
+ &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
-}]]></component>
+}</component>
<component name="ReactBuddySettings">
<option name="extensionsIgnore" value="true" />
</component>
@@ -89,6 +84,7 @@
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
+ <recent name="E:\project-dev\web\艺咖\aitoearn-web\src\components\PublishDialog\compoents\PubParmasTextarea\components" />
<recent name="E:\project-dev\web\艺咖\aitoearn-web\src\components\PublishDialog\plats" />
</key>
<key name="MoveFile.RECENT_KEYS">
@@ -113,7 +109,7 @@
<workItem from="1750763285511" duration="48000" />
<workItem from="1750763342070" duration="32000" />
<workItem from="1750763376065" duration="41000" />
- <workItem from="1750763426455" duration="22965000" />
+ <workItem from="1750763426455" duration="30631000" />
</task>
<task id="LOCAL-00001" summary="feat: 日历完善">
<option name="closed" value="true" />
@@ -187,7 +183,15 @@
<option name="project" value="LOCAL" />
<updated>1750772741634</updated>
</task>
- <option name="localTasksCounter" value="10" />
+ <task id="LOCAL-00010" summary="feat: 发布弹框:上传图片/视频完成、裁剪图片,描述写入,完成。">
+ <option name="closed" value="true" />
+ <created>1750851652194</created>
+ <option name="number" value="00010" />
+ <option name="presentableId" value="LOCAL-00010" />
+ <option name="project" value="LOCAL" />
+ <updated>1750851652194</updated>
+ </task>
+ <option name="localTasksCounter" value="11" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -216,6 +220,7 @@
<MESSAGE value="feat: 添加b站icon" />
<MESSAGE value="feat: 发布弹框开发中..." />
<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 file
diff --git a/src/app/[lng]/publish/imagePage/useImagePageStore.ts b/src/app/[lng]/publish/imagePage/useImagePageStore.ts
index 7dec80ca..bc064442 100644
--- a/src/app/[lng]/publish/imagePage/useImagePageStore.ts
+++ b/src/app/[lng]/publish/imagePage/useImagePageStore.ts
@@ -162,6 +162,7 @@ export const useImagePageStore = create(
// 设置通用发布参数
setCommonPubParams(pubParmas: IPubParams) {
+ console.log(pubParmas);
const commonPubParams = { ...get().commonPubParams };
const imageAccounts = [...get().imageAccounts];
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
index 67ef47d9..ab5a8020 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
@@ -1,24 +1,51 @@
-import { ForwardedRef, forwardRef, memo } from "react";
+import { ForwardedRef, forwardRef, memo, useMemo } from "react";
import styles from "./platParamsSetting.module.scss";
-import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
+import {
+ PubItem,
+ usePublishDialog,
+} from "@/components/PublishDialog/usePublishDialog";
+import { useShallow } from "zustand/react/shallow";
+import { AccountPlatInfoMap, PlatType } from "@/app/config/platConfig";
+import BilibParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams";
+import KwaiParams from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams";
export interface IPlatParamsSettingRef {}
-export interface IPlatParamsSettingProps {}
+export interface IPlatParamsSettingProps {
+ pubItem: PubItem;
+}
const PlatParamsSetting = memo(
forwardRef(
- ({}: IPlatParamsSettingProps, ref: ForwardedRef<IPlatParamsSettingRef>) => {
+ (
+ { pubItem }: IPlatParamsSettingProps,
+ ref: ForwardedRef<IPlatParamsSettingRef>,
+ ) => {
+ const { step } = usePublishDialog(
+ useShallow((state) => ({
+ step: state.step,
+ })),
+ );
+
+ const platConfig = useMemo(() => {
+ return AccountPlatInfoMap.get(pubItem.account.type)!;
+ }, [pubItem]);
+
+ const PlatItemComp = useMemo(() => {
+ switch (pubItem.account.type) {
+ case PlatType.KWAI:
+ return <KwaiParams pubItem={pubItem} />;
+ case PlatType.BILIBILI:
+ return <BilibParams pubItem={pubItem} />;
+ }
+ }, [pubItem]);
+
return (
<div className={styles.platParamsSetting}>
- <PubParmasTextarea
- onChange={(v) => {
- console.log(v);
- }}
- onUpload={(files) => {
- console.log(files);
- }}
- />
+ <div className="platParamsSetting-icon">
+ <img src={platConfig.icon} style={{ borderRadius: "50%" }} />
+ </div>
+ {PlatItemComp}
</div>
);
},
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss b/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss
index 191a0f9f..f49c4f53 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss
@@ -1,3 +1,8 @@
.platParamsSetting {
-
+ display: flex;
+ :global {
+ .platParamsSetting-icon {
+ margin-right: 10px;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
index aca00ac1..81295012 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
@@ -3,11 +3,25 @@ import {
IPlatsParamsProps,
IPlatsParamsRef,
} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
const BilibParams = memo(
- forwardRef(({}: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
- return <div>b站</div>;
- }),
+ forwardRef(
+ ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
+ return (
+ <>
+ <PubParmasTextarea
+ desValue={pubItem.params.des}
+ imageFileListValue={pubItem.params.images}
+ videoFileValue={pubItem.params.video}
+ onChange={(v) => {
+ console.log(v);
+ }}
+ />
+ </>
+ );
+ },
+ ),
);
export default BilibParams;
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
index b0a4d1e2..8d4e635a 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
@@ -3,11 +3,25 @@ import {
IPlatsParamsProps,
IPlatsParamsRef,
} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
const KwaiParams = memo(
- forwardRef(({}: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
- return <div>快手</div>;
- }),
+ forwardRef(
+ ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
+ return (
+ <>
+ <PubParmasTextarea
+ desValue={pubItem.params.des}
+ imageFileListValue={pubItem.params.images}
+ videoFileValue={pubItem.params.video}
+ onChange={(v) => {
+ console.log(v);
+ }}
+ />
+ </>
+ );
+ },
+ ),
);
export default KwaiParams;
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts
index 21128e27..8ecfd5a4 100644
--- a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts
@@ -1,3 +1,7 @@
+import { PubItem } from "@/components/PublishDialog/usePublishDialog";
+
export interface IPlatsParamsRef {}
-export interface IPlatsParamsProps {}
+export interface IPlatsParamsProps {
+ pubItem: PubItem;
+}
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
index 204665af..af2ff0fa 100644
--- a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
@@ -1,4 +1,5 @@
import React, {
+ CSSProperties,
ForwardedRef,
forwardRef,
memo,
@@ -21,6 +22,7 @@ import { IImgFile } from "@/app/[lng]/publish/components/Choose/ImgChoose";
import { formatVideo } from "@/app/[lng]/publish/components/Choose/videoChoose.util";
import { formatImg } from "@/app/[lng]/publish/components/Choose/ImgChoose.util";
import VideoCoverSeting from "@/app/[lng]/publish/videoPage/components/VideoCoverSeting";
+import isEqual from "lodash/isEqual";
const { TextArea } = Input;
const { Dragger } = Upload;
@@ -28,9 +30,11 @@ const { Dragger } = Upload;
export interface IPubParmasTextareaRef {}
export interface IPubParmasTextareaProps {
- onChange: (value: string) => void;
- // 上传change
- onUpload: (files: { imgs?: IImgFile[]; video?: IVideoFile }) => void;
+ onChange: (values: {
+ imgs?: IImgFile[];
+ video?: IVideoFile;
+ value: string;
+ }) => void;
rows?: number;
// 视频数量限制
videoMax?: number;
@@ -38,33 +42,65 @@ export interface IPubParmasTextareaProps {
imageMax?: number;
// 扩展内容
extend?: React.ReactNode;
+ style?: CSSProperties;
+ imageFileListValue?: IImgFile[];
+ videoFileValue?: IVideoFile;
+ desValue?: string;
}
const PubParmasTextarea = memo(
forwardRef(
(
{
+ style,
onChange,
- onUpload,
rows = 12,
videoMax = 1,
imageMax = 20,
extend,
+ imageFileListValue = [],
+ videoFileValue,
+ desValue = "",
}: IPubParmasTextareaProps,
ref: ForwardedRef<IPubParmasTextareaRef>,
) => {
- const [value, setValue] = useState("");
+ const [value, setValue] = useState(desValue);
const [previewData, setPreviewData] = useState<
IImgFile | IVideoFile | undefined
>(undefined);
// 图片
- const [imageFileList, setImageFileList] = useState<IImgFile[]>([]);
+ const [imageFileList, setImageFileList] =
+ useState<IImgFile[]>(imageFileListValue);
// 视频
const [videoFile, setVideoFile] = useState<IVideoFile | undefined>(
- undefined,
+ videoFileValue,
);
+ // 裁剪弹框
const [videoCoverSetingModal, setVideoCoverSetingModal] = useState(false);
+ useEffect(() => {
+ const values = {
+ imgs: imageFileList,
+ video: videoFile,
+ value,
+ };
+ onChange(values);
+ }, [imageFileList, videoFile, value]);
+
+ useEffect(() => {
+ if (imageFileListValue.length === 0 && imageFileList.length === 0)
+ return;
+ if (isEqual(imageFileListValue, imageFileList)) {
+ setImageFileList(imageFileListValue);
+ }
+ }, [imageFileListValue]);
+ useEffect(() => {
+ setValue(desValue || "");
+ }, [desValue]);
+ useEffect(() => {
+ setVideoFile(videoFileValue);
+ }, [videoFileValue]);
+
// 动态accept类型
const uploadAccept = useMemo(() => {
const hasImage = imageFileList.length !== 0;
@@ -87,19 +123,6 @@ const PubParmasTextarea = memo(
return true;
}, [videoFile, imageMax, videoMax, videoFile]);
- useEffect(() => {
- onChange(value);
- }, [value]);
-
- useEffect(() => {
- const files = {
- imgs: imageFileList,
- video: videoFile,
- };
-
- onUpload(files);
- }, [imageFileList, videoFile]);
-
// 检查上传文件类型
const checkFileListType = useCallback(
(fileList: File[]) => {
@@ -215,7 +238,7 @@ const PubParmasTextarea = memo(
)}
</Modal>
- <div className={styles.pubParmasTextarea}>
+ <div className={styles.pubParmasTextarea} style={style}>
<div className="pubParmasTextarea-input">
<TextArea
placeholder="开始写"
@@ -378,10 +401,6 @@ const PubParmasTextarea = memo(
)}
</div>
- <div className="pubParmasTextarea-menus">
- <div className="pubParmasTextarea-menus-item">1</div>
- </div>
-
{extend && <div className="pubParmasTextarea-other">{extend}</div>}
</div>
</>
diff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsx
index 69d970d1..f994ac76 100644
--- a/src/components/PublishDialog/index.tsx
+++ b/src/components/PublishDialog/index.tsx
@@ -3,12 +3,13 @@ import {
forwardRef,
memo,
useCallback,
+ useEffect,
useMemo,
useState,
} from "react";
import styles from "./publishDialog.module.scss";
import { Button, Modal } from "antd";
-import { ExclamationCircleFilled } from "@ant-design/icons";
+import { ArrowRightOutlined, ExclamationCircleFilled } from "@ant-design/icons";
import PublishDialogAi from "@/components/PublishDialog/compoents/PublishDialogAi";
import PublishDialogPreview from "@/components/PublishDialog/compoents/PublishDialogPreview";
import { CSSTransition } from "react-transition-group";
@@ -18,6 +19,7 @@ import AvatarPlat from "@/components/AvatarPlat";
import { usePublishDialog } from "@/components/PublishDialog/usePublishDialog";
import { useShallow } from "zustand/react/shallow";
import PlatParamsSetting from "@/components/PublishDialog/compoents/PlatParamsSetting";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
export interface IPublishDialogRef {}
@@ -37,14 +39,37 @@ const PublishDialog = memo(
ref: ForwardedRef<IPublishDialogRef>,
) => {
const [openLeft, setOpenLeft] = useState(false);
- const { setAccountChoosed, accountChoosed } = usePublishDialog(
+ const {
+ pubListChoosed,
+ setPubListChoosed,
+ init,
+ clear,
+ pubList,
+ setStep,
+ step,
+ setAccountAllParams,
+ commonPubParams,
+ } = usePublishDialog(
useShallow((state) => ({
- accountChoosed: state.accountChoosed,
- setAccountChoosed: state.setAccountChoosed,
+ pubListChoosed: state.pubListChoosed,
+ setPubListChoosed: state.setPubListChoosed,
+ init: state.init,
+ clear: state.clear,
+ pubList: state.pubList,
+ setStep: state.setStep,
+ step: state.step,
+ setAccountAllParams: state.setAccountAllParams,
+ commonPubParams: state.commonPubParams,
})),
);
- // 当前步骤,0=所有账号没有参数,要设置参数。 1=所有账号有参数,详细设置参数
- const [step, setStep] = useState(0);
+
+ useEffect(() => {
+ if (open) {
+ init(accounts);
+ } else {
+ clear();
+ }
+ }, [accounts, open]);
// 关闭弹框并确认关闭
const closeDialog = useCallback(() => {
@@ -68,10 +93,8 @@ const PublishDialog = memo(
// 是否打开右侧预览
const openRight = useMemo(() => {
- return accountChoosed.length !== 0;
- }, [accountChoosed]);
-
- // 获取
+ return pubListChoosed.length !== 0;
+ }, [pubListChoosed]);
return (
<>
@@ -97,10 +120,12 @@ const PublishDialog = memo(
<span className="publishDialog-con-head-title">发布作品</span>
</div>
<div className="publishDialog-con-acconts">
- {accounts.map((account) => {
- const platConfig = AccountPlatInfoMap.get(account.type)!;
- const isChoosed = accountChoosed.find(
- (v) => v.id === account.id,
+ {pubList.map((pubItem) => {
+ const platConfig = AccountPlatInfoMap.get(
+ pubItem.account.type,
+ )!;
+ const isChoosed = pubListChoosed.find(
+ (v) => v.account.id === pubItem.account.id,
);
return (
@@ -116,24 +141,24 @@ const PublishDialog = memo(
? platConfig.themeColor
: "transparent",
}}
- key={account.id}
+ key={pubItem.account.id}
onClick={() => {
- const newAccountChoosed = [...accountChoosed];
+ const newPubListChoosed = [...pubListChoosed];
// 查找当前账户是否已被选择
- const index = newAccountChoosed.findIndex(
- (v) => v.id === account.id,
+ const index = newPubListChoosed.findIndex(
+ (v) => v.account.id === pubItem.account.id,
);
if (index !== -1) {
- newAccountChoosed.splice(index, 1);
+ newPubListChoosed.splice(index, 1);
} else {
- newAccountChoosed.push(account);
+ newPubListChoosed.push(pubItem);
}
- setAccountChoosed(newAccountChoosed);
+ setPubListChoosed(newPubListChoosed);
}}
>
<AvatarPlat
className="publishDialog-con-acconts-item-avatar"
- account={account}
+ account={pubItem.account}
size="large"
/>
</div>
@@ -142,35 +167,63 @@ const PublishDialog = memo(
</div>
<div className="publishDialog-paramsSet">
- <PlatParamsSetting />
{step === 0 ? (
<>
- {accountChoosed.length === 0 && (
- <div className="publishDialog-con-tips">
- 你的工作被保存了,选择一个账号来创建一个帖子。
- </div>
- )}
- {accountChoosed.length == 1 && (
- <div style={{ height: "500px" }}>{accountChoosed[0].type}</div>
+ {pubListChoosed.length == 1 && (
+ <PlatParamsSetting pubItem={pubListChoosed[0]} />
+ // <div style={{ height: "500px" }}>
+ // {accountChoosed[0].type}
+ // </div>
)}
- {accountChoosed.length >= 2 && (
- <div style={{ height: "500px" }}>通用参数</div>
+ {pubListChoosed.length >= 2 && (
+ <PubParmasTextarea
+ rows={16}
+ desValue={commonPubParams.des}
+ videoFileValue={commonPubParams.video}
+ imageFileListValue={commonPubParams.images}
+ onChange={(values) => {
+ setAccountAllParams({
+ ...values,
+ });
+ }}
+ />
+ // <div style={{ height: "500px" }}>通用参数</div>
)}
</>
) : (
- <>第二步</>
+ <>第二部</>
+ )}
+
+ {pubListChoosed.length === 0 && (
+ <div className="publishDialog-con-tips">
+ 你的工作被保存了,选择一个账号来创建一个帖子。
+ </div>
)}
</div>
</div>
<div className="publishDialog-footer">
time
<div className="publishDialog-footer-btns">
- <Button size="large" onClick={closeDialog}>
- 取消
- </Button>
- <Button size="large" type="primary">
- 确认
- </Button>
+ {step === 0 && pubListChoosed.length >= 2 ? (
+ <Button
+ size="large"
+ onClick={() => {
+ setStep(1);
+ }}
+ >
+ 针对每个账户进行定制
+ <ArrowRightOutlined />
+ </Button>
+ ) : (
+ <>
+ <Button size="large" onClick={closeDialog}>
+ 取消发布
+ </Button>
+ <Button size="large" type="primary">
+ 计划发布
+ </Button>
+ </>
+ )}
</div>
</div>
</div>
diff --git a/src/components/PublishDialog/publishDialog.module.scss b/src/components/PublishDialog/publishDialog.module.scss
index 5edfed24..0304df9e 100644
--- a/src/components/PublishDialog/publishDialog.module.scss
+++ b/src/components/PublishDialog/publishDialog.module.scss
@@ -63,11 +63,11 @@ $assistantWidth: 300px;
&-tips {
text-align: center;
- margin: 30px 0 0 0;
color: var(--grayColor7);
}
}
.publishDialog-paramsSet {
+ margin-top: 30px;
max-height: 600px;
overflow: auto;
}
diff --git a/src/components/PublishDialog/usePublishDialog.ts b/src/components/PublishDialog/usePublishDialog.ts
index 2e167220..6f55861c 100644
--- a/src/components/PublishDialog/usePublishDialog.ts
+++ b/src/components/PublishDialog/usePublishDialog.ts
@@ -2,14 +2,40 @@ import { create } from "zustand";
import { combine } from "zustand/middleware";
import lodash from "lodash";
import { SocialAccount } from "@/api/types/account.type";
+import { IImgFile } from "@/app/[lng]/publish/components/Choose/ImgChoose";
+import { IVideoFile } from "@/app/[lng]/publish/components/Choose/VideoChoose";
+
+interface IPubParams {
+ des: string;
+ images?: IImgFile[];
+ video?: IVideoFile;
+}
+
+export interface PubItem {
+ account: SocialAccount;
+ params: IPubParams;
+}
export interface IPublishDialogStore {
- // 选择的账户
- accountChoosed: SocialAccount[];
+ // 选择的发布列表
+ pubListChoosed: PubItem[];
+ // 所有发布列表
+ pubList: PubItem[];
+ // 通用发布参数
+ commonPubParams: IPubParams;
+ // 当前步骤,0=所有账号没有参数,要设置参数。 1=所有账号有参数,详细设置参数
+ step: number;
}
const store: IPublishDialogStore = {
- accountChoosed: [],
+ pubListChoosed: [],
+ pubList: [],
+ step: 0,
+ commonPubParams: {
+ des: "",
+ video: undefined,
+ images: [],
+ },
};
const getStore = () => {
@@ -29,10 +55,56 @@ export const usePublishDialog = create(
...getStore(),
});
},
+ setStep(step: number) {
+ set({ step });
+ },
+
+ // 初始化发布参数
+ pubParamsInit(): IPubParams {
+ return lodash.cloneDeep(get().commonPubParams);
+ },
+
+ // 初始化
+ init(account: SocialAccount[]) {
+ const pubList: PubItem[] = [];
+
+ account.map((v) => {
+ pubList.push({
+ account: v,
+ params: methods.pubParamsInit(),
+ });
+ });
+
+ set({
+ pubList,
+ });
+ },
+
+ // 参数设置到所有账户
+ setAccountAllParams(pubParmas: Partial<IPubParams>) {
+ const pubList = [...get().pubList];
+ const commonPubParams = { ...get().commonPubParams };
+
+ for (const key in commonPubParams) {
+ if (pubParmas.hasOwnProperty(key)) {
+ const keyType = key as "des";
+ const val = pubParmas[keyType];
+ commonPubParams[keyType] = pubParmas[keyType]!;
+ pubList.map((v) => {
+ v.params[keyType] = val!;
+ });
+ }
+ }
+
+ set({
+ pubList,
+ commonPubParams,
+ });
+ },
- setAccountChoosed(accountChoosed: SocialAccount[]) {
+ setPubListChoosed(pubListChoosed: PubItem[]) {
set({
- accountChoosed,
+ pubListChoosed,
});
},
};