2024-08-20 12:11:31 +00:00
|
|
|
import { ref, Ref, unref, computed } from 'vue'
|
|
|
|
import { Message, MessageBox } from 'element-ui'
|
|
|
|
|
|
|
|
export default function (propertyState: any, tables: Ref<any[]>) {
|
|
|
|
const sourceTable = ref([])
|
|
|
|
function selectSource(sourceField: number) {
|
2024-08-21 01:17:14 +00:00
|
|
|
const item: any = propertyState.sourceFieldList.find((a: any) => a.id === sourceField)
|
2024-08-20 12:11:31 +00:00
|
|
|
if (item.type.includes('TABLE')) {
|
|
|
|
sourceTable.value = item.itemList
|
|
|
|
} else {
|
2024-08-21 01:17:14 +00:00
|
|
|
sourceTable.value = []
|
2024-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const targetTable = ref([])
|
|
|
|
function selectTarget(targetField: number) {
|
2024-08-21 01:17:14 +00:00
|
|
|
const item: any = propertyState.targetFieldList.find((a: any) => a.id === targetField)
|
2024-08-20 12:11:31 +00:00
|
|
|
if (item.type.includes('TABLE')) {
|
|
|
|
targetTable.value = item.itemList
|
|
|
|
} else {
|
2024-08-21 01:17:14 +00:00
|
|
|
targetTable.value = []
|
2024-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const keys = computed(() => {
|
2024-08-21 01:17:14 +00:00
|
|
|
return unref(tables)
|
|
|
|
.filter((item: any) => item.sourceValue && item.targetValue)
|
|
|
|
.map((item: any) => {
|
|
|
|
return `${item.sourceValue}-${item.targetValue}`
|
|
|
|
})
|
|
|
|
})
|
2024-08-20 12:11:31 +00:00
|
|
|
function getDisabled(record: any, item: any, type: string) {
|
2024-08-21 01:17:14 +00:00
|
|
|
if (!record.targetValue && !record.sourceValue) return false
|
2024-08-20 12:11:31 +00:00
|
|
|
return keys.value.includes(type === 'source' ? `${item.id}-${record.targetValue}` : `${record.sourceValue}-${item.id}`)
|
|
|
|
}
|
|
|
|
function handleAddTable() {
|
|
|
|
tables.value.push({})
|
|
|
|
}
|
|
|
|
function handleDeleteTable(index: number) {
|
|
|
|
MessageBox.confirm('您确定要删除吗?', '提示', {
|
|
|
|
confirmButtonClass: 'el-button--danger',
|
2024-08-21 01:17:14 +00:00
|
|
|
type: 'warning',
|
2024-08-20 12:11:31 +00:00
|
|
|
})
|
|
|
|
.then(async () => {
|
|
|
|
tables.value.splice(index, 1)
|
|
|
|
})
|
2024-08-21 01:17:14 +00:00
|
|
|
.catch((e) => {})
|
2024-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
sourceTable,
|
|
|
|
targetTable,
|
|
|
|
selectSource,
|
|
|
|
selectTarget,
|
|
|
|
getDisabled,
|
|
|
|
handleAddTable,
|
2024-08-21 01:17:14 +00:00
|
|
|
handleDeleteTable,
|
2024-08-20 12:11:31 +00:00
|
|
|
}
|
|
|
|
}
|