refactor: 彻底删除 useForm 组合函数

This commit is contained in:
2024-11-23 22:57:44 +08:00
parent 7fa42975cf
commit 7fe3ffe9da
6 changed files with 8 additions and 26 deletions

View File

@@ -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'

View File

@@ -1,17 +0,0 @@
import { reactive } from 'vue'
import { cloneDeep } from 'lodash-es'
export function useForm<F extends object>(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 }
}

View File

@@ -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<boolean>(false)
const formRef = ref<FormInstance>()
const { form } = useForm({
const [form] = useResetReactive({
SITE_FAVICON: '',
SITE_LOGO: '',
SITE_TITLE: '',

View File

@@ -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<boolean>(false)
const formRef = ref<FormInstance>()
const { form } = useForm({
const [form] = useResetReactive({
MAIL_PROTOCOL: '',
MAIL_HOST: '',
MAIL_PORT: 0,

View File

@@ -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<boolean>(false)
const formRef = ref<FormInstance>()
const { form } = useForm({
const [form] = useResetReactive({
PASSWORD_ERROR_LOCK_COUNT: 0,
PASSWORD_ERROR_LOCK_MINUTES: 0,
PASSWORD_EXPIRATION_DAYS: 0,

View File

@@ -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([