34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
import { createApp } from 'vue'
|
||
|
import MinWindow from '@/components/floatingBubble/index.vue'
|
||
|
|
||
|
let minWindowInstance = null
|
||
|
let minWindowApp = null // 新增:保存应用实例
|
||
|
|
||
|
// 创建悬浮窗
|
||
|
export const showMinWindow1 = ( props = {}) => {
|
||
|
if (process.client){
|
||
|
const container = document.createElement('div')
|
||
|
container.className = 'floating-bubble-container' // 添加类名
|
||
|
document.body.appendChild(container)
|
||
|
const app = createApp(MinWindow, {
|
||
|
...props
|
||
|
})
|
||
|
|
||
|
minWindowApp = app // 保存应用实例
|
||
|
minWindowInstance = app.mount(container)
|
||
|
return minWindowInstance
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const hideMinWindow1 = () => {
|
||
|
if (!minWindowApp) return
|
||
|
const cleanup = () => {
|
||
|
minWindowApp.unmount() // 使用应用实例的unmount方法
|
||
|
const container = document.querySelector('.floating-bubble-container') // 假设您的容器有这个类名
|
||
|
container && document.body.removeChild(container)
|
||
|
minWindowApp = null
|
||
|
minWindowInstance = null
|
||
|
}
|
||
|
|
||
|
cleanup()
|
||
|
}
|