Skip to content

Let's use AI to Earn!

feat: 发布弹框:上传图片/视频完成、裁剪图片,描述写入,完成。

gaoSir3a6b0529bde8
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d7138f26..76b61d55 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,22 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="feat: 发布弹框开发中...">
+ <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" />
<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/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" />
</list>
<option name="SHOW_DIALOG" value="false" />
@@ -41,27 +54,27 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
- <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/plats&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 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>
+}]]></component>
<component name="ReactBuddySettings">
<option name="extensionsIgnore" value="true" />
</component>
@@ -79,6 +92,8 @@
<recent name="E:\project-dev\web\艺咖\aitoearn-web\src\components\PublishDialog\plats" />
</key>
<key name="MoveFile.RECENT_KEYS">
+ <recent name="E:\project-dev\web\艺咖\aitoearn-web\src\components\PublishDialog\compoents\PubParmasTextarea" />
+ <recent name="E:\project-dev\web\艺咖\aitoearn-web\src\components\PublishDialog\compoents\PlatParamsSetting" />
<recent name="E:\project-dev\web\艺咖\aitoearn-web\src\assets\svgs\plat" />
</key>
</component>
@@ -98,7 +113,7 @@
<workItem from="1750763285511" duration="48000" />
<workItem from="1750763342070" duration="32000" />
<workItem from="1750763376065" duration="41000" />
- <workItem from="1750763426455" duration="8516000" />
+ <workItem from="1750763426455" duration="22965000" />
</task>
<task id="LOCAL-00001" summary="feat: 日历完善">
<option name="closed" value="true" />
@@ -164,7 +179,15 @@
<option name="project" value="LOCAL" />
<updated>1750770307974</updated>
</task>
- <option name="localTasksCounter" value="9" />
+ <task id="LOCAL-00009" summary="feat: 发布逻辑初步实现">
+ <option name="closed" value="true" />
+ <created>1750772741634</created>
+ <option name="number" value="00009" />
+ <option name="presentableId" value="LOCAL-00009" />
+ <option name="project" value="LOCAL" />
+ <updated>1750772741634</updated>
+ </task>
+ <option name="localTasksCounter" value="10" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -192,6 +215,7 @@
<MESSAGE value="feat: 日历样式调整" />
<MESSAGE value="feat: 添加b站icon" />
<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/components/Choose/ImgChoose.tsx b/src/app/[lng]/publish/components/Choose/ImgChoose.tsx
index 7dc73f75..24b573f0 100644
--- a/src/app/[lng]/publish/components/Choose/ImgChoose.tsx
+++ b/src/app/[lng]/publish/components/Choose/ImgChoose.tsx
@@ -5,8 +5,10 @@
* @LastEditors: nevin
* @Description: 选择图片
*/
-import { Button } from "antd";
-import { FC } from "react";
+import { Button, message, Upload } from "antd";
+import { FC, useRef } from "react";
+import { RcFile } from "antd/es/upload";
+import { formatImg } from "@/app/[lng]/publish/components/Choose/ImgChoose.util";
interface ImgChooseProps {
// 单选就使用单选方法,多选就使用单选方法
@@ -33,64 +35,65 @@ export interface IImgFile {
height: number;
}
-// 根据图片在硬盘上的路径获取文件
-// export const getImgFile = async (path: string): Promise<IImgFile> => {
-// const file = await icpGetFileStream(path);
-// return await formatImg({ path, file });
-// };
-
const ImgChoose: FC<ImgChooseProps> = ({
onChoose,
onMultipleChoose,
children,
}) => {
+ const chooseCount = useRef<number>(0);
+ const fileListRef = useRef<RcFile[]>([]);
+
/**
* 发送上传的事件
*/
const handleUploadImg = async () => {
- // TODO 上传图片
- // try {
- // const result: {
- // path: string;
- // file: Uint8Array;
- // }[] = await window.ipcRenderer.invoke(
- // "ICP_VIEWS_CHOSE_IMG",
- // !!onMultipleChoose,
- // );
- // if (!result) return;
- // const tasks: Promise<IImgFile>[] = [];
- // for (const v of result) {
- // tasks.push(formatImg(v));
- // }
- // const imgFiles = await Promise.all(tasks);
- //
- // if (onMultipleChoose) {
- // onMultipleChoose(imgFiles);
- // } else if (onChoose) {
- // onChoose(imgFiles[0]);
- // }
- // } catch (error) {
- // message.error("选择图片失败");
- // console.error(error);
- // }
+ try {
+ const tasks: Promise<IImgFile>[] = [];
+ for (const file of fileListRef.current) {
+ tasks.push(
+ formatImg({
+ path: file.name,
+ blob: file,
+ }),
+ );
+ }
+ const imgFiles = await Promise.all(tasks);
+ if (onMultipleChoose) {
+ onMultipleChoose(imgFiles);
+ } else if (onChoose) {
+ onChoose(imgFiles[0]);
+ }
+ } catch (e) {
+ message.error("选择图片失败");
+ console.error(e);
+ }
};
return (
- <>
+ <Upload
+ accept="image/*"
+ multiple={!!onMultipleChoose}
+ beforeUpload={async (file, uploadFileList) => {
+ chooseCount.current++;
+ fileListRef.current = [...fileListRef.current, file];
+
+ if (chooseCount.current === uploadFileList.length) {
+ await handleUploadImg();
+ fileListRef.current = [];
+ chooseCount.current = 0;
+ }
+
+ return Upload.LIST_IGNORE;
+ }}
+ >
{children ? (
- <div
- className="imgChoose"
- onClick={handleUploadImg}
- style={{ cursor: "pointer" }}
- >
+ <div className="imgChoose" style={{ cursor: "pointer" }}>
{children}
</div>
) : (
- <Button type="primary" onClick={handleUploadImg}>
- 选择图片
- </Button>
+ <Button type="primary">选择图片</Button>
)}
- </>
+ </Upload>
);
};
diff --git a/src/app/[lng]/publish/components/Choose/VideoChoose.tsx b/src/app/[lng]/publish/components/Choose/VideoChoose.tsx
index 63ea2548..4932f204 100644
--- a/src/app/[lng]/publish/components/Choose/VideoChoose.tsx
+++ b/src/app/[lng]/publish/components/Choose/VideoChoose.tsx
@@ -9,7 +9,10 @@ import { Button, message, Upload } from "antd";
import { FC, useRef } from "react";
import { IImgFile } from "@/app/[lng]/publish/components/Choose/ImgChoose";
import { RcFile } from "antd/es/upload";
-import { VideoGrabFrame } from "@/app/[lng]/publish/components/Choose/videoChoose.util";
+import {
+ formatVideo,
+ VideoGrabFrame,
+} from "@/app/[lng]/publish/components/Choose/videoChoose.util";
interface VideoChooseProps {
// 单选就使用单选方法,多选就使用单选方法
@@ -30,8 +33,6 @@ export interface IVideoFile {
// 前端临时路径,注意不要存到数据库
videoUrl: string;
filename: string;
- // 视频在硬盘上的路径
- // videoPath: string;
// 视频宽度
width: number;
// 视频高度
@@ -73,19 +74,6 @@ async function getVideoInfo(videoUrl: string): Promise<{
// };
// };
-const formatVideo = async (file: RcFile): Promise<IVideoFile> => {
- const videoUrl = URL.createObjectURL(file);
- const videoInfo = await VideoGrabFrame(videoUrl, 0);
-
- return {
- filename: file.name,
- videoUrl,
- size: file.size!,
- file: file,
- ...videoInfo,
- };
-};
-
const VideoChoose: FC<VideoChooseProps> = ({
onChoose,
onMultipleChoose,
@@ -136,17 +124,11 @@ const VideoChoose: FC<VideoChooseProps> = ({
}}
>
{children ? (
- <div
- className="videoChoose"
- onClick={handleUploadVideo}
- style={{ cursor: "pointer" }}
- >
+ <div className="videoChoose" style={{ cursor: "pointer" }}>
{children}
</div>
) : (
- <Button type="primary" onClick={handleUploadVideo}>
- 选择视频
- </Button>
+ <Button type="primary">选择视频</Button>
)}
</Upload>
);
diff --git a/src/app/[lng]/publish/components/Choose/videoChoose.util.ts b/src/app/[lng]/publish/components/Choose/videoChoose.util.ts
index ee69333f..2b20bf15 100644
--- a/src/app/[lng]/publish/components/Choose/videoChoose.util.ts
+++ b/src/app/[lng]/publish/components/Choose/videoChoose.util.ts
@@ -1,6 +1,21 @@
// 视频截帧
import { formatImg } from "@/app/[lng]/publish/components/Choose/ImgChoose.util";
import { IImgFile } from "@/app/[lng]/publish/components/Choose/ImgChoose";
+import { RcFile } from "antd/es/upload";
+import { IVideoFile } from "@/app/[lng]/publish/components/Choose/VideoChoose";
+
+export const formatVideo = async (file: RcFile): Promise<IVideoFile> => {
+ const videoUrl = URL.createObjectURL(file);
+ const videoInfo = await VideoGrabFrame(videoUrl, 0);
+
+ return {
+ filename: file.name,
+ videoUrl,
+ size: file.size!,
+ file: file,
+ ...videoInfo,
+ };
+};
export function VideoGrabFrame(
videoUrl: string,
diff --git a/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx b/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx
index 76974c48..81d35e22 100644
--- a/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx
+++ b/src/app/[lng]/publish/videoPage/components/VideoCoverSeting.tsx
@@ -8,13 +8,12 @@ import {
} from "react";
import ImgChoose, { IImgFile } from "../../components/Choose/ImgChoose";
import styles from "./videoCoverSeting.module.scss";
-import { Alert, Button, message, Modal, Slider, Spin } from "antd";
+import { Alert, Button, Modal, Slider, Spin } from "antd";
import { IVideoFile } from "../../components/Choose/VideoChoose";
import Cropper from "cropperjs";
import "cropperjs/dist/cropper.css";
import { useVideoPageStore } from "@/app/[lng]/publish/videoPage/useVideoPageStore";
import { useShallow } from "zustand/react/shallow";
-import { CloseCircleOutlined } from "@ant-design/icons";
import { formatImg } from "@/app/[lng]/publish/components/Choose/ImgChoose.util";
import { VideoGrabFrame } from "@/app/[lng]/publish/components/Choose/videoChoose.util";
@@ -28,9 +27,10 @@ export interface IVideoCoverSetingProps {
// 需要截帧的视频
videoFile?: IVideoFile;
// 保存图片的唯一值
- saveImgId: string;
+ saveImgId?: string;
// 关闭按钮点击事件,如果有这个事件就会显示关闭按钮
- onClose?: () => void;
+ onClose: () => void;
+ videoCoverSetingModal: boolean;
}
// 视频封面设置
@@ -38,16 +38,16 @@ const VideoCoverSeting = memo(
forwardRef(
(
{
+ videoCoverSetingModal,
onChoosed,
value,
videoFile,
- saveImgId,
+ saveImgId = "",
onClose,
}: IVideoCoverSetingProps,
ref: ForwardedRef<IVideoCoverSetingRef>,
) => {
const [imgFile, setImgFile] = useState<IImgFile>();
- const [videoCoverSetingModal, setVideoCoverSetingModal] = useState(false);
const cropper = useRef<Cropper>();
const cropperImg = useRef<HTMLImageElement>(null);
const [videoCoverLoading, setVideoCoverLoading] = useState(false);
@@ -81,7 +81,7 @@ const VideoCoverSeting = memo(
};
const close = () => {
- setVideoCoverSetingModal(false);
+ onClose();
};
// 初始化裁剪工具
@@ -111,30 +111,30 @@ const VideoCoverSeting = memo(
return (
<>
- <div
- className={styles.videoCoverSeting}
- onClick={() => {
- if (!videoFile) return message.warning("您必须上传一个视频!");
- setVideoCoverSetingModal(true);
- }}
- >
- <div className="videoCoverSeting-img">
- {value && (
- <div className="videoCoverSeting-choosed">
- <img src={value?.imgUrl} />
- {onClose && (
- <CloseCircleOutlined
- onClick={(e) => {
- e.stopPropagation();
- onClose();
- }}
- />
- )}
- </div>
- )}
- </div>
- <div className="videoCoverSeting-text">上传图片</div>
- </div>
+ {/*<div*/}
+ {/* className={styles.videoCoverSeting}*/}
+ {/* onClick={() => {*/}
+ {/* if (!videoFile) return message.warning("您必须上传一个视频!");*/}
+ {/* setVideoCoverSetingModal(true);*/}
+ {/* }}*/}
+ {/*>*/}
+ {/* <div className="videoCoverSeting-img">*/}
+ {/* {value && (*/}
+ {/* <div className="videoCoverSeting-choosed">*/}
+ {/* <img src={value?.imgUrl} />*/}
+ {/* {onClose && (*/}
+ {/* <CloseCircleOutlined*/}
+ {/* onClick={(e) => {*/}
+ {/* e.stopPropagation();*/}
+ {/* onClose();*/}
+ {/* }}*/}
+ {/* />*/}
+ {/* )}*/}
+ {/* </div>*/}
+ {/* )}*/}
+ {/* </div>*/}
+ {/* <div className="videoCoverSeting-text">上传图片</div>*/}
+ {/*</div>*/}
<Modal
width={600}
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
new file mode 100644
index 00000000..67ef47d9
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/index.tsx
@@ -0,0 +1,28 @@
+import { ForwardedRef, forwardRef, memo } from "react";
+import styles from "./platParamsSetting.module.scss";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
+
+export interface IPlatParamsSettingRef {}
+
+export interface IPlatParamsSettingProps {}
+
+const PlatParamsSetting = memo(
+ forwardRef(
+ ({}: IPlatParamsSettingProps, ref: ForwardedRef<IPlatParamsSettingRef>) => {
+ return (
+ <div className={styles.platParamsSetting}>
+ <PubParmasTextarea
+ onChange={(v) => {
+ console.log(v);
+ }}
+ onUpload={(files) => {
+ console.log(files);
+ }}
+ />
+ </div>
+ );
+ },
+ ),
+);
+
+export default PlatParamsSetting;
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss b/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss
new file mode 100644
index 00000000..191a0f9f
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/platParamsSetting.module.scss
@@ -0,0 +1,3 @@
+.platParamsSetting {
+
+}
\ No newline at end of file
diff --git a/src/components/PublishDialog/plats/BilibParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
similarity index 77%
rename from src/components/PublishDialog/plats/BilibParams.tsx
rename to src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
index 8b99fa32..aca00ac1 100644
--- a/src/components/PublishDialog/plats/BilibParams.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/BilibParams.tsx
@@ -2,7 +2,7 @@ import { ForwardedRef, forwardRef, memo } from "react";
import {
IPlatsParamsProps,
IPlatsParamsRef,
-} from "@/components/PublishDialog/plats/plats.type";
+} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
const BilibParams = memo(
forwardRef(({}: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
diff --git a/src/components/PublishDialog/plats/KwaiParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
similarity index 77%
rename from src/components/PublishDialog/plats/KwaiParams.tsx
rename to src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
index 78c0fe02..b0a4d1e2 100644
--- a/src/components/PublishDialog/plats/KwaiParams.tsx
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/KwaiParams.tsx
@@ -2,7 +2,7 @@ import { ForwardedRef, forwardRef, memo } from "react";
import {
IPlatsParamsProps,
IPlatsParamsRef,
-} from "@/components/PublishDialog/plats/plats.type";
+} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
const KwaiParams = memo(
forwardRef(({}: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
diff --git a/src/components/PublishDialog/plats/plats.type.ts b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts
similarity index 100%
rename from src/components/PublishDialog/plats/plats.type.ts
rename to src/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type.ts
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
new file mode 100644
index 00000000..204665af
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/index.tsx
@@ -0,0 +1,393 @@
+import React, {
+ ForwardedRef,
+ forwardRef,
+ memo,
+ useCallback,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
+import { Button, Image, Input, message, Modal, Tooltip, Upload } from "antd";
+import styles from "@/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss";
+import { ReactSortable } from "react-sortablejs";
+import { CSSTransition, TransitionGroup } from "react-transition-group";
+import {
+ CaretRightOutlined,
+ CloseOutlined,
+ PlusOutlined,
+} from "@ant-design/icons";
+import { IVideoFile } from "@/app/[lng]/publish/components/Choose/VideoChoose";
+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";
+
+const { TextArea } = Input;
+const { Dragger } = Upload;
+
+export interface IPubParmasTextareaRef {}
+
+export interface IPubParmasTextareaProps {
+ onChange: (value: string) => void;
+ // 上传change
+ onUpload: (files: { imgs?: IImgFile[]; video?: IVideoFile }) => void;
+ rows?: number;
+ // 视频数量限制
+ videoMax?: number;
+ // 图片数量限制
+ imageMax?: number;
+ // 扩展内容
+ extend?: React.ReactNode;
+}
+
+const PubParmasTextarea = memo(
+ forwardRef(
+ (
+ {
+ onChange,
+ onUpload,
+ rows = 12,
+ videoMax = 1,
+ imageMax = 20,
+ extend,
+ }: IPubParmasTextareaProps,
+ ref: ForwardedRef<IPubParmasTextareaRef>,
+ ) => {
+ const [value, setValue] = useState("");
+ const [previewData, setPreviewData] = useState<
+ IImgFile | IVideoFile | undefined
+ >(undefined);
+ // 图片
+ const [imageFileList, setImageFileList] = useState<IImgFile[]>([]);
+ // 视频
+ const [videoFile, setVideoFile] = useState<IVideoFile | undefined>(
+ undefined,
+ );
+ const [videoCoverSetingModal, setVideoCoverSetingModal] = useState(false);
+
+ // 动态accept类型
+ const uploadAccept = useMemo(() => {
+ const hasImage = imageFileList.length !== 0;
+ const hasVideo = !!videoFile;
+ if (hasImage && !hasVideo) return "image/*";
+ if (!hasImage && hasVideo) return "video/*";
+ return "image/*,video/*";
+ }, [imageFileList, videoFile]);
+
+ // 是否可见Dragger
+ const canShowDragger = useMemo(() => {
+ const imageCount = imageFileList.length;
+ const videoCount = videoFile ? 1 : 0;
+ const hasImage = imageCount > 0;
+ const hasVideo = videoCount > 0;
+
+ if (hasImage && imageCount >= imageMax) return false;
+ if (hasVideo && videoCount >= videoMax) return false;
+ // 视频和图片都没有,或者只选一种且未到上限
+ 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[]) => {
+ const hasImageInList = imageFileList.length !== 0;
+ const hasVideoInList = !!videoFile;
+ let uploadHasImage = false;
+ let uploadHasVideo = false;
+ let invalidFile = false;
+
+ for (const file of fileList) {
+ if (file.type.startsWith("image/")) {
+ uploadHasImage = true;
+ } else if (file.type.startsWith("video/")) {
+ uploadHasVideo = true;
+ } else {
+ invalidFile = true;
+ }
+ }
+
+ const messageOpen = (content: string) => {
+ message.open({
+ content: content,
+ type: "warning",
+ key: "1",
+ });
+ };
+
+ // 已有图片,只能传图片
+ if (hasImageInList && !hasVideoInList && uploadHasVideo) {
+ messageOpen("已有图片,仅可继续上传图片,不能上传视频!");
+ return false;
+ }
+ // 已有视频,只能传视频
+ if (hasVideoInList && !hasImageInList && uploadHasImage) {
+ messageOpen("已有视频,仅可继续上传视频,不能上传图片!");
+ return false;
+ }
+ // 混合上传拦截
+ if (
+ (uploadHasImage && uploadHasVideo) ||
+ (hasImageInList && uploadHasVideo) ||
+ (hasVideoInList && uploadHasImage)
+ ) {
+ messageOpen("图片和视频不能混合上传!");
+ return false;
+ }
+ // 非法类型
+ if (invalidFile) {
+ messageOpen("只能上传图片或视频文件!");
+ return false;
+ }
+ if (uploadHasVideo) {
+ // 视频条数限制
+ const totalVideoCount =
+ (videoFile ? 1 : 0) +
+ fileList.filter((f) => f.type.startsWith("video/")).length;
+ if (totalVideoCount > videoMax) {
+ messageOpen(`视频上传数量不能大于${videoMax}`);
+ return false;
+ }
+ }
+ if (uploadHasImage) {
+ // 图片条数限制
+ const totalImageCount =
+ imageFileList.length +
+ fileList.filter((f) => f.type.startsWith("image/")).length;
+ if (totalImageCount > imageMax) {
+ messageOpen(`图片上传数量不能大于${imageMax}`);
+ return false;
+ }
+ }
+ return true;
+ },
+ [imageFileList, videoMax, imageMax, videoFile],
+ );
+
+ return (
+ <>
+ <VideoCoverSeting
+ videoCoverSetingModal={videoCoverSetingModal}
+ onClose={() => setVideoCoverSetingModal(false)}
+ videoFile={videoFile}
+ value={videoFile?.cover}
+ onChoosed={(newCover) => {
+ setVideoFile((prevState) => {
+ const newState = { ...(prevState as IVideoFile) };
+ newState.cover = newCover;
+ return newState;
+ });
+ }}
+ />
+
+ <Modal
+ title="查看素材"
+ open={!!previewData}
+ onCancel={() => setPreviewData(undefined)}
+ >
+ {previewData && (
+ <>
+ {previewData!.file.type.startsWith("video") ? (
+ <video
+ src={(previewData as IVideoFile).videoUrl}
+ controls={true}
+ style={{ width: "100%", maxHeight: "600px" }}
+ />
+ ) : (
+ <Image
+ src={(previewData as IImgFile).imgUrl}
+ style={{ width: "100%" }}
+ />
+ )}
+ </>
+ )}
+ </Modal>
+
+ <div className={styles.pubParmasTextarea}>
+ <div className="pubParmasTextarea-input">
+ <TextArea
+ placeholder="开始写"
+ value={value}
+ onChange={(e) => setValue(e.target.value)}
+ rows={rows}
+ />
+ <ReactSortable
+ className="pubParmasTextarea-uploads"
+ list={imageFileList}
+ animation={250}
+ setList={setImageFileList}
+ scrollSensitivity={100}
+ scrollSpeed={15}
+ id="id"
+ >
+ <TransitionGroup
+ className="pubParmasTextarea-uploads-list"
+ component={null}
+ >
+ {/* 图像 ------------------------------------------- */}
+ {imageFileList.map((v, i) => (
+ <CSSTransition
+ key={v.id}
+ timeout={300}
+ classNames={{
+ enter: styles.itemEnter,
+ enterActive: styles.itemEnterActive,
+ exit: styles.itemExit,
+ exitActive: styles.itemExitActive,
+ }}
+ >
+ <div
+ className="pubParmasTextarea-uploads-item"
+ onClick={() => {
+ setPreviewData(v);
+ }}
+ >
+ <div
+ className="pubParmasTextarea-uploads-item-close"
+ onClick={(e) => {
+ e.stopPropagation();
+ setImageFileList((prevState) => {
+ const newState = [...prevState];
+ newState.splice(i, 1);
+ return newState;
+ });
+ }}
+ >
+ <CloseOutlined />
+ </div>
+ <Tooltip title="点击查看">
+ <img src={v.imgUrl} />
+ </Tooltip>
+ </div>
+ </CSSTransition>
+ ))}
+
+ {/* 视频 ------------------------------------------- */}
+ {(videoFile ? [videoFile] : []).map((v, i) => {
+ return (
+ <CSSTransition
+ timeout={300}
+ classNames={{
+ enter: styles.itemEnter,
+ enterActive: styles.itemEnterActive,
+ exit: styles.itemExit,
+ exitActive: styles.itemExitActive,
+ }}
+ key={i}
+ >
+ <div
+ className="pubParmasTextarea-uploads-item"
+ onClick={() => {
+ setPreviewData(videoFile);
+ }}
+ >
+ <div
+ className="pubParmasTextarea-uploads-item-close"
+ onClick={(e) => {
+ e.stopPropagation();
+ setVideoFile(undefined);
+ }}
+ >
+ <CloseOutlined />
+ </div>
+ <Tooltip title="点击查看">
+ <div className="pubParmasTextarea-uploads-item-video">
+ <img src={v.cover.imgUrl} />
+ <div className="pubParmasTextarea-uploads-item-play">
+ <CaretRightOutlined />
+ </div>
+ </div>
+ </Tooltip>
+ </div>
+ </CSSTransition>
+ );
+ })}
+
+ {canShowDragger && (
+ <CSSTransition
+ key="dragger"
+ timeout={300}
+ classNames={{
+ enter: styles.itemEnter,
+ enterActive: styles.itemEnterActive,
+ exit: styles.itemExit,
+ exitActive: styles.itemExitActive,
+ }}
+ unmountOnExit
+ >
+ <Tooltip title="上传图片或视频">
+ <div onClick={(e) => e.stopPropagation()}>
+ <Dragger
+ accept={uploadAccept}
+ multiple={true}
+ listType="text"
+ beforeUpload={async (file, fileList) => {
+ if (!checkFileListType(fileList)) {
+ return Upload.LIST_IGNORE;
+ }
+ if (file.type.startsWith("video/")) {
+ // 视频
+ const video = await formatVideo(file);
+ // 封面
+ setVideoFile(video);
+ } else {
+ // 图片
+ const image = await formatImg({
+ blob: file!,
+ path: file.name,
+ });
+ setImageFileList((prevState) => {
+ const newState = [...prevState];
+ newState.push(image);
+ return newState;
+ });
+ }
+ return false;
+ }}
+ showUploadList={false}
+ >
+ <PlusOutlined />
+ <p>拖放 & 选择图片或视频</p>
+ </Dragger>
+ </div>
+ </Tooltip>
+ </CSSTransition>
+ )}
+ </TransitionGroup>
+ </ReactSortable>
+
+ {videoFile && (
+ <Button
+ style={{ marginTop: "10px" }}
+ onClick={() => setVideoCoverSetingModal(true)}
+ >
+ 裁剪封面
+ </Button>
+ )}
+ </div>
+
+ <div className="pubParmasTextarea-menus">
+ <div className="pubParmasTextarea-menus-item">1</div>
+ </div>
+
+ {extend && <div className="pubParmasTextarea-other">{extend}</div>}
+ </div>
+ </>
+ );
+ },
+ ),
+);
+
+export default PubParmasTextarea;
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss b/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss
new file mode 100644
index 00000000..9ce38a35
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/pubCommonComps.module.scss
@@ -0,0 +1,122 @@
+.pubParmasTextarea {
+ border: 1px solid var(--grayColor4);
+ border-radius: 6px;
+
+ :global {
+ .pubParmasTextarea-input {
+ padding: 15px;
+ textarea {
+ resize: none;
+ border-radius: 3px;
+ border: none;
+ box-shadow: none;
+ padding: 0;
+ }
+ }
+
+ .ant-upload-wrapper {
+ display: block;
+ width: 100px;
+ height: 100px;
+ p {
+ font-size: 12px;
+ }
+ .ant-upload-list {
+ display: none;
+ }
+ }
+
+ .pubParmasTextarea-uploads {
+ display: grid;
+ grid-template-columns: repeat(6, 1fr);
+ flex-wrap: wrap;
+ gap: 15px;
+ &-item {
+ //width: 98px;
+ height: 100px;
+ border: 1px solid var(--grayColor4);
+ border-radius: 4px;
+ box-sizing: border-box;
+ cursor: pointer;
+ position: relative;
+ img, video {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ }
+ &-video {
+ width: 100%;
+ height: 100%;
+ }
+ &-play {
+ position: absolute;
+ bottom: 5px;
+ left: 5px;
+ color: #fff;
+ background: rgba(255, 255, 255, 0.6);
+ border-radius: 50%;
+ width: 25px;
+ height: 25px;
+ font-size: 20px;
+ text-align: center;
+ line-height: 25px;
+ }
+ &-close {
+ color: #fff;
+ background: rgba(0, 0, 0, 0.8);
+ width: 24px;
+ height: 24px;
+ text-align: center;
+ line-height: 20px;
+ border-radius: 50%;
+ font-size: var(--fs-xs);
+ position: absolute;
+ right: -5px;
+ top: -5px;
+ border: 2px solid #fff;
+ transform: scale(1);
+ transition: 0.3s;
+ z-index: 10;
+ &:hover {
+ transform: scale(1.1);
+ }
+ }
+ }
+ }
+
+ .pubParmasTextarea-menus {
+ display: flex;
+ border-top: 1px solid var(--grayColor4);
+ padding: 15px 0;
+ &-item {
+ border-right: 1px solid var(--grayColor4);
+ display: flex;
+ padding: 0 20px;
+ }
+ }
+
+ .pubParmasTextarea-other {
+ border-top: 1px solid var(--grayColor4);
+ }
+ }
+}
+
+// 上传项动画
+.itemEnter {
+ opacity: 0;
+ transform: scale(0.8);
+}
+.itemEnterActive {
+ opacity: 1;
+ transform: scale(1);
+ transition: opacity 300ms, transform 300ms;
+}
+.itemExit {
+ opacity: 1;
+ transform: scale(1);
+}
+.itemExitActive {
+ opacity: 0;
+ transform: scale(0.8);
+ transition: opacity 300ms, transform 300ms;
+}
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.type.ts b/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.type.ts
new file mode 100644
index 00000000..59f081bc
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.type.ts
@@ -0,0 +1,5 @@
+export interface FileItem {
+ id: string;
+ file: File;
+ url: string;
+}
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.utils.ts b/src/components/PublishDialog/compoents/PubParmasTextarea/pubParmasTextarea.utils.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsx
index 589f0ba5..69d970d1 100644
--- a/src/components/PublishDialog/index.tsx
+++ b/src/components/PublishDialog/index.tsx
@@ -17,6 +17,7 @@ import { AccountPlatInfoMap } from "@/app/config/platConfig";
import AvatarPlat from "@/components/AvatarPlat";
import { usePublishDialog } from "@/components/PublishDialog/usePublishDialog";
import { useShallow } from "zustand/react/shallow";
+import PlatParamsSetting from "@/components/PublishDialog/compoents/PlatParamsSetting";
export interface IPublishDialogRef {}
@@ -140,23 +141,26 @@ const PublishDialog = memo(
})}
</div>
- {step === 0 ? (
- <>
- {accountChoosed.length === 0 && (
- <div className="publishDialog-con-tips">
- 你的工作被保存了,选择一个账号来创建一个帖子。
- </div>
- )}
- {accountChoosed.length == 1 && (
- <div style={{ height: "500px" }}>{accountChoosed[0].type}</div>
- )}
- {accountChoosed.length >= 2 && (
- <div style={{ height: "500px" }}>通用参数</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>
+ )}
+ {accountChoosed.length >= 2 && (
+ <div style={{ height: "500px" }}>通用参数</div>
+ )}
+ </>
+ ) : (
+ <>第二步</>
+ )}
+ </div>
</div>
<div className="publishDialog-footer">
time
diff --git a/src/components/PublishDialog/publishDialog.module.scss b/src/components/PublishDialog/publishDialog.module.scss
index 0a82325e..5edfed24 100644
--- a/src/components/PublishDialog/publishDialog.module.scss
+++ b/src/components/PublishDialog/publishDialog.module.scss
@@ -67,6 +67,10 @@ $assistantWidth: 300px;
color: var(--grayColor7);
}
}
+ .publishDialog-paramsSet {
+ max-height: 600px;
+ overflow: auto;
+ }
.publishDialog-footer {
display: flex;
align-items: center;