inleft
2022-08-12 0dd41bd8cee430d3a948b89c664cb511c400993c
src/components/mini/box10-add.vue
@@ -21,18 +21,10 @@
            </span>
         </a-form-model-item>
         <a-form-model-item label="日志文件" v-show="!form.online">
            <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
               :default-file-list="form.blogFileList">
               <a-button>
                  <a-icon type="upload" /> 限 markdown/html
               </a-button>
            </a-upload> -->
            <a-upload :customRequest="customRequest" name="file" :showUploadList="true" @change="handleChange"
               :default-file-list="form.blogFileList" :beforeUpload="beforeUpload">
            <a-upload ref="blogFileUpload" :customRequest="customRequest" name="file" :showUploadList="true"
               @change="handleChange" :default-file-list="form.blogFileList" :beforeUpload="beforeUpload"
               :data="{'fileType':fileTypeMarkDown}" accept=".md,.html,.htm,.txt">
               <a-button>
                  <a-icon type="upload" />限 markdown/html
               </a-button>
@@ -69,13 +61,16 @@
            <a-form-model-item label=" 日志类型">
               <a-select v-model="form.blogType" mode="default" placeholder=""
                  :getPopupContainer="getCalendarContainer()">
                  <a-select-option   value="1">
                  <a-select-option value="1">
                     markdown
                  </a-select-option>
                  <a-select-option   value="2">
                  <a-select-option value="2">
                     html
                  </a-select-option>
                  <a-select-option   value="5">
                  <a-select-option value="3">
                     video
                  </a-select-option>
                  <a-select-option value="5">
                     fast(闪念)
                  </a-select-option>
               </a-select>
@@ -106,16 +101,11 @@
            <a-form-model-item label="封面">
               <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" list-type="picture"
                  :default-file-list="form.coverFileList" class="upload-list-inline">
                  <a-button>
                     <a-icon type="upload" /> jpg/png/jpeg..
                  </a-button>
               </a-upload> -->
               <a-upload :customRequest="customRequest" name="file" :showUploadList="true" list-type="picture"
                  @change="handleChangeCoverFile"
                  :default-file-list="form.coverFileList">
                  :data="{'fileType':fileTypeCover}" @change="handleChangeCoverFile"
                  :default-file-list="form.coverFileList" :beforeUpload="beforeUploadCover"
                  accept=".jpg,.png,.jpeg">
                  <!-- :disabled="form.coverFileList.length>=1" -->
                  <a-button>
                     <a-icon type="upload" />jpg/png/jpeg..
                  </a-button>
