|
@@ -0,0 +1,61 @@
|
|
|
+<template>
|
|
|
+ <div id="e-upload">
|
|
|
+ <el-upload :action="url" :http-request="upload" :list-type="type" :fileList="fileList" :on-remove="onRemove">
|
|
|
+ <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+const _ = require('lodash');
|
|
|
+import axios from 'axios';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+export default {
|
|
|
+ name: 'e-upload',
|
|
|
+ props: {
|
|
|
+ url: { type: String, required: true },
|
|
|
+ type: { type: String, default: 'picture-card' },
|
|
|
+ fileList: { type: Array },
|
|
|
+ },
|
|
|
+ model: {
|
|
|
+ prop: 'fileList',
|
|
|
+ event: 'change',
|
|
|
+ },
|
|
|
+ components: {},
|
|
|
+ data: function() {
|
|
|
+ return {};
|
|
|
+ },
|
|
|
+ created() {},
|
|
|
+ methods: {
|
|
|
+ async upload({ file }) {
|
|
|
+ let formdata = new FormData();
|
|
|
+ formdata.append('file', file, file.name);
|
|
|
+ const res = await axios.post(this.url, formdata, { headers: { 'Content-Type': 'multipart/form-data' } });
|
|
|
+ if (res.status === 200 && res.data.errcode == 0) {
|
|
|
+ const { id, name, uri } = res.data;
|
|
|
+ const obj = { url: uri, name };
|
|
|
+ this.fileList.push(obj);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onRemove(file) {
|
|
|
+ const index = this.fileList.findIndex(f => f.url === file.url);
|
|
|
+ this.fileList.splice(index, 1);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user', 'menuParams']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+/deep/.el-upload-list__item.is-ready {
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+</style>
|