fix: 优化设备物模型
This commit is contained in:
parent
c8fa001655
commit
a8338a5981
|
@ -115,7 +115,20 @@
|
|||
</j-tag>
|
||||
</template>
|
||||
<template #other="{ data }">
|
||||
<OtherSetting v-model:value="data.record.expands" :type="data.record.valueType.type" />
|
||||
<j-tooltip
|
||||
v-if="target === 'device' && productNoEdit.id?.includes?.(data.record._sortIndex)"
|
||||
title="继承自产品物模型的数据不支持删除"
|
||||
>
|
||||
<ModelButton :disabled="true"/>
|
||||
</j-tooltip>
|
||||
<OtherSetting
|
||||
v-model:value="data.record.expands"
|
||||
:type="data.record.valueType.type"
|
||||
:disabled="target === 'device' && productNoEdit.id?.includes?.(data.record._sortIndex)"
|
||||
:tooltip="target === 'device' && productNoEdit.id?.includes?.(data.record._sortIndex) ? {
|
||||
title: '继承自产品物模型的数据不支持删除',
|
||||
} : undefined"
|
||||
/>
|
||||
</template>
|
||||
<template #action="{data}">
|
||||
<j-space>
|
||||
|
@ -124,7 +137,7 @@
|
|||
type="link"
|
||||
key="edit"
|
||||
style="padding: 0"
|
||||
:disabled="operateLimits('add', type)"
|
||||
:disabled="!!operateLimits('add', type)"
|
||||
@click="copyItem(data.record, data.index)"
|
||||
:tooltip="{
|
||||
title: operateLimits('add', type) ? '当前的存储方式不支持复制' : '复制',
|
||||
|
@ -137,7 +150,7 @@
|
|||
type="link"
|
||||
key="edit"
|
||||
style="padding: 0"
|
||||
:disabled="operateLimits('add', type)"
|
||||
:disabled="!!operateLimits('add', type)"
|
||||
@click="handleAddClick(null, data.index)"
|
||||
:tooltip="{
|
||||
title: operateLimits('add', type) ? '当前的存储方式不支持新增' : '新增',
|
||||
|
@ -165,14 +178,16 @@
|
|||
danger
|
||||
:pop-confirm="{
|
||||
placement: 'topRight',
|
||||
title: showSave ? '这是最后一条数据了,确认删除?' : '确认删除?',
|
||||
onConfirm: async () => {
|
||||
await removeItem(data.index, showSave);
|
||||
},
|
||||
}"
|
||||
title: showSave ? '这是最后一条数据了,确认删除?' : '确认删除?',
|
||||
onConfirm: async () => {
|
||||
await removeItem(data.index, showSave);
|
||||
},
|
||||
}"
|
||||
:tooltip="{
|
||||
title: '删除',
|
||||
placement: 'topRight',
|
||||
title: target === 'device' && productNoEdit.id?.includes?.(data.record._sortIndex) ? '继承自产品物模型的数据不支持删除' :'删除',
|
||||
}"
|
||||
:disabled="target === 'device' && productNoEdit.id?.includes?.(data.record._sortIndex)"
|
||||
>
|
||||
<AIcon type="DeleteOutlined" />
|
||||
</PermissionButton>
|
||||
|
@ -242,7 +257,7 @@ const props = defineProps({
|
|||
|
||||
const _target = inject<'device' | 'product'>('_metadataType', props.target);
|
||||
|
||||
const { data: metadata, noEdit } = useMetadata(_target, props.type);
|
||||
const { data: metadata, noEdit, productNoEdit } = useMetadata(_target, props.type);
|
||||
const { hasOperate } = useOperateLimits(_target);
|
||||
|
||||
const metadataStore = useMetadataStore()
|
||||
|
@ -254,7 +269,7 @@ const tableRef = ref();
|
|||
const loading = ref(false)
|
||||
|
||||
// const columns = computed(() => MetadataMapping.get(props.type!));
|
||||
const {columns} = useColumns(props.type, _target, noEdit)
|
||||
const {columns} = useColumns(props.type, _target, noEdit, productNoEdit)
|
||||
|
||||
const detailData = reactive({
|
||||
data: {},
|
||||
|
|
|
@ -7,6 +7,8 @@ import {MetadataType} from "@/views/device/Product/typings";
|
|||
import { getUnit } from '@/api/device/instance';
|
||||
import {Ref} from "vue";
|
||||
import {omit} from "lodash-es";
|
||||
import { message } from 'jetlinks-ui-components'
|
||||
import { onlyMessage } from "@/utils/comm";
|
||||
interface DataTableColumnProps extends ColumnProps {
|
||||
type?: string,
|
||||
components?: {
|
||||
|
@ -106,7 +108,16 @@ export const typeSelectChange = (type: string) => {
|
|||
return obj
|
||||
}
|
||||
|
||||
export const useColumns = (type?: MetadataType, target?: 'device' | 'product', noEdit?: Ref<any>) => {
|
||||
const isExtendsProdcut = (index: string, productKeys: string, type: string) => {
|
||||
const vailKeys = productKeys[type] || []
|
||||
if (vailKeys.includes(index)) {
|
||||
onlyMessage('继承自产品物模型的数据不支持修改', 'warning')
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export const useColumns = (type?: MetadataType, target?: 'device' | 'product', noEdit?: Ref<any>, productNoEdit?: Ref<any>) => {
|
||||
|
||||
const BaseColumns: DataTableColumnProps[] = [
|
||||
{
|
||||
|
@ -137,6 +148,9 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
]
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'id')) {
|
||||
return false
|
||||
}
|
||||
const ids = (noEdit?.value?.id || []) as any[]
|
||||
return !ids.includes(record._sortIndex)
|
||||
}
|
||||
|
@ -155,6 +169,12 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
},
|
||||
{ max: 64, message: '最多可输入64个字符' },
|
||||
]
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'name')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@ -169,6 +189,12 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
props: {
|
||||
options: EventLevel
|
||||
}
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'expands')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -184,6 +210,12 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
title: '说明',
|
||||
dataIndex: 'description',
|
||||
type: 'text',
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'description')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
|
@ -205,6 +237,12 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
{ label: '否', value: false }
|
||||
]
|
||||
}
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'async')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -218,12 +256,24 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
type: 'components',
|
||||
components: {
|
||||
name: OutputParams
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'output')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'description',
|
||||
type: 'text',
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'description')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
|
@ -257,7 +307,13 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
}
|
||||
}]
|
||||
},
|
||||
width: 230
|
||||
width: 230,
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'valueType')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '属性来源',
|
||||
|
@ -269,8 +325,9 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
noEdit: noEdit?.value?.source || []
|
||||
}
|
||||
},
|
||||
doubleClick(){
|
||||
return target !== 'device'
|
||||
doubleClick(record){
|
||||
console.log(record);
|
||||
return target !== 'device' || (target === 'device' && record.expands.source === 'rule')
|
||||
},
|
||||
form: {
|
||||
required: true,
|
||||
|
@ -333,6 +390,12 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
}
|
||||
}]
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'valueType')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '读写类型',
|
||||
|
@ -340,12 +403,24 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', n
|
|||
type: 'components',
|
||||
components: {
|
||||
name: TagsType
|
||||
},
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'readType')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'description',
|
||||
type: 'text',
|
||||
doubleClick(record) {
|
||||
if (isExtendsProdcut(record._sortIndex, productNoEdit?.value, 'description')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<j-button type="link" stype="padding-left: 0;">
|
||||
<j-button type="link" style="padding-left: 0;" :disabled="disabled">
|
||||
<AIcon type="SettingOutlined" />
|
||||
配置
|
||||
</j-button>
|
||||
|
@ -7,6 +7,12 @@
|
|||
|
||||
<script setup name="ModelButton">
|
||||
|
||||
const props = defineProps({
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<j-popconfirm-modal
|
||||
body-style="padding-top:4px;width:600px;"
|
||||
placement="topRight"
|
||||
:disabled="disabled"
|
||||
@confirm="confirm"
|
||||
@cancel="cancel"
|
||||
@visibleChange="visibleChange"
|
||||
|
@ -49,7 +50,7 @@
|
|||
</div>
|
||||
|
||||
</template>
|
||||
<ModelButton />
|
||||
<ModelButton :disabled="disabled"/>
|
||||
</j-popconfirm-modal>
|
||||
</template>
|
||||
|
||||
|
@ -71,7 +72,11 @@ const props = defineProps({
|
|||
type: {
|
||||
type: String,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
})
|
||||
|
||||
const type = inject('_metadataType')
|
||||
|
|
|
@ -7,11 +7,13 @@ const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
|
|||
data: ComputedRef<MetadataItem[]>,
|
||||
metadata: Ref<Partial<DeviceMetadata>>,
|
||||
noEdit: Ref<any>
|
||||
productNoEdit: Ref<any>
|
||||
} => {
|
||||
const instanceStore = useInstanceStore()
|
||||
const productStore = useProductStore()
|
||||
const metadata = ref<Partial<DeviceMetadata>>({})
|
||||
const noEdit = ref<any>({})
|
||||
const productNoEdit = ref<any>({})
|
||||
|
||||
const data = computed(() => {
|
||||
const _metadataStr = type === 'product' ? productStore.current?.metadata : instanceStore.current.metadata
|
||||
|
@ -19,7 +21,8 @@ const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
|
|||
const newMetadata = (key ? _metadata?.[key] || [] : []) as MetadataItem[]
|
||||
|
||||
const indexKeys = newMetadata.map((item, index) => index)
|
||||
|
||||
noEdit.value = {}
|
||||
productNoEdit.value = {}
|
||||
noEdit.value.id = indexKeys
|
||||
|
||||
if (key === 'properties') {
|
||||
|
@ -30,31 +33,31 @@ const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
|
|||
const productMetadata: any = JSON.parse(instanceStore.current.productMetadata)
|
||||
const metaArray = key ? productMetadata[key] : []
|
||||
const productIndexKeys = metaArray?.map((item:any, index: number) => index) || []
|
||||
noEdit.value.id = productIndexKeys
|
||||
noEdit.value.name = productIndexKeys
|
||||
productNoEdit.value.id = productIndexKeys
|
||||
productNoEdit.value.name = productIndexKeys
|
||||
if (key === 'properties') {
|
||||
noEdit.value.valueType = productIndexKeys
|
||||
noEdit.value.expands = productIndexKeys
|
||||
productNoEdit.value.valueType = productIndexKeys
|
||||
productNoEdit.value.expands = productIndexKeys
|
||||
}
|
||||
|
||||
if (key === 'functions') {
|
||||
noEdit.value.async = productIndexKeys
|
||||
noEdit.value.inputs = productIndexKeys
|
||||
noEdit.value.output = productIndexKeys
|
||||
noEdit.value.description = productIndexKeys
|
||||
productNoEdit.value.async = productIndexKeys
|
||||
productNoEdit.value.inputs = productIndexKeys
|
||||
productNoEdit.value.output = productIndexKeys
|
||||
productNoEdit.value.description = productIndexKeys
|
||||
}
|
||||
|
||||
if (key === 'events') {
|
||||
noEdit.value.expands = productIndexKeys
|
||||
noEdit.value.outInput = productIndexKeys
|
||||
noEdit.value.properties = productIndexKeys
|
||||
noEdit.value.description = productIndexKeys
|
||||
productNoEdit.value.expands = productIndexKeys
|
||||
productNoEdit.value.outInput = productIndexKeys
|
||||
productNoEdit.value.properties = productIndexKeys
|
||||
productNoEdit.value.description = productIndexKeys
|
||||
}
|
||||
|
||||
if (key === 'tags') {
|
||||
noEdit.value.valueType = productIndexKeys
|
||||
noEdit.value.readType = productIndexKeys
|
||||
noEdit.value.description = productIndexKeys
|
||||
productNoEdit.value.valueType = productIndexKeys
|
||||
productNoEdit.value.readType = productIndexKeys
|
||||
productNoEdit.value.description = productIndexKeys
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +67,8 @@ const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
|
|||
return {
|
||||
data,
|
||||
metadata,
|
||||
noEdit
|
||||
noEdit,
|
||||
productNoEdit
|
||||
}
|
||||
}
|
||||
export default useMetadata
|
Loading…
Reference in New Issue