From d92972ba3eead714d65fbbf2cf4a67ff51083547 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 21:38:46 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E7=9A=84=20confirm=20=E6=9B=BF=E6=8D=A2=20Modal.confirm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_core/profile/modules/user-social.vue | 22 +++++----- .../src/views/infra/apiErrorLog/index.vue | 21 ++++------ apps/web-antd/src/views/infra/file/index.vue | 3 +- .../src/views/infra/fileConfig/index.vue | 14 +++---- apps/web-antd/src/views/infra/job/index.vue | 34 ++++++---------- apps/web-antd/src/views/system/user/index.vue | 40 ++++++++----------- 6 files changed, 56 insertions(+), 78 deletions(-) diff --git a/apps/web-antd/src/views/_core/profile/modules/user-social.vue b/apps/web-antd/src/views/_core/profile/modules/user-social.vue index b44317af..62f3669a 100644 --- a/apps/web-antd/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-antd/src/views/_core/profile/modules/user-social.vue @@ -5,7 +5,9 @@ import type { SystemSocialUserApi } from '#/api/system/social/user'; import { computed, onMounted, ref } from 'vue'; 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 { socialAuthRedirect } from '#/api/core/auth'; @@ -102,19 +104,13 @@ const [Grid, gridApi] = useVbenVxeGrid({ /** 解绑账号 */ function onUnbind(row: SystemSocialUserApi.SocialUser) { - Modal.confirm({ - type: 'warning', - title: '提示', + confirm({ content: `确定解绑[${getDictLabel(DICT_TYPE.SYSTEM_SOCIAL_TYPE, row.type)}]平台的[${row.openid}]账号吗?`, - async onOk() { - await socialUnbind({ type: row.type, openid: row.openid }); - // 提示成功 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - await gridApi.reload(); - }, + }).then(async () => { + await socialUnbind({ type: row.type, openid: row.openid }); + // 提示成功 + message.success($t('ui.actionMessage.operationSuccess')); + await gridApi.reload(); }); } diff --git a/apps/web-antd/src/views/infra/apiErrorLog/index.vue b/apps/web-antd/src/views/infra/apiErrorLog/index.vue index c649090d..c8ee3736 100644 --- a/apps/web-antd/src/views/infra/apiErrorLog/index.vue +++ b/apps/web-antd/src/views/infra/apiErrorLog/index.vue @@ -5,11 +5,11 @@ import type { } from '#/adapter/vxe-table'; 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 { 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 { @@ -47,18 +47,13 @@ function onDetail(row: InfraApiErrorLogApi.ApiErrorLog) { /** 处理已处理 / 已忽略的操作 */ async function onProcess(id: number, processStatus: number) { - Modal.confirm({ - title: '确认操作', + confirm({ content: `确认标记为${InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'}?`, - onOk: async () => { - await updateApiErrorLogStatus(id, processStatus); - // 关闭并提示 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - onRefresh(); - }, + }).then(async () => { + await updateApiErrorLogStatus(id, processStatus); + // 关闭并提示 + message.success($t('ui.actionMessage.operationSuccess')); + onRefresh(); }); } diff --git a/apps/web-antd/src/views/infra/file/index.vue b/apps/web-antd/src/views/infra/file/index.vue index ac0ff543..5383a4dc 100644 --- a/apps/web-antd/src/views/infra/file/index.vue +++ b/apps/web-antd/src/views/infra/file/index.vue @@ -7,6 +7,7 @@ import type { InfraFileApi } from '#/api/infra/file'; import { Page, useVbenModal } from '@vben/common-ui'; import { Upload } from '@vben/icons'; +import { openWindow } from '@vben/utils'; import { useClipboard } from '@vueuse/core'; import { Button, Image, message } from 'ant-design-vue'; @@ -52,7 +53,7 @@ async function onCopyUrl(row: InfraFileApi.File) { /** 打开 URL */ function openUrl(url?: string) { if (url) { - window.open(url, '_blank'); + openWindow(url); } } diff --git a/apps/web-antd/src/views/infra/fileConfig/index.vue b/apps/web-antd/src/views/infra/fileConfig/index.vue index 5c8921ec..1db98faa 100644 --- a/apps/web-antd/src/views/infra/fileConfig/index.vue +++ b/apps/web-antd/src/views/infra/fileConfig/index.vue @@ -5,10 +5,11 @@ import type { } from '#/adapter/vxe-table'; 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 { 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 { @@ -72,14 +73,13 @@ async function onTest(row: InfraFileConfigApi.FileConfig) { const response = await testFileConfig(row.id as number); hideLoading(); // 确认是否访问该文件 - Modal.confirm({ + confirm({ title: '测试上传成功', content: '是否要访问该文件?', - okText: '访问', + confirmText: '访问', cancelText: '取消', - onOk: () => { - window.open(response, '_blank'); - }, + }).then(() => { + openWindow(response); }); } catch { hideLoading(); diff --git a/apps/web-antd/src/views/infra/job/index.vue b/apps/web-antd/src/views/infra/job/index.vue index 33036fc4..5d76addb 100644 --- a/apps/web-antd/src/views/infra/job/index.vue +++ b/apps/web-antd/src/views/infra/job/index.vue @@ -7,11 +7,11 @@ import type { InfraJobApi } from '#/api/infra/job'; 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 { 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 { @@ -74,32 +74,24 @@ async function onUpdateStatus(row: InfraJobApi.Job) { ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP; const statusText = status === InfraJobStatusEnum.NORMAL ? '启用' : '停用'; - Modal.confirm({ - title: '确认操作', + + confirm({ content: `确定${statusText} ${row.name} 吗?`, - onOk: async () => { - await updateJobStatus(row.id as number, status); - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - onRefresh(); - }, + }).then(async () => { + await updateJobStatus(row.id as number, status); + // 提示成功 + message.success($t('ui.actionMessage.operationSuccess')); + onRefresh(); }); } /** 执行一次任务 */ async function onTrigger(row: InfraJobApi.Job) { - Modal.confirm({ - title: '确认操作', + confirm({ content: `确定执行一次 ${row.name} 吗?`, - onOk: async () => { - await runJob(row.id as number); - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - }, + }).then(async () => { + await runJob(row.id as number); + message.success($t('ui.actionMessage.operationSuccess')); }); } diff --git a/apps/web-antd/src/views/system/user/index.vue b/apps/web-antd/src/views/system/user/index.vue index 1609b4bc..90dc7bd9 100644 --- a/apps/web-antd/src/views/system/user/index.vue +++ b/apps/web-antd/src/views/system/user/index.vue @@ -8,11 +8,11 @@ import type { SystemUserApi } from '#/api/system/user'; 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 { 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 { @@ -114,35 +114,29 @@ function onAssignRole(row: SystemUserApi.User) { assignRoleModalApi.setData(row).open(); } -// TODO @芋艿:后续怎么简化一下 confirm 的实现。 /** 更新用户状态 */ async function onStatusChange( newStatus: number, row: SystemUserApi.User, ): Promise { return new Promise((resolve, reject) => { - Modal.confirm({ - title: '切换状态', + confirm({ content: `你要将${row.username}的状态切换为【${getDictLabel(DICT_TYPE.COMMON_STATUS, newStatus)}】吗?`, - onCancel() { - reject(new Error('已取消')); - }, - onOk() { + }) + .then(async () => { // 更新用户状态 - updateUserStatus(row.id as number, newStatus) - .then(() => { - // 提示并返回成功 - message.success({ - content: $t('ui.actionMessage.operationSuccess'), - key: 'action_process_msg', - }); - resolve(true); - }) - .catch((error) => { - 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('取消操作')); + }); }); }