mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-01 13:36:55 +08:00
refactor(message): clean code logic
This commit is contained in:
parent
ce46f0de8e
commit
d213bf5209
@ -2,9 +2,16 @@ import { Fragment, ref, h, nextTick, toRef } from 'vue'
|
||||
import createId from '../../_utils/vue/createId'
|
||||
import MessageEnvironment from './MessageEnvironment.js'
|
||||
import { useContainer } from '../../_utils/composition'
|
||||
import omit from '../../_utils/vue/omit'
|
||||
|
||||
export default {
|
||||
name: 'MessageController',
|
||||
props: {
|
||||
to: {
|
||||
type: [String, Object],
|
||||
default: 'body'
|
||||
}
|
||||
},
|
||||
setup (props) {
|
||||
const messageListRef = ref([])
|
||||
const [mountContainerIfNotExist, unmountContainerIfEmpty] = useContainer(
|
||||
@ -17,12 +24,6 @@ export default {
|
||||
unmountContainerIfEmpty
|
||||
}
|
||||
},
|
||||
props: {
|
||||
to: {
|
||||
type: [String, Object],
|
||||
default: 'body'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
create (content, options = {}) {
|
||||
this.mountContainerIfNotExist()
|
||||
@ -31,7 +32,9 @@ export default {
|
||||
...options,
|
||||
content,
|
||||
key,
|
||||
destroy: null
|
||||
destroy: () => {
|
||||
this.$refs[`n-message-${key}`].hide()
|
||||
}
|
||||
}
|
||||
this.messageList.push(messageReactive)
|
||||
return messageReactive
|
||||
@ -62,8 +65,8 @@ export default {
|
||||
render () {
|
||||
return h(Fragment, null, this.messageList.map(
|
||||
message => h(MessageEnvironment, {
|
||||
...message,
|
||||
controller: message,
|
||||
ref: `n-message-${message.key}`,
|
||||
...omit(message, ['destroy']),
|
||||
onInternalAfterLeave: this.handleAfterLeave
|
||||
}))
|
||||
)
|
||||
|
@ -20,14 +20,6 @@ export default {
|
||||
default: () => {}
|
||||
},
|
||||
// private
|
||||
controller: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
destroy: {
|
||||
type: Function,
|
||||
default: null
|
||||
},
|
||||
onInternalAfterLeave: {
|
||||
type: Function,
|
||||
default: () => {}
|
||||
@ -49,9 +41,6 @@ export default {
|
||||
show: true
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.controller.destroy = this.hide
|
||||
},
|
||||
mounted () {
|
||||
if (this.duration) {
|
||||
this.timerId = window.setTimeout(this.hide, this.duration)
|
||||
|
Loading…
Reference in New Issue
Block a user