Explorar el Código

feat(api): 添加用户信息接口类型定义和API配置

- 新增userInfo接口类型定义,包含头像、余额、ID、手机号、昵称等字段
- 添加sys.userInfo API定义,对应GET /smqjh-system/app-api/v1/members/me接口
- 在全局API定义中注册用户信息接口

fix(auth): 修复登录过期跳转逻辑

- 将登录过期提示时长从50ms调整为2000ms
- 修改路由跳转路径从'login'改为'smqjh-login'
- 确保401/403错误处理的一致性

refactor(loading): 替换全局loading实现方式

- 移除原有的globalLoading方案
- 改用uni.showLoading和uni.hideLoading进行loading控制
- 保持loading的mask和title配置

chore(config): 更新开发环境配置

- 切换开发环境地址从192.168.1.166:8080到192.168.1.101:8080
- 更新体验版环境地址为192.168.1.242:8080

feat(user): 实现用户信息获取功能

- 在用户登录成功后调用getUserInfo获取用户信息
- 在我的页面onMounted时获取用户信息
- 添加getUserInfo方法到用户store中

refactor(tab): 修复tab组件滚动状态初始化

- 在onMounted钩子中初始化ScrollDown状态为false
zhangtao hace 5 días
padre
commit
56a7d001d9

+ 23 - 0
src/api/api.type.d.ts

