|
@@ -3,10 +3,15 @@ import config from "@/common/config";
|
|
|
var num = 1;
|
|
|
//接口api
|
|
|
// export const BASE_URL = 'https://api.xyyxt.net' //release
|
|
|
-export const BASE_URL = config.BASE_URL; // 测试环境
|
|
|
-// export const BASE_URL = 'http://42.192.164.187:19005' //test(后端本地)
|
|
|
-export const tenantId = config.tenantId; // 祥粤云学堂:867735392558919680,祥粤学堂:667735392758919630, 中建云学堂-567735392758918520
|
|
|
-
|
|
|
+export const BASE_URL = config.BASE_URL;
|
|
|
+// #ifdef MP-WEIXIN
|
|
|
+export let tenantId = config.tenantId; // 祥粤云学堂:867735392558919680,祥粤学堂:667735392758919630, 中建云学堂-567735392758918520
|
|
|
+// #endif
|
|
|
+// #ifdef H5
|
|
|
+const host =
|
|
|
+ config.NODE_ENV === "pro" ? window.location.host : "120.79.166.78:19012";
|
|
|
+export let tenantId = uni.getStorageSync(host) || "";
|
|
|
+// #endif
|
|
|
export const myRequest = (options) => {
|
|
|
if (store.state.allowLoading && !options.noLoading) {
|
|
|
uni.showLoading({
|
|
@@ -14,10 +19,15 @@ export const myRequest = (options) => {
|
|
|
mask: true,
|
|
|
});
|
|
|
}
|
|
|
- // await getTenantId(options)
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let token = uni.getStorageSync("token");
|
|
|
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
+ // #ifdef H5
|
|
|
+ if (!tenantId) {
|
|
|
+ tenantId = await getTenantId(options);
|
|
|
+ uni.setStorageSync(host, tenantId);
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ let token = uni.getStorageSync("token");
|
|
|
uni.request({
|
|
|
url: BASE_URL + options.url,
|
|
|
method: options.method || "GET",
|
|
@@ -119,22 +129,33 @@ export const myRequest = (options) => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- function getTenantId(response) {
|
|
|
- new Promise((resolve, reject) => {
|
|
|
- uni.request({
|
|
|
- url: config.BASE_URL + "/app/user/edit/shareActivityCode",
|
|
|
- method: "POST",
|
|
|
- success: (res) => {
|
|
|
- if (res.data.code == 200) {
|
|
|
- resolve(res.data.data);
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- reject(JSON.stringify(err));
|
|
|
- },
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
};
|
|
|
+function getTenantId(response) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ uni.request({
|
|
|
+ url: config.BASE_URL + "/app/common/findTenantId",
|
|
|
+ method: "get",
|
|
|
+ data: {
|
|
|
+ hostH5: host,
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ if (res.data.code == 200) {
|
|
|
+ resolve(res.data.data);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: "请求接口失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ reject();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ uni.showToast({
|
|
|
+ title: "请求接口失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ reject(JSON.stringify(err));
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|