فهرست منبع

使用 axios 替换 fetch 获取视频分类

reghao 4 سال پیش
والد
کامیت
a935014a8b
2فایلهای تغییر یافته به همراه27 افزوده شده و 18 حذف شده
  1. 7 1
      src/api/media/video.js
  2. 20 17
      src/components/upload/upload-video.vue

+ 7 - 1
src/api/media/video.js

@@ -4,7 +4,8 @@ const videoApi = {
   videoRecommendApi: '/api/media/video/post/recommend',
   similarVideoApi: '/api/media/video/post/similar',
   videoInfoApi: '/api/media/video/post',
-  videoUrlApi: '/api/media/video/url'
+  videoUrlApi: '/api/media/video/url',
+  videoCategoryApi: '/api/media/video/category'
 }
 
 // 视频推荐接口
@@ -26,3 +27,8 @@ export function videoInfo(videoId) {
 export function videoUrl(videoId) {
   return $axios.get(videoApi.videoUrlApi + '/' + videoId)
 }
+
+// 视频 URL 接口
+export function videoCategory() {
+  return $axios.get(videoApi.videoCategoryApi)
+}

+ 20 - 17
src/components/upload/upload-video.vue

@@ -123,6 +123,7 @@
 
 <script>
 import FilePondUpload from '@/components/upload/filepond-upload.vue'
+import { videoCategory } from '@/api/media/video'
 export default {
   components: {
     FilePondUpload
@@ -158,7 +159,7 @@ export default {
     }
   },
   created() {
-    this.getCategoryList()
+    this.getVideoCategory()
   },
   methods: {
     publish() {
@@ -262,24 +263,26 @@ export default {
           return null
         })
     },
-    getCategoryList() {
-      fetch(`/api/media/video/category`, {
-        headers: {
-          'Content-Type': 'application/json; charset=UTF-8',
-          'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
-        },
-        method: 'GET',
-        credentials: 'include'
-      }).then(response => response.json())
-        .then(json => {
-          for (let i = 0; i < json.data.length; i++) {
-            const name = json.data[i].name
-            this.category.push(name)
-            this.categoryMap.Set(name, json.data[i])
+    getVideoCategory() {
+      videoCategory()
+        .then(res => {
+          if (res.code === 0) {
+            for (let i = 0; i < res.data.length; i++) {
+              const name = res.data[i].name
+              this.category.push(name)
+              this.categoryMap.Set(name, res.data[i])
+            }
+          } else {
+            this.$notify({
+              title: res.code,
+              message: res.msg,
+              type: 'warning',
+              duration: 500
+            })
           }
         })
-        .catch(e => {
-          return null
+        .catch(error => {
+          this.$message.error(error.message)
         })
     },
     getCategory(name) {