Selaa lähdekoodia

fix: 修改忘记密码部分逻辑bug

zhouyuhao 1 vuosi sitten
vanhempi
commit
9b2059f9ff

+ 2 - 2
src/router/index.ts

@@ -97,14 +97,14 @@ router.beforeEach(async (to, from, next) => {
   // 如果手动跳转登录页,清除登录信息
   if (to.path === '/login') {
     const userStore = useUserStore()
-    userStore.clearUsername()
+    userStore.logout()
   }
   // 未登录白名单
   const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
   // 判断是否登录
   if (!whiteList.includes(to.path) && !localStorage.getItem('username')) {
     const userStore = useUserStore()
-    userStore.clearUsername()
+    userStore.logout()
     if (whiteList.includes(from.path)) {
       ElMessage.warning({
         message: 'Please log in to use this feature.',

+ 1 - 8
src/stores/modules/user.ts

@@ -14,14 +14,7 @@ export const useUserStore = defineStore('user', {
       this.username = username
     },
     logout() {
-      $api.logout().then((res: any) => {
-        if (res.code === 200) {
-          localStorage.removeItem('username')
-          this.username = ''
-        }
-      })
-    },
-    clearUsername() {
+      $api.logout().then(() => {})
       localStorage.removeItem('username')
       this.username = ''
     }

+ 1 - 1
src/utils/axios.ts

@@ -58,7 +58,7 @@ class HttpAxios {
     if (response.status === 200) {
       if (response.data.code === 401 || response.data.code === 403) {
         const userStore = useUserStore()
-        userStore.clearUsername()
+        userStore.logout()
         router.push('/login')
         ElMessage.warning({
           message: 'Please log in to use this feature.',

+ 1 - 0
src/views/Booking/src/components/BookingDetail/src/components/EmailView.vue

@@ -181,6 +181,7 @@ const sendEmail = () => {
               effect="dark"
               content="Separated by;"
               placement="top-start"
+              :offset="-8"
             >
               <span class="font_family icon-icon_tipsfilled_b" style="font-size: 19px"></span>
             </el-tooltip>

+ 3 - 1
src/views/Booking/src/components/BookingTable/src/components/DownloadDialog.vue

@@ -37,7 +37,9 @@ defineExpose({
       <div class="download-dialog">
         <div class="select-data">
           <div style="display: inline-block">
-            Select data on your shipment list:<span style="color: var(--color-theme)">1330</span>
+            Select data on your booking list:<span style="color: var(--color-theme)">{{
+              listData.length || 0
+            }}</span>
           </div>
         </div>
         <div class="data-filter">

+ 39 - 22
src/views/Login/src/loginView.vue

@@ -36,6 +36,26 @@ const saveCredentials = () => {
   localStorage.setItem('password', encryptedPassword)
 }
 
+// 验证当前用户是否存在
+const handleCheckUser = () => {
+  if (!loginForm.value.username) {
+    return
+  }
+  // 这里是验证用户是否存在的逻辑
+  $api.isUserNameExit({ uname: loginForm.value.username }).then((res: any) => {
+    if (res.code === 200) {
+      if (res.data.msg !== 'no_exist') {
+        isUserNameExit.value = true
+      } else {
+        loginError.value.username = true
+        isUserNameExit.value = false
+      }
+    } else {
+      isUserNameExit.value = false
+    }
+  })
+}
+
 // 读取存储的账号和解密后的密码
 const getCredentials = () => {
   const username = localStorage.getItem('account')
@@ -45,6 +65,8 @@ const getCredentials = () => {
     loginForm.value.username = username
     loginForm.value.password = password
     isRememerPwd.value = true
+    // 验证用户名是否存在
+    handleCheckUser()
   }
 }
 
@@ -69,6 +91,7 @@ watch(status, () => {
     code: false
   }
   isRememerPwd.value = false
+  isUserNameExit.value = false
   verificationCode.value = ''
   getCode()
 })
@@ -100,30 +123,13 @@ const getCode = () => {
 }
 getCode()
 
-// 验证当前用户是否存在
-const handleCheckUser = () => {
-  if (!loginForm.value.username) {
-    return
-  }
-  // 这里是验证用户是否存在的逻辑
-  $api.isUserNameExit({ uname: loginForm.value.username }).then((res: any) => {
-    if (res.code === 200) {
-      if (res.data.msg !== 'no_exist') {
-        isUserNameExit.value = true
-      } else {
-        loginError.value.username = true
-        isUserNameExit.value = false
-      }
-    } else {
-      isUserNameExit.value = false
-    }
-  })
-}
-
 const userStore = useUserStore()
 
 // 点击登录按钮
 const handleLogin = () => {
+  if (!isUserNameExit.value || !loginForm.value.username) {
+    return
+  }
   // 这里是登录逻辑
   $api
     .login({
@@ -189,6 +195,7 @@ const handleLogin = () => {
 const backLogin = (emailTips: boolean) => {
   status.value = 'login'
   isEmailTips.value = emailTips
+  emailTipsContent.value = emailTips ? 'Your password sent to registered email.' : ''
   // 如果是成功忘记密码,清空保存的账号密码
   // 如果是直接返回登录,获取保存的账号密码
   setTimeout(() => {
@@ -204,10 +211,12 @@ const isUserNameExit = ref(false)
 
 const handleForgot = () => {
   status.value = 'reset'
-  isUserNameExit.value = false
   handleDeleteEmailTips()
 }
 const handleSendPassword = () => {
+  if (!isUserNameExit.value || !loginForm.value.username) {
+    return
+  }
   // 这里是发送密码逻辑
   $api
     .forgotPassword({
@@ -218,8 +227,16 @@ const handleSendPassword = () => {
     .then((res: any) => {
       if (res.code === 200) {
         backLogin(true)
+      } else if (res.code === 400) {
+        const { data } = res
+        if (data.msg === 'verifcation_error') {
+          loginError.value.code = true
+        }
       }
     })
+    .finally(() => {
+      getCode()
+    })
 }
 
 const isEmailTips = ref(false)
@@ -231,7 +248,7 @@ const initEmailTips = () => {
     emailTipsContent.value = 'Changed successfully. Please log in.'
   } else {
     isEmailTips.value = false
-    emailTipsContent.value = 'New Password sent to registered email.'
+    emailTipsContent.value = 'Your password sent to registered email.'
   }
 }
 initEmailTips()

+ 22 - 2
src/views/Tracking/src/components/PublicTracking/src/PublicTrackingSearch.vue

@@ -2,6 +2,7 @@
 import { useRouter } from 'vue-router'
 import { useHeaderSearch } from '@/stores/modules/headerSearch'
 import SlideVerify from './components/SlideVerify.vue'
+import CryptoJS from 'crypto-js'
 
 const router = useRouter()
 
@@ -29,16 +30,23 @@ watch(
 )
 
 const loading = ref(false)
+const confirmVerifyStatus = ref('')
 const handleSearchNo = () => {
   if (!inputVModel.value) {
     return
   }
   loading.value = true
   $api
-    .getPublicTrackingDetail({ reference_number: inputVModel.value })
+    .getPublicTrackingDetail({
+      reference_number: inputVModel.value,
+      verifcation_code: confirmVerifyStatus.value
+    })
     .then((res) => {
       if (res.code === 200) {
         const { data } = res
+        if (data.msg === 'visit limit') {
+          slideVerifyRef.value?.openDialog()
+        }
         if (data.msg === 'No matches') {
           searchResult.value = 'error'
         } else if (data.msg === 'Multiple results') {
@@ -51,8 +59,20 @@ const handleSearchNo = () => {
     })
     .finally(() => {
       loading.value = false
+      confirmVerifyStatus.value = ''
     })
 }
+
+const slideVerifyRef = ref<InstanceType<typeof SlideVerify> | null>(null)
+const secretKey = 'fT5!R1k$7Mv@4Q9X'
+// AES 加密函数
+const encryptPassword = (password) => {
+  return CryptoJS.AES.encrypt(password, secretKey).toString()
+}
+// 验证滑块成功
+const confirmVerify = () => {
+  confirmVerifyStatus.value = encryptPassword('completed')
+}
 </script>
 
 <template>
@@ -94,7 +114,7 @@ const handleSearchNo = () => {
         </VEmpty>
       </div>
     </div>
-    <SlideVerify></SlideVerify>
+    <SlideVerify ref="slideVerifyRef" @verify-success="confirmVerify"></SlideVerify>
   </div>
 </template>
 

+ 11 - 0
src/views/Tracking/src/components/PublicTracking/src/components/SlideVerify.vue

@@ -1,6 +1,10 @@
 <script lang="ts" setup>
 const dialogVisible = ref(false)
 
+const openDialog = () => {
+  dialogVisible.value = true
+}
+
 const position = ref(0)
 const isDragging = ref(false)
 const verifyText = ref('Swipe right to verify')
@@ -64,6 +68,9 @@ const onDrag = (event: MouseEvent) => {
   }
 }
 
+const emit = defineEmits<{
+  verifySuccess: []
+}>()
 const stopDrag = () => {
   isDragging.value = false
   document.removeEventListener('mousemove', onDrag)
@@ -76,6 +83,7 @@ const stopDrag = () => {
       verifyText.value = 'Verification successful'
       setTimeout(() => {
         dialogVisible.value = false
+        emit('verifySuccess')
       }, 500)
     } else {
       sliderState.value = 'error'
@@ -94,6 +102,9 @@ const moveSlider = (event: MouseEvent) => {
     onDrag(event)
   }
 }
+defineExpose({
+  openDialog
+})
 </script>
 
 <template>

+ 1 - 0
src/views/Tracking/src/components/TrackingDetail/src/components/EmailDrawer.vue

@@ -194,6 +194,7 @@ defineExpose({
                 effect="dark"
                 content="Separated by;"
                 placement="top-start"
+                :offset="-8"
               >
                 <span class="font_family icon-icon_tipsfilled_b" style="font-size: 19px"></span>
               </el-tooltip>