|
|
<template>
|
|
|
<div>
|
|
|
<Modal
|
|
|
width="800"
|
|
|
v-model="showModal"
|
|
|
title="图片"
|
|
|
@on-ok="insertImage"
|
|
|
ok-text="保存"
|
|
|
class="multi-image">
|
|
|
<Row :gutter="16">
|
|
|
<Col span="10">
|
|
|
<Input v-model="file" placeholder="请输入地址" @on-enter="addFile"/>
|
|
|
|
|
|
</Col>
|
|
|
<Col span="8">
|
|
|
<Button type="primary" @click="addFile">确定</Button>
|
|
|
</Col>
|
|
|
</Row>
|
|
|
<br />
|
|
|
<Upload
|
|
|
ref="upload"
|
|
|
multiple
|
|
|
type="drag"
|
|
|
:data="{bucket: 'goodsimg'}"
|
|
|
:max-size="2048"
|
|
|
:format="['jpg','jpeg','png']"
|
|
|
:show-upload-list="false"
|
|
|
:on-format-error="handleFormatError"
|
|
|
:on-exceeded-size="handleMaxSize"
|
|
|
:on-success="handleSuccess"
|
|
|
:on-error="handleError"
|
|
|
action="/Api/upload/image">
|
|
|
<div style="padding: 20px 0">
|
|
|
<Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
|
|
|
<p>点击或将文件拖拽到这里上传</p>
|
|
|
</div>
|
|
|
</Upload>
|
|
|
<div class="upload-list" v-for="item in fileList">
|
|
|
<template v-if="item.status === 'finished'">
|
|
|
<img :src="item.url">
|
|
|
<div class="upload-list-cover">
|
|
|
<Icon type="ios-eye-outline" @click.native="handleView(item)"></Icon>
|
|
|
<Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-else>
|
|
|
<Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
|
|
|
</template>
|
|
|
</div>
|
|
|
</Modal>
|
|
|
<Modal title="查看图片" v-model="visible">
|
|
|
<img :src="imgUrl" v-if="visible" style="width: 100%">
|
|
|
</Modal>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import _ from 'lodash';
|
|
|
export default {
|
|
|
name: 'MultiImage',
|
|
|
created() {
|
|
|
this.$watch('$parent.dashboard', () => {
|
|
|
this.$parent.dashboard === 'dashboard-multi-image' && (this.showModal = true);
|
|
|
});
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
showModal: true,
|
|
|
fileList: [],
|
|
|
imgUrl: '',
|
|
|
file: '',
|
|
|
visible: false
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
handleView(item) {
|
|
|
this.imgUrl = item.url;
|
|
|
this.visible = true;
|
|
|
},
|
|
|
handleRemove(file) {
|
|
|
// 从 upload 实例删除数据
|
|
|
let fileList = this.$refs.upload.fileList;
|
|
|
|
|
|
this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
|
|
|
},
|
|
|
handleFormatError(file) {
|
|
|
this.$Notice.warning({
|
|
|
title: '文件格式不正确',
|
|
|
desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
|
|
|
});
|
|
|
},
|
|
|
handleMaxSize(file) {
|
|
|
this.$Notice.warning({
|
|
|
title: '超出文件大小限制',
|
|
|
desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
|
|
|
});
|
|
|
},
|
|
|
handleSuccess(response, file) {
|
|
|
let url = _.get(response, 'data.imagesList[0]');
|
|
|
|
|
|
if (url) {
|
|
|
file.url = url;
|
|
|
}
|
|
|
},
|
|
|
handleError(error) {
|
|
|
this.$Notice.error(error);
|
|
|
},
|
|
|
insertImage() {
|
|
|
_.each(this.fileList, file => {
|
|
|
this.$parent.execCommand('insertImage', file.url);
|
|
|
});
|
|
|
},
|
|
|
addFile() {
|
|
|
if (this.file) {
|
|
|
this.fileList.push({
|
|
|
name: '',
|
|
|
status: 'finished',
|
|
|
url: this.file,
|
|
|
uid: ''
|
|
|
});
|
|
|
this.file = '';
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
showModal(val) {
|
|
|
if (!val) {
|
|
|
this.fileList = this.$refs.upload.fileList = [];
|
|
|
this.$parent.dashboard = null;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
this.fileList = this.$refs.upload.fileList;
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss">
|
|
|
.multi-image {
|
|
|
.upload-list {
|
|
|
margin-top: 20px;
|
|
|
display: inline-block;
|
|
|
width: 60px;
|
|
|
height: 60px;
|
|
|
text-align: center;
|
|
|
line-height: 60px;
|
|
|
border: 1px solid transparent;
|
|
|
border-radius: 4px;
|
|
|
overflow: hidden;
|
|
|
background: #fff;
|
|
|
position: relative;
|
|
|
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
|
|
margin-right: 4px;
|
|
|
}
|
|
|
|
|
|
.upload-list img {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
}
|
|
|
|
|
|
.upload-list-cover {
|
|
|
display: none;
|
|
|
position: absolute;
|
|
|
top: 0;
|
|
|
bottom: 0;
|
|
|
left: 0;
|
|
|
right: 0;
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
|
}
|
|
|
|
|
|
.upload-list:hover .upload-list-cover {
|
|
|
display: block;
|
|
|
}
|
|
|
|
|
|
.upload-list-cover i {
|
|
|
color: #fff;
|
|
|
font-size: 20px;
|
|
|
cursor: pointer;
|
|
|
margin: 0 2px;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
</style> |
...
|
...
|
|