2025-01-10 07:00:58 +00:00
|
|
|
import { createApp, nextTick } from 'vue'
|
|
|
|
import MessagePopup from './index.vue'
|
|
|
|
|
|
|
|
const message = {
|
2025-02-08 02:06:21 +00:00
|
|
|
success(options, duration = 2000) {
|
2025-01-10 07:00:58 +00:00
|
|
|
if (process.client) {
|
2025-02-08 02:06:21 +00:00
|
|
|
if (typeof options === 'string') {
|
|
|
|
this.show({ type: 'success', message: options, duration })
|
|
|
|
} else {
|
|
|
|
this.show({
|
|
|
|
type: 'success',
|
|
|
|
...options,
|
|
|
|
duration
|
|
|
|
})
|
|
|
|
}
|
2025-01-10 07:00:58 +00:00
|
|
|
}
|
|
|
|
},
|
2025-02-08 02:06:21 +00:00
|
|
|
error(options, duration = 2000) {
|
2025-01-10 07:00:58 +00:00
|
|
|
if (process.client) {
|
2025-02-08 02:06:21 +00:00
|
|
|
if (typeof options === 'string') {
|
|
|
|
this.show({ type: 'error', message: options, duration })
|
|
|
|
} else {
|
|
|
|
this.show({
|
|
|
|
type: 'error',
|
|
|
|
...options,
|
|
|
|
duration
|
|
|
|
})
|
|
|
|
}
|
2025-01-10 07:00:58 +00:00
|
|
|
}
|
|
|
|
},
|
2025-02-08 02:06:21 +00:00
|
|
|
warning(options, duration = 2000) {
|
2025-01-10 07:00:58 +00:00
|
|
|
if (process.client) {
|
2025-02-08 02:06:21 +00:00
|
|
|
if (typeof options === 'string') {
|
|
|
|
this.show({ type: 'warning', message: options, duration })
|
|
|
|
} else {
|
|
|
|
this.show({
|
|
|
|
type: 'warning',
|
|
|
|
...options,
|
|
|
|
duration
|
|
|
|
})
|
|
|
|
}
|
2025-01-10 07:00:58 +00:00
|
|
|
}
|
|
|
|
},
|
2025-02-08 02:06:21 +00:00
|
|
|
show(options) {
|
2025-01-10 07:00:58 +00:00
|
|
|
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(() => {
|
2025-02-08 02:06:21 +00:00
|
|
|
instance.showMessage?.(options)
|
2025-01-10 07:00:58 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { message }
|