From 1d84c5db5577d875a1f07a6247d5b35824256d30 Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Thu, 7 Nov 2024 15:01:48 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E5=8A=9F=E8=83=BD=E5=92=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=20=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/log.js | 2 +- src/views/system/log/abnormalLog/index.vue | 4 ++-- src/views/system/log/businessLog/index.vue | 4 ++-- src/views/system/log/logAnalyse/index.vue | 1 + src/views/system/log/systemLog/index.vue | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api/system/log.js b/src/api/system/log.js index 80d6e06a..fc3b90b2 100644 --- a/src/api/system/log.js +++ b/src/api/system/log.js @@ -30,7 +30,7 @@ export function getSysLogs(data) { //备份系统日志列表 export function downloadSysLogs(data) { return request({ - url: '/sys/sysLog/downloadSysLogs', + url: '/system/sys/sysLog/downloadSysLogs', method: 'get', params: data, responseType: 'blob' diff --git a/src/views/system/log/abnormalLog/index.vue b/src/views/system/log/abnormalLog/index.vue index 0756171e..518fd7c2 100644 --- a/src/views/system/log/abnormalLog/index.vue +++ b/src/views/system/log/abnormalLog/index.vue @@ -39,9 +39,9 @@ 重置 - + 重置 - + 日志类型 操作类型 + 操作人 查询 diff --git a/src/views/system/log/systemLog/index.vue b/src/views/system/log/systemLog/index.vue index 1759d266..52abe27b 100644 --- a/src/views/system/log/systemLog/index.vue +++ b/src/views/system/log/systemLog/index.vue @@ -42,9 +42,9 @@ 重置 - + Date: Fri, 8 Nov 2024 10:27:51 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/configure.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/configure.js b/src/utils/configure.js index f3e168eb..2925eb16 100644 --- a/src/utils/configure.js +++ b/src/utils/configure.js @@ -21,9 +21,9 @@ export function generateUUID() { }); } -// 使用示例 -const uuid = generateUUID(); -console.log(uuid); +// // 使用示例 +// const uuid = generateUUID(); +// console.log(uuid); module.exports = { SM_CONFIG, AES_CONFIG, From 295174579e8936c01616efa85615eeaeb429676d Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Fri, 8 Nov 2024 10:35:39 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/configure.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/configure.js b/src/utils/configure.js index 2925eb16..1c966d84 100644 --- a/src/utils/configure.js +++ b/src/utils/configure.js @@ -1,5 +1,5 @@ // SM 配置 -const SM_CONFIG = { +export const SM_CONFIG = { SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值(16 字节) SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥 SM4_SALT:generateUUID(), @@ -7,7 +7,7 @@ const SM_CONFIG = { SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥 } // AES 配置 -const AES_CONFIG = { +export const AES_CONFIG = { AES_KEY: 'zhgd@bonus@zhgd@bonus@1234567890', // AES key值 AES_IV: '1234567812345678' // AES 偏移量 } @@ -24,7 +24,7 @@ export function generateUUID() { // // 使用示例 // const uuid = generateUUID(); // console.log(uuid); -module.exports = { - SM_CONFIG, - AES_CONFIG, -} +// module.exports = { +// SM_CONFIG, +// AES_CONFIG, +// } From b6fd43084e2faf80f5ee04c3db66d56ed4e234dc Mon Sep 17 00:00:00 2001 From: jiang Date: Fri, 8 Nov 2024 10:51:14 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 2 +- src/views/system/user/index.vue | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index c4b397e5..d7ba1333 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -8,7 +8,7 @@ import cache from '@/plugins/cache' import { saveAs } from 'file-saver' import { encryptCBC, decryptCBC } from '@/utils/aescbc' import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' -const systemConfig = { +const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || { requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false } }; diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index ba4e99ee..ffa6dc26 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -583,7 +583,7 @@ export default { handleCommand(command, row) { switch (command) { case 'handleResetPwd': - this.handleResetPwd(row) + this.confirmResetPwd(row) break case 'handleAuthRole': this.handleAuthRole(row) @@ -653,6 +653,32 @@ export default { }).catch(() => { }) }, + confirmResetPwd(row){ + this.$prompt('请输入密码,鉴别用户', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + closeOnClickModal: false, + inputPattern: /^.{8,16}$/, + inputErrorMessage: '用户密码长度必须介于 8 和 16 之间', + inputValidator: (value) => { + // 调用 validateNewPassword 校验 + const errorMessage=function(error) { + if (error) { + return error.message; + } else { + console.log('验证通过'); + } + }; + validateNewPassword(null, value, errorMessage); + } + }).then(({ value }) => { + confirmPassword(value).then(response => { + this.$modal.msgSuccess('验证成功') + this.handleResetPwd(row) + }) + }).catch(() => { + }) + }, /** 重置密码按钮操作 */ handleResetPwd(row) { this.$prompt('请输入"' + row.userName + '"的新密码', '提示', { From 68f09fcb7d00d3a58ee827f8457328c29e489df7 Mon Sep 17 00:00:00 2001 From: jiang Date: Fri, 8 Nov 2024 15:01:17 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/configure.js | 9 +-------- src/utils/request.js | 3 ++- src/utils/sm.js | 8 ++------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/utils/configure.js b/src/utils/configure.js index 1c966d84..6e26ee8a 100644 --- a/src/utils/configure.js +++ b/src/utils/configure.js @@ -2,7 +2,7 @@ export const SM_CONFIG = { SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值(16 字节) SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥 - SM4_SALT:generateUUID(), + SM4_SALT:"f555adf6c01d0ab0761e626a2dae34a2", SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥 SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥 } @@ -21,10 +21,3 @@ export function generateUUID() { }); } -// // 使用示例 -// const uuid = generateUUID(); -// console.log(uuid); -// module.exports = { -// SM_CONFIG, -// AES_CONFIG, -// } diff --git a/src/utils/request.js b/src/utils/request.js index d7ba1333..7d2be68e 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -6,7 +6,6 @@ import errorCode from '@/utils/errorCode' import { tansParams, blobValidate } from '@/utils/bonus' import cache from '@/plugins/cache' import { saveAs } from 'file-saver' -import { encryptCBC, decryptCBC } from '@/utils/aescbc' import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || { requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false } @@ -66,6 +65,8 @@ service.interceptors.request.use(config => { if (contentType.includes('application/json') && typeof data !== 'undefined') { // 加密数据 if (systemConfig.requestConfig.encryptRequest && encryptRequest) { + console.log(data); + console.log(hashWithSM3AndSalt(data)); config.data = encryptWithSM4(data+"|"+hashWithSM3AndSalt(data)) } } diff --git a/src/utils/sm.js b/src/utils/sm.js index 9d8c15c4..8ed7008b 100644 --- a/src/utils/sm.js +++ b/src/utils/sm.js @@ -36,8 +36,7 @@ export function decryptWithSM2(encryptedText) { * @returns {string} 加密后的密文(Hex 编码格式) */ export function encryptWithSM4(plainText) { - const salt =SM_CONFIG.SM4_SALT - return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:salt})+salt; + return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:SM_CONFIG.SM4_SALT}); } /** @@ -46,9 +45,6 @@ export function encryptWithSM4(plainText) { * @returns {string} 解密后的明文 */ export function decryptWithSM4(cipherText){ - const length = cipherText.length; - const salt = length > 32 ? cipherText.substring(length - 32) : cipherText; - const originalHex = length > 32 ? cipherText.substring(0, length - 32) : ''; - return SM4.decrypt(originalHex, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5' ,iv:salt}); + return SM4.decrypt(cipherText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5' ,iv:SM_CONFIG.SM4_SALT}); } From daff010eb7aac5960602d0d5a4d11ad5bf3f4415 Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Sun, 10 Nov 2024 08:55:36 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/App.vue | 1 + src/layout/index.vue | 102 ++++++++++++++++++- src/views/warning/AlertNotification.vue | 126 ++++++++++++++++++++++++ 4 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 src/views/warning/AlertNotification.vue diff --git a/package.json b/package.json index 0b43c319..434db7e3 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "vue-meta": "2.4.0", "vue-router": "3.4.9", "vuedraggable": "2.24.3", - "vuex": "3.6.0" + "vuex": "3.6.0", + "webstomp-client": "^1.2.6" }, "devDependencies": { "@vue/cli-plugin-babel": "4.4.6", diff --git a/src/App.vue b/src/App.vue index 97626af5..e8b1f8b7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,6 +9,7 @@ import ThemePicker from "@/components/ThemePicker"; import { mapActions } from 'vuex' import { get } from '@/utils/config' +// import AlertNotification from "@/views/warning/AlertNotification.vue"; export default { name: "App", diff --git a/src/layout/index.vue b/src/layout/index.vue index 26f9ebf7..02e87b23 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -46,6 +46,7 @@ import { mapState } from 'vuex' import variables from '@/assets/styles/variables.scss' import { validateNewPassword } from '@/utils/validate' import { updateUserPwd, checkPasswordStatus } from '@/api/system/user' +import {MessageBox} from "element-ui"; export default { name: 'Layout', @@ -78,7 +79,12 @@ export default { { required: true, message: '确认密码不能为空', trigger: 'blur' }, { required: true, validator: equalToPassword, trigger: 'blur' } ] - } + }, + socket: null, + wsUrl: 'ws://localhost:18082/ws', // WebSocket 端点 + isConnected: false, // 连接状态 + reconnectInterval: 5000 // 自动重连时间间隔(毫秒 + } }, components: { @@ -113,6 +119,7 @@ export default { }, created() { this.checkPasswordStatus() + this.connectWebSocket(); }, methods: { checkPasswordStatus() { @@ -140,7 +147,100 @@ export default { this.$store.dispatch('LogOut').then(() => { location.href = '/index'; }) + }, + + // 连接 WebSocket + connectWebSocket() { + if (this.socket) { + console.log("WebSocket 已连接"); + return; + } + + this.socket = new WebSocket(this.wsUrl); + + // 监听 WebSocket 连接成功事件 + this.socket.onopen = () => { + console.log("WebSocket 连接成功"); + this.isConnected = true; + }; + + // 接收消息 + this.socket.onmessage = (event) => { + console.log("收到消息:", event.data); + const warning = JSON.parse(event.data); + this.handleWarning(warning); + }; + + // 监听连接关闭事件 + this.socket.onclose = () => { + console.log("WebSocket 连接已关闭"); + this.isConnected = false; + this.socket = null; + // 自动重连 + this.reconnectWebSocket(); + }; + + // 监听连接错误事件 + this.socket.onerror = (error) => { + console.error("WebSocket 错误:", error); + this.isConnected = false; + this.socket = null; + // 自动重连 + this.reconnectWebSocket(); + }; + }, + + // 自动重连 WebSocket + reconnectWebSocket() { + console.log("尝试重新连接 WebSocket..."); + setTimeout(() => { + this.connectWebSocket(); + }, this.reconnectInterval); + }, + + // 处理告警信息并显示弹窗 + handleWarning(warning) { + console.log(warning) + const formattedTime = new Date(warning.warningTime).toLocaleString(); + + // 弹出告警信息 + MessageBox.alert( + ` +

事件:${warning.warningEvent}

+

内容:${warning.warningContent}

+

等级:${warning.warningGrade}

+

IP:${warning.warningIp}

+

时间:${formattedTime}

+ `, + '告警通知', + { + dangerouslyUseHTMLString: true, + confirmButtonText: '确认', + callback: () => { + this.notifyBackend(warning.warningId); + } + } + ); + }, + + // 通知后端告警已处理 + notifyBackend(warningId) { + if (this.socket && this.socket.readyState === WebSocket.OPEN) { + const message = { + warningId, + status: '1' // 1 表示已处理 + }; + this.socket.send(JSON.stringify(message)); + console.log(`已通知后端处理告警: ${warningId}`); + } } + }, + beforeDestroy() { + // 页面销毁时关闭 WebSocket 连接 + if (this.socket) { + this.socket.close(); + } + } } diff --git a/src/views/warning/AlertNotification.vue b/src/views/warning/AlertNotification.vue new file mode 100644 index 00000000..c583e09b --- /dev/null +++ b/src/views/warning/AlertNotification.vue @@ -0,0 +1,126 @@ + + + + + From 2d898be6c4f1f7adf5b57e06042b3c29526640fd Mon Sep 17 00:00:00 2001 From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com> Date: Mon, 11 Nov 2024 09:49:34 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/index.vue | 11 ++++------- src/views/system/user/index.vue | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/layout/index.vue b/src/layout/index.vue index 02e87b23..512fac59 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -201,16 +201,14 @@ export default { // 处理告警信息并显示弹窗 handleWarning(warning) { console.log(warning) - const formattedTime = new Date(warning.warningTime).toLocaleString(); - + // const formattedTime = new Date(warning.warningTime).toLocaleString(); // 弹出告警信息 MessageBox.alert( ` +

操作人:${warning.operaUserName}

事件:${warning.warningEvent}

-

内容:${warning.warningContent}

-

等级:${warning.warningGrade}

IP:${warning.warningIp}

-

时间:${formattedTime}

+

时间:${warning.warningTime}

`, '告警通知', { @@ -228,9 +226,8 @@ export default { if (this.socket && this.socket.readyState === WebSocket.OPEN) { const message = { warningId, - status: '1' // 1 表示已处理 }; - this.socket.send(JSON.stringify(message)); + this.socket.send(warningId); console.log(`已通知后端处理告警: ${warningId}`); } } diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index ffa6dc26..e9879ca7 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -123,7 +123,7 @@ -