Skip to content

Let's use AI to Earn!

feat: 热点渲染完成,添加查询全部热点api及接入

gaoSir699f336108b0
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index 515bb557..840c1ad5 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -72,6 +72,7 @@ export interface IVideoPublishParams {
timingTime?: Date;
// 地点
location?: ILableValue;
+ other: any;
}
// 获取话题返回值
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 34ee181c..46fd37c4 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -194,6 +194,12 @@ export class Douyin extends PlatformBase {
return hotDataRes.data;
}
+ // 获取所有热点数据
+ async getAllHotData() {
+ const hotDataRes = await douyinService.getAllHotspotData();
+ return hotDataRes.data;
+ }
+
async getLocationData(params: IGetLocationDataParams) {
const locationRes = await douyinService.getLocation({
...params,
diff --git a/electron/main/publish/video/controller.ts b/electron/main/publish/video/controller.ts
index ca181b4f..01a0fe11 100644
--- a/electron/main/publish/video/controller.ts
+++ b/electron/main/publish/video/controller.ts
@@ -18,6 +18,8 @@ import { PublishService } from '../service';
import platController from '../../plat';
import { AccountService } from '../../account/service';
import { AccountType } from '../../../../commont/AccountEnum';
+import douyin from '../../plat/platforms/douyin';
+import { AccountModel } from '../../../db/models/account';
@Controller()
export class VideoPubController {
@@ -166,6 +168,22 @@ export class VideoPubController {
await this.videoPubService.deleteVideoPulByPubRecordId(pulRecordId);
}
+ // 获取抖音热点数据
+ @Icp('ICP_PUBLISH_GET_DOYTIN_HOT')
+ async getDoytinHot(
+ event: Electron.IpcMainInvokeEvent,
+ account: AccountModel,
+ query: string,
+ ) {
+ return await douyin.getHotData(query, JSON.parse(account.loginCookie));
+ }
+
+ // 获取抖音所有热点数据
+ @Icp('ICP_PUBLISH_GET_ALL_DOYTIN_HOT')
+ async getDoytinHotAll(event: Electron.IpcMainInvokeEvent) {
+ return await douyin.getAllHotData();
+ }
+
// 删除发布记录
@Icp('ICP_PUBLISH_DEL_PUB_RECORD_ITEM_VIDEO')
async delPubRecordItem(
diff --git a/electron/plat/douyin/douyin.type.ts b/electron/plat/douyin/douyin.type.ts
index e0f231d2..b7a237f0 100644
--- a/electron/plat/douyin/douyin.type.ts
+++ b/electron/plat/douyin/douyin.type.ts
@@ -147,7 +147,7 @@ interface Cover {
url_list: string[];
}
-interface Sentence {
+export interface DouyinHotSentence {
aweme_infos: any;
challenge_id: string;
display_style: number;
@@ -170,7 +170,15 @@ interface Sentence {
export interface DouyinHotDataResponse {
extra: Extra;
log_pb: LogPb;
- sentences: Sentence[];
+ sentences: DouyinHotSentence[];
+ status_code: number;
+}
+
+// 抖音的所有热点数据
+export interface DouyinAllHotDataResponse {
+ extra: Extra;
+ log_pb: LogPb;
+ all_sentences: DouyinHotSentence[];
status_code: number;
}
diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.ts
index bdfa8241..522c1d4c 100644
--- a/electron/plat/douyin/index.ts
+++ b/electron/plat/douyin/index.ts
@@ -8,9 +8,11 @@ import { v4 as uuidv4 } from 'uuid';
import crc32 from 'crc32';
import { CookieToString, getFileContent } from '../utils';
import {
+ DouyinAllHotDataResponse,
+ DouyinHotDataResponse,
DouyinLocationDataResponse,
- DouyinTopicsSugResponse,
-} from './douyin.type';
+ DouyinTopicsSugResponse
+} from "./douyin.type";
import requestNet from '../requestNet';
import { jsonToQueryString } from '../../util';
@@ -2022,7 +2024,7 @@ export class DouyinService {
// 获取热点数据
async getHotspotData(params: { query: string; cookie: Electron.Cookie[] }) {
- return await requestNet<DouyinLocationDataResponse>({
+ return await requestNet<DouyinHotDataResponse>({
url: `${this.loginUrl}aweme/v1/hotspot/search/?${jsonToQueryString({
...params,
count: 50,
@@ -2033,6 +2035,14 @@ export class DouyinService {
method: 'GET',
});
}
+
+ // 获取默认热点数据,默认热点数据是没有搜索热点数据之前展示的默认数据
+ async getAllHotspotData() {
+ return await requestNet<DouyinAllHotDataResponse>({
+ url: `${this.loginUrl}aweme/v1/hotspot/recommend`,
+ method: 'GET',
+ });
+ }
}
// 导出服务实例
diff --git a/src/icp/publish.ts b/src/icp/publish.ts
index ba852800..9c3761b6 100644
--- a/src/icp/publish.ts
+++ b/src/icp/publish.ts
@@ -17,6 +17,8 @@ import {
IGetTopicsResponse,
} from '../../electron/main/plat/plat.type';
import { AccountInfo } from '@/views/account/comment';
+import { AccountModel } from '../../electron/db/models/account';
+import { DouyinAllHotDataResponse, DouyinHotDataResponse } from "../../electron/plat/douyin/douyin.type";
// 创建发布记录
export async function icpCreatePubRecord(pubRecord: Partial<PubRecordModel>) {
@@ -179,3 +181,21 @@ export async function icpGetLocationData(params: IGetLocationDataParams) {
);
return res;
}
+
+// 获取抖音热点数据
+export async function icpGetDoytinHot(account: AccountModel, query: string) {
+ const res: DouyinHotDataResponse = await window.ipcRenderer.invoke(
+ 'ICP_PUBLISH_GET_DOYTIN_HOT',
+ account,
+ query,
+ );
+ return res;
+}
+
+// 获取抖音所有热点数据
+export async function icpGetDoytinHotAll() {
+ const res: DouyinAllHotDataResponse = await window.ipcRenderer.invoke(
+ 'ICP_PUBLISH_GET_ALL_DOYTIN_HOT',
+ );
+ return res;
+}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 07bf4557..2e2d2ba8 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,5 +1,4 @@
import moment from 'moment';
-import { message } from 'antd';
/**
* 生成唯一ID
*/
@@ -42,70 +41,22 @@ 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;
+/**
+ * 根据输入数值返回中文描述
+ * @param value 输入的数值
+ * @returns 如果数值超过1000返回'n千',超过10000返回'n万'
+ */
+export function describeNumber(value: number): string {
+ if (value > 10000) {
+ // 数值超过10000,返回'n万'
+ const wan = Math.floor(value / 10000);
+ return `${wan}万`;
+ } else if (value > 1000) {
+ // 数值超过1000,返回'n千'
+ const qian = Math.floor(value / 1000);
+ return `${qian}千`;
+ } else {
+ // 数值不超过1000,直接返回数值的字符串形式
+ return value.toString();
}
}
-
-// 获取位置信息
-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 f80d9d10..ca4b5526 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
@@ -1,22 +1,106 @@
-import React, { ForwardedRef, forwardRef, memo } from 'react';
+import React, { ForwardedRef, forwardRef, memo, useEffect, useRef, useState } from "react";
import {
IVideoPubSetModalChildProps,
IVideoPubSetModalChildRef,
} from '@/views/publish/children/videoPage/components/VideoPubSetModal/videoPubSetModal.type';
-import { Input, Radio, Select } from 'antd';
+import { Input, Radio, Select, Spin } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
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';
+import { AccountStatus, AccountType } from '@@/AccountEnum';
+import useDebounceFetcher from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/useDebounceFetcher';
+import { icpGetDoytinHot, icpGetDoytinHotAll } from '@/icp/publish';
+import { ipcUpdateAccountStatus } from '@/icp/account';
+import { VideoPubRestartLogin } from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon';
+import { DouyinHotSentence } from '../../../../../../../../electron/plat/douyin/douyin.type';
+import styles from '../components/videoPubSetModalCommon.module.scss';
+import { describeNumber } from '@/utils';
const { TextArea } = Input;
+const HotspotSelect = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {
+ const { setOnePubParams, updateAccounts } = useVideoPageStore(
+ useShallow((state) => ({
+ setOnePubParams: state.setOnePubParams,
+ updateAccounts: state.updateAccounts,
+ })),
+ );
+ const [doytinHotAll, setDoytinHotAll] = useState<DouyinHotSentence[]>([]);
+ const [keywords, setKeywords] = useState('');
+
+ const { fetching, options, debounceFetcher } =
+ useDebounceFetcher<DouyinHotSentence>(async (keywords) => {
+ setKeywords(keywords);
+ const res = await icpGetDoytinHot(
+ currChooseAccount.account!,
+ keywords || '',
+ );
+ if (res.status_code !== 0) {
+ currChooseAccount.account!.status = AccountStatus.DISABLE;
+ updateAccounts({ accounts: [currChooseAccount.account!] });
+ await ipcUpdateAccountStatus(
+ currChooseAccount.account!.id,
+ AccountStatus.DISABLE,
+ );
+ return null;
+ }
+ return res.sentences;
+ });
+
+ useEffect(() => {
+ icpGetDoytinHotAll().then((res) => {
+ setDoytinHotAll(res.all_sentences);
+ });
+ }, []);
+
+ return (
+ <>
+ <h1>申请关联热点</h1>
+ <Select
+ showSearch
+ allowClear
+ style={{ width: '100%' }}
+ placeholder="输入热点词搜索"
+ labelInValue
+ filterOption={false}
+ onSearch={debounceFetcher}
+ notFoundContent={fetching ? <Spin size="small" /> : null}
+ options={(!keywords ? doytinHotAll : options).map((v) => {
+ return {
+ ...v,
+ label: v.word,
+ value: v.sentence_id,
+ };
+ })}
+ optionRender={({ data }) => {
+ return (
+ <div className={styles.hotspotSelect}>
+ <div className="hotspotSelect-left">
+ <img src={data.word_cover.url_list[0]} />
+ <span>{data.word}</span>
+ </div>
+ <div className="hotspotSelect-right">
+ {describeNumber(data.hot_value)}在看
+ </div>
+ </div>
+ );
+ }}
+ // value={currChooseAccount.pubParams!.location as any}
+ onChange={(newValue) => {
+ console.log(newValue);
+ }}
+ />
+ <VideoPubRestartLogin currChooseAccount={currChooseAccount} />
+ </>
+ );
+};
+
const VideoPubSetModal_KWAI = memo(
forwardRef(
(
- { currChooseAccount }: IVideoPubSetModalChildProps,
+ props: IVideoPubSetModalChildProps,
ref: ForwardedRef<IVideoPubSetModalChildRef>,
) => {
const { setOnePubParams } = useVideoPageStore(
@@ -25,6 +109,7 @@ const VideoPubSetModal_KWAI = memo(
videoListChoose: state.videoListChoose,
})),
);
+ const { currChooseAccount } = props;
return (
<>
@@ -94,6 +179,8 @@ const VideoPubSetModal_KWAI = memo(
value={currChooseAccount?.pubParams.visibleType}
/>
+ <HotspotSelect {...props} />
+
<h1>自主声明</h1>
<Select
allowClear
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 ac5def11..5c4ef2e0 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
@@ -128,7 +128,7 @@ const VideoPubSetModal_KWAI = memo(
}}
/>
- <h1>声明远程</h1>
+ <h1>声明原创</h1>
<Checkbox
value={
currChooseAccount?.pubParams.diffParams![AccountType.WxSph]!
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
index 7d99729b..7edd2788 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
@@ -1,5 +1,5 @@
import React, { useEffect, useRef } from 'react';
-import { Button, Select, SelectProps, Spin } from 'antd';
+import { Select, SelectProps, Spin } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
import { icpGetLocationData } from '@/icp/publish';
@@ -8,9 +8,10 @@ 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';
+import styles from './videoPubSetModalCommon.module.scss';
// @ts-ignore
import { icpGetLocation } from '@/icp/view';
+import { VideoPubRestartLogin } from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon';
interface DebounceSelectProps<ValueType = any>
extends Omit<SelectProps<ValueType | ValueType[]>, 'options' | 'children'> {
@@ -22,11 +23,10 @@ export default function LocationSelect({
currChooseAccount,
...props
}: DebounceSelectProps<ILocationDataItem>) {
- const { setOnePubParams, updateAccounts, accountRestart } = useVideoPageStore(
+ const { setOnePubParams, updateAccounts } = useVideoPageStore(
useShallow((state) => ({
setOnePubParams: state.setOnePubParams,
updateAccounts: state.updateAccounts,
- accountRestart: state.accountRestart,
})),
);
const { fetching, options, debounceFetcher } =
@@ -101,21 +101,7 @@ export default function LocationSelect({
);
}}
/>
-
- {currChooseAccount.account?.status === AccountStatus.DISABLE && (
- <div className="videoPubSetModal_con-accountDisable">
- 账户已失效,
- <Button
- type="link"
- onClick={() => {
- accountRestart(currChooseAccount.account!.type);
- }}
- >
- 重新登录
- </Button>
- 后可获取
- </div>
- )}
+ <VideoPubRestartLogin currChooseAccount={currChooseAccount} />
</>
);
}
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 b24d52b7..321107c9 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/TopicSelect.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { Button, SelectProps } from 'antd';
+import { SelectProps } from 'antd';
import { Select, Spin } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
@@ -8,6 +8,7 @@ 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';
+import { VideoPubRestartLogin } from '@/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon';
interface DebounceSelectProps<ValueType = any>
extends Omit<SelectProps<ValueType | ValueType[]>, 'options' | 'children'> {
@@ -46,11 +47,10 @@ export default function TopicSelect<
},
);
- const { setOnePubParams, updateAccounts, accountRestart } = useVideoPageStore(
+ const { setOnePubParams, updateAccounts } = useVideoPageStore(
useShallow((state) => ({
setOnePubParams: state.setOnePubParams,
updateAccounts: state.updateAccounts,
- accountRestart: state.accountRestart,
})),
);
@@ -98,21 +98,7 @@ export default function TopicSelect<
);
}}
/>
-
- {currChooseAccount.account?.status === AccountStatus.DISABLE && (
- <div className="videoPubSetModal_con-accountDisable">
- 账户已失效,
- <Button
- type="link"
- onClick={() => {
- accountRestart(currChooseAccount.account!.type);
- }}
- >
- 重新登录
- </Button>
- 后可获取
- </div>
- )}
+ <VideoPubRestartLogin currChooseAccount={currChooseAccount} />
<p className="videoPubSetModal_con-tips">{tips}</p>
</>
);
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon.tsx
new file mode 100644
index 00000000..9b3cbf00
--- /dev/null
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalCommon.tsx
@@ -0,0 +1,37 @@
+import { AccountStatus } from '@@/AccountEnum';
+import { Button } from 'antd';
+import React from 'react';
+import { IVideoChooseItem } from '@/views/publish/children/videoPage/videoPage';
+import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
+import { useShallow } from 'zustand/react/shallow';
+
+export const VideoPubRestartLogin = ({
+ currChooseAccount,
+}: {
+ currChooseAccount: IVideoChooseItem;
+}) => {
+ const { accountRestart } = useVideoPageStore(
+ useShallow((state) => ({
+ accountRestart: state.accountRestart,
+ })),
+ );
+
+ return (
+ <>
+ {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/locationSelect.module.scss b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/locationSelect.module.scss
deleted file mode 100644
index 38f34080..00000000
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/locationSelect.module.scss
+++ /dev/null
@@ -1,11 +0,0 @@
-.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/videoPubSetModalCommon.module.scss b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/videoPubSetModalCommon.module.scss
new file mode 100644
index 00000000..6a0a3a61
--- /dev/null
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/videoPubSetModalCommon.module.scss
@@ -0,0 +1,34 @@
+.locationSelect {
+ :global {
+ .location-name {
+ margin-bottom: 2px;
+ }
+ .location-simpleAddress {
+ font-size: var(--fs-xs);
+ color: var(--lightGreyColor);
+ }
+ }
+}
+
+.hotspotSelect {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 3px 10px;
+ :global {
+ .hotspotSelect-left {
+ display: flex;
+ align-items: center;
+ img {
+ width: 35px;
+ height: 35px;
+ border-radius: 4px;
+ object-fit: cover;
+ margin-right: 10px;
+ }
+ }
+
+ .hotspotSelect-right {
+ }
+ }
+}
\ No newline at end of file