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

View File

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

View File

@ -1,6 +1,6 @@
<template> <template>
<j-form-item :name="name.concat(['script'])"> <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> </j-form-item>
<template v-if="showWindow"> <template v-if="showWindow">
<j-form-item label="规则配置" :name="name.concat(['isVirtualRule'])"> <j-form-item label="规则配置" :name="name.concat(['isVirtualRule'])">

View File

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