UpdateRuleChainModal.vue
1.94 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
69
70
<script lang="ts" setup>
import { ref, unref } from 'vue';
import { doBatchChangeRuleChain, doQueryRuleChainList } from '/@/api/device/deviceConfigApi';
import { BasicForm, useForm } from '/@/components/Form';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const emit = defineEmits(['register', 'success']);
const deviceProfileIds = ref<string[]>([]);
const [registerModal, { closeModal }] = useModalInner((data: ModalParamsType<string[]>) => {
resetFields();
deviceProfileIds.value = data.record;
});
const [register, { getFieldsValue, resetFields, validate }] = useForm({
layout: 'horizontal',
showActionButtonGroup: false,
schemas: [
{
field: 'targetRuleChainId',
component: 'ApiSelect',
label: t('deviceManagement.product.ruleChainText'),
required: true,
componentProps: {
api: async () => {
const result = await doQueryRuleChainList();
return result.map((item) => ({ ...item, value: item.id.id }));
},
labelField: 'name',
valueFiled: 'value',
getPopupContainer: () => document.body,
},
},
],
});
const { createMessage } = useMessage();
async function handleSubmit() {
await validate();
const result = getFieldsValue() as Record<'targetRuleChainId', string>;
await doBatchChangeRuleChain({
...result,
deviceProfileIds: unref(deviceProfileIds),
});
createMessage.success(t('layout.setting.operatingTitle'));
emit('success');
closeModal();
}
</script>
<template>
<BasicModal
:title="t('deviceManagement.product.updateRuleChain')"
:min-height="100"
:width="300"
@ok="handleSubmit"
@register="registerModal"
>
<BasicForm @register="register" />
</BasicModal>
</template>