From 641c2abb24907cfeaa32a5f6ec2a18e3a8b3940b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AE=97=E6=B4=8B?= Date: Tue, 14 Feb 2023 10:33:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A8=E5=90=8D+schema=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E9=AB=98=E4=BA=AE=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/ops/db/component/InstanceTree.vue | 66 +++++++++++++++---- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/mayfly_go_web/src/views/ops/db/component/InstanceTree.vue b/mayfly_go_web/src/views/ops/db/component/InstanceTree.vue index cd5ced56..37d655c9 100644 --- a/mayfly_go_web/src/views/ops/db/component/InstanceTree.vue +++ b/mayfly_go_web/src/views/ops/db/component/InstanceTree.vue @@ -40,7 +40,9 @@ - {{ schema.name }} + + + @@ -77,10 +79,10 @@ - {{ tb.tableName }} + :content="tb.tableComment" placement="right" > + - {{ tb.tableName }} + @@ -228,21 +230,57 @@ const filterTableName = (instId: number, schema: string, event?: any) => { state.filterParam[key] = event.target.value } let param = state.filterParam[key] as string - param = param?.replace('/', '\/') state.tables[key].forEach((a: any) => { - a.show = param ? eval('/' + param.split('').join('[_\w]*') + '[_\w]*/ig').test(a.tableName) || eval('/' + param.split('').join('[_\w]*') + '[_\w]*/ig').test(a.tableComment) : true + let {match, showName} = matchAndHighLight(param, a.tableName+a.tableComment, a.tableName) + a.show = match; + a.showName = showName }) } const filterSchemaName = (instId: number, event?: any) => { - if (event) { - state.schemaFilterParam[instId] = event.target.value - } - let param = state.schemaFilterParam[instId] as string - param = param?.replace('/', '\/') - state.dbs[instId].forEach((a: any) => { - a.show = param ? eval('/' + param.split('').join('[_\w]*') + '[_\w]*/ig').test(a.name) : true - }) + if (event) { + state.schemaFilterParam[instId] = event.target.value + } + let param = state.schemaFilterParam[instId] as string + param = param?.replace('/', '\/') + state.dbs[instId].forEach((a: any) => { + let {match, showName} = matchAndHighLight(param, a.name, a.name) + a.show = match + a.showName = showName + }) +} + +const matchAndHighLight = (searchParam: string, param: string, title: string): {match: boolean, showName: string} => { + if(!searchParam){ + return {match: true, showName: ''} + } + let str = ''; + for(let c of searchParam?.replace('/', '\/')){ + str += `(${c}).*` + } + let regex = eval(`/${str}/i`) + let res = param.match(regex); + if(res?.length){ + if(res?.length){ + let tmp = '', showName = ''; + for(let i =1; i<=res.length-1; i++){ + let head = (tmp || title).replace(res[i], `###${res[i]}!!!`); + let idx = head.lastIndexOf('!!!')+3; + tmp = head.substring(idx); + showName += head.substring(0, idx) + if(!tmp){ + break + } + } + showName += tmp; + showName = showName.replaceAll('###','') + showName = showName.replaceAll('!!!','') + return {match: true, showName} + } + } + + return {match: false, showName: ''} + } /**