fix: 优化物模型-事件定义

This commit is contained in:
xieyonghong 2023-07-06 22:33:29 +08:00
parent a869162799
commit d76aa3f65c
6 changed files with 88 additions and 30 deletions

View File

@ -18,6 +18,7 @@
@click="handleAddClick()"
:disabled="hasOperate('add', type)"
:tooltip="{
placement: hasOperate('add', type) ? 'topRight' : 'top',
title: hasOperate('add', type)
? '当前的存储方式不支持新增'
: '新增',
@ -36,6 +37,7 @@
title: hasOperate('add', type)
? '当前的存储方式不支持新增'
: '保存',
placement: hasOperate('add', type) ? 'topRight' : 'top',
}"
>
保存
@ -88,7 +90,6 @@
</template>
<template #inputs="{ data }">
<InputParams v-model:value="dataSource[data.index]" />
{{ data.record.inputs?.map(item => item.name).join(',') }}
</template>
<template #output="{ data }">
{{ data.record.output?.type }}
@ -100,7 +101,7 @@
{{ levelMap?.[data.record.expands?.level] || '-' }}
</template>
<template #properties="{ data }">
{{ data.record.valueType?.properties?.map(item => item.name).join(',') }}
<ConfigParams v-model:value="dataSource[data.index]" />
</template>
<template #outInput>
object
@ -203,7 +204,7 @@ import { useMetadata, useOperateLimits } from './hooks';
import { useColumns } from './columns';
import { levelMap, sourceMap, expandsType, limitsMap } from './utils';
import Rule from '@/components/Metadata/Rule';
import { Source, OtherSetting, InputParams } from './components';
import { Source, OtherSetting, InputParams, ConfigParams } from './components';
import { saveProductVirtualProperty } from '@/api/device/product';
import { saveDeviceVirtualProperty } from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';

View File

