|
|
@@ -199,10 +199,41 @@ async function onEdit(row) {
|
|
|
showEditDialog.value = true
|
|
|
}
|
|
|
async function submit() {
|
|
|
+ const isHttpUrl = (val) => typeof val === 'string' && /^http/.test(val)
|
|
|
+ const buildPayload = () => {
|
|
|
+ const payload = { ...model.value }
|
|
|
+ if (Array.isArray(model.value.categories)) {
|
|
|
+ const original = model.value.categories
|
|
|
+ const mapped = original
|
|
|
+ .map((c) => (typeof c === 'object' ? c.id : c))
|
|
|
+ .map((id) => (typeof id === 'string' ? id.trim() : id))
|
|
|
+ const filtered = mapped.filter(
|
|
|
+ (id) => id !== undefined && id !== null && id !== '' && id !== 'undefined' && id !== 'null'
|
|
|
+ )
|
|
|
+ const asNumbers = filtered.map((id) => Number(id))
|
|
|
+ const finalIds = asNumbers.filter((id) => Number.isInteger(id) && id > 0)
|
|
|
+ const finalObjects = finalIds.map((id) => ({ id }))
|
|
|
+ payload.categories = finalObjects
|
|
|
+ }
|
|
|
+ if (model.value.cover === null) {
|
|
|
+ payload.cover = null
|
|
|
+ } else if (isHttpUrl(model.value.cover)) {
|
|
|
+ delete payload.cover
|
|
|
+ }
|
|
|
+ if (model.value.landscapeCover === null) {
|
|
|
+ payload.landscapeCover = null
|
|
|
+ } else if (isHttpUrl(model.value.landscapeCover)) {
|
|
|
+ delete payload.landscapeCover
|
|
|
+ }
|
|
|
+ return payload
|
|
|
+ }
|
|
|
+
|
|
|
+ const payload = buildPayload()
|
|
|
+
|
|
|
if (model.value.id) {
|
|
|
- await http.put(`/series/${model.value.id}`, model.value)
|
|
|
+ await http.put(`/series/${model.value.id}`, payload)
|
|
|
} else {
|
|
|
- await http.post('/series', model.value)
|
|
|
+ await http.post('/series', payload)
|
|
|
}
|
|
|
ElMessage.success('保存成功')
|
|
|
}
|