From ade081b70a8e9e7faa113606b65f3201179b8363 Mon Sep 17 00:00:00 2001
From: chuan_wuhao <443547225@qq.com>
Date: Wed, 10 Aug 2022 19:01:01 +0800
Subject: [PATCH] update code
---
README.md | 3 +-
package.json | 5 +++
postcss.config.cjs | 20 ++++++++++
src/main.ts | 1 +
src/types/index.d.ts | 8 ++++
src/utils/crypto.ts | 91 ++++++++++++++++++++++++++++++++++++++++++++
yarn.lock | 54 +++++++++++++++++++++++++-
7 files changed, 180 insertions(+), 2 deletions(-)
create mode 100644 postcss.config.cjs
create mode 100644 src/utils/crypto.ts
diff --git a/README.md b/README.md
index db3848ac..0ef3ea7e 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
## 项目说明
-项目采用 `Vue 3` `TypeScript` `TSX` `Vite` 进行开发, 已经集成了一些常用的开发库, 进行了一些 `Vite` 相关配置, 例如全局自动引入、`GZ` 打包、按需引入打包、[reactivityTransform](https://vuejs.org/guide/extras/reactivity-transform.html)等, 解放你的双手. 国际化插件, 按照项目需求自己取舍. 引入了比较火的 `hook` 库 [@vueuse](https://vueuse.org/), 极大提高你的搬砖效率. `小提醒: 为了避免使用 @vueuse 时出现奇奇怪怪的错误(例如: useDraggable 在使用的时候, TSX 形式开发会失效), 建议采用 形式进行开发`.
+项目采用 `Vue 3` `TypeScript` `TSX` `Vite` 进行开发, 已经集成了一些常用的开发库, 进行了一些 `Vite` 相关配置, 例如全局自动引入、`GZ` 打包、按需引入打包、[reactivityTransform](https://vuejs.org/guide/extras/reactivity-transform.html)等, 解放你的双手. 国际化插件, 按照项目需求自己取舍. 引入了比较火的 `hook` 库 [@vueuse](https://vueuse.org/), 极大提高你的搬砖效率. `小提醒: 为了避免使用 @vueuse 时出现奇奇怪怪的错误(例如: useDraggable 在使用的时候, TSX 形式开发会失效), 建议采用 形式进行开发`. 可以根据自己项目实际需求进行配置 `px` 与 'rem' 转换比例(使用 `postcss-pxtorem` 与 `autoprefixer` 实现)
## 启动项目
@@ -22,6 +22,7 @@
- [axios](http://axios-js.com/zh-cn/docs/index.html) `ajax request`
- [vue-i18n](https://kazupon.github.io/vue-i18n/zh/introduction.html) `国际化`
- [scrollreveal.js](https://scrollrevealjs.org/) `滚动加载动画`
+- [crypto-js](https://github.com/brix/crypto-js) `加密`
## 组件说明
diff --git a/package.json b/package.json
index bbecc7b5..aee55c52 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,9 @@
},
"dependencies": {
"@vueuse/core": "^9.1.0",
+ "amfe-flexible": "^2.2.1",
"axios": "^0.27.2",
+ "crypto-js": "^4.1.1",
"pinia": "^2.0.17",
"sass": "^1.54.3",
"scrollreveal": "^4.0.9",
@@ -20,9 +22,12 @@
},
"devDependencies": {
"@intlify/unplugin-vue-i18n": "^0.5.0",
+ "@types/crypto-js": "^4.1.1",
"@types/scrollreveal": "^0.0.8",
"@vitejs/plugin-vue": "^3.0.0",
"@vitejs/plugin-vue-jsx": "^2.0.0",
+ "autoprefixer": "^10.4.8",
+ "postcss-pxtorem": "^6.0.0",
"prettier": "^2.7.1",
"typescript": "^4.6.4",
"unplugin-auto-import": "^0.11.0",
diff --git a/postcss.config.cjs b/postcss.config.cjs
new file mode 100644
index 00000000..55f2bf20
--- /dev/null
+++ b/postcss.config.cjs
@@ -0,0 +1,20 @@
+module.exports = {
+ plugins: {
+ autoprefixer: {
+ overrideBrowserslist: [
+ 'Android 4.1',
+ 'iOS 7.1',
+ 'Chrome > 31',
+ 'ff > 31',
+ 'ie >= 8',
+ 'last 10 versions',
+ ],
+ grid: true,
+ },
+ 'postcss-pxtorem': {
+ rootValue: 37.5,
+ propList: ['*'],
+ unitPrecision: 5,
+ },
+ },
+}
diff --git a/src/main.ts b/src/main.ts
index c7a7f970..62c4f44e 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -3,6 +3,7 @@ import { createApp } from 'vue'
import '@/styles/base.scss'
import 'virtual:svg-icons-register' // 注册 vite-plugin-svg-icons 脚本
+import 'amfe-flexible'
import App from './App'
diff --git a/src/types/index.d.ts b/src/types/index.d.ts
index 7fea3b68..d1a00cfd 100644
--- a/src/types/index.d.ts
+++ b/src/types/index.d.ts
@@ -1,5 +1,7 @@
export {}
+import type CryptoJS from 'crypto-js'
+
export global {
declare interface IUnknownObjectKey {
[propName: string]: any
@@ -22,4 +24,10 @@ export global {
| 'Math'
| 'RegExp'
| 'Error'
+
+ declare type WordArray = CryptoJS.lib.WordArray
+
+ declare type CipherOption = CryptoJS.lib.CipherOption
+
+ declare type CipherParams = CryptoJS.lib.CipherParams
}
diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts
new file mode 100644
index 00000000..94fefd50
--- /dev/null
+++ b/src/utils/crypto.ts
@@ -0,0 +1,91 @@
+import HmacSHA256 from 'crypto-js/hmac-sha256'
+import SHA256 from 'crypto-js/sha256'
+import AES from 'crypto-js/aes'
+import MD5 from 'crypto-js/md5'
+
+/**
+ *
+ * @param message 待加密信息
+ * @param key 加密key
+ *
+ * HmacSHA256 加密
+ */
+export const useHmacSHA256 = (
+ message: WordArray | string,
+ key: WordArray | string,
+) => {
+ return new Promise((resolve) => {
+ const cry = HmacSHA256(message, key)
+
+ resolve(cry)
+ })
+}
+
+/**
+ *
+ * @param message 待加密信息
+ *
+ * SHA256 加密
+ */
+export const useSHA256 = (message: WordArray | string) => {
+ return new Promise((resolve) => {
+ const cry = SHA256(message)
+
+ resolve(cry)
+ })
+}
+
+/**
+ *
+ * @param message 待加密信息
+ * @param key 加密key
+ * @param cfg 加密配置信息
+ *
+ * AES 加密
+ */
+export const useAESEncrypt = (
+ message: WordArray | string,
+ key: WordArray | string,
+ cfg?: CipherOption,
+) => {
+ return new Promise((resolve) => {
+ const cry = AES.encrypt(message, key, cfg)
+
+ resolve(cry)
+ })
+}
+
+/**
+ *
+ * @param ciphertext 待解密信息
+ * @param key 解密key
+ * @param cfg 解密配置信息
+ *
+ * AES 解密
+ */
+export const useAESDecrypt = (
+ ciphertext: CipherParams | string,
+ key: WordArray | string,
+ cfg?: CipherOption,
+) => {
+ return new Promise((resolve) => {
+ const cry = AES.decrypt(ciphertext, key, cfg)
+
+ resolve(cry)
+ })
+}
+
+/**
+ *
+ * @param message 待加密信息
+ * @param cfg md5 加密配置
+ *
+ * md5 加密
+ */
+export const useMD5 = (message: WordArray | string, cfg?: object) => {
+ return new Promise((resolve) => {
+ const cry = MD5(message, cfg)
+
+ resolve(cry)
+ })
+}
diff --git a/yarn.lock b/yarn.lock
index ed9a6225..3d3c1cfa 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -438,6 +438,11 @@
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"
integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==
+"@types/crypto-js@^4.1.1":
+ version "4.1.1"
+ resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.1.1.tgz#602859584cecc91894eb23a4892f38cfa927890d"
+ integrity sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==
+
"@types/node@*":
version "18.6.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.4.tgz#fd26723a8a3f8f46729812a7f9b4fc2d1608ed39"
@@ -661,6 +666,11 @@ acorn@^8.7.1, acorn@^8.8.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==
+amfe-flexible@^2.2.1:
+ version "2.2.1"
+ resolved "https://registry.yarnpkg.com/amfe-flexible/-/amfe-flexible-2.2.1.tgz#353f00289e4d38ca88a21eb3854420308af0b559"
+ integrity sha512-L2VfvDzoETBjhRptg5u/IUuzHSuxm22JpSRb404p/TBGeRfwWmmNEbB+TFPIP/sS/+pbM18bCFH9QnMojLuPNw==
+
ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@@ -733,6 +743,18 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
+autoprefixer@^10.4.8:
+ version "10.4.8"
+ resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.8.tgz#92c7a0199e1cfb2ad5d9427bd585a3d75895b9e5"
+ integrity sha512-75Jr6Q/XpTqEf6D2ltS5uMewJIx5irCU1oBYJrWjFenq/m12WRRrz6g15L1EIoYvPLXTbEry7rDOwrcYNj77xw==
+ dependencies:
+ browserslist "^4.21.3"
+ caniuse-lite "^1.0.30001373"
+ fraction.js "^4.2.0"
+ normalize-range "^0.1.2"
+ picocolors "^1.0.0"
+ postcss-value-parser "^4.2.0"
+
axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
@@ -809,7 +831,7 @@ braces@^3.0.2, braces@~3.0.2:
dependencies:
fill-range "^7.0.1"
-browserslist@^4.20.2:
+browserslist@^4.20.2, browserslist@^4.21.3:
version "4.21.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.3.tgz#5df277694eb3c48bc5c4b05af3e8b7e09c5a6d1a"
integrity sha512-898rgRXLAyRkM1GryrrBHGkqA5hlpkV5MhtZwg9QXeiyLUYs2k00Un05aX5l2/yJIOObYKOpS2JNo8nJDE7fWQ==
@@ -844,6 +866,11 @@ caniuse-lite@^1.0.30001370:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001374.tgz#3dab138e3f5485ba2e74bd13eca7fe1037ce6f57"
integrity sha512-mWvzatRx3w+j5wx/mpFN5v5twlPrabG8NqX2c6e45LCpymdoGqNvRkRutFUqpRTXKFQFNQJasvK0YT7suW6/Hw==
+caniuse-lite@^1.0.30001373:
+ version "1.0.30001375"
+ resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001375.tgz#8e73bc3d1a4c800beb39f3163bf0190d7e5d7672"
+ integrity sha512-kWIMkNzLYxSvnjy0hL8w1NOaWNr2rn39RTAVyIwcw8juu60bZDWiF1/loOYANzjtJmy6qPgNmn38ro5Pygagdw==
+
chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -971,6 +998,11 @@ cors@^2.8.5:
object-assign "^4"
vary "^1"
+crypto-js@^4.1.1:
+ version "4.1.1"
+ resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
+ integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
+
css-select@^4.1.3:
version "4.3.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.3.0.tgz#db7129b2846662fd8628cfc496abb2b59e41529b"
@@ -1400,6 +1432,11 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"
+fraction.js@^4.2.0:
+ version "4.2.0"
+ resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
+ integrity sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==
+
fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"
@@ -1967,6 +2004,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
+normalize-range@^0.1.2:
+ version "0.1.2"
+ resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942"
+ integrity sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==
+
nth-check@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"
@@ -2059,6 +2101,16 @@ postcss-prefix-selector@^1.6.0:
resolved "https://registry.yarnpkg.com/postcss-prefix-selector/-/postcss-prefix-selector-1.16.0.tgz#ad5b56f9a73a2c090ca7161049632c9d89bcb404"
integrity sha512-rdVMIi7Q4B0XbXqNUEI+Z4E+pueiu/CS5E6vRCQommzdQ/sgsS4dK42U7GX8oJR+TJOtT+Qv3GkNo6iijUMp3Q==
+postcss-pxtorem@^6.0.0:
+ version "6.0.0"
+ resolved "https://registry.yarnpkg.com/postcss-pxtorem/-/postcss-pxtorem-6.0.0.tgz#f228a4d05d8a73f0642eabae950e2b19836366d7"
+ integrity sha512-ZRXrD7MLLjLk2RNGV6UA4f5Y7gy+a/j1EqjAfp9NdcNYVjUMvg5HTYduTjSkKBkRkfqbg/iKrjMO70V4g1LZeg==
+
+postcss-value-parser@^4.2.0:
+ version "4.2.0"
+ resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
+ integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==
+
postcss@^5.2.17:
version "5.2.18"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-5.2.18.tgz#badfa1497d46244f6390f58b319830d9107853c5"