fix: 修改物模型BUG

This commit is contained in:
wangshuaiswim 2023-03-20 20:40:21 +08:00
parent d5876a0ed1
commit 2511baf944
14 changed files with 104 additions and 96 deletions

View File

@ -1,5 +1,5 @@
<template>
<a-modal :mask-closable="false" visible width="70vw" title="设置属性规则" @cancel="handleCancel" @ok="handleOk">
<j-modal :mask-closable="false" visible width="70vw" title="设置属性规则" @cancel="handleCancel" @ok="handleOk">
<div class="advance-box">
<div class="left">
<Editor
@ -20,7 +20,7 @@
<Operator :id="id" @add-operator-value="addOperatorValue"/>
</div>
</div>
</a-modal>
</j-modal>
</template>
<script setup lang="ts" name="Advance">
import Editor from '../Editor/index.vue'

View File

@ -12,28 +12,28 @@
</div>
</div>
</div>
<a-table :columns="columns" :data-source="property" :pagination="false" bordered size="small">
<j-table :columns="columns" :data-source="property" :pagination="false" bordered size="small">
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'id'">
<j-auto-complete :options="options" v-model:value="record.id" size="small" width="130px"/>
</template>
<template v-if="column.key === 'current'">
<a-input v-model:value="record.current" size="small"></a-input>
<j-input v-model:value="record.current" size="small"></j-input>
</template>
<template v-if="column.key === 'last'">
<a-input v-model:value="record.last" size="small"></a-input>
<j-input v-model:value="record.last" size="small"></j-input>
</template>
<template v-if="column.key === 'action'">
<delete-outlined @click="deleteItem(index)" />
<AIcon type="DeleteOutlined" @click="deleteItem(index)" />
</template>
</template>
</a-table>
<a-button type="dashed" block style="margin-top: 5px" @click="addItem">
</j-table>
<j-button type="dashed" block style="margin-top: 5px" @click="addItem">
<template #icon>
<plus-outlined />
<AIcon type="PlusOutlined" />
</template>
添加条目
</a-button>
</j-button>
</div>
<div class="right">
<div class="header">
@ -57,15 +57,14 @@
</div>
</div>
<div class="log">
<a-descriptions>
<a-descriptions-item v-for="item in ruleEditorStore.state.log" :label="moment(item.time).format('HH:mm:ss')"
<j-descriptions>
<j-descriptions-item v-for="item in ruleEditorStore.state.log" :label="moment(item.time).format('HH:mm:ss')"
:key="item.time" :span="3">
<a-tooltip placement="top" :title="item.content">
<j-tooltip placement="top" :title="item.content">
{{ item.content }}
</a-tooltip>
</a-descriptions-item>
))}
</a-descriptions>
</j-tooltip>
</j-descriptions-item>
</j-descriptions>
</div>
</div>
</div>

View File

@ -7,9 +7,8 @@
{{ item.value }}
</span>
<span>
<a-dropdown>
<!-- <AIcon type="MoreOutline" /> -->
<more-outlined />
<j-dropdown>
<AIcon type="MoreOutlined" />
<template #overlay>
<j-menu>
<j-menu-item v-for="item in symbolList.filter((t: SymbolType, i: number) => i > 6)" :key="item.key"
@ -18,14 +17,13 @@
</j-menu-item>
</j-menu>
</template>
</a-dropdown>
</j-dropdown>
</span>
</div>
<div class="right">
<span v-if="mode !== 'advance'">
<j-tooltip :title="!id ? '请先输入标识' : '设置属性规则'">
<AIcon type="FullscreenOutlined" :class="!id ? 'disabled' : ''" @click="fullscreenClick" />
<!-- <fullscreen-outlined :class="!id ? 'disabled' : ''" @click="fullscreenClick" /> -->
</j-tooltip>
</span>
</div>

View File

