Skip to content

Let's use AI to Earn!

feat: 经纬度添加、位置添加

gaoSir43dcbaf9671c
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index 7e0c518e..515bb557 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -72,7 +72,6 @@ export interface IVideoPublishParams {
timingTime?: Date;
// 地点
location?: ILableValue;
- other?: any;
}
// 获取话题返回值
diff --git a/electron/main/views.ts b/electron/main/views.ts
index d8e824a0..c2413743 100644
--- a/electron/main/views.ts
+++ b/electron/main/views.ts
@@ -9,6 +9,9 @@ import { dialog, ipcMain } from 'electron';
import fs from 'fs';
import { FileUtils } from '../util/file';
import path from 'path';
+import requestNet from '../plat/requestNet';
+// @ts-ignore
+import coordtransform from 'coordtransform';
export interface ISaveFileParams {
// 要保存的路由
@@ -22,23 +25,24 @@ 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);
- },
- );
+ const res = await requestNet({
+ url: `https://map.baidu.com/?qt=ipLocation&t=${Date.now()}`,
+ headers: {
+ cookie:
+ 'BAIDUID=C6DFA184EA0E181B507D36D4E39DE552:FG=1; BAIDUID_BFESS=C6DFA184EA0E181BFB22AB6E4BC30249:FG=1',
},
- );
+ method: 'GET',
+ });
+ const { lat, lng } = res.data.rgc.result.location;
+ const gcj02 = coordtransform.bd09togcj02(lng, lat);
+ return {
+ bd09: [lng, lat],
+ wgs84: coordtransform.gcj02towgs84(gcj02[0], gcj02[1]),
+ gcj02,
+ };
});
+ // 打开开发者工具
ipcMain.handle('OPEN_DEV_TOOLS', () => {
win.webContents.openDevTools({ mode: 'right' });
});
diff --git a/package-lock.json b/package-lock.json
index 65b909fe..eae972ca 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"antd-img-crop": "^4.24.0",
"axios": "^1.7.9",
"better-sqlite3": "^11.8.1",
+ "coordtransform": "^2.1.2",
"crc32": "^0.2.2",
"cropperjs": "^1.6.2",
"crypto": "^1.0.1",
@@ -3651,6 +3652,12 @@
"node": ">= 0.8"
}
},
+ "node_modules/coordtransform": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmmirror.com/coordtransform/-/coordtransform-2.1.2.tgz",
+ "integrity": "sha512-0xLJApBlrUP+clyLJWIaqg4GXE5JTbAJb5d/CDMqebIksAMMze8eAyO6YfHEIxWJ+c42mXoMHBzWTeUrG7RFhw==",
+ "license": "MIT"
+ },
"node_modules/copy-to": {
"version": "2.0.1",
"license": "MIT"
@@ -14041,6 +14048,11 @@
"keygrip": "~1.1.0"
}
},
+ "coordtransform": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmmirror.com/coordtransform/-/coordtransform-2.1.2.tgz",
+ "integrity": "sha512-0xLJApBlrUP+clyLJWIaqg4GXE5JTbAJb5d/CDMqebIksAMMze8eAyO6YfHEIxWJ+c42mXoMHBzWTeUrG7RFhw=="
+ },
"copy-to": {
"version": "2.0.1"
},
diff --git a/package.json b/package.json
index 87ead458..c638cc95 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
"antd-img-crop": "^4.24.0",
"axios": "^1.7.9",
"better-sqlite3": "^11.8.1",
+ "coordtransform": "^2.1.2",
"crc32": "^0.2.2",
"cropperjs": "^1.6.2",
"crypto": "^1.0.1",
diff --git a/src/icp/view.ts b/src/icp/view.ts
index a3376e37..86d43099 100644
--- a/src/icp/view.ts
+++ b/src/icp/view.ts
@@ -20,7 +20,10 @@ export async function icpSaveFile(params: ISaveFileParams) {
// 获取经纬度
export async function icpGetLocation() {
- const res: { latitude: number; longitude: number } =
- await window.ipcRenderer.invoke('GET_LOCATION');
+ const res: {
+ bd09: number[];
+ wgs84: number[];
+ gcj02: number[];
+ } = await window.ipcRenderer.invoke('GET_LOCATION');
return res;
}
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
index ffe6b5ab..d9cbc9de 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
@@ -429,7 +429,6 @@ const VideoPubSetModal = memo(
<VideoPubSetModalVideo
ref={videoPubSetModalVideoRef}
chooseAccountItem={currChooseAccount}
- key={currChooseAccount?.video?.videoUrl}
/>
)}
</div>
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 ac34fc29..42cf376e 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
@@ -28,6 +28,23 @@ const VideoPubSetModal_KWAI = memo(
return (
<>
+ <h1>短标题</h1>
+ <Input
+ value={currChooseAccount.pubParams.title}
+ showCount
+ maxLength={30}
+ placeholder="好的标题可以获得更多浏览"
+ variant="filled"
+ onChange={(e) => {
+ setOnePubParams(
+ {
+ title: e.target.value,
+ },
+ currChooseAccount.id,
+ );
+ }}
+ />
+
<h1>描述</h1>
<TextArea
value={currChooseAccount?.pubParams.describe}
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 a0775e14..7d99729b 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/LocationSelect.tsx
@@ -1,6 +1,5 @@
-import React, { useEffect } from 'react';
-import { Button, SelectProps } from 'antd';
-import { Select, Spin } from 'antd';
+import React, { useEffect, useRef } from 'react';
+import { Button, Select, SelectProps, Spin } from 'antd';
import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
import { useShallow } from 'zustand/react/shallow';
import { icpGetLocationData } from '@/icp/publish';
@@ -10,6 +9,8 @@ import { ILocationDataItem } from '../../../../../../../../electron/main/plat/pl
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';
+// @ts-ignore
+import { icpGetLocation } from '@/icp/view';
interface DebounceSelectProps<ValueType = any>
extends Omit<SelectProps<ValueType | ValueType[]>, 'options' | 'children'> {
@@ -30,11 +31,12 @@ export default function LocationSelect({
);
const { fetching, options, debounceFetcher } =
useDebounceFetcher<ILocationDataItem>(async (keywords) => {
+ if (location.current.length === 0) await getLocation();
const locationData = await icpGetLocationData({
account: currChooseAccount.account!,
keywords,
- latitude: 40.043624478084524,
- longitude: 116.24432699979916,
+ latitude: location.current[1],
+ longitude: location.current[0],
});
if (locationData.status !== 200 && locationData.status !== 201) {
if (locationData.status === 401) {
@@ -49,13 +51,18 @@ export default function LocationSelect({
}
return locationData.data!;
});
+ // 位置 0=经度 1=纬度
+ const location = useRef<number[]>([]);
useEffect(() => {
- // getLocation().then((res) => {
- // console.log(res);
- // });
+ getLocation();
}, []);
+ const getLocation = async () => {
+ const res = await icpGetLocation();
+ location.current = res.gcj02;
+ };
+
return (
<>
<h1>位置</h1>
@@ -69,7 +76,13 @@ export default function LocationSelect({
onSearch={debounceFetcher}
notFoundContent={fetching ? <Spin size="small" /> : null}
{...props}
- options={options}
+ options={options.map((v) => {
+ return {
+ value: v.id,
+ label: v.name,
+ ...v,
+ };
+ })}
optionRender={({ data }) => {
return (
<div className={styles.locationSelect}>
@@ -78,9 +91,14 @@ export default function LocationSelect({
</div>
);
}}
- // value={currChooseAccount.pubParams!.topics} TODO 参数选择接入
+ value={currChooseAccount.pubParams!.location as any}
onChange={(newValue) => {
- console.log(newValue);
+ setOnePubParams(
+ {
+ location: newValue || null,
+ },
+ currChooseAccount.id,
+ );
}}
/>
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalVideo.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalVideo.tsx
index 9543f2f0..5d8d06d3 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalVideo.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/VideoPubSetModalVideo.tsx
@@ -9,6 +9,8 @@ import {
import { IVideoChooseItem } from '@/views/publish/children/videoPage/videoPage';
import { Avatar, Segmented } from 'antd';
import { HeartFilled } from '@ant-design/icons';
+import { useVideoPageStore } from '@/views/publish/children/videoPage/useVideoPageStore';
+import { useShallow } from 'zustand/react/shallow';
export interface IVideoPubSetModalVideoRef {
play: () => void;
@@ -63,7 +65,11 @@ const VideoPubSetModalVideo = memo(
) => {
const videoRef = useRef<HTMLVideoElement>(null);
const [active, setActive] = useState(1);
-
+ const { videoListChoose } = useVideoPageStore(
+ useShallow((state) => ({
+ videoListChoose: state.videoListChoose,
+ })),
+ );
const imperativeMethods: IVideoPubSetModalVideoRef = {
play: () => {
videoRef.current?.play();
diff --git a/src/views/publish/children/videoPage/useVideoPageStore.ts b/src/views/publish/children/videoPage/useVideoPageStore.ts
index 4a445713..6bb1d143 100644
--- a/src/views/publish/children/videoPage/useVideoPageStore.ts
+++ b/src/views/publish/children/videoPage/useVideoPageStore.ts
@@ -340,7 +340,7 @@ export const useVideoPageStore = create(
if (findedData) {
for (const key in pubParmas) {
if (
- pubParmas[key as 'title'] ||
+ pubParmas[key as 'title'] !== undefined ||
pubParmas[key as 'title'] === ''
) {
findedData.pubParams[key as 'title'] =
diff --git a/src/views/publish/children/videoPage/videoPage.d.ts b/src/views/publish/children/videoPage/videoPage.d.ts
index 7d7ef1c1..5262b3ea 100644
--- a/src/views/publish/children/videoPage/videoPage.d.ts
+++ b/src/views/publish/children/videoPage/videoPage.d.ts
@@ -4,6 +4,7 @@ import { IImgFile } from '@/components/Choose/ImgChoose';
import { VisibleTypeEnum } from '@@/publish/PublishEnum';
import {
DiffParmasType,
+ ILableValue,
TopicsArrType,
} from '../../../../../electron/db/models/video';
@@ -20,6 +21,8 @@ export interface IPubParams {
topics?: TopicsArrType;
// 每个平台的差异性参数
diffParams?: DiffParmasType;
+ // 位置
+ location?: ILableValue;
}
// 选择视频的每项数据