registry.js
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 注册
import Vuex from 'vuex'
export default function registry(v) {
v.use(Vuex)
// 挂在store到全局(this)
v.prototype.$toastStore = new Vuex.Store({
state: {
show:false,
text:'提示',
duration: 1500,
textClass:null,
icon:null,
iconClass:null,
},
getters:{
'GET_TOAST_SHOW': function (state) {
return state.show
},
'GET_TOAST_TEXT': function (state) {
return state.text
},
'GET_TOAST_DURATION': function (state) {
return state.duration
},
'GET_TOAST_TEXT_CLASS_NAME': function (state) {
return state.textClass
},
'GET_TOAST_ICON': function (state) {
return state.icon
},
'GET_TOAST_ICON_CLASS_NAME': function (state) {
return state.iconClass
},
},
mutations: {
hideToast(state) {
state.show = false
},
showToast(state, data) {
if (state.show) return
data.duration = data.duration || 1500
let dt = {
show: true,
text: data.text || '提示',
duration: data.duration + 700,
textClass: data.textClass || '',
icon:data.icon || '',
iconClass:data.iconClass || '',
}
state = Object.assign(state, dt)
}
}
})
// 注册显示方法 $mptoast 到全局
v.prototype.$mptoast = function (data, icon = '', duration = 1500, textClass = '',iconClass= '') {
if (typeof data === 'string' || typeof data === 'number') {
v.prototype.$toastStore.commit('showToast', {text: data, icon:icon, duration: duration, textClass: textClass, iconClass: iconClass})
}
if (typeof data === 'object') {
v.prototype.$toastStore.commit('showToast', data)
}
}
}