Kaynağa Gözat

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

- 在全局类型定义中添加 tenantCode 字段
- 为所有请求添加 X-Tenant-code 请求头,值为 'zswl'
- 登录页面调用发送验证码接口时携带 tenantCode 参数
- 登录接口请求中增加 tenantCode 参数以支持多租户环境
zhangtao 2 gün önce
ebeveyn
işleme
caf9d7dd26

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

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

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

@@ -45,7 +45,7 @@ async function handleSendCode() {
   }, 1000)
   }, 1000)
 
 
   // TODO: 调用发送验证码接口
   // 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('验证码已发送')
   useGlobalToast().show('验证码已发送')
 }
 }
 
 
@@ -61,7 +61,7 @@ async function handleLogin() {
   }
   }
   uni.showLoading({ mask: true })
   uni.showLoading({ mask: true })
   try {
   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()
     uni.hideLoading()
     token.value = `Bearer ${res.data.access_token}`
     token.value = `Bearer ${res.data.access_token}`
     useGlobalToast().show('登录成功')
     useGlobalToast().show('登录成功')