Parcourir la source

feat(core): 添加租户代码tenantCode支持并优化环境配置

- 在全局类型定义中新增tenantCode字段以支持多租户
- 在请求实例中为H5端请求头添加X-Tenant-code字段传递tenantCode
- 在登录和验证码请求中加入tenantCode参数以支持租户鉴权
- 配置文件调整开发环境服务地址为http://192.168.0.11:8081
- 系统状态管理新增tenantCode字段,并从接口获取租户信息赋值
- 首页根据平台分别展示本地和第三方logo
- 登录页调整验证码发送和Token请求逻辑,传递当前tenantCode
- 新增获取渠道accessId的方法,提升多渠道支持
- 景点预订页调整界面布局,添加底部间距优化显示
zhangtao il y a 4 jours
Parent
commit
b7668d898d

+ 4 - 7
src/api/core/instance.ts

@@ -13,13 +13,12 @@ export const alovaInstance = createAlova({
     if (['POST', 'PUT', 'PATCH'].includes(method.type)) {
       method.config.headers['Content-Type'] = 'application/json'
     }
-    // if (['POST', 'PUT', 'PATCH', 'DELETE', 'GET'].includes(method.type)) {
-    //   method.config.headers['X-Tenant-Domain'] = BASE_URL
-    // }
     const { token } = useUserStore()
     method.config.headers.Authorization = token || 'Basic c21xamgtYXBwbGV0OjEyMzQ1Ng=='
-    method.config.headers['X-Tenant-Domain'] = 'http://192.168.1.40:5174'
-    // Add timestamp to prevent caching for GET requests
+    // #ifdef H5
+    method.config.headers['X-Tenant-code'] = useSysStore().tenantCode
+    // #endif
+
     if (method.type === 'GET' && CommonUtil.isObj(method.config.params)) {
       method.config.params._t = Date.now()
     }
@@ -30,8 +29,6 @@ export const alovaInstance = createAlova({
         `[Alova Request] ${method.type} ${method.url}`,
         method.data || method.config.params,
       )
-      // console.log(`[API Base URL] ${import.meta.env.VITE_API_BASE_URL}`);
-      // console.log(`[Environment] ${import.meta.env.VITE_ENV_NAME}`);
     }
     console.log(
       BASE_URL,

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

@@ -2787,6 +2787,7 @@ declare global {
             mobile: string;
             token_type: string;
             expires_in: number;
+            tenantCode: string;
           };
           msg: string;
         }> & {
@@ -2851,6 +2852,7 @@ declare global {
              * 手机号
              */
             mobile: string;
+            tenantCode: string;
           };
         }
       >(
@@ -7595,6 +7597,7 @@ export interface loginModel {
   grant_type?: string;
   mobile?: string;
   password?: string;
+  tenantCode?: string;
   [property: string]: any;
 }
 

+ 4 - 4
src/config/index.ts

@@ -8,10 +8,10 @@ const mapEnvVersion = {
   // develop: 'http://192.168.1.253:8080',
   // develop: 'http://192.168.0.19:8080', // 邓
   // develop: 'http://192.168.1.20:8080', // 黄
-  // develop: 'http://192.168.0.11:8080', // 王
+  develop: 'http://192.168.0.11:8081', // 王
   // develop: 'http://192.168.1.21:8080', // 田
   // develop: 'http://74949mkfh190.vicp.fun', // 付
-  develop: 'http://47.109.84.152:8081', // 测试代理
+  // develop: 'http://47.109.84.152:8081', // 测试代理
   // develop: 'https://5ed0f7cc.r9.vip.cpolar.cn',
   // develop: 'https://25740642.r3.cpolar.top',
   // develop: 'https://smqjh.api.zswlgz.com',
@@ -45,9 +45,9 @@ function handleEnvVersion() {
   // #ifdef H5
   const mode = import.meta.env.MODE
   const h5Server = {
-    development: 'http://47.109.84.152:8081',
+    // development: 'http://47.109.84.152:8081',
     // development: 'http://192.168.0.157:8080',
-    // development: 'http://192.168.0.11:8080',
+    development: 'http://192.168.0.11:8081',
     // development: 'http://192.168.1.21:8080',
     // development: 'https://smqjh.api.zswlgz.com',
     production: 'https://smqjh.api.zswlgz.com',

+ 6 - 1
src/pages/index/index.vue

@@ -18,7 +18,7 @@ definePage({
 const { show } = useGlobalToast()
 
 const addressStore = useAddressStore()
-const { statusBarHeight, MenuButtonHeight, opcity, isOnlineAudit } = storeToRefs(useSysStore())
+const { statusBarHeight, MenuButtonHeight, opcity, isOnlineAudit, thirdPartyLogo } = storeToRefs(useSysStore())
 const { name } = storeToRefs(addressStore)
 const { userInfo, userMemberInfo } = storeToRefs(useUserStore())
 const xsbStore = ref<typeof import('@/subPack-xsb/store-xsb/sys')>()
@@ -159,7 +159,12 @@ function handleJyBanner() {
     >
       <template #left>
         <view class="relative z-10 h-48rpx w-202rpx w-full opacity-100">
+          <!-- #ifdef MP-WEIXIN -->
           <image class="absolute left-0 top-0 h-48rpx w-202rpx" :src="`${StaticUrl}/logo.png`" />
+          <!-- #endif -->
+          <!-- #ifdef H5 -->
+          <image class="absolute left-0 top-0 h-48rpx w-202rpx" :src="thirdPartyLogo" />
+          <!-- #endif -->
         </view>
       </template>
     </wd-navbar>

+ 4 - 3
src/pages/login/index.vue

@@ -12,11 +12,12 @@ definePage({
   },
 })
 const { token, redirectName } = storeToRefs(useUserStore())
-const { thirdPartyName, thirdPartyLogo } = storeToRefs(useSysStore())
+const { thirdPartyName, thirdPartyLogo, tenantCode } = storeToRefs(useSysStore())
 const { data, send } = useRequest((code, phoneCode) => Apis.sys.auth({ params: {
   grant_type: 'wechat',
   code,
   phoneCode,
+  tenantCode: 'zswl',
 } }), { middleware: createGlobalLoadingMiddleware({ loadingText: '手机号授权登录中' }), immediate: false })
 const tabList = ['/pages/my/index', '/pages/index/index', '/pages/cart/index', '/pages/classfiy/index']
 // 表单数据
@@ -54,7 +55,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: tenantCode.value } })
   useGlobalToast().show('验证码已发送')
 }
 
@@ -70,7 +71,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: tenantCode.value } })
     token.value = `Bearer ${res.data.access_token}`
     useUserStore().getUserInfo()
     uni.hideLoading()

+ 24 - 4
src/store/sys.ts

@@ -45,6 +45,10 @@ interface SysState {
    */
   thirdPartyLogo: string
 
+  /**
+   * 租户代码
+   */
+  tenantCode: string
 }
 export const useSysStore = defineStore('system', {
   state: (): SysState => ({
@@ -58,6 +62,7 @@ export const useSysStore = defineStore('system', {
     refreshOrderList: false,
     thirdPartyName: '',
     thirdPartyLogo: '',
+    tenantCode: '',
   }),
   actions: {
     getSystemData() {
@@ -112,10 +117,25 @@ export const useSysStore = defineStore('system', {
      * 获取第三方主题色
      */
     async getThirdPartyThemeColor() {
-      const res = await Apis.sys.appAccess({ pathParams: { accessId: 'ch_001' } })
-      this.thirdPartyName = res.data.accessName
-      this.thirdPartyLogo = res.data.logoUrl
-      useManualThemeStore().setCurrentThemeColor({ name: '三方主题色', value: 'blue', primary: res.data.themeMainColor })
+      const accessId = this.getAccessIdFromHash() || 'ch_002'
+      try {
+        const res = await Apis.sys.appAccess({ pathParams: { accessId } })
+        this.thirdPartyName = res.data.accessName
+        this.thirdPartyLogo = res.data.logoUrl
+        this.tenantCode = res.data.tenantCode
+        useManualThemeStore().setCurrentThemeColor({ name: '三方主题色', value: 'blue', primary: res.data.themeMainColor })
+      }
+      catch {
+        useGlobalToast().show('渠道有问题!,请联系管理员')
+      }
+    },
+
+    getAccessIdFromHash() {
+      // 仅在 H5 下从地址栏 hash 路由中提取第一个路径段作为 accessId
+      const hash = window.location.hash || ''
+      const path = hash.replace(/^#\/?/, '').split('?')[0]
+      const [accessId] = path.split('/').filter(Boolean)
+      return accessId
     },
 
   },

+ 3 - 1
src/subPack-attractions/attractionsReservation/attractionsReservation.vue

@@ -333,9 +333,11 @@ async function handleSubmit() {
             {{ formattedDate }}
           </view>
         </view>
+        <view class="h120rpx" />
       </view>
     </Zpopup>
   </view>
 </template>
 
-<style lang="scss" scoped></style>
+<style lang="scss" scoped>
+</style>