feat: 服务接口地址动态获取
This commit is contained in:
@@ -1,7 +1 @@
|
|||||||
NODE_ENV = development
|
NODE_ENV = development
|
||||||
|
|
||||||
# 测试
|
|
||||||
VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
|
||||||
|
|
||||||
# 测试
|
|
||||||
VITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
|
|
||||||
|
|||||||
@@ -1,7 +1 @@
|
|||||||
NODE_ENV = production
|
NODE_ENV = production
|
||||||
|
|
||||||
# 生产
|
|
||||||
VITE_BASE_URL = https://biz.nianxx.cn
|
|
||||||
|
|
||||||
# 生产
|
|
||||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
|
||||||
@@ -1,7 +1 @@
|
|||||||
NODE_ENV = staging
|
NODE_ENV = staging
|
||||||
|
|
||||||
# 生产
|
|
||||||
VITE_BASE_URL = https://biz.nianxx.cn
|
|
||||||
|
|
||||||
# 生产
|
|
||||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"appid": "wx5e79df5996572539",
|
"appid": "wx23f86d809ae80259",
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"libVersion": "3.8.10",
|
"libVersion": "3.8.10",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||||
|
import { getEvnUrl } from "@/request/api/config";
|
||||||
|
|
||||||
onLaunch(async () => {
|
onLaunch(() => {
|
||||||
console.log("App Launch");
|
getEvnUrl({ versionValue: "1.0.1" });
|
||||||
});
|
});
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import rawConfigs from '../../client-configs.json' with { type: 'json' };
|
|||||||
export const CLIENT_CONFIGS = rawConfigs;
|
export const CLIENT_CONFIGS = rawConfigs;
|
||||||
|
|
||||||
// 获取当前用户端配置
|
// 获取当前用户端配置
|
||||||
export const getCurrentConfig = () => CLIENT_CONFIGS.zhinian;
|
export const getCurrentConfig = () => CLIENT_CONFIGS.duohua;
|
||||||
export const clientId = getCurrentConfig().clientId;
|
export const clientId = getCurrentConfig().clientId;
|
||||||
export const appId = getCurrentConfig().appId;
|
export const appId = getCurrentConfig().appId;
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
朵花:wx23f86d809ae80259
|
朵花:wx23f86d809ae80259
|
||||||
*/
|
*/
|
||||||
"mp-weixin": {
|
"mp-weixin": {
|
||||||
"appid": "wx5e79df5996572539",
|
"appid": "wx23f86d809ae80259",
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false,
|
"urlCheck": false,
|
||||||
"minified": true
|
"minified": true
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ import {
|
|||||||
NOTICE_EVENT_LOGOUT,
|
NOTICE_EVENT_LOGOUT,
|
||||||
NOTICE_EVENT_LOGIN_SUCCESS,
|
NOTICE_EVENT_LOGIN_SUCCESS,
|
||||||
} from "@/constant/constant";
|
} from "@/constant/constant";
|
||||||
import { WSS_URL } from "@/request/base/baseUrl";
|
|
||||||
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
|
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
|
||||||
import ChatTopWelcome from "../ChatTopWelcome/index.vue";
|
import ChatTopWelcome from "../ChatTopWelcome/index.vue";
|
||||||
import ChatTopNavBar from "../ChatTopNavBar/index.vue";
|
import ChatTopNavBar from "../ChatTopNavBar/index.vue";
|
||||||
@@ -414,7 +413,7 @@ const initWebSocket = () => {
|
|||||||
|
|
||||||
// 使用配置的WebSocket服务器地址
|
// 使用配置的WebSocket服务器地址
|
||||||
const token = uni.getStorageSync("token");
|
const token = uni.getStorageSync("token");
|
||||||
const wsUrl = `${WSS_URL}?access_token=${token}`;
|
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
|
||||||
|
|
||||||
// 初始化WebSocket管理器
|
// 初始化WebSocket管理器
|
||||||
webSocketManager = new WebSocketManager({
|
webSocketManager = new WebSocketManager({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BASE_URL } from "@/request/base/baseUrl";
|
|
||||||
import { goLogin } from "@/hooks/useGoLogin";
|
import { goLogin } from "@/hooks/useGoLogin";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
|
||||||
/// 请求流式数据的API
|
/// 请求流式数据的API
|
||||||
const API = "/agent/assistant/chat";
|
const API = "/agent/assistant/chat";
|
||||||
@@ -93,8 +93,9 @@ const agentChatStream = (params, onChunk) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
const { serverConfig } = useAppStore();
|
||||||
requestTask = uni.request({
|
requestTask = uni.request({
|
||||||
url: BASE_URL + API, // 替换为你的接口地址
|
url: serverConfig.baseUrl + API, // 替换为你的接口地址
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data: params,
|
data: params,
|
||||||
enableChunked: true,
|
enableChunked: true,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { BASE_URL } from "@/request/base/baseUrl";
|
|
||||||
import { getCurrentConfig } from "@/constant/base";
|
import { getCurrentConfig } from "@/constant/base";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
|
||||||
export const updateImageFile = (file) => {
|
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 token = uni.getStorageSync("token");
|
||||||
const clientId = getCurrentConfig().clientId;
|
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 { goLogin } from "../../hooks/useGoLogin";
|
||||||
import { BASE_URL } from "./baseUrl";
|
|
||||||
import { getCurrentConfig } from "@/constant/base";
|
import { getCurrentConfig } from "@/constant/base";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||||
@@ -14,9 +13,10 @@ const defaultConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function request(url, args = {}, method = "POST", customConfig = {}) {
|
function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||||
|
const appStore = useAppStore();
|
||||||
// 判断 url 是否以 http 开头
|
// 判断 url 是否以 http 开头
|
||||||
if (!/^http/.test(url)) {
|
if (!/^http/.test(url)) {
|
||||||
url = BASE_URL + url;
|
url = appStore.serverConfig.baseUrl + url;
|
||||||
}
|
}
|
||||||
// 动态获取 token
|
// 动态获取 token
|
||||||
const token = uni.getStorageSync("token");
|
const token = uni.getStorageSync("token");
|
||||||
@@ -58,7 +58,6 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
|||||||
if (res.statusCode && res.statusCode === 424) {
|
if (res.statusCode && res.statusCode === 424) {
|
||||||
console.log("424错误,重新登录");
|
console.log("424错误,重新登录");
|
||||||
uni.setStorageSync("token", "");
|
uni.setStorageSync("token", "");
|
||||||
const appStore = useAppStore();
|
|
||||||
appStore.setHasToken(false);
|
appStore.setHasToken(false);
|
||||||
appStore.setTokenExpired(true);
|
appStore.setTokenExpired(true);
|
||||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ export const useAppStore = defineStore("app", {
|
|||||||
state() {
|
state() {
|
||||||
return {
|
return {
|
||||||
title: "",
|
title: "",
|
||||||
sceneId: "", /// 分身场景id
|
sceneId: "", // 分身场景id
|
||||||
hasToken: false, /// 是否有token
|
hasToken: false, // 是否有token
|
||||||
tokenExpired: false, /// token是否过期
|
tokenExpired: false, // token是否过期
|
||||||
previewImageData: [], /// 预览图片数据
|
previewImageData: [], // 预览图片数据
|
||||||
|
serverConfig: {
|
||||||
|
baseUrl: "https://onefeel.brother7.cn/ingress", // 服务器基础地址
|
||||||
|
wssUrl: "wss://onefeel.brother7.cn/ingress/agent/ws/chat", // 服务器ws地址
|
||||||
|
}, // 服务器配置
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getters: {},
|
getters: {},
|
||||||
@@ -28,6 +32,9 @@ export const useAppStore = defineStore("app", {
|
|||||||
setPreviewImageData(data) {
|
setPreviewImageData(data) {
|
||||||
this.previewImageData = data;
|
this.previewImageData = data;
|
||||||
},
|
},
|
||||||
|
setServerConfig(data) {
|
||||||
|
this.serverConfig = data;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
unistorage: true,
|
unistorage: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user