wip: use weboffice

This commit is contained in:
zzs 2025-03-19 19:16:55 +08:00
parent 36db6015dc
commit d8603e1a35
2 changed files with 124 additions and 4 deletions

View File

@ -9,10 +9,9 @@ const props = defineProps({
}, },
}) })
const loading = ref(true) const loading = ref(true)
const height = ref('') const height = ref<string | number>('')
const frameRef = ref<HTMLElement | null>(null) const frameRef = ref<null | HTMLIFrameElement>(null)
function init() { function init() {
console.warn(height.value)
if (!props.height) if (!props.height)
height.value = `${document.documentElement.clientHeight - 94.5}px` height.value = `${document.documentElement.clientHeight - 94.5}px`
else else
@ -25,6 +24,24 @@ onMounted(() => {
init() init()
}, 300) }, 300)
}) })
function sendMessageToIframe(message) {
if (frameRef.value && frameRef.value.contentWindow)
frameRef.value.contentWindow.postMessage(message, '*')
}
defineExpose({
sendMessageToIframe,
})
onMounted(() => {
//
window.addEventListener('message', (event) => {
//
if (event.data)
console.log(event.data)
})
})
</script> </script>
<template> <template>

View File

@ -17,10 +17,113 @@ onMounted(() => {
}) })
previewUrl.value = rouer.currentRoute.value.query?.url as string previewUrl.value = rouer.currentRoute.value.query?.url as string
const iframeRef = ref<InstanceType<typeof IFrame> | null>(null)
const isShow = ref(false)
function sendMessage() {
if (iframeRef.value) {
iframeRef.value.sendMessageToIframe(JSON.stringify({
// MessageId: 'CallPythonScript',
// SendTime: Date.now(),
// Values: {
// ScriptFile: 'InsertText.py',
// Function: 'InsertHello',
// Values: {
//
// },
// },
MessageId: isShow.value ? 'Hide_StatusBar' : 'Show_StatusBar',
SendTime: Date.now(),
Values: {},
// Values: { Mimetype: 'text/plain;charset=utf-8', Data: 'foo' },
}))
isShow.value = !isShow.value
}
}
function findAllBookmark() {
if (iframeRef.value) {
iframeRef.value.sendMessageToIframe(JSON.stringify({
MessageId: 'CallPythonScript',
SendTime: Date.now(),
ScriptFile: 'BookmarkQuery.py',
Function: 'FindAllBookmarks',
// Values: { text: { type: 'string', value: '111222' } },
}))
}
}
function handleDoReplaceBookmark() {
if (iframeRef.value) {
iframeRef.value.sendMessageToIframe(JSON.stringify({
MessageId: 'CallPythonScript',
SendTime: Date.now(),
ScriptFile: 'BookmarkExec.py',
Function: 'ReplaceBookmark',
Values: { param: { type: 'string', value: JSON.stringify(
{
text: {
row1: `${Date.now()}_row_1`,
row2: `${Date.now()}_row_2`,
h1: `${Date.now()}_h1`,
},
table: [
{
tableIndex: 0,
loopRowIndex: 1,
data: [
{
c1: '11',
c2: '12',
c3: '13',
c4: '14',
},
{
c1: '21',
c2: '22',
c3: '23',
c4: '24',
},
],
},
],
},
) } },
}))
}
}
function readEvent() {
if (iframeRef.value) {
iframeRef.value.sendMessageToIframe(JSON.stringify({
MessageId: 'Host_PostmessageReady',
SendTime: Date.now(),
}))
}
}
</script> </script>
<template> <template>
<div> <div>
<i-frame v-if="previewUrl" :src="previewUrl" /> <div>
<a-button @click="readEvent">
readEvent
</a-button>
<a-button @click="sendMessage">
Send Message
</a-button>
<a-button @click="findAllBookmark">
findAllBookmark
</a-button>
<a-button @click="handleDoReplaceBookmark">
Replace
</a-button>
</div>
<i-frame v-if="previewUrl" ref="iframeRef" :src="previewUrl" />
</div> </div>
</template> </template>