소스 검색

fix(api): 修复登录流程及请求头设置相关问题

- 在请求头中新增 'X-Tenant-Domain' 字段以支持多租户请求
- 修改开发环境服务器地址配置
- 优化登录成功后的用户信息获取顺序,确保 token 设置后再请求用户信息
- 修正跳转逻辑,优先跳转到重定向路径或默认首页
- 登录失败时清空 token 并展示失败提示
- 优化手机号登录流程,确保登录成功后获取用户信息
- my 页面路由跳转前展示加载动画,提升用户体验
- 调整 my 组件样式,统一 channelName 显示宽度为自适应
- 清理代码中未使用的变量,保持代码简洁
zhangtao 2 일 전
부모
커밋
4f43417b32
5개의 변경된 파일20개의 추가작업 그리고 15개의 파일을 삭제
  1. 1 1
      src/api/core/instance.ts
  2. 2 1
      src/config/index.ts
  3. 10 10
      src/pages/login/index.vue
  4. 6 2
      src/pages/my/index.vue
  5. 1 1
      src/subPack-xsb/commonTab/components/my.vue

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

@@ -15,7 +15,7 @@ export const alovaInstance = createAlova({
     }
     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
     if (method.type === 'GET' && CommonUtil.isObj(method.config.params)) {
       method.config.params._t = Date.now()

+ 2 - 1
src/config/index.ts

@@ -46,7 +46,8 @@ function handleEnvVersion() {
   const h5Server = {
     // development: 'http://47.109.84.152:8081',
     // development: 'http://192.168.0.157:8080',
-    development: 'http://192.168.1.21:8080',
+    development: 'http://192.168.0.11:8080',
+    // development: 'http://192.168.1.21:8080',
     production: 'https://smqjh.api.zswlgz.com',
   }
   return h5Server[mode as 'development' | 'production']

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

@@ -11,7 +11,7 @@ definePage({
     navigationStyle: 'custom',
   },
 })
-const { token, redirectName, userInfo } = storeToRefs(useUserStore())
+const { token, redirectName } = storeToRefs(useUserStore())
 const { thirdPartyName, thirdPartyLogo } = storeToRefs(useSysStore())
 const { data, send } = useRequest((code, phoneCode) => Apis.sys.auth({ params: {
   grant_type: 'wechat',
@@ -71,24 +71,24 @@ 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 } })
-    uni.hideLoading()
     token.value = `Bearer ${res.data.access_token}`
+    useUserStore().getUserInfo()
+    uni.hideLoading()
     useGlobalToast().show('登录成功')
-    const user = await Apis.general.get_smqjh_system_app_api_v1_members_me()
-    userInfo.value = user.data as Api.userInfo
-    console.log(redirectName.value, '==========redirectName.value')
-
     setTimeout(() => {
-      if (tabList.includes(redirectName.value)) {
-        router.pushTab({ path: redirectName.value })
+      const path = redirectName.value || '/pages/index/index'
+      if (tabList.includes(path)) {
+        router.pushTab({ path })
       }
       else {
-        router.replace({ path: redirectName.value })
+        router.replace({ path })
       }
     }, 1000)
   }
   catch {
+    token.value = ''
     uni.hideLoading()
+    useGlobalToast().show('登录失败')
   }
 }
 async function handleGetPhone(e: UniHelper.ButtonOnGetphonenumberDetail) {
@@ -100,8 +100,8 @@ async function handleGetPhone(e: UniHelper.ButtonOnGetphonenumberDetail) {
       uni.hideLoading()
       await send(res.code, e.code)
       token.value = `Bearer ${data.value.data.access_token}`
-      useGlobalToast().show({ msg: '登录成功' })
       useUserStore().getUserInfo()
+      useGlobalToast().show({ msg: '登录成功' })
 
       setTimeout(() => {
         if (tabList.includes(redirectName.value)) {

+ 6 - 2
src/pages/my/index.vue

@@ -31,7 +31,11 @@ function handleLoginOut() {
       useSmqjhCartStore().$reset()
       useAddressStore().$reset()
       useTabbar().setTabbarItem('smqjh-cart', 0)
-      router.replace({ name: 'smqjh-login' })
+      uni.showLoading({ mask: true })
+      setTimeout(() => {
+        uni.hideLoading()
+        router.replace({ name: 'smqjh-login' })
+      }, 1000)
     },
   })
 }
@@ -65,7 +69,7 @@ function handleGo(item: { name: string, status: string }) {
               <view class="text-32rpx font-semibold">
                 {{ userInfo.nickName }}
               </view>
-              <view class="mt-12rpx rounded-8rpx bg-white px-12rpx py-4rpx text-24rpx text-[var(--them-color)] opacity-70">
+              <view class="mt-12rpx w-fit rounded-8rpx bg-white px-12rpx py-4rpx text-24rpx text-[var(--them-color)] opacity-70">
                 {{ userInfo.channelName }}
               </view>
             </view>

+ 1 - 1
src/subPack-xsb/commonTab/components/my.vue

@@ -45,7 +45,7 @@ function handleGo(item: { name: string, status: string }) {
               <view class="text-32rpx font-semibold">
                 {{ userInfo.nickName }}
               </view>
-              <view class="mt12rpx rounded-8rpx bg-white px12rpx py4rpx text-24rpx text-[var(--them-color)] opacity-70">
+              <view class="mt12rpx w-fit rounded-8rpx bg-white px12rpx py4rpx text-24rpx text-[var(--them-color)] opacity-70">
                 {{ userInfo.channelName }}
               </view>
             </view>