fix: 优化物模型-功能定义-(输入、输出)
This commit is contained in:
parent
7c2f4c410c
commit
9eacdb2687
|
@ -135,7 +135,7 @@ const handleDataTable = (type: string) => {
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
dataTypeTable.dataSource = {
|
dataTypeTable.dataSource = {
|
||||||
...props.data.valueType
|
...omit(props.data.valueType, ['type'])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
|
|
|
@ -32,6 +32,36 @@ const type = {
|
||||||
report: '上报',
|
report: '上报',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleTypeValue = (type:string, value: any = {}) => {
|
||||||
|
let obj: any = {}
|
||||||
|
switch (type) {
|
||||||
|
case 'array':
|
||||||
|
obj.elementType = value
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
obj.properties = value
|
||||||
|
break;
|
||||||
|
case 'int':
|
||||||
|
case 'long':
|
||||||
|
obj.unit = value
|
||||||
|
break;
|
||||||
|
case 'file':
|
||||||
|
obj.fileType = value
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
obj.format = value
|
||||||
|
break;
|
||||||
|
case 'string':
|
||||||
|
case 'password':
|
||||||
|
obj.maxLength = value
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
obj = value
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
export const typeSelectChange = (type: string) => {
|
export const typeSelectChange = (type: string) => {
|
||||||
let obj: any = {}
|
let obj: any = {}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: [String, Array],
|
type: [String, Array],
|
||||||
default: 'required'
|
default: ['expands','required']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ const emit = defineEmits(['update:value'])
|
||||||
|
|
||||||
const myValue = ref()
|
const myValue = ref()
|
||||||
|
|
||||||
const change = () => {
|
const change = (e) => {
|
||||||
const newData = { ...props.value }
|
const newData = { ...props.value }
|
||||||
set(newData, props.name, myValue.value)
|
set(newData, props.name, myValue.value)
|
||||||
console.log(newData);
|
console.log(newData, e);
|
||||||
emit('update:value', newData)
|
emit('update:value', newData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,64 +8,14 @@
|
||||||
v-model:value="_valueType.elementType"
|
v-model:value="_valueType.elementType"
|
||||||
:unitOptions="options"
|
:unitOptions="options"
|
||||||
placement="topRight"
|
placement="topRight"
|
||||||
@confirm="valueChange"
|
@confirm="(data) => {valueChange(data, 'array')}"
|
||||||
/>
|
/>
|
||||||
<DataTableObject
|
<DataTableObject
|
||||||
v-else-if="type === 'object'"
|
v-else-if="type === 'object'"
|
||||||
:value="_valueType.properties"
|
:value="_valueType.properties"
|
||||||
placement="topRight"
|
placement="topRight"
|
||||||
:columns="[
|
:columns="columns"
|
||||||
{
|
@confirm="(data) => {valueChange(data, 'object')}"
|
||||||
title: '参数标识',
|
|
||||||
dataIndex: 'id',
|
|
||||||
type: 'text',
|
|
||||||
width: 100,
|
|
||||||
form: {
|
|
||||||
required: true,
|
|
||||||
rules: [{
|
|
||||||
callback() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '参数名称',
|
|
||||||
dataIndex: 'name',
|
|
||||||
type: 'text',
|
|
||||||
width: 100,
|
|
||||||
form: {
|
|
||||||
required: true,
|
|
||||||
rules: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入参数名称'
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '数据类型',
|
|
||||||
type: 'components',
|
|
||||||
dataIndex: 'valueType',
|
|
||||||
components: {
|
|
||||||
name: ValueObject,
|
|
||||||
props: {
|
|
||||||
filter: ['object']
|
|
||||||
}
|
|
||||||
},
|
|
||||||
width: 100
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '其他配置',
|
|
||||||
dataIndex: 'config',
|
|
||||||
width: 100
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
dataIndex: 'action',
|
|
||||||
width: 60
|
|
||||||
}
|
|
||||||
]"
|
|
||||||
@confirm="valueChange"
|
|
||||||
>
|
>
|
||||||
<template #valueType="{ data }">
|
<template #valueType="{ data }">
|
||||||
{{ data.record.valueType?.type }}
|
{{ data.record.valueType?.type }}
|
||||||
|
@ -75,28 +25,29 @@
|
||||||
<ConfigModal v-model:value="data.record" />
|
<ConfigModal v-model:value="data.record" />
|
||||||
</template>
|
</template>
|
||||||
</DataTableObject>
|
</DataTableObject>
|
||||||
<DataTableEnum v-else-if="type === 'enum'" v-model:value="_valueType" placement="topRight" @confirm="valueChange"/>
|
<DataTableEnum v-else-if="type === 'enum'" v-model:value="_valueType" placement="topRight" @confirm="(data) => {valueChange(data, 'enum')}"/>
|
||||||
<DataTableBoolean v-else-if="type === 'boolean'" v-model:value="_valueType" placement="topRight" @confirm="valueChange"/>
|
<DataTableBoolean v-else-if="type === 'boolean'" v-model:value="_valueType" placement="topRight" @confirm="(data) => {valueChange(data, 'boolean')}" />
|
||||||
<DataTableDouble
|
<DataTableDouble
|
||||||
v-else-if="['float', 'double'].includes(type)"
|
v-else-if="['float', 'double'].includes(type)"
|
||||||
:options="options"
|
:options="options"
|
||||||
v-model:value="_valueType"
|
v-model:value="_valueType"
|
||||||
placement="topRight"
|
placement="topRight"
|
||||||
@confirm="valueChange"
|
@confirm="(data) => {valueChange(data, 'float')}"
|
||||||
/>
|
/>
|
||||||
<DataTableInteger
|
<DataTableInteger
|
||||||
v-else-if="['int', 'long'].includes(type)"
|
v-else-if="['int', 'long'].includes(type)"
|
||||||
:options="options"
|
:options="options"
|
||||||
v-model:value="_valueType.unit"
|
v-model:value="_valueType.unit"
|
||||||
placement="topRight"
|
placement="topRight"
|
||||||
@confirm="valueChange"
|
@confirm="(data) => {valueChange(data, 'int')}"
|
||||||
/>
|
/>
|
||||||
<DataTableFile v-else-if="type === 'file'" v-model:value="_valueType.fileType" placement="topRight" @confirm="valueChange"/>
|
<DataTableFile v-else-if="type === 'file'" v-model:value="_valueType.fileType" placement="topRight" @confirm="(data) => {valueChange(data, 'file')}"/>
|
||||||
<DataTableDate v-else-if="type === 'date'" v-model:value="_valueType.format" placement="topRight" @confirm="valueChange"/>
|
<DataTableDate v-else-if="type === 'date'" v-model:value="_valueType.format" placement="topRight" @confirm="(data) => {valueChange(data, 'date')}"/>
|
||||||
<DataTableString
|
<DataTableString
|
||||||
v-else-if="['string', 'password'].includes(type)"
|
v-else-if="['string', 'password'].includes(type)"
|
||||||
v-model:value="_valueType.maxLength"
|
v-model:value="_valueType.maxLength"
|
||||||
placement="topRight"
|
placement="topRight"
|
||||||
|
@confirm="(data) => {valueChange(data, 'string')}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -117,7 +68,7 @@ import {
|
||||||
DataTableObject,
|
DataTableObject,
|
||||||
} from 'jetlinks-ui-components';
|
} from 'jetlinks-ui-components';
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
import { typeSelectChange } from '../columns'
|
import {handleTypeValue, typeSelectChange} from '../columns'
|
||||||
import ConfigModal from './ConfigModal.vue'
|
import ConfigModal from './ConfigModal.vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
@ -127,6 +78,56 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
title: '参数标识',
|
||||||
|
dataIndex: 'id',
|
||||||
|
type: 'text',
|
||||||
|
width: 100,
|
||||||
|
form: {
|
||||||
|
required: true,
|
||||||
|
rules: [{
|
||||||
|
callback() {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '参数名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
type: 'text',
|
||||||
|
width: 100,
|
||||||
|
form: {
|
||||||
|
required: true,
|
||||||
|
rules: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入参数名称'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据类型',
|
||||||
|
type: 'components',
|
||||||
|
dataIndex: 'valueType',
|
||||||
|
components: {
|
||||||
|
name: ValueObject,
|
||||||
|
props: {
|
||||||
|
filter: ['object']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
width: 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '其他配置',
|
||||||
|
dataIndex: 'config',
|
||||||
|
width: 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'action',
|
||||||
|
width: 60
|
||||||
|
}]
|
||||||
|
|
||||||
const options = ref<{ label: string; value: string }[]>([]);
|
const options = ref<{ label: string; value: string }[]>([]);
|
||||||
const emit = defineEmits(['update:value']);
|
const emit = defineEmits(['update:value']);
|
||||||
|
|
||||||
|
@ -144,10 +145,13 @@ const typeChange = (e: string) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const valueChange = () => {
|
const valueChange = (_data: any, _type: string) => {
|
||||||
|
console.log(_type, _data)
|
||||||
|
const newData = handleTypeValue(_type, _data)
|
||||||
|
console.log('dataType',{...newData, type: type.value})
|
||||||
emit('update:value', {
|
emit('update:value', {
|
||||||
...props.value,
|
...props.value,
|
||||||
valueType: {...(_valueType.value || {}), type: type.value},
|
valueType: {...newData, type: type.value},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<DataTableObject v-model:value="dataSource" :columns="columns" :onAdd="addItem" width="700px" @confirm="confirm">
|
<DataTableObject :value="dataSource" :columns="columns" :onAdd="addItem" width="700px" @confirm="confirm">
|
||||||
<template #valueType="{ data }">
|
<template #valueType="{ data }">
|
||||||
<span>{{ data.record.valueType?.type }}</span>
|
<span>{{ data.record.valueType?.type }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
<span>{{ data.record.expands?.required ? "是": '否' }}</span>
|
<span>{{ data.record.expands?.required ? "是": '否' }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #config="{ data }">
|
<template #config="{ data }">
|
||||||
<OtherConfigInfo :value="data.record.valueType"></OtherConfigInfo>
|
<ConfigModal v-model:value="data.record" />
|
||||||
</template>
|
</template>
|
||||||
<j-button>
|
<j-button>
|
||||||
<AIcon type="SettingOutlined" />
|
<AIcon type="SettingOutlined" />
|
||||||
|
@ -18,26 +18,12 @@
|
||||||
|
|
||||||
<script setup lang="ts" name="InputParams">
|
<script setup lang="ts" name="InputParams">
|
||||||
import type { PropType } from 'vue';
|
import type { PropType } from 'vue';
|
||||||
import DataTypeObjectChild from '../DataTypeObjectChild.vue'
|
import ConfigModal from '@/views/device/components/Metadata/Base/components/ConfigModal.vue'
|
||||||
import {
|
import {
|
||||||
DataTableObject,
|
DataTableObject,
|
||||||
} from 'jetlinks-ui-components';
|
} from 'jetlinks-ui-components';
|
||||||
import { ConstraintSelect, OtherConfigInfo, ValueObject } from '../index'
|
import { ConstraintSelect, OtherConfigInfo, ValueObject } from '../index'
|
||||||
|
|
||||||
const addItem = () => {
|
|
||||||
return {
|
|
||||||
id: undefined,
|
|
||||||
name: undefined,
|
|
||||||
valueType: {
|
|
||||||
|
|
||||||
},
|
|
||||||
expands: {
|
|
||||||
required: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const columns = ref()
|
|
||||||
|
|
||||||
type Emits = {
|
type Emits = {
|
||||||
(e: 'update:value', data: Record<string, any>): void;
|
(e: 'update:value', data: Record<string, any>): void;
|
||||||
|
@ -60,6 +46,76 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const addItem = () => {
|
||||||
|
return {
|
||||||
|
id: undefined,
|
||||||
|
name: undefined,
|
||||||
|
valueType: {
|
||||||
|
|
||||||
|
},
|
||||||
|
expands: {
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = ref([
|
||||||
|
{
|
||||||
|
title: '参数标识',
|
||||||
|
dataIndex: 'id',
|
||||||
|
type: 'text',
|
||||||
|
form: {
|
||||||
|
required: true,
|
||||||
|
rules: [
|
||||||
|
{ required: true, message: '请输入标识' },
|
||||||
|
{
|
||||||
|
validator(va:any,value: any) {
|
||||||
|
const fieldIndex = va.field.split('.')[1]
|
||||||
|
const oldValue = (dataSource!.value || []).filter((_, index) => index != fieldIndex)
|
||||||
|
console.log(dataSource!.value)
|
||||||
|
const hasId = oldValue.some((item) => item.id === value)
|
||||||
|
if (value) {
|
||||||
|
if (hasId) {
|
||||||
|
return Promise.reject('该标识存在')
|
||||||
|
}
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
return Promise.reject('请输入标识')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ title: '参数名称', dataIndex: 'name', type: 'text', form: { required: true, rules: [{ required: true, message: '请输入名称'}]} },
|
||||||
|
{
|
||||||
|
title: '填写约束',
|
||||||
|
dataIndex: 'required',
|
||||||
|
type: 'components',
|
||||||
|
width: 100,
|
||||||
|
components: {
|
||||||
|
name: ConstraintSelect,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '数据类型',
|
||||||
|
type: 'components',
|
||||||
|
dataIndex: 'valueType',
|
||||||
|
components: {
|
||||||
|
name: ValueObject,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '其他配置',
|
||||||
|
dataIndex: 'config',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'action',
|
||||||
|
width: 60
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
const dataSource = ref(props.value);
|
const dataSource = ref(props.value);
|
||||||
|
|
||||||
const change = (v: string) => {
|
const change = (v: string) => {
|
||||||
|
@ -68,76 +124,19 @@ const change = (v: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.value,
|
() => JSON.stringify(props.value),
|
||||||
(newV) => {
|
(newV) => {
|
||||||
|
console.log('inputParams-change')
|
||||||
dataSource.value = props.value.inputs;
|
dataSource.value = props.value.inputs;
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(() => JSON.stringify(dataSource.value), () => {
|
|
||||||
columns.value = [
|
|
||||||
{
|
|
||||||
title: '参数标识',
|
|
||||||
dataIndex: 'id',
|
|
||||||
type: 'text',
|
|
||||||
form: {
|
|
||||||
required: true,
|
|
||||||
rules: [
|
|
||||||
{ required: true, message: '请输入标识' },
|
|
||||||
{
|
|
||||||
validator(va:any,value: any) {
|
|
||||||
const fieldIndex = va.field.split('.')[1]
|
|
||||||
const oldValue = (dataSource!.value || []).filter((_, index) => index != fieldIndex)
|
|
||||||
console.log(dataSource!.value)
|
|
||||||
const hasId = oldValue.some((item) => item.id === value)
|
|
||||||
if (value) {
|
|
||||||
if (hasId) {
|
|
||||||
return Promise.reject('该标识存在')
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
return Promise.reject('请输入标识')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ title: '参数名称', dataIndex: 'name', type: 'text', form: { required: true, rules: [{ required: true, message: '请输入名称'}]} },
|
|
||||||
{
|
|
||||||
title: '填写约束',
|
|
||||||
dataIndex: 'required',
|
|
||||||
type: 'components',
|
|
||||||
width: 100,
|
|
||||||
components: {
|
|
||||||
name: ConstraintSelect,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '数据类型',
|
|
||||||
type: 'components',
|
|
||||||
dataIndex: 'valueType',
|
|
||||||
components: {
|
|
||||||
name: ValueObject,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '其他配置',
|
|
||||||
dataIndex: 'config',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
dataIndex: 'action',
|
|
||||||
width: 60
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, { immediate: true})
|
|
||||||
|
|
||||||
const confirm = (v: any) => {
|
const confirm = (v: any) => {
|
||||||
console.log(v)
|
console.log('inputParams',v)
|
||||||
emit('update:value', {
|
emit('update:value', {
|
||||||
...props.value,
|
...props.value,
|
||||||
inputs: dataSource.value
|
inputs: v
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3825,8 +3825,8 @@ jetlinks-store@^0.0.3:
|
||||||
|
|
||||||
jetlinks-ui-components@^1.0.23, jetlinks-ui-components@^1.0.24:
|
jetlinks-ui-components@^1.0.23, jetlinks-ui-components@^1.0.24:
|
||||||
version "1.0.24"
|
version "1.0.24"
|
||||||
resolved "http://registry.jetlinks.cn/jetlinks-ui-components/-/jetlinks-ui-components-1.0.24.tgz#552bad6c9ef733c941168c01fcfe594317add9e2"
|
resolved "http://registry.jetlinks.cn/jetlinks-ui-components/-/jetlinks-ui-components-1.0.24.tgz#7d651f3d333ad52154f5dbbbcba7f6ed8e85e442"
|
||||||
integrity sha512-34a8yGQpOHy3DsdRO+pc9Qn5HoeLSGhc2wJhVd22/EbyG5X08EENOsIu+Jg6o/ELmSB2gKnvvhpR4rxawN28hQ==
|
integrity sha512-MtIwdFA2kq3s1rGLExYjjjuit05pjoIURDelUIE4swN3q9qh8QgHcjAOtwEor+UNp333LT2FnSQbMkfXctrqUQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@vueuse/core" "^9.12.0"
|
"@vueuse/core" "^9.12.0"
|
||||||
"@vueuse/router" "^9.13.0"
|
"@vueuse/router" "^9.13.0"
|
||||||
|
|
Loading…
Reference in New Issue