@@ -1,4 +1,27 @@
 namespace Api {
+  interface userInfo {
+    /**
+     * 会员头像地址
+     */
+    avatarUrl?: string
+    /**
+     * 会员余额(单位:分)
+     */
+    balance?: number
+    /**
+     * 会员ID
+     */
+    id?: number
+    /**
+     * 会员手机号
+     */
+    mobile?: string
+    /**
+     * 会员昵称
+     */
+    nickName?: string
+    [property: string]: any
+  }
 
   interface xsbCategoriesChildren {
     id: number

+ 1 - 0
src/api/apiDefinitions.ts

@@ -25,6 +25,7 @@ Some useful links:
  */
 export default {
   'sys.auth': ['POST', '/smqjh-auth/oauth2/token'],
+  'sys.userInfo': ['GET', '/smqjh-system/app-api/v1/members/me'],
   'xsb.categories':['GET', '/smqjh-pms/app-api/v1/categories'],
   'xsb.getCategoryProductList':['GET', '/smqjh-pms/app-api/v1/spu/getCategoryProductList'],
   'xsb.getProductDetail':['GET', '/smqjh-pms/app-api/v1/spu/getProductDetails'],

+ 6 - 6
src/api/core/handlers.ts

@@ -35,11 +35,11 @@ export async function handleAlovaResponse(
   // 处理401/403错误(如果不是在handleAlovaResponse中处理的)
   if ((statusCode === 401 || statusCode === 403)) {
     // 如果是未授权错误,清除用户信息并跳转到登录页
-    globalToast.error({ msg: '登录已过期,请重新登录!', duration: 500 })
+    globalToast.error({ msg: '登录已过期,请重新登录!', duration: 2000 })
     const timer = setTimeout(() => {
       clearTimeout(timer)
-      router.replaceAll({ name: 'login' })
-    }, 500)
+      router.replaceAll({ name: 'smqjh-login' })
+    }, 2000)
 
     throw new ApiError('登录已过期,请重新登录!', statusCode, data)
   }
@@ -72,11 +72,11 @@ export function handleAlovaError(error: any, method: Method) {
   // 处理401/403错误(如果不是在handleAlovaResponse中处理的)
   if (error instanceof ApiError && (error.code === 401 || error.code === 403)) {
     // 如果是未授权错误,清除用户信息并跳转到登录页
-    globalToast.error({ msg: '登录已过期,请重新登录!', duration: 500 })
+    globalToast.error({ msg: '登录已过期,请重新登录!', duration: 2000 })
     const timer = setTimeout(() => {
       clearTimeout(timer)
-      router.replaceAll({ name: 'login' })
-    }, 500)
+      router.replaceAll({ name: 'smqjh-login' })
+    }, 2000)
     throw new ApiError('登录已过期,请重新登录!', error.code, error.data)
   }
 

+ 13 - 4
src/api/core/middleware.ts

@@ -59,17 +59,25 @@ export function createGlobalLoadingMiddleware(options: {
     // 自行控制loading
     ctx.controlLoading()
 
-    const globalLoading = useGlobalLoading()
+    // const globalLoading = useGlobalLoading()
     let timer: ReturnType<typeof setTimeout> | null = null
 
     // 如果delay为0或未设置,直接显示loading
     if (delay <= 0) {
-      globalLoading.loading(loadingText)
+      // globalLoading.loading(loadingText)
+      uni.showLoading({
+        mask: true,
+        title: loadingText,
+      })
     }
     else {
       // 延迟特定时间显示全局loading
       timer = setTimeout(() => {
-        globalLoading.loading(loadingText)
+        // globalLoading.loading(loadingText)
+        uni.showLoading({
+          mask: true,
+          title: loadingText,
+        })
       }, delay)
     }
 
@@ -81,7 +89,8 @@ export function createGlobalLoadingMiddleware(options: {
       if (timer) {
         clearTimeout(timer)
       }
-      globalLoading.close()
+      // globalLoading.close()
+      uni.hideLoading()
     }
   }
 }

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

@@ -115,6 +115,11 @@ declare global {
       >(
         config: Config
       ): Alova2Method<logoinToken, 'sys.auth', Config>;
+      userInfo<
+        Config extends Alova2MethodConfig<userInfo>
+      >(
+        config: Config
+      ): Alova2Method<userInfo, 'sys.userInfo', Config>;
     }
     xsb: {
       categories<

+ 3 - 3
src/config/index.ts

@@ -11,15 +11,15 @@ const mapEnvVersion = {
   /**
    * 开发版
    */
-  develop: 'http://192.168.1.166:8080', // 张
-  // develop: 'http://192.168.1.101:8080',
+  // develop: 'http://192.168.1.166:8080', // 张
+  develop: 'http://192.168.1.101:8080',
   // develop: 'http://192.168.0.157:8080',
   /**
    * 体验版
    */
   // trial: "http://192.168.1.166:8080/jeecg-boot",
   // trial: "http://192.168.0.11:8080/jeecg-boot",
-  trial: 'http://192.168.1.101:8080',
+  trial: 'http://192.168.1.242:8080',
   /**
    * 正式版
    */

+ 1 - 0
src/pages/login/index.vue

@@ -27,6 +27,7 @@ async function handleGetPhone(e: UniHelper.ButtonOnGetphonenumberDetail) {
       useGlobalToast().show({ msg: '登录成功' })
       setTimeout(() => {
         router.replace({ name: redirectName.value })
+        useUserStore().getUserInfo()
       }, 2000)
     },
   })

+ 3 - 0
src/pages/my/index.vue

@@ -18,6 +18,9 @@ const tabList = ref([
   { title: '已完成', icon: `${StaticUrl}/6.png`, name: 'smqjh-order' },
   { title: '退款售后', icon: `${StaticUrl}/3.png`, name: 'common-afterSalesList' },
 ])
+onMounted(() => {
+  useUserStore().getUserInfo()
+})
 </script>
 
 <template>

+ 5 - 1
src/store/user.ts

@@ -6,6 +6,7 @@ interface userStroe {
    * 重定向路由名称
    */
   redirectName: string
+
 }
 export const useUserStore = defineStore('user', {
   state: (): userStroe => ({
@@ -13,6 +14,9 @@ export const useUserStore = defineStore('user', {
     redirectName: '',
   }),
   actions: {
-
+    async getUserInfo() {
+      const res = await api.sys.userInfo({})
+      console.log(res, '用户信息')
+    },
   },
 })

+ 3 - 0
src/subPack-xsb/commonTab/components/index.vue

@@ -40,6 +40,9 @@ function handleScroll(e: UniHelper.ScrollViewOnScrollEvent) {
     ScrollDown.value = false
   }
 }
+onMounted(() => {
+  ScrollDown.value = false
+})
 function handleCommonName(name: string) {
   router.push({ name })
 }