Compare commits

..

No commits in common. 'a5961850fd5db2b9b71ee4542e94b308322713e3' and 'd2f010d6f15cc683fe399b7d20416e3b74a42cdb' have entirely different histories.

  1. 1
      package.json
  2. 67
      src/utils/aes.js
  3. 17
      src/utils/request.js
  4. 2
      src/views/login/index.vue
  5. 8
      src/views/qr/qrImage.vue

@ -16,7 +16,6 @@
"dependencies": { "dependencies": {
"axios": "0.18.1", "axios": "0.18.1",
"core-js": "3.6.5", "core-js": "3.6.5",
"crypto-js": "^4.2.0",
"element-ui": "2.15.6", "element-ui": "2.15.6",
"js-cookie": "2.2.0", "js-cookie": "2.2.0",
"normalize.css": "7.0.0", "normalize.css": "7.0.0",

@ -1,67 +0,0 @@
/**
* Aes加解密
* aec1b4218112932c
* b0e8d4dbaff1ed30
* ec241d54487cabf8
* f768a3dc18069961
* 620b8d3c3be1e725
*/
const aesKey = '620b8d3c3be1e725'
const crypto = require('crypto-js')
const key = crypto.enc.Utf8.parse(aesKey)
/**
* 加密解密工具类
*/
function encrypt(word) {
var srcs = crypto.enc.Utf8.parse(word)
var encrypted = crypto.AES.encrypt(srcs, key, {
mode: crypto.mode.ECB,
padding: crypto.pad.Pkcs7
})
return encrypted.toString()
// return strToHex(encrypted.toString());
}
function decrypt(word) {
//word = hexToStr(word);
var decrypt = crypto.AES.decrypt(word, key, {
mode: crypto.mode.ECB,
padding: crypto.pad.Pkcs7
})
return crypto.enc.Utf8.stringify(decrypt).toString()
}
function strToHex(str) {
var val = ''
for (var i = 0; i < str.length; i++) {
if (val == '') {
val = str.charCodeAt(i).toString(16)
} else {
val += str.charCodeAt(i).toString(16)
}
}
val += '0a'
return val
}
function hexToStr(hex) {
debugger;
//hex = JSON.stringify(hex);
hex = hex + ''
var arr = hex.split('')
var out = ''
for (var i = 0; i < arr.length / 2; i++) {
var tmp = '0x' + arr[i * 2] + arr[i * 2 + 1]
var charValue = String.fromCharCode(tmp)
out += charValue
}
return out
}
export default {
decrypt,
encrypt,
}

@ -2,7 +2,6 @@ import axios from 'axios'
import { Message, MessageBox } from 'element-ui' import { Message, MessageBox } from 'element-ui'
import store from '@/store' import store from '@/store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import aes from '@/utils/aes'
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
@ -19,12 +18,6 @@ const service = axios.create({
service.interceptors.request.use( service.interceptors.request.use(
config => { config => {
// do something before request is sent // do something before request is sent
// 对post请求进行加密
if (config.data && config.method === 'post') {
let sourceBody = JSON.stringify(config.data)
config.data = aes.encrypt(JSON.stringify(config.data))
// console.log('加密请求参数 ', sourceBody, ' -> ', config.data)
}
if (store.getters.token) { if (store.getters.token) {
// let each request carry token // let each request carry token
@ -54,14 +47,8 @@ service.interceptors.response.use(
* You can also judge the status by HTTP Status Code * You can also judge the status by HTTP Status Code
*/ */
response => { response => {
// console.log(response) const res = response.data
// console.log(JSON.stringify(response.headers))
const source = response.data
if (response.headers['encrypt'] != null) {
response.data = aes.decrypt(response.data)
}
// console.log(`响应数据解密: ${source} -> ${response.data}`)
const res = JSON.parse(response.data)
// if the custom code is not 0, it is judged as an error. // if the custom code is not 0, it is judged as an error.
if (res.code !== 0) { if (res.code !== 0) {
Message({ Message({

@ -64,7 +64,7 @@ export default {
name: 'Login', name: 'Login',
data() { data() {
const validateUsername = (rule, value, callback) => { const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) { if (false || !validUsername(value)) {
callback(new Error('Please enter the correct user name')) callback(new Error('Please enter the correct user name'))
} else { } else {
callback() callback()

@ -45,10 +45,10 @@ export default {
}, },
mounted() { mounted() {
// if (this.row !== null) { if (this.row !== null) {
// this.edit = JSON.parse(JSON.stringify(this.row)) this.edit = JSON.parse(JSON.stringify(this.row))
// // console.log(this.edit) // console.log(this.edit)
// } }
}, },
methods: { methods: {
closeDialog() { closeDialog() {

Loading…
Cancel
Save