|
@@ -32,16 +32,44 @@ const ExitModal: React.FC<ExitModalProps> = ({ visible, onClose }) => {
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
const handleExit = async (type: 'close' | 'logout' | 'shutdown') => {
|
|
|
+ // 对危险操作进行二次确认
|
|
|
+ const isDangerousOperation = type === 'shutdown' || type === 'logout';
|
|
|
+ if (isDangerousOperation) {
|
|
|
+ const confirmMessages = {
|
|
|
+ shutdown: {
|
|
|
+ title: '确认关机',
|
|
|
+ content: '确定要关闭系统吗?此操作将关闭计算机。',
|
|
|
+ },
|
|
|
+ logout: {
|
|
|
+ title: '确认注销',
|
|
|
+ content: '确定要注销当前用户吗?您将退出登录状态。',
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ const config = confirmMessages[type];
|
|
|
+
|
|
|
+ Modal.confirm({
|
|
|
+ title: config.title,
|
|
|
+ content: config.content,
|
|
|
+ okText: '确认',
|
|
|
+ cancelText: '取消',
|
|
|
+ centered: true,
|
|
|
+ onOk: async () => {
|
|
|
+ await executeAction(type);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 非危险操作直接执行
|
|
|
+ await executeAction(type);
|
|
|
+ };
|
|
|
+
|
|
|
+ const executeAction = async (type: 'close' | 'logout' | 'shutdown') => {
|
|
|
try {
|
|
|
let result;
|
|
|
let actionName = '';
|
|
|
|
|
|
- // 添加操作确认
|
|
|
- const isDangerousOperation = type === 'shutdown' || type === 'logout';
|
|
|
- if (isDangerousOperation) {
|
|
|
- // 这里可以添加二次确认逻辑,暂时省略,直接执行
|
|
|
- }
|
|
|
-
|
|
|
switch (type) {
|
|
|
case 'close':
|
|
|
actionName = '关闭程序';
|
|
@@ -62,13 +90,13 @@ const ExitModal: React.FC<ExitModalProps> = ({ visible, onClose }) => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (result.success) {
|
|
|
+ if (result && result.success) {
|
|
|
message.success(`${actionName}操作已执行`);
|
|
|
if (type === 'close') {
|
|
|
// 关闭程序操作会直接退出,不需要关闭弹框
|
|
|
return;
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if (result) {
|
|
|
// 处理不同类型的错误
|
|
|
if (result.requiresAdmin) {
|
|
|
message.warning({
|