解决小程序上传时出现的问题。
This commit is contained in:
102
unpackage/dist/dev/mp-weixin/common/appInit.js
vendored
102
unpackage/dist/dev/mp-weixin/common/appInit.js
vendored
@@ -2,22 +2,6 @@
|
||||
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;
|
||||
@@ -27,26 +11,28 @@ function setupRequestInterceptor() {
|
||||
const originalRequest = common_vendor.index.request;
|
||||
common_vendor.index.request = function(options = {}) {
|
||||
const { url, header = {}, method = "GET", ...restOptions } = options;
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:59", "[Request Interceptor] 开始拦截请求:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
isLoginApi: isLoginApi(url),
|
||||
originalOptions: 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);
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:71", "[Request Interceptor] 获取 tenantId 失败:", e);
|
||||
}
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:74", "[Request Interceptor] tenantId状态:", {
|
||||
tenantId,
|
||||
hasTenantId: !!tenantId
|
||||
});
|
||||
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("未登录,请先登录"));
|
||||
}
|
||||
}
|
||||
common_vendor.index.__f__("warn", "at common/appInit.js:83", "[Request Interceptor] 租户ID为空,但允许请求继续执行,由后端处理认证");
|
||||
} else if (isLoginApi(url)) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:86", "[Request Interceptor] 这是登录接口,跳过租户ID检查");
|
||||
} else {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:88", "[Request Interceptor] 租户ID存在,正常处理请求");
|
||||
}
|
||||
const newHeader = {
|
||||
"Content-Type": "application/json",
|
||||
@@ -64,7 +50,7 @@ function setupRequestInterceptor() {
|
||||
delete newHeader["Authorization"];
|
||||
}
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:118", "获取 token 失败:", e);
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:115", "获取 token 失败:", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -77,25 +63,42 @@ function setupRequestInterceptor() {
|
||||
newHeader["X-Scenario"] = scenario;
|
||||
}
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:133", "获取 roleName 或 scenario 失败:", e);
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:130", "获取 roleName 或 scenario 失败:", e);
|
||||
}
|
||||
const finalRequestOptions = {
|
||||
...restOptions,
|
||||
url,
|
||||
method,
|
||||
header: newHeader
|
||||
};
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:141", "[Request Interceptor] 准备发送请求:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
headers: newHeader,
|
||||
hasData: !!restOptions.data
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:151", "[Request Interceptor] 开始调用原始 uni.request");
|
||||
originalRequest.call(common_vendor.index, {
|
||||
...restOptions,
|
||||
url,
|
||||
method,
|
||||
header: newHeader,
|
||||
...finalRequestOptions,
|
||||
success: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:155", "[Request Interceptor] 请求成功:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
statusCode: res.statusCode,
|
||||
hasData: !!res.data
|
||||
});
|
||||
if (options.success) {
|
||||
options.success(res);
|
||||
}
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:153", "[Request Interceptor] 请求失败:", {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:170", "[Request Interceptor] 请求失败:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
error: err
|
||||
error: err,
|
||||
errorMessage: err.errMsg || "未知错误"
|
||||
});
|
||||
if (options.fail) {
|
||||
options.fail(err);
|
||||
@@ -103,6 +106,11 @@ function setupRequestInterceptor() {
|
||||
reject(err);
|
||||
},
|
||||
complete: (res) => {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:184", "[Request Interceptor] 请求完成:", {
|
||||
url,
|
||||
method: method.toUpperCase(),
|
||||
hasResponse: !!res
|
||||
});
|
||||
if (options.complete) {
|
||||
options.complete(res);
|
||||
}
|
||||
@@ -123,7 +131,7 @@ async function initApp() {
|
||||
app.globalData.config = uniStarter_config.config;
|
||||
}
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("warn", "at common/appInit.js:194", "[appInit] 挂载配置失败:", e);
|
||||
common_vendor.index.__f__("warn", "at common/appInit.js:217", "[appInit] 挂载配置失败:", e);
|
||||
}
|
||||
}, 1);
|
||||
function onDBError({
|
||||
@@ -131,11 +139,11 @@ async function initApp() {
|
||||
// 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
|
||||
message
|
||||
}) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:207", "onDBError", {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:230", "onDBError", {
|
||||
code,
|
||||
message
|
||||
});
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:212", code, message);
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:235", code, message);
|
||||
}
|
||||
db.on("error", onDBError);
|
||||
common_vendor.tr.interceptObject({
|
||||
@@ -148,21 +156,21 @@ async function initApp() {
|
||||
// 参数列表
|
||||
}) {
|
||||
if (objectName == "uni-id-co" && (methodName.includes("loginBy") || ["login", "registerUser"].includes(methodName))) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:231", "执行登录相关云对象");
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:254", "执行登录相关云对象");
|
||||
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);
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:258", "剪切板内容:" + 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);
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:261", "当前用户是其他用户推荐下载的,推荐者的code是:" + uniInvitationCode);
|
||||
callBack(uniInvitationCode);
|
||||
} else {
|
||||
callBack();
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:250", "error--");
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:273", "error--");
|
||||
callBack();
|
||||
},
|
||||
complete() {
|
||||
@@ -173,12 +181,12 @@ async function initApp() {
|
||||
}
|
||||
},
|
||||
success(e) {
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:265", e);
|
||||
common_vendor.index.__f__("log", "at common/appInit.js:288", e);
|
||||
},
|
||||
complete() {
|
||||
},
|
||||
fail(e) {
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:271", e);
|
||||
common_vendor.index.__f__("error", "at common/appInit.js:294", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user