Browse Source

feat: api adjust

arvin 6 years ago
parent
commit
d1f2abe1ff

+ 0 - 302
components/editor.vue

@@ -1,302 +0,0 @@
-<template>
-  <div class="editor">
-    <el-input v-model="title" class="title" placeholder="请输入文章标题" :maxlength="50"></el-input>
-    <el-input v-model="subTitle" class="sub-title" placeholder="请输入导语(选填)" :maxlength="300"></el-input>
-    <div class="quill-editor" v-model="content" v-quill:myQuillEditor="editorOption"></div>
-    <h5 class="label">封面图</h5>
-    <el-upload
-      action="#"
-      list-type="picture-card"
-      :multiple="false"
-      :limit="1"
-      accept="image/png, image/jpeg"
-      :before-upload="handleFileChange"
-      :http-request="handleFileUpload"
-    >
-      <i slot="default" class="el-icon-plus"></i>
-      <div slot="file" slot-scope="{file}">
-        <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
-        <span class="el-upload-list__item-actions">
-          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
-            <i class="el-icon-zoom-in"></i>
-          </span>
-          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
-            <i class="el-icon-download"></i>
-          </span>
-          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
-            <i class="el-icon-delete"></i>
-          </span>
-        </span>
-      </div>
-      <div slot="tip" class="el-upload__tip">建议尺寸:700*480,大小在500k以内</div>
-    </el-upload>
-    <el-dialog :visible.sync="dialogVisible">
-      <img width="100%" :src="cover_url" alt />
-    </el-dialog>
-    <h5 class="label">选择分类</h5>
-    <el-select v-model="categoryId" placeholder="请选择文章分类" class="class">
-      <el-option
-        v-for="item in categoryList"
-        :key="item.value"
-        :label="item.label"
-        :value="item.value"
-      ></el-option>
-    </el-select>
-    <h5 class="label">标签</h5>
-    <el-select
-      class="tags"
-      v-model="tags"
-      multiple
-      filterable
-      allow-create
-      default-first-option
-      placeholder="每个标签以逗号隔开、最多5个,如:技术,经验"
-    >
-      <el-option
-        v-for="item in tagOptions"
-        :key="item.value"
-        :label="item.label"
-        :value="item.value"
-      ></el-option>
-    </el-select>
-    <footer>
-      <el-button type="primary" @click="publish">发布</el-button>
-      <el-button @click="cancel">取消</el-button>
-    </footer>
-  </div>
-</template>
-
-<script>
-import Vue from 'vue';
-import 'quill/dist/quill.core.css'
-import 'quill/dist/quill.snow.css'
-// import 'quill/dist/quill.bubble.css'
-if (process.browser) {
-  const VueQuillEditor = require('vue-quill-editor/dist/ssr')
-  Vue.use(VueQuillEditor)
-}
-import hljs from 'hljs'
-export default {
-  head() {
-    return {
-      script: [
-      ]
-    };
-  },
-  components: {
-    // quillEditor
-    // Editor
-  },
-  data() {
-    return {
-      topicId: '654', // 编辑
-      title: '',
-      subTitle: '',
-      content: '',
-      cover_url: '',
-      tags: [],
-      categoryId: '123',
-      dialogVisible: false,
-      disabled: false,
-      categoryList: [{
-        value: 'default',
-        label: '推荐'
-      }],
-      tagOptions: [{
-        value: 'HTML',
-        label: 'HTML'
-      }, {
-        value: 'CSS',
-        label: 'CSS'
-      }, {
-        value: 'JavaScript',
-        label: 'JavaScript'
-      }],
-      fileList: [],
-      uploading: false,
-      editorOption: {
-        theme: 'snow',
-        placeholder: '请输入正文...',
-        modules: {
-          toolbar: [
-            ['bold', 'italic', 'underline', 'strike'],
-            ['blockquote', 'code-block'],
-            [{ 'header': 1 }, { 'header': 2 }],
-            [{ 'list': 'ordered' }, { 'list': 'bullet' }],
-            [{ 'script': 'sub' }, { 'script': 'super' }],
-            [{ 'indent': '-1' }, { 'indent': '+1' }],
-            [{ 'direction': 'rtl' }],
-            [{ 'size': ['small', false, 'large', 'huge'] }],
-            [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
-            [{ 'font': [] }],
-            [{ 'color': [] }, { 'background': [] }],
-            [{ 'align': [] }],
-            ['clean'],
-            ['link', 'image']
-          ],
-          syntax: {
-            highlight: text => hljs.highlightAuto(text).value
-          }
-        }
-      }
-    };
-  },
-  computed: {
-  },
-  mounted() {
-    this.needLogin();
-    this.$axios.$post(
-      `/api/community/topic/get_nav_list`
-    ).then(res => {
-      if (res.status === 1) {
-        this.categoryList = res.data.map(it => ({ value: it.id, label: it.name }));
-      }
-    });
-  },
-  methods: {
-    publish() {
-      if (!this.title) {
-        this.$message.error('请输入文章标题');
-        return;
-      }
-      if (!this.categoryId) {
-        this.$message.error('请选择文章分类');
-        return;
-      }
-      if (this.tags.length > 5) {
-        this.$message.error('标签最多可填写5个标签,请删减');
-        return;
-      }
-
-      if (this.content.length > 100000) {
-        this.$message.error('文章正文不可超过10万字符,请删减');
-        return;
-      }
-      const data = {
-        topicId: this.topicId,
-        title: this.title,
-        intro: this.subTitle,
-        body: this.content,
-        categoryId: this.categoryId,
-        label: this.tags.join(',').slice(0, -1),
-        cover_url: this.cover_url
-      };
-      if (this.topicId) {
-        this.$axios.$post(
-          `/api/community/topic/update_topic`,
-          data
-        ).then(res => {
-          console.log(res);
-          this.$message.success('更新成功!')
-          // TODO go details
-        })
-      } else {
-        this.$axios.$post(
-          `/api/community/topic/create_topic`,
-          data
-        ).then(res => {
-          console.log(res);
-          this.$message.success('发布成功!')
-          // TODO go details
-        })
-
-      }
-    },
-    cancel() {
-      this.$router.back();
-    },
-    handleFileChange(file) {
-      console.log(file)
-      if (file.size / 1024 > 500) {
-        this.$message.error('图片大小不得超过500k,请重新选择');
-        return false;
-      }
-      this.fileList = [file];
-      return true;
-    },
-    handleFileUpload(...arge) {
-      console.log(arge)
-    },
-    onEditorChange(event) {
-      console.log('onEditorChange')
-    },
-    handleRemove(file) {
-      console.log(file);
-    },
-    handlePictureCardPreview(file) {
-      this.cover_url = file.url;
-      this.dialogVisible = true;
-    },
-    handleDownload(file) {
-      console.log(file);
-    }
-  }
-}
-</script>
-
-<style lang="scss">
-.editor {
-  position: relative;
-  padding: 20px;
-  width: 740px;
-  background: #fff;
-  .title,
-  .sub-title {
-    .el-input__inner {
-      padding: 0;
-      border: 0;
-      border-radius: 0;
-    }
-  }
-  .title {
-    margin: 10px auto 20px;
-    font-size: 28px;
-    font-family: PingFangSC-Medium;
-    font-weight: 500;
-    color: rgba(29, 42, 58, 1);
-    line-height: 40px;
-  }
-  .sub-title {
-    margin-bottom: 28px;
-    height: 18px;
-    font-size: 13px;
-    font-family: PingFangSC-Regular;
-    font-weight: 400;
-    color: rgba(145, 154, 167, 1);
-    line-height: 18px;
-    border-left: 2px solid #0093fd;
-    .el-input__inner {
-      height: 18px;
-      line-height: 18px;
-    }
-  }
-  .label {
-    margin: 20px auto 10px;
-    font-size: 13px;
-    font-family: PingFangSC-Medium;
-    font-weight: 500;
-    color: rgba(25, 34, 46, 1);
-    line-height: 18px;
-  }
-  .quill-editor {
-    min-height: 450px;
-  }
-  .ql-snow.ql-toolbar::after {
-    display: inline-block;
-  }
-  .class {
-    width: 320px;
-  }
-  .tags {
-    width: 560px;
-  }
-  footer {
-    margin: 40px 0;
-    button {
-      width: 100px;
-      height: 40px;
-      border-radius: 0;
-    }
-  }
-}
-</style>

+ 51 - 0
components/topics/edit.vue

@@ -0,0 +1,51 @@
+<template>
+  <div>
+    <breadcrumb :locations="locations"></breadcrumb>
+    <editor-aside></editor-aside>
+    <editor></editor>
+  </div>
+</template>
+
+<script>
+import { mapState } from 'vuex'
+import breadcrumb from '@/components/breadcrumb'
+import editorAside from '@/components/topics/editor-aside'
+import editor from '@/components/topics/editor'
+// import getDeviceType from '@/mixins/getDeviceType'
+import qs from 'qs';
+
+export default {
+  props: ['locations'],
+  head: {
+    title: '发布文章-技术圈',
+  },
+  components: {
+    breadcrumb,
+    editor,
+    editorAside,
+  },
+  // mixins: [getDeviceType],
+  data() {
+    return {
+    }
+  },
+  mounted() {
+    // this.getList()
+  },
+  methods: {
+    async getList() {
+      let extraHeaders = {};
+      if (this.deviceType === 'ios') {
+        extraHeaders = this.getSign();
+      }
+      let res = await this.$axios.$post(`/api/vip/getList`, extraHeaders)
+      if (res) {
+        this.vipList = res.data
+      }
+    }
+  }
+}
+</script>
+
+<style>
+</style>

+ 0 - 1
components/editor-aside.vue

@@ -9,7 +9,6 @@
 
 <script>
 export default {
-  // props: ['locations'],
   data() {
     return {
       activities: [

+ 391 - 0
components/topics/editor.vue

@@ -0,0 +1,391 @@
+<template>
+  <div class="editor">
+    <el-input v-model="title" class="title" placeholder="请输入文章标题" :maxlength="50"></el-input>
+    <el-input v-model="subTitle" class="sub-title" placeholder="请输入导语(选填)" :maxlength="300"></el-input>
+    <div class="quill-editor" v-model="content" v-quill:myQuillEditor="editorOption"></div>
+    <input type="file" id="imgInput" @change="handleContentFileChange" style="display: none;" />
+    <h5 class="label">封面图</h5>
+    <el-upload
+      action="#"
+      list-type="picture-card"
+      :file-list="fileList"
+      :multiple="false"
+      accept="image/png, image/jpeg"
+      :before-upload="handleFileChange"
+      :http-request="handleFileUpload"
+    >
+      <i slot="default" class="el-icon-plus"></i>
+      <div slot="file" slot-scope="{file}">
+        <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
+        <span class="el-upload-list__item-actions">
+          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
+            <i class="el-icon-zoom-in"></i>
+          </span>
+          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
+            <i class="el-icon-download"></i>
+          </span>
+          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
+            <i class="el-icon-delete"></i>
+          </span>
+        </span>
+      </div>
+      <div slot="tip" class="el-upload__tip">建议尺寸:700*480,大小在500k以内</div>
+    </el-upload>
+    <el-dialog :visible.sync="dialogVisible">
+      <img width="100%" :src="cover_url" alt />
+    </el-dialog>
+    <h5 class="label">选择分类</h5>
+    <el-select v-model="categoryId" placeholder="请选择文章分类" class="class">
+      <el-option
+        v-for="item in categoryList"
+        :key="item.value"
+        :label="item.label"
+        :value="item.value"
+      ></el-option>
+    </el-select>
+    <h5 class="label">标签</h5>
+    <el-select
+      class="tags"
+      v-model="tags"
+      multiple
+      filterable
+      allow-create
+      default-first-option
+      placeholder="每个标签以逗号隔开、最多5个,如:技术,经验"
+    >
+      <el-option
+        v-for="item in tagOptions"
+        :key="item.value"
+        :label="item.label"
+        :value="item.value"
+      ></el-option>
+    </el-select>
+    <footer>
+      <el-button type="primary" @click="publish">发布</el-button>
+      <el-button @click="cancel">取消</el-button>
+    </footer>
+  </div>
+</template>
+
+<script>
+import Vue from "vue";
+import "quill/dist/quill.core.css";
+import "quill/dist/quill.snow.css";
+// import 'quill/dist/quill.bubble.css'
+if (process.browser) {
+  const VueQuillEditor = require("vue-quill-editor/dist/ssr");
+  Vue.use(VueQuillEditor);
+}
+import hljs from "hljs";
+export default {
+  head() {
+    return {
+      script: []
+    };
+  },
+  components: {
+    // quillEditor
+    // Editor
+  },
+  data() {
+    return {
+      topicId: "", // 编辑
+      title: "",
+      subTitle: "",
+      content: "",
+      cover_url: "",
+      tags: [],
+      categoryId: "",
+      dialogVisible: false,
+      disabled: false,
+      categoryList: [
+        {
+          value: "default",
+          label: "推荐"
+        }
+      ],
+      fileList: [],
+      tagOptions: [
+        {
+          value: "HTML",
+          label: "HTML"
+        },
+        {
+          value: "CSS",
+          label: "CSS"
+        },
+        {
+          value: "JavaScript",
+          label: "JavaScript"
+        }
+      ],
+      uploading: false,
+      editorOption: {
+        theme: "snow",
+        placeholder: "请输入正文...",
+        modules: {
+          toolbar: [
+            ["bold", "italic", "underline", "strike"],
+            ["blockquote", "code-block"],
+            [{ header: 1 }, { header: 2 }],
+            [{ list: "ordered" }, { list: "bullet" }],
+            [{ script: "sub" }, { script: "super" }],
+            [{ indent: "-1" }, { indent: "+1" }],
+            [{ direction: "rtl" }],
+            [{ size: ["small", false, "large", "huge"] }],
+            [{ header: [1, 2, 3, 4, 5, 6, false] }],
+            [{ font: [] }],
+            [{ color: [] }, { background: [] }],
+            [{ align: [] }],
+            ["clean"],
+            ["link", "image"]
+          ],
+          syntax: {
+            highlight: text => hljs.highlightAuto(text).value
+          }
+        }
+      }
+    };
+  },
+  computed: {},
+  mounted() {
+    this.needLogin();
+    this.loadData();
+    this.$axios.$post(`/api/community/topic/get_category`).then(res => {
+      if (res.status === 1) {
+        this.categoryList = res.data.map(it => ({
+          value: it.id,
+          label: it.name
+        }));
+      }
+    });
+    console.log(this.myQuillEditor);
+    // 为图片ICON绑定事件  getModule 为编辑器的内部属性
+    this.myQuillEditor
+      .getModule("toolbar")
+      .addHandler("image", this.imgHandler);
+    // this.myQuillEditor
+    //   .getModule("toolbar")
+    //   .addHandler("video", this.videoHandler); // 为视频ICON绑定事件
+  },
+  methods: {
+    loadData() {
+      const data = {
+        topicId: this.$route.params.id
+      };
+      this.$axios
+        .$post(`/api/community/topic/get_edit_topic`, data)
+        .then(res => {
+          console.log(res);
+          const topic = res.data;
+          if (topic) {
+            this.cover_url = topic.cover_url;
+            this.topicId = topic.id;
+            this.title = topic.title;
+            this.intro = topic.intro;
+            this.content = topic.body;
+            this.tags = topic.label.split(',');
+            this.categoryId = topic.category_id;
+            if (this.cover_url) {
+              this.fileList.push({
+                name: 'cover_image',
+                url: this.cover_url
+              })
+            }
+          }
+          // TODO go details
+        });
+    },
+    publish() {
+      if (!this.title) {
+        this.$message.error("请输入文章标题");
+        return;
+      }
+      if (!this.categoryId) {
+        this.$message.error("请选择文章分类");
+        return;
+      }
+      if (this.tags.length > 5) {
+        this.$message.error("标签最多可填写5个标签,请删减");
+        return;
+      }
+      if (this.content.length > 100000) {
+        this.$message.error("文章正文不可超过10万字符,请删减");
+        return;
+      }
+      const data = {
+        title: this.title,
+        intro: this.subTitle,
+        body: this.content,
+        categoryId: this.categoryId,
+        label: this.tags.join(",").slice(0, -1),
+        cover_url: this.cover_url
+      };
+      if (this.topicId) {
+        data.topicId = this.topicId;
+        this.$axios
+          .$post(`/api/community/topic/update_topic`, data)
+          .then(res => {
+            console.log(res);
+            this.$message.success("编辑成功!");
+            // TODO go details
+            window.location.href = `/p/${this.topicId}.html`;
+          });
+      } else {
+        this.$axios
+          .$post(`/api/community/topic/create_topic`, data)
+          .then(res => {
+            console.log(res);
+            this.$message.success("发布成功!");
+            // TODO go details
+            window.location.href = `/p/${res.data.topicId}.html`;
+          });
+      }
+    },
+    cancel() {
+      this.$router.back();
+    },
+    // 点击图片ICON触发事件
+    imgHandler(state) {
+      this.addRange = this.myQuillEditor.getSelection();
+      if (state) {
+        let fileInput = document.getElementById("imgInput");
+        fileInput.click(); // 加一个触发事件
+      }
+      this.uploadType = "image";
+    },
+
+    // 点击视频ICON触发事件
+    videoHandler(state) {
+      this.addRange = this.myQuillEditor.getSelection();
+      if (state) {
+        let fileInput = document.getElementById("imgInput");
+        fileInput.click(); // 加一个触发事件
+      }
+      // this.uploadType = "video";
+    },
+    handleContentFileChange(e) {
+      const file = e.target.files[0];
+      if (file.size / 1024 > 500) {
+        this.$message.error("图片大小不得超过500k,请重新选择");
+        return false;
+      }
+      const formData = new FormData();
+      formData.append('file', file);
+      formData.append('original_filename', file.name)
+      this.$axios
+        .$post(`/upload_image`, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
+        .then(res => {
+          this.content += `<img src="${res.filename}" alt="${file.name}"/>`;
+        });
+    },
+    handleFileChange(file) {
+      console.log(file);
+      if (file.size / 1024 > 500) {
+        this.$message.error("图片大小不得超过500k,请重新选择");
+        return false;
+      }
+      const formData = new FormData();
+      formData.append('target', '{ "type": 3 }');
+      formData.append('id', 'WU_FILE_0');
+      formData.append('name', file.name);
+      formData.append('type', file.type);
+      formData.append('lastModifiedDate', file.lastModifiedDate);
+      formData.append('size', file.size);
+      formData.append('file', file);
+      this.$axios
+        .$post(`/file/proxyUpload`, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
+        .then(res => {
+          this.cover_url = res.data && res.data.url || '';
+          this.fileList = [{
+            name: 'file.name',
+            url: this.cover_url
+          }];
+        });
+    },
+    handleFileUpload(...arge) {
+      console.log(arge);
+    },
+    onEditorChange(event) {
+      console.log("onEditorChange", event);
+    },
+    handleRemove(file) {
+      console.log(file);
+    },
+    handlePictureCardPreview(file) {
+      this.cover_url = file.url;
+      this.dialogVisible = true;
+    },
+    handleDownload(file) {
+      console.log(file);
+    }
+  }
+};
+</script>
+
+<style lang="scss">
+.editor {
+  position: relative;
+  padding: 20px;
+  width: 740px;
+  background: #fff;
+  .title,
+  .sub-title {
+    .el-input__inner {
+      padding: 0;
+      border: 0;
+      border-radius: 0;
+    }
+  }
+  .title {
+    margin: 10px auto 20px;
+    font-size: 28px;
+    font-family: PingFangSC-Medium;
+    font-weight: 500;
+    color: rgba(29, 42, 58, 1);
+    line-height: 40px;
+  }
+  .sub-title {
+    margin-bottom: 28px;
+    height: 18px;
+    font-size: 13px;
+    font-family: PingFangSC-Regular;
+    font-weight: 400;
+    color: rgba(145, 154, 167, 1);
+    line-height: 18px;
+    border-left: 2px solid #0093fd;
+    .el-input__inner {
+      height: 18px;
+      line-height: 18px;
+    }
+  }
+  .label {
+    margin: 20px auto 10px;
+    font-size: 13px;
+    font-family: PingFangSC-Medium;
+    font-weight: 500;
+    color: rgba(25, 34, 46, 1);
+    line-height: 18px;
+  }
+  .quill-editor {
+    min-height: 450px;
+  }
+  .ql-snow.ql-toolbar::after {
+    display: inline-block;
+  }
+  .class {
+    width: 320px;
+  }
+  .tags {
+    width: 560px;
+  }
+  footer {
+    margin: 40px 0;
+    button {
+      width: 100px;
+      height: 40px;
+      border-radius: 0;
+    }
+  }
+}
+</style>

+ 4 - 2
nuxt.config.js

@@ -67,7 +67,7 @@ module.exports = {
   */
   axios: {
     // See https://github.com/nuxt-community/axios-module#options
-    // proxy: true,
+    proxy: true,
     // https: true,
     progress: true,
     // baseURL: process.env.BASE_URL || '',
@@ -75,13 +75,15 @@ module.exports = {
     timeout: 15000,
     credentials: true,
     proxyHeaders: true,
-    debug: true
+    // debug: true
   },
   /**
    * Proxy
    */
   proxy: [
     ['/api', { target: 'https://dev.test.proginn.com', changeOrigin: true }],
+    ['/file/proxyUpload', { target: 'https://dev.test.proginn.com', changeOrigin: true }],
+    ['/upload_image', { target: 'https://dev.test-jishuin.proginn.com', changeOrigin: true }],
     ['/image', { target: 'https://stacdn.proginn.com', changeOrigin: true }],
   ],
 

+ 47 - 0
pages/topics/_id/edit.vue

@@ -0,0 +1,47 @@
+<template>
+  <div>
+    <edit :locations="locations"></edit>
+  </div>
+</template>
+
+<script>
+import { mapState } from 'vuex'
+import edit from '@/components/topics/edit'
+import qs from 'qs';
+
+export default {
+  // async asyncData({ $axios, params }) {
+  //   let res = await $axios.$get(`/api/vip/getList`)
+  //   console.log('init', res)
+  // },
+  head: {
+    title: '编辑文章-技术圈',
+  },
+  components: {
+    edit
+  },
+  data() {
+    return {
+      locations: [
+        {
+          url: 'https://jishuin.proginn.com/',
+          title: '技术圈'
+        },
+        {
+          url: '/topics/create',
+          title: '发布'
+        }
+      ]
+    }
+  },
+  computed: {
+  },
+  mounted() {
+  },
+  methods: {
+  }
+}
+</script>
+
+<style>
+</style>

+ 4 - 32
pages/topics/create.vue

@@ -1,18 +1,12 @@
 <template>
   <div>
-    <breadcrumb :locations="locations"></breadcrumb>
-    <editor-aside></editor-aside>
-    <editor></editor>
+    <edit :locations="locations"></edit>
   </div>
 </template>
 
 <script>
 import { mapState } from 'vuex'
-// import http from '@/plugins/http'
-import breadcrumb from '@/components/breadcrumb'
-import editorAside from '@/components/editor-aside'
-import editor from '@/components/editor'
-import getDeviceType from '@/mixins/getDeviceType'
+import edit from '@/components/topics/edit'
 import qs from 'qs';
 
 export default {
@@ -24,11 +18,8 @@ export default {
     title: '发布文章-技术圈',
   },
   components: {
-    breadcrumb,
-    editor,
-    editorAside,
+    edit
   },
-  mixins: [getDeviceType],
   data() {
     return {
       locations: [
@@ -40,33 +31,14 @@ export default {
           url: '/topics/create',
           title: '发布'
         }
-      ],
-      vipList: [],
+      ]
     }
   },
   computed: {
-    ...mapState(['isPC']),
-    com() {
-      return this.vipList[0];
-    },
-    dev() {
-      return this.vipList[1];
-    }
   },
   mounted() {
-    this.getList()
   },
   methods: {
-    async getList() {
-      let extraHeaders = {};
-      if (this.deviceType === 'ios') {
-        extraHeaders = this.getSign();
-      }
-      let res = await this.$axios.$post(`/api/vip/getList`, extraHeaders)
-      if (res) {
-        this.vipList = res.data
-      }
-    }
   }
 }
 </script>

+ 2 - 1
plugins/common.js

@@ -5,7 +5,8 @@ Vue.mixin({
   async fetch({ $axios, store, req }) {
     let headers = req && req.headers
     let res = await $axios.$get('/api/user/getInfo', {headers});
-    if(res) {
+    console.log(res.data)
+    if(res && res.data) {
       store.commit('updateUserinfo', { userinfo: res.data || {} })
     }
   },

+ 10 - 7
plugins/nuxtAxios.js

@@ -3,7 +3,10 @@ import qs from 'qs';
 
 export default function ({ $axios, redirect, req, ...args }) {
     $axios.onRequest(config => {
-        config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
+        const isUpload = config.headers['Content-Type'] === 'multipart/form-data';
+        if (!isUpload) {
+            config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
+        }
         console.log('Before, making request to ', config.url, config.baseURL)
         const referer = config.headers.common && config.headers.common.referer;
         const url = config.url;
@@ -14,10 +17,10 @@ export default function ({ $axios, redirect, req, ...args }) {
         } else {
             // client http
             config.url = /https?/.test(url) ? `/${url.split('/').slice(3).join('/')}` : url;
-            config.baseURL = '';
+            // config.baseURL = '';
         }
         // stringify post data
-        if (config.method === 'post') {
+        if (config.method === 'post' && !isUpload) {
             // config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
             const data = config.data;
             // const cookie = config.headers.cookie || config.headers.common.cookie || '';
@@ -35,7 +38,7 @@ export default function ({ $axios, redirect, req, ...args }) {
         console.log('After, making request to ', config.url, config.baseURL)
         return config;
     })
-  
+
     $axios.onResponse(res => {
         const data = res.data;
         // 不跳转到login的页面reg list
@@ -52,14 +55,14 @@ export default function ({ $axios, redirect, req, ...args }) {
             return result;
         }
         // req && req.url && needLogin(req.url)
-        if(data.status === 1) {
+        if(data.status === 1 || data.filename) {
             return res;
         } else if(data.status === -99) {
             console.log(req && req.url)
             // if (req && req.url && needLogin(req.url)) {
             //     redirect('/?loginbox=show');
             // }
-            return Promise.reject(res);
+            return Promise.reject({code: '401', message: '请登录!'});
         } else {
             Vue.prototype.$message.error(data.info);
             return Promise.reject(data);
@@ -72,4 +75,4 @@ export default function ({ $axios, redirect, req, ...args }) {
     //     redirect('/400')
     //   }
     })
-}
+}