index.vue
4.6 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
<BasicModal
v-bind="$attrs"
@register="registerModal"
:title="t('common.assignDevices')"
:canFullscreen="false"
centered
:minHeight="300"
@ok="handleEventIsDistribution"
@cancel="handleEventIsCancel"
:okText="t('common.assign')"
>
<div class="!flex items-center gap-5">
<BasicForm @register="register" class="device-picker" />
</div>
</BasicModal>
</template>
<script lang="ts" setup>
import { BasicModal, useModalInner } from '/@/components/Modal';
import { useMessage } from '/@/hooks/web/useMessage';
import { createPickerSearch } from '/@/utils/pickerSearch';
import { useI18n } from '/@/hooks/web/useI18n';
import { BasicForm, useForm } from '/@/components/Form';
import { getMeetTheConditionsDevice } from '/@/api/dataBoard';
import { findDictItemByCode } from '/@/api/system/dict';
import { getOrganizationList } from '/@/api/system/system';
import { DictEnum } from '/@/enums/dictEnum';
import { copyTransFun } from '/@/utils/fnUtils';
import { edgeDeviceDistribution } from '/@/api/edgeManage/edgeInstance';
const { t } = useI18n();
const emits = defineEmits(['success', 'register']);
const { createMessage } = useMessage();
const props = defineProps({
edgeId: {
type: String,
default: '',
},
});
const [registerModal, { closeModal }] = useModalInner(() => {
resetFields();
});
const [register, { resetFields, validate, setFieldsValue }] = useForm({
schemas: [
{
field: 'deviceType',
component: 'ApiSelect',
label: t('common.deviceTypeText'),
required: true,
componentProps: () => {
return {
api: findDictItemByCode,
params: {
dictCode: DictEnum.DEVICE_TYPE,
},
labelField: 'itemText',
valueField: 'itemValue',
...createPickerSearch(),
onChange() {
setFieldsValue({ deviceId: [] });
},
};
},
},
{
field: 'organizationId',
component: 'ApiTreeSelect',
label: t('common.organizationId'),
required: true,
componentProps: () => {
return {
api: async () => {
try {
const data = await getOrganizationList();
copyTransFun(data as any);
return data;
} catch (error) {
console.error(error);
return [];
}
},
labelField: 'name',
valueField: 'id',
childField: 'children',
dropdownStyle: { maxHeight: '300px' },
getPopupContainer: () => document.body,
onChange() {
setFieldsValue({ deviceId: [] });
},
};
},
},
{
field: 'deviceId',
label: t('common.device'),
required: true,
component: 'ApiSelect',
componentProps: ({ formModel }) => {
const deviceType = Reflect.get(formModel, 'deviceType');
const organizationId = Reflect.get(formModel, 'organizationId');
return {
api: async () => {
try {
if (!organizationId) return [];
const result = await getMeetTheConditionsDevice({
deviceType,
organizationId,
isEdgeDistribution: true,
edgeId: props.edgeId,
// isExcludeEdge: true,
isExcludeCloud: true,
});
return result.map((item) => ({
...item,
value: item.tbDeviceId,
label: item.alias || item.name,
}));
} catch (error) {
return [];
}
},
mode: 'multiple',
...createPickerSearch(),
};
},
},
],
showActionButtonGroup: false,
});
const handleEventIsDistribution = async () => {
if (!props.edgeId) return;
const value = await validate();
if (!value) return;
console.warn(value['deviceId']);
for (let item of value['deviceId']) await edgeDeviceDistribution(props?.edgeId, item);
createMessage.success(t('common.assignSuccessful'));
handleEventIsCancel();
emits('success');
};
const handleEventIsCancel = () => {
closeModal();
};
</script>
<style lang="less" scoped>
.device-picker {
:deep(.ant-row) {
width: 100%;
}
:deep(.ant-form-item-control-input-content) {
div > div {
width: 100%;
}
}
}
</style>