diff --git a/src/components/GeoComponent/index.vue b/src/components/GeoComponent/index.vue
index 3c7eab82..ceb4f8b8 100644
--- a/src/components/GeoComponent/index.vue
+++ b/src/components/GeoComponent/index.vue
@@ -45,6 +45,7 @@ initAMapApiLoader({
interface EmitProps {
(e: 'update:point', data: string): void;
+ (e: 'change', data: string): void;
}
const props = defineProps({
point: { type: [Number, String], default: '' },
@@ -59,6 +60,7 @@ const inputPoint = computed({
set: (val: any) => {
mapPoint.value = val;
emit('update:point', val);
+ emit('change', val);
},
});
diff --git a/src/components/ValueItem/index.vue b/src/components/ValueItem/index.vue
index 0dbf02fb..79725601 100644
--- a/src/components/ValueItem/index.vue
+++ b/src/components/ValueItem/index.vue
@@ -46,6 +46,7 @@
('');
const handleItemModalSubmit = () => {
myValue.value = objectValue.value.replace(/[\r\n]\s*/g, '');
modalVis.value = false;
- emit('change', myValue.value);
+ emit('change', objectValue.value)
};
// 文件上传
diff --git a/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue b/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue
index f2dc5ad0..d6533ba7 100644
--- a/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue
+++ b/src/views/rule-engine/Scene/Save/action/Device/actions/WriteProperty.vue
@@ -8,8 +8,8 @@
{{ item?.name }}
-
+
@@ -73,7 +72,7 @@ const props = defineProps({
},
});
-const emit = defineEmits(['update:value']);
+const emit = defineEmits(['update:value', 'change']);
const propertyFormRef = ref();
@@ -83,6 +82,7 @@ const propertyModelRef = reactive({
source: 'fixed',
});
+
const getType = computed(() => {
return props.metadata.properties.find(
(item: any) => item.id === propertyModelRef.properties,
@@ -154,7 +154,7 @@ const handleOptions = computed(() => {
const onChange = () => {
propertyModelRef.propertiesValue = undefined;
- propertyModelRef.source = 'fixed'
+ propertyModelRef.source = 'fixed';
emit('update:value', {
[`${propertyModelRef.properties}`]: {
value: propertyModelRef?.propertiesValue,
@@ -169,8 +169,9 @@ const onValueChange = () => {
value: propertyModelRef?.propertiesValue,
source: propertyModelRef?.source,
},
- }
+ };
emit('update:value', obj);
+ emit('change', propertyModelRef?.propertiesValue)
};
watch(
@@ -187,4 +188,19 @@ watch(
},
{ deep: true, immediate: true },
);
+
+const onSave = () => {
+ return new Promise((resolve, reject) => {
+ propertyFormRef.value
+ .validate()
+ .then(() => {
+ resolve(true);
+ })
+ .catch((err: any) => {
+ reject(err);
+ });
+ });
+};
+
+defineExpose({ onSave });
\ No newline at end of file
diff --git a/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue b/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue
index f935083e..e6004fd6 100644
--- a/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue
+++ b/src/views/rule-engine/Scene/Save/action/Device/actions/index.vue
@@ -22,7 +22,7 @@
showSearch
placeholder="请选择功能"
v-model:value="modelRef.message.functionId"
- @select='functionSelect'
+ @select="functionSelect"
>
{{ item?.name }}
@@ -83,7 +87,7 @@ import EditTable from './EditTable.vue';
import WriteProperty from './WriteProperty.vue';
import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia';
-import { getParams } from '../../../util'
+import { getParams } from '../../../util';
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
@@ -137,26 +141,39 @@ const modelRef = reactive({
properties: undefined,
inputs: [],
},
+ propertiesValue: '',
});
-const functionSelect = () => {
- modelRef.message.inputs = []
-}
+const writeFormRef = ref();
-const functionRules = [{
- validator(_: string, value: any) {
- if (!value?.length && functions.value.length) {
- return Promise.reject('请输入功能值')
- } else {
- const hasValue = value.find((item: { name: string, value: any}) => !item.value)
- if (hasValue) {
- const functionItem = functions.value.find((item: any) => item.id === hasValue.name)
- return Promise.reject(functionItem?.name ? `请输入${functionItem.name}值` : '请输入功能值')
- }
- }
- return Promise.resolve();
- }
-}]
+const functionSelect = () => {
+ modelRef.message.inputs = [];
+};
+
+const functionRules = [
+ {
+ validator(_: string, value: any) {
+ if (!value?.length && functions.value.length) {
+ return Promise.reject('请输入功能值');
+ } else {
+ const hasValue = value.find(
+ (item: { name: string; value: any }) => !item.value,
+ );
+ if (hasValue) {
+ const functionItem = functions.value.find(
+ (item: any) => item.id === hasValue.name,
+ );
+ return Promise.reject(
+ functionItem?.name
+ ? `请输入${functionItem.name}值`
+ : '请输入功能值',
+ );
+ }
+ }
+ return Promise.resolve();
+ },
+ },
+];
const metadata = ref<{
functions: any[];
@@ -205,15 +222,15 @@ const queryBuiltIn = async () => {
action: props.name - 1,
};
const _data = await getParams(_params, unref(data));
- builtInList.value = _data
+ builtInList.value = _data;
};
const onMessageTypeChange = (val: string) => {
- const flag = ['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)
+ const flag = ['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val);
modelRef.message = {
messageType: val,
functionId: undefined,
- properties:(flag ? undefined : []) as any,
+ properties: (flag ? undefined : []) as any,
inputs: [],
};
if (flag) {
@@ -251,7 +268,11 @@ watch(
(newVal) => {
if (newVal?.messageType) {
modelRef.message = newVal;
- if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(newVal.messageType)) {
+ if (
+ ['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(
+ newVal.messageType,
+ )
+ ) {
queryBuiltIn();
}
}
@@ -259,11 +280,21 @@ watch(
{ immediate: true },
);
+const onWriteChange = (val: string) => {
+ modelRef.propertiesValue = val;
+};
+
const onFormSave = () => {
return new Promise((resolve, reject) => {
formRef.value
.validate()
- .then((_data: any) => {
+ .then(async (_data: any) => {
+ if (writeFormRef.value) {
+ const _val = await writeFormRef.value?.onSave();
+ if (!_val) {
+ reject(false);
+ }
+ }
// 处理三种情况的值的格式
const obj = {
message: {
@@ -273,6 +304,7 @@ const onFormSave = () => {
deviceMessageType.value === 'INVOKE_FUNCTION'
? _function.value?.name
: _property.value?.name,
+ propertiesValue: modelRef.propertiesValue,
},
};
resolve(obj);
diff --git a/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue b/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue
index d3a07b0e..418e943c 100644
--- a/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue
+++ b/src/views/rule-engine/Scene/Save/action/Device/device/Device.vue
@@ -77,12 +77,12 @@ type Emit = {
const actionRef = ref();
const params = ref({
- terms: []
+ terms: [],
});
const props = defineProps({
value: {
type: Array as PropType,
- default: []
+ default: [],
},
detail: {
type: Object,
@@ -90,8 +90,8 @@ const props = defineProps({
},
productId: {
type: String,
- default: ''
- }
+ default: '',
+ },
});
const emit = defineEmits();
@@ -143,9 +143,9 @@ const handleSearch = (p: any) => {
...p,
terms: [
...p.terms,
- {terms: [{ column: 'productId', value: props?.productId }]}
- ]
- }
+ { terms: [{ column: 'productId', value: props?.productId }] },
+ ],
+ };
};
const deviceQuery = (p: any) => {
@@ -162,19 +162,26 @@ const deviceQuery = (p: any) => {
};
const handleClick = (detail: any) => {
- emit('update:value', [{ value: detail.id, name: detail.name }]);
- emit('change', detail);
+ if (props.value?.[0]?.value === detail.id) {
+ emit('update:value', undefined);
+ emit('change', {});
+ } else {
+ emit('update:value', [{ value: detail.id, name: detail.name }]);
+ emit('change', detail);
+ }
};
watchEffect(() => {
params.value = {
...params.value,
- terms: params.value?.terms ? [
- ...(params.value.terms || []),
- {terms: [{ column: 'productId', value: props?.productId }]}
- ] : [{terms: [{ column: 'productId', value: props?.productId }]}]
- }
-})
+ terms: params.value?.terms
+ ? [
+ ...(params.value.terms || []),
+ { terms: [{ column: 'productId', value: props?.productId }] },
+ ]
+ : [{ terms: [{ column: 'productId', value: props?.productId }] }],
+ };
+});