From b03696ad78378cbe176ec8378b1d99fd1e8fcf30 Mon Sep 17 00:00:00 2001 From: lbw Date: Wed, 15 Mar 2023 17:55:30 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactoring=20code.=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin/i18n.ts | 1 - src/api/gen/datasource.ts | 5 +- src/components/DictTag/index.vue | 8 +- src/components/Pagination/index.vue | 2 +- src/components/QueryTree/index.vue | 3 + src/components/TreeSelect/index.vue | 26 ++++ src/components/Upload/Excel.vue | 29 +++- src/components/Upload/Image.vue | 7 +- src/components/Upload/index.vue | 14 +- src/hooks/table.ts | 133 +++++++++++++------ src/i18n/index.ts | 7 +- src/layout/lockScreen/index.vue | 33 +++-- src/stores/dict.ts | 65 +++++---- src/stores/msg.ts | 2 - src/stores/userInfo.ts | 54 +++++++- src/utils/other.ts | 20 ++- src/utils/request.ts | 90 +++++++------ src/views/admin/audit/index.vue | 33 +++-- src/views/admin/client/form.vue | 4 +- src/views/admin/client/index.vue | 32 +++-- src/views/admin/dept/form.vue | 39 ++---- src/views/admin/dept/index.vue | 49 +++---- src/views/admin/dict/dictItem/index.vue | 28 ++-- src/views/admin/dict/index.vue | 43 +++--- src/views/admin/file/form.vue | 2 - src/views/admin/file/index.vue | 31 +++-- src/views/admin/i18n/index.vue | 31 +++-- src/views/admin/log/detail.vue | 3 +- src/views/admin/log/index.vue | 48 ++++--- src/views/admin/menu/index.vue | 34 ++--- src/views/admin/param/index.vue | 40 +++--- src/views/admin/post/index.vue | 31 +++-- src/views/admin/role/index.vue | 31 +++-- src/views/admin/role/permession.vue | 19 +-- src/views/admin/social/form.vue | 54 +++----- src/views/admin/social/index.vue | 31 +++-- src/views/admin/tenant/form.vue | 48 +++---- src/views/admin/tenant/index.vue | 31 +++-- src/views/admin/tenant/tenantMenu/form.vue | 73 +++------- src/views/admin/tenant/tenantMenu/index.vue | 29 ++-- src/views/admin/token/i18n/en.ts | 2 + src/views/admin/token/i18n/zh-cn.ts | 2 + src/views/admin/token/index.vue | 37 +++--- src/views/admin/user/form.vue | 61 ++++----- src/views/admin/user/i18n/en.ts | 1 + src/views/admin/user/i18n/zh-cn.ts | 49 +++---- src/views/admin/user/index.vue | 55 ++++---- src/views/app/appmenu/form.vue | 140 ++++++++------------ src/views/app/appmenu/index.vue | 59 ++++----- src/views/app/approle/form.vue | 56 ++------ src/views/app/approle/index.vue | 42 +++--- src/views/app/approle/permession.vue | 20 +-- src/views/app/appsocial/form.vue | 54 +++----- src/views/app/appsocial/index.vue | 42 +++--- src/views/app/appuser/form.vue | 104 +++++++-------- src/views/app/appuser/index.vue | 43 +++--- src/views/daemon/job-manage/form.vue | 45 ++----- src/views/daemon/job-manage/index.vue | 25 ++-- src/views/daemon/job-manage/job-log.vue | 31 +++-- src/views/gen/datasource/form.vue | 51 +++---- src/views/gen/datasource/index.vue | 41 +++--- src/views/gen/design/form.vue | 29 ++-- src/views/gen/design/index.vue | 40 +++--- src/views/gen/field-type/form.vue | 6 +- src/views/gen/field-type/index.vue | 40 +++--- src/views/gen/gener/index.vue | 3 +- src/views/gen/group/form.vue | 13 +- src/views/gen/group/index.vue | 32 +++-- src/views/gen/table/preview.vue | 4 + src/views/gen/template/form.vue | 7 +- src/views/gen/template/index.vue | 32 +++-- src/views/home/current-user.vue | 30 +++-- src/views/home/schedule/calendar.vue | 2 +- src/views/home/schedule/form.vue | 56 +++----- src/views/home/schedule/index.vue | 55 ++++---- src/views/login/component/mobile.vue | 26 ++-- src/views/login/component/register.vue | 30 ++--- src/views/mp/wx-account-fans/index.vue | 6 +- src/views/mp/wx-account-tag/index.vue | 2 +- src/views/mp/wx-account/index.vue | 2 +- src/views/oa/leave_bill/form.vue | 53 +++----- src/views/oa/leave_bill/index.vue | 65 ++++----- src/views/oa/model/form.vue | 54 +++----- src/views/oa/model/index.vue | 35 +++-- src/views/oa/process/index.vue | 61 +++++---- src/views/oa/task/comment.vue | 4 +- src/views/oa/task/form.vue | 61 ++++----- src/views/oa/task/index.vue | 32 +++-- src/views/pay/cd/index.vue | 24 +++- src/views/pay/channel/form.vue | 79 +++++------ src/views/pay/channel/index.vue | 32 +++-- src/views/pay/order/form.vue | 75 ++++------- src/views/pay/order/index.vue | 32 +++-- src/views/pay/record/index.vue | 32 +++-- src/views/pay/refund/index.vue | 32 +++-- src/views/pay/trade/form.vue | 69 ++++------ src/views/pay/trade/index.vue | 32 +++-- src/views/pay/trade/refund.vue | 53 ++++---- vite.config.ts | 49 ++++--- 99 files changed, 1658 insertions(+), 1854 deletions(-) diff --git a/src/api/admin/i18n.ts b/src/api/admin/i18n.ts index de42bbe1..cced3211 100644 --- a/src/api/admin/i18n.ts +++ b/src/api/admin/i18n.ts @@ -1,5 +1,4 @@ import request from '/@/utils/request'; -import { getObjDetails } from '/@/api/admin/param'; export function fetchList(query?: Object) { return request({ diff --git a/src/api/gen/datasource.ts b/src/api/gen/datasource.ts index 26ef8174..7e90360c 100644 --- a/src/api/gen/datasource.ts +++ b/src/api/gen/datasource.ts @@ -39,10 +39,11 @@ export function getObj(id?: string) { }); } -export function delObj(id?: string) { +export function delObj(ids?: Object) { return request({ - url: '/gen/dsconf/' + id, + url: '/gen/dsconf', method: 'delete', + data: ids, }); } diff --git a/src/components/DictTag/index.vue b/src/components/DictTag/index.vue index fed7eeb9..5c3d4823 100644 --- a/src/components/DictTag/index.vue +++ b/src/components/DictTag/index.vue @@ -2,13 +2,11 @@
diff --git a/src/views/app/approle/form.vue b/src/views/app/approle/form.vue index 08e3a561..a2a551c7 100644 --- a/src/views/app/approle/form.vue +++ b/src/views/app/approle/form.vue @@ -46,7 +46,6 @@ const { t } = useI18n(); // 定义变量内容 const dataFormRef = ref(); -const deptTreeRef = ref(); const visible = ref(false); // 提交表单数据 @@ -55,8 +54,6 @@ const form = reactive({ roleName: '', roleCode: '', roleDesc: '', - dsType: 0, - dsScope: '', }); // 页面对应元数据 @@ -94,7 +91,6 @@ const dataRules = ref({ }, ], roleDesc: [{ max: 128, message: '长度在 128 个字符内', trigger: 'blur' }], - dsType: [{ required: true, message: '请选择数据权限类型', trigger: 'blur' }], }); // 打开弹窗 @@ -103,10 +99,9 @@ const openDialog = (id: string) => { form.roleId = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } - + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取角色信息 if (id) { form.roleId = id; @@ -115,41 +110,18 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - if (form.dsType === 1) { - form.dsScope = deptTreeRef.value.getCheckedKeys().join(','); - } else { - form.dsScope = ''; +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + try { + form.roleId ? await putObj(form) : await addObj(form); + useMessage().success(t(form.roleId ? 'common.editSuccessText' : 'common.addSuccessText')); + visible.value = false; + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); } - - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - - // 更新 - if (form.roleId) { - 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); - }); - } - }); }; // 初始化角色数据 diff --git a/src/views/app/approle/index.vue b/src/views/app/approle/index.vue index 51eb401c..b83eb43c 100644 --- a/src/views/app/approle/index.vue +++ b/src/views/app/approle/index.vue @@ -114,33 +114,31 @@ const resetQuery = () => { getDataList(); }; -// 多选事件 -const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.roleId); - }); - multiple.value = !objs.length; -}; - // 导出excel const exportExcel = () => { downBlobFile('/app/approle/export', state.queryForm, 'approle.xlsx'); }; +// 多选事件 +const handleSelectionChange = (objs: any) => { + selectObjs.value.push(...objs.map((val: any) => val.roleId)); + multiple.value = !objs.length; +}; + // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/app/approle/permession.vue b/src/views/app/approle/permession.vue index 27cb98f3..b89cdb77 100644 --- a/src/views/app/approle/permession.vue +++ b/src/views/app/approle/permession.vue @@ -30,6 +30,7 @@ import { pageList } from '/@/api/app/appmenu'; import { useMessage } from '/@/hooks/message'; import { Ref } from 'vue'; import { useI18n } from 'vue-i18n'; +import other from '/@/utils/other'; const { t } = useI18n(); @@ -65,7 +66,7 @@ const openDialog = (row: any) => { }) .then((r) => { state.treeData = r.data; - state.checkedKeys = resolveAllEunuchNodeId(state.treeData, checkedKeys.value, []); + state.checkedKeys = other.resolveAllEunuchNodeId(state.treeData, checkedKeys.value, []); }); state.dialog.isShowDialog = true; }; @@ -74,10 +75,12 @@ const openDialog = (row: any) => { const closeDialog = () => { state.dialog.isShowDialog = false; }; + // 取消 const onCancel = () => { closeDialog(); }; + const onSubmit = () => { const menuIds = menuTree.value.getCheckedKeys().join(',').concat(',').concat(menuTree.value.getHalfCheckedKeys().join(',')); permissionUpd(state.roleId, menuIds).then(() => { @@ -86,21 +89,6 @@ const onSubmit = () => { }); }; -const resolveAllEunuchNodeId = (json: any[], idArr: any[], temp: any[]) => { - for (let i = 0; i < json.length; i++) { - const item = json[i]; - // 国际化 - item.name = t(item.name); - // 存在子节点,递归遍历;不存在子节点,将json的id添加到临时数组中 - if (item.children && item.children.length !== 0) { - resolveAllEunuchNodeId(item.children, idArr, temp); - } else { - temp.push(idArr.filter((id) => id === item.id)); - } - } - return temp; -}; - // 暴露变量 defineExpose({ openDialog, diff --git a/src/views/app/appsocial/form.vue b/src/views/app/appsocial/form.vue index 86f2a6b5..fb4e4360 100644 --- a/src/views/app/appsocial/form.vue +++ b/src/views/app/appsocial/form.vue @@ -96,9 +96,9 @@ const openDialog = (id: string) => { form.id = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取appSocialDetails信息 if (id) { @@ -108,43 +108,27 @@ 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.appSecret && form.appSecret.indexOf('******') >= 0) { - form.appSecret = undefined; - } + // 隐藏敏感信息 + form.appSecret = form.appSecret?.includes('******') ? undefined : form.appSecret; + form.appId = form.appId?.includes('******') ? undefined : form.appId; - if (form.appId && form.appId.indexOf('******') >= 0) { - form.appId = undefined; - } - - // 更新 + try { if (form.id) { - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); + await putObj(form); + useMessage().success(t('common.editSuccessText')); } else { - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); + await addObj(form); + useMessage().success(t('common.addSuccessText')); } - }); + visible.value = false; // 关闭弹窗 + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 初始化表单数据 diff --git a/src/views/app/appsocial/index.vue b/src/views/app/appsocial/index.vue index 154671fc..8d353d1a 100644 --- a/src/views/app/appsocial/index.vue +++ b/src/views/app/appsocial/index.vue @@ -129,33 +129,31 @@ const resetQuery = () => { getDataList(); }; -// 多选事件 -const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); - multiple.value = !objs.length; -}; - // 导出excel const exportExcel = () => { downBlobFile('/app/appsocial/export', state.queryForm, 'appsocial.xlsx'); }; +// 多选事件 +const handleSelectionChange = (objs: any) => { + selectObjs.value.push(...objs.map((val: any) => val.id)); + multiple.value = !objs.length; +}; + // 删除操作 -const handleDelete = (ids: any) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/app/appuser/form.vue b/src/views/app/appuser/form.vue index d918085c..2ee5f7b8 100644 --- a/src/views/app/appuser/form.vue +++ b/src/views/app/appuser/form.vue @@ -145,9 +145,9 @@ const openDialog = (id: string) => { dataForm.userId = ''; // 重置表单数据 - if (dataFormRef.value) { + nextTick(() => { dataFormRef.value.resetFields(); - } + }); // 修改获取用户信息 if (id) { @@ -158,64 +158,52 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新方法 - if (dataForm.userId) { - if (dataForm.phone && dataForm.phone.indexOf('*') >= 0) { - dataForm.phone = undefined; - } - if (dataForm.password && dataForm.password.indexOf('******') >= 0) { - dataForm.password = undefined; - } - putObj(dataForm) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err) => { - useMessage().error(err.msg); - }); - } else { - // 新增方法 - if (dataForm.phone && dataForm.phone.indexOf('*') > 0) { - dataForm.phone = undefined; - } - addObj(dataForm) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err) => { - useMessage().error(err.msg); - }); - } - }); -}; +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; -// 初始化部门数据 -const getUserData = (id: string) => { - // 获取部门数据 + try { + const { userId, phone, password } = dataForm; + + if (userId) { + // 清除占位符,避免提交错误的数据 + if (phone?.includes('*')) dataForm.phone = undefined; + if (password?.includes('******')) dataForm.password = undefined; + + loading.value = true; + await putObj(dataForm); + useMessage().success(t('common.editSuccessText')); + visible.value = false; // 关闭弹窗 + emit('refresh'); + } else { + loading.value = true; + await addObj(dataForm); + useMessage().success(t('common.addSuccessText')); + visible.value = false; // 关闭弹窗 + emit('refresh'); + } + } catch (error: any) { + useMessage().error(error.msg); + } finally { + loading.value = false; + } +}; +// 初始化用户信息数据 +const getUserData = async (id: string) => { loading.value = true; - getObj(id) - .then((res) => { - Object.assign(dataForm, res.data); - dataForm.password = '******'; - if (res.data.roleList) { - dataForm.role = []; - res.data.roleList.map((item: any) => { - dataForm.role.push(item.roleId); - }); - } - }) - .finally(() => { - loading.value = false; - }); + + try { + const { data } = await getObj(id); + + Object.assign(dataForm, data); + dataForm.password = '******'; + + if (data.roleList) { + dataForm.role = data.roleList.map((item: any) => item.roleId); + } + } finally { + loading.value = false; + } }; // 角色数据 diff --git a/src/views/app/appuser/index.vue b/src/views/app/appuser/index.vue index 4b5a9e3c..b6a8a27d 100644 --- a/src/views/app/appuser/index.vue +++ b/src/views/app/appuser/index.vue @@ -135,34 +135,31 @@ const resetQuery = () => { getDataList(); }; -// 多选事件 -const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.userId); - }); - multiple.value = !objs.length; -}; - // 导出excel const exportExcel = () => { downBlobFile('/app/appuser/export', state.queryForm, 'users.xlsx'); }; +// 多选事件 +const handleSelectionChange = (objs: any) => { + selectObjs.value.push(...objs.map((val: any) => val.userId)); + multiple.value = !objs.length; +}; + // 删除用户 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - // 删除用户的接口 - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/daemon/job-manage/form.vue b/src/views/daemon/job-manage/form.vue index 7f017860..3940f61b 100644 --- a/src/views/daemon/job-manage/form.vue +++ b/src/views/daemon/job-manage/form.vue @@ -145,9 +145,9 @@ const openDialog = (id: string) => { form.jobId = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取sysJob信息 if (id) { @@ -157,35 +157,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.jobId) { - 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.jobId ? await putObj(form) : await addObj(form); + useMessage().success(t(form.jobId ? 'common.editSuccessText' : 'common.addSuccessText')); + visible.value = false; + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 初始化表单数据 diff --git a/src/views/daemon/job-manage/index.vue b/src/views/daemon/job-manage/index.vue index a127729f..e85a391c 100644 --- a/src/views/daemon/job-manage/index.vue +++ b/src/views/daemon/job-manage/index.vue @@ -244,22 +244,21 @@ const handleRunJob = (row: any) => { // 删除操作 const handleDelete = (row: any) => { if (!row) { - selectObjs.value.forEach((val: any) => { - handleDelete(val); - }); + selectObjs.value.forEach(handleDelete); return; } + + const { jobId, jobName } = row; useMessageBox() - .confirm(t('common.delConfirmText') + '(任务名称:' + row.jobName + ')') - .then(() => { - delObj(row.jobId) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); + .confirm(`${t('common.delConfirmText')}(任务名称:${jobName})`) + .then(async () => { + try { + await delObj(jobId); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (error: any) { + useMessage().error(error.msg); + } }); }; diff --git a/src/views/daemon/job-manage/job-log.vue b/src/views/daemon/job-manage/job-log.vue index c336589f..1cf38a77 100644 --- a/src/views/daemon/job-manage/job-log.vue +++ b/src/views/daemon/job-manage/job-log.vue @@ -87,26 +87,25 @@ const openDialog = (id: string) => { // 多选事件 const handleSelectionChange = (objs: any) => { - objs.forEach((val: any) => { - selectObjs.value.push(val.jobLogId); - }); + selectObjs.value.push(...objs.map((val: any) => val.jobLogId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 暴露变量 diff --git a/src/views/gen/datasource/form.vue b/src/views/gen/datasource/form.vue index 0649e135..10828fa9 100644 --- a/src/views/gen/datasource/form.vue +++ b/src/views/gen/datasource/form.vue @@ -90,7 +90,7 @@ const form = reactive({ name: '', url: '', username: '', - password: '', + password: '' as string || undefined, createTime: '', updateTime: '', dsType: '', @@ -139,9 +139,9 @@ const openDialog = async (id: string) => { form.id = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取DatasourceConf信息 if (id) { @@ -153,39 +153,20 @@ const openDialog = async (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) { - if (form.password.indexOf('********') === 0) { - form.password = ''; - } + form.password = form.password?.includes('******') ? undefined : form.password; - 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/gen/datasource/index.vue b/src/views/gen/datasource/index.vue index a5c531a1..6e7c2728 100644 --- a/src/views/gen/datasource/index.vue +++ b/src/views/gen/datasource/index.vue @@ -19,7 +19,7 @@ {{ $t('common.addBtn') }} - + {{ $t('common.delBtn') }} {{ $t('common.editBtn') }} - {{ $t('common.delBtn') }} + {{ $t('common.delBtn') }} @@ -73,7 +73,7 @@ const formDialogRef = ref(); const queryRef = ref(); const showSearch = ref(true); // 多选变量 -const selectObjs = ref([]); +const selectObjs = ref([]) as any; const multiple = ref(true); const state: BasicTableProps = reactive({ @@ -96,31 +96,26 @@ const resetQuery = () => { }; // 多选事件 -const handleSelectionChange = (val: any) => { - selectObjs.value = val; - multiple.value = !val.length; +// 多选事件 +const handleSelectionChange = (objs: any) => { + selectObjs.value.push(...objs.map((val: any) => val.id)); + multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (row: any) => { - if (!row) { - selectObjs.value.forEach((val: any) => { - handleDelete(val); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { return; } - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(row.id) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/gen/design/form.vue b/src/views/gen/design/form.vue index 8d4c32cc..4602f662 100644 --- a/src/views/gen/design/form.vue +++ b/src/views/gen/design/form.vue @@ -18,7 +18,9 @@ import { BasicTableProps, useTable } from '/@/hooks/table'; import { delFormObj, fetchFormList } from '/@/api/gen/table'; import { useMessage, useMessageBox } from '/@/hooks/message'; +import { useI18n } from 'vue-i18n'; const emit = defineEmits(['refresh']); +const { t } = useI18n(); // 搜索变量 const visible = ref(false); // table hook @@ -31,19 +33,20 @@ const state: BasicTableProps = reactive({ const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle } = useTable(state); // 删除操作 -const handleDelete = (id: string) => { - useMessageBox() - .confirm('此操作将永久删除') - .then(() => { - delFormObj(id) - .then(() => { - getDataList(false); - useMessage().success('删除成功'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (id: string) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delFormObj(id); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 回滚 diff --git a/src/views/gen/design/index.vue b/src/views/gen/design/index.vue index 748fbf09..ae1e06de 100644 --- a/src/views/gen/design/index.vue +++ b/src/views/gen/design/index.vue @@ -15,6 +15,7 @@ diff --git a/src/views/gen/field-type/form.vue b/src/views/gen/field-type/form.vue index 1f9cd5d6..706654d7 100644 --- a/src/views/gen/field-type/form.vue +++ b/src/views/gen/field-type/form.vue @@ -74,9 +74,9 @@ const openDialog = (id: string) => { visible.value = true; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 如果有id参数,表示是编辑操作,需要设置form.id和获取FieldType信息 if (id) { diff --git a/src/views/gen/field-type/index.vue b/src/views/gen/field-type/index.vue index a8c5743d..1b6394ec 100644 --- a/src/views/gen/field-type/index.vue +++ b/src/views/gen/field-type/index.vue @@ -89,31 +89,31 @@ const resetQuery = () => { getDataList(); }; -// 多选事件 -const handleSelectionChange = (objs: any) => { - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); - multiple.value = !objs.length; -}; // 导出excel const exportExcel = () => { downBlobFile('/gen/fieldtype/export', state.queryForm, 'fieldtype.xlsx'); }; +// 多选事件 +const handleSelectionChange = (objs: any) => { + selectObjs.value.push(...objs.map((val: any) => val.id)); + multiple.value = !objs.length; +}; + // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/gen/gener/index.vue b/src/views/gen/gener/index.vue index ff78e877..8cecba3b 100644 --- a/src/views/gen/gener/index.vue +++ b/src/views/gen/gener/index.vue @@ -47,9 +47,10 @@ const dsName = ref(); const editTableRef = ref(); const generatorType = ref(); -const go = async (activeNum) => { +const go = async (activeNum: number) => { if (active.value === activeNum) return; active.value = activeNum; + if (activeNum === 0) { await editTableRef.value.submitHandle(); } else if (activeNum === 1) { diff --git a/src/views/gen/group/form.vue b/src/views/gen/group/form.vue index 72dc488f..3947d905 100644 --- a/src/views/gen/group/form.vue +++ b/src/views/gen/group/form.vue @@ -60,27 +60,22 @@ const dataRules = ref({ templateId: [{ required: true, message: '模板不能为空', trigger: 'blur' }], }); -// 打开弹窗 const openDialog = (id: string) => { visible.value = true; form.id = ''; // 重置表单数据 - if (dataFormRef.value) { + nextTick(() => { dataFormRef.value.resetFields(); - } + }); - // 修改获取用户信息 + // 如果有 id 参数,获取 genGroup 信息 if (id) { form.id = id; getgenGroupData(id); } - // 获取genGroup信息 - if (id) { - form.id = id; - getgenGroupData(id); - } + // 获取模板信息 getTemplateData(); }; diff --git a/src/views/gen/group/index.vue b/src/views/gen/group/index.vue index fdfecc2c..b89dae9c 100644 --- a/src/views/gen/group/index.vue +++ b/src/views/gen/group/index.vue @@ -115,26 +115,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/gen/table/preview.vue b/src/views/gen/table/preview.vue index 0eb4428b..99d1232a 100644 --- a/src/views/gen/table/preview.vue +++ b/src/views/gen/table/preview.vue @@ -53,6 +53,10 @@ const openDialog = async (id: string) => { const loading = ref(false); +/** + * 获取特定资源的代码生成文件,显示在页面上。 + * @param id 需要渲染的资源 ID。 + */ const getGenCodeFile = (id: string) => { loading.value = true; fileTreeOriginal.value = []; diff --git a/src/views/gen/template/form.vue b/src/views/gen/template/form.vue index b7e0cc8e..02adf1ab 100644 --- a/src/views/gen/template/form.vue +++ b/src/views/gen/template/form.vue @@ -72,10 +72,9 @@ const openDialog = (id: string) => { form.id = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } - + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取genTemplate信息 if (id) { form.id = id; diff --git a/src/views/gen/template/index.vue b/src/views/gen/template/index.vue index 53eb51ff..540417c2 100644 --- a/src/views/gen/template/index.vue +++ b/src/views/gen/template/index.vue @@ -104,26 +104,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/home/current-user.vue b/src/views/home/current-user.vue index bd93e6ef..3071b9bf 100644 --- a/src/views/home/current-user.vue +++ b/src/views/home/current-user.vue @@ -38,19 +38,21 @@ onMounted(() => { initUserInfo(data.user.userId); }); -const initUserInfo = (userId: any) => { - loading.value = true; - getObj(userId) - .then((res) => { - userData.value = res.data; - userData.value.postName = res.data.postList - .map((item) => { - return item.postName; - }) - .join(','); - }) - .finally(() => { - loading.value = false; - }); +/** + * 根据用户 ID 初始化用户信息。 + * @param {any} userId - 要查询的用户 ID。 + * @returns {Promise} - 初始化用户信息的 Promise 实例。 + */ + const initUserInfo = async (userId: any): Promise => { + try { + loading.value = true; // 显示加载状态 + + const res = await getObj(userId); // 执行查询操作 + userData.value = res.data; // 将查询到的数据保存到 userData 变量中 + userData.value.postName = res.data?.postList?.map((item: any) => item.postName).join(',') || ''; // 将 postList 中的 postName 合并成字符串并保存到 userData 变量中 + } finally { + loading.value = false; // 结束加载状态 + } }; + diff --git a/src/views/home/schedule/calendar.vue b/src/views/home/schedule/calendar.vue index 13479c3e..9c84e2ef 100644 --- a/src/views/home/schedule/calendar.vue +++ b/src/views/home/schedule/calendar.vue @@ -13,7 +13,7 @@ - + diff --git a/src/views/mp/wx-account-fans/index.vue b/src/views/mp/wx-account-fans/index.vue index d36d762a..bd0816d4 100644 --- a/src/views/mp/wx-account-fans/index.vue +++ b/src/views/mp/wx-account-fans/index.vue @@ -182,7 +182,7 @@ const handleDelete = (ids: string[]) => { .then(() => { delObjs(ids) .then(() => { - getDataList(false); + getDataList(); useMessage().success(t('common.delSuccessText')); }) .catch((err: any) => { @@ -197,7 +197,7 @@ const handelBlack = (ids: string[]) => { .then(() => { black(ids, state.queryForm.wxAccountAppid) .then(() => { - getDataList(false); + getDataList(); useMessage().success('拉黑用户成功'); }) .catch((err: any) => { @@ -212,7 +212,7 @@ const handelUnBlack = (ids: string[]) => { .then(() => { unblack(ids, state.queryForm.wxAccountAppid) .then(() => { - getDataList(false); + getDataList(); useMessage().success('设置成功'); }) .catch((err: any) => { diff --git a/src/views/mp/wx-account-tag/index.vue b/src/views/mp/wx-account-tag/index.vue index 8176752f..4b9badc5 100644 --- a/src/views/mp/wx-account-tag/index.vue +++ b/src/views/mp/wx-account-tag/index.vue @@ -171,7 +171,7 @@ const handleDelete = (ids: string[]) => { wxAccountAppid: state.queryForm.wxAccountAppid, }) .then(() => { - getDataList(false); + getDataList(); useMessage().success(t('common.delSuccessText')); }) .catch((err: any) => { diff --git a/src/views/mp/wx-account/index.vue b/src/views/mp/wx-account/index.vue index 866fdc61..c2701f0f 100644 --- a/src/views/mp/wx-account/index.vue +++ b/src/views/mp/wx-account/index.vue @@ -152,7 +152,7 @@ const handleDelete = (ids: string[]) => { .then(() => { delObjs(ids) .then(() => { - getDataList(false); + getDataList(); useMessage().success(t('common.delSuccessText')); }) .catch((err: any) => { diff --git a/src/views/oa/leave_bill/form.vue b/src/views/oa/leave_bill/form.vue index efd22baf..ae03d6a4 100644 --- a/src/views/oa/leave_bill/form.vue +++ b/src/views/oa/leave_bill/form.vue @@ -79,9 +79,10 @@ const openDialog = (id: string) => { form.leaveId = ''; // 重置表单数据 - if (dataFormRef.value) { + + nextTick(() => { dataFormRef.value.resetFields(); - } + }); // 获取oaLeaveBill信息 if (id) { @@ -93,42 +94,18 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新 - if (form.leaveId) { - loading.value = true; - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } else { - loading.value = true; - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } - }); +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + try { + form.leaveId ? await putObj(form) : await addObj(form); + useMessage().success(t(form.leaveId ? 'common.editSuccessText' : 'common.addSuccessText')); + visible.value = false; + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 初始化表单数据 diff --git a/src/views/oa/leave_bill/index.vue b/src/views/oa/leave_bill/index.vue index 326103f4..04da253a 100644 --- a/src/views/oa/leave_bill/index.vue +++ b/src/views/oa/leave_bill/index.vue @@ -130,42 +130,45 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.leaveId); - }); - console.log(selectObjs); + selectObjs.value.push(...objs.map((val: any) => val.leaveId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; -const handleSubmit = (row) => { - useMessageBox() - .confirm(t('common.optConfirmText')) - .then(() => { - submit(row.leaveId) - .then(() => { - getDataList(false); - useMessage().success(t('common.optSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +/** + * 提交表单数据。 + * @param {object} row 当前行数据。 + * @returns {void} + */ +const handleSubmit = async (row) => { + try { + await useMessageBox().confirm(t('common.optConfirmText')); + } catch { + return; + } + + try { + await submit(row.leaveId); + getDataList(); + useMessage().success(t('common.optSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/oa/model/form.vue b/src/views/oa/model/form.vue index 74566ee7..aaaf26d0 100644 --- a/src/views/oa/model/form.vue +++ b/src/views/oa/model/form.vue @@ -64,9 +64,9 @@ const openDialog = (id: string) => { form.id = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); if (id) { form.id = id; @@ -86,42 +86,18 @@ const getModelData = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新 - if (form.id) { - loading.value = true; - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } else { - loading.value = true; - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } - }); +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + 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/oa/model/index.vue b/src/views/oa/model/index.vue index 874347cb..c63f7c2f 100644 --- a/src/views/oa/model/index.vue +++ b/src/views/oa/model/index.vue @@ -43,7 +43,7 @@ @@ -93,29 +93,26 @@ const resetQuery = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); -}; +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } +}; const handleDeploy = (id: string) => { deploy(id).then(() => { useMessage().success(t('common.optSuccessText')); diff --git a/src/views/oa/process/index.vue b/src/views/oa/process/index.vue index 9e515870..f82cabe0 100644 --- a/src/views/oa/process/index.vue +++ b/src/views/oa/process/index.vue @@ -51,7 +51,7 @@ 流程图 失效 激活 - {{ $t('common.delBtn') }} + {{ $t('common.delBtn') }} @@ -103,27 +103,25 @@ const resetQuery = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.roleId); - }); + selectObjs.value.push(...objs.map((val: any) => val.processonDefinitionId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; //查看流程图 @@ -135,18 +133,19 @@ const handleView = (row: any) => { }; // 失效 -const handleStatus = (row, type) => { - useMessageBox() - .confirm('是否将此流程设置为 ' + type) - .then(() => { - status(row.processonDefinitionId, type) - .then(() => { - getDataList(); - useMessage().success(t('common.optSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleStatus = async (row, type) => { + try { + await useMessageBox().confirm('是否将此流程设置为 ' + type); + } catch { + return; + } + + try { + await status(row.processonDefinitionId, type) + getDataList(); + useMessage().success(t('common.optSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/oa/task/comment.vue b/src/views/oa/task/comment.vue index 362d21e9..90143cac 100644 --- a/src/views/oa/task/comment.vue +++ b/src/views/oa/task/comment.vue @@ -55,9 +55,7 @@ const { getDataList, sortChangeHandle } = useTable(state); // 多选事件 const handleSelectionChange = (objs: any) => { - objs.forEach((val: any) => { - selectObjs.value.push(val.leaveId); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; diff --git a/src/views/oa/task/form.vue b/src/views/oa/task/form.vue index 54b5f8cb..2bbce5d7 100644 --- a/src/views/oa/task/form.vue +++ b/src/views/oa/task/form.vue @@ -86,9 +86,9 @@ const openDialog = (id: string) => { form.taskId = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取oaLeaveBill信息 if (id) { @@ -100,36 +100,37 @@ const openDialog = (id: string) => { }; // 提交 -const handleTask = (result) => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - loading.value = true; - form.taskFlag = result; - doTask(form).then(() => { - useMessage().success(t('common.optSuccessText')); - visible.value = false; - emit('refresh'); - }); +const handleTask = async (result) => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + loading.value = true; + form.taskFlag = result; + doTask(form).then(() => { + useMessage().success(t('common.optSuccessText')); + visible.value = false; + emit('refresh'); }); }; -// 初始化表单数据 -const getTaskById = (id: string) => { - // 获取数据 - loading.value = true; - fetchDetail(id) - .then((res: any) => { - Object.assign(form, res.data); - form.comment = res.data.comment ? res.data.comment : ''; - }) - .catch((err) => { - useMessage().error('操作失败'); - }) - .finally(() => { - loading.value = false; - }); +/** + * 根据 ID 获取任务数据并初始化表单。 + * @param {string} id - 要查询的任务 ID。 + * @returns {Promise} - 初始化表单的 Promise 实例。 + */ +const getTaskById = async (id) => { + loading.value = true; // 显示加载状态 + + try { + const res = await fetchDetail(id); // 执行查询操作 + // 将查询到的数据合并到表单中,并设置表单评论信息 + Object.assign(form, res.data); + form.comment = res.data.comment ?? ''; + } catch (err) { + useMessage().error('操作失败'); // 如果查询失败,则显示错误提示信息 + } finally { + loading.value = false; // 结束加载状态 + } }; // 暴露变量 diff --git a/src/views/oa/task/index.vue b/src/views/oa/task/index.vue index 4340ae3e..6a968899 100644 --- a/src/views/oa/task/index.vue +++ b/src/views/oa/task/index.vue @@ -112,27 +112,25 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.taskId); - }); + selectObjs.value.push(...objs.map((val: any) => val.taskId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObj(ids) - .then(() => { - getDataList(); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObj(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; //查看流程图 diff --git a/src/views/pay/cd/index.vue b/src/views/pay/cd/index.vue index f44eb494..ef960516 100755 --- a/src/views/pay/cd/index.vue +++ b/src/views/pay/cd/index.vue @@ -64,14 +64,24 @@ onMounted(() => { getQr(); }); -const getQr = () => { - if (state.type === '0') { - useBuyApi(state.amount).then((res) => { - url.value = res.params; - }); - } else { +/** + * 获取支付二维码信息。 + * @param {Object} state - 包含 type 和 amount 两个属性的对象。 + * @param {string} state.type - 支付类型。"0" 表示直接购买,其他值表示商品购买。 + * @param {number} state.amount - 支付金额。 + * @returns {Promise} - 返回 Promise 实例,包含获取到的支付二维码链接地址。 + */ +const getQr = async () => { + const { type, amount } = state; + try { + if (type === '0') { + const res = await useBuyApi(amount); + return res.params; // 直接返回购买 API 返回的二维码链接地址 + } const tenantId = Session.getTenant(); - url.value = `${protocol}//${host}/admin/goods/buy?amount=${state.amount}&TENANT-ID=${tenantId}`; + return `${protocol}//${host}/admin/goods/buy?amount=${amount}&TENANT-ID=${tenantId}`; // 返回商品购买的二维码链接地址 + } catch (err) { + throw new Error('获取支付信息失败'); } }; diff --git a/src/views/pay/channel/form.vue b/src/views/pay/channel/form.vue index f18d9583..d34813ed 100644 --- a/src/views/pay/channel/form.vue +++ b/src/views/pay/channel/form.vue @@ -132,9 +132,9 @@ const openDialog = (id: string) => { form.id = ''; // 重置表单数据 - if (dataFormRef.value) { + nextTick(() => { dataFormRef.value.resetFields(); - } + }); // 获取payChannel信息 if (id) { @@ -144,55 +144,36 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新 - if (form.id) { - loading.value = true; - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } else { - loading.value = true; - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } - }); +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + 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); + } }; -// 初始化表单数据 -const getpayChannelData = (id: string) => { - // 获取数据 - loading.value = true; - getObj(id) - .then((res: any) => { - Object.assign(form, res.data); - }) - .finally(() => { - loading.value = false; - }); +/** + * 根据 ID 获取支付通道数据并初始化表单。 + * @param {string} id - 要查询的支付通道 ID。 + * @returns {Promise} - 初始化表单的 Promise 实例。 + */ +const getpayChannelData = async (id: string): Promise => { + loading.value = true; // 显示加载状态 + + try { + const res = await getObj(id); // 执行查询操作 + Object.assign(form, res.data); // 将查询到的数据合并到表单中 + } catch (err) { + useMessage().error('操作失败'); // 如果查询失败,则显示错误提示信息 + } finally { + loading.value = false; // 结束加载状态 + } }; // 暴露变量 diff --git a/src/views/pay/channel/index.vue b/src/views/pay/channel/index.vue index f310822a..4944c58e 100644 --- a/src/views/pay/channel/index.vue +++ b/src/views/pay/channel/index.vue @@ -135,26 +135,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/pay/order/form.vue b/src/views/pay/order/form.vue index 5c1f18b9..b2a00502 100644 --- a/src/views/pay/order/form.vue +++ b/src/views/pay/order/form.vue @@ -118,55 +118,36 @@ const openDialog = (id: string) => { }; // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新 - if (form.goodsOrderId) { - loading.value = true; - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } else { - loading.value = true; - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } - }); +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + 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); + } }; -// 初始化表单数据 -const getpayGoodsOrderData = (id: string) => { - // 获取数据 - loading.value = true; - getObj(id) - .then((res: any) => { - Object.assign(form, res.data); - }) - .finally(() => { - loading.value = false; - }); +/** + * 根据 ID 获取商品支付订单数据并初始化表单。 + * @param {string} id - 要查询的商品支付订单 ID。 + * @returns {Promise} - 初始化表单的 Promise 实例。 + */ +const getpayGoodsOrderData = async (id: string): Promise => { + loading.value = true; // 显示加载状态 + + try { + const res = await getObj(id); // 执行查询操作 + Object.assign(form, res.data); // 将查询到的数据合并到表单中 + } catch (err) { + useMessage().error('操作失败'); // 如果查询失败,则显示错误提示信息 + } finally { + loading.value = false; // 结束加载状态 + } }; // 暴露变量 diff --git a/src/views/pay/order/index.vue b/src/views/pay/order/index.vue index 9d547eb8..29496208 100644 --- a/src/views/pay/order/index.vue +++ b/src/views/pay/order/index.vue @@ -136,26 +136,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.goodsOrderId); - }); + selectObjs.value.push(...objs.map((val: any) => val.goodsOrderId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/pay/record/index.vue b/src/views/pay/record/index.vue index d0ef263c..615cc884 100644 --- a/src/views/pay/record/index.vue +++ b/src/views/pay/record/index.vue @@ -107,26 +107,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.id); - }); + selectObjs.value.push(...objs.map((val: any) => val.id)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/pay/refund/index.vue b/src/views/pay/refund/index.vue index 827843a4..a99eca1c 100644 --- a/src/views/pay/refund/index.vue +++ b/src/views/pay/refund/index.vue @@ -113,26 +113,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.refundOrderId); - }); + selectObjs.value.push(...objs.map((val: any) => val.refundOrderId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/pay/trade/form.vue b/src/views/pay/trade/form.vue index 4269237c..49970d34 100644 --- a/src/views/pay/trade/form.vue +++ b/src/views/pay/trade/form.vue @@ -155,55 +155,32 @@ const dictType = ref([ ]); // 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - // 更新 - if (form.orderId) { - loading.value = true; - putObj(form) - .then(() => { - useMessage().success(t('common.editSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } else { - loading.value = true; - addObj(form) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - } - }); +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + try { + form.orderId ? await putObj(form) : await addObj(form); + useMessage().success(t(form.orderId ? 'common.editSuccessText' : 'common.addSuccessText')); + visible.value = false; + emit('refresh'); + } catch (err: any) { + useMessage().error(err.msg); + } }; // 初始化表单数据 -const getpayTradeOrderData = (id: string) => { - // 获取数据 - loading.value = true; - getObj(id) - .then((res: any) => { - Object.assign(form, res.data); - }) - .finally(() => { - loading.value = false; - }); +const getpayTradeOrderData = async (id: string) => { + loading.value = true; // 显示加载状态 + + try { + const res = await getObj(id); // 执行查询操作 + Object.assign(form, res.data); // 将查询到的数据合并到表单中 + } catch (err) { + useMessage().error('操作失败'); // 如果查询失败,则显示错误提示信息 + } finally { + loading.value = false; // 结束加载状态 + } }; // 暴露变量 diff --git a/src/views/pay/trade/index.vue b/src/views/pay/trade/index.vue index ef6740ab..82f6dd68 100644 --- a/src/views/pay/trade/index.vue +++ b/src/views/pay/trade/index.vue @@ -158,26 +158,24 @@ const exportExcel = () => { // 多选事件 const handleSelectionChange = (objs: any) => { - selectObjs.value = []; - objs.forEach((val: any) => { - selectObjs.value.push(val.orderId); - }); + selectObjs.value.push(...objs.map((val: any) => val.orderId)); multiple.value = !objs.length; }; // 删除操作 -const handleDelete = (ids: string[]) => { - useMessageBox() - .confirm(t('common.delConfirmText')) - .then(() => { - delObjs(ids) - .then(() => { - getDataList(false); - useMessage().success(t('common.delSuccessText')); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }); - }); +const handleDelete = async (ids: string[]) => { + try { + await useMessageBox().confirm(t('common.delConfirmText')); + } catch { + return; + } + + try { + await delObjs(ids); + getDataList(); + useMessage().success(t('common.delSuccessText')); + } catch (err: any) { + useMessage().error(err.msg); + } }; diff --git a/src/views/pay/trade/refund.vue b/src/views/pay/trade/refund.vue index 3425f891..ee626fc5 100644 --- a/src/views/pay/trade/refund.vue +++ b/src/views/pay/trade/refund.vue @@ -108,9 +108,9 @@ const openDialog = (id: string) => { form.orderId = ''; // 重置表单数据 - if (dataFormRef.value) { - dataFormRef.value.resetFields(); - } + nextTick(() => { + dataFormRef.value?.resetFields(); + }); // 获取payTradeOrder信息 if (id) { @@ -119,26 +119,33 @@ const openDialog = (id: string) => { } }; -// 提交 -const onSubmit = () => { - dataFormRef.value.validate((valid: boolean) => { - if (!valid) { - return false; - } - loading.value = true; - useRefundApi({ payOrderId: form.orderId, refundAmount: form.amount, remark: form.remark, channelId: form.channelId }) - .then(() => { - useMessage().success(t('common.addSuccessText')); - visible.value = false; // 关闭弹窗 - emit('refresh'); - }) - .catch((err: any) => { - useMessage().error(err.msg); - }) - .finally(() => { - loading.value = false; - }); - }); +/** + * 提交表单数据并执行退款操作。 + * @returns {Promise} - 执行退款操作的 Promise 实例。 + */ +const onSubmit = async () => { + const valid = await dataFormRef.value.validate().catch(() => {}); + if (!valid) return false; + + try { + loading.value = true; // 显示加载状态 + + await useRefundApi({ + // 执行退款操作 + payOrderId: form.orderId, + refundAmount: form.amount, + remark: form.remark, + channelId: form.channelId, + }); + + useMessage().success(t('common.optSuccessText')); // 如果退款成功,则显示成功提示信息 + visible.value = false; // 关闭弹窗 + emit('refresh'); // 触发 refresh 事件 + } catch (err: any) { + useMessage().error(err.msg); // 如果出现异常,则显示错误提示信息 + } finally { + loading.value = false; // 结束加载状态 + } }; // 初始化表单数据 diff --git a/vite.config.ts b/vite.config.ts index 268564a8..23d7287b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,14 +2,12 @@ import vue from '@vitejs/plugin-vue'; import { resolve } from 'path'; import { defineConfig, loadEnv, ConfigEnv } from 'vite'; import vueSetupExtend from 'vite-plugin-vue-setup-extend'; -// vue3 自动引入 import AutoImport from 'unplugin-auto-import/vite'; import topLevelAwait from 'vite-plugin-top-level-await'; -import { svgBuilder } from '/@/components/iconSelector/index'; - -// 按需加载 import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'; import viteCompression from 'vite-plugin-compression'; +// @ts-ignore +import { svgBuilder } from '/@/components/iconSelector/index'; const pathResolve = (dir: string) => { return resolve(__dirname, '.', dir); @@ -24,42 +22,41 @@ const viteConfig = defineConfig((mode: ConfigEnv) => { const env = loadEnv(mode.mode, process.cwd()); return { plugins: [ - vue(), - svgBuilder('./src/assets/icons/'), - vueSetupExtend(), + vue(), // Vue 插件 + svgBuilder('./src/assets/icons/'), // 将 SVG 文件转换成 Vue 组件 + vueSetupExtend(), // setup语法糖增强插件 AutoImport({ - imports: ['vue', 'vue-router', 'pinia'], - dts: './auto-imports.d.ts', + imports: ['vue', 'vue-router', 'pinia'], // 自动导入的依赖库数组 + dts: './auto-imports.d.ts', // 自动导入类型定义文件路径 }), createStyleImportPlugin({ - resolves: [VxeTableResolve()], + resolves: [VxeTableResolve()], // 配置vxetable 按需加载 }), topLevelAwait({ - // The export name of top-level await promise for each chunk module - promiseExportName: '__tla', - // The function to generate import names of top-level await promise in each chunk module - promiseImportName: (i) => `__tla_${i}`, + promiseExportName: '__tla', // TLA Promise 变量名 + promiseImportName: (i) => `__tla_${i}`, // TLA Promise 导入名 }), viteCompression({ - deleteOriginFile: true, + deleteOriginFile: true, // 压缩后删除原来的文件 }), ], - root: process.cwd(), - resolve: { alias }, + root: process.cwd(), // 项目根目录 + resolve: { alias }, // 路径别名配置 base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH, optimizeDeps: { include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en'], }, server: { - host: '0.0.0.0', - port: env.VITE_PORT as unknown as number, - open: env.VITE_OPEN === 'true', - hmr: true, + host: '0.0.0.0', // 服务器地址 + port: env.VITE_PORT as unknown as number, // 服务器端口号 + open: env.VITE_OPEN === 'true', // 是否自动打开浏览器 + hmr: true, // 启用热更新 proxy: { + // 代理设置,用于解决跨域问题 '/admin': { - target: env.VITE_ADMIN_PROXY_PATH, - ws: true, - changeOrigin: true, + target: env.VITE_ADMIN_PROXY_PATH, // 目标服务器地址 + ws: true, // 是否启用 WebSocket + changeOrigin: true, // 是否修改请求头中的 Origin 字段 }, '/gen': { target: env.VITE_GEN_PROXY_PATH, @@ -69,8 +66,8 @@ const viteConfig = defineConfig((mode: ConfigEnv) => { }, }, build: { - outDir: 'dist', - chunkSizeWarningLimit: 1500, + outDir: 'dist', // 打包输出目录 + chunkSizeWarningLimit: 1500, // 代码分包阈值 rollupOptions: { output: { entryFileNames: `assets/[name].[hash].js`,