浏览代码

修改 打包时 utils下文件的问题 类型及ts的区别

plg 6 月之前
父节点
当前提交
9cd2e670cb
共有 5 个文件被更改,包括 53 次插入49 次删除
  1. 13 1
      package-lock.json
  2. 3 1
      package.json
  3. 27 45
      src/utils/utils.ts
  4. 2 2
      src/views/shapeIntuition_random.vue
  5. 8 0
      vite.config.ts

+ 13 - 1
package-lock.json

@@ -8,7 +8,9 @@
       "name": "cpdm_pc",
       "version": "0.0.0",
       "dependencies": {
+        "@types/crypto-js": "^4.2.2",
         "axios": "^1.7.2",
+        "crypto-js": "^4.2.0",
         "date-fns": "^3.6.0",
         "echarts": "^5.5.1",
         "element-plus": "^2.7.7",
@@ -22,7 +24,7 @@
       "devDependencies": {
         "@rushstack/eslint-patch": "^1.8.0",
         "@tsconfig/node20": "^20.1.4",
-        "@types/node": "^20.14.12",
+        "@types/node": "^20.16.10",
         "@vitejs/plugin-vue": "^5.0.5",
         "@vitejs/plugin-vue-jsx": "^4.0.0",
         "@vue/eslint-config-prettier": "^9.0.0",
@@ -1312,6 +1314,11 @@
       "integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==",
       "dev": true
     },
+    "node_modules/@types/crypto-js": {
+      "version": "4.2.2",
+      "resolved": "https://registry.npmmirror.com/@types/crypto-js/-/crypto-js-4.2.2.tgz",
+      "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ=="
+    },
     "node_modules/@types/estree": {
       "version": "1.0.6",
       "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.6.tgz",
@@ -2184,6 +2191,11 @@
         "node": ">= 8"
       }
     },
