Commit bba7768759c5d4dedd6599417154c4cb8ab64920

Authored by Vben
1 parent 8a9ca498

perf: replace crypto-es with crypto-js

CHANGELOG.zh_CN.md
... ... @@ -9,6 +9,7 @@
9 9 - 登录界面动画优化
10 10 - 修复 github 仓库体积过大问题.
11 11 - 默认隐藏表格全屏按钮
  12 +- `crypto-es`改为`crypto-js`,减小打包体积
12 13  
13 14 ### 🐛 Bug Fixes
14 15  
... ...
build/vite/plugin/visualizer.ts
... ... @@ -9,6 +9,10 @@ export function configVisualizerConfig() {
9 9 return visualizer({
10 10 filename: './node_modules/.cache/visualizer/stats.html',
11 11 open: true,
  12 + // @ts-ignore
  13 + gzipSize: true,
  14 + // @ts-ignore
  15 + brotliSize: true,
12 16 }) as Plugin;
13 17 }
14 18 return [];
... ...
package.json
... ... @@ -31,7 +31,7 @@
31 31 "ant-design-vue": "2.0.0",
32 32 "apexcharts": "^3.25.0",
33 33 "axios": "^0.21.1",
34   - "crypto-es": "^1.2.7",
  34 + "crypto-js": "^4.0.0",
35 35 "echarts": "^5.0.2",
36 36 "lodash-es": "^4.17.21",
37 37 "mockjs": "^1.1.0",
... ... @@ -49,11 +49,12 @@
49 49 "xlsx": "^0.16.9"
50 50 },
51 51 "devDependencies": {
52   - "@commitlint/cli": "^12.0.0",
53   - "@commitlint/config-conventional": "^12.0.0",
  52 + "@commitlint/cli": "^12.0.1",
  53 + "@commitlint/config-conventional": "^12.0.1",
54 54 "@iconify/json": "^1.1.308",
55 55 "@ls-lint/ls-lint": "^1.9.2",
56 56 "@purge-icons/generated": "^0.7.0",
  57 + "@types/crypto-js": "^4.0.1",
57 58 "@types/fs-extra": "^9.0.7",
58 59 "@types/http-proxy": "^1.17.5",
59 60 "@types/lodash-es": "^4.17.4",
... ... @@ -102,7 +103,7 @@
102 103 "vite-plugin-imagemin": "^0.2.8",
103 104 "vite-plugin-mock": "^2.1.5",
104 105 "vite-plugin-purge-icons": "^0.7.0",
105   - "vite-plugin-pwa": "^0.5.3",
  106 + "vite-plugin-pwa": "^0.5.4",
106 107 "vite-plugin-style-import": "^0.7.5",
107 108 "vite-plugin-theme": "^0.4.8",
108 109 "vite-plugin-windicss": "0.5.0",
... ...
src/components/Scrollbar/src/index.vue
... ... @@ -29,6 +29,7 @@
29 29 nextTick,
30 30 provide,
31 31 computed,
  32 + unref,
32 33 } from 'vue';
33 34 import Bar from './bar';
34 35  
... ... @@ -73,18 +74,25 @@
73 74  
74 75 provide('scroll-bar-wrap', wrap);
75 76  
  77 + const style = computed(() => {
  78 + if (Array.isArray(props.wrapStyle)) {
  79 + return toObject(props.wrapStyle);
  80 + }
  81 + return props.wrapStyle;
  82 + });
  83 +
