perf: 使用封装的 confirm 替换 Modal.confirm

pull/90/MERGE
xingyu4j 2025-05-06 21:38:46 +08:00
parent b724ca2917
commit d92972ba3e
6 changed files with 56 additions and 78 deletions

View File

@ -5,7 +5,9 @@ import type { SystemSocialUserApi } from '#/api/system/social/user';
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { Button, Card, Image, message, Modal } from 'ant-design-vue'; import { confirm } from '@vben/common-ui';
import { Button, Card, Image, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { socialAuthRedirect } from '#/api/core/auth'; import { socialAuthRedirect } from '#/api/core/auth';
@ -102,19 +104,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
/** 解绑账号 */ /** 解绑账号 */
function onUnbind(row: SystemSocialUserApi.SocialUser) { function onUnbind(row: SystemSocialUserApi.SocialUser) {
Modal.confirm({ confirm({
type: 'warning',
title: '提示',
content: `确定解绑[${getDictLabel(DICT_TYPE.SYSTEM_SOCIAL_TYPE, row.type)}]平台的[${row.openid}]账号吗?`, content: `确定解绑[${getDictLabel(DICT_TYPE.SYSTEM_SOCIAL_TYPE, row.type)}]平台的[${row.openid}]账号吗?`,
async onOk() { }).then(async () => {
await socialUnbind({ type: row.type, openid: row.openid }); await socialUnbind({ type: row.type, openid: row.openid });
// //
message.success({ message.success($t('ui.actionMessage.operationSuccess'));
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
await gridApi.reload(); await gridApi.reload();
},
}); });
} }

View File

@ -5,11 +5,11 @@ import type {
} from '#/adapter/vxe-table'; } from '#/adapter/vxe-table';
import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log'; import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log';
import { Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { Download } from '@vben/icons'; import { Download } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message, Modal } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@ -47,18 +47,13 @@ function onDetail(row: InfraApiErrorLogApi.ApiErrorLog) {
/** 处理已处理 / 已忽略的操作 */ /** 处理已处理 / 已忽略的操作 */
async function onProcess(id: number, processStatus: number) { async function onProcess(id: number, processStatus: number) {
Modal.confirm({ confirm({
title: '确认操作',
content: `确认标记为${InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'}?`, content: `确认标记为${InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'}?`,
onOk: async () => { }).then(async () => {
await updateApiErrorLogStatus(id, processStatus); await updateApiErrorLogStatus(id, processStatus);
// //
message.success({ message.success($t('ui.actionMessage.operationSuccess'));
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
onRefresh(); onRefresh();
},
}); });
} }

View File

@ -7,6 +7,7 @@ import type { InfraFileApi } from '#/api/infra/file';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { Upload } from '@vben/icons'; import { Upload } from '@vben/icons';
import { openWindow } from '@vben/utils';
import { useClipboard } from '@vueuse/core'; import { useClipboard } from '@vueuse/core';
import { Button, Image, message } from 'ant-design-vue'; import { Button, Image, message } from 'ant-design-vue';
@ -52,7 +53,7 @@ async function onCopyUrl(row: InfraFileApi.File) {
/** 打开 URL */ /** 打开 URL */
function openUrl(url?: string) { function openUrl(url?: string) {
if (url) { if (url) {
window.open(url, '_blank'); openWindow(url);
} }
} }

View File

@ -5,10 +5,11 @@ import type {
} from '#/adapter/vxe-table'; } from '#/adapter/vxe-table';
import type { InfraFileConfigApi } from '#/api/infra/file-config'; import type { InfraFileConfigApi } from '#/api/infra/file-config';
import { Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { Plus } from '@vben/icons'; import { Plus } from '@vben/icons';
import { openWindow } from '@vben/utils';
import { Button, message, Modal } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@ -72,14 +73,13 @@ async function onTest(row: InfraFileConfigApi.FileConfig) {
const response = await testFileConfig(row.id as number); const response = await testFileConfig(row.id as number);
hideLoading(); hideLoading();
// 访 // 访
Modal.confirm({ confirm({
title: '测试上传成功', title: '测试上传成功',
content: '是否要访问该文件?', content: '是否要访问该文件?',
okText: '访问', confirmText: '访问',
cancelText: '取消', cancelText: '取消',
onOk: () => { }).then(() => {
window.open(response, '_blank'); openWindow(response);
},
}); });
} catch { } catch {
hideLoading(); hideLoading();

View File

@ -7,11 +7,11 @@ import type { InfraJobApi } from '#/api/infra/job';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { Download, History, Plus } from '@vben/icons'; import { Download, History, Plus } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message, Modal } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@ -74,32 +74,24 @@ async function onUpdateStatus(row: InfraJobApi.Job) {
? InfraJobStatusEnum.NORMAL ? InfraJobStatusEnum.NORMAL
: InfraJobStatusEnum.STOP; : InfraJobStatusEnum.STOP;
const statusText = status === InfraJobStatusEnum.NORMAL ? '启用' : '停用'; const statusText = status === InfraJobStatusEnum.NORMAL ? '启用' : '停用';
Modal.confirm({
title: '确认操作', confirm({
content: `确定${statusText} ${row.name} 吗?`, content: `确定${statusText} ${row.name} 吗?`,
onOk: async () => { }).then(async () => {
await updateJobStatus(row.id as number, status); await updateJobStatus(row.id as number, status);
message.success({ //
content: $t('ui.actionMessage.operationSuccess'), message.success($t('ui.actionMessage.operationSuccess'));
key: 'action_process_msg',
});
onRefresh(); onRefresh();
},
}); });
} }
/** 执行一次任务 */ /** 执行一次任务 */
async function onTrigger(row: InfraJobApi.Job) { async function onTrigger(row: InfraJobApi.Job) {
Modal.confirm({ confirm({
title: '确认操作',
content: `确定执行一次 ${row.name} 吗?`, content: `确定执行一次 ${row.name} 吗?`,
onOk: async () => { }).then(async () => {
await runJob(row.id as number); await runJob(row.id as number);
message.success({ message.success($t('ui.actionMessage.operationSuccess'));
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
},
}); });
} }

View File

@ -8,11 +8,11 @@ import type { SystemUserApi } from '#/api/system/user';
import { ref } from 'vue'; import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { Download, Plus, Upload } from '@vben/icons'; import { Download, Plus, Upload } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
import { Button, message, Modal } from 'ant-design-vue'; import { Button, message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@ -114,34 +114,28 @@ function onAssignRole(row: SystemUserApi.User) {
assignRoleModalApi.setData(row).open(); assignRoleModalApi.setData(row).open();
} }
// TODO @ confirm
/** 更新用户状态 */ /** 更新用户状态 */
async function onStatusChange( async function onStatusChange(
newStatus: number, newStatus: number,
row: SystemUserApi.User, row: SystemUserApi.User,
): Promise<boolean | undefined> { ): Promise<boolean | undefined> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Modal.confirm({ confirm({
title: '切换状态',
content: `你要将${row.username}的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`, content: `你要将${row.username}的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`,
onCancel() {
reject(new Error('已取消'));
},
onOk() {
//
updateUserStatus(row.id as number, newStatus)
.then(() => {
//
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_process_msg',
});
resolve(true);
}) })
.catch((error) => { .then(async () => {
reject(error); //
}); const res = await updateUserStatus(row.id as number, newStatus);
}, if (res) {
//
message.success($t('ui.actionMessage.operationSuccess'));
resolve(true);
} else {
reject(new Error('更新失败'));
}
})
.catch(() => {
reject(new Error('取消操作'));
}); });
}); });
} }