2023-11-12 11:37:28 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { FormSchema, Form } from '@/components/Form'
|
2023-12-10 09:18:33 +08:00
|
|
|
import { ElDrawer } from 'element-plus'
|
2023-11-12 11:37:28 +08:00
|
|
|
import { reactive } from 'vue'
|
|
|
|
import { useForm } from '@/hooks/web/useForm'
|
|
|
|
import { useValidator } from '@/hooks/web/useValidator'
|
|
|
|
|
|
|
|
const modelValue = defineModel<boolean>()
|
|
|
|
|
|
|
|
const { required } = useValidator()
|
|
|
|
|
|
|
|
const formSchema = reactive<FormSchema[]>([
|
|
|
|
{
|
|
|
|
field: 'label',
|
|
|
|
label: 'label',
|
|
|
|
component: 'Input',
|
|
|
|
colProps: {
|
|
|
|
span: 24
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'value',
|
|
|
|
label: 'value',
|
|
|
|
component: 'Input',
|
|
|
|
colProps: {
|
|
|
|
span: 24
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
const { formRegister, formMethods } = useForm()
|
|
|
|
const { getFormData, getElFormExpose } = formMethods
|
|
|
|
|
|
|
|
const emit = defineEmits(['confirm'])
|
|
|
|
|
|
|
|
const rules = reactive({
|
|
|
|
label: [required()],
|
|
|
|
value: [required()]
|
|
|
|
})
|
|
|
|
|
|
|
|
const confirm = async () => {
|
|
|
|
const elFormExpose = await getElFormExpose()
|
|
|
|
if (!elFormExpose) return
|
|
|
|
const valid = await elFormExpose?.validate().catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
if (valid) {
|
|
|
|
const formData = await getFormData()
|
2024-06-20 18:05:32 +08:00
|
|
|
formData.id = Date.now()
|
2023-11-12 11:37:28 +08:00
|
|
|
emit('confirm', formData)
|
|
|
|
modelValue.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<ElDrawer v-model="modelValue" title="新增按钮权限">
|
|
|
|
<template #default>
|
|
|
|
<Form :rules="rules" @register="formRegister" :schema="formSchema" />
|
|
|
|
</template>
|
|
|
|
<template #footer>
|
|
|
|
<div>
|
2023-12-10 09:18:33 +08:00
|
|
|
<BaseButton @click="() => (modelValue = false)">取消</BaseButton>
|
|
|
|
<BaseButton type="primary" @click="confirm">确认</BaseButton>
|
2023-11-12 11:37:28 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</ElDrawer>
|
|
|
|
</template>
|