优化Link控件
This commit is contained in:
parent
f43410abaf
commit
88e0e32c75
@ -110,6 +110,15 @@ async function getRecordTitle(pagetype: string, recordName: string) {
|
||||
return recordName
|
||||
}
|
||||
}
|
||||
// 创建新建选项
|
||||
function createNewOption() {
|
||||
return {
|
||||
label: `${t('Create')}${t(options.value)}`,
|
||||
value: 'create_new',
|
||||
type: 'create'
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索链接选项
|
||||
async function searchOptions() {
|
||||
if (!options.value) return
|
||||
@ -132,39 +141,22 @@ async function searchOptions() {
|
||||
|
||||
if (result.success && result.data) {
|
||||
// 处理记录数据,优先显示标题字段
|
||||
const processedRecords = await Promise.all(
|
||||
result.data.map(async (item: any) => {
|
||||
const title = titleField === 'name' ? item.name : (item[titleField] || item.name)
|
||||
return {
|
||||
label: title,
|
||||
value: item.name,
|
||||
title: title
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
dropdownOptions.value = [
|
||||
...processedRecords,
|
||||
{
|
||||
label: `${t('Create')}${t(options.value)}`,
|
||||
value: 'create_new',
|
||||
type: 'create'
|
||||
const processedRecords = result.data.map((item: any) => {
|
||||
const title = titleField === 'name' ? item.name : (item[titleField] || item.name)
|
||||
return {
|
||||
label: title,
|
||||
value: item.name,
|
||||
title: title
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
dropdownOptions.value = [...processedRecords, createNewOption()]
|
||||
} else {
|
||||
dropdownOptions.value = [{
|
||||
label: `${t('Create')}${t(options.value)}`,
|
||||
value: 'create_new',
|
||||
type: 'create'
|
||||
}]
|
||||
dropdownOptions.value = [createNewOption()]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('搜索选项失败:', error)
|
||||
dropdownOptions.value = [{
|
||||
label: `${t('Create')}${t(options.value)}`,
|
||||
value: 'create_new',
|
||||
type: 'create'
|
||||
}]
|
||||
dropdownOptions.value = [createNewOption()]
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user