Skip to content

Let's use AI to Earn!

add

bulaienaofutuojiesenzhangcc4262c13bd9
diff --git a/src/api/plat/threads.ts b/src/api/plat/threads.ts
new file mode 100644
index 00000000..d156dbf3
--- /dev/null
+++ b/src/api/plat/threads.ts
@@ -0,0 +1,29 @@
+// Threads API接口
+import http from "@/utils/request";
+
+export interface ThreadsLocationItem {
+ id: string;
+ label: string;
+}
+
+export interface ThreadsLocationsResponse {
+ data: ThreadsLocationItem[];
+ code: number;
+}
+
+/**
+ * 获取Threads位置列表
+ * @param accountId 账户ID
+ * @param keyword 搜索关键词(可选)
+ * @returns
+ */
+export const apiGetThreadsLocations = (accountId: string, keyword?: string) => {
+ const params: any = { accountId };
+ if (keyword) {
+ params.keyword = keyword;
+ }
+ return http.get<ThreadsLocationsResponse>(
+ `plat/meta/threads/locations`,
+ params
+ );
+};
diff --git a/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx
new file mode 100644
index 00000000..cddf4524
--- /dev/null
+++ b/src/components/PublishDialog/compoents/PlatParamsSetting/plats/ThreadsParams.tsx
@@ -0,0 +1,140 @@
+import { ForwardedRef, forwardRef, memo, useEffect, useState } from "react";
+import {
+ IPlatsParamsProps,
+ IPlatsParamsRef,
+} from "@/components/PublishDialog/compoents/PlatParamsSetting/plats/plats.type";
+import PubParmasTextarea from "@/components/PublishDialog/compoents/PubParmasTextarea";
+import usePlatParamsCommon from "@/components/PublishDialog/compoents/PlatParamsSetting/hooks/usePlatParamsCoomon";
+// 去掉标题输入
+import styles from "../platParamsSetting.module.scss";
+import { Select, Input } from "antd";
+import { useTransClient } from "@/app/i18n/client";
+import { apiGetThreadsLocations, ThreadsLocationItem } from "@/api/plat/threads";
+import { debounce } from "lodash";
+
+const { Search } = Input;
+
+const ThreadsParams = memo(
+ forwardRef(
+ ({ pubItem }: IPlatsParamsProps, ref: ForwardedRef<IPlatsParamsRef>) => {
+ const { t } = useTransClient("publish");
+ const { pubParmasTextareaCommonParams, setOnePubParams } =
+ usePlatParamsCommon(pubItem);
+
+ const [locations, setLocations] = useState<ThreadsLocationItem[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [searchKeyword, setSearchKeyword] = useState("");
+
+ // 初始化Threads参数
+ useEffect(() => {
+ const option = pubItem.params.option;
+ if (!option.threads) {
+ setOnePubParams(
+ {
+ option: {
+ ...option,
+ threads: {
+ location_id: null,
+ },
+ },
+ },
+ pubItem.account.id,
+ );
+ }
+ }, [pubItem.account.id, setOnePubParams]);
+
+ // 获取位置列表
+ const fetchLocations = async (keyword?: string) => {
+ if (!keyword) {
+ return;
+ }
+ try {
+ setLoading(true);
+ const response:any = await apiGetThreadsLocations(
+ pubItem.account.id,
+ keyword
+ );
+ console.log('response', response)
+ if (response && response.code === 0) {
+ setLocations(response.data);
+ }
+ } catch (error) {
+ console.error("获取Threads位置列表失败:", error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ // 防抖搜索
+ const debouncedSearch = debounce((keyword: string) => {
+ fetchLocations(keyword);
+ }, 300);
+
+ // 初始加载位置列表
+ useEffect(() => {
+ fetchLocations();
+ }, [pubItem.account.id]);
+
+ // 处理位置选择
+ const handleLocationChange = (locationId: string) => {
+ const selectedLocation = locations.find(loc => loc.id === locationId);
+ const option = pubItem.params.option;
+ setOnePubParams(
+ {
+ option: {
+ ...option,
+ threads: {
+ ...option.threads,
+ location_id: selectedLocation?.id || null,
+ },
+ },
+ },
+ pubItem.account.id,
+ );
+ };
+
+ // 处理搜索
+ const handleSearch = (value: string) => {
+ setSearchKeyword(value);
+ debouncedSearch(value);
+ };
+
+ return (
+ <>
+ <PubParmasTextarea
+ {...pubParmasTextareaCommonParams}
+ extend={
+ <>
+ <div
+ className={styles.commonTitleInput}
+ style={{ marginTop: "10px" }}
+ >
+ <div className="platParamsSetting-label">
+ {t("form.location" as any)}
+ </div>
+ <Select
+ placeholder={t("form.selectLocation" as any)}
+ value={pubItem.params.option.threads?.location_id || undefined}
+ onChange={handleLocationChange}
+ loading={loading}
+ style={{ width: "100%" }}
+ showSearch
+ filterOption={false}
+ onSearch={(val) => handleSearch(val)}
+ options={locations.map((location) => ({
+ value: location.id,
+ label: location.label,
+ }))}
+ allowClear
+ />
+ </div>
+ </>
+ }
+ />
+ </>
+ );
+ },
+ ),
+);
+
+export default ThreadsParams;