Skip to content

Commit

Permalink
Merge pull request #331 from kaola-fed/bugfix_klimagepreview_20180321
Browse files Browse the repository at this point in the history
修复组件KLImagePreview图片点击下载直接在当前页面打开图片的问题
  • Loading branch information
nupthale authored Mar 29, 2018
2 parents 532d750 + 7132c5b commit 19853b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const doc = (isDev, callback) => {
// 组件文档
CATES.forEach((c) => {
const components = getComponents(c.cate).filter((comp) => {
if (isDev && !/^KL(Sidebar|Menu|Button|Table|Select|MultiSelect)$/.test(comp)) {
if (isDev && !/^KL(Sidebar|Upload|Menu|Button|Table|Select|MultiSelect)$/.test(comp)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/components/widget/KLImagePreview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{#list opList as op}
<li class="m-btn-item" r-style={{"margin-right": op.name === 'zoomIn' ? '30px' : 0}}>
{#if (imageList[curIndex].status === 'success' || imageList[curIndex].status === undefined) && op.name === 'remove'}
<a class="u-download" href={imageList[curIndex].src} download={imageList[curIndex].name}><i class="u-icon u-icon-export"></i></a>
<a class="u-download" href="javascript:void(0);" on-click={this.downloadFile(imageList[curIndex])}><i class="u-icon u-icon-export"></i></a>
{#elseif op.name === 'zoomIn'}
<i class="u-icon u-icon-{op.icon}" on-click={this[op.fnName].bind(this)(curIndex)}></i>
<span class="u-scale">{parseInt(virtualInfo.scale * 100)}%</span>
Expand Down
10 changes: 10 additions & 0 deletions src/js/components/widget/KLImagePreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ const KLImagePreview = Component.extend({
minTranslateY: minDeltaY < 0 ? minDeltaY : 0,
};
},
downloadFile(file) {
const a = document.createElement('a');
a.download = file.name;
fetch(file.src).then(res => res.blob().then((blob) => {
const blobUrl = window.URL.createObjectURL(blob);
a.href = blobUrl;
a.click();
window.URL.revokeObjectURL(blobUrl);
}));
},
});

module.exports = KLImagePreview;

0 comments on commit 19853b9

Please sign in to comment.