+    "node_modules/crypto-js": {
+      "version": "4.2.0",
+      "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz",
+      "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
+    },
     "node_modules/cssesc": {
       "version": "3.0.0",
       "resolved": "https://registry.npmmirror.com/cssesc/-/cssesc-3.0.0.tgz",

+ 3 - 1
package.json

@@ -13,7 +13,9 @@
     "format": "prettier --write src/"
   },
   "dependencies": {
+    "@types/crypto-js": "^4.2.2",
     "axios": "^1.7.2",
+    "crypto-js": "^4.2.0",
     "date-fns": "^3.6.0",
     "echarts": "^5.5.1",
     "element-plus": "^2.7.7",
@@ -27,7 +29,7 @@
   "devDependencies": {
     "@rushstack/eslint-patch": "^1.8.0",
     "@tsconfig/node20": "^20.1.4",
-    "@types/node": "^20.14.12",
+    "@types/node": "^20.16.10",
     "@vitejs/plugin-vue": "^5.0.5",
     "@vitejs/plugin-vue-jsx": "^4.0.0",
     "@vue/eslint-config-prettier": "^9.0.0",

+ 27 - 45
src/utils/utils.ts

@@ -1,53 +1,35 @@
 import { ElLoading } from 'element-plus'
-import { de } from 'element-plus/es/locales.mjs'
 
-// const CryptoJS = require('crypto-js');  //引用AES源码js
-// const key = CryptoJS.enc.Utf8.parse("Sp5biS+gX+#CqAFF");  //十六位十六进制数作为密钥
-// const iv = CryptoJS.enc.Utf8.parse('ud2E8l6wchltwIDA');   //十六位十六进制数作为密钥偏移量
+
+import CryptoJS from 'crypto-js'
+// import CryptoJS from 'crypto-js';  //引用AES源码js
+const key = CryptoJS.enc.Utf8.parse("Sp5biS+gX+#CqAFF");  //十六位十六进制数作为密钥
+const iv = CryptoJS.enc.Utf8.parse('ud2E8l6wchltwIDA');   //十六位十六进制数作为密钥偏移量
 
 //解密方法
-// const Decrypt = function (word) {
-//     let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
-//     let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
-//     let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
-//     let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
-//     return decryptedStr.toString();
-// }
+const Decrypt = function (word: any) {
+  let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
+  let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
+  let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
+  let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
+  return decryptedStr.toString();
+}
 
 // //加密方法
-// const Encrypt = function (word) {
-//     let srcs = CryptoJS.enc.Utf8.parse(word);
-//     let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
-//     return encrypted.ciphertext.toString().toUpperCase();
-// }
+const Encrypt = function (word: any) {
+  let srcs = CryptoJS.enc.Utf8.parse(word);
+  let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
+  return encrypted.ciphertext.toString().toUpperCase();
+}
 
-const splitCheckItems = function (str) {
+const splitCheckItems = function (str: any) {
   return str.split(';')
 }
 
-// 日期格式化
-const dateFormat = function (fmt, date) {
-  let ret
-  const opt = {
-    'Y+': date.getFullYear().toString(), // 年
-    'm+': (date.getMonth() + 1).toString(), // 月
-    'd+': date.getDate().toString(), // 日
-    'H+': date.getHours().toString(), // 时
-    'M+': date.getMinutes().toString(), // 分
-    'S+': date.getSeconds().toString() // 秒
-    // 有其他格式化字符需求可以继续添加,必须转化成字符串
-  }
-  for (let k in opt) {
-    ret = new RegExp('(' + k + ')').exec(fmt)
-    if (ret) {
-      fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'))
-    }
-  }
-  return fmt
-}
+
 
 // 图片预加载
-const preloader = function (imgList, next) {
+const preloader = function (imgList: any, next: any) {
   let count = 0
   let loadingInstance1 = ElLoading.service({ fullscreen: true, text: '0%' })
   for (let img of imgList) {
@@ -55,7 +37,8 @@ const preloader = function (imgList, next) {
     image.src = img.imgUrl
     image.onload = () => {
       count++
-      let point = (count / imgList.length).toFixed(2) * 100
+      // let point = (count / imgList.length).toFixed(2) * 100
+      let point = parseFloat((count / imgList.length).toFixed(2)) * 100
       loadingInstance1.setText(Math.floor(point) + '%')
       if (count == imgList.length) {
         loadingInstance1.setText('100%')
@@ -66,7 +49,7 @@ const preloader = function (imgList, next) {
   }
 }
 
-const preloader2 = function (imgList, next) {
+const preloader2 = function (imgList: any, next: any) {
   let count = 0
   for (let img of imgList) {
     let image = new Image()
@@ -82,23 +65,23 @@ const preloader2 = function (imgList, next) {
 
 // sessionStorage 加解密处理
 let oSessionStorage = {
-  setItem(key, value) {
+  setItem(key: any, value: any) {
     sessionStorage.setItem(Encrypt(key), Encrypt(value))
   },
-  getItem(key) {
+  getItem(key: any) {
     if (sessionStorage.getItem(Encrypt(key))) {
       return Decrypt(sessionStorage.getItem(Encrypt(key)))
     } else {
       return null
     }
   },
-  removeItem(key) {
+  removeItem(key: any) {
     sessionStorage.removeItem(Encrypt(key))
   }
 }
 
 // 从测试记录附件名中截取用户昵称
-let getPetName = function (str) {
+let getPetName = function (str: any) {
   let sd = str.split('/')
   let sp = sd[sd.length - 1]
 
@@ -114,7 +97,6 @@ const requireImg = (imgUrl: string) => {
 
 export {
   splitCheckItems,
-  dateFormat,
   preloader,
   preloader2,
   oSessionStorage,

+ 2 - 2
src/views/shapeIntuition_random.vue

@@ -8,9 +8,9 @@
     <div v-if="testFlag" :class="{ testMainDiv: !testState, activeTask: testState }" @contextmenu.prevent=""
       @click.left="userClick('L')" @click.right="userClick('R')">
       <div class="taskHead">
-        <div class="scale" @click.stop="screen">
+        <!-- <div class="scale" @click.stop="screen">
           <img src="../../assets/small-big.png" alt="" />
-        </div>
+        </div> -->
         <el-progress class="main_progress" color="linear-gradient(to right, #ffd650, #ff8431)" :stroke-width="48"
           :text-inside="true" :format="format" :percentage="(imgIndex * 100) / 120" v-if="testTypeCode == 1"
           style="width:50%"></el-progress>

+ 8 - 0
vite.config.ts

@@ -6,6 +6,14 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
 
 // https://vitejs.dev/config/
 export default defineConfig({
+  css: {
+    preprocessorOptions: {
+      scss: {
+        api: "modern-compiler" // or 'modern'
+      }
+    }
+  },
+
   plugins: [
     vue(),
     vueJsx(),