ソースを参照

feat:工作桌面导航栏聚合搜索功能实现

yangfeng 2 年 前
コミット
2a5d911901

+ 12 - 1
apps/work-bench/config/dev-proxy.js

@@ -1,7 +1,7 @@
 // 需要代理到的开发环境地址
 const ProxyTargets = {
   开发环境: 'https://webdev-webtest.jydev.jianyu360.com',
-  测试环境: 'https://jybx2-webtest.jydev.jianyu360.com'
+  测试环境: 'https://jybx3-webtest.jydev.jianyu360.com'
 }
 const ProxyTarget = ProxyTargets['测试环境']
 
@@ -29,6 +29,9 @@ const ProxyPrefixs = [
   'antiRes',
   'images/wx/',
   'common-module',
+  'jyapi',
+  'jyMerge',
+  'commonFunctions',
   // 子应用资源代理,可实现正常访问对于环境的子应用,本地联调子应用时需移除
   'page_big_pc',
   'swordfish/page_big_pc',
@@ -42,6 +45,14 @@ const ProxyPrefixs = [
 
 // 最终代理配置
 const proxy = {
+  '/api/jyapi/jybx': {
+    target: ProxyTargets['开发环境'],
+    changeOrigin: true,
+    logLevel: 'debug',
+    pathRewrite: {
+      '^/api': ''
+    }
+  },
   '/api': {
     target: ProxyTarget,
     changeOrigin: true,

+ 9 - 0
apps/work-bench/src/api/modules/navbar.js

@@ -46,3 +46,12 @@ export function ajaxSetReadMessages (data) {
     data
   })
 }
+
+// 导航栏搜索聚合查询
+export function ajaxNavbarConvergeSearch (data) {
+  return request({
+    url: '/jyapi/jybx/core/polymerizeSearch',
+    method: 'post',
+    data
+  })
+}

+ 118 - 2
apps/work-bench/src/store/modules/work-bench.js

@@ -5,10 +5,10 @@ import {
   ajaxGetPower,
   ajaxGetUserInfo, ajaxSetClickMessages,
   ajaxSetMenuType, ajaxSetReadMessages,
-  ajaxSetSignOut
+  ajaxSetSignOut, ajaxNavbarConvergeSearch
 } from '../../api/modules'
 import { storeModules } from '@jy/work-bench-frame'
-import { clearStorage } from '@/utils'
+import { clearStorage, replaceKeyword } from '@/utils'
 
 /**
  * 搜索页面
@@ -69,8 +69,52 @@ export default {
   state: () => ({
     custom: {
       'nav-user-info': true
+    },
+    // 聚合搜索信息
+    searchInfo: {
+      ent: {
+        title: '企业列表',
+        list: [],
+        count: 0,
+        isLink: true,
+        url: '/jylab/entSearch/index.html?searchvalue=',
+        appType: 'iframe',
+        showEmpty: true
+      },
+      menu: {
+        title: '功能列表',
+        list: [],
+        isLink: false,
+        showEmpty: true
+      },
+      buyer: {
+        title: '采购单位列表',
+        list: [],
+        count: 0,
+        isLink: true,
+        url: '/jylab/purSearch/index.html?searchvalue=',
+        appType: 'iframe',
+        showEmpty: true
+      },
+      bidding: {
+        title: '查看的标讯搜索结果',
+        list: [],
+        isLink: true,
+        url: '/jylab/supsearch/index.html?keywords=',
+        appType: 'iframe',
+        showEmpty: false
+      }
     }
   }),
+  mutations: {
+    changeSearchInfo (state, data = {}) {
+      const { ent, buyer, menu, bidding } = data
+      Object.assign(state.searchInfo.ent, ent)
+      Object.assign(state.searchInfo.buyer, buyer)
+      Object.assign(state.searchInfo.menu, menu)
+      Object.assign(state.searchInfo.bidding, bidding)
+    }
+  },
   actions: {
     /**
      * 获取菜单数据源
@@ -266,12 +310,84 @@ export default {
         }
         commit('user/changeCustomerInfo', target || {})
       }
+    },
+    /**
+     * 导航栏聚合查询
+     * @param {*} param0
+     * @param {*} payload
+     */
+    async navbarConvergeSearch ({ commit }, payload) {
+      try {
+        const { searchCode } = payload
+        const bidding = {
+          title: `查看<span class="highlight-text">“${searchCode}”</span>的标讯搜索结果`
+        }
+        const { error_code: code, data = {} } = await ajaxNavbarConvergeSearch(payload)
+        if (code === 0) {
+          const { entList, procureList, menuList } = data
+          const ent = {}
+          const buyer = {}
+          const menu = {}
+          if (Object.keys(entList)?.length) {
+            ent.list = entList?.data.map(v => {
+              return {
+                ...v,
+                value: replaceKeyword(v.title, searchCode),
+                appType: 'outer',
+                openType: '_blank',
+                usable: true,
+                url: `/swordfish/page_big_pc/free/loading/ent/${v.url}`
+              }
+            })
+            ent.count = entList?.count
+          } else {
+            ent.list = []
+            ent.count = 0
+          }
+          if (Object.keys(procureList)?.length) {
+            buyer.list = procureList?.data.map(v => {
+              return {
+                ...v,
+                value: replaceKeyword(v.title, searchCode),
+                appType: 'outer',
+                openType: '_blank',
+                usable: true,
+                url: `/swordfish/page_big_pc/free/loading/buyer/${v.title}`
+              }
+            })
+            buyer.count = procureList?.count
+          } else {
+            buyer.list = []
+            buyer.count = 0
+          }
+          if (Array.isArray(menuList)) {
+            menu.list = menuList.map(v => {
+              return {
+                ...v,
+                title: v.name.replace(/<br\s*\/?>/g, ''),
+                value: replaceKeyword(v.name.replace(/<br\s*\/?>/g, ''), searchCode),
+                label: v.path.replace(/<br\s*\/?>/g, ''),
+                url: v.url
+              }
+            })
+          } else {
+            menu.list = []
+          }
+          commit('changeSearchInfo', { ent, buyer, menu, bidding })
+        }
+        // 标讯搜索纯展示,不依赖请求
+        commit('changeSearchInfo', { bidding })
+      } catch (error) {
+      }
     }
   },
   modules: storeModules,
   getters: {
     useCustomStatus (state) {
       return state.custom
+    },
+    navBarSearchInfo (state) {
+      return state.searchInfo
     }
   }
 }