@ -137,10 +137,7 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
{
title: '配置参数',
dataIndex: 'properties',
type: 'components',
components: {
name: ConfigParams,
}
width: 100
},
{
title: '说明',

View File

@ -3,23 +3,26 @@
<div class="values-test">
{{ text }}
</div>
<OtherConfigInfo :value="formData"></OtherConfigInfo>
<DataTableEnum v-if="formData.type === 'enum'" v-model:value="formData" />
<DataTableBoolean v-else-if="formData.type === 'boolean'" v-model:value="formData" />
<!-- <OtherConfigInfo :value="formData"></OtherConfigInfo> -->
<DataTableEnum placement="topRight" v-if="formData.type === 'enum'" v-model:value="formData" />
<DataTableBoolean placement="topRight" v-else-if="formData.type === 'boolean'" v-model:value="formData" />
<DataTableDouble
placement="topRight"
v-else-if="['float', 'double'].includes(formData.type)"
:options="options"
v-model:value="formData"
/>
<DataTableArray
v-else-if="formData.type === 'array'"
placement="topRight"
v-model:value="formData.unit"
/>
<DataTableFile v-else-if="formData.type === 'file'" v-model:value="formData.fileType"/>
<DataTableDate v-else-if="formData.type === 'date'" v-model:value="formData.date"/>
<DataTableFile v-else-if="formData.type === 'file'" v-model:value="formData.fileType" placement="topRight"/>
<DataTableDate v-else-if="formData.type === 'date'" v-model:value="formData.date" placement="topRight"/>
<DataTableString
v-else-if="['string', 'password'].includes(formData.type)"
v-model:value="formData.expands.maxLength"
placement="topRight"
/>
</div>
</template>
@ -83,13 +86,13 @@ const type = ref(props.value?.valueType?.type);
console.log(props.value);
console.log('dataTypeObject1', formData.value);
const emit = defineEmits(['update:value', 'cancel']);
const options = ref<{ label: string; value: string }[]>([]);
const text = computed(() => {
console.log(props.value);
console.log('dataTypeObject2', formData.value);
const value = props.value?.valueType
if (value) {
switch(type.value) {
@ -114,6 +117,7 @@ const text = computed(() => {
watch(
() => formData.value?.type,
() => {
console.log('dataTypeObject3', formData.value);
if (formData.value?.type && ['float', 'double', 'int', 'long'].includes(formData.value.type)) {
const res = getUnit().then((res) => {
if (res.success) {

View File

@ -1,17 +1,16 @@
<template>
<div class="metadata-config-params">
<div class="metadata-config-value">
{{ value?.map((item: any) => item.name).join(',') }}
</div>
<DataTableObject v-model:value="value" :columns="columns" @confirm="confirm">
<DataTableObject v-model:value="value" :columns="columns" @confirm="confirm">
<template #valueType="{ data }">
<span>{{ data.record.valueType?.type }}</span>
</template>
<template #config="{ data }">
<OtherConfigInfo :value="data.record.valueType"></OtherConfigInfo>
</template>
<j-button>
<AIcon type="SettingOutlined" />
配置
</j-button>
</DataTableObject>
</div>
</template>
<script setup lang="ts" name="InputParams">
@ -23,8 +22,30 @@ import {
import { OtherConfigInfo, ValueObject } from '../index'
const columns = [
{ title: '参数标识', dataIndex: 'id', type: 'text' },
{ title: '参数名称', dataIndex: 'name', type: 'text' },
{
title: '参数标识',
dataIndex: 'id',
type: 'text',
form: {
required: true,
rules: [{
required: true,
message: '请输入参数标识'
}]
}
},
{
title: '参数名称',
dataIndex: 'name',
type: 'text',
form: {
required: true,
rules: [{
required: true,
message: '请输入参数标识名称'
}]
}
},
{
title: '数据类型',
type: 'components',

View File

@ -12,13 +12,34 @@
v-else-if="type === 'object'"
v-model:value="data.properties"
:columns="[
{ title: '参数标识', dataIndex: 'id', type: 'text' },
{ title: '参数名称', dataIndex: 'name', type: 'text' },
{
title: '参数标识',
dataIndex: 'id',
type: 'text',
form: {
required: true,
rules: [{
required: true,
message: '请输入参数标识'
}]
}
},
{
title: '参数名称',
dataIndex: 'name',
type: 'text',
form: {
required: true,
rules: [{
required: true,
message: '请输入参数标识名称'
}]
}
},
{
title: '数据类型',
type: 'components',
dataIndex: 'valueTypes',
dataIndex: 'valueType',
components: {
name: Type,
}
@ -26,7 +47,7 @@
{
title: '其他配置',
type: 'components',
dataIndex: 'valueType',
dataIndex: 'config',
components: {
name: DataTypeObjectChild
}
@ -39,7 +60,14 @@
]"
@confirm="valueChange"
:onAdd="addItem"
/>
>
<template #valueType="{ data }">
<span>{{ data.record.valueType?.type }}</span>
</template>
<template #config="{ data }">
<OtherConfigInfo :value="data.record.valueType"></OtherConfigInfo>
</template>
</DataTableObject>
<DataTableEnum v-else-if="type === 'enum'" v-model:value="data" @confirm="valueChange"/>
<DataTableBoolean v-else-if="type === 'boolean'" v-model:value="data" @confirm="valueChange"/>
<DataTableDouble
@ -82,6 +110,7 @@ import {
import DataTypeObjectChild from '../DataTypeObjectChild.vue';
import { cloneDeep } from 'lodash-es';
import {typeSelectChange} from "@/views/device/components/Metadata/Base/columns";
import { OtherConfigInfo } from '../index'
import Type from './Type.vue'
const props = defineProps({

View File

@ -1,6 +1,6 @@
<template>
<DataTableTypeSelect
v-model="myValue"
v-model:value="myValue"
:filter="['object']"
@change="change"
/>
@ -26,11 +26,17 @@ const myValue = ref()
const change = (e: string) => {
const obj = typeSelectChange(e)
const _data = {...props.value}
_data.valueType = obj
myValue.value = e
_data.valueType = {
type: e,
...obj
}
emit('update:value', _data)
}
watch(() => props.value, () => {
console.log(props.value);
myValue.value = props.value?.valueType?.type
}, { immediate: true, deep: true})