gohttpdUi/src/views/Example/Dialog/components/Write.vue

57 lines
1.1 KiB
Vue
Raw Normal View History

2022-02-11 17:17:29 +08:00
<script setup lang="ts">
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
2022-02-19 15:36:18 +08:00
import { PropType, reactive, watch } from 'vue'
2022-02-11 17:17:29 +08:00
import { TableData } from '@/api/table/types'
2022-06-25 21:56:24 +08:00
import { useValidator } from '@/hooks/web/useValidator'
2022-10-09 17:12:03 +08:00
import { FormSchema } from '@/types/form'
2022-06-25 21:56:24 +08:00
const { required } = useValidator()
2022-02-11 17:17:29 +08:00
const props = defineProps({
currentRow: {
type: Object as PropType<Nullable<TableData>>,
default: () => null
},
2022-04-26 15:03:48 +08:00
formSchema: {
type: Array as PropType<FormSchema[]>,
default: () => []
2022-02-11 17:17:29 +08:00
}
2022-04-26 15:03:48 +08:00
})
2022-02-11 17:17:29 +08:00
const rules = reactive({
2022-06-25 21:56:24 +08:00
title: [required()],
author: [required()],
importance: [required()],
pageviews: [required()],
display_time: [required()],
content: [required()]
2022-02-11 17:17:29 +08:00
})
const { register, methods, elFormRef } = useForm({
2022-04-26 15:03:48 +08:00
schema: props.formSchema
2022-02-11 17:17:29 +08:00
})
2022-02-19 15:36:18 +08:00
watch(
() => props.currentRow,
(currentRow) => {
if (!currentRow) return
2022-04-26 15:03:48 +08:00
const { setValues } = methods
2022-02-19 15:36:18 +08:00
setValues(currentRow)
},
{
deep: true,
immediate: true
}
)
2022-02-11 17:17:29 +08:00
defineExpose({
elFormRef,
getFormData: methods.getFormData
})
</script>
<template>
<Form :rules="rules" @register="register" />
</template>