/** * PC页面模板 */ var PCPage = { /** * 获得当前域的Cookie值 * @param cookieName cookie名称 * @returns */ setCookie : function (name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; }, getCookieValue : function(cookieName) { if (document.cookie != "") { var _thisCookie = document.cookie.split("; "); for (var i = 0; i < _thisCookie.length; i++) if (cookieName == _thisCookie[i].split("=")[0]) return _thisCookie[i].split("=")[1]; return; } }, deleteCookie : function(name) { document.cookie = name + '=; Max-Age=0; path=/'; }, /** * 退出系统 * @param url * @return */ logout : function (url){ $.messager.confirm("提示", "您确定要退出系统吗?", function(r){ if(r){ PCPage.logoutUnconfirmed(url); } else return false; }); }, logoutUnconfirmed : function (url){ $.get(Tools.getContextUrl() +"/login/logout", function(result) { if (result.success) { if(Tools.isEmptyString(url)) { top.location.href = Tools.getContextUrl() +"/login/doLogin"; } else { top.location.href = url; } } PCPage.deleteCookie("EOA_TOKEN"); }) }, /** * 列表操作按钮MenuButton模板渲染(王华) * @param menus 菜单JSON结构 * menus demo: { * id: row.rownum_, //重要参数 * text: "操作", * iconCls: "fa fa-cog", * clickFun: "alert('操作')", //如果有二级选项时该事件失效,仅一级时生效 * children: [ //二级选项菜单(可选) * { * text: "添加", * iconCls: "fa fa-plus", * clickFun: "", * }, * { * text: "删除", * iconCls: "fa fa-trash", * clickFun: "alert('"+ row.code +"删除了')", //方法传参示例 * } * ] * } */ renderMenuButton: function(menus) { if (!$.isEmptyObject(menus)) { let menuBox = ''; let downMmenuItem = ''; // 有子菜单(children)情况 if ('children' in menus && menus.children.length) { menus.children.forEach((item) => { // 注意:item.clickFun 中的引号建议使用转义或确保格式正确 downMmenuItem += `
${item.text}
`; }); menuBox = `
${menus.text}
`; // 移除旧菜单 DOM,避免重复追加 $("#down" + menus.id).remove(); // 追加下拉菜单项 $('body').append(` `); } // 无子菜单情况(注意添加 data-menu) else { menuBox = `
${menus.text}
`; } return menuBox; } else { return ``; } }, /** * 列表操作按钮点击事件(王华) * @param item */ clickListMenuButton: function(item) { const clickevent = item.attr("data-clickevent"); const menu = item.attr("data-menu"); event.stopPropagation(); if (typeof clickevent !== 'undefined' && clickevent) { // 如果存在下拉菜单则关闭 if (menu) { $("#down" + menu).menu('hide'); } try { eval(clickevent); // ⚠️ 尽量仅执行受信任内容 } catch (e) { console.error("执行菜单操作 clickFun 出错:", e); } } else { PCPage.errorMsgBox('未找到事件方法请检查是否配置正确!'); } }, /** * 提示框 * - 在 PCPage.msgBox 中自动判断移动端:屏幕宽度 <= 768px 以移动端效果展现,否则默认为 PC 端效果。 * * - 支持强制控制: * PCPage.msgBox({ * type: 'question', * title: '培训班切换', * message: '你确定要切换当前培训班吗?', * mobile: true * }); * * - 调用示例: *
info 普通提示
*
alert 自动关闭
*
warning 带回调
*
question 确认回调
*
mobile 移动端样式
*
error 错误提示
*
object 对象参数
* * @param type 提示类型:info、alert、warning、question 或 error * @param message 提示内容 * @param closeFunction 点击确定或自动关闭后的回调函数 * @param options 可选的 Swal 配置项,用于覆盖默认配置 */ msgBox : function(type, message, closeFunction, options){ var presets = { info: { title: "提示", icon: "success", showConfirmButton: true }, alert: { title: "提示", icon: "success", timer: 1000, padding: "2em", showConfirmButton: false, toast: true }, warning: { title: "警告", icon: "warning", showConfirmButton: true }, question: { title: "询问", icon: "question", showConfirmButton: true }, error: { title: "错误提示", icon: "error", showConfirmButton: true } }; // 同时支持使用对象参数调用,便于统一配置提示框。 if (typeof type === "object") { var params = type; type = params.type; message = params.message; closeFunction = params.closeFunction || params.callback; options = params.options || params; } type = String(type || "info").toLowerCase(); var swalOptions = Object.assign({}, presets[type] || presets.info, options || {}, { text: message, width: 300, timerProgressBar: true, confirmButtonText: "知道了", customClass: Object.assign({ confirmButton: "confirm-button-css", cancelButton: "cancel-button-css" }, (options && options.customClass) || {}) }); // question 类型在 PC 端和移动端都使用确定/取消双按钮布局。 if (type === "question") { swalOptions.showCancelButton = true; swalOptions.confirmButtonText = "确定"; swalOptions.cancelButtonText = "取消"; swalOptions.customClass.cancelButton = "pc-msg-question-cancel"; if (!document.getElementById("pc-msg-question-style")) { var questionStyle = document.createElement("style"); questionStyle.id = "pc-msg-question-style"; questionStyle.textContent = ".pc-msg-question-cancel{background:#fff!important;color:var(--default--color)!important;border:1px solid var(--default--color)!important;}"; document.head.appendChild(questionStyle); } } // 移动端提示框使用独立样式,不影响 PC 端样式。 var mobileOption = options && options.mobile; var isMobile = mobileOption === true || (mobileOption !== false && ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 768 )); if (isMobile && !swalOptions.toast) { if (!document.getElementById("pc-msg-mobile-style")) { var mobileStyle = document.createElement("style"); mobileStyle.id = "pc-msg-mobile-style"; mobileStyle.textContent = ".pc-msg-mobile-popup{width:calc(100% - 30px)!important;max-width:478px;padding:24px 20px 18px!important;border-radius:3px!important;}" + ".pc-msg-mobile-popup .swal2-icon{display:none!important;}" + ".pc-msg-mobile-title{display:flex!important;align-items:center;gap:10px;margin:0 0 12px!important;padding:0!important;color:#333!important;font-size:larger!important;font-weight:500!important;text-align:left!important;}" + ".pc-msg-mobile-title-icon{display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;flex:0 0 30px;border-radius:50%;background:#d00000;color:#fff;font-size:20px;font-weight:700;line-height:30px;}" + ".pc-msg-mobile-popup .swal2-html-container,.pc-msg-mobile-popup .swal2-content{margin:0!important;color:#555!important;font-size:medium!important;line-height:1.6!important;text-align:left!important;}" + ".pc-msg-mobile-popup .swal2-actions{justify-content:flex-end;width:100%;gap:14px;margin:22px 0 0!important;}" + ".pc-msg-mobile-popup .swal2-confirm,.pc-msg-mobile-popup .swal2-cancel{min-width:60px;height:36px;margin:0!important;padding:0 14px!important;border-radius:3px!important;font-size:16px!important;line-height:36px!important;}" + ".pc-msg-mobile-popup .swal2-confirm{background:#d00000!important;color:#fff!important;border:none;}" + ".pc-msg-mobile-popup .swal2-cancel{border:1px solid #d00000!important;background:#fff!important;color:#d00000!important;}"; document.head.appendChild(mobileStyle); } var mobileIcon = { info: "i", alert: "i", warning: "!", question: "?", error: "×" }[type] || "i"; var mobileTitle = String(swalOptions.title || ""); mobileTitle = mobileTitle.replace(/[&<>\"']/g, function(character) { return {"&":"&", "<":"<", ">":">", "\"":""", "'":"'"}[character]; }); swalOptions.title = "" + mobileIcon + "" + "" + mobileTitle + ""; swalOptions.width = "calc(100% - 30px)"; swalOptions.padding = "24px 20px 18px"; swalOptions.buttonsStyling = false; swalOptions.confirmButtonText = "确定"; swalOptions.customClass = Object.assign({}, swalOptions.customClass, { popup: "pc-msg-mobile-popup", title: "pc-msg-mobile-title" }); // 移动端 question 类型使用取消在左、确定在右的双按钮布局。 if (type === "question") { if (!options || typeof options.showCancelButton === "undefined") { swalOptions.showCancelButton = true; swalOptions.cancelButtonText = "取消"; } swalOptions.reverseButtons = true; } } // 保持模态提示框的键盘焦点可访问。 if (!swalOptions.toast && typeof swalOptions.didOpen === "undefined") { swalOptions.didOpen = function() { var popup = Swal.getPopup(); if (popup) { popup.setAttribute("tabindex", "-1"); popup.focus(); } }; } return Swal.fire(swalOptions).then(function(result) { var confirmed = result.isConfirmed; var timedOut = result.dismiss === Swal.DismissReason.timer; var cancelled = type === "question" && result.dismiss === Swal.DismissReason.cancel; if ((confirmed || timedOut || cancelled) && typeof closeFunction === "function") { closeFunction(result); } return result; }); }, infoMsgBox : function(message, closeFunction){ return this.msgBox("info", message, closeFunction); // $.messager.alert($.i18n.prop("pc_message_info"), message, "info", closeFunction); // Swal.fire({ // title: "提示", // text: message, // icon: 'success', // width: 300, //// timer: 1000, //// padding: '2em', // showConfirmButton: true, // timerProgressBar: true, // confirmButtonText: '知道了', // // allowOutsideClick: true, //如果使用了toast参数后不要再使用allowOutsideClick参数 // customClass: { // confirmButton: 'confirm-button-css', // 自定义确定按钮 CSS 类名 // cancelButton: 'cancel-button-css' // 自定义取消按钮 CSS 类名 // } // }).then((result) => { // if (result.dismiss === Swal.DismissReason.timer) { // closeFunction && closeFunction(); // } // }); }, /** * 提示框 * @param content 提示内容 */ alertMsgBox : function(message, closeFunction){ return this.msgBox("alert", message, closeFunction); // $.messager.alert($.i18n.prop("pc_message_info"), message, "info", closeFunction); // Swal.fire({ // title: "提示", // text: message, // icon: 'success', // width: 300, // timer: 1000, // padding: '2em', // showConfirmButton: false, // timerProgressBar: true, // toast: true, // // allowOutsideClick: true, //如果使用了toast参数后不要再使用allowOutsideClick参数 // customClass: { // confirmButton: 'confirm-button-css', // 自定义确定按钮 CSS 类名 // cancelButton: 'cancel-button-css' // 自定义取消按钮 CSS 类名 // } // }).then((result) => { // if (result.dismiss === Swal.DismissReason.timer) { // closeFunction && closeFunction(); // } // }); }, warningMsgBox : function(message, closeFunction){ return this.msgBox("warning", message, closeFunction); // $.messager.alert($.i18n.prop("pc_message_warning"), ""+ message +"", "warning", closeFunction); // Swal.fire({ // title: "警告", // text: message, // icon: 'warning', // width: 300, // showConfirmButton: true, // timerProgressBar: true, // confirmButtonText: '知道了', // didOpen: () => { // // 将焦点从确认按钮移动到弹出框的其他元素上 // const popup = Swal.getPopup(); // popup.setAttribute('tabindex', '-1'); // popup.focus(); // }, // customClass: { // confirmButton: 'confirm-button-css', // 自定义确定按钮 CSS 类名 // cancelButton: 'cancel-button-css' // 自定义取消按钮 CSS 类名 // } // }).then((result) => { // if (result.isConfirmed) { // closeFunction && closeFunction(); // } // }); }, questionMsgBox : function(message, closeFunction){ return this.msgBox("question", message, closeFunction); // $.messager.alert($.i18n.prop("pc_message_question"), message, "question", closeFunction); // Swal.fire({ // title: "询问", // text: message, // icon: 'question', // width: 300, // showConfirmButton: true, // timerProgressBar: true, // confirmButtonText: '知道了', // didOpen: () => { // // 将焦点从确认按钮移动到弹出框的其他元素上 // const popup = Swal.getPopup(); // popup.setAttribute('tabindex', '-1'); // popup.focus(); // }, // customClass: { // confirmButton: 'confirm-button-css', // 自定义确定按钮 CSS 类名 // cancelButton: 'cancel-button-css' // 自定义取消按钮 CSS 类名 // } // }).then((result) => { // if (result.isConfirmed) { // closeFunction && closeFunction(); // } // }); }, errorMsgBox : function(message, closeFunction){ return this.msgBox("error", message, closeFunction); // $.messager.alert($.i18n.prop("pc_message_error"), message, "error", closeFunction); // Swal.fire({ // title: "错误提示", // text: message, // icon: 'error', // width: 300, //// padding: '2em', // showConfirmButton: true, // timerProgressBar: true, // confirmButtonText: '知道了', //// focusConfirm: false, //// toast: true // didOpen: () => { // // 将焦点从确认按钮移动到弹出框的其他元素上 // const popup = Swal.getPopup(); // popup.setAttribute('tabindex', '-1'); // popup.focus(); // }, // customClass: { // confirmButton: 'confirm-button-css', // 自定义确定按钮 CSS 类名 // cancelButton: 'cancel-button-css' // 自定义取消按钮 CSS 类名 // } // }).then((result) => { // if (result.isConfirmed) { // closeFunction && closeFunction(); // } // }); }, /** * 获得页面JSON参数 */ getPageJSONParams : function(){ if(Tools.isEmptyString($("#page_Params").html())){ return {}; } else { return eval("("+ $("#page_Params").html() +")"); } }, /** * 直接关闭编辑表单 * @param formid 打开窗口的ID,只关闭当前窗口时可以不传ID值 */ closeForm : function(){ if (Tools.getUrlQueryString("opentype") == "tab") PCPage.closePortalTab(); else if(Tools.getUrlQueryString("opentype") == "win") { var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) { window.location.replace("about:blank"); } else { window.opener = null; window.open("", "_self"); window.close(); } } else { top.isExecFormCloseFunc = false; top.$(".panel-tool-close").last().click(); top.$('.panel-tool-close').last().remove(); } }, /** * 保存并关闭编辑表单,关闭后同时刷新所在列表 * @param formid 打开窗口的ID,只关闭当前窗口时可以不传ID值 */ closeSaveForm : function(formid){ if (Tools.getUrlQueryString("opentype") == "tab") PCPage.closePortalTab(); else { top.isExecFormCloseFunc = true; top.$(".panel-tool-close").last().click(); top.$('.panel-tool-close').last().remove(); } }, /* 带有排序的表单 重置功能。 如果是新建表单,重置后排序选项恢复到“保持不变”状态。 如果是编辑表单,重置后排序选项恢复到“移至最后”状态。 */ resetForm : function() { $("form:first")[0].reset(); if (typeof ($("input[name='Sequence']")) != "undefined") { $.each($("input[name='Sequence']"), function() { if ($(this).val() == "3") { $(this).attr("checked", "checked"); } }); $("#ForSequ").hide(); } }, /* 初始化排序 */ initSequenceNumber : function(){ $.each($("input[name='Sequence']"),function(){ if($(this).val() =="3") { $(this).attr("checked","checked"); } }); $("#ForSequID").val(""); $("#ForSequName").val(""); }, /* 点击排序选项 */ clickSequence : function(selItemObj){ if (selItemObj.val()=="1" || selItemObj.val()=="3"){ $("#ForSequID").val(""); $("#ForSequName").val(""); $("#ForSequ").hide(); } else if(selItemObj.val()=="2"){ $("#ForSequ").show(); } }, /** * 为EUI中的Datebox控件赋值当前日期。 * @returns {String} */ getCurrentDateForDatebox : function() { var _currtime = new Date(); var _strDate = _currtime.getFullYear()+"-"; _strDate += _currtime.getMonth()+1+"-"; _strDate += _currtime.getDate(); return _strDate; }, /** * 在页面标签中新增css样式