/** * PC页面模板 */ var PCPage = { /** * 获得当前域的Cookie值 * @param cookieName cookie名称 * @returns */ setCookie : function(c_name,value,expiredays,path){ var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/programs"; }, 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; } }, /** * 退出系统 * @param url * @return */ logout : function (url){ $.messager.confirm("提示", "您确定要退出系统吗?", function(r){ if(r){ $.get(Tools.getContextUrl() +"/login/logout", function(result) { if (result.success) { if(Tools.isEmptyString(url)) { window.location = "login/doLogin"; } else { window.location = url; } } }) } else return false; }); }, /** * 列表操作按钮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 = ''; if ('children' in menus && menus.children.length) { menus.children.forEach((item) => { downMmenuItem += `
${item.text}
`; }) menuBox = `
${menus.text}
`; $("#down" + menus.id).remove(); //避免重复id追加前移除已存在的id元素 $('body').append(`
`); }else { menuBox = `
${menus.text}
`; } return menuBox }else { return `` } }, /** * 列表操作按钮点击事件(王华) * @param item */ clickListMenuButton : function(item){ let { clickevent, menu } = $(item).data(); event.stopPropagation(); if (clickevent !== 'undefined' && clickevent){ $("#down" + menu).menu('hide'); eval(clickevent); }else { PCPage.errorMsgBox('未找到事件方法请检查!') } }, /** * 提示框 * @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($("#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样式