import Vue from ‘vue’
import { Toast, Dialog } from ‘cube-ui’
import _ from ‘lodash’
Vue.use(Toast, Dialog)
function success (text) {
Toast.$create({
txt: text,
type: ‘correct’,
time: 1000
}).show()
}
function error (text) {
// eslint-disable-next-line no-console
console.log(‘toast error:’ + text)
Toast.$create({
txt: text,
type: ‘error’,
time: 3000
}).show()
}
function warn (text) {
Toast.$create({
txt: text,
type: ‘warn’,
time: 1000
}).show()
}
function loading (text) {
Toast.$create({
txt: text,
type: ‘loading’,
time: 1000
}).show()
}
function txt (text) {
Toast.$create({
txt: text,
type: ‘text’,
time: 1000
}).show()
}
function confirm (
{
title,
content,
successMsg = ‘’,
confirmBtnText = ‘确定’,
cancelBtnText = ‘取消’,
cancelMsg = ‘取消操作’,
successCallBack = null,
cancelCallBack = null
}
) {
Dialog.$create({
icon: ‘cubeic-alert’,
type: ‘confirm’,
title,
content,
confirmBtn: {
text: confirmBtnText,
active: true,
disabled: false,
href: ‘javascript:;’
},
cancelBtn: {
text: cancelBtnText,
active: false,
disabled: false,
href: ‘javascript:;’
},
onConfirm: () => {
if (!.isEmpty(successMsg)) {
success(successMsg)
}
if (successCallBack) {
successCallBack.apply(successCallBack)
}
},
onCancel: () => {
if (!.isEmpty(cancelMsg)) {
warn(cancelMsg)
}
if (cancelCallBack) {
cancelCallBack.apply(cancelCallBack)
}
}
}).show()
}
export default {
success, warn, error, loading, txt, confirm
}
// 在其他页面中使用
import toast from ‘toast’
toast.warn()
toast.confirm({
content: ‘’,
successCallBack:()=>{},
cancelCallBack:()=>{}
})