fix: 修复 drawio 网络慢的时候不能调整高度问题

This commit is contained in:
purocean
2021-08-05 14:52:11 +08:00
parent 00e2736457
commit 428ee411f4
3 changed files with 5649 additions and 2283 deletions
+1
View File
@@ -63,6 +63,7 @@ export const IFrame = defineComponent({
}
expose({
getIframe: () => iframe.value,
reload: () => {
iframe.value?.contentWindow?.location.reload()
},
+16 -11
View File
@@ -15,21 +15,28 @@ const Drawio = defineComponent({
setup (props) {
const bus = useBus()
const srcdoc = ref('')
const iframe = ref<HTMLIFrameElement>()
const refIFrame = ref<any>()
watch(props, async () => {
srcdoc.value = await buildSrcdoc({ url: props.url, content: props.content || '' })
}, { immediate: true })
const resize = () => {
iframe.value!.contentDocument!.body.style.height = 'auto'
iframe.value!.contentDocument!.documentElement.style.height = 'auto'
iframe.value!.height = iframe.value!.contentDocument!.documentElement.offsetHeight + 'px'
iframe.value!.contentDocument!.body.style.height = iframe.value!.contentDocument!.body.clientHeight + 'px'
iframe.value!.contentDocument!.documentElement.style.height = '100%'
bus.emit('global.resize')
const iframe = refIFrame.value.getIframe()
if (iframe) {
iframe.contentDocument.body.style.height = 'auto'
iframe.contentDocument.documentElement.style.height = 'auto'
iframe.height = iframe.contentDocument.documentElement.offsetHeight + 'px'
iframe.contentDocument.body.style.height = iframe.contentDocument.body.clientHeight + 'px'
iframe.contentDocument.documentElement.style.height = '100%'
bus.emit('global.resize')
}
}
}
setTimeout(resize, 1000)
const button = (text: string, onClick: any) => h('button', {
style: 'margin-left: 5px;font-size: 14px;background: #cacaca; border: 0; padding: 0 6px; color: #2c2b2b; cursor: pointer; border-radius: 2px; transition: all .1s ease-in-out; line-height: 24px;',
onClick
@@ -49,10 +56,8 @@ const Drawio = defineComponent({
),
h(IFrame, {
html: srcdoc.value,
onLoad (frame) {
iframe.value = frame
resize()
},
ref: refIFrame,
onLoad: resize,
iframeProps: {
class: 'drawio',
height: '300px',
+5632 -2272
View File
File diff suppressed because one or more lines are too long