Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
素材库 草稿箱问题
daoyiandfe739f9833d
diff --git a/src/app/i18n/locales/en/publish.json b/src/app/i18n/locales/en/publish.jsonindex 8ad30daf..1dec59f5 100644--- a/src/app/i18n/locales/en/publish.json+++ b/src/app/i18n/locales/en/publish.json@@ -1,19 +1,19 @@{- "title": "Publish",+ "title": "Publish Work","confirmClose": {- "title": "Discard changes?",- "content": "All changes will be lost"+ "title": "Confirm Close",+ "content": "After closing, the filled content will be lost. Are you sure to close?"},"buttons": {"customizePerAccount": "Customize per account",- "cancelPublish": "Cancel",- "schedulePublish": "Publish now",+ "cancelPublish": "Cancel Publish",+ "schedulePublish": "Schedule Publish","publishNow": "Publish now","copyLink": "Copy link","delete": "Delete"},"tips": {- "workSaved": "Work saved. Select an account to create a post."+ "workSaved": "Please select the account to publish"},"status": {"publishFailed": "Failed",@@ -64,14 +64,21 @@"emptyDescription": "See your work preview here"},"draft": {- "selectDraft": "Select draft",- "selectDraftGroup": "Select draft group",- "selectDraftItem": "Select draft",- "noDraftGroups": "No draft groups",- "noDrafts": "No drafts in this group",- "backToGroups": "Back to groups",- "selectDraftSuccess": "Draft applied",- "imageGroup": "Image group",- "videoGroup": "Video group"+ "selectDraft": "Select Draft",+ "selectDraftGroup": "Select Draft Group",+ "selectDraftItem": "Select Draft",+ "noDraftGroups": "No Draft Groups",+ "noDrafts": "No Drafts in This Group",+ "backToGroups": "Back to Groups",+ "selectDraftSuccess": "Draft Applied",+ "imageGroup": "Image Group",+ "videoGroup": "Video Group",+ "selectLibrary": "Select Library",+ "selectLibraryItem": "Select Material",+ "selectLibraryGroup": "Select Library Group",+ "noLibraryGroups": "No Library Groups",+ "backToLibraryGroups": "Back to Library Groups",+ "noLibraryItems": "No Materials in This Group",+ "selectLibrarySuccess": "Material Applied"}}\ No newline at end of filediff --git a/src/app/i18n/locales/zh-CN/publish.json b/src/app/i18n/locales/zh-CN/publish.jsonindex e7142aa6..c7cd3315 100644--- a/src/app/i18n/locales/zh-CN/publish.json+++ b/src/app/i18n/locales/zh-CN/publish.json@@ -1,19 +1,19 @@{"title": "发布作品","confirmClose": {- "title": "放弃更改?",- "content": "您所做的任何更改都将永久丢失"+ "title": "确认关闭",+ "content": "关闭后,已填写的内容将丢失,是否确认关闭?"},"buttons": {- "customizePerAccount": "针对每个账户进行定制",+ "customizePerAccount": "自定义每个账户","cancelPublish": "取消发布",- "schedulePublish": "立即发布",+ "schedulePublish": "定时发布","publishNow": "立即发布","copyLink": "复制链接","delete": "删除"},"tips": {- "workSaved": "你的工作被保存了,选择一个账号来创建一个帖子。"+ "workSaved": "请选择要发布的账户"},"status": {"publishFailed": "发布失败",@@ -72,6 +72,13 @@"backToGroups": "返回草稿箱组","selectDraftSuccess": "草稿已应用","imageGroup": "图文组",- "videoGroup": "视频组"+ "videoGroup": "视频组",+ "selectLibrary": "选择素材库",+ "selectLibraryItem": "选择素材",+ "selectLibraryGroup": "选择素材库组",+ "noLibraryGroups": "暂无素材库组",+ "backToLibraryGroups": "返回素材库组",+ "noLibraryItems": "该组暂无素材",+ "selectLibrarySuccess": "素材已应用"}}\ No newline at end of filediff --git a/src/components/PublishDialog/index.tsx b/src/components/PublishDialog/index.tsxindex e2d4d9b2..1736b726 100644--- a/src/components/PublishDialog/index.tsx+++ b/src/components/PublishDialog/index.tsx@@ -10,7 +10,7 @@ import {} from "react";import styles from "./publishDialog.module.scss";import { Button, message, Modal, List, Spin } from "antd";-import { ArrowRightOutlined, ExclamationCircleFilled, FileTextOutlined, FolderOpenOutlined } from "@ant-design/icons";+import { ArrowRightOutlined, ExclamationCircleFilled, FileTextOutlined, FolderOpenOutlined, PictureOutlined } from "@ant-design/icons";import PublishDialogAi from "@/components/PublishDialog/compoents/PublishDialogAi";import PublishDialogPreview from "@/components/PublishDialog/compoents/PublishDialogPreview";import { CSSTransition } from "react-transition-group";@@ -32,6 +32,7 @@ import {import { generateUUID } from "@/utils";import { useTransClient } from "@/app/i18n/client";import { apiGetMaterialGroupList, apiGetMaterialList, MaterialType } from "@/api/material";+import { getMediaGroupList, getMediaList } from "@/api/media";import { getOssUrl } from "@/utils/oss";export interface IPublishDialogRef {@@ -112,6 +113,14 @@ const PublishDialog = memo(const [draftLoading, setDraftLoading] = useState(false);const [drafts, setDrafts] = useState<any[]>([]);+ // 素材库选择弹窗/数据+ const [libraryModalOpen, setLibraryModalOpen] = useState(false);+ const [libraryGroupLoading, setLibraryGroupLoading] = useState(false);+ const [libraryGroups, setLibraryGroups] = useState<any[]>([]);+ const [selectedLibraryGroup, setSelectedLibraryGroup] = useState<any | null>(null);+ const [libraryLoading, setLibraryLoading] = useState(false);+ const [libraryItems, setLibraryItems] = useState<any[]>([]);+// 过滤可用类型(根据当前步骤和账户选择)const allowImage = useMemo(() => {if (step === 1 && expandedPubItem) {@@ -165,6 +174,36 @@ const PublishDialog = memo(}}, []);+ // 获取素材库组列表+ const fetchLibraryGroups = useCallback(async () => {+ try {+ setLibraryGroupLoading(true);+ const res: any = await getMediaGroupList(1, 100);+ const list = res?.data?.list || [];+ const filtered = list.filter((g: any) => {+ if (g.type === 'img') return allowImage;+ if (g.type === 'video') return allowVideo;+ return true;+ });+ setLibraryGroups(filtered);+ } catch (e) {+ } finally {+ setLibraryGroupLoading(false);+ }+ }, [allowImage, allowVideo]);++ // 获取素材库内容+ const fetchLibraryItems = useCallback(async (groupId: string) => {+ try {+ setLibraryLoading(true);+ const res: any = await getMediaList(groupId, 1, 100);+ setLibraryItems(res?.data?.list || []);+ } catch (e) {+ } finally {+ setLibraryLoading(false);+ }+ }, []);+useEffect(() => {if (draftModalOpen) {setSelectedGroup(null);@@ -179,6 +218,22 @@ const PublishDialog = memo(}}, [selectedGroup, fetchDrafts]);+ // 素材库弹窗打开时获取组列表+ useEffect(() => {+ if (libraryModalOpen) {+ setSelectedLibraryGroup(null);+ setLibraryItems([]);+ fetchLibraryGroups();+ }+ }, [libraryModalOpen, fetchLibraryGroups]);++ // 选中素材库组后加载组内素材+ useEffect(() => {+ if (selectedLibraryGroup?._id) {+ fetchLibraryItems(selectedLibraryGroup._id);+ }+ }, [selectedLibraryGroup, fetchLibraryItems]);+useEffect(() => {if (open) {init(accounts, defaultAccountId);@@ -213,20 +268,25 @@ const PublishDialog = memo(const nextParams: any = {};if (draft.title) nextParams.title = draft.title;if (draft.desc) nextParams.des = draft.desc;- // mediaList: [{url,type}]- const hasVideo = Array.isArray(draft.mediaList) && draft.mediaList.some((m: any) => m.type === MaterialType.VIDEO);- const hasImage = Array.isArray(draft.mediaList) && draft.mediaList.some((m: any) => m.type === MaterialType.ARTICLE);- if (hasVideo) {- const firstVideo = draft.mediaList.find((m: any) => m.type === MaterialType.VIDEO);- nextParams.video = {- ossUrl: firstVideo?.url,- cover: draft.coverUrl ? { ossUrl: draft.coverUrl } : undefined,- };- }- if (hasImage) {- nextParams.images = draft.mediaList- .filter((m: any) => m.type === MaterialType.ARTICLE)- .map((m: any) => ({ ossUrl: m.url }));++ // 处理媒体内容+ if (Array.isArray(draft.mediaList) && draft.mediaList.length > 0) {+ const videos = draft.mediaList.filter((m: any) => m.type === MaterialType.VIDEO);+ const images = draft.mediaList.filter((m: any) => m.type === MaterialType.ARTICLE);++ // 如果有视频,设置视频参数+ if (videos.length > 0) {+ const firstVideo = videos[0];+ nextParams.video = {+ ossUrl: getOssUrl(firstVideo.url),+ cover: draft.coverUrl ? { ossUrl: getOssUrl(draft.coverUrl) } : undefined,+ };+ }++ // 如果有图片,设置图片参数+ if (images.length > 0) {+ nextParams.images = images.map((m: any) => ({ ossUrl: getOssUrl(m.url) }));+ }}if (step === 1 && expandedPubItem) {@@ -238,6 +298,29 @@ const PublishDialog = memo(message.success("草稿已应用");}, [setAccountAllParams, setOnePubParams, step, expandedPubItem]);+ // 选择素材库内容后填充参数+ const applyLibraryItem = useCallback((item: any) => {+ const nextParams: any = {};++ // 处理媒体内容+ if (item.type === 'video') {+ nextParams.video = {+ ossUrl: getOssUrl(item.url),+ cover: item.cover ? { ossUrl: getOssUrl(item.cover) } : undefined,+ };+ } else if (item.type === 'img') {+ nextParams.images = [{ ossUrl: getOssUrl(item.url) }];+ }++ if (step === 1 && expandedPubItem) {+ setOnePubParams(nextParams, expandedPubItem.account.id);+ } else {+ setAccountAllParams(nextParams);+ }+ setLibraryModalOpen(false);+ message.success("素材已应用");+ }, [setAccountAllParams, setOnePubParams, step, expandedPubItem]);+// 是否打开右侧预览const openRight = useMemo(() => {if (step === 0) {@@ -321,9 +404,14 @@ const PublishDialog = memo(<div className="publishDialog-con"><div className="publishDialog-con-head" style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}><span className="publishDialog-con-head-title">{t("title")}</span>- <Button size="small" icon={<FileTextOutlined />} onClick={(e) => { e.stopPropagation(); setDraftModalOpen(true); }}>- 选择草稿- </Button>+ <div style={{ display: 'flex', gap: 8 }}>+ <Button size="small" icon={<PictureOutlined />} onClick={(e) => { e.stopPropagation(); setLibraryModalOpen(true); }}>+ 选择素材库+ </Button>+ <Button size="small" icon={<FileTextOutlined />} onClick={(e) => { e.stopPropagation(); setDraftModalOpen(true); }}>+ 选择草稿+ </Button>+ </div></div><div className="publishDialog-con-acconts">{pubList.map((pubItem) => {@@ -408,6 +496,7 @@ const PublishDialog = memo()}{pubListChoosed.length >= 2 && (<PubParmasTextarea+ key={`${commonPubParams.images?.length || 0}-${commonPubParams.video ? 'video' : 'no-video'}-${commonPubParams.des?.length || 0}`}platType={PlatType.Instagram}rows={16}desValue={commonPubParams.des}@@ -608,6 +697,108 @@ const PublishDialog = memo(</div>)}</Modal>++ {/* 选择素材库弹窗 */}+ <Modal+ open={libraryModalOpen}+ onCancel={() => setLibraryModalOpen(false)}+ footer={null}+ title={selectedLibraryGroup ? "选择素材" : "选择素材库组"}+ width={720}+ >+ {!selectedLibraryGroup ? (+ <div>+ {libraryGroupLoading ? (+ <div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>+ ) : (+ <List+ grid={{ gutter: 16, column: 2 }}+ dataSource={libraryGroups}+ locale={{ emptyText: "暂无素材库组" }}+ renderItem={(item: any) => (+ <List.Item>+ <div+ style={{+ background: '#F0F8FF',+ border: '2px solid transparent',+ padding: '16px',+ borderRadius: '12px',+ cursor: 'pointer',+ transition: 'all 0.3s ease',+ minHeight: '80px',+ display: 'flex',+ flexDirection: 'column',+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+ position: 'relative'+ }}+ onClick={() => setSelectedLibraryGroup(item)}+ >+ <div style={{ fontSize: 24, marginBottom: 8, color: '#1890ff' }}>+ <PictureOutlined />+ </div>+ <div style={{ fontWeight: 600, fontSize: 16, color: '#2c3e50', marginBottom: 4 }}>+ {item.title}+ </div>+ {item.desc && (+ <div style={{ fontSize: 12, color: '#7f8c8d', lineHeight: 1.4 }}>+ {item.desc}+ </div>+ )}+ <div style={{+ position: 'absolute', top: 8, left: 8, padding: '2px 8px', borderRadius: '12px', fontSize: 10,+ color: '#fff', background: item.type === 'img' ? '#52c41a' : '#1890ff'+ }}>+ {item.type === 'img' ? '图片组' : '视频组'}+ </div>+ </div>+ </List.Item>+ )}+ />+ )}+ </div>+ ) : (+ <div>+ <div style={{ marginBottom: 12 }}>+ <Button type="link" onClick={() => setSelectedLibraryGroup(null)}>+ 返回素材库组+ </Button>+ </div>+ {libraryLoading ? (+ <div style={{ textAlign: 'center', padding: 24 }}><Spin /></div>+ ) : (+ <List+ grid={{ gutter: 16, column: 2 }}+ dataSource={libraryItems}+ locale={{ emptyText: "该组暂无素材" }}+ renderItem={(item: any) => (+ <List.Item>+ <div+ style={{+ border: '1px solid #eee', borderRadius: 8, overflow: 'hidden', cursor: 'pointer'+ }}+ onClick={() => applyLibraryItem(item)}+ >+ <div style={{ width: '100%', paddingTop: '56%', position: 'relative', background: '#f7f7f7' }}>+ <img+ src={getOssUrl(item.url)}+ alt=""+ style={{ position: 'absolute', left: 0, top: 0, width: '100%', height: '100%', objectFit: 'cover' }}+ />+ </div>+ <div style={{ padding: 8 }}>+ <div style={{ fontWeight: 600 }}>{item.title || '-'}</div>+ <div style={{ fontSize: 12, color: '#999' }}>{item.desc || ''}</div>+ </div>+ </div>+ </List.Item>+ )}+ />+ )}+ </div>+ )}+ </Modal></>);},diff --git a/src/components/PublishDialog/usePublishDialog.ts b/src/components/PublishDialog/usePublishDialog.tsindex d7cdc758..d02f0522 100644--- a/src/components/PublishDialog/usePublishDialog.ts+++ b/src/components/PublishDialog/usePublishDialog.ts@@ -132,25 +132,41 @@ export const usePublishDialog = create(const commonPubParams = { ...get().commonPubParams };let pubListChoosed = [...get().pubListChoosed];- for (const key in commonPubParams) {+ // 更新 commonPubParams+ for (const key in pubParmas) {if (pubParmas.hasOwnProperty(key)) {- const keyType = key as "des";- const val = pubParmas[keyType];- commonPubParams[keyType] = pubParmas[keyType]!;-- for (let i = 0; i < pubList.length; i++) {- const v = pubList[i];- const platConfig = AccountPlatInfoMap.get(v.account.type)!;- if (- (key === "video" &&- !platConfig.pubTypes.has(PubType.VIDEO)) ||- (key === "images" &&- !platConfig.pubTypes.has(PubType.ImageText))- ) {- continue;- }- v.params[keyType] = val!;- }+ (commonPubParams as any)[key] = (pubParmas as any)[key];+ }+ }++ // 更新所有账户的参数+ for (let i = 0; i < pubList.length; i++) {+ const v = pubList[i];+ const platConfig = AccountPlatInfoMap.get(v.account.type)!;++ // 更新描述+ if (pubParmas.des !== undefined) {+ v.params.des = pubParmas.des;+ }++ // 更新标题+ if (pubParmas.title !== undefined) {+ v.params.title = pubParmas.title;+ }++ // 更新视频(如果平台支持)+ if (pubParmas.video !== undefined && platConfig.pubTypes.has(PubType.VIDEO)) {+ v.params.video = pubParmas.video;+ }++ // 更新图片(如果平台支持)+ if (pubParmas.images !== undefined && platConfig.pubTypes.has(PubType.ImageText)) {+ v.params.images = pubParmas.images;+ }++ // 更新选项+ if (pubParmas.option) {+ v.params.option = lodash.merge({}, v.params.option, pubParmas.option);}}