Commit 1179ca1a8aab3340ca678f2b8dbdcb8bbf3c76ea
1 parent
0cb6dd58
feat: add message hook
Showing
8 changed files
with
128 additions
and
79 deletions
yudao-ui-admin-vue3/src/hooks/web/useMessage.ts
0 → 100644
| 1 | +import { ElMessage, ElMessageBox, ElNotification } from 'element-plus' | ||
| 2 | +import { useI18n } from './useI18n' | ||
| 3 | +export const useMessage = () => { | ||
| 4 | + const { t } = useI18n() | ||
| 5 | + return { | ||
| 6 | + // 消息提示 | ||
| 7 | + info(content: string) { | ||
| 8 | + ElMessage.info(content) | ||
| 9 | + }, | ||
| 10 | + // 错误消息 | ||
| 11 | + error(content: string) { | ||
| 12 | + ElMessage.error(content) | ||
| 13 | + }, | ||
| 14 | + // 成功消息 | ||
| 15 | + success(content: string) { | ||
| 16 | + ElMessage.success(content) | ||
| 17 | + }, | ||
| 18 | + // 警告消息 | ||
| 19 | + warning(content: string) { | ||
| 20 | + ElMessage.warning(content) | ||
| 21 | + }, | ||
| 22 | + // 弹出提示 | ||
| 23 | + alert(content: string) { | ||
| 24 | + ElMessageBox.alert(content, t('common.confirmTitle')) | ||
| 25 | + }, | ||
| 26 | + // 错误提示 | ||
| 27 | + alertError(content: string) { | ||
| 28 | + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'error' }) | ||
| 29 | + }, | ||
| 30 | + // 成功提示 | ||
| 31 | + alertSuccess(content: string) { | ||
| 32 | + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'success' }) | ||
| 33 | + }, | ||
| 34 | + // 警告提示 | ||
| 35 | + alertWarning(content: string) { | ||
| 36 | + ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'warning' }) | ||
| 37 | + }, | ||
| 38 | + // 通知提示 | ||
| 39 | + notify(content: string) { | ||
| 40 | + ElNotification.info(content) | ||
| 41 | + }, | ||
| 42 | + // 错误通知 | ||
| 43 | + notifyError(content: string) { | ||
| 44 | + ElNotification.error(content) | ||
| 45 | + }, | ||
| 46 | + // 成功通知 | ||
| 47 | + notifySuccess(content: string) { | ||
| 48 | + ElNotification.success(content) | ||
| 49 | + }, | ||
| 50 | + // 警告通知 | ||
| 51 | + notifyWarning(content: string) { | ||
| 52 | + ElNotification.warning(content) | ||
| 53 | + }, | ||
| 54 | + // 确认窗体 | ||
| 55 | + confirm(content: string, tip: string) { | ||
| 56 | + return ElMessageBox.confirm(content, tip, { | ||
| 57 | + confirmButtonText: t('common.ok'), | ||
| 58 | + cancelButtonText: t('common.cancel'), | ||
| 59 | + type: 'warning' | ||
| 60 | + }) | ||
| 61 | + }, | ||
| 62 | + // 提交内容 | ||
| 63 | + prompt(content: string, tip: string) { | ||
| 64 | + return ElMessageBox.prompt(content, tip, { | ||
| 65 | + confirmButtonText: t('common.ok'), | ||
| 66 | + cancelButtonText: t('common.cancel'), | ||
| 67 | + type: 'warning' | ||
| 68 | + }) | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | +} |
yudao-ui-admin-vue3/src/views/infra/apiErrorLog/index.vue
| @@ -8,7 +8,8 @@ import type { ApiErrorLogVO } from '@/api/infra/apiErrorLog/types' | @@ -8,7 +8,8 @@ import type { ApiErrorLogVO } from '@/api/infra/apiErrorLog/types' | ||
| 8 | import { allSchemas } from './apiErrorLog.data' | 8 | import { allSchemas } from './apiErrorLog.data' |
| 9 | import * as ApiErrorLogApi from '@/api/infra/apiErrorLog' | 9 | import * as ApiErrorLogApi from '@/api/infra/apiErrorLog' |
| 10 | import { InfraApiErrorLogProcessStatusEnum } from '@/utils/constants' | 10 | import { InfraApiErrorLogProcessStatusEnum } from '@/utils/constants' |
| 11 | -import { ElMessage, ElMessageBox } from 'element-plus' | 11 | +import { useMessage } from '@/hooks/web/useMessage' |
| 12 | +const message = useMessage() | ||
| 12 | const { t } = useI18n() // 国际化 | 13 | const { t } = useI18n() // 国际化 |
| 13 | 14 | ||
| 14 | // ========== 列表相关 ========== | 15 | // ========== 列表相关 ========== |
| @@ -36,14 +37,11 @@ const handleDetail = (row: ApiErrorLogVO) => { | @@ -36,14 +37,11 @@ const handleDetail = (row: ApiErrorLogVO) => { | ||
| 36 | } | 37 | } |
| 37 | // 异常处理操作 | 38 | // 异常处理操作 |
| 38 | const handleProcessClick = (row: ApiErrorLogVO, processSttatus: number, type: string) => { | 39 | const handleProcessClick = (row: ApiErrorLogVO, processSttatus: number, type: string) => { |
| 39 | - ElMessageBox.confirm('确认标记为' + type + '?', t('common.reminder'), { | ||
| 40 | - confirmButtonText: t('common.ok'), | ||
| 41 | - cancelButtonText: t('common.cancel'), | ||
| 42 | - type: 'warning' | ||
| 43 | - }) | 40 | + message |
| 41 | + .confirm('确认标记为' + type + '?', t('common.reminder')) | ||
| 44 | .then(async () => { | 42 | .then(async () => { |
| 45 | ApiErrorLogApi.updateApiErrorLogPageApi(row.id, processSttatus).then(() => { | 43 | ApiErrorLogApi.updateApiErrorLogPageApi(row.id, processSttatus).then(() => { |
| 46 | - ElMessage.success(t('common.updateSuccess')) | 44 | + message.success(t('common.updateSuccess')) |
| 47 | getList() | 45 | getList() |
| 48 | }) | 46 | }) |
| 49 | }) | 47 | }) |
yudao-ui-admin-vue3/src/views/infra/codegen/index.vue
| @@ -10,7 +10,8 @@ import ImportTable from './components/ImportTable.vue' | @@ -10,7 +10,8 @@ import ImportTable from './components/ImportTable.vue' | ||
| 10 | import Preview from './components/Preview.vue' | 10 | import Preview from './components/Preview.vue' |
| 11 | import download from '@/utils/download' | 11 | import download from '@/utils/download' |
| 12 | import { useRouter } from 'vue-router' | 12 | import { useRouter } from 'vue-router' |
| 13 | -import { ElMessage, ElMessageBox } from 'element-plus' | 13 | +import { useMessage } from '@/hooks/web/useMessage' |
| 14 | +const message = useMessage() | ||
| 14 | const { t } = useI18n() // 国际化 | 15 | const { t } = useI18n() // 国际化 |
| 15 | const { push } = useRouter() | 16 | const { push } = useRouter() |
| 16 | // ========== 列表相关 ========== | 17 | // ========== 列表相关 ========== |
| @@ -37,14 +38,12 @@ const handleEditTable = (row: CodegenTableVO) => { | @@ -37,14 +38,12 @@ const handleEditTable = (row: CodegenTableVO) => { | ||
| 37 | const handleSynchDb = (row: CodegenTableVO) => { | 38 | const handleSynchDb = (row: CodegenTableVO) => { |
| 38 | // 基于 DB 同步 | 39 | // 基于 DB 同步 |
| 39 | const tableName = row.tableName | 40 | const tableName = row.tableName |
| 40 | - ElMessageBox.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'), { | ||
| 41 | - confirmButtonText: t('common.ok'), | ||
| 42 | - cancelButtonText: t('common.cancel'), | ||
| 43 | - type: 'warning' | ||
| 44 | - }).then(async () => { | ||
| 45 | - await CodegenApi.syncCodegenFromDBApi(row.id) | ||
| 46 | - ElMessage.success('同步成功') | ||
| 47 | - }) | 41 | + message |
| 42 | + .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder')) | ||
| 43 | + .then(async () => { | ||
| 44 | + await CodegenApi.syncCodegenFromDBApi(row.id) | ||
| 45 | + message.success('同步成功') | ||
| 46 | + }) | ||
| 48 | } | 47 | } |
| 49 | // 生成代码操作 | 48 | // 生成代码操作 |
| 50 | const handleGenTable = (row: CodegenTableVO) => { | 49 | const handleGenTable = (row: CodegenTableVO) => { |
yudao-ui-admin-vue3/src/views/infra/fileConfig/index.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { ref, unref } from 'vue' | 2 | import { ref, unref } from 'vue' |
| 3 | import dayjs from 'dayjs' | 3 | import dayjs from 'dayjs' |
| 4 | -import { ElMessage, ElMessageBox } from 'element-plus' | ||
| 5 | import { DICT_TYPE } from '@/utils/dict' | 4 | import { DICT_TYPE } from '@/utils/dict' |
| 6 | import { useTable } from '@/hooks/web/useTable' | 5 | import { useTable } from '@/hooks/web/useTable' |
| 7 | import { useI18n } from '@/hooks/web/useI18n' | 6 | import { useI18n } from '@/hooks/web/useI18n' |
| @@ -9,6 +8,8 @@ import { FormExpose } from '@/components/Form' | @@ -9,6 +8,8 @@ import { FormExpose } from '@/components/Form' | ||
| 9 | import type { FileConfigVO } from '@/api/infra/fileConfig/types' | 8 | import type { FileConfigVO } from '@/api/infra/fileConfig/types' |
| 10 | import { rules, allSchemas } from './fileConfig.data' | 9 | import { rules, allSchemas } from './fileConfig.data' |
| 11 | import * as FileConfigApi from '@/api/infra/fileConfig' | 10 | import * as FileConfigApi from '@/api/infra/fileConfig' |
| 11 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 12 | +const message = useMessage() | ||
| 12 | const { t } = useI18n() // 国际化 | 13 | const { t } = useI18n() // 国际化 |
| 13 | 14 | ||
| 14 | // ========== 列表相关 ========== | 15 | // ========== 列表相关 ========== |
| @@ -49,16 +50,12 @@ const handleUpdate = async (row: FileConfigVO) => { | @@ -49,16 +50,12 @@ const handleUpdate = async (row: FileConfigVO) => { | ||
| 49 | 50 | ||
| 50 | // 主配置操作 | 51 | // 主配置操作 |
| 51 | const handleMaster = (row: FileConfigVO) => { | 52 | const handleMaster = (row: FileConfigVO) => { |
| 52 | - ElMessageBox.confirm('是否确认修改配置【 ' + row.name + ' 】为主配置?', t('common.reminder'), { | ||
| 53 | - confirmButtonText: t('common.ok'), | ||
| 54 | - cancelButtonText: t('common.cancel'), | ||
| 55 | - type: 'warning' | ||
| 56 | - }) | 53 | + message |
| 54 | + .confirm('是否确认修改配置【 ' + row.name + ' 】为主配置?', t('common.reminder')) | ||
| 57 | .then(async () => { | 55 | .then(async () => { |
| 58 | await FileConfigApi.updateFileConfigMasterApi(row.id) | 56 | await FileConfigApi.updateFileConfigMasterApi(row.id) |
| 59 | await getList() | 57 | await getList() |
| 60 | }) | 58 | }) |
| 61 | - .catch(() => {}) | ||
| 62 | } | 59 | } |
| 63 | 60 | ||
| 64 | // 提交按钮 | 61 | // 提交按钮 |
| @@ -69,10 +66,10 @@ const submitForm = async () => { | @@ -69,10 +66,10 @@ const submitForm = async () => { | ||
| 69 | const data = unref(formRef)?.formModel as FileConfigVO | 66 | const data = unref(formRef)?.formModel as FileConfigVO |
| 70 | if (actionType.value === 'create') { | 67 | if (actionType.value === 'create') { |
| 71 | await FileConfigApi.createFileConfigApi(data) | 68 | await FileConfigApi.createFileConfigApi(data) |
| 72 | - ElMessage.success(t('common.createSuccess')) | 69 | + message.success(t('common.createSuccess')) |
| 73 | } else { | 70 | } else { |
| 74 | await FileConfigApi.updateFileConfigApi(data) | 71 | await FileConfigApi.updateFileConfigApi(data) |
| 75 | - ElMessage.success(t('common.updateSuccess')) | 72 | + message.success(t('common.updateSuccess')) |
| 76 | } | 73 | } |
| 77 | // 操作成功,重新加载列表 | 74 | // 操作成功,重新加载列表 |
| 78 | dialogVisible.value = false | 75 | dialogVisible.value = false |
yudao-ui-admin-vue3/src/views/infra/job/index.vue
| @@ -9,8 +9,9 @@ import { useTable } from '@/hooks/web/useTable' | @@ -9,8 +9,9 @@ import { useTable } from '@/hooks/web/useTable' | ||
| 9 | import { useI18n } from '@/hooks/web/useI18n' | 9 | import { useI18n } from '@/hooks/web/useI18n' |
| 10 | import { FormExpose } from '@/components/Form' | 10 | import { FormExpose } from '@/components/Form' |
| 11 | import { rules, allSchemas } from './job.data' | 11 | import { rules, allSchemas } from './job.data' |
| 12 | -import { ElMessage, ElMessageBox } from 'element-plus' | ||
| 13 | import { useRouter } from 'vue-router' | 12 | import { useRouter } from 'vue-router' |
| 13 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 14 | +const message = useMessage() | ||
| 14 | const { t } = useI18n() // 国际化 | 15 | const { t } = useI18n() // 国际化 |
| 15 | const { push } = useRouter() | 16 | const { push } = useRouter() |
| 16 | // ========== 列表相关 ========== | 17 | // ========== 列表相关 ========== |
| @@ -64,18 +65,11 @@ const handleJobLog = (row: JobVO) => { | @@ -64,18 +65,11 @@ const handleJobLog = (row: JobVO) => { | ||
| 64 | } | 65 | } |
| 65 | // 执行一次 | 66 | // 执行一次 |
| 66 | const handleRun = (row: JobVO) => { | 67 | const handleRun = (row: JobVO) => { |
| 67 | - ElMessageBox.confirm('确认要立即执行一次' + row.name + '?', t('common.reminder'), { | ||
| 68 | - confirmButtonText: t('common.ok'), | ||
| 69 | - cancelButtonText: t('common.cancel'), | ||
| 70 | - type: 'warning' | 68 | + message.confirm('确认要立即执行一次' + row.name + '?', t('common.reminder')).then(async () => { |
| 69 | + await JobApi.runJobApi(row.id) | ||
| 70 | + message.success('执行成功') | ||
| 71 | + getList() | ||
| 71 | }) | 72 | }) |
| 72 | - .then(async () => { | ||
| 73 | - JobApi.runJobApi(row.id).then(() => { | ||
| 74 | - ElMessage.success('执行成功') | ||
| 75 | - getList() | ||
| 76 | - }) | ||
| 77 | - }) | ||
| 78 | - .catch(() => {}) | ||
| 79 | } | 73 | } |
| 80 | // 提交按钮 | 74 | // 提交按钮 |
| 81 | const submitForm = async () => { | 75 | const submitForm = async () => { |
| @@ -85,10 +79,10 @@ const submitForm = async () => { | @@ -85,10 +79,10 @@ const submitForm = async () => { | ||
| 85 | const data = unref(formRef)?.formModel as JobVO | 79 | const data = unref(formRef)?.formModel as JobVO |
| 86 | if (actionType.value === 'create') { | 80 | if (actionType.value === 'create') { |
| 87 | await JobApi.createJobApi(data) | 81 | await JobApi.createJobApi(data) |
| 88 | - ElMessage.success(t('common.createSuccess')) | 82 | + message.success(t('common.createSuccess')) |
| 89 | } else { | 83 | } else { |
| 90 | await JobApi.updateJobApi(data) | 84 | await JobApi.updateJobApi(data) |
| 91 | - ElMessage.success(t('common.updateSuccess')) | 85 | + message.success(t('common.updateSuccess')) |
| 92 | } | 86 | } |
| 93 | // 操作成功,重新加载列表 | 87 | // 操作成功,重新加载列表 |
| 94 | dialogVisible.value = false | 88 | dialogVisible.value = false |
yudao-ui-admin-vue3/src/views/system/dept/index.vue
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { useI18n } from '@/hooks/web/useI18n' | 2 | import { useI18n } from '@/hooks/web/useI18n' |
| 3 | -import { ElInput, ElCard, ElTree, ElTreeSelect, ElMessage, ElMessageBox } from 'element-plus' | 3 | +import { ElInput, ElCard, ElTree, ElTreeSelect } from 'element-plus' |
| 4 | import { handleTree } from '@/utils/tree' | 4 | import { handleTree } from '@/utils/tree' |
| 5 | import { onMounted, ref, unref, watch } from 'vue' | 5 | import { onMounted, ref, unref, watch } from 'vue' |
| 6 | import * as DeptApi from '@/api/system/dept' | 6 | import * as DeptApi from '@/api/system/dept' |
| 7 | import { Form, FormExpose } from '@/components/Form' | 7 | import { Form, FormExpose } from '@/components/Form' |
| 8 | import { modelSchema } from './dept.data' | 8 | import { modelSchema } from './dept.data' |
| 9 | import { DeptVO } from '@/api/system/dept/types' | 9 | import { DeptVO } from '@/api/system/dept/types' |
| 10 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 11 | +const message = useMessage() | ||
| 10 | interface Tree { | 12 | interface Tree { |
| 11 | id: number | 13 | id: number |
| 12 | name: string | 14 | name: string |
| @@ -60,14 +62,11 @@ const handleUpdate = async (data: { id: number }) => { | @@ -60,14 +62,11 @@ const handleUpdate = async (data: { id: number }) => { | ||
| 60 | } | 62 | } |
| 61 | // 删除 | 63 | // 删除 |
| 62 | const handleDelete = async (data: { id: number }) => { | 64 | const handleDelete = async (data: { id: number }) => { |
| 63 | - ElMessageBox.confirm(t('common.delDataMessage'), t('common.confirmTitle'), { | ||
| 64 | - confirmButtonText: t('common.ok'), | ||
| 65 | - cancelButtonText: t('common.cancel'), | ||
| 66 | - type: 'warning' | ||
| 67 | - }) | 65 | + message |
| 66 | + .confirm(t('common.delDataMessage'), t('common.confirmTitle')) | ||
| 68 | .then(async () => { | 67 | .then(async () => { |
| 69 | await DeptApi.deleteDeptApi(data.id) | 68 | await DeptApi.deleteDeptApi(data.id) |
| 70 | - ElMessage.success(t('common.delSuccess')) | 69 | + message.success(t('common.delSuccess')) |
| 71 | }) | 70 | }) |
| 72 | .catch(() => {}) | 71 | .catch(() => {}) |
| 73 | await getTree() | 72 | await getTree() |
yudao-ui-admin-vue3/src/views/system/menu/index.vue
| @@ -18,14 +18,14 @@ import { | @@ -18,14 +18,14 @@ import { | ||
| 18 | ElSelect, | 18 | ElSelect, |
| 19 | ElTreeSelect, | 19 | ElTreeSelect, |
| 20 | ElOption, | 20 | ElOption, |
| 21 | - ElMessageBox, | ||
| 22 | - ElMessage, | ||
| 23 | ElRadioGroup, | 21 | ElRadioGroup, |
| 24 | ElRadioButton | 22 | ElRadioButton |
| 25 | } from 'element-plus' | 23 | } from 'element-plus' |
| 26 | import { MenuVO } from '@/api/system/menu/types' | 24 | import { MenuVO } from '@/api/system/menu/types' |
| 27 | import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants' | 25 | import { SystemMenuTypeEnum, CommonStatusEnum } from '@/utils/constants' |
| 28 | import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' | 26 | import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
| 27 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 28 | +const message = useMessage() | ||
| 29 | const { t } = useI18n() // 国际化 | 29 | const { t } = useI18n() // 国际化 |
| 30 | // ========== 创建菜单树结构 ========== | 30 | // ========== 创建菜单树结构 ========== |
| 31 | const loading = ref(true) | 31 | const loading = ref(true) |
| @@ -111,14 +111,11 @@ const handleUpdate = async (row: MenuVO) => { | @@ -111,14 +111,11 @@ const handleUpdate = async (row: MenuVO) => { | ||
| 111 | } | 111 | } |
| 112 | // 删除操作 | 112 | // 删除操作 |
| 113 | const handleDelete = async (row: MenuVO) => { | 113 | const handleDelete = async (row: MenuVO) => { |
| 114 | - ElMessageBox.confirm(t('common.delDataMessage'), t('common.confirmTitle'), { | ||
| 115 | - confirmButtonText: t('common.ok'), | ||
| 116 | - cancelButtonText: t('common.cancel'), | ||
| 117 | - type: 'warning' | ||
| 118 | - }) | 114 | + message |
| 115 | + .confirm(t('common.delDataMessage'), t('common.confirmTitle')) | ||
| 119 | .then(async () => { | 116 | .then(async () => { |
| 120 | await MenuApi.deleteMenuApi(row.id) | 117 | await MenuApi.deleteMenuApi(row.id) |
| 121 | - ElMessage.success(t('common.delSuccess')) | 118 | + message.success(t('common.delSuccess')) |
| 122 | }) | 119 | }) |
| 123 | .catch(() => {}) | 120 | .catch(() => {}) |
| 124 | await getList() | 121 | await getList() |
| @@ -137,20 +134,20 @@ const submitForm = async () => { | @@ -137,20 +134,20 @@ const submitForm = async () => { | ||
| 137 | ) { | 134 | ) { |
| 138 | if (!isExternal(menuForm.value.path)) { | 135 | if (!isExternal(menuForm.value.path)) { |
| 139 | if (menuForm.value.parentId === 0 && menuForm.value.path.charAt(0) !== '/') { | 136 | if (menuForm.value.parentId === 0 && menuForm.value.path.charAt(0) !== '/') { |
| 140 | - ElMessage.error('路径必须以 / 开头') | 137 | + message.error('路径必须以 / 开头') |
| 141 | return | 138 | return |
| 142 | } else if (menuForm.value.parentId !== 0 && menuForm.value.path.charAt(0) === '/') { | 139 | } else if (menuForm.value.parentId !== 0 && menuForm.value.path.charAt(0) === '/') { |
| 143 | - ElMessage.error('路径不能以 / 开头') | 140 | + message.error('路径不能以 / 开头') |
| 144 | return | 141 | return |
| 145 | } | 142 | } |
| 146 | } | 143 | } |
| 147 | } | 144 | } |
| 148 | if (actionType.value === 'create') { | 145 | if (actionType.value === 'create') { |
| 149 | await MenuApi.createMenuApi(menuForm.value) | 146 | await MenuApi.createMenuApi(menuForm.value) |
| 150 | - ElMessage.success(t('common.createSuccess')) | 147 | + message.success(t('common.createSuccess')) |
| 151 | } else { | 148 | } else { |
| 152 | await MenuApi.updateMenuApi(menuForm.value) | 149 | await MenuApi.updateMenuApi(menuForm.value) |
| 153 | - ElMessage.success(t('common.updateSuccess')) | 150 | + message.success(t('common.updateSuccess')) |
| 154 | } | 151 | } |
| 155 | // 操作成功,重新加载列表 | 152 | // 操作成功,重新加载列表 |
| 156 | dialogVisible.value = false | 153 | dialogVisible.value = false |
yudao-ui-admin-vue3/src/views/system/user/index.vue
| @@ -3,7 +3,6 @@ import { onMounted, ref, unref, watch } from 'vue' | @@ -3,7 +3,6 @@ import { onMounted, ref, unref, watch } from 'vue' | ||
| 3 | import dayjs from 'dayjs' | 3 | import dayjs from 'dayjs' |
| 4 | import { | 4 | import { |
| 5 | ElInput, | 5 | ElInput, |
| 6 | - ElMessage, | ||
| 7 | ElCard, | 6 | ElCard, |
| 8 | ElTree, | 7 | ElTree, |
| 9 | ElTreeSelect, | 8 | ElTreeSelect, |
| @@ -14,7 +13,6 @@ import { | @@ -14,7 +13,6 @@ import { | ||
| 14 | ElUpload, | 13 | ElUpload, |
| 15 | ElSwitch, | 14 | ElSwitch, |
| 16 | ElCheckbox, | 15 | ElCheckbox, |
| 17 | - ElMessageBox, | ||
| 18 | UploadInstance, | 16 | UploadInstance, |
| 19 | UploadRawFile | 17 | UploadRawFile |
| 20 | } from 'element-plus' | 18 | } from 'element-plus' |
| @@ -32,6 +30,8 @@ import * as UserApi from '@/api/system/user' | @@ -32,6 +30,8 @@ import * as UserApi from '@/api/system/user' | ||
| 32 | import download from '@/utils/download' | 30 | import download from '@/utils/download' |
| 33 | import { CommonStatusEnum } from '@/utils/constants' | 31 | import { CommonStatusEnum } from '@/utils/constants' |
| 34 | import { getAccessToken, getTenantId } from '@/utils/auth' | 32 | import { getAccessToken, getTenantId } from '@/utils/auth' |
| 33 | +import { useMessage } from '@/hooks/web/useMessage' | ||
| 34 | +const message = useMessage() | ||
| 35 | interface Tree { | 35 | interface Tree { |
| 36 | id: number | 36 | id: number |
| 37 | name: string | 37 | name: string |
| @@ -127,10 +127,10 @@ const submitForm = async () => { | @@ -127,10 +127,10 @@ const submitForm = async () => { | ||
| 127 | data.postIds = postIds.value | 127 | data.postIds = postIds.value |
| 128 | if (actionType.value === 'create') { | 128 | if (actionType.value === 'create') { |
| 129 | await UserApi.createUserApi(data) | 129 | await UserApi.createUserApi(data) |
| 130 | - ElMessage.success(t('common.createSuccess')) | 130 | + message.success(t('common.createSuccess')) |
| 131 | } else { | 131 | } else { |
| 132 | await UserApi.updateUserApi(data) | 132 | await UserApi.updateUserApi(data) |
| 133 | - ElMessage.success(t('common.updateSuccess')) | 133 | + message.success(t('common.updateSuccess')) |
| 134 | } | 134 | } |
| 135 | // 操作成功,重新加载列表 | 135 | // 操作成功,重新加载列表 |
| 136 | dialogVisible.value = false | 136 | dialogVisible.value = false |
| @@ -142,16 +142,13 @@ const submitForm = async () => { | @@ -142,16 +142,13 @@ const submitForm = async () => { | ||
| 142 | // 改变用户状态操作 | 142 | // 改变用户状态操作 |
| 143 | const handleStatusChange = async (row: UserVO) => { | 143 | const handleStatusChange = async (row: UserVO) => { |
| 144 | const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用' | 144 | const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用' |
| 145 | - ElMessageBox.confirm('确认要"' + text + '""' + row.username + '"用户吗?', t('common.reminder'), { | ||
| 146 | - confirmButtonText: t('common.ok'), | ||
| 147 | - cancelButtonText: t('common.cancel'), | ||
| 148 | - type: 'warning' | ||
| 149 | - }) | 145 | + message |
| 146 | + .confirm('确认要"' + text + '""' + row.username + '"用户吗?', t('common.reminder')) | ||
| 150 | .then(async () => { | 147 | .then(async () => { |
| 151 | row.status = | 148 | row.status = |
| 152 | row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.ENABLE : CommonStatusEnum.DISABLE | 149 | row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.ENABLE : CommonStatusEnum.DISABLE |
| 153 | await UserApi.updateUserStatusApi(row.id, row.status) | 150 | await UserApi.updateUserStatusApi(row.id, row.status) |
| 154 | - ElMessage.success(text + '成功') | 151 | + message.success(text + '成功') |
| 155 | await getList() | 152 | await getList() |
| 156 | }) | 153 | }) |
| 157 | .catch(() => { | 154 | .catch(() => { |
| @@ -161,12 +158,9 @@ const handleStatusChange = async (row: UserVO) => { | @@ -161,12 +158,9 @@ const handleStatusChange = async (row: UserVO) => { | ||
| 161 | } | 158 | } |
| 162 | // 重置密码 | 159 | // 重置密码 |
| 163 | const handleResetPwd = (row: UserVO) => { | 160 | const handleResetPwd = (row: UserVO) => { |
| 164 | - ElMessageBox.prompt('请输入"' + row.username + '"的新密码', t('common.reminder'), { | ||
| 165 | - confirmButtonText: t('common.ok'), | ||
| 166 | - cancelButtonText: t('common.cancel') | ||
| 167 | - }).then(({ value }) => { | 161 | + message.prompt('请输入"' + row.username + '"的新密码', t('common.reminder')).then(({ value }) => { |
| 168 | UserApi.resetUserPwdApi(row.id, value).then(() => { | 162 | UserApi.resetUserPwdApi(row.id, value).then(() => { |
| 169 | - ElMessage.success('修改成功,新密码是:' + value) | 163 | + message.success('修改成功,新密码是:' + value) |
| 170 | }) | 164 | }) |
| 171 | }) | 165 | }) |
| 172 | } | 166 | } |
| @@ -207,8 +201,8 @@ const beforeExcelUpload = (file: UploadRawFile) => { | @@ -207,8 +201,8 @@ const beforeExcelUpload = (file: UploadRawFile) => { | ||
| 207 | file.type === 'application/vnd.ms-excel' || | 201 | file.type === 'application/vnd.ms-excel' || |
| 208 | file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 202 | file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
| 209 | const isLt5M = file.size / 1024 / 1024 < 5 | 203 | const isLt5M = file.size / 1024 / 1024 < 5 |
| 210 | - if (!isExcel) ElMessage.error('上传文件只能是 xls / xlsx 格式!') | ||
| 211 | - if (!isLt5M) ElMessage.error('上传文件大小不能超过 5MB!') | 204 | + if (!isExcel) message.error('上传文件只能是 xls / xlsx 格式!') |
| 205 | + if (!isLt5M) message.error('上传文件大小不能超过 5MB!') | ||
| 212 | return isExcel && isLt5M | 206 | return isExcel && isLt5M |
| 213 | } | 207 | } |
| 214 | // 文件上传 | 208 | // 文件上传 |
| @@ -224,7 +218,7 @@ const submitFileForm = () => { | @@ -224,7 +218,7 @@ const submitFileForm = () => { | ||
| 224 | // 文件上传成功 | 218 | // 文件上传成功 |
| 225 | const handleFileSuccess = (response: any): void => { | 219 | const handleFileSuccess = (response: any): void => { |
| 226 | if (response.code !== 0) { | 220 | if (response.code !== 0) { |
| 227 | - ElMessage.error(response.msg) | 221 | + message.error(response.msg) |
| 228 | return | 222 | return |
| 229 | } | 223 | } |
| 230 | importDialogVisible.value = false | 224 | importDialogVisible.value = false |
| @@ -242,15 +236,15 @@ const handleFileSuccess = (response: any): void => { | @@ -242,15 +236,15 @@ const handleFileSuccess = (response: any): void => { | ||
| 242 | for (const username in data.failureUsernames) { | 236 | for (const username in data.failureUsernames) { |
| 243 | text += '< ' + username + ': ' + data.failureUsernames[username] + ' >' | 237 | text += '< ' + username + ': ' + data.failureUsernames[username] + ' >' |
| 244 | } | 238 | } |
| 245 | - ElMessageBox.alert(text) | 239 | + message.alert(text) |
| 246 | } | 240 | } |
| 247 | // 文件数超出提示 | 241 | // 文件数超出提示 |
| 248 | const handleExceed = (): void => { | 242 | const handleExceed = (): void => { |
| 249 | - ElMessage.error('最多只能上传一个文件!') | 243 | + message.error('最多只能上传一个文件!') |
| 250 | } | 244 | } |
| 251 | // 上传错误提示 | 245 | // 上传错误提示 |
| 252 | const excelUploadError = (): void => { | 246 | const excelUploadError = (): void => { |
| 253 | - ElMessage.error('导入数据失败,请您重新上传!') | 247 | + message.error('导入数据失败,请您重新上传!') |
| 254 | } | 248 | } |
| 255 | // ========== 初始化 ========== | 249 | // ========== 初始化 ========== |
| 256 | onMounted(async () => { | 250 | onMounted(async () => { |