Преглед изворни кода

feat(api): 添加租户编码支持及相关请求头处理

- 在全局类型定义中添加 tenantCode 字段
- 为所有请求添加 X-Tenant-code 请求头,值为 'zswl'
- 登录页面调用发送验证码接口时携带 tenantCode 参数
- 登录接口请求中增加 tenantCode 参数以支持多租户环境
zhangtao пре 2 дана
родитељ
комит
caf9d7dd26
3 измењених фајлова са 4 додато и 3 уклоњено
  1. 1 1
      src/api/core/instance.ts
  2. 1 0
      src/api/globals.d.ts
  3. 2 2
      src/pages/login/index.vue

+ 1 - 1
src/api/core/instance.ts

@@ -20,7 +20,7 @@ export const alovaInstance = createAlova({
     if (method.type === 'GET' && CommonUtil.isObj(method.config.params)) {
       method.config.params._t = Date.now()
     }
-
+    method.config.headers['X-Tenant-code'] = 'zswl'
     // Log request in development
     if (import.meta.env.MODE === 'development') {
       console.log(`[Alova Request] ${method.type} ${method.url}`, method.data || method.config.params)

+ 1 - 0
src/api/globals.d.ts

@@ -4079,6 +4079,7 @@ declare global {
              * 手机号
              */
             mobile: string;
+            tenantCode: string;
           };
         }
       >(

+ 2 - 2
src/pages/login/index.vue

@@ -45,7 +45,7 @@ async function handleSendCode() {
   }, 1000)
 
   // TODO: 调用发送验证码接口
-  await Apis.general.post_smqjh_auth_api_v1_auth_sms_code({ params: { mobile: phone.value } })
+  await Apis.general.post_smqjh_auth_api_v1_auth_sms_code({ params: { mobile: phone.value, tenantCode: 'zswl' } })
   useGlobalToast().show('验证码已发送')
 }
 
@@ -61,7 +61,7 @@ async function handleLogin() {
   }
   uni.showLoading({ mask: true })
   try {
-    const res = await Apis.general.post_smqjh_auth_oauth2_token({ params: { grant_type: 'sms_code', mobile: phone.value, code: code.value } })
+    const res = await Apis.general.post_smqjh_auth_oauth2_token({ params: { grant_type: 'sms_code', mobile: phone.value, code: code.value, tenantCode: 'zswl' } })
     uni.hideLoading()
     token.value = `Bearer ${res.data.access_token}`
     useGlobalToast().show('登录成功')