From e6fc123b1f5998437a7e489f31ac20c5bdf1cf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=A3=AE?= Date: Fri, 8 May 2026 07:47:04 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=91=98=E5=B7=A5?= =?UTF-8?q?=E9=97=A8=E6=88=B7=E7=99=BB=E5=BD=95=E7=A7=9F=E6=88=B7=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=92=8C=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 主要修改 ### 1. 登录租户选择修复 - 新增全局租户状态管理(useLoginTenantId hook) - 使用 @vueuse/core 的 createGlobalState 持久化租户选择 - 确保组件重新挂载时租户ID不丢失 - 修复登录时租户自动跳回第一个的问题 - 删除登录时强制覆盖租户ID的代码 - 用户选择的租户现在会被正确使用 - 恢复"记住登录"功能 - 自动恢复上次登录的租户、用户名、密码 ### 2. ERP 动态API迁移 - 员工门户和经销商门户的ERP API从硬编码迁移到动态API系统 - /erp/customer/* → /erp/dynamic/v1/customer/* - 新增 customer/list, customer/detail, sales-areas, brands API - 修复API响应嵌套结构问题 - 动态API返回数据嵌套在 data 字段中 - 调整响应类型定义和数据处理逻辑 ### 3. 经销商管理数据显示修复 - 处理动态API响应的嵌套数据结构 - 兼容 res.rows 和 res.data.rows 两种格式 - 添加详细调试日志便于排查问题 ## 文件清单 - 新增文件: - hzhub-portal-employee/src/hooks/useLoginTenantId.ts - hzhub-portal-dealer/src/hooks/useLoginTenantId.ts - hzhub-portal-employee/src/api/erp/index.ts - hzhub-portal-dealer/src/api/erp/index.ts - 修改文件: - 登录组件:TenantAccountPassword.vue, AccountPassword.vue - API文件:auth/index.ts, auth/types.ts - 经销商页面:dealer/index.vue ## 测试验证 - ✅ 租户下拉列表正常显示 - ✅ 选择租户后不会跳回第一个 - ✅ 记住登录功能可用 - ✅ 经销商管理页面数据正常显示 Co-Authored-By: Claude Sonnet 4.6 --- hzhub-portal-dealer/src/api/auth/index.ts | 7 +- hzhub-portal-dealer/src/api/auth/types.ts | 13 + hzhub-portal-dealer/src/api/erp/index.ts | 92 +++ .../components/FormLogin/AccountPassword.vue | 77 ++- .../src/hooks/useLoginTenantId.ts | 15 + hzhub-portal-employee/src/api/auth/index.ts | 7 +- hzhub-portal-employee/src/api/auth/types.ts | 13 + hzhub-portal-employee/src/api/erp/index.ts | 92 +++ .../src/hooks/useLoginTenantId.ts | 15 + .../src/pages/dealer/index.vue | 544 ++++++++++++++---- .../components/TenantAccountPassword.vue | 114 +++- 11 files changed, 867 insertions(+), 122 deletions(-) create mode 100644 hzhub-portal-dealer/src/api/erp/index.ts create mode 100644 hzhub-portal-dealer/src/hooks/useLoginTenantId.ts create mode 100644 hzhub-portal-employee/src/api/erp/index.ts create mode 100644 hzhub-portal-employee/src/hooks/useLoginTenantId.ts diff --git a/hzhub-portal-dealer/src/api/auth/index.ts b/hzhub-portal-dealer/src/api/auth/index.ts index c1b21b9..53112bb 100644 --- a/hzhub-portal-dealer/src/api/auth/index.ts +++ b/hzhub-portal-dealer/src/api/auth/index.ts @@ -1,8 +1,11 @@ -import type { EmailCodeDTO, LoginDTO, LoginVO, RegisterDTO } from './types'; -import { post } from '@/utils/request'; +import type { EmailCodeDTO, LoginDTO, LoginVO, RegisterDTO, TenantResp } from './types'; +import { post, get } from '@/utils/request'; export const login = (data: LoginDTO) => post('/auth/login', data).json(); +// 获取租户列表 +export const tenantList = () => get('/auth/tenant/list').json(); + // 邮箱验证码 export const emailCode = (data: EmailCodeDTO) => post('/resource/email/code', data).json(); diff --git a/hzhub-portal-dealer/src/api/auth/types.ts b/hzhub-portal-dealer/src/api/auth/types.ts index 84eaced..5c6cf41 100644 --- a/hzhub-portal-dealer/src/api/auth/types.ts +++ b/hzhub-portal-dealer/src/api/auth/types.ts @@ -16,6 +16,19 @@ export interface LoginVO { userInfo?: LoginUser; } +// 租户选项 +export interface TenantOption { + companyName: string; + domain?: string; + tenantId: string; +} + +// 租户列表响应 +export interface TenantResp { + tenantEnabled: boolean; + voList: TenantOption[]; +} + /** * LoginUser,登录用户身份权限 */ diff --git a/hzhub-portal-dealer/src/api/erp/index.ts b/hzhub-portal-dealer/src/api/erp/index.ts new file mode 100644 index 0000000..0cd2f1d --- /dev/null +++ b/hzhub-portal-dealer/src/api/erp/index.ts @@ -0,0 +1,92 @@ +import request from '@/utils/request'; + +/** + * 测试 ERP 数据库连接 + */ +export function testErpConnection() { + return request.get<{ + status: string; + database: string; + version: string; + error?: string; + }>('/erp/test/connection').json(); +} + +/** + * ERP 健康检查 + */ +export function erpHealth() { + return request.get('/erp/test/health').json(); +} + +/** + * 客户档案接口类型 + */ +export interface CustomerVO { + customerCode: string; + customerName: string; + companyCode: string; + companyName: string; + brand: string; + brandName: string; + contactName: string; + salesAreaCode: string; + salesAreaName: string; + salesPersonCode: string; + salesPersonName: string; + saleDocCode: string; + saleDocName: string; + pricePlanCode: string; + pricePlanName: string; + customerType: string; + address: string; + phone: string; + email: string; + sdOrgCode: string; + sdOrgName: string; + province: string; + city: string; + isStop: number; +} + +/** + * 分页查询客户列表 + * 使用动态API: /erp/dynamic/v1/customer/list + */ +export function getCustomerList(params: { + pageNum: number; + pageSize: number; + keyword?: string; + companyCode?: string; + salesAreaCode?: string; + brand?: string; +}) { + return request.get<{ rows: CustomerVO[]; total: number; code: number; msg: string }>( + '/erp/dynamic/v1/customer/list', + params + ).json(); +} + +/** + * 获取客户详情 + * 使用动态API: /erp/dynamic/v1/customer/detail + */ +export function getCustomerDetail(customerCode: string) { + return request.get<{ code: number; msg: string; data: CustomerVO }>(`/erp/dynamic/v1/customer/detail?customerCode=${customerCode}`).json(); +} + +/** + * 获取销区列表 + * 使用动态API: /erp/dynamic/v1/customer/sales-areas + */ +export function getSalesAreas() { + return request.get<{ code: number; msg: string; data: CustomerVO[] }>('/erp/dynamic/v1/customer/sales-areas').json(); +} + +/** + * 获取品牌列表 + * 使用动态API: /erp/dynamic/v1/customer/brands + */ +export function getBrands() { + return request.get<{ code: number; msg: string; data: CustomerVO[] }>('/erp/dynamic/v1/customer/brands').json(); +} \ No newline at end of file diff --git a/hzhub-portal-dealer/src/components/LoginDialog/components/FormLogin/AccountPassword.vue b/hzhub-portal-dealer/src/components/LoginDialog/components/FormLogin/AccountPassword.vue index b289a35..cbf8d6d 100644 --- a/hzhub-portal-dealer/src/components/LoginDialog/components/FormLogin/AccountPassword.vue +++ b/hzhub-portal-dealer/src/components/LoginDialog/components/FormLogin/AccountPassword.vue @@ -1,26 +1,36 @@ @@ -58,6 +111,18 @@ async function handleSubmit() { style="width: 230px" @submit.prevent="handleSubmit" > + + + + + + +