1
This commit is contained in:
@@ -6,18 +6,26 @@ const fallbackBaseUrl = "http://127.0.0.1:8080";
|
||||
const API_BASE_URL = (envBaseUrl || storageBaseUrl || fallbackBaseUrl).replace(/\/$/, "");
|
||||
const candidateBases = [envBaseUrl, storageBaseUrl, fallbackBaseUrl, "http://127.0.0.1:8080", "http://localhost:8080"];
|
||||
const API_BASE_URL_CANDIDATES = Array.from(new Set(candidateBases.filter(Boolean))).map((u) => String(u).replace(/\/$/, ""));
|
||||
const envShopId = typeof process !== "undefined" && process.env && (process.env.VITE_APP_SHOP_ID || process.env.SHOP_ID) || "";
|
||||
const storageShopId = typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("SHOP_ID") || "" : "";
|
||||
const SHOP_ID = Number(envShopId || storageShopId || 1);
|
||||
typeof process !== "undefined" && process.env && (process.env.VITE_APP_SHOP_ID || process.env.SHOP_ID) || "";
|
||||
typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("SHOP_ID") || "" : "";
|
||||
const envEnableDefaultUser = typeof process !== "undefined" && process.env && (process.env.VITE_APP_ENABLE_DEFAULT_USER || process.env.ENABLE_DEFAULT_USER) || "";
|
||||
const storageEnableDefaultUser = typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("ENABLE_DEFAULT_USER") || "" : "";
|
||||
const ENABLE_DEFAULT_USER = String(envEnableDefaultUser || storageEnableDefaultUser || "true").toLowerCase() === "true";
|
||||
const envDefaultUserId = typeof process !== "undefined" && process.env && (process.env.VITE_APP_DEFAULT_USER_ID || process.env.DEFAULT_USER_ID) || "";
|
||||
const storageDefaultUserId = typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("DEFAULT_USER_ID") || "" : "";
|
||||
const DEFAULT_USER_ID = Number(envDefaultUserId || storageDefaultUserId || 2);
|
||||
String(envEnableDefaultUser || storageEnableDefaultUser || "false").toLowerCase() === "true";
|
||||
typeof process !== "undefined" && process.env && (process.env.VITE_APP_DEFAULT_USER_ID || process.env.DEFAULT_USER_ID) || "";
|
||||
typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("DEFAULT_USER_ID") || "" : "";
|
||||
const envVipPrice = typeof process !== "undefined" && process.env && (process.env.VITE_APP_VIP_PRICE || process.env.VIP_PRICE) || "";
|
||||
const storageVipPrice = typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("VIP_PRICE") || "" : "";
|
||||
const VIP_PRICE_PER_MONTH = Number(envVipPrice || storageVipPrice || 15);
|
||||
typeof process !== "undefined" && process.env && (process.env.VITE_APP_HOME_BANNER_IMG || process.env.HOME_BANNER_IMG) || "";
|
||||
typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("HOME_BANNER_IMG") || "" : "";
|
||||
const KPI_ICONS = {
|
||||
todaySales: "/static/icons/sale.png",
|
||||
monthSales: "/static/icons/report.png",
|
||||
monthProfit: "/static/icons/report.png",
|
||||
stockCount: "/static/icons/product.png"
|
||||
};
|
||||
exports.API_BASE_URL = API_BASE_URL;
|
||||
exports.API_BASE_URL_CANDIDATES = API_BASE_URL_CANDIDATES;
|
||||
exports.DEFAULT_USER_ID = DEFAULT_USER_ID;
|
||||
exports.ENABLE_DEFAULT_USER = ENABLE_DEFAULT_USER;
|
||||
exports.SHOP_ID = SHOP_ID;
|
||||
exports.KPI_ICONS = KPI_ICONS;
|
||||
exports.VIP_PRICE_PER_MONTH = VIP_PRICE_PER_MONTH;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/config.js.map
|
||||
|
||||
@@ -23,6 +23,7 @@ const ROUTES = {
|
||||
detail: "/pages/detail/index",
|
||||
my: "/pages/my/index",
|
||||
myAbout: "/pages/my/about",
|
||||
myVip: "/pages/my/vip",
|
||||
report: "/pages/report/index",
|
||||
customerSelect: "/pages/customer/select",
|
||||
supplierSelect: "/pages/supplier/select",
|
||||
|
||||
@@ -8,56 +8,84 @@ function buildUrl(path) {
|
||||
return path;
|
||||
return common_config.API_BASE_URL + (path.startsWith("/") ? path : "/" + path);
|
||||
}
|
||||
function parseJwtClaims(token) {
|
||||
try {
|
||||
const parts = String(token || "").split(".");
|
||||
if (parts.length < 2)
|
||||
return {};
|
||||
const payload = JSON.parse(decodeURIComponent(escape(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")))));
|
||||
return payload || {};
|
||||
} catch (_) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
function buildAuthHeaders(base = {}) {
|
||||
const headers = { ...base };
|
||||
try {
|
||||
const token = typeof common_vendor.index !== "undefined" ? common_vendor.index.getStorageSync("TOKEN") || "" : "";
|
||||
if (token) {
|
||||
headers["Authorization"] = `Bearer ${token}`;
|
||||
const claims = parseJwtClaims(token);
|
||||
if (claims && claims.shopId)
|
||||
headers["X-Shop-Id"] = claims.shopId;
|
||||
if (claims && claims.userId)
|
||||
headers["X-User-Id"] = claims.userId;
|
||||
}
|
||||
} catch (_) {
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
function requestWithFallback(options, candidates, idx, resolve, reject) {
|
||||
const base = candidates[idx] || common_config.API_BASE_URL;
|
||||
const url = options.url.replace(/^https?:\/\/[^/]+/, base);
|
||||
common_vendor.index.request({ ...options, url, success: (res) => {
|
||||
let url = options.url;
|
||||
if (!/^https?:\/\//.test(url)) {
|
||||
url = base + (url.startsWith("/") ? "" : "/") + url;
|
||||
} else {
|
||||
url = options.url.replace(/^https?:\/\/[^/]+/, base);
|
||||
}
|
||||
common_vendor.index.request({ ...options, url, dataType: "json", success: (res) => {
|
||||
const { statusCode, data } = res;
|
||||
if (statusCode >= 200 && statusCode < 300)
|
||||
return resolve(data);
|
||||
const msg = data && (data.message || data.error || data.msg) || "HTTP " + statusCode;
|
||||
common_vendor.index.showToast({ title: msg, icon: "none" });
|
||||
if (idx + 1 < candidates.length)
|
||||
if (!options.__noRetry && statusCode >= 500 && idx + 1 < candidates.length) {
|
||||
return requestWithFallback(options, candidates, idx + 1, resolve, reject);
|
||||
}
|
||||
reject(new Error(msg));
|
||||
}, fail: (err) => {
|
||||
if (idx + 1 < candidates.length)
|
||||
if (!options.__noRetry && idx + 1 < candidates.length)
|
||||
return requestWithFallback(options, candidates, idx + 1, resolve, reject);
|
||||
reject(err);
|
||||
} });
|
||||
}
|
||||
function get(path, params = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const headers = { "X-Shop-Id": common_config.SHOP_ID };
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID)
|
||||
headers["X-User-Id"] = common_config.DEFAULT_USER_ID;
|
||||
const headers = buildAuthHeaders({});
|
||||
const options = { url: buildUrl(path), method: "GET", data: params, header: headers };
|
||||
requestWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
}
|
||||
function post(path, body = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const headers = { "Content-Type": "application/json", "X-Shop-Id": common_config.SHOP_ID };
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID)
|
||||
headers["X-User-Id"] = common_config.DEFAULT_USER_ID;
|
||||
const headers = buildAuthHeaders({ "Content-Type": "application/json" });
|
||||
const options = { url: buildUrl(path), method: "POST", data: body, header: headers };
|
||||
const p = String(path || "");
|
||||
if (p.includes("/api/auth/wxmp/login") || p.includes("/api/auth/sms/login") || p.includes("/api/auth/sms/send") || p.includes("/api/auth/password/login") || p.includes("/api/auth/register"))
|
||||
options.__noRetry = true;
|
||||
requestWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
}
|
||||
function put(path, body = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const headers = { "Content-Type": "application/json", "X-Shop-Id": common_config.SHOP_ID };
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID)
|
||||
headers["X-User-Id"] = common_config.DEFAULT_USER_ID;
|
||||
const headers = buildAuthHeaders({ "Content-Type": "application/json" });
|
||||
const options = { url: buildUrl(path), method: "PUT", data: body, header: headers };
|
||||
requestWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
}
|
||||
function del(path, body = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const headers = { "Content-Type": "application/json", "X-Shop-Id": common_config.SHOP_ID };
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID)
|
||||
headers["X-User-Id"] = common_config.DEFAULT_USER_ID;
|
||||
const headers = buildAuthHeaders({ "Content-Type": "application/json" });
|
||||
const options = { url: buildUrl(path), method: "DELETE", data: body, header: headers };
|
||||
requestWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
@@ -91,9 +119,7 @@ function uploadWithFallback(options, candidates, idx, resolve, reject) {
|
||||
}
|
||||
function upload(path, filePath, formData = {}, name = "file") {
|
||||
return new Promise((resolve, reject) => {
|
||||
const header = { "X-Shop-Id": common_config.SHOP_ID };
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID)
|
||||
header["X-User-Id"] = common_config.DEFAULT_USER_ID;
|
||||
const header = buildAuthHeaders({});
|
||||
const options = { url: buildUrl(path), filePath, name, formData, header };
|
||||
uploadWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
|
||||
@@ -7074,7 +7074,7 @@ function isConsoleWritable() {
|
||||
function initRuntimeSocketService() {
|
||||
const hosts = "198.18.0.1,192.168.31.192,127.0.0.1";
|
||||
const port = "8090";
|
||||
const id = "mp-weixin_qYdvJf";
|
||||
const id = "mp-weixin_t4IBTG";
|
||||
const lazy = typeof swan !== "undefined";
|
||||
let restoreError = lazy ? () => {
|
||||
} : initOnError();
|
||||
|
||||
Reference in New Issue
Block a user