8000 1.0.9 vue部分crypto进行cdn引入 · HyperGenm/springboot-vue@4e95402 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 4e95402

Browse files
author
WeiziPlus
committed
1.0.9 vue部分crypto进行cdn引入
1 parent c0f1242 commit 4e95402

File tree

14 files changed

+102
-11356
lines changed

14 files changed

+102
-11356
lines changed

vue/package-lock.json

Lines changed: 0 additions & 11206 deletions
This file was deleted.

vue/public/cdn/axios-0.19.2.min.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

vue/public/cdn/crypto-js-4.0.0.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vue/public/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<meta name="viewport" content="width=device-width,initial-scale=1.0">
1010
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
1111
<title>WeiziPlus</title>
12+
<!--CDN引入CryptoJS-->
13+
<script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
14+
<script>window.CryptoJS || document.write('<script src="<%= BASE_URL %>cdn/crypto-js-4.0.0.min.js"><\/script>')</script>
1215
<% if(process.env.NODE_ENV === 'production'){ %>
1316
<!--CDN引入Vue后,element-ui才可以CDN引入-->
1417
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
@@ -22,9 +25,6 @@
2225
<!--CDN引入vuex,减少打包体积-->
2326
<script src="https://cdn.bootcss.com/vuex/3.2.0/vuex.min.js"></script>
2427
<script>window.Vuex || document.write('<script src="<%= BASE_URL %>cdn/vuex-3.2.0.min.js"><\/script>')</script>
25-
<!--CDN引入axios,减少打包体积-->
26-
<script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
27-
<script>window.axios || document.write('<script src="<%= BASE_URL %>cdn/axios-0.19.2.min.js"><\/script>')</script>
2828
<% } %>
2929
</head>
3030
<body>

vue/src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ Vue.prototype.$axiosDown = weiAxiosDown;
2020
/**引入全局变量和方法*/
2121
import globalVariable from './utils/global_variable'
2222
import globalFunction from './utils/global_function'
23+
import cryptoJS from './utils/cryptoJS'
24+
import jsEncrypt from './utils/jsEncrypt'
2325

2426
Vue.prototype.$global = globalVariable;
2527
Vue.prototype.$globalFun = globalFunction;
28+
Vue.prototype.$cryptoJS = cryptoJS;
29+
Vue.prototype.$jsEncrypt = jsEncrypt;
2630

2731
new Vue({
2832
router,

vue/src/utils/axios.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function weiAxios(
112112
data[key] = urlParamMap[key];
113113
}
114114
let asciiStr = that.$globalFun.sortAscii(data);
115-
data['__sign'] = that.$globalFun.md5NoSalt(asciiStr);
115+
data['__sign'] = that.$cryptoJS.md5NoSalt(asciiStr);
116116
}
117117
/**axios请求处理不同请求方式时的参数*/
118118
method = method.toUpperCase();
@@ -233,7 +233,7 @@ export function weiAxiosDown(
233233
data[key] = urlParamMap[key];
234234
}
235235
let asciiStr = that.$globalFun.sortAscii(data);
236-
data['__sign'] = that.$globalFun.md5NoSalt(asciiStr);
236+
data['__sign'] = that.$cryptoJS.md5NoSalt(asciiStr);
237237
}
238238
/**axios请求处理不同请求方式时的参数*/
239239
method = method.toUpperCase();

vue/src/utils/cryptoJS.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*引入CryptoJS加密,此处替换为CDN*/
2+
3+
// import CryptoJS from "crypto-js";
4+
5+
/**
6+
* base64加密
7+
* @param word
8+
* @returns {string}
9+
*/
10+
function base64Encrypt(word) {
11+
if (null == word) {
12+
return null;
13+
}
14+
let wordArray = CryptoJS.enc.Utf8.parse(word);
15+
return CryptoJS.enc.Base64.stringify(wordArray);
16+
}
17+
18+
/**
19+
* base64解密
20+
* @param wordArray
21+
* @returns {*}
22+
*/
23+
function base64Decrypt(wordArray) {
24+
if (null == wordArray) {
25+
return null;
26+
}
27+
let parsedWordArray = CryptoJS.enc.Base64.parse(wordArray);
28+
return parsedWordArray.toString(CryptoJS.enc.Utf8);
29+
}
30+
31+
/**
32+
* md5加密
33+
* @param str
34+
* @returns {*}
35+
*/
36+
function md5(str) {
37+
if (null == str) {
38+
return null;
39+
}
40+
str = `weiziplus-${str}`;
41+
return CryptoJS.MD5(str).toString().toUpperCase();
42+
}
43+
44+
/**
45+
* md5加密没有加密盐
46+
* @param str
47+
* @returns {*}
48+
*/
49+
function md5NoSalt(str) {
50+
if (null == str) {
51+
return null;
52+
}
53+
return CryptoJS.MD5(str).toString().toUpperCase();
54+
}
55+
56+
/**
57+
* 将方法暴露出去
58+
*/
59+
export default {
60+
base64Encrypt,
61+
base64Decrypt,
62+
md5,
63+
md5NoSalt,
64+
};

0 commit comments

Comments
 (0)
0