Procházet zdrojové kódy

登陆密码加密

coys před 1 rokem
rodič
revize
82454947d3

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 585 - 28
package-lock.json


+ 2 - 0
package.json

@@ -20,8 +20,10 @@
     "core-js": "^3.23.3",
     "dayjs": "^1.11.9",
     "echarts": "^4.9.0",
+    "gm-crypt": "0.0.2",
     "js-image-compressor": "^2.0.0",
     "liquor-tree": "^0.2.70",
+    "node-polyfill-webpack-plugin": "^3.0.0",
     "pdfjs-dist": "2.5.207",
     "regenerator-runtime": "^0.13.5",
     "v-calendar": "^2.4.1",

+ 34 - 0
src/utils/sm4.js

@@ -0,0 +1,34 @@
+const SM4 = require('gm-crypt').sm4;
+const pwdKey = 'rDWBHusbFTlOURS4'; // 密钥 前后端一致即可,后端提供
+let sm4Config = {
+  key: pwdKey, // key值要与后端的一致,后端解密是根据这个key
+  mode: 'ecb', // 加密的方式有两种,ecb和cbc两种,也是看后端如何定义的,cbc的话下面还要加一个iv的参数,ecb不用
+//   iv: pwdKey, // iv是cbc模式的第二个参数,也需要跟后端配置的一致 iv是initialization vector的意思,就是加密的初始化矢量,初始化加密函数的变量,也叫初始向量
+  cipherType: 'base64',
+};
+
+/*
+ * 加密工具函数
+ * @param {String} text 待加密文本
+ * @param key string 加密key(16位)
+ * @param iv string 偏移向量(16位)
+ */
+export function SM4Encrypt(text, key = pwdKey, iv = pwdKey) {
+  sm4Config.key = key;
+//   sm4Config.iv = iv;
+  const sm4Util = new SM4(sm4Config); // new一个sm4函数,将sm4Config作为参数传递进去
+  return sm4Util.encrypt(text, key);
+}
+
+/*
+ * 解密工具函数
+ * @param {String} text 待解密密文
+ * @param key string 加密key(16位)
+ * @param iv string 偏移向量(16位)
+ */
+export function SM4Decrypt(text, key = pwdKey, iv = pwdKey) {
+  sm4Config.key = key;
+//   sm4Config.iv = iv;
+  const sm4Util = new SM4(sm4Config); // new一个sm4函数,将sm4Config作为参数传递进去
+  return sm4Util.decrypt(text, key);
+}

+ 3 - 1
src/views/login.vue

@@ -48,6 +48,7 @@
 // 请求接口
 import { login } from '@/api/public.js'
 import { mapGetters } from 'vuex'
+import { SM4Encrypt, SM4Decrypt } from '@/utils/sm4.js'
 export default {
   data() {
     return {
@@ -70,10 +71,11 @@ export default {
   },
   methods: {
     onSubmit() {
+      this.formData.password = SM4Encrypt(this.formData.password)
       login(this.formData).then(res => {
         if (this.checked) {
           localStorage.setItem('username', this.formData.username)
-          localStorage.setItem('password', this.formData.password)
+          localStorage.setItem('password', SM4Encrypt(this.formData.password))
           localStorage.setItem('checked', this.checked)
         } else {
           localStorage.clear()

+ 2 - 7
src/views/menu/resumptionEvaluate/evaluate.vue

@@ -21,13 +21,8 @@
       </div>
       <van-form @submit="onSubmit" ref="form" v-if="addOrInfo == 'add'">
         <van-cell
-        v-for="item in formData.coreEvaluateContentList"
-          :title="
-            item.code +
-            '.' +
-            item.content
-          "
-          
+          v-for="item in formData.coreEvaluateContentList"
+          :title="item.code + '.' + item.content"
           :key="item.id"
         >
           <!-- 使用 title 插槽来自定义标题 -->

+ 10 - 1
vue.config.js

@@ -1,3 +1,8 @@
+
+const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
+
+
+
 const path = require('path')
 const defaultSettings = require('./src/config/index.js')
 const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
@@ -39,6 +44,7 @@ require('events').EventEmitter.defaultMaxListeners = 0;
 // }
 
 module.exports = defineConfig({
+  
   publicPath: './', // 署应用包时的基本 URL。 vue-router hash 模式使用
   outputDir: 'app', //  生产环境构建文件的目录
   assetsDir: 'static', //  outputDir的静态资源(js、css、img、fonts)目录
@@ -119,6 +125,7 @@ module.exports = defineConfig({
       },
       '/dev': {
         target: "http://47.92.229.224:8080",
+        // target: "http://10.87.23.48:8080",
         // ws:true,
         changOrigin:true,
         pathRewrite:{
@@ -159,9 +166,11 @@ module.exports = defineConfig({
       }
     }
   },
+
+
   configureWebpack: config => {
     config.name = name
-
+    // config.plugins= [new NodePolyfillPlugin()]
     // 为生产环境修改配置...
     // if (IS_PROD) {
     //   // externals

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů