feat: 服务接口地址动态获取
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { BASE_URL } from "@/request/base/baseUrl";
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
/// 请求流式数据的API
|
||||
const API = "/agent/assistant/chat";
|
||||
@@ -93,8 +93,9 @@ const agentChatStream = (params, onChunk) => {
|
||||
};
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const { serverConfig } = useAppStore();
|
||||
requestTask = uni.request({
|
||||
url: BASE_URL + API, // 替换为你的接口地址
|
||||
url: serverConfig.baseUrl + API, // 替换为你的接口地址
|
||||
method: "POST",
|
||||
data: params,
|
||||
enableChunked: true,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { BASE_URL } from "@/request/base/baseUrl";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
export const updateImageFile = (file) => {
|
||||
const url = BASE_URL + "/hotelBiz/hotBizCommon/upload";
|
||||
const { serverConfig } = useAppStore();
|
||||
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
|
||||
const token = uni.getStorageSync("token");
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
|
||||
|
||||
17
src/request/api/config.js
Normal file
17
src/request/api/config.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import request from "../base/request";
|
||||
import { isProd } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
// 获取服务地址
|
||||
const getEvnUrl = (args) => {
|
||||
if (isProd) {
|
||||
const appStore = useAppStore();
|
||||
|
||||
request.post("/hotelBiz/mainScene/getServiceUrl", args).then(({ data }) => {
|
||||
console.log("🚀 ~ getEvnUrl ~ data:", data);
|
||||
appStore.setServerConfig(data);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { getEvnUrl };
|
||||
@@ -1,19 +1 @@
|
||||
import { isProd } from '@/constant/base.js';
|
||||
|
||||
// 测试
|
||||
const VITE_BASE_URL_TEST = "https://onefeel.brother7.cn/ingress";
|
||||
const VITE_WSS_URL_TEST = "wss://onefeel.brother7.cn/ingress/agent/ws/chat";
|
||||
|
||||
// 生产
|
||||
const VITE_BASE_URL_PRO = "https://biz.nianxx.cn";
|
||||
const VITE_WSS_URL_PRO = "wss://biz.nianxx.cn/agent/ws/chat";
|
||||
|
||||
// 环境配置 - 根据客户端配置动态决定环境
|
||||
export const BASE_URL = isProd ? VITE_BASE_URL_PRO : VITE_BASE_URL_TEST;
|
||||
export const WSS_URL = isProd ? VITE_WSS_URL_PRO : VITE_WSS_URL_TEST;
|
||||
|
||||
// =====================================
|
||||
// 环境配置文件使用方法
|
||||
// console.log("当前环境:", import.meta.env);
|
||||
// export const BASE_URL = import.meta.env.VITE_BASE_URL;
|
||||
// export const WSS_URL = import.meta.env.VITE_WSS_URL;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { goLogin } from "../../hooks/useGoLogin";
|
||||
import { BASE_URL } from "./baseUrl";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||
@@ -14,9 +13,10 @@ const defaultConfig = {
|
||||
};
|
||||
|
||||
function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
const appStore = useAppStore();
|
||||
// 判断 url 是否以 http 开头
|
||||
if (!/^http/.test(url)) {
|
||||
url = BASE_URL + url;
|
||||
url = appStore.serverConfig.baseUrl + url;
|
||||
}
|
||||
// 动态获取 token
|
||||
const token = uni.getStorageSync("token");
|
||||
@@ -58,7 +58,6 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
if (res.statusCode && res.statusCode === 424) {
|
||||
console.log("424错误,重新登录");
|
||||
uni.setStorageSync("token", "");
|
||||
const appStore = useAppStore();
|
||||
appStore.setHasToken(false);
|
||||
appStore.setTokenExpired(true);
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
|
||||
Reference in New Issue
Block a user