Browse Source

更新用户头像上传代码

reghao 3 năm trước cách đây
mục cha
commit
ffd2f284c4
1 tập tin đã thay đổi với 7 bổ sung7 xóa
  1. 7 7
      src/components/setting/user-head-setting.vue

+ 7 - 7
src/components/setting/user-head-setting.vue

@@ -71,6 +71,7 @@ export default {
       userInfo: {
         username: ''
       },
+      avatarFile: null,
       files: [],
       rules: [
         value => !value || value.size < 2000000 || '头像大小必须在2MB以内!'
@@ -84,6 +85,7 @@ export default {
   },
   methods: {
     setFile(value) {
+      this.avatarFile = value
       this.files = []
       this.files.push(value)
     },
@@ -94,10 +96,9 @@ export default {
         return
       }
       const formData = new FormData()
-      for (let i = 0; i < this.files.length; i++) {
-        formData.append('file[]', this.files[i])
-      }
-      fetch(`/api/upload/avatar`, {
+      formData.append('videoFileId', 'test')
+      formData.append('file', this.avatarFile)
+      fetch(`//file.reghao.cn/api/file/upload/video/cover`, {
         headers: {
           'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
         },
@@ -106,9 +107,8 @@ export default {
         body: formData
       }).then(response => response.json())
         .then(json => {
-          if (json.status === 200) {
-            //
-            this.userInfo.avatarUrl = json.data[0].fileUrl
+          if (json.code === 0) {
+            this.userInfo.avatarUrl = json.data.originalUrl
             this.message = '上传成功,请点击保存,保存头像设置!'
             this.showMessage = true
           } else {