From 7fe3ffe9dab318d744d2dd8d7d1e793efdbc97d1 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 23 Nov 2024 22:57:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=BD=BB=E5=BA=95=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20useForm=20=E7=BB=84=E5=90=88=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/index.ts | 1 - src/hooks/modules/useForm.ts | 17 ----------------- .../system/config/components/BasicSetting.vue | 4 ++-- .../system/config/components/MailSetting.vue | 4 ++-- .../config/components/SecuritySetting.vue | 4 ++-- src/views/system/user/index.vue | 4 ++-- 6 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 src/hooks/modules/useForm.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 8a9dc90..34b9233 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -3,7 +3,6 @@ export * from './modules/usePagination' export * from './modules/useRequest' export * from './modules/useChart' export * from './modules/useTable' -export * from './modules/useForm' export * from './modules/useDevice' export * from './modules/useBreakpoint' export * from './modules/useDownload' diff --git a/src/hooks/modules/useForm.ts b/src/hooks/modules/useForm.ts deleted file mode 100644 index fbf2ac5..0000000 --- a/src/hooks/modules/useForm.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { reactive } from 'vue' -import { cloneDeep } from 'lodash-es' - -export function useForm(initValue: F) { - const getInitValue = () => cloneDeep(initValue) - - const form = reactive(getInitValue()) - - const resetForm = () => { - for (const key in form) { - delete form[key] - } - Object.assign(form, getInitValue()) - } - - return { form, resetForm } -} diff --git a/src/views/system/config/components/BasicSetting.vue b/src/views/system/config/components/BasicSetting.vue index 06f34c4..6e3ec5e 100644 --- a/src/views/system/config/components/BasicSetting.vue +++ b/src/views/system/config/components/BasicSetting.vue @@ -130,14 +130,14 @@ import { updateOption, } from '@/apis/system' import { useAppStore } from '@/stores' -import { useForm } from '@/hooks' +import { useResetReactive } from '@/hooks' import { fileToBase64 } from '@/utils' defineOptions({ name: 'BasicSetting' }) const loading = ref(false) const formRef = ref() -const { form } = useForm({ +const [form] = useResetReactive({ SITE_FAVICON: '', SITE_LOGO: '', SITE_TITLE: '', diff --git a/src/views/system/config/components/MailSetting.vue b/src/views/system/config/components/MailSetting.vue index 439fa11..8c26398 100644 --- a/src/views/system/config/components/MailSetting.vue +++ b/src/views/system/config/components/MailSetting.vue @@ -69,13 +69,13 @@ import { resetOptionValue, updateOption, } from '@/apis/system' -import { useForm } from '@/hooks' +import { useResetReactive } from '@/hooks' defineOptions({ name: 'MailSetting' }) const { width } = useWindowSize() const loading = ref(false) const formRef = ref() -const { form } = useForm({ +const [form] = useResetReactive({ MAIL_PROTOCOL: '', MAIL_HOST: '', MAIL_PORT: 0, diff --git a/src/views/system/config/components/SecuritySetting.vue b/src/views/system/config/components/SecuritySetting.vue index 8a2a663..3c8e1f6 100644 --- a/src/views/system/config/components/SecuritySetting.vue +++ b/src/views/system/config/components/SecuritySetting.vue @@ -112,14 +112,14 @@ import { useWindowSize } from '@vueuse/core' import { type FormInstance, Message, Modal } from '@arco-design/web-vue' import { type OptionResp, type SecurityConfig, listOption, resetOptionValue, updateOption } from '@/apis/system' -import { useForm } from '@/hooks' +import { useResetReactive } from '@/hooks' defineOptions({ name: 'SecuritySetting' }) const { width } = useWindowSize() const loading = ref(false) const formRef = ref() -const { form } = useForm({ +const [form] = useResetReactive({ PASSWORD_ERROR_LOCK_COUNT: 0, PASSWORD_ERROR_LOCK_MINUTES: 0, PASSWORD_EXPIRATION_DAYS: 0, diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index d9d61cc..4c4b33e 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -105,7 +105,7 @@ import { type UserResp, deleteUser, exportUser, listUser } from '@/apis/system/u import type { Columns, Options } from '@/components/GiForm' import type { TableInstanceColumns } from '@/components/GiTable/type' import { DisEnableStatusList } from '@/constant/common' -import { useDownload, useForm, useTable } from '@/hooks' +import { useDownload, useResetReactive, useTable } from '@/hooks' import { isMobile } from '@/utils' import has from '@/utils/has' @@ -116,7 +116,7 @@ const options: Options = reactive({ grid: { cols: { xs: 1, sm: 1, md: 2, lg: 3, xl: 3, xxl: 3 } }, fold: { enable: true, index: 1, defaultCollapsed: true }, }) -const { form: queryForm, resetForm } = useForm({ +const [queryForm, resetForm] = useResetReactive({ sort: ['t1.id,desc'], }) const queryFormColumns: Columns = reactive([