Ver Fonte

搜索增加突出显示

hejq há 7 anos atrás
pai
commit
85e1d815e6

+ 4 - 0
src/main/webapp/resources/css/common.css

@@ -126,4 +126,8 @@ footer a:focus, footer a:hover {
 .qrcode-text {
 	padding: 32px 0 0 20px;
 	font-size: 12px;
+}
+
+.highlight {
+	color: red;
 }

+ 6 - 4
src/main/webapp/resources/js/account/enterprise.js

@@ -94,6 +94,8 @@ function getEnterpriseList(count, page, keyword) {
  * @returns {Element}
  */
 function getDataRow(en, i) {
+    var keyword = $('#keyword').val();
+
     var row = document.createElement('tr'); //创建行
     row.id = "link_b2b_" + i;
     row.class = "redirect_b2b";
@@ -105,18 +107,18 @@ function getDataRow(en, i) {
 
     var uuCell = document.createElement('td'); //UU
     uuCell.setAttribute("class", "text-center");
-    uuCell.innerHTML = en.uu; //填充数据
+    uuCell.innerHTML = highLightKeywords(en.uu, keyword, null); //填充数据
     row.appendChild(uuCell);
 
     var nameCell = document.createElement('td'); //企业名称
     nameCell.setAttribute("class", "text-center");
-    nameCell.innerHTML = en.enName; //填充数据
+    nameCell.innerHTML = highLightKeywords(en.enName, keyword, null); //填充数据
     row.appendChild(nameCell);
 
     var addressCell = document.createElement('td'); //企业地址
     addressCell.setAttribute("class", "text-center");
     if (en.enAddress != null) {
-        addressCell.innerHTML = en.enAddress; //填充数据
+        addressCell.innerHTML = highLightKeywords(en.enAddress, keyword, null); //填充数据
     } else {
         addressCell.innerHTML = '-';
     }
@@ -124,7 +126,7 @@ function getDataRow(en, i) {
 
     var busiCodeCell = document.createElement('td'); //营业执照
     busiCodeCell.setAttribute("class", "text-center");
-    busiCodeCell.innerHTML = en.enBussinessCode; //填充数据
+    busiCodeCell.innerHTML = highLightKeywords(en.enBussinessCode, keyword, null); //填充数据
     row.appendChild(busiCodeCell);
 
     var dateCell = document.createElement('td'); //注册日期

+ 66 - 0
src/main/webapp/resources/js/common/base.js

@@ -57,3 +57,69 @@ function syntaxHighlight(json) {
         return '<span class="' + cls + '">' + match + '</span>';
     });
 }
+
+// 数字正则式
+ var numReg = /-?[1-9]\d*/;
+
+/**
+ * 高亮关键字 text =>内容  words:关键词   tag 被包裹的标签
+ * <pre>
+ *     匹配每一个关键字字符
+ * </pre>
+ * @param text
+ * @param words
+ * @param tag
+ * @returns {*}
+ */
+function highlight(text, words, tag) {
+    // 默认的标签,如果没有指定,使用span
+    tag = tag || 'span';
+    if (numReg.test(text)) {
+        text = text.toString();
+    }
+    var i, len = words.length, re;
+
+    for (i = 0; i < len; i++) {
+        // 正则匹配所有的文本
+        re = new RegExp(words[i], 'g');
+        if (re.test(text)) {
+            text = text.replace(re, '<'+ tag +' class="highlight">$&</'+ tag +'>');
+        }
+    }
+    return text;
+}
+
+/**
+ * 匹配整个关键词 不拆分
+ *
+ * @param text
+ * @param words
+ * @param tag
+ * @returns {*}
+ */
+function highLightKeywords(text, words, tag) {
+    // 默认的标签,如果没有指定,使用span
+    tag = tag || 'span';
+
+    if (numReg.test(text)) {
+        text = text.toString();
+    }
+
+    var i, len = words.length, re;
+
+    //匹配每一个特殊字符 ,进行转义
+    var specialStr = ["*", ".", "?", "+", "$", "^", "[", "]", "{", "}", "|", "\\", "(", ")", "/", "%"];
+    $.each(specialStr, function(i, item) {
+        if(words.indexOf(item) != -1) {
+            words = words.replace(new RegExp("\\" + item, 'g'), "\\" + item);
+        }
+    });
+
+    //匹配整个关键词
+    re = new RegExp(words, 'g');
+
+    if (re.test(text)) {
+        text = text.replace(re, '<' + tag + ' class="highlight">$&</' + tag + '>');
+    }
+    return text;
+}

+ 7 - 4
src/main/webapp/resources/js/common/invite.js

@@ -167,6 +167,9 @@ $('#export').click(function () {
  * @returns {Element}
  */
 function getDataRow(invite, i) {
+
+    var keyword = $('#keyword').val();
+
     //创建行
     var row = document.createElement('tr');
 
@@ -179,13 +182,13 @@ function getDataRow(invite, i) {
     // 邀请企业名称
     var inviteEnNameCell = document.createElement('td');
     inviteEnNameCell.setAttribute("class", "text-center");
-    inviteEnNameCell.innerHTML = invite.inviteEnName || '-';
+    inviteEnNameCell.innerHTML = highLightKeywords(invite.inviteEnName, keyword, null) || '-';
     row.appendChild(inviteEnNameCell);
 
     // 邀请用户名称
     var inviteUserNameCell = document.createElement('td');
     inviteUserNameCell.setAttribute("class", "text-center");
-    inviteUserNameCell.innerHTML = invite.inviteUserName || '-';
+    inviteUserNameCell.innerHTML = highLightKeywords(invite.inviteUserName, keyword, null) || '-';
     row.appendChild(inviteUserNameCell);
 
     // 邀请人联系方式
@@ -197,7 +200,7 @@ function getDataRow(invite, i) {
     // 注册企业名称
     var enNameCell = document.createElement('td');
     enNameCell.setAttribute("class", "text-center");
-    enNameCell.innerHTML = invite.enName;
+    enNameCell.innerHTML = highLightKeywords(invite.enName, keyword, null);
     row.appendChild(enNameCell);
 
     // 注册时间
@@ -209,7 +212,7 @@ function getDataRow(invite, i) {
     // 联系人
     var adminNameCell = document.createElement('td'); //detail
     adminNameCell.setAttribute("class", "text-center");
-    adminNameCell.innerHTML = invite.adminName || '-';
+    adminNameCell.innerHTML = highLightKeywords(invite.adminName, keyword, null) || '-';
     row.appendChild(adminNameCell);
 
     // 物料数

+ 4 - 2
src/main/webapp/resources/js/common/log.js

@@ -158,6 +158,8 @@ function getNotExistData(uuid, msg, name) {
  * @returns {Element}
  */
 function getDataRow(log, i) {
+    var keyword = $('#keyword').val();
+
     var row = document.createElement('tr'); //创建行
 
     var indexCell = document.createElement('td'); //序号
@@ -172,12 +174,12 @@ function getDataRow(log, i) {
 
     var uuCell = document.createElement('td'); //enUU
     uuCell.setAttribute("class", "text-center");
-    uuCell.innerHTML = log.enUU; //填充数据
+    uuCell.innerHTML = highLightKeywords(log.enUU, keyword, null); //填充数据
     row.appendChild(uuCell);
 
     var nameCell = document.createElement('td'); //enName
     nameCell.setAttribute("class", "text-center");
-    nameCell.innerHTML = log.enName; //填充数据
+    nameCell.innerHTML = highLightKeywords(log.enName, keyword, null); //填充数据
     row.appendChild(nameCell);
 
     var urlCell = document.createElement('td'); //enName

+ 5 - 2
src/main/webapp/resources/js/common/schedular.js

@@ -177,6 +177,9 @@ $('#okay').click(function () {
  * @returns {Element}
  */
 function getDataRow(schedular, i) {
+
+    var keyword = $('#keyword').val();
+
     var row = document.createElement('tr'); //创建行
 
     var indexCell = document.createElement('td'); //序号
@@ -186,12 +189,12 @@ function getDataRow(schedular, i) {
 
     var nameCell = document.createElement('td'); //enName
     nameCell.setAttribute("class", "text-center");
-    nameCell.innerHTML = schedular.name; //填充数据
+    nameCell.innerHTML = highLightKeywords(schedular.name, keyword, null); //填充数据
     row.appendChild(nameCell);
 
     var urlCell = document.createElement('td'); //访问路径
     urlCell.setAttribute("class", "text-center");
-    urlCell.innerHTML = schedular.url;
+    urlCell.innerHTML = highLightKeywords(schedular.url, keyword, null);
     urlCell.setAttribute("id", "link_schedular_" + schedular.id);
     row.appendChild(urlCell);