浏览代码

feat: 给public-tracking搜索页加上高频请求验证

zhouyuhao 1 年之前
父节点
当前提交
96261abad4

+ 16 - 5
src/views/Tracking/src/components/PublicTracking/src/PublicTrackingSearch.vue

@@ -3,6 +3,7 @@ import { useRouter } from 'vue-router'
 import { useHeaderSearch } from '@/stores/modules/headerSearch'
 import SlideVerify from './components/SlideVerify.vue'
 import CryptoJS from 'crypto-js'
+import dayjs from 'dayjs'
 
 const router = useRouter()
 
@@ -44,9 +45,7 @@ const handleSearchNo = () => {
     .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') {
@@ -55,6 +54,11 @@ const handleSearchNo = () => {
           sessionStorage.setItem('publicTrackingData', JSON.stringify(data.data))
           router.push(`/public-tracking/detail?searchNo=${inputVModel.value}`)
         }
+      } else if (res.code === 400) {
+        const { data } = res
+        if (data.msg === 'visit limit') {
+          slideVerifyRef.value?.openDialog()
+        }
       }
     })
     .finally(() => {
@@ -65,13 +69,20 @@ const handleSearchNo = () => {
 
 const slideVerifyRef = ref<InstanceType<typeof SlideVerify> | null>(null)
 const secretKey = 'fT5!R1k$7Mv@4Q9X'
+const fixedIv = '1234567890123456' // 固定的初始化向量,长度为16字符
+
 // AES 加密函数
 const encryptPassword = (password) => {
-  return CryptoJS.AES.encrypt(password, secretKey).toString()
+  const key = CryptoJS.enc.Utf8.parse(secretKey) // 解析密钥
+  const iv = CryptoJS.enc.Utf8.parse(fixedIv) // 解析IV
+  const encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(password), key, { iv: iv })
+  return encrypted.toString()
 }
+
 // 验证滑块成功
 const confirmVerify = () => {
-  confirmVerifyStatus.value = encryptPassword('completed')
+  const pwd = dayjs().unix()
+  confirmVerifyStatus.value = encryptPassword(pwd)
 }
 </script>
 

+ 16 - 1
src/views/Tracking/src/components/PublicTracking/src/components/SlideVerify.vue

@@ -102,13 +102,28 @@ const moveSlider = (event: MouseEvent) => {
     onDrag(event)
   }
 }
+
+const clearData = () => {
+  sliderState.value = 'start'
+  verifyText.value = 'Swipe right to verify'
+  position.value = 0
+}
 defineExpose({
   openDialog
 })
 </script>
 
 <template>
-  <el-dialog top="30vh" v-model="dialogVisible" width="400" class="slide-verify-dialog">
+  <el-dialog
+    top="30vh"
+    destroy-on-close
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    @closed="clearData"
+    v-model="dialogVisible"
+    width="400"
+    class="slide-verify-dialog"
+  >
     <div class="content">
       <p>Please drag the slider below to complete the</p>
       <p>verification to ensure normal access</p>

+ 0 - 10
vite.config.ts

@@ -60,14 +60,4 @@ export default defineConfig({
       }
     }
   }
-  // build: {
-  //   assetsDir: 'assets',
-  //   rollupOptions: {
-  //     output: {
-  //       entryFileNames: `assets/[name].[hash].js`,
-  //       chunkFileNames: `assets/[name].[hash].js`,
-  //       assetFileNames: `assets/[name].[hash].[ext]`
-  //     }
-  //   }
-  // }
 })