Browse Source

BI-137665 fix: 代码优化

research/test
jian 11 months ago
parent
commit
3d59f37953
  1. 289
      packages/fineui/src/base/foundation/message.js

289
packages/fineui/src/base/foundation/message.js

@ -33,10 +33,10 @@ const defaultConfig = {
export const Msg = { 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);
}, },
toast(message, options, context) { toast(message, options, context) {
isString(options) && (options = { level: options }); isString(options) && (options = { level: options });
@ -97,173 +97,174 @@ export const Msg = {
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");
const controlItems = []; function close() {
if (hasCancel === true) { messageShows[messageShows.length - 1].destroy();
controlItems.push({ messageShows.pop();
el: { if (messageShows.length === 0) {
type: "bi.button", $mask.remove();
height: config.buttonHeight, $mask = null;
text: i18nText("BI-Basic_Cancel"),
light: true,
handler() {
close();
if (isFunction(callback)) {
callback.apply(null, [false]);
}
},
},
});
} }
}
const controlItems = [];
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_OK"), text: i18nText("BI-Basic_Cancel"),
light: true,
handler() { handler() {
close(); close();
if (isFunction(callback)) { if (isFunction(callback)) {
callback.apply(null, [true]); callback.apply(null, [false]);
} }
}, },
}, },
}); });
const conf = { }
element: $pop, controlItems.push({
type: "bi.center_adapt", el: {
items: [ type: "bi.button",
{ height: config.buttonHeight,
type: "bi.border", text: i18nText("BI-Basic_OK"),
attributes: { handler() {
tabIndex: 1, close();
}, if (isFunction(callback)) {
mounted() { callback.apply(null, [true]);
this.element.keyup(e => { }
if (e.keyCode === KeyCode.ENTER) { },
close(); },
});
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)) { if (isFunction(callback)) {
callback.apply(null, [true]); callback.apply(null, [false]);
}
} 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", try {
items: { this.element.focus();
north: { } catch (e) {
el: { }
type: "bi.border", },
cls: "bi-message-title bi-background", cls: "bi-card",
items: { items: {
center: { north: {
el: { el: {
type: "bi.label", type: "bi.border",
cls: "bi-font-bold", cls: "bi-message-title bi-background",
text: title || i18nText("BI-Basic_Prompt"), items: {
textAlign: "left", center: {
hgap: 20, el: {
height: 40, type: "bi.label",
}, cls: "bi-font-bold",
text: title || i18nText("BI-Basic_Prompt"),
textAlign: "left",
hgap: 20,
height: 40,
}, },
east: { },
el: { east: {
type: "bi.icon_button", el: {
cls: "bi-message-close close-font", type: "bi.icon_button",
// height: 50, cls: "bi-message-close close-font",
handler() { // height: 50,
close(); handler() {
if (isFunction(callback)) { close();
callback.apply(null, [false]); if (isFunction(callback)) {
} callback.apply(null, [false]);
}, }
}, },
width: 56,
}, },
width: 56,
}, },
}, },
height: 40,
},
center: {
el: isPlainObject(message)
? message
: {
type: "bi.label",
vgap: 10,
hgap: 20,
whiteSpace: "normal",
text: message,
},
}, },
south: { height: 40,
el: { },
type: "bi.absolute", center: {
items: [ el: isPlainObject(message)
{ ? message
el: { : {
type: "bi.right_vertical_adapt", type: "bi.label",
lgap: 10, vgap: 10,
items: controlItems, hgap: 20,
}, whiteSpace: "normal",
top: 0, text: message,
left: 20,
right: 20,
bottom: 0,
}
],
}, },
height: 44, },
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, width: 450,
} height: 200,
], }
}; ],
};
messageShows[messageShows.length] = createWidget(conf); messageShows[messageShows.length] = createWidget(conf);
}, }
};

Loading…
Cancel
Save