|
@@ -4,7 +4,11 @@ import type { StoreData } from "@/core/store/store";
|
|
import { token, params, urlUpdateQuery, urlGetQuery } from "../env";
|
|
import { token, params, urlUpdateQuery, urlGetQuery } from "../env";
|
|
import { genLoading } from "../loadding";
|
|
import { genLoading } from "../loadding";
|
|
import { tempStrFill } from "@/utils/shared";
|
|
import { tempStrFill } from "@/utils/shared";
|
|
-import { latlngStrTransform } from "../dialog/basemap/leaflet/useLeaflet";
|
|
|
|
|
|
+import {
|
|
|
|
+ type LatLng,
|
|
|
|
+ latlngStrTransform,
|
|
|
|
+} from "../dialog/basemap/leaflet/useLeaflet";
|
|
|
|
+import mitt from "mitt";
|
|
|
|
|
|
export const SCENE_TYPE = {
|
|
export const SCENE_TYPE = {
|
|
fuse: "fuse",
|
|
fuse: "fuse",
|
|
@@ -30,6 +34,8 @@ export const getHeaders = () => ({
|
|
"page-type": "edit",
|
|
"page-type": "edit",
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+export const bus = mitt();
|
|
|
|
+
|
|
export const get = (url: string, params: Record<string, any>) => {
|
|
export const get = (url: string, params: Record<string, any>) => {
|
|
const p = new URLSearchParams();
|
|
const p = new URLSearchParams();
|
|
for (const key in params) {
|
|
for (const key in params) {
|
|
@@ -96,7 +102,31 @@ export const login = (isBack = true) => {
|
|
};
|
|
};
|
|
|
|
|
|
const after = async (fet: Promise<Response>) => {
|
|
const after = async (fet: Promise<Response>) => {
|
|
- const res = await fet.then((res) => res.json());
|
|
|
|
|
|
+ let res: any;
|
|
|
|
+ const response = await fet;
|
|
|
|
+ if (response.status !== 200) {
|
|
|
|
+ if (response.status === 404) {
|
|
|
|
+ res = {
|
|
|
|
+ code: 404,
|
|
|
|
+ message: "网络异常",
|
|
|
|
+ };
|
|
|
|
+ } else {
|
|
|
|
+ res = {
|
|
|
|
+ code: 500,
|
|
|
|
+ message: "服务异常",
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ res = await response.json();
|
|
|
|
+ } catch {
|
|
|
|
+ res = {
|
|
|
|
+ code: 500,
|
|
|
|
+ message: "服务异常",
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (res.code === 8034) {
|
|
if (res.code === 8034) {
|
|
if (!import.meta.env.DEV) {
|
|
if (!import.meta.env.DEV) {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
@@ -106,12 +136,18 @@ const after = async (fet: Promise<Response>) => {
|
|
throw `${res.message},即将退出`;
|
|
throw `${res.message},即将退出`;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
if ([4008, 4010, 7012].includes(res.code)) {
|
|
if ([4008, 4010, 7012].includes(res.code)) {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
window.platform.login(res.code !== 7012);
|
|
window.platform.login(res.code !== 7012);
|
|
}, 1000);
|
|
}, 1000);
|
|
throw res.message;
|
|
throw res.message;
|
|
- } else if (res.code !== 0) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (res.code !== 0) {
|
|
|
|
+ bus.emit("requestError", res);
|
|
|
|
+ }
|
|
|
|
+ if (res.code !== 0) {
|
|
throw res.message;
|
|
throw res.message;
|
|
} else {
|
|
} else {
|
|
return res.data;
|
|
return res.data;
|
|
@@ -142,7 +178,7 @@ export const getSceneList = (keyword: string) => {
|
|
);
|
|
);
|
|
list.push(...current);
|
|
list.push(...current);
|
|
page++;
|
|
page++;
|
|
- final = data.total / data.pageSize <= page;
|
|
|
|
|
|
+ final = Math.ceil(data.total / data.pageSize) < page;
|
|
});
|
|
});
|
|
let next = async () => {
|
|
let next = async () => {
|
|
if (!final) {
|
|
if (!final) {
|
|
@@ -154,7 +190,7 @@ export const getSceneList = (keyword: string) => {
|
|
list,
|
|
list,
|
|
};
|
|
};
|
|
};
|
|
};
|
|
- return {next, final, list};
|
|
|
|
|
|
+ return { next, final, list };
|
|
};
|
|
};
|
|
|
|
|
|
export const getOverviewData = genLoading(async (id: string) => {
|
|
export const getOverviewData = genLoading(async (id: string) => {
|
|
@@ -334,6 +370,22 @@ export const getTileGroups = async () => {
|
|
};
|
|
};
|
|
|
|
|
|
export const searchAddress = async (keyword: string, mapId: number) => {
|
|
export const searchAddress = async (keyword: string, mapId: number) => {
|
|
- const data = await post(`fusion/mapConfig/geocode`, { address: keyword, mapId })
|
|
|
|
- return data.map((item: any) => ({...item, latlng: latlngStrTransform(item.location.split(',').reverse().join(','))}))
|
|
|
|
|
|
+ const data = await post(`fusion/mapConfig/geocode`, {
|
|
|
|
+ address: keyword,
|
|
|
|
+ mapId,
|
|
|
|
+ });
|
|
|
|
+ return data.map((item: any) => ({
|
|
|
|
+ ...item,
|
|
|
|
+ latlng: latlngStrTransform(item.location.split(",").reverse().join(",")),
|
|
|
|
+ }));
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const getDefaultAddress = () => {
|
|
|
|
+ try {
|
|
|
|
+ console.log(params.value.latlng);
|
|
|
|
+ let latlng: LatLng = JSON.parse(params.value.latlng);
|
|
|
|
+ return latlng;
|
|
|
|
+ } catch {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
};
|
|
};
|