fix: 修改运行状态写入bool下拉显示问题

This commit is contained in:
100011797 2023-06-02 10:04:20 +08:00
parent f0d7cbddc5
commit af5d2e08f6
2 changed files with 64 additions and 33 deletions

View File

@ -7,22 +7,26 @@
@cancel="handleCancel"
:confirmLoading="loading"
>
<j-alert message="当数据来源为设备时,填写的值将下发到设备" type="warning" showIcon />
<j-form :rules="rules" layout="vertical" ref="formRef" :model="modelRef" style="margin-top: 20px">
<j-form-item name="propertyValue" :label="data?.name || '自定义属性'">
<j-alert
message="当数据来源为设备时,填写的值将下发到设备"
type="warning"
showIcon
/>
<j-form
:rules="rules"
layout="vertical"
ref="formRef"
:model="modelRef"
style="margin-top: 20px"
>
<j-form-item
name="propertyValue"
:label="data?.name || '自定义属性'"
>
<ValueItem
v-model:modelValue="modelRef.propertyValue"
:itemType="data?.valueType?.type || data?.dataType"
:options="
(data?.valueType?.type || data?.dataType) === 'enum'
? (data?.valueType?.elements || []).map((item) => {
return {
label: item?.text,
value: item?.value
};
})
: undefined
"
:options="options"
/>
</j-form-item>
</j-form>
@ -30,57 +34,84 @@
</template>
<script lang="ts" setup>
import { setProperty } from '@/api/device/instance'
import { useInstanceStore } from "@/store/instance"
import { setProperty } from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';
import { message } from 'jetlinks-ui-components';
const props = defineProps({
data: {
type: Object,
default: () => {}
}
})
default: () => {},
},
});
const emit = defineEmits(['close']);
const loading = ref<boolean>(false)
const instanceStore = useInstanceStore()
const loading = ref<boolean>(false);
const instanceStore = useInstanceStore();
const formRef = ref();
const modelRef = reactive({
propertyValue: undefined
propertyValue: undefined,
});
const handleCancel = () => {
emit('close')
emit('close');
};
const options = computed(() => {
const _type = props.data?.valueType?.type || props.data?.dataType;
if (_type === 'enum') {
return (props.data?.valueType?.elements || []).map((item: any) => {
return {
label: item?.text,
value: item?.value,
};
});
}
if (_type === 'boolean') {
return [
{
label: props.data?.valueType?.falseText,
value: props.data?.valueType?.falseValue,
},
{
label: props.data?.valueType?.trueText,
value: props.data?.valueType?.trueValue,
}
];
}
return undefined;
});
const rules = {
propertyValue: [
{
required: true,
message: '该字段是必填字段',
}
},
],
}
};
const handleSave = () => {
formRef.value
.validate()
.then(async () => {
loading.value = true;
const resp = await setProperty(instanceStore.current?.id || '', {[props.data?.id]: toRaw(modelRef)?.propertyValue}).finally(() => {
loading.value = false
})
const resp = await setProperty(instanceStore.current?.id || '', {
[props.data?.id]: toRaw(modelRef)?.propertyValue,
}).finally(() => {
loading.value = false;
});
if (resp.status === 200) {
message.success('操作成功!');
emit('close')
emit('close');
formRef.value.resetFields();
}
})
.catch((err: any) => {
console.log('error', err);
});
}
};
</script>

View File

@ -40,7 +40,7 @@ export const mergeArr = (oldData: Array<any>, newData: Array<any>) => {
}
if(oldItem && newItem){
oldItem = { ...oldData,...omit(newItem, ['children'])}
oldItem.sortIndex = newItem?.sortIndex
}
if (!oldItem.children && newItem.children) {