fix: 优化物模型必填校验
This commit is contained in:
parent
be0aeb9a0a
commit
7f75c05f79
|
@ -232,7 +232,7 @@ const props = defineProps({
|
|||
|
||||
const target = inject<'device' | 'product'>('_metadataType', 'product');
|
||||
|
||||
const { data: metadata } = useMetadata(target, props.type);
|
||||
const { data: metadata, noEdit } = useMetadata(target, props.type);
|
||||
const { hasOperate } = useOperateLimits(target);
|
||||
|
||||
const metadataStore = useMetadataStore()
|
||||
|
@ -243,7 +243,7 @@ const dataSource = ref<MetadataItem[]>(metadata.value || []);
|
|||
const tableRef = ref();
|
||||
|
||||
// const columns = computed(() => MetadataMapping.get(props.type!));
|
||||
const {columns} = useColumns(props.type, target, dataSource, metadata.value)
|
||||
const {columns} = useColumns(props.type, target, dataSource, noEdit)
|
||||
|
||||
const detailData = reactive({
|
||||
data: {},
|
||||
|
@ -334,7 +334,7 @@ const handleAddClick = async (_data?: any, index?: number) => {
|
|||
|
||||
const newObject = _data || getDataByType()
|
||||
|
||||
// tableRef.value?.addItem?.(newObject, index)
|
||||
|
||||
|
||||
const data = [...dataSource.value];
|
||||
|
||||
|
@ -349,6 +349,8 @@ const handleAddClick = async (_data?: any, index?: number) => {
|
|||
data.push(newObject);
|
||||
}
|
||||
dataSource.value = data
|
||||
const _index = index !== undefined ? index + 1 : 0
|
||||
tableRef.value?.addItemAll?.(_index)
|
||||
};
|
||||
|
||||
const copyItem = (record: any, index: number) => {
|
||||
|
|
|
@ -32,7 +32,7 @@ const type = {
|
|||
report: '上报',
|
||||
};
|
||||
|
||||
export const useColumns = (type?: MetadataType, target?: 'device' | 'product', dataSource?: Ref<any[]>, noEditor?: any[]) => {
|
||||
export const useColumns = (type?: MetadataType, target?: 'device' | 'product', dataSource?: Ref<any[]>, noEdit?: Ref<any>) => {
|
||||
|
||||
const BaseColumns: DataTableColumnProps[] = [
|
||||
{
|
||||
|
@ -40,6 +40,7 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
dataIndex: 'id',
|
||||
type: 'text',
|
||||
form: {
|
||||
required: true,
|
||||
rules: [{
|
||||
validator(va:any,value: any) {
|
||||
const fieldIndex = va.field.split('.')[1]
|
||||
|
@ -55,6 +56,10 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
return Promise.reject('请输入标识')
|
||||
}
|
||||
}]
|
||||
},
|
||||
doubleClick(record) {
|
||||
const ids = (noEdit?.value?.id || []) as any[]
|
||||
return !ids.includes(record._sortIndex)
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -63,6 +68,7 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
width: 300,
|
||||
type: 'text',
|
||||
form: {
|
||||
required: true,
|
||||
rules: [{
|
||||
required: true,
|
||||
message: '请输入名称'
|
||||
|
@ -163,6 +169,18 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
components: {
|
||||
name: DataType
|
||||
},
|
||||
form: {
|
||||
required: true,
|
||||
rules: [{
|
||||
validator(_: any, value: any) {
|
||||
console.log('validator',value)
|
||||
if (!value?.valueType?.type) {
|
||||
return Promise.reject('请选择数据类型')
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
}]
|
||||
},
|
||||
width: 230
|
||||
},
|
||||
{
|
||||
|
@ -170,7 +188,10 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
dataIndex: 'expands',
|
||||
type: 'components',
|
||||
components: {
|
||||
name: Source
|
||||
name: Source,
|
||||
props: {
|
||||
noEdit: noEdit?.value?.source || []
|
||||
}
|
||||
},
|
||||
doubleClick(){
|
||||
return target !== 'device'
|
||||
|
@ -247,7 +268,7 @@ export const useColumns = (type?: MetadataType, target?: 'device' | 'product', d
|
|||
const columns = ref<any[]>([])
|
||||
|
||||
watch(() => JSON.stringify(dataSource!.value), () => {
|
||||
console.log(dataSource!.value)
|
||||
console.log(noEdit!.value)
|
||||
switch(type) {
|
||||
case 'properties':
|
||||
columns.value = PropertyColumns
|
||||
|
|
|
@ -30,12 +30,14 @@ const myValue = ref()
|
|||
|
||||
const change = () => {
|
||||
const newData = { ...props.value }
|
||||
set(newData, name, myValue.value)
|
||||
set(newData, props.name, myValue.value)
|
||||
console.log(newData);
|
||||
emit('update:value', newData)
|
||||
}
|
||||
|
||||
watch(() => JSON.stringify(props.data), () => {
|
||||
myValue.value = get(props.data, name)
|
||||
console.log(props.value, props.name);
|
||||
myValue.value = get(props.value, props.name) || false
|
||||
}, { immediate: true })
|
||||
|
||||
</script>
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<template #valueType="{ data }">
|
||||
<span>{{ data.record.valueType?.type }}</span>
|
||||
</template>
|
||||
<template #required="{ data }">
|
||||
<span>{{ data.record.expands?.required ? "是": '否' }}</span>
|
||||
</template>
|
||||
<template #config="{ data }">
|
||||
<OtherConfigInfo :value="data.record.valueType"></OtherConfigInfo>
|
||||
</template>
|
||||
|
@ -25,8 +28,8 @@ import {
|
|||
import { ConstraintSelect, OtherConfigInfo, ValueObject } from '../index'
|
||||
|
||||
const columns = [
|
||||
{ title: '参数标识', dataIndex: 'id', type: 'text' },
|
||||
{ title: '参数名称', dataIndex: 'name', type: 'text' },
|
||||
{ title: '参数标识', dataIndex: 'id', type: 'text', form: { required: true, rules: [{ required: true, message: '请输入标识'}]} },
|
||||
{ title: '参数名称', dataIndex: 'name', type: 'text', form: { required: true, rules: [{ required: true, message: '请输入名称'}]} },
|
||||
{
|
||||
title: '填写约束',
|
||||
dataIndex: 'required',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
:options="PropertySource"
|
||||
placeholder="请选择来源"
|
||||
@change="onChange"
|
||||
:disabled="false"
|
||||
:disabled="disabled"
|
||||
>
|
||||
</j-select>
|
||||
<j-popconfirm-modal
|
||||
|
@ -75,6 +75,10 @@ const props = defineProps({
|
|||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
noEdit: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits<Emit>();
|
||||
|
@ -83,6 +87,12 @@ const myValue = ref<SourceType>('');
|
|||
const type = ref<string>('');
|
||||
const virtualRuleRef = ref<any>(null);
|
||||
|
||||
const disabled = computed(() => {
|
||||
console.log(props.value);
|
||||
console.log(props.noEdit);
|
||||
return props.noEdit?.length ? props.noEdit.includes(props.value._sortIndex) :false
|
||||
})
|
||||
|
||||
const onChange = (keys: SourceType) => {
|
||||
myValue.value = keys;
|
||||
emit('update:value', {
|
||||
|
|
|
@ -3,24 +3,32 @@ import {useInstanceStore} from "store/instance";
|
|||
import {useProductStore} from "store/product";
|
||||
import type { Ref, ComputedRef } from "vue";
|
||||
|
||||
const useMetadata = (type: 'device' | 'product', key?: MetadataType): {
|
||||
const useMetadata = (type: 'device' | 'product', key?: MetadataType, ): {
|
||||
data: ComputedRef<MetadataItem[]>,
|
||||
metadata: Ref<Partial<DeviceMetadata>>
|
||||
metadata: Ref<Partial<DeviceMetadata>>,
|
||||
noEdit: Ref<any>
|
||||
} => {
|
||||
const instanceStore = useInstanceStore()
|
||||
const productStore = useProductStore()
|
||||
const metadata = ref<Partial<DeviceMetadata>>({})
|
||||
const noEdit = ref<any>({})
|
||||
|
||||
const data = computed(() => {
|
||||
const _metadataStr = type === 'product' ? productStore.current?.metadata : instanceStore.current.metadata
|
||||
const _metadata = JSON.parse(_metadataStr || '{}')
|
||||
console.log(_metadata)
|
||||
return (key ? _metadata[key] : []) as MetadataItem[]
|
||||
const newMetadata = (key ? _metadata[key] : []) as MetadataItem[]
|
||||
const indexs = newMetadata.map((item, index) => index)
|
||||
noEdit.value.id = indexs
|
||||
if (key === 'properties') {
|
||||
noEdit.value.source = indexs
|
||||
}
|
||||
return newMetadata
|
||||
})
|
||||
|
||||
return {
|
||||
data,
|
||||
metadata
|
||||
metadata,
|
||||
noEdit
|
||||
}
|
||||
}
|
||||
export default useMetadata
|
|
@ -3825,8 +3825,8 @@ jetlinks-store@^0.0.3:
|
|||
|
||||
jetlinks-ui-components@^1.0.23, jetlinks-ui-components@^1.0.24:
|
||||
version "1.0.24"
|
||||
resolved "http://registry.jetlinks.cn/jetlinks-ui-components/-/jetlinks-ui-components-1.0.24.tgz#4e5c267278af7a0893df5d27e221baccdde973d0"
|
||||
integrity sha512-OmiI624o6wCBXmQCP3jXyfGagNfZTJ7g/U5FMOB4dFAEeI+hdO1pnS7Cb/uJIH570K+jbx3Q4qjREJ0OjlddNg==
|
||||
resolved "http://registry.jetlinks.cn/jetlinks-ui-components/-/jetlinks-ui-components-1.0.24.tgz#c40d77f2e4544f3bfccd5736670dc6ec1c1c7745"
|
||||
integrity sha512-oggX6nWZ8uDoA7EVdc7y5xj5EbxvHmeFJx3TDif1S+3O0oH4ejx387nV3nvpE1d3QB4R463VHeB5Lv4a64GgRQ==
|
||||
dependencies:
|
||||
"@vueuse/core" "^9.12.0"
|
||||
"@vueuse/router" "^9.13.0"
|
||||
|
|
Loading…
Reference in New Issue