Skip to content

Commit

Permalink
Image: Perfect picture preview behavior (ElemeFE#16985) (ElemeFE#17375)
Browse files Browse the repository at this point in the history
* Perfect picture preview function

* update test
  • Loading branch information
luckyCao authored and oleksiikhr committed Jan 13, 2020
1 parent ff0097d commit 8151b0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/image/src/image-viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ export default {
onClose: {
type: Function,
default: () => {}
},
initialIndex: {
type: Number,
default: 0
}
},
data() {
return {
index: 0,
index: this.initialIndex,
isShow: false,
infinite: true,
loading: false,
Expand Down
7 changes: 6 additions & 1 deletion packages/image/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
:src="src"
:style="imageStyle"
:class="{ 'el-image__inner--center': alignCenter, 'el-image__preview': preview }">
<image-viewer :z-index="zIndex" v-if="preview && showViewer" :on-close="closeViewer" :url-list="previewSrcList"/>
<template v-if="preview">
<image-viewer :z-index="zIndex" :initial-index="imageIndex" v-show="showViewer" :on-close="closeViewer" :url-list="previewSrcList"/>
</template>
</div>
</template>

Expand Down Expand Up @@ -88,6 +90,9 @@
preview() {
const { previewSrcList } = this;
return Array.isArray(previewSrcList) && previewSrcList.length > 0;
},
imageIndex() {
return this.previewSrcList.indexOf(this.src);
}
},
Expand Down
6 changes: 4 additions & 2 deletions test/unit/specs/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ describe('Image', () => {
await wait();
vm.$el.querySelector('.el-image__inner').click();
await wait();
expect(vm.$el.querySelector('.el-image-viewer__wrapper')).to.exist;

const $wrapper = vm.$el.querySelector('.el-image-viewer__wrapper');
expect($wrapper).to.exist;
vm.$el.querySelector('.el-image-viewer__close').click();
await wait(1000);
expect(vm.$el.querySelector('.el-image-viewer__wrapper')).to.not.exist;
expect($wrapper.style.display).to.equal('none');
});
});

0 comments on commit 8151b0c

Please sign in to comment.