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()
}
// 带输入框的警告框
function prompt (
{
title,
placeholder = '请输入理由',
successMsg = '',
confirmBtnText = '确定',
cancelBtnText = '取消',
cancelMsg = '取消操作',
successCallBack = null,
cancelCallBack = null
}) {
Dialog.$create({
title,
type: 'prompt',
prompt: {
value: '',
placeholder
},
confirmBtn: {
text: confirmBtnText,
active: true,
disabled: false,
href: 'javascript:;'
},
cancelBtn: {
text: cancelBtnText,
active: false,
disabled: false,
href: 'javascript:;'
},
onConfirm: (e, val) => {
if (!_.isEmpty(successMsg)) {
success(successMsg)
}
if (successCallBack) {
successCallBack(val)
}
},
onCancel: () => {
if (!_.isEmpty(cancelMsg)) {
warn(cancelMsg)
}
if (cancelCallBack) {
cancelCallBack.apply(cancelCallBack)
}
}
}, false).show()
}
export default {
success, warn, error, loading, txt, confirm, prompt
}
// 在文件中调用
import Toast from 'toast'
toast.success('text')