@ -1,30 +1,30 @@
<template>
<div class="operator-box">
<a-input-search @search="search" allow-clear placeholder="搜索关键字" />
<j-input-search @search="search" allow-clear placeholder="搜索关键字" />
<div class="tree">
<a-tree @select="selectTree" :field-names="{ title: 'name', key: 'id', }" auto-expand-parent
<j-tree @select="selectTree" :field-names="{ title: 'name', key: 'id', }" auto-expand-parent
:tree-data="data">
<template #title="node">
<div class="node">
<div>{{ node.name }}</div>
<div :class="node.children?.length > 0 ? 'parent' : 'add'">
<a-popover v-if="node.type === 'property'" placement="right" title="请选择使用值">
<j-popover v-if="node.type === 'property'" placement="right" title="请选择使用值">
<template #content>
<a-space direction="vertical">
<a-tooltip placement="right" title="实时值为空时获取上一有效值补齐,实时值不为空则使用实时值">
<a-button type="text" @click="recentClick(node)">
<j-space direction="vertical">
<j-tooltip placement="right" title="实时值为空时获取上一有效值补齐,实时值不为空则使用实时值">
<j-button type="text" @click="recentClick(node)">
$recent实时值
</a-button>
</a-tooltip>
<a-tooltip placement="right" title="实时值的上一有效值">
<a-button @click="lastClick(node)" type="text">
</j-button>
</j-tooltip>
<j-tooltip placement="right" title="实时值的上一有效值">
<j-button @click="lastClick(node)" type="text">
上一值
</a-button>
</a-tooltip>
</a-space>
</j-button>
</j-tooltip>
</j-space>
</template>
<a>添加</a>
</a-popover>
</j-popover>
<a v-else @click="addClick(node)">
添加
@ -32,7 +32,7 @@
</div>
</div>
</template>
</a-tree>
</j-tree>
</div>
<div class="explain">
<Markdown :source="item?.description || ''"></Markdown>

View File

@ -3,16 +3,16 @@
<template v-if="['int', 'long', 'double', 'float'].includes(type)">
<template v-if="value.range">
<j-input-number v-model:value="value.value[0]" :max="value.value[1]" size="small"
style="width: 100%;"></j-input-number>
style="width: 100%;" placeholder="请输入"></j-input-number>
~
<j-input-number v-model:value="value.value[1]" :min="value.value[0]" size="small"
style="width: 100%;"></j-input-number>
style="width: 100%;" placeholder="请输入"></j-input-number>
</template>
<j-input-number v-else v-model:value="value.value" size="small" style="width: 100%;"></j-input-number>
<j-input-number v-else v-model:value="value.value" size="small" style="width: 100%;" placeholder="请输入"></j-input-number>
</template>
<template v-else-if="type === 'date'">
<j-range-picker v-if="value.range" show-time v-model:value="value.value" size="small" />
<j-date-picker v-else show-time v-model:value="value.value" size="small" />
<j-range-picker v-if="value.range" show-time v-model:value="value.value" size="small" placeholder="请输入"/>
<j-date-picker v-else show-time v-model:value="value.value" size="small" placeholder="请输入"/>
</template>
<template v-else-if="type === 'boolean'">
<j-select v-model:value="value.value[0]" :options="list" size="small" placeholder="请选择"></j-select>
@ -57,7 +57,7 @@ const props = defineProps({
}
})
Form.useInjectFormItemContext()
// Form.useInjectFormItemContext()
const changeChecked = (e: CheckboxChangeEvent) => {
if (e.target.checked) {

View File

@ -13,7 +13,7 @@
<j-form-item label="说明" :name="name.concat(['description'])" :rules="[
{ max: 200, message: '最多可输入200个字符' },
]">
<j-textarea v-model:value="_value.description" size="small"></j-textarea>
<j-textarea v-model:value="_value.description" size="small" placeholder="请输入说明"></j-textarea>
</j-form-item>
</div>
</div>

View File

@ -1,24 +1,25 @@
<template>
<j-popover placement="left" trigger="click">
<template #title>
<div class="edit-title" style="display: flex; justify-content: space-between; align-items: center;">
<div style="width: 150px;">{{ config.name }}</div>
</div>
</template>
<template #content>
<div style="max-width: 400px;" class="ant-form-vertical">
<j-form-item v-for="item in config.properties" :name="name.concat([item.property])" :label="item.name">
<j-select v-model:value="value[item.property]" :options="item.type?.elements?.map((e: { 'text': string, 'value': string }) => ({
label: e.text,
value: e.value,
}))" size="small"></j-select>
</j-form-item>
</div>
</template>
<j-button type="dashed" block>
存储配置<AIcon type="EditOutlined" class="item-icon"/>
</j-button>
</j-popover>
<j-button type="dashed" block>
<j-popover placement="left" trigger="click">
<template #title>
<div class="edit-title" style="display: flex; justify-content: space-between; align-items: center;">
<div style="width: 150px;">{{ config.name }}</div>
</div>
</template>
<template #content>
<div style="max-width: 400px;" class="ant-form-vertical">
<j-form-item v-for="item in config.properties" :name="name.concat([item.property])" :label="item.name">
<j-select v-model:value="value[item.property]" :options="item.type?.elements?.map((e: { 'text': string, 'value': string }) => ({
label: e.text,
value: e.value,
}))" size="small" :placeholder="`请输入${item.name}`"></j-select>
</j-form-item>
</div>
</template>
存储配置
<AIcon type="EditOutlined" class="item-icon" />
</j-popover>
</j-button>
</template>
<script setup lang="ts" name="ConfigParam">
import { PropType } from 'vue';
@ -30,7 +31,7 @@ const props = defineProps({
default: () => ({})
},
name: {
type: Array as PropType<(string| number)[]>,
type: Array as PropType<(string | number)[]>,
default: () => ([]),
required: true
},
@ -57,15 +58,17 @@ const props = defineProps({
color: rgb(136, 136, 136);
font-size: 12px;
}
:deep(.ant-form-item-label) {
>label {
font-size: 12px;
}
}
:deep(.ant-select) {
font-size: 12px;
}
:deep(input) {
height: 22px;
}
</style>
}</style>

View File

@ -18,13 +18,13 @@
{ required: true, message: '请输入Value' },
{ max: 64, message: '最多可输入64个字符' },
]">
<j-input v-model:value="_value[index].value" size="small"></j-input>
<j-input v-model:value="_value[index].value" size="small" placeholder="请输入Value"></j-input>
</j-form-item>
<j-form-item label="Text" :name="name.concat([index, 'text'])" :rules="[
{ required: true, message: '请输入Text' },
{ max: 64, message: '最多可输入64个字符' },
]">
<j-input v-model:value="_value[index].text" size="small"></j-input>
<j-input v-model:value="_value[index].text" size="small" placeholder="请输入Text"></j-input>
</j-form-item>
</div>
</template>

