diff --git a/src/views/rule-engine/Scene/Save/Device/CheckItem.vue b/src/views/rule-engine/Scene/Save/Device/CheckItem.vue new file mode 100644 index 00000000..fd9e62b6 --- /dev/null +++ b/src/views/rule-engine/Scene/Save/Device/CheckItem.vue @@ -0,0 +1,128 @@ + + + + + \ No newline at end of file diff --git a/src/views/rule-engine/Scene/Save/Device/index.vue b/src/views/rule-engine/Scene/Save/Device/index.vue index f5026a08..ff4b5efa 100644 --- a/src/views/rule-engine/Scene/Save/Device/index.vue +++ b/src/views/rule-engine/Scene/Save/Device/index.vue @@ -7,13 +7,15 @@ - - - </AddButton> - <AddModel v-if='visible' @cancel='visible = false' @save='save' :value='data.trigger.device' :options='data.options.trigger' /> + + <AddButton + style='width: 100%' + @click='visible = true' + > + <Title :options='data.options.trigger' /> + </AddButton> + <AddModel v-if='visible' @cancel='visible = false' @save='save' :value='data.trigger.device' :options='data.options.trigger' /> + <CheckItem /> </j-form-item> <Terms /> </div> @@ -28,6 +30,7 @@ import Title from '../components/Title.vue' import Terms from '../components/Terms' import type { TriggerDevice } from '@/views/rule-engine/Scene/typings' import { EventEmitter, DeviceEmitterKey } from '@/views/rule-engine/Scene/Save/util' +import CheckItem from './CheckItem.vue' const sceneStore = useSceneStore() const { data } = storeToRefs(sceneStore) @@ -38,6 +41,21 @@ const rules = [{ validator(_: any, v: any) { if (!v) { return Promise.reject(new Error('请配置设备触发规则')); + } else { + console.log('device-validator', v) + if ( + !v.productId || + (['fixed', 'org'].includes(v.selector) && !v.selectorValues) || + (v.operation?.operator === 'readProperty' && !v.operation!.readProperties.length) || + (v.operation?.operator === 'writeProperty' && !Object.keys(v.operation!.writeProperties).length) || + (v.operation?.operator === 'invokeFunction' && !v.operation.functionId) || + (v.operation?.operator === 'reportEvent' && !v.operation.eventId) + ) { + return Promise.reject(new Error('该数据已发生变更,请重新配置')); + } + // 判断产品 + // 判断设备或者组织 + // 判断属性、事件、功能 } return Promise.resolve(); }, diff --git a/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue b/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue index e102fb81..941d9cb1 100644 --- a/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue +++ b/src/views/rule-engine/Scene/Save/action/ListItem/CheckItem.vue @@ -48,28 +48,33 @@ const formTouchOff = () => { const checkDeviceDelete = async () => { const item = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device const proResp = await queryProductList({ terms: [{ terms: [{ column: 'id', termType: 'eq', value: item!.productId }]}]}) - const productDetail = proResp?.result?.data?.[0] if (proResp.success && (proResp.result as any)?.total === 0 && item && item.productId) { // 产品已删除 _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.productId = undefined formTouchOff() return } - const metadata = JSON.parse(productDetail?.metadata || '{}') + const productDetail = proResp?.result?.data?.[0] + let metadata = JSON.parse(productDetail?.metadata || '{}') if (item?.selector === 'fixed') { let hasDevice = false if (item!.selectorValues) { const deviceList = item!.selectorValues?.map(item => item.value) || [] const deviceResp = await deviceQuery({ terms: [{ terms: [{ column: 'id', termType: 'in', value: deviceList.toString() }]}]}) hasDevice = deviceResp.success && (deviceResp.result as any)?.total === (item!.selectorValues?.length || 0) + + if (item!.selectorValues!.length === 1 && hasDevice) { + const deviceDetail = deviceResp?.result?.data?.[0] + metadata = JSON.parse(deviceDetail?.metadata || '{}') // 只选中一个设备,以设备物模型为准 + } } - console.log('hasDevice', item!.selectorValues) if (!hasDevice) { // 某一个设备被删除 _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.selectorValues = undefined _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.changeData = true formTouchOff() return } + } else if (item!.selector === 'context') { // 如果是按变量,校验上一个设备输出的产品id if (props.name === 0) { _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.upperKey = undefined