fix: 修改物模型规则属性

This commit is contained in:
wangshuaiswim 2023-03-09 16:04:11 +08:00
parent 4dcbf18939
commit 1642290608
5 changed files with 73 additions and 52 deletions

View File

@ -135,18 +135,18 @@ const runScript = () => {
});
if (ws.value) {
ws.value.unsubscribe();
ws.value.unsubscribe?.();
}
if (!props.virtualRule?.script) {
isBeginning.value = true;
message.warning('请编辑规则');
return;
}
ws.value = getWebSocket(`virtual-property-debug-${ruleEditorStore.state.property}-${new Date().getTime()}`,
ws.value = getWebSocket(`virtual-property-debug-${props.id}-${new Date().getTime()}`,
'/virtual-property-debug',
{
virtualId: `${virtualIdRef.value}-virtual-id`,
property: ruleEditorStore.state.property,
property: props.id,
virtualRule: {
...props.virtualRule,
},
@ -163,7 +163,7 @@ const beginAction = () => {
const stopAction = () => {
isBeginning.value = true;
if (ws.value) {
ws.value.unsubscribe();
ws.value.unsubscribe?.();
}
}
const clearAction = () => {
@ -172,7 +172,7 @@ const clearAction = () => {
onUnmounted(() => {
if (ws.value) {
ws.value.unsubscribe();
ws.value.unsubscribe?.();
}
})
</script>

View File

@ -1,6 +1,5 @@
<template>
<Editor key="simple" @change="change" v-model:value="_value" :id="id" />
{{ _value }}
<Advance v-if="ruleEditorStore.state.model === 'advance'" v-model:value="_value" :model="ruleEditorStore.state.model"
:virtualRule="virtualRule" :id="id" @change="change" />
</template>

View File

@ -1,6 +1,6 @@
<template>
<j-form-item :name="name.concat(['script'])">
<f-rule-editor v-model:value="value.script" :id="id"></f-rule-editor>
<f-rule-editor v-model:value="value.script" :id="id" :virtualRule="value"></f-rule-editor>
</j-form-item>
<template v-if="showWindow">
<j-form-item label="规则配置" :name="name.concat(['isVirtualRule'])">

View File

@ -86,7 +86,7 @@ const metadataStore = useMetadataStore()
onMounted(() => {
if (props.type === 'product' || !props.value?.source) {
emit('update:value', { ...props.value, source: 'device' })
emit('update:value', { source: 'device', ...props.value })
}
})

View File

@ -1,9 +1,9 @@
<template>
<j-pro-table :loading="loading" :data-source="data" size="small" :columns="columns" row-key="id" model="TABLE">
<template #headerTitle>
<div class="table-header">
<div>
<j-input-search v-model:value="searchValue" placeholder="请输入名称" @search="handleSearch"></j-input-search>
</template>
<template #rightExtraRender>
</div>
<div>
<PermissionButton type="primary" :uhas-permission="`${permission}:update`" key="add" @click="handleAddClick"
:disabled="operateLimits('add', type)" :tooltip="{
title: operateLimits('add', type) ? '当前的存储方式不支持新增' : '新增',
@ -14,28 +14,32 @@
新增
</PermissionButton>
<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"
:pagination="pagination">
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'level'">
{{ levelMap[record.expands?.level] || '-' }}
</template>
<template #level="slotProps">
{{ levelMap[slotProps.expands?.level] || '-' }}
<template v-if="column.dataIndex === 'async'">
{{ record.async ? '是' : '否' }}
</template>
<template #async="slotProps">
{{ slotProps.async ? '是' : '否' }}
<template v-if="column.dataIndex === 'valueType'">
{{ record.valueType?.type }}
</template>
<template #valueType="slotProps">
{{ slotProps.valueType?.type }}
<template v-if="column.dataIndex === 'source'">
{{ sourceMap[record.expands?.source] }}
</template>
<template #source="slotProps">
{{ sourceMap[slotProps.expands?.source] }}
</template>
<template #type="slotProps">
<j-tag v-for="item in (slotProps.expands?.type || [])" :key="item">
<template v-if="column.dataIndex === 'type'">
<j-tag v-for="item in (record.expands?.type || [])" :key="item">
{{ expandsType[item] }}
</j-tag>
</template>
<template #action="slotProps">
<template v-if="column.dataIndex === 'action'">
<j-space>
<PermissionButton :uhas-permission="`${permission}:update`" type="link" key="edit" style="padding: 0"
:udisabled="operateLimits('updata', type)" @click="handleEditClick(slotProps)" :tooltip="{
:udisabled="operateLimits('updata', type)" @click="handleEditClick(record)" :tooltip="{
title: operateLimits('updata', type) ? '当前的存储方式不支持编辑' : '编辑',
}">
<AIcon type="EditOutlined" />
@ -43,16 +47,19 @@
<PermissionButton :uhas-permission="`${permission}:delete`" type="link" key="delete" style="padding: 0"
:pop-confirm="{
title: '确认删除?', onConfirm: async () => {
await removeItem(slotProps);
await removeItem(record);
},
}" :tooltip="{
}"
:tooltip="{
title: '删除',
}">
<Aicon type="DeleteOutlined" />
}"
>
<AIcon type="DeleteOutlined" />
</PermissionButton>
</j-space>
</template>
</j-pro-table>
</template>
</a-table>
</template>
<script setup lang="ts" name="BaseMetadata">
import type { MetadataItem, MetadataType } from '@/views/device/Product/typings'
@ -61,7 +68,7 @@ import { useInstanceStore } from '@/store/instance'
import { useProductStore } from '@/store/product'
import { useMetadataStore } from '@/store/metadata'
import PermissionButton from '@/components/PermissionButton/index.vue'
import { message } from 'ant-design-vue/es'
import { TablePaginationConfig, message } from 'ant-design-vue/es'
import { SystemConst } from '@/utils/consts'
import { Store } from 'jetlinks-store'
import { asyncUpdateMetadata, removeMetadata } from '../metadata'
@ -106,6 +113,15 @@ const actions = [
scopedSlots: true,
},
];
const pagination = {
showTotal: (num: number, range: number[]) => {
return `${range[0]} - ${range[1]} 条/总共 ${num}`;
},
showSizeChanger: true,
showQuickJumper: false,
defaultPageSize: 10,
size: 'small',
} as TablePaginationConfig
const columns = computed(() => MetadataMapping.get(type)!.concat(actions))
const items = computed(() => JSON.parse((target === 'product' ? productStore.current?.metadata : instanceStore.current.metadata) || '{}') as MetadataItem[])
const searchValue = ref<string>()
@ -196,4 +212,10 @@ const removeItem = async (record: MetadataItem) => {
}
};
</script>
<style scoped lang="less"></style>
<style scoped lang="less">
.table-header {
display: flex;
justify-content: space-between;
padding: 16px 0;
}
</style>