feat: 增加获取位置的方法

This commit is contained in:
2026-05-08 14:58:13 +08:00
parent a3c82382c2
commit 25c8a3570d
6 changed files with 103 additions and 27 deletions

View File

@@ -1,14 +1,14 @@
import { getCurrentConfig } from "@/constant/base";
import { useAppStore } from "@/store";
import { useAppStore, useLocationStore } from "@/store";
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
import { getAccessToken } from "@/constant/token";
import { getAccessToken, removeAccessToken } from "@/constant/token";
import { goLogin } from "../../hooks/useGoLogin";
const clientId = getCurrentConfig().clientId;
const defaultConfig = {
header: {
Authorization: "", // 可在此动态设置 token
"Content-Type": "application/json",
Authorization: "", // 可在此动态设置 token
clientId: clientId,
},
};
@@ -19,6 +19,17 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
if (!/^http/.test(url)) {
url = appStore.serverConfig?.baseUrl + url;
}
// 获取位置信息并添加到请求头
const locationStore = useLocationStore();
if (locationStore.latitude && locationStore.longitude) {
customConfig.header = {
...customConfig.header,
"X-Latitude": locationStore.latitude,
"X-Longitude": locationStore.longitude
};
}
// 动态获取 token
const token = getAccessToken();