fix: 优化场景联动布尔值

This commit is contained in:
xieyonghong 2023-03-30 17:45:58 +08:00
parent 683751af53
commit 84e5a57c67
4 changed files with 31 additions and 26 deletions

View File

@ -211,7 +211,9 @@ const dateChange = (e: any) => {
emit('change', e) emit('change', e)
} }
myValue.value = props.modelValue watch(() => props.modelValue, () => {
myValue.value = props.modelValue
}, { immediate: true })
if (props.itemType === 'object') { if (props.itemType === 'object') {
objectValue.value = props.modelValue as string objectValue.value = props.modelValue as string

View File

@ -75,16 +75,18 @@ const formModel = reactive({
functionData: props.functionParameters functionData: props.functionParameters
}) })
const handlePropertiesOptions = (propertiesItem: any) => { const handlePropertiesOptions = (propertiesValueType: any) => {
const _type = propertiesItem?.valueType.type const _type = propertiesValueType?.type
if (_type === 'boolean') { if (_type === 'boolean') {
return [ return [
{ label: propertiesItem.valueType.falseText || '是', value: propertiesItem.valueType.falseValue || false }, { label: propertiesValueType?.falseText || '是', value: propertiesValueType?.falseValue || false },
{ label: propertiesItem.valueType.trueText || '否', value: propertiesItem.valueType.trueValue || true }, { label: propertiesValueType?.trueText || '否', value: propertiesValueType?.trueValue || true },
] ]
} else if (_type === 'enum') {
return propertiesValueType?.elements?.map((a: any) => ({ ...a, label: a.text }))
} }
return propertiesItem.valueType?.elements return propertiesValueType?.elements
} }
/** /**
@ -95,14 +97,14 @@ const functionData = computed(() => {
const arrCache = [] const arrCache = []
if (functionItem) { if (functionItem) {
const properties = functionItem.valueType ? functionItem.valueType.properties : functionItem.inputs; const properties = functionItem.input?.properties || functionItem.inputs;
for (const datum of properties) { for (const datum of properties) {
arrCache.push({ arrCache.push({
id: datum.id, id: datum.id,
name: datum.name, name: datum.name,
type: datum.valueType ? datum.valueType.type : '-', type: datum.valueType?.type || '-',
format: datum.valueType ? datum.valueType.format : undefined, format: datum.valueType?.format || undefined,
options: handlePropertiesOptions(datum), options: handlePropertiesOptions(datum.valueType),
value: undefined, value: undefined,
}); });
} }
@ -113,12 +115,10 @@ const functionData = computed(() => {
const rules = [{ const rules = [{
validator(_: string, value: any) { validator(_: string, value: any) {
console.log(value)
if (!value?.length && functionData.value.length) { if (!value?.length && functionData.value.length) {
return Promise.reject('请输入功能值') return Promise.reject('请输入功能值')
} else { } else {
let hasValue = value.find((item: { name: string, value: any}) => item.value === undefined) let hasValue = value.find((item: { name: string, value: any}) => item.value === undefined)
console.log('hasValue', hasValue)
if (hasValue) { if (hasValue) {
const functionItem = functionData.value.find((item: any) => item.id === hasValue.name) const functionItem = functionData.value.find((item: any) => item.id === hasValue.name)
return Promise.reject(functionItem?.name ? `请输入${functionItem?.name}` : '请输入功能值') return Promise.reject(functionItem?.name ? `请输入${functionItem?.name}` : '请输入功能值')

View File

@ -75,18 +75,32 @@ const callData = ref<Array<{ id: string, value: string | undefined }>>()
const writeForm = ref() const writeForm = ref()
const _value = ref([]) const _value = ref([])
const handleOptions = (item: any, type: string) => {
if (type === 'enum') {
return item.valueType.elements?.map((a: any) => ({ ...a, label: a.text }))
} else if (type === 'boolean') {
return [
{ label: item.valueType.trueText, value: item.valueType.trueValue },
{ label: item.valueType.falseText, value: item.valueType.falseValue },
]
}
return undefined
}
const callDataOptions = computed(() => { const callDataOptions = computed(() => {
const _valueKeys = Object.keys(props.value) const _valueKeys = Object.keys(props.value)
if (_valueKeys.length) { if (_valueKeys.length) {
return _valueKeys.map(key => { return _valueKeys.map(key => {
const item: any = props.properties.find((p: any) => p.id === key) const item: any = props.properties.find((p: any) => p.id === key)
console.log(item, props.value, key)
if (item) { if (item) {
const _options = handleOptions(item, item.valueType?.type)
return { return {
id: item.id, id: item.id,
name: item.name, name: item.name,
type: item.valueType ? item.valueType.type : '-', type: item.valueType ? item.valueType.type : '-',
format: item.valueType ? item.valueType.format : undefined, format: item.valueType ? item.valueType.format : undefined,
options: item.valueType ? item.valueType.element : undefined, options: _options,
value: props.value[key] value: props.value[key]
} }
} }
@ -96,7 +110,7 @@ const callDataOptions = computed(() => {
type: '', type: '',
format: undefined, format: undefined,
options: undefined, options: undefined,
value: props.value[key] value: undefined
} }
}) })
} }

View File

@ -35,7 +35,7 @@
<ValueItem <ValueItem
v-model:modelValue='record.value' v-model:modelValue='record.value'
:itemType="record.type" :itemType="record.type"
:options="handleOptions(record)" :options="record.options"
@change='valueChange' @change='valueChange'
/> />
</div> </div>
@ -87,17 +87,6 @@ const columns = [
}, },
] ]
const handleOptions = (record: any) => {
switch(record.type) {
case 'enum':
return (record?.options?.elements || []).map((item: any) => ({ label: item.text, value: item.value }))
case 'boolean':
return record?.options
default:
return undefined
}
}
const valueChange = () => { const valueChange = () => {
const _value = dataSource.value.map(item => { const _value = dataSource.value.map(item => {
return { return {