View File

@ -22,13 +22,13 @@
message: 'ID只能由数字、字母、下划线、中划线组成',
},
]">
<j-input v-model:value="_value[index].id" size="small"></j-input>
<j-input v-model:value="_value[index].id" size="small" placeholder="请输入标识"></j-input>
</j-form-item>
<j-form-item label="名称" :name="name.concat([index, 'name'])" :rules="[
{ required: true, message: '请输入名称' },
{ max: 64, message: '最多可输入64个字符' },
]">
<j-input v-model:value="_value[index].name" size="small"></j-input>
<j-input v-model:value="_value[index].name" size="small" placeholder="请输入名称"></j-input>
</j-form-item>
<value-type-form v-model:value="_value[index].valueType" :name="name.concat([index, 'valueType'])" :isSub="isSub"
key="json_sub"></value-type-form>

View File

@ -6,7 +6,7 @@
{{ `#${index + 1}.` }}
</div>
<div class="item-middle item-editable">
<j-popover :visible="editIndex === index" placement="top" @visible-change="change" trigger="click">
<j-popover :visible="editIndex === index" placement="left" @visible-change="change" trigger="click">
<template #title>
<div class="edit-title" style="display: flex; justify-content: space-between; align-items: center;">
<div style="width: 150px;">配置参数</div>
@ -24,13 +24,13 @@
message: 'ID只能由数字、字母、下划线、中划线组成',
},
]">
<j-input v-model:value="_value[index].id" size="small"></j-input>
<j-input v-model:value="_value[index].id" size="small" placeholder="请输入标识"></j-input>
</j-form-item>
<j-form-item label="名称" :name="name.concat([index, 'name'])" :rules="[
{ required: true, message: '请输入名称' },
{ max: 64, message: '最多可输入64个字符' },
]">
<j-input v-model:value="_value[index].name" size="small"></j-input>
<j-input v-model:value="_value[index].name" size="small" placeholder="请输入名称"></j-input>
</j-form-item>
<j-form-item label="指标值" :name="name.concat([index, 'value'])" :rules="[
{ required: true, validator: () => validateIndicator(_value[index]), message: '请输入指标值' }
@ -41,7 +41,7 @@
</div>
</template>
<div class="item-edit" @click="handleEdit(index)">
{{ item.name || '配置参数' }}
<Ellipsis>{{ item.name || '配置参数' }}</Ellipsis>
<AIcon type="EditOutlined" class="item-icon" />
</div>
</j-popover>
@ -118,7 +118,7 @@ const validateIndicator = (value: any) => {
return Promise.reject(new Error('请输入指标值'));
}
} else {
if (value?.value === '' || value?.value === undefined) {
if (!value?.value) {
return Promise.reject(new Error('请输入指标值'));
}
}
@ -151,6 +151,10 @@ const change = (visible: boolean) => {
// }
.item-edit {
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
max-width: 240px;
}
.item-icon {

View File

@ -19,9 +19,17 @@
</j-form-item>
<j-form-item
v-if="type === 'product' && ['int', 'float', 'double', 'long', 'date', 'string', 'boolean'].includes(valueType.type)"
label="指标配置" :name="name.concat(['metrics'])" :rules="[
:name="name.concat(['metrics'])" :rules="[
{ validator: () => validateMetrics(_value.metrics), message: '请输入指标配置' }
]">
<template #label>
<j-space>
指标配置
<j-tooltip title="场景联动页面可引用指标配置作为触发条件">
<AIcon type="QuestionCircleOutlined" style="color: rgb(136, 136, 136); font-size: 12px;"/>
</j-tooltip>
</j-space>
</template>
<metrics-param v-model:value="_value.metrics" :type="valueType.type" :enum="valueType"
:name="name.concat(['metrics'])"></metrics-param>
</j-form-item>

View File

@ -152,6 +152,9 @@ const changeType = (val: SelectValue) => {
if (['float', 'double'].includes(_value.value.type) && _value.value.scale === undefined) {
_value.value.scale = 2
}
if (['file'].includes(val as string)) {
_value.value.fileType = _value.value.fileType || 'url'
}
emit('changeType', val as string)
}

View File

@ -1,4 +1,4 @@
import { JColumnProps } from "@/components/Table";
import { ColumnProps } from "ant-design-vue/es/table";
const SourceMap = {
device: '设备',
@ -12,7 +12,7 @@ const type = {
report: '上报',
};
const BaseColumns: JColumnProps[] = [
const BaseColumns: ColumnProps[] = [
{
title: '标识',
dataIndex: 'id',
@ -30,19 +30,17 @@ const BaseColumns: JColumnProps[] = [
},
];
const EventColumns: JColumnProps[] = BaseColumns.concat([
const EventColumns: ColumnProps[] = BaseColumns.concat([
{
title: '事件级别',
dataIndex: 'level',
scopedSlots: true,
},
]);
const FunctionColumns: JColumnProps[] = BaseColumns.concat([
const FunctionColumns: ColumnProps[] = BaseColumns.concat([
{
title: '是否异步',
dataIndex: 'async',
scopedSlots: true,
},
// {
// title: '读写类型',
@ -51,38 +49,33 @@ const FunctionColumns: JColumnProps[] = BaseColumns.concat([
// },
]);
const PropertyColumns: JColumnProps[] = BaseColumns.concat([
const PropertyColumns: ColumnProps[] = BaseColumns.concat([
{
title: '数据类型',
dataIndex: 'valueType',
scopedSlots: true,
},
{
title: '属性来源',
dataIndex: 'source',
scopedSlots: true,
},
{
title: '读写类型',
dataIndex: 'type',
scopedSlots: true,
},
]);
const TagColumns: JColumnProps[] = BaseColumns.concat([
const TagColumns: ColumnProps[] = BaseColumns.concat([
{
title: '数据类型',
dataIndex: 'valueType',
scopedSlots: true,
},
{
title: '读写类型',
dataIndex: 'type',
scopedSlots: true,
},
]);
const MetadataMapping = new Map<string, JColumnProps[]>();
const MetadataMapping = new Map<string, ColumnProps[]>();
MetadataMapping.set('properties', PropertyColumns);
MetadataMapping.set('events', EventColumns);
MetadataMapping.set('tags', TagColumns);

View File

@ -16,7 +16,7 @@
<Edit v-if="metadataStore.model.edit" :type="target" :tabs="type" @refresh="refreshMetadata"></Edit>
</div>
</div>
<a-table :loading="loading" :data-source="data" :columns="columns" row-key="id" model="TABLE" size="small"
<j-table :loading="loading" :data-source="data" :columns="columns" row-key="id" model="TABLE" size="small"
:pagination="pagination">
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'level'">
@ -57,7 +57,7 @@
</j-space>
</template>
</template>
</a-table>
</j-table>
</template>
<script setup lang="ts" name="BaseMetadata">
import type { MetadataItem, MetadataType } from '@/views/device/Product/typings'
@ -69,6 +69,7 @@ import PermissionButton from '@/components/PermissionButton/index.vue'
import { TablePaginationConfig, message } from 'ant-design-vue/es'
import { asyncUpdateMetadata, removeMetadata } from '../metadata'
import Edit from './Edit/index.vue'
import { ColumnProps } from 'ant-design-vue/es/table'
interface Props {
type: MetadataType;
target: 'product' | 'device';
@ -97,13 +98,12 @@ const expandsType = ref({
write: '写',
report: '上报',
});
const actions = [
const actions: ColumnProps[] = [
{
title: '操作',
align: 'left',
width: 200,
dataIndex: 'action',
scopedSlots: true,
},
];
const pagination = {
@ -215,6 +215,6 @@ const removeItem = async (record: MetadataItem) => {
.table-header {
display: flex;
justify-content: space-between;
padding: 16px 0;
padding: 16px;
}
</style>