Эх сурвалжийг харах

feat(SeriesView): 优化编辑功能并添加分类数据获取

wuyi 5 сар өмнө
parent
commit
dcef5b6b63
1 өөрчлөгдсөн 22 нэмэгдсэн , 0 устгасан
  1. 22 0
      src/views/SeriesView.vue

+ 22 - 0
src/views/SeriesView.vue

@@ -184,7 +184,18 @@ const rules = {
 }
 const { showEditDialog } = setupEditDialog(model)
 async function onEdit(row) {
+    if (!categories.value.length) {
+        await fetchCategories()
+    }
     model.value = row ? await http.get(`/series/${row.id}`) : {}
+    if (Array.isArray(model.value.categories)) {
+        const isIdArray = model.value.categories.length > 0 && typeof model.value.categories[0] !== 'object'
+        if (isIdArray) {
+            model.value.categories = model.value.categories
+                .map((cid) => categories.value.find((c) => c.id === cid))
+                .filter(Boolean)
+        }
+    }
     showEditDialog.value = true
 }
 async function submit() {
@@ -196,6 +207,17 @@ async function submit() {
     ElMessage.success('保存成功')
 }
 const categories = ref([])
+async function fetchCategories() {
+    try {
+        const res = await http.get('/categories', { order: 'sort', pageSize: 1000 })
+        categories.value = Array.isArray(res) ? res : res?.data || []
+    } catch (e) {
+        categories.value = []
+    }
+}
+onMounted(() => {
+    fetchCategories()
+})
 const showUploadDialog = ref(false)
 const uploading = ref(false)
 const uploadingVideo = ref(false)