weirenchun 1 year ago
parent
commit
e70d4ea06a

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "js-md5": "^0.7.3",
     "jsonp": "^0.2.1",
     "nprogress": "^0.2.0",
+    "crypto-js": "^4.1.1",
     "path": "^0.12.7",
     "pinia": "^2.0.28",
     "pinia-plugin-persistedstate": "^3.0.2",

+ 80 - 0
src/utils/crypto.js

@@ -0,0 +1,80 @@
+import CryptoJS from 'crypto-js'
+
+export default class crypto {
+  // 使用AesUtil.genAesKey()生成,需和后端配置保持一致
+  static aesKey = "uQFw4pOEtPdzU4LP3ywbaUtoGMHywnUi";
+
+  // 使用DesUtil.genDesKey()生成,需和后端配置保持一致
+  static desKey = "XHHUNdnCka60Y5zJ";
+
+  /**
+   * aes 加密方法
+   * @param data
+   * @returns {*}
+   */
+  static encrypt(data) {
+    return this.encryptAES(data, this.aesKey);
+  }
+
+  /**
+   * aes 解密方法
+   * @param data
+   * @returns {*}
+   */
+  static decrypt(data) {
+    return this.decryptAES(data, this.aesKey);
+  }
+
+  /**
+   * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
+   */
+  static encryptAES(data, key) {
+    const dataBytes = CryptoJS.enc.Utf8.parse(data);
+    const keyBytes = CryptoJS.enc.Utf8.parse(key);
+    const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
+      iv: keyBytes,
+      mode: CryptoJS.mode.CBC,
+      padding: CryptoJS.pad.Pkcs7
+    });
+    return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
+  }
+
+  /**
+   * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
+   */
+  static decryptAES(data, key) {
+    const keyBytes = CryptoJS.enc.Utf8.parse(key);
+    const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
+      iv: keyBytes,
+      mode: CryptoJS.mode.CBC,
+      padding: CryptoJS.pad.Pkcs7
+    });
+    return CryptoJS.enc.Utf8.stringify(decrypted);
+  }
+
+  /**
+   * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
+   */
+  static encryptDES(data, key) {
+    const keyHex = CryptoJS.enc.Utf8.parse(key);
+    const encrypted = CryptoJS.DES.encrypt(data, keyHex, {
+      mode: CryptoJS.mode.ECB,
+      padding: CryptoJS.pad.Pkcs7
+    });
+    return encrypted.toString();
+  }
+
+  /**
+   * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
+   */
+  static decryptDES(data, key) {
+    const keyHex = CryptoJS.enc.Utf8.parse(key);
+    const decrypted = CryptoJS.DES.decrypt({
+      ciphertext: CryptoJS.enc.Base64.parse(data)
+    }, keyHex, {
+      mode: CryptoJS.mode.ECB,
+      padding: CryptoJS.pad.Pkcs7
+    });
+    return decrypted.toString(CryptoJS.enc.Utf8);
+  }
+}

+ 4 - 2
src/views/home/components/chart3.vue

@@ -13,6 +13,7 @@
 <script lang="js">
 import charts from '../../../components/echarts/index.vue'
 import * as echarts from 'echarts'
+import crypto from "@/utils/crypto.js"
 export default {
   components: { charts },
   data() {
@@ -100,8 +101,9 @@ export default {
   methods: {
     getDebtList() {
       this.$api.biz.getDebtList({ current: 1, size: 5}).then(res => {
-        if (res.code === 200) {
-          this.option.series[0].data = res.data.records.map((item) => {
+        let result = JSON.parse(crypto.decryptDES(res, crypto.desKey))
+        if (result.code === 200) {
+          this.option.series[0].data = result.data.records.map((item) => {
             return item.viewNumber
           }).reverse()
         }

+ 5 - 2
src/views/home/components/left1.vue

@@ -115,6 +115,8 @@
 </template>
 
 <script>
+import crypto from '@/utils/crypto.js'
+
 export default {
   data() {
     return {
@@ -131,8 +133,9 @@ export default {
         size: 20
       }
       this.$api.biz.getTagsList(data).then(res => {
-        if (res.code === 200) {
-          this.tagsList = res.data.records
+        let result = JSON.parse(crypto.decryptDES(res, crypto.desKey))
+        if (result.code === 200) {
+          this.tagsList = result.data.records
         }
       })
     }

+ 5 - 2
src/views/home/components/left2.vue

@@ -42,6 +42,8 @@
 </template>
 
 <script>
+import crypto from '@/utils/crypto.js'
+
 export default {
   data() {
     return {
@@ -54,8 +56,9 @@ export default {
   methods: {
     getCount() {
       this.$api.biz.getCount().then(res => {
-        if (res.code === 200) {
-          this.data = res.data
+        let result = JSON.parse(crypto.decryptDES(res, crypto.desKey))
+        if (result.code === 200) {
+          this.data = result.data
         }
       })
     }

+ 5 - 2
src/views/home/components/rotation.vue

@@ -40,6 +40,8 @@
 </template>
 
 <script>
+import crypto from '@/utils/crypto.js'
+
 export default {
   data() {
     return {
@@ -56,8 +58,9 @@ export default {
         current: 1
       }
       this.$api.biz.bigList(data).then(res => {
-        if (res.code === 200) {
-          this.data = res.data.records
+        let result = JSON.parse(crypto.decryptDES(res, crypto.desKey))
+        if (result.code === 200) {
+          this.data = result.data.records
         }
       })
     }

+ 2 - 2
vite.config.js

@@ -36,8 +36,8 @@ export default defineConfig({
     proxy: {
       '/api': {
         // 正式环境地址
-        target: 'https://dev.wutongresearch.club/api',
-        // target: 'https://prod.wutongshucloud.com/api',
+        // target: 'https://dev.wutongresearch.club/api',
+        target: 'https://prod.wutongshucloud.com/api',
         // target: 'http://192.168.31.181:8110',
         changeOrigin: true,
         rewrite: path => path.replace(/^\/api/, '')