@@ -188,13 +178,16 @@
<script>
   import moment from "moment";
   import {
      sysFileInfoUpload
      sysFileInfoUpload,
      myFileInfoUpload
   } from '../../api/fileManage.js';
   import {
      queryBlogArticleType
   } from '../../api/blogArticleType.js'
   import myConstant from "../../config/myConstant.js"
   import md5 from 'js-md5';
   export default {
      beforeMount() {
@@ -203,18 +196,16 @@
         })
      },
      data() {
         let _this = this;
         let validateContent = (rule, value, callback) => {
            if (this.form.online) {
               console.log("内容未填");
               this.$refs.myForm.validateField('content')
               if (this.form.content == null || this.form.content == "") {
            if (_this.form.online) {
               //this.$refs.myForm.validateField('content')
               if (_this.form.content == null || _this.form.content == "") {
                  callback(new Error('内容未填'));
               }
            } else {
               console.log("文件未传");
               this.$refs.myForm.validateField('blogFileList')
               if (this.form.fileId == null) {
               //this.$refs.myForm.validateField('blogFileList')
               if (_this.form.fileId == null) {
                  callback(new Error('文件未传'));
               }
            }
@@ -222,6 +213,8 @@
         };
         return {
            fileTypeMarkDown: myConstant.fileTypeMarkDown,
            fileTypeCover: myConstant.fileTypeCover,
            blogArticleType: [],
            tags: [],
            inputVisible: false,
@@ -244,7 +237,7 @@
               publishDate: "",
               lock: false,
               top: false,
               sliderValue:50,
               sliderValue: 50,
               auth: 1,
               password: "",
               fileId: null,
@@ -267,7 +260,7 @@
               ],
               secret: [{
                  required: true,
                  message: '不正经的人..',
                  message: '好像这里错了..',
                  trigger: 'blur'
               }],
               common: [{
@@ -295,21 +288,41 @@
         };
      },
      methods: {
         beforeUpload(file, fileList) {
         reset() {
            // this.form.blogFileList = [];
            // this.form.coverFileList = [];
         },
         beforeUploadCover(file, fileList) {
            return new Promise((resolve, reject) => {
               if (this.form.fileId != null) {
               if (this.form.secret == null || this.form.secret == "") {
                  this.$message.error('需要正确的授权码');
                  return reject(false);
               }
               if (this.form.coverFileList.length >= 1) {
                  this.$message.error('这里最多上传一个文件');
                  return reject(false);
               }
               // var testmsg=/^image\/(jpeg|png|jpg)$/.test(file.type)
               // // var testmsg=/^image\/(md|html|markdown)$/.test(file.type)
               // if (!testmsg) {
               //   this.$message.error('上传文件格式不对!');
               //   return reject(false);
               // }
               if (file.size > myConstant.uploadFileSizeLimit) {
                  this.$message.error('上传文件大小不能超过 2M!');
                  return reject(false);
               }
               return resolve(true)
            });
         },
         beforeUpload(file, fileList) {
            return new Promise((resolve, reject) => {
               if (this.form.secret == null || this.form.secret == "") {
                  this.$message.error('需要正确的口令..');
                  return reject(false);
               }
               const isLt2M = file.size / 1024 / 1024 <= 2 //图片大小不超过2MB
               if (!isLt2M) {
               if (this.form.blogFileList.length >= 1) {
                  this.$message.error('这里最多上传一个文件');
                  return reject(false);
               }
               if (file.size > myConstant.uploadFileSizeLimit) {
                  this.$message.error('上传文件大小不能超过 2M!');
                  return reject(false);
               }
@@ -318,6 +331,8 @@
         },
         handleChange(info) {
            this.form.blogFileList = info.fileList;
            if (info.file.status !== 'uploading') {
               console.log(info.file, info.fileList);
            }
@@ -327,8 +342,14 @@
            } else if (info.file.status === 'error') {
               this.$message.error(`${info.file.name} file upload failed.`);
            }
            if (this.form.blogFileList == null || this.form.blogFileList.length == 0) {
               this.form.fileId = null
            }
         },
         handleChangeCoverFile(info) {
            this.form.coverFileList = info.fileList;
            if (info.file.status !== 'uploading') {
               console.log(info.file, info.fileList);
            }
@@ -338,6 +359,10 @@
            } else if (info.file.status === 'error') {
               this.$message.error(`${info.file.name} file upload failed.`);
            }
            if (this.form.coverFileList == null || this.form.coverFileList.length == 0) {
               this.form.coverFile = null
            }
         },
         /**
          * 上传文件
@@ -345,7 +370,9 @@
         customRequest(option) {
            const formData = new FormData()
            formData.append('file', option.file)
            sysFileInfoUpload(formData).then((res) => {
            formData.append('fileType', option.data.fileType)
            formData.append('authCode', this.form.secret == "" ? "" : md5(this.form.secret))
            myFileInfoUpload(formData).then((res) => {
               if (res.success) {
                  this.$message.success('上传成功')
@@ -362,9 +389,9 @@
            return trigger => trigger.parentNode;
         },
         handleClose(removedTag) {
            const tags = this.tags.filter(tag => tag !== removedTag);
            // const tags = this.tags.filter(tag => tag !== removedTag);
            //console.log(tags);
            this.tags = tags;
            this.tags = this.tags.filter(tag => tag !== removedTag);
         },
         showInput() {