Showing
4 changed files
with
63 additions
and
143 deletions
... | ... | @@ -12,8 +12,10 @@ import { findDictItemByCode } from '/@/api/system/dict'; |
12 | 12 | import { deviceProfile } from '/@/api/device/deviceManager'; |
13 | 13 | import { getModelServices } from '/@/api/device/modelOfMatter'; |
14 | 14 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
15 | +import useCommonFun from '../hooks/useCommonFun'; | |
15 | 16 | |
16 | -type TOption = { | |
17 | +const { useByProductGetAttribute } = useCommonFun(); | |
18 | +export type TOption = { | |
17 | 19 | label: string; |
18 | 20 | value: string; |
19 | 21 | }; |
... | ... | @@ -217,27 +219,10 @@ export const trigger_condition_schema: FormSchema[] = [ |
217 | 219 | onChange: async (e) => { |
218 | 220 | if (e) { |
219 | 221 | setFieldsValue({ type2: '' }); |
222 | + setFieldsValue({ entityId: [] }); | |
220 | 223 | const res = await getAttribute(e); |
221 | 224 | const options = ref<TOption[]>([]); |
222 | - const obj = (options) => | |
223 | - updateSchema({ | |
224 | - field: 'type2', | |
225 | - componentProps: { | |
226 | - placeholder: '请选择属性', | |
227 | - options, | |
228 | - }, | |
229 | - }); | |
230 | - if (Array.isArray(res)) { | |
231 | - options.value = res.map((m) => { | |
232 | - return { | |
233 | - label: m?.identifier, | |
234 | - value: m?.identifier, | |
235 | - }; | |
236 | - }); | |
237 | - obj(options.value); | |
238 | - } else { | |
239 | - obj(options.value); | |
240 | - } | |
225 | + useByProductGetAttribute(res, updateSchema, options); | |
241 | 226 | } |
242 | 227 | }, |
243 | 228 | }; |
... | ... | @@ -260,10 +245,22 @@ export const trigger_condition_schema: FormSchema[] = [ |
260 | 245 | { |
261 | 246 | field: 'entityId', |
262 | 247 | label: '', |
263 | - component: 'Select', | |
264 | - componentProps: { | |
265 | - placeholder: '请选择设备', | |
266 | - mode: 'multiple', | |
248 | + component: 'ApiSelect', | |
249 | + componentProps: ({ formModel }) => { | |
250 | + const deviceProfileId = formModel['deviceProfileId']; | |
251 | + if (unref(organizationId)) { | |
252 | + return { | |
253 | + placeholder: '请选择设备', | |
254 | + mode: 'multiple', | |
255 | + api: byOrganizationIdGetMasterDevice, | |
256 | + params: { | |
257 | + organizationId: unref(organizationId), | |
258 | + deviceProfileId, | |
259 | + }, | |
260 | + labelField: 'name', | |
261 | + valueField: 'id', | |
262 | + }; | |
263 | + } | |
267 | 264 | }, |
268 | 265 | ifShow: ({ values }) => isPart(values.device), |
269 | 266 | colProps: { span: 6 }, | ... | ... |
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | import { CollapseContainer } from '/@/components/Container/index'; |
63 | 63 | import { BasicForm, useForm } from '/@/components/Form/index'; |
64 | 64 | import { Card, Select, Input, Tooltip } from 'ant-design-vue'; |
65 | - import { trigger_condition_schema } from '../config/config.data'; | |
65 | + import { trigger_condition_schema, TOption } from '../config/config.data'; | |
66 | 66 | import { getAttribute } from '/@/api/ruleengine/ruleengineApi'; |
67 | 67 | import ConditionScreening from './ConditionScreening.vue'; |
68 | 68 | import { scheduleOptions, timeUnitOptions, options } from '../config/formatData'; |
... | ... | @@ -70,7 +70,9 @@ |
70 | 70 | import AlarmSchedule from './AlarmSchedule.vue'; |
71 | 71 | import { useModal } from '/@/components/Modal'; |
72 | 72 | import { cloneDeep } from 'lodash-es'; |
73 | + import useCommonFun from '../hooks/useCommonFun'; | |
73 | 74 | |
75 | + const { useByProductGetAttribute } = useCommonFun(); | |
74 | 76 | defineProps({ |
75 | 77 | index: { |
76 | 78 | type: Number, |
... | ... | @@ -100,40 +102,8 @@ |
100 | 102 | }; |
101 | 103 | |
102 | 104 | const updateFieldDeviceId = (deviceList: any[], _, isUpdate) => { |
103 | - if (isUpdate) { | |
104 | - updateSchema({ | |
105 | - field: 'entityId', | |
106 | - componentProps: { | |
107 | - options: deviceList, | |
108 | - }, | |
109 | - }); | |
110 | - } | |
111 | - //新增、编辑都会触发onChang事件 | |
112 | - updateSchema({ | |
113 | - field: 'device', | |
114 | - componentProps: { | |
115 | - options: [ | |
116 | - { label: '全部', value: 'ALL' }, | |
117 | - { label: '部分', value: 'PART' }, | |
118 | - ], | |
119 | - async onChange(e) { | |
120 | - setFieldsValue({ entityId: [] }); | |
121 | - if (e) { | |
122 | - //fengtao | |
123 | - if (e == 'ALL') { | |
124 | - } else { | |
125 | - updateSchema({ | |
126 | - field: 'entityId', | |
127 | - componentProps: { | |
128 | - options: deviceList, | |
129 | - }, | |
130 | - }); | |
131 | - } | |
132 | - //fengtao | |
133 | - } | |
134 | - }, | |
135 | - }, | |
136 | - }); | |
105 | + console.log(deviceList); | |
106 | + console.log(isUpdate); | |
137 | 107 | }; |
138 | 108 | |
139 | 109 | const resetFieldsValueFunc = () => resetFields(); |
... | ... | @@ -143,30 +113,8 @@ |
143 | 113 | }; |
144 | 114 | const updateFieldAttributeFunc = async (e) => { |
145 | 115 | const res = await getAttribute(e); |
146 | - let options: any = []; | |
147 | - if (Array.isArray(res)) { | |
148 | - options = res.map((m) => { | |
149 | - return { | |
150 | - label: m?.identifier, | |
151 | - value: m?.identifier, | |
152 | - }; | |
153 | - }); | |
154 | - updateSchema({ | |
155 | - field: 'type2', | |
156 | - componentProps: { | |
157 | - placeholder: '请选择属性', | |
158 | - options, | |
159 | - }, | |
160 | - }); | |
161 | - } else { | |
162 | - updateSchema({ | |
163 | - field: 'type2', | |
164 | - componentProps: { | |
165 | - placeholder: '请选择属性', | |
166 | - options, | |
167 | - }, | |
168 | - }); | |
169 | - } | |
116 | + const options = ref<TOption[]>([]); | |
117 | + useByProductGetAttribute(res, updateSchema, options); | |
170 | 118 | }; |
171 | 119 | //TODO-fengtao |
172 | 120 | const schedule = ref('ANY_TIME'); | ... | ... |
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | import { BasicForm, useForm } from '/@/components/Form/index'; |
63 | 63 | import { Icon } from '/@/components/Icon'; |
64 | 64 | import { Tooltip, Card, Select, Input } from 'ant-design-vue'; |
65 | - import { trigger_condition_schema } from '../config/config.data'; | |
65 | + import { trigger_condition_schema, TOption } from '../config/config.data'; | |
66 | 66 | import { getAttribute } from '/@/api/ruleengine/ruleengineApi'; |
67 | 67 | import ConditionScreening from './ConditionScreening.vue'; |
68 | 68 | import { scheduleOptions, timeUnitOptions, options } from '../config/formatData'; |
... | ... | @@ -70,7 +70,9 @@ |
70 | 70 | import { useModal } from '/@/components/Modal'; |
71 | 71 | import { cloneDeep } from 'lodash-es'; |
72 | 72 | import { useMessage } from '/@/hooks/web/useMessage'; |
73 | + import useCommonFun from '../hooks/useCommonFun'; | |
73 | 74 | |
75 | + const { useByProductGetAttribute } = useCommonFun(); | |
74 | 76 | defineProps({ |
75 | 77 | title: { |
76 | 78 | type: String, |
... | ... | @@ -140,41 +142,8 @@ |
140 | 142 | |
141 | 143 | //TODO-fengtao |
142 | 144 | const updateFieldDeviceId = (deviceList: any[], _, isUpdate) => { |
143 | - //用于编辑回显 | |
144 | - if (isUpdate.value) { | |
145 | - updateSchema({ | |
146 | - field: 'entityId', | |
147 | - componentProps: { | |
148 | - options: deviceList, | |
149 | - }, | |
150 | - }); | |
151 | - } | |
152 | - //新增、编辑都会触发onChang事件 | |
153 | - updateSchema({ | |
154 | - field: 'device', | |
155 | - componentProps: { | |
156 | - options: [ | |
157 | - { label: '全部', value: 'ALL' }, | |
158 | - { label: '部分', value: 'PART' }, | |
159 | - ], | |
160 | - async onChange(e) { | |
161 | - setFieldsValue({ entityId: [] }); | |
162 | - if (e) { | |
163 | - //fengtao | |
164 | - if (e == 'ALL') { | |
165 | - } else { | |
166 | - updateSchema({ | |
167 | - field: 'entityId', | |
168 | - componentProps: { | |
169 | - options: deviceList, | |
170 | - }, | |
171 | - }); | |
172 | - } | |
173 | - //fengtao | |
174 | - } | |
175 | - }, | |
176 | - }, | |
177 | - }); | |
145 | + console.log(deviceList); | |
146 | + console.log(isUpdate); | |
178 | 147 | }; |
179 | 148 | //TODO-fengtao |
180 | 149 | const resetFieldsValueFunc = () => { |
... | ... | @@ -188,30 +157,8 @@ |
188 | 157 | //TODO-fengtao |
189 | 158 | const updateFieldAttributeFunc = async (e) => { |
190 | 159 | const res = await getAttribute(e); |
191 | - let options: any = []; | |
192 | - if (Array.isArray(res)) { | |
193 | - options = res.map((m) => { | |
194 | - return { | |
195 | - label: m?.identifier, | |
196 | - value: m?.identifier, | |
197 | - }; | |
198 | - }); | |
199 | - updateSchema({ | |
200 | - field: 'type2', | |
201 | - componentProps: { | |
202 | - placeholder: '请选择属性', | |
203 | - options, | |
204 | - }, | |
205 | - }); | |
206 | - } else { | |
207 | - updateSchema({ | |
208 | - field: 'type2', | |
209 | - componentProps: { | |
210 | - placeholder: '请选择属性', | |
211 | - options, | |
212 | - }, | |
213 | - }); | |
214 | - } | |
160 | + const options = ref<TOption[]>([]); | |
161 | + useByProductGetAttribute(res, updateSchema, options); | |
215 | 162 | }; |
216 | 163 | //TODO-fengtao |
217 | 164 | const handleDelete = (params: { index: number; title: string }) => { | ... | ... |
1 | +export default () => { | |
2 | + //根据产品获取对应属性 | |
3 | + const useByProductGetAttribute = (res, callback, opt) => { | |
4 | + const getAttr = (opt) => | |
5 | + callback({ | |
6 | + field: 'type2', | |
7 | + componentProps: { | |
8 | + placeholder: '请选择属性', | |
9 | + opt, | |
10 | + }, | |
11 | + }); | |
12 | + if (Array.isArray(res)) { | |
13 | + opt = res.map((m) => { | |
14 | + return { | |
15 | + label: m?.identifier, | |
16 | + value: m?.identifier, | |
17 | + }; | |
18 | + }); | |
19 | + getAttr(opt); | |
20 | + } else { | |
21 | + getAttr(opt); | |
22 | + } | |
23 | + }; | |
24 | + | |
25 | + return { | |
26 | + useByProductGetAttribute, | |
27 | + }; | |
28 | +}; | ... | ... |