AddParamsModal.vue
1.71 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
<template>
<div>
<BasicModal
:title="getTitle"
:maskClosable="false"
v-bind="$attrs"
width="45rem"
@register="register"
@ok="handleSubmit"
@cancel="handleCancel"
>
<AddParamForm ref="AddParamFormRef" />
</BasicModal>
</div>
</template>
<script lang="ts" setup>
import { ref, computed, reactive } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import AddParamForm from './AddParamForm.vue';
const emits = defineEmits(['register', 'data']);
const setEditData: any = reactive({
getEditData: {},
});
const AddParamFormRef = ref<InstanceType<typeof AddParamForm>>();
const isUpdate = ref(false);
const isFlag = ref('');
const getTitle = computed(() => (!isUpdate.value ? '编辑参数' : '新增参数'));
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ loading: true });
handleCancel(false);
isUpdate.value = data.isUpdate;
isFlag.value = data.flag;
AddParamFormRef.value?.setFormData(data.record);
setEditData.getEditData = data.record;
setModalProps({ loading: false });
});
const handleCancel = (flag) => {
AddParamFormRef.value?.resetFormData();
if (flag) {
closeModal();
}
};
const handleSubmit = async () => {
const value = await AddParamFormRef.value?.getFormData();
if (!value) return;
emits(
'data',
{
...value,
...{ id: !isUpdate.value ? setEditData.getEditData.id : null },
...{ index: !isUpdate.value ? setEditData.getEditData.index : null },
},
isFlag.value
);
handleCancel(true);
};
defineExpose({});
</script>
<style lang="less" scope></style>