|
|
@ -21,254 +21,250 @@ import { |
|
|
|
} from "../../core"; |
|
|
|
} from "../../core"; |
|
|
|
import { Toast } from "../single"; |
|
|
|
import { Toast } from "../single"; |
|
|
|
|
|
|
|
|
|
|
|
export const Msg = (() => { |
|
|
|
let $mask, $pop; |
|
|
|
let $mask, $pop; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const messageShows = []; |
|
|
|
const messageShows = []; |
|
|
|
|
|
|
|
|
|
|
|
const toastStack = []; |
|
|
|
const toastStack = []; |
|
|
|
|
|
|
|
|
|
|
|
const defaultConfig = { |
|
|
|
const defaultConfig = { |
|
|
|
buttonHeight: 24, |
|
|
|
buttonHeight: 24, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
export const Msg = { |
|
|
|
alert(title, message, callback, config = defaultConfig) { |
|
|
|
alert(title, message, callback, config = defaultConfig) { |
|
|
|
this._show(false, title, message, callback, config); |
|
|
|
_show(false, title, message, callback, config); |
|
|
|
}, |
|
|
|
}, |
|
|
|
confirm(title, message, callback, config = defaultConfig) { |
|
|
|
confirm(title, message, callback, config = defaultConfig) { |
|
|
|
this._show(true, title, message, callback, config); |
|
|
|
_show(true, title, message, callback, config); |
|
|
|
}, |
|
|
|
}, |
|
|
|
prompt(title, message, value, callback, min_width) { |
|
|
|
toast(message, options, context) { |
|
|
|
// Msg.prompt(title, message, value, callback, min_width);
|
|
|
|
isString(options) && (options = { level: options }); |
|
|
|
}, |
|
|
|
options = options || {}; |
|
|
|
toast(message, options, context) { |
|
|
|
context = context || Widget._renderEngine.createElement("body"); |
|
|
|
isString(options) && (options = { level: options }); |
|
|
|
const level = options.level || "common"; |
|
|
|
options = options || {}; |
|
|
|
const autoClose = isNull(options.autoClose) ? true : options.autoClose; |
|
|
|
context = context || Widget._renderEngine.createElement("body"); |
|
|
|
const callback = isFunction(options.callback) ? options.callback : emptyFn; |
|
|
|
const level = options.level || "common"; |
|
|
|
const toast = createWidget({ |
|
|
|
const autoClose = isNull(options.autoClose) ? true : options.autoClose; |
|
|
|
type: "bi.toast", |
|
|
|
const callback = isFunction(options.callback) ? options.callback : emptyFn; |
|
|
|
cls: "bi-message-animate bi-message-leave", |
|
|
|
const toast = createWidget({ |
|
|
|
level, |
|
|
|
type: "bi.toast", |
|
|
|
autoClose, |
|
|
|
cls: "bi-message-animate bi-message-leave", |
|
|
|
closable: options.closable, |
|
|
|
level, |
|
|
|
text: message, |
|
|
|
autoClose, |
|
|
|
listeners: [ |
|
|
|
closable: options.closable, |
|
|
|
{ |
|
|
|
text: message, |
|
|
|
eventName: Toast.EVENT_DESTORY, |
|
|
|
listeners: [ |
|
|
|
action() { |
|
|
|
{ |
|
|
|
remove(toastStack, toast.element); |
|
|
|
eventName: Toast.EVENT_DESTORY, |
|
|
|
let _height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
action() { |
|
|
|
each(toastStack, (i, element) => { |
|
|
|
remove(toastStack, toast.element); |
|
|
|
element.css({ top: _height }); |
|
|
|
let _height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
_height += element.outerHeight() + 10; |
|
|
|
each(toastStack, (i, element) => { |
|
|
|
}); |
|
|
|
element.css({ top: _height }); |
|
|
|
callback(); |
|
|
|
_height += element.outerHeight() + 10; |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
callback(); |
|
|
|
], |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
let height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
], |
|
|
|
each(toastStack, (i, element) => { |
|
|
|
}); |
|
|
|
height += element.outerHeight() + 10; |
|
|
|
let height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
}); |
|
|
|
each(toastStack, (i, element) => { |
|
|
|
createWidget({ |
|
|
|
height += element.outerHeight() + 10; |
|
|
|
type: "bi.absolute", |
|
|
|
}); |
|
|
|
element: context, |
|
|
|
createWidget({ |
|
|
|
items: [ |
|
|
|
type: "bi.absolute", |
|
|
|
{ |
|
|
|
element: context, |
|
|
|
el: toast, |
|
|
|
items: [ |
|
|
|
left: "50%", |
|
|
|
{ |
|
|
|
top: height, |
|
|
|
el: toast, |
|
|
|
} |
|
|
|
left: "50%", |
|
|
|
], |
|
|
|
top: height, |
|
|
|
}); |
|
|
|
} |
|
|
|
toastStack.push(toast.element); |
|
|
|
], |
|
|
|
toast.element.css({ "margin-left": (-1 * toast.element.outerWidth()) / 2 }); |
|
|
|
}); |
|
|
|
toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); |
|
|
|
toastStack.push(toast.element); |
|
|
|
|
|
|
|
toast.element.css({ "margin-left": (-1 * toast.element.outerWidth()) / 2 }); |
|
|
|
|
|
|
|
toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autoClose && |
|
|
|
autoClose && |
|
|
|
delay(() => { |
|
|
|
delay(() => { |
|
|
|
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); |
|
|
|
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); |
|
|
|
toast.destroy?.(); |
|
|
|
toast.destroy?.(); |
|
|
|
}, 5000); |
|
|
|
}, 5000); |
|
|
|
|
|
|
|
|
|
|
|
return function() { |
|
|
|
return function() { |
|
|
|
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); |
|
|
|
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); |
|
|
|
toast.destroy?.(); |
|
|
|
toast.destroy?.(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
_show(hasCancel, title, message, callback, config) { |
|
|
|
}; |
|
|
|
isNull($mask) && |
|
|
|
|
|
|
|
($mask = Widget._renderEngine |
|
|
|
|
|
|
|
.createElement("<div class=\"bi-z-index-mask\">") |
|
|
|
|
|
|
|
.css({ |
|
|
|
|
|
|
|
position: "absolute", |
|
|
|
|
|
|
|
zIndex: zIndex_tip - 2, |
|
|
|
|
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 0, |
|
|
|
|
|
|
|
right: 0, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
opacity: 0.5, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.appendTo("body")); |
|
|
|
|
|
|
|
$pop = Widget._renderEngine |
|
|
|
|
|
|
|
.createElement("<div class=\"bi-message-depend\">") |
|
|
|
|
|
|
|
.css({ |
|
|
|
|
|
|
|
position: "absolute", |
|
|
|
|
|
|
|
zIndex: zIndex_tip - 1, |
|
|
|
|
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 0, |
|
|
|
|
|
|
|
right: 0, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.appendTo("body"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function close() { |
|
|
|
function _show(hasCancel, title, message, callback, config) { |
|
|
|
messageShows[messageShows.length - 1].destroy(); |
|
|
|
isNull($mask) && |
|
|
|
messageShows.pop(); |
|
|
|
($mask = Widget._renderEngine |
|
|
|
if (messageShows.length === 0) { |
|
|
|
.createElement("<div class=\"bi-z-index-mask\">") |
|
|
|
$mask.remove(); |
|
|
|
.css({ |
|
|
|
$mask = null; |
|
|
|
position: "absolute", |
|
|
|
} |
|
|
|
zIndex: zIndex_tip - 2, |
|
|
|
} |
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 0, |
|
|
|
|
|
|
|
right: 0, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
opacity: 0.5, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.appendTo("body")); |
|
|
|
|
|
|
|
$pop = Widget._renderEngine |
|
|
|
|
|
|
|
.createElement("<div class=\"bi-message-depend\">") |
|
|
|
|
|
|
|
.css({ |
|
|
|
|
|
|
|
position: "absolute", |
|
|
|
|
|
|
|
zIndex: zIndex_tip - 1, |
|
|
|
|
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 0, |
|
|
|
|
|
|
|
right: 0, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.appendTo("body"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function close() { |
|
|
|
|
|
|
|
messageShows[messageShows.length - 1].destroy(); |
|
|
|
|
|
|
|
messageShows.pop(); |
|
|
|
|
|
|
|
if (messageShows.length === 0) { |
|
|
|
|
|
|
|
$mask.remove(); |
|
|
|
|
|
|
|
$mask = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const controlItems = []; |
|
|
|
const controlItems = []; |
|
|
|
if (hasCancel === true) { |
|
|
|
if (hasCancel === true) { |
|
|
|
controlItems.push({ |
|
|
|
controlItems.push({ |
|
|
|
el: { |
|
|
|
el: { |
|
|
|
type: "bi.button", |
|
|
|
type: "bi.button", |
|
|
|
height: config.buttonHeight, |
|
|
|
height: config.buttonHeight, |
|
|
|
text: i18nText("BI-Basic_Cancel"), |
|
|
|
text: i18nText("BI-Basic_Cancel"), |
|
|
|
light: true, |
|
|
|
light: true, |
|
|
|
handler() { |
|
|
|
handler() { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [false]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
controlItems.push({ |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.button", |
|
|
|
|
|
|
|
height: config.buttonHeight, |
|
|
|
|
|
|
|
text: i18nText("BI-Basic_OK"), |
|
|
|
|
|
|
|
handler() { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [true]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const conf = { |
|
|
|
|
|
|
|
element: $pop, |
|
|
|
|
|
|
|
type: "bi.center_adapt", |
|
|
|
|
|
|
|
items: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: "bi.border", |
|
|
|
|
|
|
|
attributes: { |
|
|
|
|
|
|
|
tabIndex: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mounted() { |
|
|
|
|
|
|
|
this.element.keyup(e => { |
|
|
|
|
|
|
|
if (e.keyCode === KeyCode.ENTER) { |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
if (isFunction(callback)) { |
|
|
|
if (isFunction(callback)) { |
|
|
|
callback.apply(null, [false]); |
|
|
|
callback.apply(null, [true]); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} else if (e.keyCode === KeyCode.ESCAPE) { |
|
|
|
}, |
|
|
|
close(); |
|
|
|
}); |
|
|
|
if (hasCancel === true) { |
|
|
|
} |
|
|
|
if (isFunction(callback)) { |
|
|
|
controlItems.push({ |
|
|
|
callback.apply(null, [false]); |
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.button", |
|
|
|
|
|
|
|
height: config.buttonHeight, |
|
|
|
|
|
|
|
text: i18nText("BI-Basic_OK"), |
|
|
|
|
|
|
|
handler() { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [true]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const conf = { |
|
|
|
|
|
|
|
element: $pop, |
|
|
|
|
|
|
|
type: "bi.center_adapt", |
|
|
|
|
|
|
|
items: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: "bi.border", |
|
|
|
|
|
|
|
attributes: { |
|
|
|
|
|
|
|
tabIndex: 1, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mounted() { |
|
|
|
|
|
|
|
this.element.keyup(e => { |
|
|
|
|
|
|
|
if (e.keyCode === KeyCode.ENTER) { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [true]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (e.keyCode === KeyCode.ESCAPE) { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (hasCancel === true) { |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [false]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
this.element.focus(); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
cls: "bi-card", |
|
|
|
}); |
|
|
|
items: { |
|
|
|
try { |
|
|
|
north: { |
|
|
|
this.element.focus(); |
|
|
|
el: { |
|
|
|
} catch (e) { |
|
|
|
type: "bi.border", |
|
|
|
} |
|
|
|
cls: "bi-message-title bi-background", |
|
|
|
}, |
|
|
|
items: { |
|
|
|
cls: "bi-card", |
|
|
|
center: { |
|
|
|
items: { |
|
|
|
el: { |
|
|
|
north: { |
|
|
|
type: "bi.label", |
|
|
|
el: { |
|
|
|
cls: "bi-font-bold", |
|
|
|
type: "bi.border", |
|
|
|
text: title || i18nText("BI-Basic_Prompt"), |
|
|
|
cls: "bi-message-title bi-background", |
|
|
|
textAlign: "left", |
|
|
|
items: { |
|
|
|
hgap: 20, |
|
|
|
center: { |
|
|
|
height: 40, |
|
|
|
el: { |
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
east: { |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.icon_button", |
|
|
|
|
|
|
|
cls: "bi-message-close close-font", |
|
|
|
|
|
|
|
// height: 50,
|
|
|
|
|
|
|
|
handler() { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [false]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
width: 56, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
height: 40, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
center: { |
|
|
|
|
|
|
|
el: isPlainObject(message) |
|
|
|
|
|
|
|
? message |
|
|
|
|
|
|
|
: { |
|
|
|
|
|
|
|
type: "bi.label", |
|
|
|
type: "bi.label", |
|
|
|
vgap: 10, |
|
|
|
cls: "bi-font-bold", |
|
|
|
|
|
|
|
text: title || i18nText("BI-Basic_Prompt"), |
|
|
|
|
|
|
|
textAlign: "left", |
|
|
|
hgap: 20, |
|
|
|
hgap: 20, |
|
|
|
whiteSpace: "normal", |
|
|
|
height: 40, |
|
|
|
text: message, |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
south: { |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.absolute", |
|
|
|
|
|
|
|
items: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.right_vertical_adapt", |
|
|
|
|
|
|
|
lgap: 10, |
|
|
|
|
|
|
|
items: controlItems, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 20, |
|
|
|
|
|
|
|
right: 20, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
height: 44, |
|
|
|
east: { |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.icon_button", |
|
|
|
|
|
|
|
cls: "bi-message-close close-font", |
|
|
|
|
|
|
|
// height: 50,
|
|
|
|
|
|
|
|
handler() { |
|
|
|
|
|
|
|
close(); |
|
|
|
|
|
|
|
if (isFunction(callback)) { |
|
|
|
|
|
|
|
callback.apply(null, [false]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
width: 56, |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
width: 450, |
|
|
|
height: 40, |
|
|
|
height: 200, |
|
|
|
}, |
|
|
|
} |
|
|
|
center: { |
|
|
|
], |
|
|
|
el: isPlainObject(message) |
|
|
|
}; |
|
|
|
? message |
|
|
|
|
|
|
|
: { |
|
|
|
messageShows[messageShows.length] = createWidget(conf); |
|
|
|
type: "bi.label", |
|
|
|
}, |
|
|
|
vgap: 10, |
|
|
|
|
|
|
|
hgap: 20, |
|
|
|
|
|
|
|
whiteSpace: "normal", |
|
|
|
|
|
|
|
text: message, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
south: { |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.absolute", |
|
|
|
|
|
|
|
items: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
el: { |
|
|
|
|
|
|
|
type: "bi.right_vertical_adapt", |
|
|
|
|
|
|
|
lgap: 10, |
|
|
|
|
|
|
|
items: controlItems, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
top: 0, |
|
|
|
|
|
|
|
left: 20, |
|
|
|
|
|
|
|
right: 20, |
|
|
|
|
|
|
|
bottom: 0, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
height: 44, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
width: 450, |
|
|
|
|
|
|
|
height: 200, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
messageShows[messageShows.length] = createWidget(conf); |
|
|
|
|
|
|
|
} |
|
|
|