+ 78 - 0
apps/work-bench/src/utils/index.js

@@ -66,3 +66,81 @@ export function checkChatIconShow (router) {
     showChatIcon(false)
   }
 }
+
+/**
+ * 通用关键字高亮替换
+ * @param {String} value 要高亮的字符串
+ * @param {String|Array} oldChar 要被替换的字符串(或数组)
+ * @param {String|Array} newChar 要替换成的字符串(或数组)
+ *
+ * 比如:要将 - `剑鱼标讯工具函数` 字符串中的 `工具` 高亮
+ * 则此时 value -> `剑鱼标讯工具函数`
+ *        oldChar -> `工具`
+ *        newChar -> `<span class="highlight-text">工具</span>`
+ *
+ * 批量高亮-----
+ * 比如:要将 - `剑鱼标讯工具函数` 字符串中的 `工具` `剑鱼` 高亮
+ * 则此时 value -> `剑鱼标讯工具函数`批量高亮
+ *        oldChar -> ['工具', '剑鱼']
+ *        newChar -> ['<span class="highlight-text">', '</span>']
+ *
+ *   注意:此时newChar为一个长度为2的数组,数组中为高亮标签的起始标签和结束标签
+ *
+ */
+export function replaceKeyword (value, oldChar, newChar = ['<span class="highlight-text">', '</span>']) {
+  if (!oldChar || !newChar) return value
+  // oldChar的字符串数组,用来循环替换
+  let oldCharArr = []
+
+  if (Array.isArray(oldChar)) {
+    oldCharArr = oldChar.concat()
+  } else {
+    oldCharArr.push(oldChar)
+  }
+
+  // 数组去重
+  oldCharArr = Array.from(new Set(oldCharArr))
+
+  try {
+    oldCharArr.forEach(function (item) {
+      // 去空格之后为空字符串,则直接跳过当前替换
+      if (item && item.replace(/\s+/g, '')) {
+        let oc = item
+        oc = oc.replace(/\$/g, '\\$')
+          .replace(/\(/g, '\\(')
+          .replace(/\)/g, '\\)')
+          .replace(/\*/g, '\\*')
+          .replace(/\+/g, '\\+')
+          .replace(/\./g, '\\.')
+          .replace(/\[/g, '\\[')
+          .replace(/\]/g, '\\]')
+          .replace(/\?/g, '\\?')
+          .replace(/\\/g, '\\')
+          .replace(/\//g, '\\/')
+          .replace(/\^/g, '\\^')
+          .replace(/\{/g, '\\{')
+          .replace(/\}/g, '\\}')
+          .replace(/\|/g, '\\|')
+
+        if (Array.isArray(newChar)) {
+          // 批量高亮
+          const tempV = value
+          value = value.replace(new RegExp('(' + oc + ')', 'gmi'), newChar[0] + oc + newChar[1])
+          if (value === tempV && oc.indexOf('+') !== -1) {
+            const splitReg = oc.split('\\+')
+            splitReg.forEach((v) => {
+              value = value.replace(new RegExp('(' + v + ')', 'gmi'), newChar[0] + v + newChar[1])
+            })
+          }
+        } else {
+          // 普通单个高亮
+          value = value.replace(new RegExp('(' + oc + ')', 'gmi'), newChar)
+        }
+      }
+    })
+  } catch (e) {
+    console.log(e)
+    return value
+  }
+  return value
+}