Skip to content

Let's use AI to Earn!

feat: 位置接入完成,前端添加一些参数

gaoSirf325236ab59c
diff --git a/electron/main/index.ts b/electron/main/index.ts
index 4b1f4fee..50eb050c 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -168,4 +168,4 @@ ipcMain.handle('open-win', (_, arg) => {
} else {
childWindow.loadFile(indexHtml, { hash: arg });
}
-});
+});
\ No newline at end of file
diff --git a/electron/main/plat/PlatformBase.ts b/electron/main/plat/PlatformBase.ts
index 28cf1f64..a5e6460d 100644
--- a/electron/main/plat/PlatformBase.ts
+++ b/electron/main/plat/PlatformBase.ts
@@ -10,9 +10,9 @@ import {
DashboardData,
IAccountInfoParams,
IGetLocationDataParams,
+ IGetLocationResponse,
IGetTopicsParams,
IGetTopicsResponse,
- ILocationDataItem,
IVideoPublishParams,
StatisticsData,
VideoCallbackType,
@@ -86,8 +86,7 @@ export abstract class PlatformBase {
abstract getTopics(params: IGetTopicsParams): Promise<IGetTopicsResponse>;
// 获取位置数据
- abstract getLocationData(params: IGetLocationDataParams): Promise<{
- status: number;
- data: ILocationDataItem[];
- }>;
+ abstract getLocationData(
+ params: IGetLocationDataParams,
+ ): Promise<IGetLocationResponse>;
}
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index f5a150d9..7e0c518e 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -114,3 +114,9 @@ export interface ILocationDataItem {
// 距离
distance: string;
}
+
+// 获取地点数据返回值
+export interface IGetLocationResponse {
+ status: number;
+ data?: ILocationDataItem[];
+}
diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.ts
index fa41fe8c..b808635e 100644
--- a/electron/main/plat/platforms/Kwai/index.ts
+++ b/electron/main/plat/platforms/Kwai/index.ts
@@ -120,7 +120,7 @@ export class Kwai extends PlatformBase {
});
return {
status: res.status,
- data: res.data.data.tags.map((v) => {
+ data: res.data?.data?.tags?.map((v) => {
return {
id: v.tag.id,
name: v.tag.name,
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 2cde9588..34ee181c 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -189,16 +189,20 @@ export class Douyin extends PlatformBase {
}
// 获取热点数据
- async getHotData(query: string) {
- const hotDataRes = await douyinService.getHotspotData({ query });
+ async getHotData(query: string, cookie: Electron.Cookie[]) {
+ const hotDataRes = await douyinService.getHotspotData({ query, cookie });
return hotDataRes.data;
}
async getLocationData(params: IGetLocationDataParams) {
- const locationRes = await douyinService.getLocation(params);
+ const locationRes = await douyinService.getLocation({
+ ...params,
+ cookie: params.cookie!,
+ });
+
return {
- status: locationRes.status,
- data: locationRes.data.poi_list.map((v) => {
+ status: locationRes.data.status_code === 8 ? 401 : locationRes.status,
+ data: locationRes?.data?.poi_list?.map((v) => {
return {
name: v.poi_name,
simpleAddress: v.simple_address_str,
diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.ts
index cb9e58ee..4839ec6c 100644
--- a/electron/main/plat/platforms/wxSph/index.ts
+++ b/electron/main/plat/platforms/wxSph/index.ts
@@ -165,10 +165,11 @@ export class WxSph extends PlatformBase {
const locationRes = await shipinhaoService.getLocation({
...params,
keyword: params.keywords,
+ cookie: params.cookie!,
});
return {
- status: locationRes.status,
- data: locationRes.data.data.list.map((v) => {
+ status: locationRes.data.errCode === 300334 ? 401 : locationRes.status,
+ data: locationRes?.data?.data?.list?.map((v) => {
return {
name: v.name,
simpleAddress: v.fullAddress,
diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.ts
index facbc29c..b63c5a23 100644
--- a/electron/main/plat/platforms/xhs/index.ts
+++ b/electron/main/plat/platforms/xhs/index.ts
@@ -202,11 +202,11 @@ export class Xhs extends PlatformBase {
const locationRes = await xiaohongshuService.getLocations({
...params,
keyword: params.keywords,
- cookies: params.cookie,
+ cookies: params.cookie!,
});
return {
status: locationRes.status,
- data: locationRes.data.data.poi_list.map((v) => {
+ data: locationRes?.data?.data?.poi_list?.map((v) => {
return {
name: v.name,
simpleAddress: v.full_address,
diff --git a/electron/main/views.ts b/electron/main/views.ts
index fe964460..d8e824a0 100644
--- a/electron/main/views.ts
+++ b/electron/main/views.ts
@@ -20,10 +20,30 @@ export interface ISaveFileParams {
}
export function views(win: Electron.BrowserWindow) {
+ // 获取经纬度
+ ipcMain.handle('GET_LOCATION', async () => {
+ return new Promise<{ latitude: number; longitude: number }>(
+ (resolve, reject) => {
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ resolve({
+ latitude: position.coords.latitude,
+ longitude: position.coords.longitude,
+ });
+ },
+ (error) => {
+ reject(error);
+ },
+ );
+ },
+ );
+ });
+
ipcMain.handle('OPEN_DEV_TOOLS', () => {
win.webContents.openDevTools({ mode: 'right' });
});
+ // 保存文件
ipcMain.handle(
'ICP_VIEWS_SAVE_FILE',
(event, { saveDir, filename, file }: ISaveFileParams) => {
diff --git a/electron/plat/Kwai/index.ts b/electron/plat/Kwai/index.ts
index 577968c5..98abb06b 100644
--- a/electron/plat/Kwai/index.ts
+++ b/electron/plat/Kwai/index.ts
@@ -6,7 +6,7 @@ import {
IKwaiUserInfoResponse,
ILoginResponse,
} from './kwai.type';
-import { cookieToPlaywright } from '../utils';
+import { cookieToPlaywright, CookieToString } from '../utils';
import { BrowserWindow } from 'electron';
import { VisibleTypeEnum } from '../plat.common.type';
import { getChromiumPath } from '../../util/chromium';
@@ -226,17 +226,13 @@ class KwaiPub {
});
}
- cookieFormat(cookies: Electron.Cookie[]) {
- return cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');
- }
-
// 获取账号信息
async getAccountInfo(cookies: Electron.Cookie[]) {
return await requestNet<IKwaiUserInfoResponse>({
url: 'https://cp.kuaishou.com/rest/v2/creator/pc/authority/account/current?__NS_sig3=9585c2f20a5d5ba1adc8cbca965d865710f45cb0d4d4d6d6d9d8dbc1',
method: 'POST',
headers: {
- cookie: this.cookieFormat(cookies),
+ cookie: CookieToString(cookies),
},
body: {
'kuaishou.web.cp.api_ph': '20d8d6752131fa2ea941cbf5965061fd0a7a',
@@ -256,7 +252,7 @@ class KwaiPub {
url: `https://cp.kuaishou.com/rest/cp/works/v2/video/pc/tag/search?__NS_sig3=9585c2f20a5d5ba1adc8cbca965d865710f45cb0d4d4d6d6d9d8dbc1`,
method: 'POST',
headers: {
- cookie: this.cookieFormat(cookies),
+ cookie: CookieToString(cookies),
},
body: {
keyword,
diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.ts
index c0b54a57..bdfa8241 100644
--- a/electron/plat/douyin/index.ts
+++ b/electron/plat/douyin/index.ts
@@ -6,7 +6,7 @@ import * as crypto from 'crypto';
import { v4 as uuidv4 } from 'uuid';
// @ts-ignore
import crc32 from 'crc32';
-import { getFileContent } from '../utils';
+import { CookieToString, getFileContent } from '../utils';
import {
DouyinLocationDataResponse,
DouyinTopicsSugResponse,
@@ -2003,6 +2003,7 @@ export class DouyinService {
keywords: string;
latitude: number;
longitude: number;
+ cookie: Electron.Cookie[];
}) {
return await requestNet<DouyinLocationDataResponse>({
url: `${this.loginUrl}aweme/v1/life/video_api/search/poi/?${jsonToQueryString(
@@ -2012,17 +2013,23 @@ export class DouyinService {
from_webapp: 1,
},
)}`,
+ headers: {
+ cookie: CookieToString(params.cookie),
+ },
method: 'GET',
});
}
// 获取热点数据
- async getHotspotData(params: { query: string }) {
+ async getHotspotData(params: { query: string; cookie: Electron.Cookie[] }) {
return await requestNet<DouyinLocationDataResponse>({
url: `${this.loginUrl}aweme/v1/hotspot/search/?${jsonToQueryString({
...params,
count: 50,
})}`,
+ headers: {
+ cookie: CookieToString(params.cookie),
+ },
method: 'GET',
});
}
diff --git a/electron/plat/requestNet.ts b/electron/plat/requestNet.ts
index 6794c2c5..93d15441 100644
--- a/electron/plat/requestNet.ts
+++ b/electron/plat/requestNet.ts
@@ -43,7 +43,13 @@ const requestNet = <T = any>({
});
response.on('end', () => {
- const parsedData: T = JSON.parse(data);
+ let parsedData: T;
+ try {
+ parsedData = JSON.parse(data);
+ } catch (e) {
+ parsedData = undefined as any;
+ console.error(e);
+ }
resolve({
status: response.statusCode,
headers: response.headers,
diff --git a/electron/plat/shipinhao/index.ts b/electron/plat/shipinhao/index.ts
index 242dc130..f12edbd2 100644
--- a/electron/plat/shipinhao/index.ts
+++ b/electron/plat/shipinhao/index.ts
@@ -1323,7 +1323,7 @@ export class ShipinhaoService {
});
}
- // 获取商品号的活动
+ // 获取视频号的活动
async getActivityList(params: { cookie: Electron.Cookie[]; query: string }) {
return await requestNet<WeChatLocationData>({
url: `https://channels.weixin.qq.com/cgi-bin/mmfinderassistant-bin/post/post_search_event`,
diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.ts
index 5bc5f3e1..61353838 100644
--- a/electron/plat/xiaohongshu/index.ts
+++ b/electron/plat/xiaohongshu/index.ts
@@ -1295,7 +1295,10 @@ export class XiaohongshuService {
url: 'https://edith.xiaohongshu.com/web_api/sns/v1/local/poi/creator/search',
headers: {
cookie: CookieToString(params.cookies),
+ Referer: this.loginUrl,
+ origin: this.loginUrl,
},
+ method: 'POST',
body: {
...params,
page: 1,
diff --git a/src/icp/publish.ts b/src/icp/publish.ts
index c7ede37b..ba852800 100644
--- a/src/icp/publish.ts
+++ b/src/icp/publish.ts
@@ -11,7 +11,11 @@ import { PubRecordModel } from '@/views/publish/comment';
import { VideoPul } from '@/views/publish/children/videoPage/comment';
import { AccountType } from '../../commont/AccountEnum';
import { PubType } from '../../commont/publish/PublishEnum';
-import { IGetTopicsResponse } from '../../electron/main/plat/plat.type';
+import {
+ type IGetLocationDataParams,
+ IGetLocationResponse,
+ IGetTopicsResponse,
+} from '../../electron/main/plat/plat.type';
import { AccountInfo } from '@/views/account/comment';
// 创建发布记录
@@ -166,3 +170,12 @@ export async function icpGetTopic(account: AccountInfo, keyword: string) {
);
return res;
}
+
+// 获取各个平台位置数据
+export async function icpGetLocationData(params: IGetLocationDataParams) {
+ const res: IGetLocationResponse = await window.ipcRenderer.invoke(
+ 'ICP_PUBLISH_GET_LOCATION',
+ params,
+ );
+ return res;
+}
diff --git a/src/icp/view.ts b/src/icp/view.ts
index 05cdc78c..a3376e37 100644
--- a/src/icp/view.ts
+++ b/src/icp/view.ts
@@ -17,3 +17,10 @@ export async function icpSaveFile(params: ISaveFileParams) {
);
return res;
}
+
+// 获取经纬度
+export async function icpGetLocation() {
+ const res: { latitude: number; longitude: number } =
+ await window.ipcRenderer.invoke('GET_LOCATION');
+ return res;
+}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index b3e77390..07bf4557 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,4 +1,5 @@
import moment from 'moment';
+import { message } from 'antd';
/**
* 生成唯一ID
*/
@@ -41,3 +42,70 @@ export function formatSeconds(seconds: number): string {
return `${pad(hours)}:${pad(minutes)}:${pad(secs)}`;
}
+function handlePositionError(e: GeolocationPositionError) {
+ switch (e.code) {
+ case e.PERMISSION_DENIED:
+ message.warning('位置服务被拒绝');
+ break;
+ case e.POSITION_UNAVAILABLE:
+ message.warning('暂时获取不到位置信息');
+ break;
+ case e.TIMEOUT:
+ message.warning('获取信息超时');
+ break;
+ default:
+ message.warning('未知错误');
+ break;
+ }
+}
+
+// 获取位置信息
+export async function getLocation(): Promise<GeolocationPosition> {
+ return new Promise((resolve) => {
+ function handlePosition(position: GeolocationPosition) {
+ resolve(position);
+ }
+
+ const options = {
+ //是否使用高精度设备,如GPS。默认是true
+ enableHighAccuracy: true,
+ //超时时间,单位毫秒,默认为0
+ timeout: 5000,
+ //使用设置时间内的缓存数据,单位毫秒
+ //默认为0,即始终请求新数据
+ //如设为Infinity,则始终使用缓存数据
+ maximumAge: 0,
+ };
+ console.log(navigator.permissions);
+ if (navigator.permissions) {
+ navigator.permissions
+ .query({ name: 'geolocation' })
+ .then(function (result) {
+ console.debug('permissions:', result.state);
+ if (result.state === 'granted') {
+ navigator.geolocation.getCurrentPosition(
+ handlePosition,
+ handlePositionError,
+ options,
+ );
+ } else if (result.state === 'prompt') {
+ navigator.geolocation.getCurrentPosition(
+ handlePosition,
+ handlePositionError,
+ options,
+ );
+ } else if (result.state === 'denied') {
+ alert(
+ 'Permission denied. Please allow location access in your browser settings.',
+ );
+ }
+ });
+ } else {
+ navigator.geolocation.getCurrentPosition(
+ handlePosition,
+ handlePositionError,
+ options,
+ );
+ }
+ });
+}
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
index c960154a..f80d9d10 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
@@ -3,11 +3,13 @@ import {
IVideoPubSetModalChildProps,
IVideoPubSetModalChildRef,
} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';
-import { Input, Radio } from 'antd';
+import { Input, Radio, Select } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
-import { VisibleTypeEnum } from '@@/publish/PublishEnum';
+import { DouyinDeclareEnum, VisibleTypeEnum } from '@@/publish/PublishEnum';
import TopicSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect';
+import LocationSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect';
+import { AccountType } from '@@/AccountEnum';
const { TextArea } = Input;
@@ -66,6 +68,8 @@ const VideoPubSetModal_KWAI = memo(
tips="最多可添加5个话题(包含活动奖励)"
/>
+ <LocationSelect currChooseAccount={currChooseAccount} />
+
<h1>谁可以看</h1>
<Radio.Group
options={[
@@ -89,6 +93,55 @@ const VideoPubSetModal_KWAI = memo(
}}
value={currChooseAccount?.pubParams.visibleType}
/>
+
+ <h1>自主声明</h1>
+ <Select
+ allowClear
+ value={
+ currChooseAccount?.pubParams.diffParams![AccountType.Douyin]!
+ .selfDeclare
+ }
+ style={{ width: '100%' }}
+ placeholder="选择声明"
+ labelInValue
+ filterOption={false}
+ options={[
+ {
+ label: '内容自行拍摄',
+ value: DouyinDeclareEnum.Self,
+ },
+ {
+ label: '内容取材网络',
+ value: DouyinDeclareEnum.Network,
+ },
+ {
+ label: '内容由AI生成',
+ value: DouyinDeclareEnum.AI,
+ },
+ {
+ label: '可能引人不适',
+ value: DouyinDeclareEnum.Uncomfortable,
+ },
+ {
+ label: '虚构演绎,仅供娱乐',
+ value: DouyinDeclareEnum.Fiction,
+ },
+ {
+ label: '危险行为,请勿模仿',
+ value: DouyinDeclareEnum.Danger,
+ },
+ ]}
+ onChange={(newValue: any) => {
+ const newDiffParams = currChooseAccount.pubParams.diffParams!;
+ newDiffParams[AccountType.Douyin]!.selfDeclare = newValue?.value;
+ setOnePubParams(
+ {
+ diffParams: newDiffParams,
+ },
+ currChooseAccount.id,
+ );
+ }}
+ />
</>
);
},
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx
index c0d56c7c..ac34fc29 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_WxSph.tsx
@@ -3,10 +3,12 @@ import {
IVideoPubSetModalChildProps,
IVideoPubSetModalChildRef,
} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';
-import { Input, Radio, Select } from 'antd';
+import { Checkbox, Input, Radio, Select } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
import { VisibleTypeEnum } from '@@/publish/PublishEnum';
+import LocationSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect';
+import { AccountType } from '@@/AccountEnum';
const { TextArea } = Input;
@@ -82,6 +84,47 @@ const VideoPubSetModal_KWAI = memo(
您可添加10个标签,按回车键确认
</p>
+ <LocationSelect currChooseAccount={currChooseAccount} />
+
+ <h1>扩展链接</h1>
+ <Input
+ placeholder="粘贴链接"
+ value={
+ currChooseAccount?.pubParams.diffParams![AccountType.WxSph]!
+ .extLink
+ }
+ onChange={(e) => {
+ const newDiffParams = currChooseAccount.pubParams.diffParams!;
+ newDiffParams[AccountType.WxSph]!.extLink = e.target.value;
+ setOnePubParams(
+ {
+ diffParams: newDiffParams,
+ },
+ currChooseAccount.id,
+ );
+ }}
+ />
+
+ <h1>声明远程</h1>
+ <Checkbox
+ value={
+ currChooseAccount?.pubParams.diffParams![AccountType.WxSph]!
+ .isOriginal
+ }
+ onChange={(e) => {
+ const newDiffParams = currChooseAccount.pubParams.diffParams!;
+ newDiffParams[AccountType.WxSph]!.isOriginal = e.target.checked;
+ setOnePubParams(
+ {
+ diffParams: newDiffParams,
+ },
+ currChooseAccount.id,
+ );
+ }}
+ >
+ 声明后,作品将展示原创标记,有机会获得广告收入
+ </Checkbox>
+
<h1>权限设置</h1>
<Radio.Group
options={[
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx
index 74367238..54b92827 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_XSH.tsx
@@ -3,11 +3,12 @@ import {
IVideoPubSetModalChildProps,
IVideoPubSetModalChildRef,
} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';
-import { Input, Radio } from 'antd';
+import { Checkbox, Input, Radio } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
import { VisibleTypeEnum } from '@@/publish/PublishEnum';
import TopicSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect';
+import LocationSelect from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect';
const { TextArea } = Input;
@@ -66,6 +67,8 @@ const VideoPubSetModal_KWAI = memo(
tips="您可以添加20个话题"
/>
+ <LocationSelect currChooseAccount={currChooseAccount} />
+
<h1>权限设置</h1>
<Radio.Group
options={[
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
new file mode 100644
index 00000000..a0775e14
--- /dev/null
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
@@ -0,0 +1,103 @@
+import React, { useEffect } from 'react';
+import { Button, SelectProps } from 'antd';
+import { Select, Spin } from 'antd';
+import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
+import { useShallow } from 'zustand/react/shallow';
+import { icpGetLocationData } from '@/icp/publish';
+import { AccountStatus } from '@@/AccountEnum';
+import { ipcUpdateAccountStatus } from '@/icp/account';
+import { ILocationDataItem } from '../../../../../../../../electron/main/plat/plat.type';
+import useDebounceFetcher from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher';
+import { IVideoChooseItem } from '@/views/publish/children/videoPage/videoPage';
+import styles from './locationSelect.module.scss';
+
+interface DebounceSelectProps<ValueType = any>
+ extends Omit<SelectProps<ValueType | ValueType[]>, 'options' | 'children'> {
+ currChooseAccount: IVideoChooseItem;
+}
+
+// 话题选择器
+export default function LocationSelect({
+ currChooseAccount,
+ ...props
+}: DebounceSelectProps<ILocationDataItem>) {
+ const { setOnePubParams, updateAccounts, accountRestart } = useVideoPageStore(
+ useShallow((state) => ({
+ setOnePubParams: state.setOnePubParams,
+ updateAccounts: state.updateAccounts,
+ accountRestart: state.accountRestart,
+ })),
+ );
+ const { fetching, options, debounceFetcher } =
+ useDebounceFetcher<ILocationDataItem>(async (keywords) => {
+ const locationData = await icpGetLocationData({
+ account: currChooseAccount.account!,
+ keywords,
+ latitude: 40.043624478084524,
+ longitude: 116.24432699979916,
+ });
+ if (locationData.status !== 200 && locationData.status !== 201) {
+ if (locationData.status === 401) {
+ currChooseAccount.account!.status = AccountStatus.DISABLE;
+ updateAccounts({ accounts: [currChooseAccount.account!] });
+ await ipcUpdateAccountStatus(
+ currChooseAccount.account!.id,
+ AccountStatus.DISABLE,
+ );
+ }
+ return [];
+ }
+ return locationData.data!;
+ });
+
+ useEffect(() => {
+ // getLocation().then((res) => {
+ // console.log(res);
+ // });
+ }, []);
+
+ return (
+ <>
+ <h1>位置</h1>
+ <Select
+ showSearch
+ allowClear
+ style={{ width: '100%' }}
+ placeholder="请选择关联位置"
+ labelInValue
+ filterOption={false}
+ onSearch={debounceFetcher}
+ notFoundContent={fetching ? <Spin size="small" /> : null}
+ {...props}
+ options={options}
+ optionRender={({ data }) => {
+ return (
+ <div className={styles.locationSelect}>
+ <p className="location-name">{data.name}</p>
+ <p className="location-simpleAddress">{data.simpleAddress}</p>
+ </div>
+ );
+ }}
+ // value={currChooseAccount.pubParams!.topics} TODO 参数选择接入
+ onChange={(newValue) => {
+ console.log(newValue);
+ }}
+ />
+
+ {currChooseAccount.account?.status === AccountStatus.DISABLE && (
+ <div className="videoPubSetModal_con-accountDisable">
+ 账户已失效,
+ <Button
+ type="link"
+ onClick={() => {
+ accountRestart(currChooseAccount.account!.type);
+ }}
+ >
+ 重新登录
+ </Button>
+ 后可获取
+ </div>
+ )}
+ </>
+ );
+}
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx
index b0a9be34..b24d52b7 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx
@@ -1,17 +1,16 @@
-import React, { useMemo, useRef, useState } from 'react';
+import React from 'react';
import { Button, SelectProps } from 'antd';
import { Select, Spin } from 'antd';
-import lodash from 'lodash';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
import { IVideoChooseItem } from '@/views/publish/children/videoPage/videoPage';
import { icpGetTopic } from '@/icp/publish';
import { AccountStatus, AccountType } from '@@/AccountEnum';
import { ipcUpdateAccountStatus } from '@/icp/account';
+import useDebounceFetcher from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher';
-export interface DebounceSelectProps<ValueType = any>
+interface DebounceSelectProps<ValueType = any>
extends Omit<SelectProps<ValueType | ValueType[]>, 'options' | 'children'> {
- debounceTimeout?: number;
tips: string;
currChooseAccount: IVideoChooseItem;
}
@@ -23,15 +22,29 @@ export default function TopicSelect<
label: React.ReactNode;
value: string | number;
} = any,
->({
- debounceTimeout = 300,
- currChooseAccount,
- tips,
- ...props
-}: DebounceSelectProps<ValueType>) {
- const [fetching, setFetching] = useState(false);
- const [options, setOptions] = useState<ValueType[]>([]);
- const fetchRef = useRef(0);
+>({ currChooseAccount, tips, ...props }: DebounceSelectProps<ValueType>) {
+ const { fetching, options, debounceFetcher } = useDebounceFetcher<ValueType>(
+ async (keyword: string): Promise<ValueType[]> => {
+ const topics = await icpGetTopic(currChooseAccount.account!, keyword);
+ if (topics.status !== 200) {
+ if (topics.status === 401) {
+ currChooseAccount.account!.status = AccountStatus.DISABLE;
+ updateAccounts({ accounts: [currChooseAccount.account!] });
+ await ipcUpdateAccountStatus(
+ currChooseAccount.account!.id,
+ AccountStatus.DISABLE,
+ );
+ }
+ return [];
+ }
+ return topics.data!.map((v) => {
+ return {
+ label: v.name,
+ value: v.name,
+ };
+ }) as ValueType[];
+ },
+ );
const { setOnePubParams, updateAccounts, accountRestart } = useVideoPageStore(
useShallow((state) => ({
@@ -41,47 +54,6 @@ export default function TopicSelect<
})),
);
- const fetchOptions = async (keyword: string): Promise<ValueType[]> => {
- const topics = await icpGetTopic(currChooseAccount.account!, keyword);
- if (topics.status !== 200) {
- if (topics.status === 401) {
- currChooseAccount.account!.status = AccountStatus.DISABLE;
- updateAccounts({ accounts: [currChooseAccount.account!] });
- await ipcUpdateAccountStatus(
- currChooseAccount.account!.id,
- AccountStatus.DISABLE,
- );
- }
- return [];
- }
- return topics.data!.map((v) => {
- return {
- label: v.name,
- value: v.name,
- };
- }) as ValueType[];
- };
-
- const debounceFetcher = useMemo(() => {
- const loadOptions = (value: string) => {
- fetchRef.current += 1;
- const fetchId = fetchRef.current;
- setOptions([]);
- setFetching(true);
-
- fetchOptions(value).then((newOptions) => {
- if (fetchId !== fetchRef.current) {
- return;
- }
-
- setOptions(newOptions);
- setFetching(false);
- });
- };
-
- return lodash.debounce(loadOptions, debounceTimeout);
- }, [fetchOptions, debounceTimeout]);
-
return (
<>
<h1>话题</h1>
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/locationSelect.module.scss b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/locationSelect.module.scss
new file mode 100644
index 00000000..38f34080
--- /dev/null
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/locationSelect.module.scss
@@ -0,0 +1,11 @@
+.locationSelect {
+ :global {
+ .location-name {
+ margin-bottom: 2px;
+ }
+ .location-simpleAddress {
+ font-size: var(--fs-xs);
+ color: var(--lightGreyColor);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher.ts b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher.ts
new file mode 100644
index 00000000..9e44fc69
--- /dev/null
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher.ts
@@ -0,0 +1,37 @@
+import { useMemo, useRef, useState } from 'react';
+import lodash from 'lodash';
+
+export default function useDebounceFetcher<T>(
+ fetchOptions: (_: string) => Promise<any>,
+ debounceTimeout = 300,
+) {
+ const fetchRef = useRef(0);
+ const [options, setOptions] = useState<T[]>([]);
+ const [fetching, setFetching] = useState(false);
+
+ const debounceFetcher = useMemo(() => {
+ const loadOptions = (value: string) => {
+ fetchRef.current += 1;
+ const fetchId = fetchRef.current;
+ setOptions([]);
+ setFetching(true);
+
+ fetchOptions(value).then((newOptions) => {
+ if (fetchId !== fetchRef.current) {
+ return;
+ }
+
+ setOptions(newOptions);
+ setFetching(false);
+ });
+ };
+
+ return lodash.debounce(loadOptions, debounceTimeout);
+ }, [fetchOptions, debounceTimeout]);
+
+ return {
+ options,
+ fetching,
+ debounceFetcher,
+ };
+}
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.module.scss b/src/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.module.scss
index d420a929..b6845bea 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.module.scss
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.module.scss
@@ -223,4 +223,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/views/publish/children/videoPage/useVideoPageStore.ts b/src/views/publish/children/videoPage/useVideoPageStore.ts
index bfc1c42d..4a445713 100644
--- a/src/views/publish/children/videoPage/useVideoPageStore.ts
+++ b/src/views/publish/children/videoPage/useVideoPageStore.ts
@@ -45,6 +45,15 @@ const store: IVideoPageStore = {
[AccountType.Xhs]: {
topicsDetail: [],
},
+ [AccountType.Douyin]: {
+ hotPoint: undefined,
+ selfDeclare: undefined,
+ },
+ [AccountType.WxSph]: {
+ isOriginal: false,
+ extLink: undefined,
+ activity: undefined,
+ },
},
},
loadingPageLoading: false,