76 84 const handleScroll = () => {
77 85 if (!props.native) {
78   - moveY.value = (wrap.value.scrollTop * 100) / wrap.value.clientHeight;
79   - moveX.value = (wrap.value.scrollLeft * 100) / wrap.value.clientWidth;
  86 + moveY.value = (unref(wrap).scrollTop * 100) / unref(wrap).clientHeight;
  87 + moveX.value = (unref(wrap).scrollLeft * 100) / unref(wrap).clientWidth;
80 88 }
81 89 };
82 90  
83 91 const update = () => {
84   - if (!wrap.value) return;
  92 + if (!unref(wrap)) return;
85 93  
86   - const heightPercentage = (wrap.value.clientHeight * 100) / wrap.value.scrollHeight;
87   - const widthPercentage = (wrap.value.clientWidth * 100) / wrap.value.scrollWidth;
  94 + const heightPercentage = (unref(wrap).clientHeight * 100) / unref(wrap).scrollHeight;
  95 + const widthPercentage = (unref(wrap).clientWidth * 100) / unref(wrap).scrollWidth;
88 96  
89 97 sizeHeight.value = heightPercentage < 100 ? heightPercentage + '%' : '';
90 98 sizeWidth.value = widthPercentage < 100 ? widthPercentage + '%' : '';
... ... @@ -94,25 +102,21 @@
94 102 if (props.native) return;
95 103 nextTick(update);
96 104 if (!props.noresize) {
97   - addResizeListener(resize.value, update);
98   - addResizeListener(wrap.value, update);
  105 + addResizeListener(unref(resize), update);
  106 + addResizeListener(unref(wrap), update);
  107 + addEventListener('resize', update);
99 108 }
100 109 });
101 110  
102 111 onBeforeUnmount(() => {
103 112 if (props.native) return;
104 113 if (!props.noresize) {
105   - removeResizeListener(resize.value, update);
106   - removeResizeListener(wrap.value, update);
  114 + removeResizeListener(unref(resize), update);
  115 + removeResizeListener(unref(wrap), update);
  116 + removeEventListener('resize', update);
107 117 }
108 118 });
109   - const style = computed(() => {
110   - let style: any = props.wrapStyle;
111   - if (Array.isArray(props.wrapStyle)) {
112   - style = toObject(props.wrapStyle);
113   - }
114   - return style;
115   - });
  119 +
116 120 return {
117 121 moveX,
118 122 moveY,
... ...
src/design/public.less
... ... @@ -6,19 +6,26 @@
6 6 // =================================
7 7 // ==============scrollbar==========
8 8 // =================================
  9 +
9 10 ::-webkit-scrollbar {
10   - width: 6px;
11   - height: 6px;
  11 + width: 8px;
  12 + height: 10px;
12 13 }
13 14  
  15 +// ::-webkit-scrollbar-track {
  16 +// background: transparent;
  17 +// }
  18 +
14 19 ::-webkit-scrollbar-track {
15 20 background: rgba(0, 0, 0, 0.05);
16 21 }
17 22  
18 23 ::-webkit-scrollbar-thumb {
19   - background: rgba(0, 0, 0, 0.2);
20   - border-radius: 4px;
21   - box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
  24 + background: rgba(0, 0, 0, 0.6);
  25 + background-color: rgba(144, 147, 153, 0.3);
  26 + // background-color: rgba(144, 147, 153, 0.3);
  27 + border-radius: 2px;
  28 + box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.2);
22 29 }
23 30  
24 31 ::-webkit-scrollbar-thumb:hover {
... ...
src/router/routes/index.ts
... ... @@ -36,5 +36,5 @@ export const LoginRoute: AppRouteRecordRaw = {
36 36 },
37 37 };
38 38  
39   -// 基础路由 不用权限
  39 +// Basic routing without permission
40 40 export const basicRoutes = [LoginRoute, RootRoute, ...mainOutRoutes, REDIRECT_ROUTE];
... ...
src/utils/encryption/aesEncryption.ts renamed to src/utils/cache/aesEncryption.ts
1   -import CryptoES from 'crypto-es';
  1 +import type { lib } from 'crypto-js';
  2 +
  3 +import { encrypt, decrypt } from 'crypto-js/aes';
  4 +import Uft8, { parse } from 'crypto-js/enc-utf8';
  5 +import pkcs7 from 'crypto-js/pad-pkcs7';
