Authored by 王涛

Merge branch 'master-v32-lushangqing' into 'master'

【无】操作记录功能迁移到master



See merge request !968
@@ -8,7 +8,8 @@ layui.define(['element', 'admin'], function (exports) { @@ -8,7 +8,8 @@ layui.define(['element', 'admin'], function (exports) {
8 data: { 8 data: {
9 contextmenuTips: null, 9 contextmenuTips: null,
10 contextmenus: [], 10 contextmenus: [],
11 - classNams: [] 11 + classNams: [],
  12 + handleLog: [] //lsq 页面点击操作集
12 }, 13 },
13 getCurrentHash: function () { 14 getCurrentHash: function () {
14 return window.location.hash; 15 return window.location.hash;
@@ -16,11 +17,16 @@ layui.define(['element', 'admin'], function (exports) { @@ -16,11 +17,16 @@ layui.define(['element', 'admin'], function (exports) {
16 init: function () { 17 init: function () {
17 var that = this; 18 var that = this;
18 19
  20 + that.bindClickEvent();
  21 +
  22 + //lsq给带有title的元素绑定点击事件复制元素内容 2022-09-05
  23 + that.copyTitle();
  24 +
19 if (that.data.contextmenus.length > 0) { 25 if (that.data.contextmenus.length > 0) {
20 that.bindContextMenuEvent(); 26 that.bindContextMenuEvent();
21 return that.data.contextmenus; 27 return that.data.contextmenus;
22 } 28 }
23 - if('#/user/login/redirect=%2F' == that.getCurrentHash()){ 29 + if ('#/user/login/redirect=%2F' == that.getCurrentHash()) {
24 return; 30 return;
25 } 31 }
26 // 获取配置的信息 32 // 获取配置的信息
@@ -68,16 +74,155 @@ layui.define(['element', 'admin'], function (exports) { @@ -68,16 +74,155 @@ layui.define(['element', 'admin'], function (exports) {
68 } 74 }
69 }) 75 })
70 76
71 - setTimeout(function (){ 77 + setTimeout(function () {
72 layer.closeAll('tips'); 78 layer.closeAll('tips');
73 - },5000) 79 + }, 5000)
74 } 80 }
75 }) 81 })
76 }, 82 },
  83 + /**
  84 + * ajax掉接口之前传参
  85 + * @author lsq
  86 + * @date 2022-08-18
  87 + * */
  88 + sendAjaxData(menuPath,elementName){
  89 + let name=encodeURIComponent(elementName);
  90 + $.ajaxSetup({
  91 + headers:{
  92 + menuPath:menuPath,
  93 + elementName:name
  94 + }
  95 +
  96 + });
  97 + },
  98 + /**
  99 + * 鼠标点击事件
  100 + */
  101 + bindClickEvent(){
  102 + let that=this;
  103 + var eventKeys = ['a','button','[data-bizid]','.layui-table-link'];
  104 + // 菜单点击
  105 + if(!$('#LAY-system-side-menu li a').hasClass("on_fn")){
  106 + $('#LAY-system-side-menu li a').unbind('click.handle').on('click.handle',(function (e){
  107 + e.preventDefault();
  108 + //start lsq 元素鼠标点击事件操作 2022-08-11
  109 + //绑定事件时增加一个class防止多次绑定事件
  110 + $(this).addClass("on_fn");
  111 + // 获取当前点击的菜单 2022-08-11
  112 + if($(this).parent('li').length>0){
  113 + //如果菜单是第一级,则清空菜单数组,重新插入
  114 + that.data.handleLog=[];
  115 + }
  116 + that.pushArrNoRepeat($(this),1);
  117 + }));
  118 + }
  119 +
  120 + //lsq 给页面的元素绑定点击事件 2022-08-11
  121 + setTimeout(function(){
  122 + that.bindElemClickEvent();
  123 + },500)
  124 + },
  125 + /**
  126 + * @desc 点击元素插入数组时的处理
  127 + * @author lsq
  128 + * @date 2022-08-11
  129 + * @param thisObj 为点击的元素
  130 + * @param flg 1菜单
  131 + */
  132 + pushArrNoRepeat (thisObj,flg) {
  133 + let that=this;
  134 + // 获取当前元素名称正则表达式
  135 + var reg = sessionStorage.getItem('regular');
  136 + // 获取当前点击的元素的内容
  137 + let text=thisObj.text()?thisObj.text().trim().replace(reg, ""):'';
  138 + // 获取当前点击的元素的lay-href-type值
  139 + let menuType=thisObj.attr('lay-href-type')?thisObj.attr('lay-href-type'):'';
  140 + // 获取当前点击的菜单的路由地址
  141 + let layHref=thisObj.attr('lay-href')?thisObj.attr('lay-href'):'';
  142 + let eleObj={
  143 + text:text,
  144 + menuType:menuType,
  145 + layHref:layHref
  146 + }
  147 + //数组中无当前点击的元素时再将当前点击元素加入到数组中
  148 + let textArr=[];
  149 + that.data.handleLog.map(item=>{
  150 + textArr.push(item.text)
  151 + })
  152 + if(textArr.indexOf(text)==-1){
  153 + if(flg && !layHref){
  154 + // 如果当前点击的菜单元素没有路由地址则删除
  155 + that.data.handleLog.splice(1) ;
  156 + }
  157 + that.data.handleLog.push(eleObj)
  158 + }
  159 + //菜单点击传入属性lay-href的值,普通元素传入当前页面路由
  160 + if(flg){
  161 + that.sendAjaxData(layHref,text)
  162 +
  163 + }else{
  164 + let locationPath=location.hash;
  165 + let pathArr=locationPath.split("#/");
  166 + let path='/'
  167 + if(pathArr && pathArr.length>1){
  168 + path=pathArr[1]
  169 + }
  170 + that.sendAjaxData(path,text)
  171 +
  172 + }
  173 + },
  174 + /**
  175 + * 页面其他元素绑定事件
  176 + * @author lsq
  177 + * @date 2022-08-11
  178 + */
  179 + clickEventHandle (thisObj) {
  180 + let that=this;
  181 + //绑定事件时增加一个class防止多次绑定事件
  182 + thisObj.addClass("on_fn");
  183 + that.pushArrNoRepeat(thisObj);
  184 + // 把点击的元素按顺序展示
  185 + let handleStr='';
  186 + let menuStrArr=[];
  187 + let menuStrArrSecond=[];
  188 + that.data.handleLog.map(item=>{
  189 + if(item.menuType){
  190 + menuStrArr.push(item.text)
  191 + }else{
  192 + menuStrArrSecond.push(item.text)
  193 + }
  194 + })
  195 + if(menuStrArr.length>0){
  196 + handleStr=menuStrArr.join('->');
  197 + }
  198 + if(menuStrArrSecond.length>0){
  199 + handleStr+='->'+menuStrArrSecond.join(',');
  200 + }
  201 + },
  202 + /**
  203 + * 页面其他元素绑定事件
  204 + * @author lsq
  205 + * @date 2022-08-11
  206 + */
  207 + bindElemClickEvent() {
  208 + let that=this;
  209 + var eventKeys = ['button','[data-bizid]','.layui-table-link'];
  210 + eventKeys.map(item=>{
  211 + if(!$(item).hasClass("on_fn")){
  212 + $(item).unbind('click.handle').on('click.handle',(function (e){
  213 + e.preventDefault();
  214 + that.clickEventHandle($(this))
  215 + }))
  216 + }
  217 +
  218 + })
  219 + },
  220 + /**
  221 + * 绑定鼠标右键事件
  222 + */
77 bindContextMenuEvent() { 223 bindContextMenuEvent() {
78 var that = this; 224 var that = this;
79 var contextmenus = that.data.contextmenus; 225 var contextmenus = that.data.contextmenus;
80 -  
81 var bindContextEvent = function (selector, index) { 226 var bindContextEvent = function (selector, index) {
82 var el = $(selector); 227 var el = $(selector);
83 228
@@ -92,8 +237,25 @@ layui.define(['element', 'admin'], function (exports) { @@ -92,8 +237,25 @@ layui.define(['element', 'admin'], function (exports) {
92 }, 500) 237 }, 500)
93 return; 238 return;
94 } 239 }
  240 + if (el.length > 0) {
  241 + $(el).each(function (i, v) {
  242 + var elItem = $(v);
  243 + elItem.attr('title', '点击鼠标右键查看功能点描述信息')
  244 + setTimeout(function () {
  245 + elItem.contextmenu(function (e) {
  246 + e.preventDefault();
  247 + let thatItem = $(this);
  248 + // 获取当前元素名称正则表达式
  249 + var reg = sessionStorage.getItem('regular');
  250 + let elementName = thatItem.text().replace(reg, "");
  251 + that.getTipsDetail(elementName, thatItem);
  252 + })
  253 + }, 1000)
  254 + });
  255 + return;
  256 + }
95 257
96 - el.attr('title', '点击鼠标右键查看功能点描述信息') 258 + setTimeout(function () {
97 el.contextmenu(function (e) { 259 el.contextmenu(function (e) {
98 e.preventDefault(); 260 e.preventDefault();
99 let thatItem = $(this); 261 let thatItem = $(this);
@@ -102,37 +264,57 @@ layui.define(['element', 'admin'], function (exports) { @@ -102,37 +264,57 @@ layui.define(['element', 'admin'], function (exports) {
102 let elementName = thatItem.text().replace(reg, ""); 264 let elementName = thatItem.text().replace(reg, "");
103 that.getTipsDetail(elementName, thatItem); 265 that.getTipsDetail(elementName, thatItem);
104 }) 266 })
  267 + }, 1000)
105 } 268 }
106 269
107 // 循环绑定事件 270 // 循环绑定事件
108 - var bind = function (){ 271 + var bind = function () {
  272 + //lsq 表格数据中的元素有时绑定不了事件,加延时 2022-08-11
  273 + setTimeout(function (){
109 $(contextmenus).each(function (index) { 274 $(contextmenus).each(function (index) {
110 let val = contextmenus[index]; 275 let val = contextmenus[index];
111 -  
112 if (val.indexOf('el::') != -1) { 276 if (val.indexOf('el::') != -1) {
113 let elName = val.replace('el::', ''); 277 let elName = val.replace('el::', '');
114 bindContextEvent(elName, 0); 278 bindContextEvent(elName, 0);
115 } 279 }
116 }) 280 })
  281 + },300)
117 } 282 }
118 -  
119 // 获取当前页面,是否在配置中 283 // 获取当前页面,是否在配置中
120 var page = that.getCurrentHash(); 284 var page = that.getCurrentHash();
121 $(contextmenus).each(function (index) { 285 $(contextmenus).each(function (index) {
122 let val = contextmenus[index]; 286 let val = contextmenus[index];
123 - if (val.indexOf('page::') != -1 ) { 287 + if (val.indexOf('page::') != -1) {
124 let elName = val.replace('page::', ''); 288 let elName = val.replace('page::', '');
125 - if(elName == page){ 289 + if (elName == page) {
126 bind(); 290 bind();
127 return; 291 return;
128 } 292 }
129 } 293 }
130 }) 294 })
131 -  
132 // 点击关闭所有tips 295 // 点击关闭所有tips
133 $(document).on('click', function (event) { 296 $(document).on('click', function (event) {
134 layer.closeAll('tips'); 297 layer.closeAll('tips');
135 }) 298 })
  299 + },
  300 + /**
  301 + * lsq
  302 + * 2022-09-13
  303 + * 给带有title的元素绑定点击事件
  304 + */
  305 + copyTitle() {
  306 + $('[title]').unbind('click.title').on('click.title',(function (e){
  307 + e.preventDefault();
  308 + let oInput = document.createElement('input');
  309 + oInput.value = $(this).attr('title').trim();
  310 + document.body.appendChild(oInput);
  311 + oInput.select();
  312 + document.execCommand("Copy");
  313 + oInput.className = 'oInput';
  314 + oInput.style.display = 'none';
  315 + // layer.msg('内容复制成功', {icon: 1, time: 2000});
  316 +
  317 + }))
136 } 318 }
137 } 319 }
138 320