Browse Source

称重请求时,登录优化

GGDemo 3 weeks ago
parent
commit
dff7a71e7b
3 changed files with 18 additions and 5 deletions
  1. 2 0
      src/pages/login/login.vue
  2. 4 4
      src/pages/weigh/weigh.vue
  3. 12 1
      src/utils/http.ts

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

@@ -27,6 +27,8 @@ const loginSuccess = (profile: LoginResult) => {
   memberStore.setProfile(profile)
   // 成功提示
   uni.showToast({ icon: 'success', title: '登录成功' })
+  console.log('登录成功', profile)
+
   setTimeout(() => {
     // 页面跳转
     // uni.switchTab({ url: '/pages/my/my' })

+ 4 - 4
src/pages/weigh/weigh.vue

@@ -390,12 +390,12 @@ const spaceRes = computed(() => {
     return ''
   }
 })
-onShow(() => {
+onShow(async () => {
   focusType.value = true
   loading.value = false
-  _getWarehouseSpace()
-  _getBindParams()
-  _getPrinterList()
+  await _getWarehouseSpace()
+  await _getBindParams()
+  await _getPrinterList()
 })
 onHide(() => {
   focusType.value = false

+ 12 - 1
src/utils/http.ts

@@ -66,10 +66,21 @@ export const http = <T>(options: UniApp.RequestOptions) => {
       ...options,
       // 响应成功
       success(res) {
+        console.log('响应成功', res)
+
         // 状态码 2xx, axios 就是这样设计的
         if (res.statusCode >= 200 && res.statusCode < 300) {
           // 2.1 提取核心数据 res.data
-          resolve(res.data as Data<T>)
+          const data = res.data as Data<T>
+          if (data.code === 302) {
+            // 401错误  -> 清理用户信息,跳转到登录页
+            const memberStore = useMemberStore()
+            memberStore.clearProfile()
+            uni.navigateTo({ url: '/pages/login/login' })
+            reject(res)
+          } else {
+            resolve(res.data as Data<T>)
+          }
         } else if (res.statusCode === 401) {
           // 401错误  -> 清理用户信息,跳转到登录页
           const memberStore = useMemberStore()