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 @@
+
+
+
告警系统
+
WebSocket 已连接
+
WebSocket 连接中...
+
+
+
+
+
+
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 @@
-
+
修改
From 56d8178d32c41aed7fb4e0d94222169a0b7a5c5b Mon Sep 17 00:00:00 2001
From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com>
Date: Mon, 11 Nov 2024 11:55:02 +0800
Subject: [PATCH 08/14] =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=92=8C=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E5=AF=B9=E5=86=85=E7=BD=AE=E5=B1=9E=E6=80=A7=E8=BF=9B?=
=?UTF-8?q?=E8=A1=8C=E5=BC=80=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/system/config/index.vue | 6 +++---
src/views/system/role/index.vue | 2 +-
src/views/system/user/authRole.vue | 9 ++++++++-
src/views/system/user/index.vue | 4 ++--
4 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/views/system/config/index.vue b/src/views/system/config/index.vue
index 3ab81fc2..8b417468 100644
--- a/src/views/system/config/index.vue
+++ b/src/views/system/config/index.vue
@@ -151,16 +151,16 @@
-
+
-
+
-
+
-
+
-
+
{{(pageNum - 1) * pageSize + scope.$index + 1}}
@@ -113,5 +113,12 @@ export default {
this.$tab.closeOpenPage(obj);
},
},
+
+ computed: {
+ filteredRoles() {
+ // 超级管理员不允许分配给其他人
+ return this.roles.filter(role => role.roleId !== 1);
+ }
+ }
};
\ No newline at end of file
diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index e9879ca7..b11e3a6a 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -123,7 +123,7 @@
-
+
修改
@@ -244,7 +244,7 @@
:key="item.roleId"
:label="item.roleName"
:value="item.roleId"
- :disabled="item.status == 1"
+ :disabled="item.status == 1 || item.roleId === 1"
>
From ae4a12098792b1a0189616b1563651e454e40008 Mon Sep 17 00:00:00 2001
From: jiang
Date: Mon, 11 Nov 2024 13:42:53 +0800
Subject: [PATCH 09/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/layout/index.vue | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/layout/index.vue b/src/layout/index.vue
index 512fac59..8412aa25 100644
--- a/src/layout/index.vue
+++ b/src/layout/index.vue
@@ -103,7 +103,8 @@ export default {
sidebar: state => state.app.sidebar,
device: state => state.app.device,
needTagsView: state => state.settings.tagsView,
- fixedHeader: state => state.settings.fixedHeader
+ fixedHeader: state => state.settings.fixedHeader,
+ roles: state => state.user.roles,
}),
classObj() {
return {
@@ -119,7 +120,9 @@ export default {
},
created() {
this.checkPasswordStatus()
- this.connectWebSocket();
+ if (this.roles.includes("audit") || this.roles.includes("systemAdmin")) {
+ this.connectWebSocket();
+ }
},
methods: {
checkPasswordStatus() {
From 2ee58cefb02e8b8d07ff8a94f61cc8ee28a34380 Mon Sep 17 00:00:00 2001
From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com>
Date: Tue, 12 Nov 2024 10:53:58 +0800
Subject: [PATCH 10/14] =?UTF-8?q?tokentime=E7=9A=84=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E5=A4=A7=E5=B0=8F=E8=BF=9B=E8=A1=8C=E9=99=90=E5=88=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/layout/index.vue | 8 +++++---
src/views/system/config/index.vue | 5 +++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/layout/index.vue b/src/layout/index.vue
index 8412aa25..98c78ac8 100644
--- a/src/layout/index.vue
+++ b/src/layout/index.vue
@@ -81,7 +81,7 @@ export default {
]
},
socket: null,
- wsUrl: 'ws://localhost:18082/ws', // WebSocket 端点
+ wsUrl: JSON.parse(localStorage.getItem('systemConfig')).webSocketurl,//'ws://localhost:18082/ws', // WebSocket 端点
isConnected: false, // 连接状态
reconnectInterval: 5000 // 自动重连时间间隔(毫秒
@@ -120,7 +120,9 @@ export default {
},
created() {
this.checkPasswordStatus()
- if (this.roles.includes("audit") || this.roles.includes("systemAdmin")) {
+ console.log("*******************")
+ console.log(this.roles)
+ if (this.roles.includes("audit") || this.roles.includes("systemAdmin")|| this.roles.includes("admin")) {
this.connectWebSocket();
}
},
@@ -158,7 +160,7 @@ export default {
console.log("WebSocket 已连接");
return;
}
-
+ console.log("WebSocket URL:{}",this.wsUrl)
this.socket = new WebSocket(this.wsUrl);
// 监听 WebSocket 连接成功事件
diff --git a/src/views/system/config/index.vue b/src/views/system/config/index.vue
index 8b417468..19a6d9e4 100644
--- a/src/views/system/config/index.vue
+++ b/src/views/system/config/index.vue
@@ -300,6 +300,11 @@ export default {
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
+ if (this.form.configKey === "sys.visit.tokentime" && (this.form.configValue <=0 || this.form.configValue > 30 ))
+ {
+ this.$modal.msgError("系统访问token有效期必须在0-30分钟之间");
+ return;
+ }
if (this.form.configId != undefined) {
updateConfig(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
From 5691d366f9768d8be44cac4b6bf4e1bbac85a2ce Mon Sep 17 00:00:00 2001
From: weiweiw <14335254+weiweiw22@user.noreply.gitee.com>
Date: Tue, 12 Nov 2024 14:56:22 +0800
Subject: [PATCH 11/14] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E8=84=B1?=
=?UTF-8?q?=E6=95=8F=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/system/log.js | 6 +++
src/layout/index.vue | 66 +++++++++++++++++++++------------
src/views/system/user/index.vue | 11 +++++-
3 files changed, 58 insertions(+), 25 deletions(-)
diff --git a/src/api/system/log.js b/src/api/system/log.js
index fc3b90b2..37abfb25 100644
--- a/src/api/system/log.js
+++ b/src/api/system/log.js
@@ -92,6 +92,12 @@ export function getLogSize(data) {
})
}
+export function handleNoWarningLog(data) {
+ return request({
+ url: '/system/sys/sysLog/logWarn',
+ method: 'get'
+ })
+}
diff --git a/src/layout/index.vue b/src/layout/index.vue
index 98c78ac8..e3c246a1 100644
--- a/src/layout/index.vue
+++ b/src/layout/index.vue
@@ -25,10 +25,6 @@
-