插件交互

This commit is contained in:
plightfield 2024-11-04 14:53:07 +08:00
parent 34d37d4efd
commit aa877662be
2 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import { defineComponent, onMounted, onUnmounted, ref, watch } from 'vue'
import useRouterStore from '@/useRouterStore'
import useSearchStore from '@/layout/header/search/useSearchStore'
import useLayoutStore from '@/layout/useLayoutStore'
import { sendParent } from '@/utils/parent'
const stageStrList = [
'dazhaohu',
@ -128,6 +129,7 @@ export default defineComponent(() => {
}}
onClick={() => {
run('aixin')
sendParent(['openSide'])
}}
/>
)

19
src/utils/parent.ts Normal file
View File

@ -0,0 +1,19 @@
// 发送消息
export function sendParent(data: ['openSide']) {
parent.window.postMessage(
{
type: data[0],
data: (data as any)[1]
},
'*'
)
}
// 接收消息
export function listenParent<T>(type: string, cb: (data: T) => void) {
window.addEventListener('message', (e) => {
if (e.data?.type === 'uitab-' + type) {
cb(e.data.data)
}
})
}