Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 【ChooseAccountModule.tsx】组件和引用传参修改
gaoSir23c2ce834aea
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/ImageRightSetting.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/ImageRightSetting.tsxindex af4ae050..da3a2ec9 100644--- a/src/views/publish/children/imagePage/components/ImageRightSetting/ImageRightSetting.tsx+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/ImageRightSetting.tsx@@ -16,9 +16,10 @@ const ImageRightSetting = memo(forwardRef(({}: IImageRightSettingProps, ref: ForwardedRef<IImageRightSettingRef>) => {const [chooseAccountOpen, setChooseAccountOpen] = useState(false);- const { imageTextData } = useImagePageStore(+ const { imageTextData, addAccount } = useImagePageStore(useShallow((state) => ({imageTextData: state.imageTextData,+ addAccount: state.addAccount,})),);@@ -27,13 +28,15 @@ const ImageRightSetting = memo(<ChooseAccountModuleopen={chooseAccountOpen}onClose={setChooseAccountOpen}- choosedAccounts={imageTextData.imageAccounts- .map((v) => v.account)- .filter((v) => v !== undefined)}+ platChooseProps={{+ choosedAccounts: imageTextData.imageAccounts+ .map((v) => v.account)+ .filter((v) => v !== undefined),+ pubType: PubType.ImageText,+ }}onPlatConfirm={(aList) => {- console.log(aList);+ addAccount(aList);}}- pubType={PubType.ImageText}/><SupportPlatdiff --git a/src/views/publish/children/imagePage/page.tsx b/src/views/publish/children/imagePage/page.tsxindex 880ead95..3dc33c90 100644--- a/src/views/publish/children/imagePage/page.tsx+++ b/src/views/publish/children/imagePage/page.tsx@@ -4,9 +4,20 @@ import { useImagePageStore } from './useImagePageStore';import ImageLeftSetting from './components/ImageLeftSetting/ImageLeftSetting';import ImageRightSetting from './components/ImageRightSetting/ImageRightSetting';import { Button, Popconfirm } from 'antd';+import { useEffect } from 'react';export default function Page() {- const {} = useImagePageStore(useShallow((state) => ({})));+ const { clear } = useImagePageStore(+ useShallow((state) => ({+ clear: state.clear,+ })),+ );++ useEffect(() => {+ return () => {+ clear();+ };+ }, []);return (<div className={styles.image}>diff --git a/src/views/publish/children/imagePage/useImagePageStore.ts b/src/views/publish/children/imagePage/useImagePageStore.tsindex 6a09ccec..5db95934 100644--- a/src/views/publish/children/imagePage/useImagePageStore.ts+++ b/src/views/publish/children/imagePage/useImagePageStore.ts@@ -3,6 +3,8 @@ import { combine } from 'zustand/middleware';import { IImgFile } from '../../../../components/Choose/ImgChoose';import { IImageAccountItem } from './imagePage.type';import lodash from 'lodash';+import { AccountInfo } from '../../../account/comment';+import { useVideoPageStore } from '../videoPage/useVideoPageStore';interface IImagePageStore {imageTextData: {@@ -30,6 +32,24 @@ export const useImagePageStore = create(},(set, get, storeApi) => {const methods = {+ // 添加账户+ addAccount(accounts: AccountInfo[]) {+ const imageTextData = {+ ...get().imageTextData,+ };++ for (const account of accounts) {+ imageTextData.imageAccounts.push({+ account,+ pubParams: useVideoPageStore.getState().pubParamsInit(),+ });+ }++ set({+ imageTextData,+ });+ },+clear() {set({...getStore(),diff --git a/src/views/publish/children/videoPage/page.tsx b/src/views/publish/children/videoPage/page.tsxindex c368038e..02114d2e 100644--- a/src/views/publish/children/videoPage/page.tsx+++ b/src/views/publish/children/videoPage/page.tsx@@ -94,15 +94,18 @@ export default function Page() {<Spin spinning={loadingPageLoading}><VideoPubSetModal onClose={setVideoPubSetModalOpen} /><ChooseAccountModule- disableAllSelect={- accountChooseType.current === AccountChooseType.Radio ||- accountChooseType.current === AccountChooseType.Replace- }+ platChooseProps={{+ disableAllSelect:+ accountChooseType.current === AccountChooseType.Radio ||+ accountChooseType.current === AccountChooseType.Replace,+ choosedAccounts: videoListChoose+ .map((v) => v.account)+ .filter((v) => v !== undefined),+ pubType: PubType.VIDEO,+ isCancelChooseAccount: true,+ }}open={chooseAccountOpen}onClose={setChooseAccountOpen}- choosedAccounts={videoListChoose- .map((v) => v.account)- .filter((v) => v !== undefined)}onPlatConfirm={(aList) => {addAccount(aList);}}@@ -118,7 +121,6 @@ export default function Page() {});}}}- pubType={PubType.VIDEO}/>{videoListChoose.length !== 0 ? (diff --git a/src/views/publish/components/ChooseAccountModule/ChooseAccountModule.tsx b/src/views/publish/components/ChooseAccountModule/ChooseAccountModule.tsxindex 57893ff0..33551f91 100644--- a/src/views/publish/components/ChooseAccountModule/ChooseAccountModule.tsx+++ b/src/views/publish/components/ChooseAccountModule/ChooseAccountModule.tsx@@ -8,43 +8,34 @@ import {} from 'react';import { Modal, Tabs } from 'antd';import { AccountInfo } from '@/views/account/comment';-import { PubType } from '../../../../../commont/publish/PublishEnum';import PlatChoose, {+ IPlatChooseProps,IPlatChooseRef,} from '@/views/publish/components/ChooseAccountModule/components/PlatChoose';-import { AccountType } from '../../../../../commont/AccountEnum';export interface IChooseAccountModuleRef {}export interface IChooseAccountModuleProps {open: boolean;onClose: (open: boolean) => void;- // 发布类型,每个类型的平台都不同- pubType: PubType;- // 按平台 选择的数据- choosedAccounts?: AccountInfo[];++ // 按平台props+ platChooseProps?: IPlatChooseProps;// 按平台选择确认onPlatConfirm?: (accounts: AccountInfo[]) => void;// 按平台选择changeonPlatChange?: (accounts: AccountInfo[], account: AccountInfo) => void;- // 按平台 是否禁用全选,true=禁用,false=不禁用,默认为false- disableAllSelect?: boolean;- // 可选择的平台,默认为全部- allowPlatSet?: Set<AccountType>;}const ChooseAccountModule = memo(forwardRef(({- allowPlatSet,open,onClose,- pubType,- choosedAccounts,onPlatConfirm,onPlatChange,- disableAllSelect,+ platChooseProps,}: IChooseAccountModuleProps,ref: ForwardedRef<IChooseAccountModuleRef>,) => {@@ -59,7 +50,7 @@ const ChooseAccountModule = memo(};const handleCancel = () => {- setNewChoosedAccounts(choosedAccounts || []);+ setNewChoosedAccounts(platChooseProps?.choosedAccounts || []);close();};@@ -69,7 +60,7 @@ const ChooseAccountModule = memo(useEffect(() => {setTimeout(() => platChooseRef.current?.recover(), 1);- }, [choosedAccounts]);+ }, [platChooseProps?.choosedAccounts]);useEffect(() => {platChooseRef.current?.init();@@ -90,17 +81,21 @@ const ChooseAccountModule = memo(key: '1',label: '按平台选择',children: (- <PlatChoose- allowPlatSet={allowPlatSet}- choosedAccounts={choosedAccounts}- disableAllSelect={disableAllSelect || false}- ref={platChooseRef}- pubType={pubType}- onChange={(aList, account) => {- setNewChoosedAccounts(aList);- if (onPlatChange) onPlatChange(aList, account);- }}- />+ <>+ {platChooseProps && (+ <PlatChoose+ {...platChooseProps}+ disableAllSelect={+ platChooseProps.disableAllSelect || false+ }+ ref={platChooseRef}+ onChange={(aList, account) => {+ setNewChoosedAccounts(aList);+ if (onPlatChange) onPlatChange(aList, account);+ }}+ />+ )}+ </>),},]}diff --git a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsxindex e77b7946..72efebdc 100644--- a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx+++ b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx@@ -38,13 +38,18 @@ export interface IPlatChooseRef {export interface IPlatChooseProps {pubType: PubType;- onChange: (choosedAcounts: AccountInfo[], choosedAcount: AccountInfo) => void;+ onChange?: (+ choosedAcounts: AccountInfo[],+ choosedAcount: AccountInfo,+ ) => void;// 外部传入的已经选中的数据,这个值只有在确认更改才会更新choosedAccounts?: AccountInfo[];// 按平台 是否禁用多选,true=禁用,false=不禁用- disableAllSelect: boolean;+ disableAllSelect?: boolean;// 可选择的平台,默认为全部allowPlatSet?: Set<AccountType>;+ // 是否可以取消已经选择的账户,默认为 false+ isCancelChooseAccount?: boolean;}const PlatChoose = memo(@@ -54,7 +59,8 @@ const PlatChoose = memo(pubType,onChange,choosedAccounts,- disableAllSelect,+ disableAllSelect = false,+ isCancelChooseAccount = false,allowPlatSet,}: IPlatChooseProps,ref: ForwardedRef<IPlatChooseRef>,@@ -155,7 +161,7 @@ const PlatChoose = memo(Array.from(choosedAcountMap).map(([key, value]) => {accounts = [...accounts, ...value];});- onChange(accounts, recentData.current!);+ if (onChange) onChange(accounts, recentData.current!);}, [choosedAcountMap]);const init = () => {@@ -295,9 +301,9 @@ const PlatChoose = memo(<div className="platChoose-accounts">{currAccountList.map((v) => {// true=禁用- const isDisable = choosedAccounts?.find(- (k) => k.id === v.id,- );+ const isDisable =+ choosedAccounts?.find((k) => k.id === v.id) &&+ isCancelChooseAccount;return (<divkey={v.id}diff --git a/src/views/task/components/videoInfo.tsx b/src/views/task/components/videoInfo.tsxindex 62bd063f..de99266b 100644--- a/src/views/task/components/videoInfo.tsx+++ b/src/views/task/components/videoInfo.tsx@@ -255,7 +255,11 @@ const Com = forwardRef<TaskInfoRef>((props: any, ref) => {<ChooseAccountModuleopen={chooseAccountOpen}onClose={() => !downloading && setChooseAccountOpen(false)}- choosedAccounts={accountListChoose}+ platChooseProps={{+ choosedAccounts: accountListChoose,+ pubType: PubType.VIDEO,+ allowPlatSet: new Set([AccountType.Douyin]),+ }}onPlatConfirm={async (aList) => {console.log('账号:', aList);setAccountListChoose(aList);@@ -263,8 +267,6 @@ const Com = forwardRef<TaskInfoRef>((props: any, ref) => {// 下载文件并发布await downloadAndPublish(aList);}}- pubType={PubType.VIDEO}- allowPlatSet={new Set([AccountType.Douyin])}/><Modal