Skip to content

Let's use AI to Earn!

feat: 账户选择开发完成

gaoSire21e94fe3c2d
diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.ts
index 79d3431f..6a08213c 100644
--- a/electron/plat/douyin/index.ts
+++ b/electron/plat/douyin/index.ts
@@ -12,7 +12,6 @@ import {
DouyinActivityListResponse,
DouyinActivityTagsResponse,
DouyinAllHotDataResponse,
- DouyinCommentReplyListResponse,
DouyinCreatorCommentListResponse,
DouyinCreatorListResponse,
DouyinHotDataResponse,
@@ -2179,6 +2178,7 @@ export class DouyinService {
longitude: number;
cookie: Electron.Cookie[];
}) {
+ console.log(CookieToString(params.cookie));
return await requestNet<DouyinLocationDataResponse>({
url: `${this.loginUrl}aweme/v1/life/video_api/search/poi/?${jsonToQueryString(
{
@@ -2229,7 +2229,6 @@ export class DouyinService {
// 获取活动详情
async getActivityDetails(cookie: Electron.Cookie[], activity_id: string) {
- console.log(activity_id);
return await requestNet<DouyinActivityDetailResponse>({
url: `https://creator.douyin.com/web/api/media/activity/detail/?activity_id=${activity_id}`,
headers: {
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
index aa687f2a..274dce27 100644
--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ImageParamsSet.tsx
@@ -1,4 +1,4 @@
-import { ForwardedRef, forwardRef, memo, useMemo, useState } from 'react';
+import { ForwardedRef, forwardRef, memo, useMemo } from 'react';
import { useImagePageStore } from '../../../useImagePageStore';
import { useShallow } from 'zustand/react/shallow';
import styles from './imageParamsSet.module.scss';
@@ -6,7 +6,7 @@ import { AccountType } from '../../../../../../../../commont/AccountEnum';
import { IImageAccountItem } from '../../../imagePage.type';
import { AccountPlatInfoMap } from '../../../../../../account/comment';
import { CloseOutlined } from '@ant-design/icons';
-import ParamsSettingItem from './ParamsSettingItem';
+import ParamsSettingDetails from './ParamsSettingDetails';
export interface IImageParamsSetRef {}
@@ -15,27 +15,75 @@ export interface IImageParamsSetProps {}
const ImageParamsSet = memo(
forwardRef(
({}: IImageParamsSetProps, ref: ForwardedRef<IImageParamsSetRef>) => {
- const { imageAccounts } = useImagePageStore(
+ const {
+ imageAccounts,
+ activePlat,
+ setActivePlat,
+ setPlatActiveAccountMap,
+ platActiveAccountMap,
+ delAccountByPalt,
+ } = useImagePageStore(
useShallow((state) => ({
imageAccounts: state.imageAccounts,
+ setActivePlat: state.setActivePlat,
+ activePlat: state.activePlat,
+ setPlatActiveAccountMap: state.setPlatActiveAccountMap,
+ platActiveAccountMap: state.platActiveAccountMap,
+ delAccountByPalt: state.delAccountByPalt,
})),
);
- // 当前选择的平台
- const [activePlat, setActivePlat] = useState<AccountType>();
const platAccountImagesMap = useMemo(() => {
+ // 平台账户map
const platAccountMap = new Map<AccountType, IImageAccountItem[]>([]);
+ // 默认选中的平台map
+ const newPlatActiveAccountMap = new Map<
+ AccountType,
+ IImageAccountItem
+ >();
+
for (const imageAccount of imageAccounts) {
if (!platAccountMap.has(imageAccount.account.type)) {
platAccountMap.set(imageAccount.account.type, []);
+ newPlatActiveAccountMap.set(
+ imageAccount.account.type,
+ imageAccount,
+ );
}
platAccountMap.get(imageAccount.account.type)?.push(imageAccount);
}
+ // 将旧的选中的平台账户设置为新的
+ for (const [accountType, imageAccountItem] of newPlatActiveAccountMap) {
+ // 旧的选中账户
+ const activeImageAccountItem = platActiveAccountMap.get(accountType);
+ if (
+ !activeImageAccountItem ||
+ activeImageAccountItem.account.id === imageAccountItem.account.id
+ )
+ continue;
+
+ // 旧的选中账户新的账户列表是否存在,如果存在则使用上一次选中的状态
+ if (
+ platAccountMap
+ .get(accountType)!
+ .some((v) => v.account.id === activeImageAccountItem.account.id)
+ ) {
+ newPlatActiveAccountMap.set(
+ accountType,
+ platActiveAccountMap.get(accountType)!,
+ );
+ break;
+ }
+ }
+
+ // 当前选择的平台不存在了
if (!activePlat || !platAccountMap.has(activePlat)) {
setActivePlat(Array.from(platAccountMap)[0][0]);
}
+ // 设置store当前选择的平台账户
+ setPlatActiveAccountMap(newPlatActiveAccountMap);
return platAccountMap;
}, [imageAccounts]);
@@ -62,7 +110,7 @@ const ImageParamsSet = memo(
className={`${styles.closeIcon} imageParamsSet_plats-item-close`}
onClick={(e) => {
e.stopPropagation();
- console.log('close');
+ delAccountByPalt(accountType);
}}
>
<CloseOutlined />
@@ -74,7 +122,7 @@ const ImageParamsSet = memo(
})}
</div>
{activePlat && (
- <ParamsSettingItem
+ <ParamsSettingDetails
imageAccountList={platAccountImagesMap.get(activePlat)!}
/>
)}
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx
new file mode 100644
index 00000000..dc4ae0d4
--- /dev/null
+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingDetails.tsx
@@ -0,0 +1,104 @@
+import { ForwardedRef, forwardRef, memo, useMemo } from 'react';
+import styles from './imageParamsSet.module.scss';
+import { CloseOutlined } from '@ant-design/icons';
+import { Avatar, Tooltip } from 'antd';
+import { AccountType } from '../../../../../../../../commont/AccountEnum';
+import ImageParamsSet_Douyin from './children/ImageParamsSet_Douyin';
+import ImageParamsSet_XHS from './children/ImageParamsSet_XHS';
+import { IImageAccountItem } from '../../../imagePage.type';
+import { useImagePageStore } from '../../../useImagePageStore';
+import { useShallow } from 'zustand/react/shallow';
+
+export interface IParamsSettingDetailsRef {}
+
+export interface IParamsSettingDetailsProps {
+ imageAccountList: IImageAccountItem[];
+}
+
+const ParamsSettingDetails = memo(
+ forwardRef(
+ (
+ { imageAccountList }: IParamsSettingDetailsProps,
+ ref: ForwardedRef<IParamsSettingDetailsRef>,
+ ) => {
+ const {
+ activePlat,
+ platActiveAccountMap,
+ delAccountById,
+ setPlatActiveAccountMap,
+ } = useImagePageStore(
+ useShallow((state) => ({
+ activePlat: state.activePlat,
+ platActiveAccountMap: state.platActiveAccountMap,
+ setPlatActiveAccountMap: state.setPlatActiveAccountMap,
+ delAccountById: state.delAccountById,
+ })),
+ );
+
+ const currAccountItem = useMemo(() => {
+ if (!activePlat) return undefined;
+ return platActiveAccountMap.get(activePlat);
+ }, [platActiveAccountMap, activePlat]);
+
+ return (
+ <div className={styles.paramsSettingItem}>
+ <h2>
+ <span>发布账号</span>
+ <i>*</i>
+ </h2>
+ <div className="paramsSettingItem-users">
+ {imageAccountList.map((v) => {
+ return (
+ <div
+ className={[
+ 'paramsSettingItem-users-item',
+ currAccountItem?.account?.id === v.account.id &&
+ 'paramsSettingItem-users-item--active',
+ ].join(' ')}
+ key={v.account.id}
+ onClick={() => {
+ const newPlatActiveAccountMap = new Map(
+ platActiveAccountMap,
+ );
+ newPlatActiveAccountMap.set(activePlat!, v);
+ setPlatActiveAccountMap(newPlatActiveAccountMap);
+ }}
+ >
+ <div className="paramsSettingItem-users-item-img">
+ <div
+ className={`paramsSettingItem-users-item-close ${styles.closeIcon}`}
+ onClick={(e) => {
+ e.stopPropagation();
+ delAccountById(v.account.id);
+ }}
+ >
+ <CloseOutlined />
+ </div>
+ <Avatar src={v.account.avatar} size="large" />
+ </div>
+ <Tooltip title={v.account.nickname}>
+ <p className="paramsSettingItem-users-item-name">
+ {v.account.nickname}
+ </p>
+ </Tooltip>
+ </div>
+ );
+ })}
+ </div>
+
+ {(() => {
+ switch (imageAccountList[0].account.type) {
+ case AccountType.Douyin:
+ return <ImageParamsSet_Douyin />;
+ case AccountType.Xhs:
+ return <ImageParamsSet_XHS />;
+ }
+ })()}
+ </div>
+ );
+ },
+ ),
+);
+ParamsSettingDetails.displayName = 'ParamsSettingDetails';
+
+export default ParamsSettingDetails;
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingItem.tsx b/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingItem.tsx
deleted file mode 100644
index 5cd8f338..00000000
--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/ParamsSettingItem.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import { ForwardedRef, forwardRef, memo, useEffect } from 'react';
-import { IImageAccountItem } from '../../../imagePage.type';
-import { AccountType } from '../../../../../../../../commont/AccountEnum';
-import ImageParamsSet_Douyin from './children/ImageParamsSet_Douyin';
-import ImageParamsSet_XHS from './children/ImageParamsSet_XHS';
-import styles from './imageParamsSet.module.scss';
-import { Avatar, Tooltip } from 'antd';
-import { CloseOutlined } from '@ant-design/icons';
-
-export interface IParamsSettingItemRef {}
-
-export interface IParamsSettingItemProps {
- imageAccountList: IImageAccountItem[];
-}
-
-const ParamsSettingItem = memo(
- forwardRef(
- (
- { imageAccountList }: IParamsSettingItemProps,
- ref: ForwardedRef<IParamsSettingItemRef>,
- ) => {
- useEffect(() => {
- console.log(imageAccountList);
- }, [imageAccountList]);
-
- return (
- <div className={styles.paramsSettingItem}>
- <h2>
- <span>发布账号</span>
- <i>*</i>
- </h2>
- <div className="paramsSettingItem-users">
- {imageAccountList.map((v) => {
- return (
- <div
- className="paramsSettingItem-users-item"
- key={v.account.id}
- >
- <div className="paramsSettingItem-users-item-img">
- <div
- className={`paramsSettingItem-users-item-close ${styles.closeIcon}`}
- >
- <CloseOutlined />
- </div>
- <Avatar src={v.account.avatar} />
- </div>
- <Tooltip title={v.account.nickname}>
- <p className="paramsSettingItem-users-item-name">
- {v.account.nickname}
- </p>
- </Tooltip>
- </div>
- );
- })}
- </div>
-
- {(() => {
- switch (imageAccountList[0].account.type) {
- case AccountType.Douyin:
- return <ImageParamsSet_Douyin />;
- case AccountType.Xhs:
- return <ImageParamsSet_XHS />;
- }
- })()}
- </div>
- );
- },
- ),
-);
-ParamsSettingItem.displayName = 'ParamsSettingItem';
-
-export default ParamsSettingItem;
diff --git a/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss b/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss
index 11c743ed..672c3bf4 100644
--- a/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss
+++ b/src/views/publish/children/imagePage/components/ImageRightSetting/components/imageParamsSet.module.scss
@@ -1,20 +1,8 @@
.imageParamsSet {
+ width: 45%;
+ min-width: 0;
display: flex;
:global {
- h2 {
- font-size: var(--fs-md);
- font-weight: 400;
- display: flex;
- align-items: center;
- color: var(--darkGreyColor);
- span {
- margin-right: 5px;
- }
- i {
- color: red;
- }
- }
-
.imageParamsSet_plats {
padding: 15px 10px;
border-right: 1px solid var(--superLightGreyColor);
@@ -27,6 +15,7 @@
cursor: pointer;
padding: 20px 15px 15px;
border-radius: 6px;
+ white-space: nowrap;
&:hover {
.imageParamsSet_plats-item-close {
display: flex !important;
@@ -40,7 +29,6 @@
}
}
&-close {
-
}
&--active {
@@ -67,23 +55,49 @@
}
.paramsSettingItem {
+ width: 100%;
:global {
+ h2 {
+ font-size: var(--fs-md);
+ font-weight: 400;
+ display: flex;
+ align-items: center;
+ color: var(--darkGreyColor);
+ margin-bottom: 10px;
+ span {
+ margin-right: 5px;
+ }
+ i {
+ color: red;
+ }
+ }
+
.paramsSettingItem-users {
display: flex;
&-item {
- width: 60px;
+ width: 70px;
font-size: var(--fs-sm);
cursor: pointer;
margin-right: 10px;
+ &--active {
+ .paramsSettingItem-users-item-img {
+ border-color: var(--colorPrimary6);
+ }
+ .paramsSettingItem-users-item-name {
+ color: var(--colorPrimary6);
+ }
+ }
&:hover {
.paramsSettingItem-users-item-close {
display: flex !important;
}
}
&-img {
- border: 1px solid red;
+ border: 2px solid transparent;
display: inline-block;
position: relative;
+ transition: 0.3s;
+ border-radius: 50%;
}
&-close {
}
diff --git a/src/views/publish/children/imagePage/image.module.scss b/src/views/publish/children/imagePage/image.module.scss
index 934996c8..222d472a 100644
--- a/src/views/publish/children/imagePage/image.module.scss
+++ b/src/views/publish/children/imagePage/image.module.scss
@@ -62,6 +62,8 @@
}
.imageRightSetting {
+ width: 45%;
+ box-sizing: border-box;
margin-left: 20px;
:global {
.imageRightSetting-title {
diff --git a/src/views/publish/children/imagePage/page.tsx b/src/views/publish/children/imagePage/page.tsx
index 3dc33c90..a35b7fcc 100644
--- a/src/views/publish/children/imagePage/page.tsx
+++ b/src/views/publish/children/imagePage/page.tsx
@@ -29,7 +29,9 @@ export default function Page() {
<Popconfirm
title="温馨提示"
description="是否确认清空内容和账号?"
- onConfirm={() => {}}
+ onConfirm={() => {
+ clear();
+ }}
okText="确认"
cancelText="取消"
>
diff --git a/src/views/publish/children/imagePage/useImagePageStore.ts b/src/views/publish/children/imagePage/useImagePageStore.ts
index 73bd332d..70096cf7 100644
--- a/src/views/publish/children/imagePage/useImagePageStore.ts
+++ b/src/views/publish/children/imagePage/useImagePageStore.ts
@@ -5,15 +5,24 @@ import { IImageAccountItem } from './imagePage.type';
import lodash from 'lodash';
import { AccountInfo } from '../../../account/comment';
import { useVideoPageStore } from '../videoPage/useVideoPageStore';
+import { AccountType } from '../../../../../commont/AccountEnum';
interface IImagePageStore {
+ // 账户数据和对应参数
imageAccounts: IImageAccountItem[];
+ // 选择的图片数据
images: IImgFile[];
+ // 每个平台当前选择的账户
+ platActiveAccountMap: Map<AccountType, IImageAccountItem>;
+ // 当前选择的平台
+ activePlat?: AccountType;
}
const store: IImagePageStore = {
images: [],
imageAccounts: [],
+ platActiveAccountMap: new Map<AccountType, IImageAccountItem>(),
+ activePlat: undefined,
};
const getStore = () => {
@@ -28,6 +37,39 @@ export const useImagePageStore = create(
},
(set, get, storeApi) => {
const methods = {
+ setPlatActiveAccountMap(
+ platActiveAccountMap: Map<AccountType, IImageAccountItem>,
+ ) {
+ set({
+ platActiveAccountMap,
+ });
+ },
+
+ setActivePlat(activePlat: AccountType) {
+ set({
+ activePlat,
+ });
+ },
+
+ // 按照账号id删除
+ delAccountById(accountId: number) {
+ const imageAccounts = get().imageAccounts.filter(
+ (v) => v.account.id !== accountId,
+ );
+ set({
+ imageAccounts,
+ });
+ },
+ // 按平台删除
+ delAccountByPalt(accountType: AccountType) {
+ const imageAccounts = get().imageAccounts.filter(
+ (v) => v.account.type !== accountType,
+ );
+ set({
+ imageAccounts,
+ });
+ },
+
// 添加账户
addAccount(accounts: AccountInfo[]) {
let imageAccounts = [...get().imageAccounts];