新建记录时生成临时id,修复新建记录上传的附件出现重复的问题
This commit is contained in:
parent
43025dc802
commit
241ce2fa08
@ -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 } }
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user