This commit is contained in:
xingyy 2025-01-10 16:45:18 +08:00
parent 07c7dfaa78
commit c132816a9f
3 changed files with 50 additions and 2 deletions

View File

@ -16,7 +16,6 @@ const showMessage = ({ type = 'warning', message, duration = 2000 }) => {
visible.value = false visible.value = false
}, duration) }, duration)
} }
defineExpose({ showMessage }) defineExpose({ showMessage })
</script> </script>

View File

@ -0,0 +1,44 @@
import { createApp, nextTick } from 'vue'
import MessagePopup from './index.vue'
const message = {
success(text, duration = 2000) {
if (process.client) {
this.show({ type: 'success', message: text, duration })
}
},
error(text, duration = 2000) {
if (process.client) {
this.show({ type: 'error', message: text, duration })
}
},
warning(text, duration = 2000) {
if (process.client) {
this.show({ type: 'warning', message: text, duration })
}
},
show({ type = 'success', message, duration = 2000 }) {
if (!process.client) return
const container = document.createElement('div')
document.body.appendChild(container)
const app = createApp(MessagePopup, {
onAfterLeave: () => {
app.unmount()
document.body.removeChild(container)
}
})
const instance = app.mount(container)
nextTick(() => {
instance.showMessage?.({
type,
message,
duration
})
})
}
}
export { message }

View File

@ -1,8 +1,13 @@
<template> <template>
<main class="flex flex-col min-h-svh"> <main class="flex flex-col min-h-svh">
<div class="flex-1 pb-[var(--van-nav-bar-height)]"> <AppHeader class="h-[var(--van-nav-bar-height)]" />
<div class="flex-1 p-16 pb-[var(--van-nav-bar-height)]">
<slot /> <slot />
</div> </div>
<AppFooter /> <AppFooter />
</main> </main>
</template> </template>
<script setup lang="ts">
</script>