SelectDevice.vue
3 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
<template>
<div v-for="param in dynamicInput.params" :key="param.name" class="mt-4 flex gap-2">
<a-input :disabled="true" v-model:value="param.name" class="w-1/2 flex-1" />
<Select
placeholder="请选择设备"
v-model:value="param.deviceList"
class="!w-1/2"
:options="selectOptions"
v-bind="createPickerSearch()"
@change="emitChange"
mode="multiple"
allowClear
/>
</div>
</template>
<script lang="ts">
export default {
inheritAttrs: false,
};
</script>
<script lang="ts" setup name="SelectAttributes">
import { reactive, UnwrapRef, watchEffect, ref, watch } from 'vue';
import { propTypes } from '/@/utils/propTypes';
import { Select } from 'ant-design-vue';
import { createPickerSearch } from '/@/utils/pickerSearch';
import { byOrganizationIdGetMasterDevice } from '/@/api/ruleengine/ruleengineApi';
const props = defineProps({
value: propTypes.object.def({}),
organizationId: {
type: String,
required: true,
},
});
const selectOptions: any = ref([]);
//动态数据
const dynamicInput: UnwrapRef<{ params: any[] }> = reactive({ params: [] });
const initVal = async () => {
if (props.value) {
dynamicInput.params.push({
name: props.value.label,
profileId: props.value.value,
deviceType: props.value?.deviceType,
transportType: props.value?.transportType,
deviceList: props.value.deviceList?.filter(Boolean)?.map((item) => item.deviceId),
});
}
};
watch(
() => props.organizationId,
async () => {
if (props.organizationId) {
const resp = await byOrganizationIdGetMasterDevice({
organizationId: props.organizationId,
deviceProfileId: props.value.value,
});
selectOptions.value = resp.map((item) => ({
...item,
label: item.alias || item.name,
value: item.tbDeviceId,
}));
}
},
{
immediate: true,
}
);
//数值改变
const valEffect = watchEffect(() => {
initVal();
});
valEffect();
//chang改变
const emitChange = () => {
const tempDeviceList: Recordable[] = []; // fix: 修改选择设备顺序问题
dynamicInput.params[0].deviceList?.forEach((item) => {
selectOptions.value?.forEach((newItem) => {
if (item === newItem.value) {
tempDeviceList.push({
name: newItem.label,
deviceId: newItem.value,
codeType: newItem.codeType,
});
}
});
});
return {
...dynamicInput.params[0],
deviceList: tempDeviceList.filter(Boolean), // 过滤假值
};
};
defineExpose({
emitChange,
});
</script>
<style scoped lang="css">
.dynamic-delete-button {
cursor: pointer;
position: relative;
top: 4px;
font-size: 24px;
color: #999;
transition: all 0.3s;
}
.dynamic-delete-button:hover {
color: #777;
}
.dynamic-delete-button[disabled] {
cursor: not-allowed;
opacity: 0.5;
}
</style>