2 6  
3 7 export interface EncryptionParams {
4 8 key: string;
... ... @@ -6,30 +10,29 @@ export interface EncryptionParams {
6 10 }
7 11  
8 12 export class Encryption {
9   - private key;
10   -
11   - private iv;
  13 + private key: lib.WordArray;
  14 + private iv: lib.WordArray;
12 15  
13 16 constructor(opt: EncryptionParams) {
14 17 const { key, iv } = opt;
15   - this.key = CryptoES.enc.Utf8.parse(key);
16   - this.iv = CryptoES.enc.Utf8.parse(iv);
  18 + this.key = parse(key);
  19 + this.iv = parse(iv);
17 20 }
18 21  
19   - get getOptions(): CryptoES.lib.CipherCfg {
  22 + get getOptions() {
20 23 return {
21   - mode: CryptoES.mode.CBC,
22   - padding: CryptoES.pad.Pkcs7,
  24 + // mode: mode.CBC,
  25 + padding: pkcs7,
23 26 iv: this.iv,
24 27 };
25 28 }
26 29  
27 30 encryptByAES(str: string) {
28   - return CryptoES.AES.encrypt(str, this.key, this.getOptions).toString();
  31 + return encrypt(str, this.key, this.getOptions).toString();
29 32 }
30 33  
31 34 decryptByAES(str: string) {
32   - return CryptoES.AES.decrypt(str, this.key, this.getOptions).toString(CryptoES.enc.Utf8);
  35 + return decrypt(str, this.key, this.getOptions).toString(Uft8);
33 36 }
34 37 }
35 38 export default Encryption;
... ...
src/utils/cache/index.ts
1   -import { getStorageShortName } from '/@/utils/helper/envHelper';
  1 +import { getStorageShortName } from '/@/utils/env';
2 2 import { createStorage as create } from './storageCache';
3 3 import { enableStorageEncryption } from '/@/settings/encryptionSetting';
  4 +import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
4 5  
5 6 const createOptions = (storage = sessionStorage) => {
6 7 return {
... ... @@ -8,6 +9,7 @@ const createOptions = (storage = sessionStorage) =&gt; {
8 9 hasEncrypt: enableStorageEncryption,
9 10 storage,
10 11 prefixKey: getStorageShortName(),
  12 + timeout: DEFAULT_CACHE_TIME,
11 13 };
12 14 };
13 15  
... ...
src/utils/cache/storageCache.ts
1   -import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
2 1 import { cacheCipher } from '/@/settings/encryptionSetting';
3   -import Encryption, { EncryptionParams } from '/@/utils/encryption/aesEncryption';
  2 +
  3 +import Encryption, { EncryptionParams } from './aesEncryption';
4 4  
5 5 export interface CreateStorageParams extends EncryptionParams {
  6 + prefixKey: string;
6 7 storage: Storage;
7   -
8 8 hasEncrypt: boolean;
  9 + timeout?: Nullable<number>;
9 10 }
10 11 export const createStorage = ({
11 12 prefixKey = '',
12 13 storage = sessionStorage,
13 14 key = cacheCipher.key,
14 15 iv = cacheCipher.iv,
  16 + timeout = null,
15 17 hasEncrypt = true,
16   -} = {}) => {
  18 +}: Partial<CreateStorageParams> = {}) => {
17 19 if (hasEncrypt && [key.length, iv.length].some((item) => item !== 16)) {
18 20 throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
19 21 }
... ... @@ -54,7 +56,7 @@ export const createStorage = ({
54 56 * @expire Expiration time in seconds
55 57 * @memberof Cache
56 58 */
57   - set(key: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) {
  59 + set(key: string, value: any, expire: number | null = timeout) {
58 60 const stringData = JSON.stringify({
59 61 value,
60 62 expire: expire !== null ? new Date().getTime() + expire * 1000 : null,
... ...
src/utils/helper/envHelper.ts deleted 100644 → 0
1   -import { getEnv } from '/@/utils/env';
2   -import { useGlobSetting } from '/@/hooks/setting';
3   -import pkg from '../../../package.json';
4   -const globSetting = useGlobSetting();
5   -
6   -// Generate cache key according to version
7   -export function getStorageShortName() {
8   - return `${globSetting.shortName}__${getEnv()}${`__${pkg.version}`}__`.toUpperCase();
9   -}
src/views/demo/main-out/index.vue
1 1 <template>
2   - <div class="test"> 位于主框架外的页面 </div>
  2 + <div class="fixed h-full w-full flex flex-col justify-center items-center text-4xl">
  3 + <div class=""> 位于主框架外的页面 </div>
  4 + <a-button @click="$router.go(-1)" class="mt-10" type="primary">Back</a-button>
  5 + </div>
3 6 </template>
4   -<script lang="ts">
5   - import { defineComponent } from 'vue';
6   -
7   - export default defineComponent({});
8   -</script>
9   -
10   -<style scoped>
11   - .test {
12   - position: fixed;
13   - display: flex;
14   - width: 100%;
15   - height: 100%;
16   - justify-content: center;
17   - align-items: center;
18   - font-size: 50px;
19   - }
20   -</style>
... ...
yarn.lock
... ... @@ -1298,6 +1298,11 @@
1298 1298 ejs "^2.6.1"
1299 1299 magic-string "^0.25.0"
1300 1300  
  1301 +"@types/crypto-js@^4.0.1":
  1302 + version "4.0.1"
  1303 + resolved "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.0.1.tgz#3a4bd24518b0e6c5940da4e2659eeb2ef0806963"
  1304 + integrity sha512-6+OPzqhKX/cx5xh+yO8Cqg3u3alrkhoxhE5ZOdSEv0DOzJ13lwJ6laqGU0Kv6+XDMFmlnGId04LtY22PsFLQUw==
  1305 +
1301 1306 "@types/estree@0.0.39":
1302 1307 version "0.0.39"
1303 1308 resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
... ... @@ -3025,10 +3030,10 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2:
3025 3030 shebang-command "^2.0.0"
3026 3031 which "^2.0.1"
3027 3032  
3028   -crypto-es@^1.2.7:
3029   - version "1.2.7"
3030   - resolved "https://registry.npmjs.org/crypto-es/-/crypto-es-1.2.7.tgz#754a6d52319a94fb4eb1f119297f17196b360f88"
3031   - integrity sha512-UUqiVJ2gUuZFmbFsKmud3uuLcNP2+Opt+5ysmljycFCyhA0+T16XJmo1ev/t5kMChMqWh7IEvURNCqsg+SjZGQ==
  3033 +crypto-js@^4.0.0:
  3034 + version "4.0.0"
  3035 + resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc"
  3036 + integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg==
3032 3037  
3033 3038 crypto-random-string@^2.0.0:
3034 3039 version "2.0.0"
... ... @@ -8930,10 +8935,10 @@ vite-plugin-purge-icons@^0.7.0:
8930 8935 "@purge-icons/generated" "^0.7.0"
8931 8936 rollup-plugin-purge-icons "^0.7.0"
8932 8937  
8933   -vite-plugin-pwa@^0.5.3:
8934   - version "0.5.3"
8935   - resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.5.3.tgz#60d97d62335846144c8e6b6a911704d6c0f75171"
8936   - integrity sha512-xGh0gIgzczvYNj8ED5HhpJ2iT5kMiieim2qI8kT/3+rfo83hTyuzhEICkljIbhausvOaGxtzLKWE8RS6cUg0Fw==
  8938 +vite-plugin-pwa@^0.5.4:
  8939 + version "0.5.4"
  8940 + resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.5.4.tgz#ce6fb85da140359057290e5eba3c22548392bea5"
  8941 + integrity sha512-Zcr190GixdvvHBS1poTevtuw0irRvRi9rLFdXUbkPyY5hozQ+JhR8i/ORRvl6a9wV6Gl/mVwJ3IaY5IjTf3zFw==
8937 8942 dependencies:
8938 8943 debug "^4.3.2"
8939 8944 fast-glob "^3.2.5"
... ...