fix: 修改物模型BUG
This commit is contained in:
parent
1f1d81c767
commit
026d9dd914
|
@ -2,7 +2,7 @@ import { LocalStore } from '@/utils/comm'
|
|||
import server from '@/utils/request'
|
||||
import { BASE_API_PATH, TOKEN_KEY } from '@/utils/variable'
|
||||
import { DeviceInstance } from '@/views/device/Instance/typings'
|
||||
import { UnitType } from '@/views/device/Product/typings';
|
||||
import { DeviceMetadata, UnitType } from '@/views/device/Product/typings';
|
||||
|
||||
/**
|
||||
* 删除设备物模型
|
||||
|
@ -17,7 +17,7 @@ export const deleteMetadata = (deviceId: string) => server.remove(`/device-insta
|
|||
* @param data 物模型
|
||||
* @returns
|
||||
*/
|
||||
export const saveMetadata = (id: string, data: string) => server.put(`/device/instance/${id}/metadata`, data)
|
||||
export const saveMetadata = (id: string, data: DeviceMetadata) => server.put(`/device/instance/${id}/metadata`, data)
|
||||
|
||||
/**
|
||||
* 根据设备ID获取设备详情
|
||||
|
|
|
@ -180,7 +180,7 @@ export const updateDevice = (data:any) => server.patch('/device-product',data)
|
|||
/**
|
||||
* 获取操作符
|
||||
*/
|
||||
export const getOperator = () => server.get<OperatorItem>('/property-calculate-rule/description')
|
||||
export const getOperator = () => server.get<OperatorItem[]>('/property-calculate-rule/description')
|
||||
|
||||
/**
|
||||
* 获取聚合函数列表
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<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"/>
|
||||
<j-auto-complete :options="options" v-model:value="record.id" size="small" style="width: 130px" />
|
||||
</template>
|
||||
<template v-if="column.key === 'current'">
|
||||
<j-input v-model:value="record.current" size="small"></j-input>
|
||||
|
@ -87,8 +87,6 @@ const props = defineProps({
|
|||
|
||||
const isBeginning = ref(true)
|
||||
|
||||
const runScriptAgain = () => { }
|
||||
|
||||
type propertyType = {
|
||||
id?: string,
|
||||
current?: string,
|
||||
|
@ -154,8 +152,37 @@ const runScript = () => {
|
|||
})
|
||||
ws.value.subscribe((data: any) => {
|
||||
ruleEditorStore.state.log.push({ time: new Date().getTime(), content: JSON.stringify(data.payload) });
|
||||
if (props.virtualRule?.type !== 'window') {
|
||||
stopAction()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const wsAgain = ref<any>();
|
||||
const runScriptAgain = async () => {
|
||||
if (wsAgain.value) {
|
||||
wsAgain.value.unsubscribe?.();
|
||||
}
|
||||
const metadata = productStore.current.metadata || '{}';
|
||||
const propertiesList = JSON.parse(metadata).properties || [];
|
||||
const _properties = property.value.map((item: any) => {
|
||||
const _item = propertiesList.find((i: any) => i.id === item.id);
|
||||
return { ...item, type: _item?.valueType?.type };
|
||||
});
|
||||
|
||||
wsAgain.value = getWebSocket(`virtual-property-debug-${props.id}-${new Date().getTime()}`,
|
||||
'/virtual-property-debug',
|
||||
{
|
||||
virtualId: `${virtualIdRef.value}-virtual-id`,
|
||||
property: props.id,
|
||||
virtualRule: {
|
||||
...props.virtualRule,
|
||||
},
|
||||
properties: _properties || [],
|
||||
})
|
||||
wsAgain.value.subscribe((data: any) => { })
|
||||
}
|
||||
|
||||
const beginAction = () => {
|
||||
isBeginning.value = false;
|
||||
runScript();
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="editor">
|
||||
<JMonacoEditor v-if="loading" v-model:model-value="_value" theme="vs" ref="editor" lang="javascript"/>
|
||||
<j-monaco-editor v-if="loading" v-model:model-value="_value" theme="vs" ref="editor" language="javascript"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
:tree-data="data">
|
||||
<template #title="node">
|
||||
<div class="node">
|
||||
<div>{{ node.name }}</div>
|
||||
<div style="max-width: 180px"><Ellipsis>{{ node.name }}</Ellipsis></div>
|
||||
<div :class="node.children?.length > 0 ? 'parent' : 'add'">
|
||||
<j-popover v-if="node.type === 'property'" placement="right" title="请选择使用值">
|
||||
<template #content>
|
||||
|
@ -107,8 +107,8 @@ const getData = async (id?: string) => {
|
|||
};
|
||||
const response = await getOperator();
|
||||
if (response.status === 200) {
|
||||
data.value = [properties, ...response.result];
|
||||
dataRef.value = [properties, ...response.result];
|
||||
data.value = [properties as OperatorItem, ...response.result];
|
||||
dataRef.value = [properties as OperatorItem, ...response.result];
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<j-col :span="12">
|
||||
<j-form-item label=" " :name="name.concat(['trueText'])" :rules="[
|
||||
{ required: true, message: '请输入trueText' },
|
||||
{ max: 64, message: '最多可输入64个字符' },
|
||||
]">
|
||||
<j-input v-model:value="value.trueText" placeholder="trueText" size="small" />
|
||||
</j-form-item>
|
||||
|
@ -11,6 +12,7 @@
|
|||
<j-col :span="12">
|
||||
<j-form-item label="-" :name="name.concat(['trueValue'])" :rules="[
|
||||
{ required: true, message: '请输入trueValue' },
|
||||
{ max: 64, message: '最多可输入64个字符' },
|
||||
]">
|
||||
<j-input v-model:value="value.trueValue" placeholder="trueValue" size="small"/>
|
||||
</j-form-item>
|
||||
|
@ -18,6 +20,7 @@
|
|||
<j-col :span="12">
|
||||
<j-form-item label=" " :name="name.concat(['falseText'])" :rules="[
|
||||
{ required: true, message: '请输入falseText' },
|
||||
{ max: 64, message: '最多可输入64个字符' },
|
||||
]">
|
||||
<j-input v-model:value="value.falseText" placeholder="falseText" size="small" />
|
||||
</j-form-item>
|
||||
|
@ -25,6 +28,7 @@
|
|||
<j-col :span="12">
|
||||
<j-form-item label="-" :name="name.concat(['falseValue'])" :rules="[
|
||||
{ required: true, message: '请输入falseValue' },
|
||||
{ max: 64, message: '最多可输入64个字符' },
|
||||
]">
|
||||
<j-input v-model:value="value.falseValue" placeholder="falseValue" size="small" />
|
||||
</j-form-item>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<div class="item-edit" @click="handleEdit(index)">
|
||||
{{ item.text || '枚举项配置' }}
|
||||
<Ellipsis>{{ item.text || '枚举项配置' }}</Ellipsis>
|
||||
<AIcon type="EditOutlined" class="item-icon" />
|
||||
</div>
|
||||
</j-popover>
|
||||
|
@ -115,6 +115,10 @@ const handleAdd = () => {
|
|||
// }
|
||||
.item-edit {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
.item-icon {
|
||||
|
|
|
@ -35,7 +35,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>
|
||||
|
@ -131,6 +131,10 @@ const handleAdd = () => {
|
|||
// }
|
||||
.item-edit {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
.item-icon {
|
||||
|
|
|
@ -55,7 +55,7 @@ const close = () => {
|
|||
metadataStore.set('item', {})
|
||||
}
|
||||
|
||||
const title = computed(() => metadataStore.model.action === 'add' ? '新增' : '修改')
|
||||
const title = computed(() => metadataStore.model.action === 'add' ? '新增' : '编辑')
|
||||
|
||||
const form = reactive({
|
||||
model: {} as any,
|
||||
|
|
|
@ -16,17 +16,17 @@ const BaseColumns: ColumnProps[] = [
|
|||
{
|
||||
title: '标识',
|
||||
dataIndex: 'id',
|
||||
ellipsis: true,
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
ellipsis: true,
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'description',
|
||||
ellipsis: true,
|
||||
width: 200
|
||||
},
|
||||
];
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div class="table-header">
|
||||
<div>
|
||||
<j-input-search v-model:value="searchValue" placeholder="请输入名称" @search="handleSearch"></j-input-search>
|
||||
<j-input-search v-model:value="searchValue" placeholder="请输入名称" @search="handleSearch" allowClear></j-input-search>
|
||||
</div>
|
||||
<div>
|
||||
<PermissionButton type="primary" :uhas-permission="`${permission}:update`" key="add" @click="handleAddClick"
|
||||
|
@ -19,6 +19,15 @@
|
|||
<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 === 'id'">
|
||||
<div style="width: 100px"><Ellipsis>{{ record.id || '-' }}</Ellipsis></div>
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'name'">
|
||||
<div style="width: 200px"><Ellipsis>{{ record.name || '-' }}</Ellipsis></div>
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'description'">
|
||||
<div style="width: 200px"><Ellipsis>{{ record.description || '-' }}</Ellipsis></div>
|
||||
</template>
|
||||
<template v-if="column.dataIndex === 'level'">
|
||||
{{ levelMap[record.expands?.level] || '-' }}
|
||||
</template>
|
||||
|
@ -102,7 +111,7 @@ const actions: ColumnProps[] = [
|
|||
{
|
||||
title: '操作',
|
||||
align: 'left',
|
||||
width: 200,
|
||||
width: 80,
|
||||
dataIndex: 'action',
|
||||
},
|
||||
];
|
||||
|
|
|
@ -208,13 +208,13 @@ const handleImport = async () => {
|
|||
if (data.metadata === 'alink') {
|
||||
const res = await convertMetadata('from', 'alink', data.import)
|
||||
if (res.status === 200) {
|
||||
const metadata = JSON.stringify(operateLimits(res.result))
|
||||
const metadata = operateLimits(res.result)
|
||||
if (props?.type === 'device') {
|
||||
await saveMetadata(id as string, metadata)
|
||||
instanceStore.setCurrent(JSON.parse(metadata || '{}'))
|
||||
// instanceStore.setCurrent(JSON.parse(metadata || '{}'))
|
||||
} else {
|
||||
await modify(id as string, { metadata: metadata })
|
||||
productStore.setCurrent(JSON.parse(metadata || '{}'))
|
||||
// productStore.setCurrent(JSON.parse(metadata || '{}'))
|
||||
}
|
||||
loading.value = false
|
||||
// MetadataAction.insert(JSON.parse(metadata || '{}'));
|
||||
|
@ -247,7 +247,7 @@ const handleImport = async () => {
|
|||
id,
|
||||
metadata: JSON.stringify(operateLimits(_object as DeviceMetadata)),
|
||||
};
|
||||
const paramsDevice = JSON.stringify(operateLimits(_object as DeviceMetadata))
|
||||
const paramsDevice = operateLimits(_object as DeviceMetadata)
|
||||
let resp = undefined
|
||||
if (props?.type === 'device') {
|
||||
resp = await saveMetadata(id as string, paramsDevice)
|
||||
|
@ -258,7 +258,7 @@ const handleImport = async () => {
|
|||
if (resp.success) {
|
||||
if (props?.type === 'device') {
|
||||
const detail = instanceStore.current
|
||||
detail.metadata = paramsDevice
|
||||
detail.metadata = JSON.stringify(paramsDevice)
|
||||
instanceStore.setCurrent(detail)
|
||||
message.success('导入成功')
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue