/** * 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('未找到事件方法请检查是否配置正确!'); } }, /** * 提示框 * @param content 提示内容 */ infoMsgBox : function(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){ // $.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){ // $.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){ // $.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){ // $.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样式