From 1179ca1a8aab3340ca678f2b8dbdcb8bbf3c76ea Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 21 Jul 2022 17:42:25 +0800 Subject: [PATCH] feat: add message hook --- .../src/hooks/web/useMessage.ts | 71 +++++++++++++++++++ .../src/views/infra/apiErrorLog/index.vue | 12 ++-- .../src/views/infra/codegen/index.vue | 17 +++-- .../src/views/infra/fileConfig/index.vue | 15 ++-- .../src/views/infra/job/index.vue | 22 +++--- .../src/views/system/dept/index.vue | 13 ++-- .../src/views/system/menu/index.vue | 21 +++--- .../src/views/system/user/index.vue | 36 ++++------ 8 files changed, 128 insertions(+), 79 deletions(-) create mode 100644 yudao-ui-admin-vue3/src/hooks/web/useMessage.ts diff --git a/yudao-ui-admin-vue3/src/hooks/web/useMessage.ts b/yudao-ui-admin-vue3/src/hooks/web/useMessage.ts new file mode 100644 index 000000000..b5e3960aa --- /dev/null +++ b/yudao-ui-admin-vue3/src/hooks/web/useMessage.ts @@ -0,0 +1,71 @@ +import { ElMessage, ElMessageBox, ElNotification } from 'element-plus' +import { useI18n } from './useI18n' +export const useMessage = () => { + const { t } = useI18n() + return { + // 消息提示 + info(content: string) { + ElMessage.info(content) + }, + // 错误消息 + error(content: string) { + ElMessage.error(content) + }, + // 成功消息 + success(content: string) { + ElMessage.success(content) + }, + // 警告消息 + warning(content: string) { + ElMessage.warning(content) + }, + // 弹出提示 + alert(content: string) { + ElMessageBox.alert(content, t('common.confirmTitle')) + }, + // 错误提示 + alertError(content: string) { + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'error' }) + }, + // 成功提示 + alertSuccess(content: string) { + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'success' }) + }, + // 警告提示 + alertWarning(content: string) { + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'warning' }) + }, + // 通知提示 + notify(content: string) { + ElNotification.info(content) + }, + // 错误通知 + notifyError(content: string) { + ElNotification.error(content) + }, + // 成功通知 + notifySuccess(content: string) { + ElNotification.success(content) + }, + // 警告通知 + notifyWarning(content: string) { + ElNotification.warning(content) + }, + // 确认窗体 + confirm(content: string, tip: string) { + return ElMessageBox.confirm(content, tip, { + confirmButtonText: t('common.ok'), + cancelButtonText: t('common.cancel'), + type: 'warning' + }) + }, + // 提交内容 + prompt(content: string, tip: string) { + return ElMessageBox.prompt(content, tip, { + confirmButtonText: t('common.ok'), + cancelButtonText: t('common.cancel'), + type: 'warning' + }) + } + } +} diff --git a/yudao-ui-admin-vue3/src/views/infra/apiErrorLog/index.vue b/yudao-ui-admin-vue3/src/views/infra/apiErrorLog/index.vue index 0ef921d3d..bf7dbaedf 100644 --- a/yudao-ui-admin-vue3/src/views/infra/apiErrorLog/index.vue +++ b/yudao-ui-admin-vue3/src/views/infra/apiErrorLog/index.vue @@ -8,7 +8,8 @@ import type { ApiErrorLogVO } from '@/api/infra/apiErrorLog/types' import { allSchemas } from './apiErrorLog.data' import * as ApiErrorLogApi from '@/api/infra/apiErrorLog' import { InfraApiErrorLogProcessStatusEnum } from '@/utils/constants' -import { ElMessage, ElMessageBox } from 'element-plus' +import { useMessage } from '@/hooks/web/useMessage' +const message = useMessage() const { t } = useI18n() // 国际化 // ========== 列表相关 ========== @@ -36,14 +37,11 @@ const handleDetail = (row: ApiErrorLogVO) => { } // 异常处理操作 const handleProcessClick = (row: ApiErrorLogVO, processSttatus: number, type: string) => { - ElMessageBox.confirm('确认标记为' + type + '?', t('common.reminder'), { - confirmButtonText: t('common.ok'), - cancelButtonText: t('common.cancel'), - type: 'warning' - }) + message + .confirm('确认标记为' + type + '?', t('common.reminder')) .then(async () => { ApiErrorLogApi.updateApiErrorLogPageApi(row.id, processSttatus).then(() => { - ElMessage.success(t('common.updateSuccess')) + message.success(t('common.updateSuccess')) getList() }) }) diff --git a/yudao-ui-admin-vue3/src/views/infra/codegen/index.vue b/yudao-ui-admin-vue3/src/views/infra/codegen/index.vue index 827b232fd..215f79e9b 100644 --- a/yudao-ui-admin-vue3/src/views/infra/codegen/index.vue +++ b/yudao-ui-admin-vue3/src/views/infra/codegen/index.vue @@ -10,7 +10,8 @@ import ImportTable from './components/ImportTable.vue' import Preview from './components/Preview.vue' import download from '@/utils/download' import { useRouter } from 'vue-router' -import { ElMessage, ElMessageBox } from 'element-plus' +import { useMessage } from '@/hooks/web/useMessage' +const message = useMessage() const { t } = useI18n() // 国际化 const { push } = useRouter() // ========== 列表相关 ========== @@ -37,14 +38,12 @@ const handleEditTable = (row: CodegenTableVO) => { const handleSynchDb = (row: CodegenTableVO) => { // 基于 DB 同步 const tableName = row.tableName - ElMessageBox.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'), { - confirmButtonText: t('common.ok'), - cancelButtonText: t('common.cancel'), - type: 'warning' - }).then(async () => { - await CodegenApi.syncCodegenFromDBApi(row.id) - ElMessage.success('同步成功') - }) + message + .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder')) + .then(async () => { + await CodegenApi.syncCodegenFromDBApi(row.id) + message.success('同步成功') + }) } // 生成代码操作 const handleGenTable = (row: CodegenTableVO) => { diff --git a/yudao-ui-admin-vue3/src/views/infra/fileConfig/index.vue b/yudao-ui-admin-vue3/src/views/infra/fileConfig/index.vue index 86313f902..1c49c173c 100644 --- a/yudao-ui-admin-vue3/src/views/infra/fileConfig/index.vue +++ b/yudao-ui-admin-vue3/src/views/infra/fileConfig/index.vue @@ -1,7 +1,6 @@