调整微信小程序的报错。

This commit is contained in:
cst61
2026-02-01 09:49:48 +08:00
parent cc01c4dc47
commit 802ffbb2f3
454 changed files with 62476 additions and 45 deletions

View File

@@ -0,0 +1,186 @@
"use strict";
const common_vendor = require("./vendor.js");
const uniStarter_config = require("../uni-starter.config.js");
const db = common_vendor.tr.database();
function redirectToLogin() {
const loginPage = "/uni_modules/uni-id-pages/pages/login/login-withpwd";
const pages = getCurrentPages();
if (pages.length > 0) {
const currentPage = pages[pages.length - 1];
if (currentPage.route && currentPage.route.includes("login")) {
return;
}
}
common_vendor.index.reLaunch({
url: loginPage,
fail: (err) => {
common_vendor.index.__f__("error", "at common/appInit.js:32", "跳转登录页失败:", err);
}
});
}
function isLoginApi(url) {
if (!url)
return false;
return url.includes("/api/sys/auth/login");
}
function setupRequestInterceptor() {
const originalRequest = common_vendor.index.request;
common_vendor.index.request = function(options = {}) {
const { url, header = {}, method = "GET", ...restOptions } = options;
let tenantId = "";
try {
tenantId = common_vendor.index.getStorageSync("backend-tenant-id") || "";
} catch (e) {
common_vendor.index.__f__("error", "at common/appInit.js:63", "获取 tenantId 失败:", e);
}
if (!isLoginApi(url) && !tenantId) {
const pages = getCurrentPages();
const hasLoadedPages = pages.length > 0 && pages[pages.length - 1].route;
if (hasLoadedPages) {
const currentPage = pages[pages.length - 1];
const currentRoute = "/" + currentPage.route;
const isHomePage = currentRoute.includes("/pages/furniture_reception/furniture_reception");
const isLoginRelated = currentRoute.includes("/uni_modules/uni-id-pages/pages/login") || currentRoute.includes("/uni_modules/uni-id-pages/pages/register") || currentRoute.includes("/uni_modules/uni-id-pages/pages/retrieve");
if (!isHomePage && !isLoginRelated) {
common_vendor.index.__f__("warn", "at common/appInit.js:85", "[Request Interceptor] 租户ID为空跳转到登录页面");
redirectToLogin();
return Promise.reject(new Error("未登录,请先登录"));
}
}
}
const newHeader = {
"Content-Type": "application/json",
...header
};
if (tenantId) {
newHeader["X-Tenant-Id"] = tenantId;
}
if (!isLoginApi(url)) {
try {
const token = common_vendor.index.getStorageSync("backend-token") || "";
if (token) {
newHeader["Authorization"] = `Bearer ${token}`;
} else {
delete newHeader["Authorization"];
}
} catch (e) {
common_vendor.index.__f__("error", "at common/appInit.js:118", "获取 token 失败:", e);
}
}
try {
const roleName = common_vendor.index.getStorageSync("backend-role-name") || "";
if (roleName) {
newHeader["X-Role-Name"] = roleName;
}
const scenario = common_vendor.index.getStorageSync("backend-scenario") || "";
if (scenario) {
newHeader["X-Scenario"] = scenario;
}
} catch (e) {
common_vendor.index.__f__("error", "at common/appInit.js:133", "获取 roleName 或 scenario 失败:", e);
}
return new Promise((resolve, reject) => {
originalRequest.call(common_vendor.index, {
...restOptions,
url,
method,
header: newHeader,
success: (res) => {
if (options.success) {
options.success(res);
}
resolve(res);
},
fail: (err) => {
common_vendor.index.__f__("error", "at common/appInit.js:153", "[Request Interceptor] 请求失败:", {
url,
method: method.toUpperCase(),
error: err
});
if (options.fail) {
options.fail(err);
}
reject(err);
},
complete: (res) => {
if (options.complete) {
options.complete(res);
}
}
});
});
};
}
async function initApp() {
uniStarter_config.config.debug;
setupRequestInterceptor();
setTimeout(() => {
try {
const app = getApp({
allowDefault: true
});
if (app && app.globalData) {
app.globalData.config = uniStarter_config.config;
}
} catch (e) {
common_vendor.index.__f__("warn", "at common/appInit.js:194", "[appInit] 挂载配置失败:", e);
}
}, 1);
function onDBError({
code,
// 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
message
}) {
common_vendor.index.__f__("log", "at common/appInit.js:207", "onDBError", {
code,
message
});
common_vendor.index.__f__("error", "at common/appInit.js:212", code, message);
}
db.on("error", onDBError);
common_vendor.tr.interceptObject({
async invoke({
objectName,
// 云对象名称
methodName,
// 云对象的方法名称
params
// 参数列表
}) {
if (objectName == "uni-id-co" && (methodName.includes("loginBy") || ["login", "registerUser"].includes(methodName))) {
common_vendor.index.__f__("log", "at common/appInit.js:231", "执行登录相关云对象");
params[0].inviteCode = await new Promise((callBack) => {
common_vendor.index.getClipboardData({
success: function(res) {
common_vendor.index.__f__("log", "at common/appInit.js:235", "剪切板内容:" + res.data);
if (res.data.slice(0, 18) == "uniInvitationCode:") {
let uniInvitationCode = res.data.slice(18, 38);
common_vendor.index.__f__("log", "at common/appInit.js:238", "当前用户是其他用户推荐下载的,推荐者的code是" + uniInvitationCode);
callBack(uniInvitationCode);
} else {
callBack();
}
},
fail() {
common_vendor.index.__f__("log", "at common/appInit.js:250", "error--");
callBack();
},
complete() {
common_vendor.index.hideToast();
}
});
});
}
},
success(e) {
common_vendor.index.__f__("log", "at common/appInit.js:265", e);
},
complete() {
},
fail(e) {
common_vendor.index.__f__("error", "at common/appInit.js:271", e);
}
});
}
exports.initApp = initApp;
//# sourceMappingURL=../../.sourcemap/mp-weixin/common/appInit.js.map