新建记录时生成临时id,修复新建记录上传的附件出现重复的问题

This commit is contained in:
jingrow 2025-10-21 23:19:31 +08:00
parent 43025dc802
commit 241ce2fa08
2 changed files with 12 additions and 5 deletions

View File

@ -281,7 +281,10 @@ const { originalSlug, entity } = usePageTypeSlug(route)
const overrideComponent = shallowRef<any | null>(null)
const toolbarComponent = shallowRef<any | null>(null)
const id = computed(() => route.params.id as string)
const isNew = computed(() => id.value === 'new')
const isNew = computed(() => {
const idValue = id.value
return idValue === 'new' || idValue.startsWith('new-')
})
const canEdit = ref(false)
const record = ref<any>({})
@ -964,13 +967,16 @@ async function handleSave() {
return
}
} catch {
// JSON
}
loading.value = true
try {
if (isNew.value) {
const url = `/api/data/${encodeURIComponent(entity.value)}`
const response = await axios.post(url, record.value, { headers: get_session_api_headers(), withCredentials: true })
const recordData = { ...record.value }
if (id.value.startsWith('new-')) {
recordData.__temporary_name = id.value
}
const response = await axios.post(url, recordData, { headers: get_session_api_headers(), withCredentials: true })
message.success(t('Created successfully'))
//
try { originalRecord.value = JSON.parse(JSON.stringify(record.value)) } catch { originalRecord.value = { ...record.value } }

View File

@ -350,8 +350,9 @@ async function handleDeleteSelected() {
}
function createRecordHandler() {
//
openDetail('new')
const randomStr = Math.random().toString(36).substring(2, 12)
const tempName = `new-${originalSlug.value}-${randomStr}`
openDetail(tempName)
}
function editRecord(row: any) {