From b783b8d991dcca24a5e7d93fe9232e2fcb9bd663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Sun, 14 Jan 2024 22:30:00 +0800 Subject: [PATCH 01/12] =?UTF-8?q?update=20=E5=85=A8=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 62 +++++++++++++++--------------- src/views/system/user/authRole.vue | 1 + 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index a93f63a..5e61e31 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "dependencies": { "@element-plus/icons-vue": "2.3.1", "@vueup/vue-quill": "1.2.0", - "@vueuse/core": "10.7.0", + "@vueuse/core": "10.7.2", "animate.css": "4.1.1", "await-to-js": "3.0.0", - "axios": "1.6.0", + "axios": "1.6.5", "crypto-js": "4.2.0", "echarts": "5.4.3", "element-plus": "2.4.4", @@ -34,57 +34,57 @@ "jsencrypt": "3.3.2", "nprogress": "0.2.0", "path-browserify": "1.0.1", - "path-to-regexp": "6.2.0", + "path-to-regexp": "6.2.1", "pinia": "2.1.7", - "screenfull": "6.0.0", - "vform3-builds": "3.0.8", - "vue": "3.4.5", + "screenfull": "6.0.2", + "vform3-builds": "3.0.10", + "vue": "3.4.13", "vue-cropper": "1.1.1", - "vue-i18n": "9.8.0", + "vue-i18n": "9.9.0", "vue-router": "4.2.5", "vue-types": "5.1.1" }, "devDependencies": { - "@iconify/json": "2.2.167", + "@iconify/json": "2.2.168", "@intlify/unplugin-vue-i18n": "2.0.0", - "@types/crypto-js": "4.2.0", - "@types/file-saver": "2.0.5", - "@types/js-cookie": "3.0.5", + "@types/crypto-js": "4.2.1", + "@types/file-saver": "2.0.7", + "@types/js-cookie": "3.0.6", "@types/node": "18.14.2", - "@types/nprogress": "0.2.0", - "@types/path-browserify": "1.0.0", - "@typescript-eslint/eslint-plugin": "6.17.0", - "@typescript-eslint/parser": "6.17.0", + "@types/nprogress": "0.2.3", + "@types/path-browserify": "1.0.2", + "@typescript-eslint/eslint-plugin": "6.18.1", + "@typescript-eslint/parser": "6.18.1", "@unocss/preset-attributify": "0.58.3", "@unocss/preset-icons": "0.58.3", "@unocss/preset-uno": "0.58.3", - "@vue/compiler-sfc": "3.4.5", - "@vitejs/plugin-vue": "5.0.2", - "autoprefixer": "10.4.14", - "eslint": "8.55.0", + "@vue/compiler-sfc": "3.4.13", + "@vitejs/plugin-vue": "5.0.3", + "autoprefixer": "10.4.16", + "eslint": "8.56.0", "eslint-config-prettier": "9.1.0", - "eslint-define-config": "2.0.0", - "eslint-plugin-prettier": "5.0.1", + "eslint-define-config": "2.1.0", + "eslint-plugin-prettier": "5.1.3", "eslint-plugin-promise": "6.1.1", "eslint-plugin-node": "11.1.0", - "eslint-plugin-import": "2.29.0", - "eslint-plugin-vue": "9.19.2", + "eslint-plugin-import": "2.29.1", + "eslint-plugin-vue": "9.20.1", "fast-glob": "3.3.2", "husky": "8.0.3", "postcss": "8.4.33", - "prettier": "3.1.1", - "sass": "1.69.5", + "prettier": "3.2.2", + "sass": "1.69.7", "typescript": "5.3.3", - "unocss": "0.58.0", - "unplugin-auto-import": "0.17.2", - "unplugin-icons": "0.18.1", + "unocss": "0.58.3", + "unplugin-auto-import": "0.17.3", + "unplugin-icons": "0.18.2", "unplugin-vue-components": "0.26.0", "unplugin-vue-setup-extend-plus": "1.0.0", "vite-plugin-compression": "0.5.1", "vite-plugin-svg-icons": "2.0.1", - "vitest": "1.1.3", - "vue-eslint-parser": "9.3.2", + "vitest": "1.2.0", + "vue-eslint-parser": "9.4.0", "vue-tsc": "1.8.27", - "vite": "5.0.10" + "vite": "5.0.11" } } diff --git a/src/views/system/user/authRole.vue b/src/views/system/user/authRole.vue index 656ffc2..9b9927d 100644 --- a/src/views/system/user/authRole.vue +++ b/src/views/system/user/authRole.vue @@ -59,6 +59,7 @@ import { RoleVO } from '@/api/system/role/types'; import { getAuthRole, updateAuthRole } from '@/api/system/user'; import { UserForm } from '@/api/system/user/types'; import { RouteLocationNormalized } from 'vue-router'; +import { parseTime } from "@/utils/ruoyi"; const route = useRoute(); const { proxy } = getCurrentInstance() as ComponentInternalInstance; From 0c56f87e06a62c4c9e5d4c3a5ebc4ec139ab924e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E5=85=B5=20=E6=9D=8E?= Date: Mon, 15 Jan 2024 22:59:22 +0800 Subject: [PATCH 02/12] =?UTF-8?q?foreach=E4=B8=ADreturn=E5=B9=B6=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E4=BD=BF=E5=85=B6=E8=B7=B3=E5=87=BA=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=BF=99=E4=B8=AA=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=80=E7=9B=B4=E9=83=BD=E4=BC=9A=E6=98=AF?= =?UTF-8?q?false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DictTag/index.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/DictTag/index.vue b/src/components/DictTag/index.vue index b355a42..7442546 100644 --- a/src/components/DictTag/index.vue +++ b/src/components/DictTag/index.vue @@ -50,12 +50,13 @@ const values = computed(() => { const unmatch = computed(() => { if (props.options?.length == 0 || props.value === '' || props.value === null || typeof props.value === 'undefined') return false; // 传入值为非数组 + let unmatch = false; // 添加一个标志来判断是否有未匹配项 values.value.forEach((item) => { if (!props.options.some((v) => v.value === item)) { - return true; // 如果有未匹配项,将标志设置为true + unmatch = true; // 如果有未匹配项,将标志设置为true } }); - return false; // 返回标志的值 + return unmatch; // 返回标志的值 }); const unmatchArray = computed(() => { From 7b7377fa1b051306dffe4633c48be92bf0d3f8ff Mon Sep 17 00:00:00 2001 From: LiuHao Date: Tue, 16 Jan 2024 09:51:51 +0800 Subject: [PATCH 03/12] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96request?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=B1=BB=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A4=B4=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 6135d69..3de2076 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -36,11 +36,12 @@ service.interceptors.request.use( // 对应国际化资源文件后缀 config.headers['Content-Language'] = getLanguage(); - const isToken = (config.headers || {}).isToken === false; + const isToken = config.headers?.isToken === false; // 是否需要防止数据重复提交 - const isRepeatSubmit = (config.headers || {}).repeatSubmit === false; + const isRepeatSubmit = config.headers?.repeatSubmit === false; // 是否需要加密 - const isEncrypt = (config.headers || {}).isEncrypt === 'true'; + const isEncrypt = config.headers?.isEncrypt === 'true'; + if (getToken() && !isToken) { config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改 } From fe3874396d594a5624dff40425ca2a97c742e119 Mon Sep 17 00:00:00 2001 From: fengheguai <923553443@qq.com> Date: Thu, 25 Jan 2024 12:50:45 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=8E=8B=E7=BC=A9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=94=AF=E6=8C=81=EF=BC=8C=E5=8F=AF=E8=87=AA=E8=A1=8C?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/components/ImageUpload/index.vue | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5e61e31..861f30c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "element-plus": "2.4.4", "file-saver": "2.0.5", "fuse.js": "7.0.0", + "image-conversion": "^2.1.1", "js-cookie": "3.0.5", "jsencrypt": "3.3.2", "nprogress": "0.2.0", diff --git a/src/components/ImageUpload/index.vue b/src/components/ImageUpload/index.vue index ae5cd45..1c6dcd1 100644 --- a/src/components/ImageUpload/index.vue +++ b/src/components/ImageUpload/index.vue @@ -44,6 +44,7 @@ import { listByIds, delOss } from '@/api/system/oss'; import { OssVO } from '@/api/system/oss/types'; import { propTypes } from '@/utils/propTypes'; import { globalHeaders } from '@/utils/request'; +import { compressAccurately } from 'image-conversion'; const props = defineProps({ modelValue: { @@ -60,7 +61,14 @@ const props = defineProps({ isShowTip: { type: Boolean, default: true - } + }, + // 是否支持压缩,默认否 + compressSupport: { + type: Boolean, + default: false + }, + // 压缩目标大小,单位KB。默认300KB以上文件才压缩,并压缩至300KB以内 + compressTargetSize: propTypes.number.def(300) }); const { proxy } = getCurrentInstance() as ComponentInternalInstance; @@ -138,8 +146,16 @@ const handleBeforeUpload = (file: any) => { return false; } } - proxy?.$modal.loading('正在上传图片,请稍候...'); - number.value++; + + //压缩图片,开启压缩并且大于指定的压缩大小时才压缩 + if (props.compressSupport && file.size / 1024 > props.compressTargetSize) { + proxy?.$modal.loading('正在上传图片,请稍候...'); + number.value++; + return compressAccurately(file, props.compressTargetSize); + } else { + proxy?.$modal.loading('正在上传图片,请稍候...'); + number.value++; + } }; // 文件个数超出 From b4cc7b3de0206123a943b1c805b458f60b149a9d Mon Sep 17 00:00:00 2001 From: LiuHao Date: Fri, 26 Jan 2024 09:58:00 +0800 Subject: [PATCH 05/12] =?UTF-8?q?add=20=E5=BC=95=E5=85=A5vxe-table?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/main.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e61e31..45630de 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "vue-cropper": "1.1.1", "vue-i18n": "9.9.0", "vue-router": "4.2.5", - "vue-types": "5.1.1" + "vue-types": "5.1.1", + "vxe-table": "4.5.18" }, "devDependencies": { "@iconify/json": "2.2.168", diff --git a/src/main.ts b/src/main.ts index 439d82c..f40059e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,12 +25,20 @@ import './permission'; // 国际化 import i18n from '@/lang/index'; +// vxeTable +import VXETable from 'vxe-table'; +import 'vxe-table/lib/style.css'; +VXETable.config({ + zIndex: 999999 +}); + const app = createApp(App); app.use(ElementIcons); app.use(router); app.use(store); app.use(i18n); +app.use(VXETable); app.use(plugins); // 自定义指令 directive(app); From 3b18a476b709bdf4cd025889b3de4cfd5aac0ab6 Mon Sep 17 00:00:00 2001 From: LiuHao Date: Fri, 26 Jan 2024 09:59:05 +0800 Subject: [PATCH 06/12] add hooks - useDialog --- src/hooks/useDialog.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/hooks/useDialog.ts diff --git a/src/hooks/useDialog.ts b/src/hooks/useDialog.ts new file mode 100644 index 0000000..547f199 --- /dev/null +++ b/src/hooks/useDialog.ts @@ -0,0 +1,31 @@ +import { Ref } from 'vue'; + +interface Options { + title?: string; +} +interface Return { + title: Ref; + visible: Ref; + openDialog: () => void; + closeDialog: () => void; +} +export default (ops?: Options): Return => { + const visible = ref(false); + const title = ref(ops.title || ''); + + const openDialog = () => { + visible.value = true; + }; + + const closeDialog = () => { + visible.value = false; + }; + + return { + title, + visible, + + openDialog, + closeDialog + }; +}; From 63ba90cc10779b34648e91019b2fb408a9fc4c2e Mon Sep 17 00:00:00 2001 From: LiuHao Date: Fri, 26 Jan 2024 09:59:23 +0800 Subject: [PATCH 07/12] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UserSelect/index.vue | 261 ++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 src/components/UserSelect/index.vue diff --git a/src/components/UserSelect/index.vue b/src/components/UserSelect/index.vue new file mode 100644 index 0000000..6a68f92 --- /dev/null +++ b/src/components/UserSelect/index.vue @@ -0,0 +1,261 @@ + + + + + From b2f00c4b71ec3288eda61a3c800d280c7f1e8be3 Mon Sep 17 00:00:00 2001 From: LiuHao Date: Fri, 26 Jan 2024 09:59:32 +0800 Subject: [PATCH 08/12] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=A7=92=E8=89=B2=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/RoleSelect/index.vue | 199 ++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 src/components/RoleSelect/index.vue diff --git a/src/components/RoleSelect/index.vue b/src/components/RoleSelect/index.vue new file mode 100644 index 0000000..a9a07d3 --- /dev/null +++ b/src/components/RoleSelect/index.vue @@ -0,0 +1,199 @@ + + + From 34c0d2d277e28620f5facacf4c651eae84dd1eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=A1=A5?= Date: Fri, 2 Feb 2024 13:43:16 +0800 Subject: [PATCH 09/12] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=A2=84=E8=A7=88=E5=A4=A7=E5=86=99=E5=90=8E=E7=BC=80?= =?UTF-8?q?=E4=B8=8D=E5=B1=95=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/oss/index.vue | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/views/system/oss/index.vue b/src/views/system/oss/index.vue index 1cc582e..77c5dcd 100644 --- a/src/views/system/oss/index.vue +++ b/src/views/system/oss/index.vue @@ -197,11 +197,10 @@ const getList = async () => { loading.value = false; showTable.value = true; }; -function checkFileSuffix(fileSuffix: string[]) { - let arr = ['png', 'jpg', 'jpeg']; - return arr.some((type) => { - return fileSuffix.indexOf(type) > -1; - }); +function checkFileSuffix(fileSuffix: string | string[]) { + const arr = [".png", ".jpg", ".jpeg"]; + const suffixArray = Array.isArray(fileSuffix) ? fileSuffix : [fileSuffix]; + return suffixArray.some(suffix => arr.includes(suffix.toLowerCase())); } /** 取消按钮 */ function cancel() { From 5b991be4c2970376cdc47e92edcab307a914fc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=99=E5=A4=8F=E5=A4=A9=E4=BE=9D=E7=84=B6=E5=B9=B3?= =?UTF-8?q?=E5=87=A1?= <1822213252@qq.com> Date: Fri, 23 Feb 2024 07:23:20 +0000 Subject: [PATCH 10/12] =?UTF-8?q?!87=20=E4=BF=AE=E6=94=B9=20el-dialog=20?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=82=B9=E5=87=BB=E9=81=AE=E7=85=A7=E4=B8=BA?= =?UTF-8?q?=E4=B8=8D=E5=85=B3=E9=97=AD=20*=20update=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20el-dialog=20=E9=BB=98=E8=AE=A4=E7=82=B9=E5=87=BB=E9=81=AE?= =?UTF-8?q?=E7=85=A7=E4=B8=BA=E4=B8=8D=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.ts b/src/main.ts index f40059e..29a5ee5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,6 +32,10 @@ VXETable.config({ zIndex: 999999 }); +// 修改 el-dialog 默认点击遮照为不关闭 +import { ElDialog } from 'element-plus'; +ElDialog.props.closeOnClickModal.default = false; + const app = createApp(App); app.use(ElementIcons); From 5cb40abe18ff0d048b91460ed546bfa19c82e8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 4 Mar 2024 10:05:47 +0800 Subject: [PATCH 11/12] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=A0=A1=E9=AA=8C=E7=AD=96=E7=95=A5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=9D=9E=E6=B3=95=E5=AD=97=E7=AC=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/register.vue | 3 ++- src/views/system/user/index.vue | 10 ++++++++-- src/views/system/user/profile/resetPwd.vue | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/views/register.vue b/src/views/register.vue index 7f078c1..99ca62f 100644 --- a/src/views/register.vue +++ b/src/views/register.vue @@ -91,7 +91,8 @@ const registerRules: ElFormRules = { ], password: [ { required: true, trigger: 'blur', message: '请输入您的密码' }, - { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' } + { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }, + { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" } ], confirmPassword: [ { required: true, trigger: 'blur', message: '请再次输入您的密码' }, diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 3ea2864..dfbd789 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -395,7 +395,8 @@ const initData: PageData = { max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' - } + }, + { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" } ], email: [ { @@ -504,7 +505,12 @@ const handleResetPwd = async (row: UserVO) => { cancelButtonText: '取消', closeOnClickModal: false, inputPattern: /^.{5,20}$/, - inputErrorMessage: '用户密码长度必须介于 5 和 20 之间' + inputErrorMessage: '用户密码长度必须介于 5 和 20 之间', + inputValidator: (value) => { + if (/<|>|"|'|\||\\/.test(value)) { + return "不能包含非法字符:< > \" ' \\\ |" + } + } }) ); if (!err && res) { diff --git a/src/views/system/user/profile/resetPwd.vue b/src/views/system/user/profile/resetPwd.vue index 0a39fb1..6d536da 100644 --- a/src/views/system/user/profile/resetPwd.vue +++ b/src/views/system/user/profile/resetPwd.vue @@ -44,7 +44,8 @@ const rules = ref({ max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' - } + }, + { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" } ], confirmPassword: [ { required: true, message: '确认密码不能为空', trigger: 'blur' }, From 542f73f0e64b9cb4963a869e61d53993770912b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 4 Mar 2024 14:18:21 +0800 Subject: [PATCH 12/12] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=85=A8=E5=B1=80=E5=BC=80=E5=90=AF=E6=88=96=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=8E=A5=E5=8F=A3=E5=8A=A0=E5=AF=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 ++ .env.production | 2 ++ src/types/env.d.ts | 1 + src/utils/request.ts | 42 +++++++++++++++++++++++------------------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.env.development b/.env.development index 53ae057..ad47825 100644 --- a/.env.development +++ b/.env.development @@ -18,6 +18,8 @@ VITE_APP_POWERJOB_ADMIN = 'http://localhost:7700/' VITE_APP_PORT = 80 +# 接口加密功能开关(如需关闭 后端也必须对应关闭) +VITE_APP_ENCRYPT = true # 接口加密传输 RSA 公钥与后端解密私钥对应 如更换需前后端一同更换 VITE_APP_RSA_PUBLIC_KEY = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==' # 接口响应解密 RSA 私钥与后端加密公钥对应 如更换需前后端一同更换 diff --git a/.env.production b/.env.production index 0e3b9fc..c15308f 100644 --- a/.env.production +++ b/.env.production @@ -21,6 +21,8 @@ VITE_BUILD_COMPRESS = gzip VITE_APP_PORT = 80 +# 接口加密功能开关(如需关闭 后端也必须对应关闭) +VITE_APP_ENCRYPT = true # 接口加密传输 RSA 公钥与后端解密私钥对应 如更换需前后端一同更换 VITE_APP_RSA_PUBLIC_KEY = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==' # 接口响应解密 RSA 私钥与后端加密公钥对应 如更换需前后端一同更换 diff --git a/src/types/env.d.ts b/src/types/env.d.ts index 6667d05..5b18a8e 100644 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -14,6 +14,7 @@ interface ImportMetaEnv { VITE_APP_MONITRO_ADMIN: string; VITE_APP_POWERJOB_ADMIN: string; VITE_APP_ENV: string; + VITE_APP_ENCRYPT: string VITE_APP_RSA_PUBLIC_KEY: string; VITE_APP_RSA_PRIVATE_KEY: string; VITE_APP_CLIENT_ID: string; diff --git a/src/utils/request.ts b/src/utils/request.ts index 3de2076..f2a69f0 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -76,12 +76,14 @@ service.interceptors.request.use( } } } - // 当开启参数加密 - if (isEncrypt && (config.method === 'post' || config.method === 'put')) { - // 生成一个 AES 密钥 - const aesKey = generateAesKey(); - config.headers[encryptHeader] = encrypt(encryptBase64(aesKey)); - config.data = typeof config.data === 'object' ? encryptWithAes(JSON.stringify(config.data), aesKey) : encryptWithAes(config.data, aesKey); + if (import.meta.env.VITE_APP_ENCRYPT === 'true') { + // 当开启参数加密 + if (isEncrypt && (config.method === 'post' || config.method === 'put')) { + // 生成一个 AES 密钥 + const aesKey = generateAesKey(); + config.headers[encryptHeader] = encrypt(encryptBase64(aesKey)); + config.data = typeof config.data === 'object' ? encryptWithAes(JSON.stringify(config.data), aesKey) : encryptWithAes(config.data, aesKey); + } } // FormData数据去请求头Content-Type if (config.data instanceof FormData) { @@ -97,19 +99,21 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( (res: AxiosResponse) => { - // 加密后的 AES 秘钥 - const keyStr = res.headers[encryptHeader]; - // 加密 - if (keyStr != null && keyStr != '') { - const data = res.data; - // 请求体 AES 解密 - const base64Str = decrypt(keyStr); - // base64 解码 得到请求头的 AES 秘钥 - const aesKey = decryptBase64(base64Str.toString()); - // aesKey 解码 data - const decryptData = decryptWithAes(data, aesKey); - // 将结果 (得到的是 JSON 字符串) 转为 JSON - res.data = JSON.parse(decryptData); + if (import.meta.env.VITE_APP_ENCRYPT === 'true') { + // 加密后的 AES 秘钥 + const keyStr = res.headers[encryptHeader]; + // 加密 + if (keyStr != null && keyStr != '') { + const data = res.data; + // 请求体 AES 解密 + const base64Str = decrypt(keyStr); + // base64 解码 得到请求头的 AES 秘钥 + const aesKey = decryptBase64(base64Str.toString()); + // aesKey 解码 data + const decryptData = decryptWithAes(data, aesKey); + // 将结果 (得到的是 JSON 字符串) 转为 JSON + res.data = JSON.parse(decryptData); + } } // 未设置状态码则默认成功状态 const code = res.data.code || HttpStatus.SUCCESS;