guhongwei 4 년 전
부모
커밋
36ac90d7ce
2개의 변경된 파일139개의 추가작업 그리고 10개의 파일을 삭제
  1. 137 0
      src/components/uploadraw.vue
  2. 2 10
      src/views/userCenter/productInfo/part/infoRelease.vue

+ 137 - 0
src/components/uploadraw.vue

@@ -0,0 +1,137 @@
+<template>
+  <div id="upload">
+    <el-upload
+      v-if="url"
+      ref="upload"
+      :action="url"
+      :list-type="listType"
+      :file-list="fileList"
+      :limit="limit"
+      :on-exceed="outLimit"
+      :on-preview="handlePictureCardPreview"
+      :before-remove="handleRemove"
+      :on-success="onSuccess"
+      :before-upload="beforeUpload"
+      :show-file-list="showList"
+      accept=".3gpp,.ac3,.au,.mp2,.mp3,.mp4,.mpeg,.mpg,.wmv,.avi,.flv"
+    >
+      <el-button size="small" type="primary" v-if="isBtn">点击上传</el-button>
+      <template v-else-if="uploadBtn">
+        <el-button type="danger">选择文件</el-button>
+      </template>
+      <template v-else>
+        <el-button type="primary" size="mini">选择文件</el-button>
+      </template>
+      <template #tip v-if="tip">
+        {{ tip }}
+      </template>
+    </el-upload>
+    <el-dialog :visible.sync="dialogVisible">
+      <img width="100%" :src="dialogImageUrl" alt="" />
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import _ from 'lodash';
+export default {
+  name: 'upload',
+  props: {
+    url: { type: null },
+    limit: { type: Number },
+    data: { type: null },
+    type: { type: String },
+    isBtn: { type: Boolean, default: false },
+    uploadBtn: { type: Boolean, default: false },
+    showList: { type: Boolean, default: true },
+    tip: { type: String, default: undefined },
+    listType: { type: String, default: 'picture-card' },
+  },
+  components: {},
+  data: () => ({
+    dialogVisible: false,
+    dialogImageUrl: '',
+    fileList: [],
+  }),
+  created() {
+    if (this.data) {
+      this.defalutProcess(this.data);
+    }
+  },
+  watch: {
+    data: {
+      handler(val) {
+        this.defalutProcess(val);
+      },
+    },
+  },
+  computed: {},
+  methods: {
+    handlePictureCardPreview(file) {
+      this.dialogImageUrl = file.url;
+      this.dialogVisible = false;
+    },
+    handleRemove(file, fileList) {
+      this.$set(this, `fileList`, []);
+      // let index = fileList.findIndex(f => _.isEqual(f, file));
+      // this.$emit('delete', index);
+      // return false;
+    },
+    outLimit() {
+      this.$message.error(`只允许上传${this.limit}个文件`);
+    },
+    onSuccess(response, file, fileList) {
+      //将文件整理好传回父组件
+      this.$emit('upload', { type: this.type, data: { ...response, name: file.name } });
+    },
+    beforeUpload(file) {
+      if (
+        file.type == 'video/mp4' ||
+        file.type == 'video/3gpp' ||
+        file.type == 'video/ac3' ||
+        file.type == 'video/au' ||
+        file.type == 'video/mp2' ||
+        file.type == 'video/mp3' ||
+        file.type == 'video/mpeg' ||
+        file.type == 'video/mpg' ||
+        file.type == 'video/wmv' ||
+        file.type == 'video/avi' ||
+        file.type == 'video/flv'
+      ) {
+        return true;
+      } else {
+        this.$message.error('只允许上传视频格式文件');
+        this.$set(this, `fileList`, []);
+      }
+      const sizeLimit = file.size / 1024 / 1024 < 1;
+      if (sizeLimit) return true;
+      else {
+        this.$message.error('文件超出10M!');
+        return false;
+      }
+    },
+    defalutProcess(val) {
+      if (_.isArray(val)) {
+        let newArr = val.map(item => {
+          let object = {};
+          object.name = item.name;
+          object.url = item.url;
+          return object;
+        });
+        this.$set(this, `fileList`, newArr);
+      } else if (_.isObject(val)) {
+        let object = {};
+        if (_.get(val, `url`)) {
+          object.name = val.name;
+          object.url = val.url;
+          this.$set(this, `fileList`, [object]);
+        }
+      } else if (typeof val === 'string') {
+        this.$set(this, `fileList`, [{ name: '附件', url: val }]);
+      }
+    },
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 2 - 10
src/views/userCenter/productInfo/part/infoRelease.vue

@@ -363,7 +363,6 @@
                           :data="form.roadshow"
                           type="roadshow"
                           listType=""
-                          accept=".mp4"
                           :url="'/files/roadshow/upload'"
                           @upload="uploadroadshow"
                           @delete="uploaddelroadshow"
@@ -692,7 +691,7 @@ import techDetail from '@/views/market/detail/techDetail.vue';
 import achiDetail from '@/views/market/detail/achiDetail.vue';
 import busiDetail from '@/views/market/detail/busiDetail.vue';
 import _ from 'lodash';
-import upload from '@/components/upload.vue';
+import upload from '@/components/uploadraw.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
 const { mapActions: markettype } = createNamespacedHelpers('markettype');
 export default {
@@ -809,14 +808,7 @@ export default {
       this.$emit('back');
     },
     uploadroadshow({ type, filetype, data }) {
-      if (filetype == 'video/mp4') {
-        this.$set(this.form, `${type}`, data.uri);
-      } else {
-        this.$message({
-          message: '失败',
-          type: 'error',
-        });
-      }
+      this.$set(this.form, `${type}`, data.uri);
     },
     uploaddelroadshow(index) {},
     // 添加专利信息