lixin-web
Version:
vue and bootstrap
116 lines (103 loc) • 2.91 kB
JavaScript
//noty v2.4.1
import 'noty/js/noty/jquery.noty'
import 'noty/js/noty/layouts/center'
import 'noty/js/noty/layouts/topRight'
import 'noty/js/noty/layouts/bottomRight'
import '../../module/ref/noty.relax'
function info(msg,arrOpt,notyOpt){
return notify('information',msg,arrOpt,notyOpt)
}
function warning(msg,arrOpt,notyOpt){
return notify('warning',msg,arrOpt,notyOpt)
}
export function error(msg,arrOpt,notyOpt){
return notify('error',msg,arrOpt,notyOpt)
}
export function success(msg,arrOpt,notyOpt){
return notify('success',msg,arrOpt,notyOpt)
}
const confirm = (msg, Ok = () => {},btnOk = '确定', btnCancel = '取消',timeout = false,Cancel = () => {},type = 'alert') => {
const n = notify(type,msg,timeout,{buttons:[
{
addClass: 'btn btn-primary',
text: btnOk,
onClick: function($noty) {
$noty.close();
Ok()
}
}, {
addClass: 'btn btn-default',
text: btnCancel,
onClick: function($noty) {
$noty.close();
Cancel()
}
}
],
afterShow(){
$(n.$buttons.children()[0])
.one('keydown.dismiss.bs.modal', e => {
e.which == 27 && n.close()
})
.trigger('focus')
}
})
}
const animated = {
open: 'animated zoomIn',
close: 'animated zoomOut',
easing: 'swing', // easing
}
export const fixCloseAnimation = {
open: {opacity: 'toggle'}, // jQuery animate function property object
close: {opacity: 'toggle'}, // jQuery animate function property object
speed: 300
}
const lastNoty = {}
export function notify(
type,text,option = 2000,
{
animation = animated,
maxVisible = 5,
progressBar = false,
buttons = false,
layout = 'center',
afterShow = () => {},
closeWith = ['click']
} = {}
){
// var timeout = typeof option == 'number' && option || option && option[1]
var timeout = Array.isArray(option) ? option[1] : typeof option == 'function' ? 2000 : option == 'keep' ? false : option
let checkID = option && option[2]
if(checkID) {
!lastNoty[checkID] && (lastNoty[checkID] = [])
// // closeAll = [].forEach.bind(Will.lastNoty[option[2]],$.noty.close)
if (lastNoty[checkID].length && lastNoty[checkID].some(i => $.noty.get(i).closeTimer)) return
}
var n = noty({
layout,
theme:'relax',
type,
text,
animation,
timeout,
progressBar,
maxVisible,
closeWith,
callback:{
// onShow: closeAll || function () {},
afterShow,
afterClose:typeof option == 'function' && option || Array.isArray(option) && option[0] || function() {}
},
buttons
});
checkID && (lastNoty[checkID].push(n.options.id))
if (buttons || option === 'keep') return n
}
export default {
success,
warning,
info,
error,
confirm
}