From f93affb4a404595d805dd9b96e7a786a5ad2eaa4 Mon Sep 17 00:00:00 2001 From: zhonghua1 Date: Sat, 27 Dec 2025 14:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E5=8C=96=EF=BC=9A=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/appInit.js | 40 +++ common/request.js | 41 +++ pages/champion/champion.vue | 385 +++++++++++++-------- pages/customer/components/CustomerList.vue | 148 +++++++- pages/customer/components/ServiceList.vue | 171 +++++---- pages/customer/customer-refactored.vue | 2 +- pages/customer/customer.vue | 27 +- pages/reception/reception.vue | 154 ++++++--- pages/team/team.vue | 15 +- 9 files changed, 694 insertions(+), 289 deletions(-) diff --git a/common/appInit.js b/common/appInit.js index 3c6ffe7..b50d0bf 100644 --- a/common/appInit.js +++ b/common/appInit.js @@ -11,6 +11,38 @@ interceptorChooseImage() // #endif const db = uniCloud.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 + } + } + + uni.reLaunch({ + url: loginPage, + fail: (err) => { + console.error('跳转登录页失败:', err) + } + }) +} + +/** + * 检查是否为登录相关接口(不需要租户ID的接口) + */ +function isLoginApi(url) { + if (!url) return false + // 登录接口不需要租户ID + return url.includes('/api/sys/auth/login') +} + /** * 设置全局 uni.request 拦截器,自动添加 X-Tenant-Id header */ @@ -30,6 +62,14 @@ function setupRequestInterceptor() { console.error('获取 tenantId 失败:', e) } + // 检查是否需要登录:如果不是登录接口且租户ID为空,则跳转到登录页 + if (!isLoginApi(url) && !tenantId) { + console.warn('[Request Interceptor] 租户ID为空,跳转到登录页面') + redirectToLogin() + // 返回一个被拒绝的Promise,阻止请求继续执行 + return Promise.reject(new Error('未登录,请先登录')) + } + // 构建新的 header(保留原有的 header,避免覆盖) const newHeader = { 'Content-Type': 'application/json', diff --git a/common/request.js b/common/request.js index 8f75558..ace2993 100644 --- a/common/request.js +++ b/common/request.js @@ -17,6 +17,38 @@ function getTenantId() { } } +/** + * 跳转到登录页面 + */ +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 + } + } + + uni.reLaunch({ + url: loginPage, + fail: (err) => { + console.error('跳转登录页失败:', err) + } + }) +} + +/** + * 检查是否为登录相关接口(不需要租户ID的接口) + */ +function isLoginApi(url) { + if (!url) return false + // 登录接口不需要租户ID + return url.includes('/api/sys/auth/login') +} + /** * 获取 token(从本地存储) */ @@ -84,6 +116,15 @@ export function request(options = {}) { // 技术方案:登录返回的 LoginResponse 中包含 tenantId,前端保存后自动添加到所有请求的 header 中 if (needTenantId) { const tenantId = getTenantId() + + // 检查是否需要登录:如果不是登录接口且租户ID为空,则跳转到登录页 + if (!isLoginApi(fullUrl) && !tenantId) { + console.warn('[Request] 租户ID为空,跳转到登录页面') + redirectToLogin() + // 返回一个被拒绝的Promise,阻止请求继续执行 + return Promise.reject(new Error('未登录,请先登录')) + } + if (tenantId) { // 将 tenantId 放入 X-Tenant-Id header(适用于所有请求类型:GET、POST、PUT、DELETE) requestHeader['X-Tenant-Id'] = tenantId diff --git a/pages/champion/champion.vue b/pages/champion/champion.vue index 2fefdb6..2302f55 100644 --- a/pages/champion/champion.vue +++ b/pages/champion/champion.vue @@ -8,7 +8,7 @@ - - - - - @@ -123,11 +118,11 @@ - - 详情: {{ getContentPreview(item.content) }} + + 详情: {{ getContentPreview(item.content || item.detail, 30) }} - 备注: {{ item.remark }} + 提示词: {{ getContentPreview(item.remark, 30) }} @@ -198,18 +193,24 @@ /> - 文件上传 - - - {{ practiceForm.file.name || '文件' }} - - - - - - - - + 详情 +