| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <template>
- <!-- <el-image
- :src="`${realSrc}`"
- fit="cover"
- :style="`width:${realWidth};height:${realHeight};`"
- :preview-src-list="realSrcList"
- >
- <div slot="error" class="image-slot">
- <i class="el-icon-picture-outline"></i>
- </div>
- </el-image> -->
- <div class="uploaders">
- <div class="images">
- <div v-for="(v, i) in fileList" :key="i">
- <!-- -->
- <slot v-if="$slots.default"
- :v="v"
- :i="i"></slot>
- <!-- -->
- <div class="image relative"
- v-else>
- <el-image :src="v.url"
- class="avatar"
- :preview-src-list="previewSrcList"
- :z-index="6000" />
- <!-- <i v-show="!disabled"
- class="el-icon-error"
- @click="onRemove(i)"></i> -->
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "ImageListPreview",
- data() {
- return {
- fileList: [],
- previewSrcList:[]
- }
- },
- watch: {
- value: {
- immediate: true,
- handler(newVal) {
- if(newVal){
- const list = Array.isArray(newVal) ? newVal : this.value.split(",");
- this.fileList = list.map((url) => ({ name: url, url }));
- this.previewSrcList=list.map((url) => url);
- console.log("this.fileList",this.fileList,this.previewSrcList);
- }
- else{
- this.fileList =[];
- this.previewSrcList=[];
- }
- },
- },
- },
- props: {
- value: {
- type: [Array,String],
- default: [],
- },
- src: {
- type: String,
- default: ""
- },
- width: {
- type: [Number, String],
- default: ""
- },
- height: {
- type: [Number, String],
- default: ""
- }
- },
- computed: {
- realSrc() {
- if (!this.src) {
- return;
- }
- let real_src = this.src.split(",")[0];
- return real_src;
- },
- realSrcList() {
- if (!this.src) {
- return;
- }
- let real_src_list = this.src.split(",");
- let srcList = [];
- real_src_list.forEach(item => {
- return srcList.push(item);
- });
- return srcList;
- },
- realWidth() {
- return typeof this.width == "string" ? this.width : `${this.width}px`;
- },
- realHeight() {
- return typeof this.height == "string" ? this.height : `${this.height}px`;
- }
- },
- };
- </script>
- <style lang="scss" scoped>
- .el-image {
- border-radius: 5px;
- background-color: #ebeef5;
- box-shadow: 0 0 5px 1px #ccc;
- ::v-deep .el-image__inner {
- transition: all 0.3s;
- cursor: pointer;
- &:hover {
- transform: scale(1.2);
- }
- }
- ::v-deep .image-slot {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- color: #909399;
- font-size: 30px;
- }
- }
- $width: 100px;
- $height: 100px;
- .uploaders {
- .red {
- font-size: 12px;
- }
- //
- .image {
- float: left;
- margin-right: 4px;
- margin-bottom: 4px;
- width: $width;
- height: $height;
- border: 1px solid #d9d9d9;
- position: relative;
- .avatar {
- width: 100%;
- height: 100%;
- }
- &:hover {
- i.el-icon-error {
- display: block;
- }
- }
- i.el-icon-error {
- display: none;
- position: absolute;
- top: 4px;
- right: 4px;
- font-size: 20px;
- }
- }
- //
- .uploader {
- width: $width;
- height: $height;
- float: left;
- position: relative;
- margin-right: 4px;
- margin-bottom: 4px;
- .el-upload {
- width: 100%;
- height: 100%;
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- .el-upload:hover {
- border-color: #20a0ff;
- }
- .avatar {
- width: 100%;
- height: 100%;
- display: block;
- }
- .avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- }
- .el-upload__input {
- opacity: 0;
- position: absolute;
- }
- }
- }
- </style>
|