Skip to content

Commit 37fe7d4

Browse files
committed
feat: msg add max length with queue
1 parent 11b6d65 commit 37fe7d4

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/renderer/components/Msg/index.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
1+
const queue = []
2+
const maxLength = 5
3+
14
export default {
25
install: function (Vue, Message, defaultOption = {}) {
36
Vue.prototype.$msg = new Proxy(Message, {
47
get (obj, prop) {
58
return (arg) => {
6-
if (arg instanceof String) {
9+
if (!(arg instanceof Object)) {
710
arg = { message: arg }
811
}
9-
obj[prop]({
10-
...defaultOption,
11-
...arg
12-
})
12+
const task = {
13+
run () {
14+
obj[prop]({
15+
...defaultOption,
16+
...arg,
17+
onClose (...data) {
18+
const currentTask = queue.pop()
19+
if (currentTask) {
20+
currentTask.run()
21+
}
22+
if (arg.onClose) {
23+
arg.onClose(...data)
24+
}
25+
}
26+
})
27+
}
28+
}
29+
30+
if (queue.length >= maxLength) {
31+
queue.pop()
32+
}
33+
queue.unshift(task)
34+
35+
if (queue.length === 1) {
36+
queue[0].run()
37+
}
1338
}
1439
}
1540
})

0 commit comments

Comments
 (0)