-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(image-viewer): 移除额外的根元素 * fix(imageviewer): 单元测试ts检测异常
- Loading branch information
1 parent
0f0910e
commit 598b417
Showing
6 changed files
with
200 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Vue from 'vue'; | ||
|
||
import props from '../props'; | ||
import { TdImageViewerProps } from '../type'; | ||
import { getAttach, removeDom } from '../../utils/dom'; | ||
|
||
// eslint-disable-next-line no-spaced-func | ||
export default Vue.extend< | ||
{ content: Vue }, | ||
// eslint-disable-next-line func-call-spacing | ||
{ mountContent: () => void; unmountContent: () => void }, | ||
Record<string, any>, | ||
Readonly<{ mode: TdImageViewerProps['mode']; renderModal: Function; renderViewer: Function }> | ||
>({ | ||
props: { | ||
mode: props.mode, | ||
renderModal: Function, | ||
renderViewer: Function, | ||
}, | ||
data() { | ||
return { | ||
content: null as Vue, | ||
}; | ||
}, | ||
methods: { | ||
mountContent() { | ||
if (this.content) return; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const _this = this; | ||
|
||
const elm = document.createElement('div'); | ||
elm.style.cssText = 'position: absolute; top: 0px; left: 0px; width: 100%'; | ||
this.content = new (this.$root.constructor as any)({ | ||
render() { | ||
return _this.mode === 'modeless' ? _this.renderModal() : _this.renderViewer(); | ||
}, | ||
destroyed() { | ||
if (_this.content.$el) { | ||
removeDom(_this.content.$el as HTMLElement); | ||
} | ||
_this.content = null; | ||
}, | ||
}); | ||
|
||
getAttach(document.body).appendChild(elm); | ||
this.content.$mount(elm); | ||
}, | ||
unmountContent() { | ||
this.content?.$destroy?.(); | ||
}, | ||
}, | ||
render() { | ||
const children = this.$slots.default || []; | ||
if (children.length > 1 || !children[0]?.tag) { | ||
return <span>{children}</span>; | ||
} | ||
return children[0]; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.