index.vue
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script lang="ts" setup>
import { Button } from 'ant-design-vue';
import { nextTick, ref, watch } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { BasicModal } from '/@/components/Modal';
import { PlusCircleOutlined } from '@ant-design/icons-vue';
import { getFormSchemas } from './config';
import { ExtensionDesc } from '/@/api/device/model/modelOfMatterModel';
const show = ref(false);
const props = withDefaults(
defineProps<{
value?: ExtensionDesc;
disabled?: boolean;
}>(),
{
value: () => ({} as ExtensionDesc),
}
);
const emit = defineEmits(['update:value']);
const [registerForm, { setFieldsValue, getFieldsValue, setProps, validate, resetFields }] =
useForm({
schemas: getFormSchemas(),
showActionButtonGroup: false,
});
const handleClick = async () => {
show.value = true;
await nextTick();
resetFields();
setProps({ disabled: props.disabled });
setFieldsValue(props.value);
};
const handleSubmit = async () => {
await validate();
const value = getFieldsValue();
emit('update:value', value);
show.value = false;
};
watch(show, async (value) => {
if (value) {
await nextTick();
setFieldsValue({ ...props.value });
}
});
</script>
<template>
<section>
<Button type="link" @click="handleClick"><PlusCircleOutlined />新增扩展描述</Button>
<BasicModal title="扩展描述" v-model:visible="show" @ok="handleSubmit" :show-ok-btn="!disabled">
<BasicForm class="extension-form" @register="registerForm" />
</BasicModal>
</section>
</template>
<style lang="less" scoped>
.extension-form {
:deep(.ant-input-number) {
width: 100%;
}
}
</style>