Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"rollup-plugin-vue": "^5.1.9",
"tdesign-publish-cli": "^0.0.12",
"@tdesign/site-components": "^0.17.0",
"tdesign-theme-generator": "^1.0.0",
"@tdesign/theme-generator": "^1.2.0",
"typescript": "~4.8.4",
"unplugin-vue2-script-setup": "^0.10.2",
"vite": "^4.5.10",
Expand Down
8 changes: 4 additions & 4 deletions site/site.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ const docs = [
titleEn: 'Theme Customization',
name: 'custom-theme',
path: '/vue/custom-theme',
component: () => import('@common/theme.md'),
componentEn: () => import('@common/theme.en-US.md'),
component: () => import('@common/docs/web/theme.md'),
componentEn: () => import('@common/docs/web/theme.en-US.md'),
},
{
title: '深色模式',
titleEn: 'Dark Mode',
name: 'dark-mode',
path: '/vue/dark-mode',
component: () => import('@common/dark-mode.md'),
componentEn: () => import('@common/dark-mode.en-US.md'),
component: () => import('@common/docs/dark-mode.md'),
componentEn: () => import('@common/docs/dark-mode.en-US.md'),
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion site/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import '@tdesign/site-components/lib/styles/prism-theme.less';
import '@tdesign/site-components/lib/styles/prism-theme-dark.less';

// 主题生成器挂件
import 'tdesign-theme-generator';
import '@tdesign/theme-generator';

import { registerLocaleChange } from '@tdesign/site-components';

Expand Down
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 858 files
6 changes: 3 additions & 3 deletions src/image-viewer/image-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { renderTNodeJSX } from '../utils/render-tnode';
import { setTransform } from '../utils/helper';
import { TdImageViewerProps } from './type';
import { useMirror, useRotate, useScale } from './hooks';

import { downloadFile, formatImages, getOverlay } from './utils';
import { downloadImage, formatImages } from '../_common/js/image-viewer/utils';
import { getOverlay } from './utils';
import { EVENT_CODE, DEFAULT_IMAGE_SCALE } from './const';
import Image from '../image';

Expand Down Expand Up @@ -102,7 +102,7 @@ export default defineComponent({
emit('download', url);
return;
}
downloadFile(url);
downloadImage(url);
};

const openHandler = (index: number) => {
Expand Down
49 changes: 2 additions & 47 deletions src/image-viewer/utils.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
import { TdImageViewerProps, ImageInfo } from './type';

export const downloadFile = function (imgSrc: string) {
const image = new Image();
const name = imgSrc?.split?.('/').pop() || Math.random().toString(32).slice(2);

image.setAttribute('crossOrigin', 'anonymous');

image.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;

const context = canvas.getContext('2d');
context.drawImage(image, 0, 0, image.width, image.height);
canvas.toBlob((blob) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.download = name;
a.href = url;
a.click();
a.remove();
URL.revokeObjectURL(url);
});
};
image.src = imgSrc;
};

const isImageInfo = (image: string | File | ImageInfo): image is ImageInfo => !!image && typeof image !== 'string' && !(image instanceof File);

export const formatImages = (images: TdImageViewerProps['images']): ImageInfo[] => {
if (!Array.isArray(images)) return [];
return images.map((item) => {
if (isImageInfo(item)) {
return {
download: true,
thumbnail: item.mainImage,
...item,
};
}
return {
mainImage: item,
thumbnail: item,
download: true,
};
});
};
import { TdImageViewerProps } from './type';

// eslint-disable-next-line import/prefer-default-export
export const getOverlay = (props: TdImageViewerProps) => {
if (props.showOverlay !== undefined) {
return props.showOverlay;
Expand Down
Loading