From 37113133ae9d3464b346d6f653e6e1e7e9766847 Mon Sep 17 00:00:00 2001 From: lbw Date: Mon, 13 Mar 2023 23:47:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin/menu.ts | 2 +- src/views/admin/audit/index.vue | 3 +- src/views/admin/client/form.vue | 44 ++----- src/views/admin/dept/form.vue | 32 ++--- src/views/admin/dict/dictItem/form.vue | 69 ++++------- src/views/admin/dict/dictItem/index.vue | 1 + src/views/admin/dict/form.vue | 69 ++++------- src/views/admin/dict/index.vue | 16 +-- src/views/admin/i18n/form.vue | 50 +++----- src/views/admin/log/detail.vue | 6 +- src/views/admin/menu/form.vue | 154 +++++++++--------------- src/views/admin/param/form.vue | 45 +++---- src/views/admin/post/form.vue | 45 +++---- src/views/admin/role/form.vue | 5 +- src/views/admin/role/permession.vue | 12 +- src/views/admin/user/form.vue | 6 +- 16 files changed, 196 insertions(+), 363 deletions(-) diff --git a/src/api/admin/menu.ts b/src/api/admin/menu.ts index c43eca14..ff25a1ec 100644 --- a/src/api/admin/menu.ts +++ b/src/api/admin/menu.ts @@ -23,7 +23,7 @@ export const save = (data: Object) => { }); }; -export const update = (data: Object) => { +export const putObj = (data: Object) => { return request({ url: '/admin/menu', method: 'put', diff --git a/src/views/admin/audit/index.vue b/src/views/admin/audit/index.vue index d4ceeb58..5053e828 100644 --- a/src/views/admin/audit/index.vue +++ b/src/views/admin/audit/index.vue @@ -84,13 +84,12 @@ const showSearch = ref(true); const selectObjs = ref([]) as any; const multiple = ref(true); +// table hook const state: BasicTableProps = reactive({ queryForm: {}, pageList: fetchList, descs: ['create_time'], }); - -// table hook const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state); // 清空搜索条件 diff --git a/src/views/admin/client/form.vue b/src/views/admin/client/form.vue index 30c03708..349d44eb 100644 --- a/src/views/admin/client/form.vue +++ b/src/views/admin/client/form.vue @@ -196,11 +196,8 @@ const dataRules = ref({ const openDialog = (id: string) => { visible.value = true; form.id = ''; - // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + dataFormRef.value?.resetFields(); // 获取sysOauthClientDetails信息 if (id) { @@ -210,35 +207,18 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; - // 更新 - if (form.id) { - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - } else { - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - } - }); + try { + form.id ? await putObj(form) : await addObj(form); + useMessage().success(t(form.id ? 'common.editSuccessText' : 'common.addSuccessText')); + visible.value = false; + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 初始化表单数据 diff --git a/src/views/admin/dept/form.vue b/src/views/admin/dept/form.vue index 9da6428a..e153d370 100644 --- a/src/views/admin/dept/form.vue +++ b/src/views/admin/dept/form.vue @@ -31,7 +31,7 @@ @@ -45,7 +45,6 @@ import { useMessage } from '/@/hooks/message'; // 定义子组件向父组件传值/事件 const emit = defineEmits(['refresh']); - // 定义变量内容 const deptDialogFormRef = ref(); const dataForm = reactive({ @@ -65,6 +64,14 @@ const dataRules = ref({ // 打开弹窗 const openDialog = (type: string, id: string) => { + visible.value = true; + dataForm.deptId = ''; + + nextTick(() => { + deptDialogFormRef.value?.resetFields(); + dataForm.parentId = id; + }); + if (type === 'edit') { getObj(id) .then((res) => { @@ -73,24 +80,11 @@ const openDialog = (type: string, id: string) => { .catch((err) => { useMessage().error(err.msg); }); - } else { - // 清空表单,此项需加表单验证才能使用 - nextTick(() => { - deptDialogFormRef?.value?.resetFields(); - dataForm.parentId = id; - }); } - visible.value = true; + getDeptData(); }; -// 关闭弹窗 -const closeDialog = () => { - visible.value = false; -}; -// 取消 -const onCancel = () => { - closeDialog(); -}; + // 提交 const onSubmit = () => { deptDialogFormRef.value.validate((valid: boolean) => { @@ -100,7 +94,7 @@ const onSubmit = () => { if (dataForm.deptId) { putObj(dataForm) .then(() => { - closeDialog(); // 关闭弹窗 + visible.value = false; // 关闭弹窗 emit('refresh'); }) .catch((err) => { @@ -109,7 +103,7 @@ const onSubmit = () => { } else { addObj(dataForm) .then(() => { - closeDialog(); // 关闭弹窗 + visible.value = false; // 关闭弹窗 emit('refresh'); }) .catch((err) => { diff --git a/src/views/admin/dict/dictItem/form.vue b/src/views/admin/dict/dictItem/form.vue index 3c14ca7b..8d14377d 100644 --- a/src/views/admin/dict/dictItem/form.vue +++ b/src/views/admin/dict/dictItem/form.vue @@ -37,7 +37,7 @@ @@ -46,11 +46,13 @@ - - diff --git a/src/views/admin/menu/form.vue b/src/views/admin/menu/form.vue index 6a2c9125..0361ce8e 100644 --- a/src/views/admin/menu/form.vue +++ b/src/views/admin/menu/form.vue @@ -3,7 +3,7 @@ - + 菜单 按钮 @@ -50,7 +50,7 @@ - + @@ -86,17 +86,19 @@