|
|
@ -3,7 +3,22 @@ |
|
|
|
* 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) |
|
|
|
* 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) |
|
|
|
* @class Msg |
|
|
|
* @class Msg |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
import { Widget, isString, isNull, isFunction, createWidget, remove, each, emptyFn, delay, zIndex_tip, i18nText, KeyCode, isPlainObject, SIZE_CONSANTS } from "../../core"; |
|
|
|
import { |
|
|
|
|
|
|
|
Widget, |
|
|
|
|
|
|
|
isString, |
|
|
|
|
|
|
|
isNull, |
|
|
|
|
|
|
|
isFunction, |
|
|
|
|
|
|
|
createWidget, |
|
|
|
|
|
|
|
remove, |
|
|
|
|
|
|
|
each, |
|
|
|
|
|
|
|
emptyFn, |
|
|
|
|
|
|
|
delay, |
|
|
|
|
|
|
|
zIndex_tip, |
|
|
|
|
|
|
|
i18nText, |
|
|
|
|
|
|
|
KeyCode, |
|
|
|
|
|
|
|
isPlainObject, |
|
|
|
|
|
|
|
SIZE_CONSANTS |
|
|
|
|
|
|
|
} from "../../core"; |
|
|
|
import { Toast } from "../single"; |
|
|
|
import { Toast } from "../single"; |
|
|
|
|
|
|
|
|
|
|
|
export const Msg = (() => { |
|
|
|
export const Msg = (() => { |
|
|
@ -13,17 +28,21 @@ export const Msg = (() => { |
|
|
|
|
|
|
|
|
|
|
|
const toastStack = []; |
|
|
|
const toastStack = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const defaultConfig = { |
|
|
|
|
|
|
|
buttonHeight: 24, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
alert (title, message, callback) { |
|
|
|
alert(title, message, callback, config = defaultConfig) { |
|
|
|
this._show(false, title, message, callback); |
|
|
|
this._show(false, title, message, callback, config); |
|
|
|
}, |
|
|
|
}, |
|
|
|
confirm (title, message, callback) { |
|
|
|
confirm(title, message, callback, config = defaultConfig) { |
|
|
|
this._show(true, title, message, callback); |
|
|
|
this._show(true, title, message, callback, config); |
|
|
|
}, |
|
|
|
}, |
|
|
|
prompt (title, message, value, callback, min_width) { |
|
|
|
prompt(title, message, value, callback, min_width) { |
|
|
|
// Msg.prompt(title, message, value, callback, min_width);
|
|
|
|
// Msg.prompt(title, message, value, callback, min_width);
|
|
|
|
}, |
|
|
|
}, |
|
|
|
toast (message, options, context) { |
|
|
|
toast(message, options, context) { |
|
|
|
isString(options) && (options = { level: options }); |
|
|
|
isString(options) && (options = { level: options }); |
|
|
|
options = options || {}; |
|
|
|
options = options || {}; |
|
|
|
context = context || Widget._renderEngine.createElement("body"); |
|
|
|
context = context || Widget._renderEngine.createElement("body"); |
|
|
@ -40,7 +59,7 @@ export const Msg = (() => { |
|
|
|
listeners: [ |
|
|
|
listeners: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
eventName: Toast.EVENT_DESTORY, |
|
|
|
eventName: Toast.EVENT_DESTORY, |
|
|
|
action () { |
|
|
|
action() { |
|
|
|
remove(toastStack, toast.element); |
|
|
|
remove(toastStack, toast.element); |
|
|
|
let _height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
let _height = SIZE_CONSANTS.TOAST_TOP; |
|
|
|
each(toastStack, (i, element) => { |
|
|
|
each(toastStack, (i, element) => { |
|
|
@ -72,30 +91,30 @@ export const Msg = (() => { |
|
|
|
toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); |
|
|
|
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) { |
|
|
|
_show(hasCancel, title, message, callback, config) { |
|
|
|
isNull($mask) && |
|
|
|
isNull($mask) && |
|
|
|
($mask = Widget._renderEngine |
|
|
|
($mask = Widget._renderEngine |
|
|
|
.createElement("<div class=\"bi-z-index-mask\">") |
|
|
|
.createElement("<div class=\"bi-z-index-mask\">") |
|
|
|
.css({ |
|
|
|
.css({ |
|
|
|
position: "absolute", |
|
|
|
position: "absolute", |
|
|
|
zIndex: zIndex_tip - 2, |
|
|
|
zIndex: zIndex_tip - 2, |
|
|
|
top: 0, |
|
|
|
top: 0, |
|
|
|
left: 0, |
|
|
|
left: 0, |
|
|
|
right: 0, |
|
|
|
right: 0, |
|
|
|
bottom: 0, |
|
|
|
bottom: 0, |
|
|
|
opacity: 0.5, |
|
|
|
opacity: 0.5, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.appendTo("body")); |
|
|
|
.appendTo("body")); |
|
|
|
$pop = Widget._renderEngine |
|
|
|
$pop = Widget._renderEngine |
|
|
|
.createElement("<div class=\"bi-message-depend\">") |
|
|
|
.createElement("<div class=\"bi-message-depend\">") |
|
|
|
.css({ |
|
|
|
.css({ |
|
|
@ -107,6 +126,7 @@ export const Msg = (() => { |
|
|
|
bottom: 0, |
|
|
|
bottom: 0, |
|
|
|
}) |
|
|
|
}) |
|
|
|
.appendTo("body"); |
|
|
|
.appendTo("body"); |
|
|
|
|
|
|
|
|
|
|
|
function close() { |
|
|
|
function close() { |
|
|
|
messageShows[messageShows.length - 1].destroy(); |
|
|
|
messageShows[messageShows.length - 1].destroy(); |
|
|
|
messageShows.pop(); |
|
|
|
messageShows.pop(); |
|
|
@ -115,14 +135,16 @@ export const Msg = (() => { |
|
|
|
$mask = null; |
|
|
|
$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, |
|
|
|
text: i18nText("BI-Basic_Cancel"), |
|
|
|
text: i18nText("BI-Basic_Cancel"), |
|
|
|
level: "ignore", |
|
|
|
light: true, |
|
|
|
handler () { |
|
|
|
handler() { |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
if (isFunction(callback)) { |
|
|
|
if (isFunction(callback)) { |
|
|
|
callback.apply(null, [false]); |
|
|
|
callback.apply(null, [false]); |
|
|
@ -134,8 +156,9 @@ export const Msg = (() => { |
|
|
|
controlItems.push({ |
|
|
|
controlItems.push({ |
|
|
|
el: { |
|
|
|
el: { |
|
|
|
type: "bi.button", |
|
|
|
type: "bi.button", |
|
|
|
|
|
|
|
height: config.buttonHeight, |
|
|
|
text: i18nText("BI-Basic_OK"), |
|
|
|
text: i18nText("BI-Basic_OK"), |
|
|
|
handler () { |
|
|
|
handler() { |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
if (isFunction(callback)) { |
|
|
|
if (isFunction(callback)) { |
|
|
|
callback.apply(null, [true]); |
|
|
|
callback.apply(null, [true]); |
|
|
@ -152,7 +175,7 @@ export const Msg = (() => { |
|
|
|
attributes: { |
|
|
|
attributes: { |
|
|
|
tabIndex: 1, |
|
|
|
tabIndex: 1, |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted () { |
|
|
|
mounted() { |
|
|
|
this.element.keyup(e => { |
|
|
|
this.element.keyup(e => { |
|
|
|
if (e.keyCode === KeyCode.ENTER) { |
|
|
|
if (e.keyCode === KeyCode.ENTER) { |
|
|
|
close(); |
|
|
|
close(); |
|
|
@ -170,7 +193,8 @@ export const Msg = (() => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
try { |
|
|
|
try { |
|
|
|
this.element.focus(); |
|
|
|
this.element.focus(); |
|
|
|
} catch (e) {} |
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
cls: "bi-card", |
|
|
|
cls: "bi-card", |
|
|
|
items: { |
|
|
|
items: { |
|
|
@ -194,7 +218,7 @@ export const Msg = (() => { |
|
|
|
type: "bi.icon_button", |
|
|
|
type: "bi.icon_button", |
|
|
|
cls: "bi-message-close close-font", |
|
|
|
cls: "bi-message-close close-font", |
|
|
|
// height: 50,
|
|
|
|
// height: 50,
|
|
|
|
handler () { |
|
|
|
handler() { |
|
|
|
close(); |
|
|
|
close(); |
|
|
|
if (isFunction(callback)) { |
|
|
|
if (isFunction(callback)) { |
|
|
|
callback.apply(null, [false]); |
|
|
|
callback.apply(null, [false]); |
|
|
|