Skip to content

Let's use AI to Earn!

feat: 【发布作品】图片和视频预览完成

gaoSir4d6e275ebfa6
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 38fc1af3..7fa50d54 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,13 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="fix: 【PubParmasTextarea.tsx】修复了初始化后会执行onChange的bug">
+ <list default="true" id="90ed3383-49aa-4e32-95a2-9f070c0da49b" name="更改" comment="feat: 1. 【发布作品弹框】填写发布参数时未选中的账户参数自动填写。&#10;2. 【发布作品弹框】切换步骤0-&gt;1保持展开状态">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PublishDialogPreview.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/PublishDialog/compoents/PublishDialogPreview.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.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" />
@@ -107,7 +111,8 @@
<workItem from="1750932869295" duration="11763000" />
<workItem from="1750989950480" duration="7000" />
<workItem from="1750989966702" duration="688000" />
- <workItem from="1751010085244" duration="5249000" />
+ <workItem from="1751010085244" duration="6172000" />
+ <workItem from="1751023561603" duration="2850000" />
</task>
<task id="LOCAL-00001" summary="feat: 日历完善">
<option name="closed" value="true" />
@@ -229,7 +234,15 @@
<option name="project" value="LOCAL" />
<updated>1751013073544</updated>
</task>
- <option name="localTasksCounter" value="16" />
+ <task id="LOCAL-00016" summary="feat: 1. 【发布作品弹框】填写发布参数时未选中的账户参数自动填写。&#10;2. 【发布作品弹框】切换步骤0-&gt;1保持展开状态">
+ <option name="closed" value="true" />
+ <created>1751018123318</created>
+ <option name="number" value="00016" />
+ <option name="presentableId" value="LOCAL-00016" />
+ <option name="project" value="LOCAL" />
+ <updated>1751018123318</updated>
+ </task>
+ <option name="localTasksCounter" value="17" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -264,6 +277,7 @@
<MESSAGE value="feat: 【发布弹框】展开和隐藏、光标自动聚焦和自动到最后一位" />
<MESSAGE value="feat: 【发布弹框】参数校验完成" />
<MESSAGE value="fix: 【PubParmasTextarea.tsx】修复了初始化后会执行onChange的bug" />
- <option name="LAST_COMMIT_MESSAGE" value="fix: 【PubParmasTextarea.tsx】修复了初始化后会执行onChange的bug" />
+ <MESSAGE value="feat: 1. 【发布作品弹框】填写发布参数时未选中的账户参数自动填写。&#10;2. 【发布作品弹框】切换步骤0-&gt;1保持展开状态" />
+ <option name="LAST_COMMIT_MESSAGE" value="feat: 1. 【发布作品弹框】填写发布参数时未选中的账户参数自动填写。&#10;2. 【发布作品弹框】切换步骤0-&gt;1保持展开状态" />
</component>
</project>
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 8922ad89..260f0d4a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -39,6 +39,7 @@
"react-transition-group": "^4.4.5",
"sass": "^1.59.2",
"sortablejs": "^1.15.6",
+ "swiper": "^11.2.8",
"zustand": "^5.0.5"
},
"devDependencies": {
@@ -7246,6 +7247,25 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/swiper": {
+ "version": "11.2.8",
+ "resolved": "https://registry.npmjs.org/swiper/-/swiper-11.2.8.tgz",
+ "integrity": "sha512-S5FVf6zWynPWooi7pJ7lZhSUe2snTzqLuUzbd5h5PHUOhzgvW0bLKBd2wv0ixn6/5o9vwc/IkQT74CRcLJQzeg==",
+ "funding": [
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/swiperjs"
+ },
+ {
+ "type": "open_collective",
+ "url": "http://opencollective.com/swiper"
+ }
+ ],
+ "license": "MIT",
+ "engines": {
+ "node": ">= 4.7.0"
+ }
+ },
"node_modules/synckit": {
"version": "0.11.6",
"resolved": "https://registry.npmmirror.com/synckit/-/synckit-0.11.6.tgz",
diff --git a/package.json b/package.json
index 656cbe4e..5c3b47d3 100644
--- a/package.json
+++ b/package.json
@@ -35,6 +35,7 @@
"idb-keyval": "^6.2.2",
"lodash": "^4.17.21",
"next": "14.2.29",
+ "swiper": "^11.2.8",
"next-sitemap": "^4.2.3",
"qs": "^6.14.0",
"react": "^18",
diff --git a/src/components/PublishDialog/compoents/PublishDialogPreview.tsx b/src/components/PublishDialog/compoents/PublishDialogPreview.tsx
index d4182c7a..09d31d91 100644
--- a/src/components/PublishDialog/compoents/PublishDialogPreview.tsx
+++ b/src/components/PublishDialog/compoents/PublishDialogPreview.tsx
@@ -1,6 +1,12 @@
-import { ForwardedRef, forwardRef, memo } from "react";
+import { ForwardedRef, forwardRef, memo, useEffect, useRef } from "react";
import styles from "../publishDialog.module.scss";
import { Empty } from "antd";
+import { usePublishDialog } from "@/components/PublishDialog/usePublishDialog";
+import { useShallow } from "zustand/react/shallow";
+import { Swiper, SwiperSlide } from "swiper/react";
+import { Navigation, Pagination } from "swiper/modules";
+import "swiper/css";
+import "swiper/css/pagination";
export interface IPublishDialogPreviewRef {}
@@ -12,13 +18,74 @@ const PublishDialogPreview = memo(
{}: IPublishDialogPreviewProps,
ref: ForwardedRef<IPublishDialogPreviewRef>,
) => {
+ const { expandedPubItem } = usePublishDialog(
+ useShallow((state) => ({
+ expandedPubItem: state.expandedPubItem,
+ pubList: state.pubList,
+ })),
+ );
+ const videoRef = useRef<HTMLVideoElement>(null);
+
+ useEffect(() => {
+ if (!expandedPubItem) {
+ videoRef.current?.pause();
+ }
+ }, [expandedPubItem]);
+
return (
<div className={styles.publishDialogPreview}>
<div className="publishDialogPreview-wrapper">
<div className="publishDialogPreview-title">预览</div>
- <div className="publishDialogPreview-empty">
- <Empty description="在这里看到你的作品预览" />
- </div>
+ {expandedPubItem?.params.video ||
+ expandedPubItem?.params.images?.length !== 0 ? (
+ <div className="publishDialogPreview-preview">
+ {expandedPubItem?.params.video ? (
+ <div className="publishDialogPreview-preview-video">
+ <div className="publishDialogPreview-preview-video-wrapper">
+ <div className="publishDialogPreview-preview-video-top" />
+ <video
+ ref={videoRef}
+ src={expandedPubItem.params.video?.videoUrl}
+ controls
+ poster={expandedPubItem.params.video?.cover.imgUrl}
+ />
+ </div>
+ </div>
+ ) : (
+ <div className="publishDialogPreview-preview-video">
+ <div className="publishDialogPreview-preview-video-wrapper">
+ <div className="publishDialogPreview-preview-video-top" />
+ <div className="publishDialogPreview-preview-images">
+ <Swiper
+ loop={true}
+ modules={[Navigation, Pagination]}
+ pagination={{
+ clickable: true,
+ el: ".swiper-pagination",
+ }}
+ >
+ {expandedPubItem!.params.images!.map(
+ (image, index) => (
+ <SwiperSlide key={index}>
+ <img
+ src={image.imgUrl}
+ alt={`Image ${index + 1}`}
+ />
+ </SwiperSlide>
+ ),
+ )}
+ </Swiper>
+ <div className="swiper-pagination"></div>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ ) : (
+ <div className="publishDialogPreview-empty">
+ <Empty description="在这里看到你的作品预览" />
+ </div>
+ )}
</div>
</div>
);
diff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsx
index dbbec2f0..544949c9 100644
--- a/src/components/PublishDialog/index.tsx
+++ b/src/components/PublishDialog/index.tsx
@@ -139,7 +139,9 @@ const PublishDialog = memo(
<div
className="publishDialog-wrapper"
onClick={() => {
- setExpandedPubItem(undefined);
+ if (step === 1) {
+ setExpandedPubItem(undefined);
+ }
}}
>
<div className="publishDialog-con">
diff --git a/src/components/PublishDialog/publishDialog.module.scss b/src/components/PublishDialog/publishDialog.module.scss
index f0efe072..6ee2caf4 100644
--- a/src/components/PublishDialog/publishDialog.module.scss
+++ b/src/components/PublishDialog/publishDialog.module.scss
@@ -1,4 +1,4 @@
-$assistantWidth: 300px;
+$assistantWidth: 330px;
.publishDialog {
width: auto !important;
@@ -130,6 +130,59 @@ $assistantWidth: 300px;
.publishDialogPreview {
margin-left: 15px;
:global {
+ .publishDialogPreview-preview {
+ padding: 20px;
+ &-images {
+ background: #fff;
+ height: 100%;
+ box-sizing: border-box;
+ padding: 30px 10px 0;
+ display: flex;
+ align-items: center;
+ .swiper-pagination-bullet {
+ background: var(--colorPrimary5);
+ }
+ img {
+ width: 100%;
+ }
+ }
+ &-video {
+ background: black;
+ border-radius: 30px;
+ overflow: hidden;
+ box-sizing: border-box;
+ position: relative;
+ width: 100%;
+ height: 510px;
+ &-wrapper {
+ margin: 5px;
+ box-sizing: border-box;
+ height: 100%;
+ border-radius: 30px;
+ overflow: hidden;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ }
+ &-top {
+ position: absolute;
+ width: 50%;
+ height: 20px;
+ z-index: 10;
+ border-radius: 0 0 15px 15px;
+ top: 0;
+ left: 50%;
+ transform: translateX(-50%);
+ background: black;
+ }
+ video {
+ width: 100%;
+ max-height: 100%;
+ object-fit: cover;
+ border-radius: 0;
+ }
+ }
+ }
.publishDialogPreview-wrapper {
text-align: left;
min-width: $assistantWidth;
diff --git a/src/components/PublishDialog/usePublishDialog.ts b/src/components/PublishDialog/usePublishDialog.ts
index 2021cb4e..69aa1bf9 100644
--- a/src/components/PublishDialog/usePublishDialog.ts
+++ b/src/components/PublishDialog/usePublishDialog.ts
@@ -121,6 +121,11 @@ export const usePublishDialog = create(
pubList,
commonPubParams,
pubListChoosed,
+ expandedPubItem: get().expandedPubItem
+ ? pubList.find(
+ (v) => v.account.id === get().expandedPubItem!.account.id,
+ )
+ : undefined,
});
},
@@ -154,6 +159,11 @@ export const usePublishDialog = create(
set({
pubList,
pubListChoosed,
+ expandedPubItem: get().expandedPubItem
+ ? pubList.find(
+ (v) => v.account.id === get().expandedPubItem!.account.id,
+ )
+ : undefined,
});
},
};