Skip to content

Commit

Permalink
feat: 表名+schema模糊高亮过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
刘宗洋 committed Feb 14, 2023
1 parent 3ab4ac8 commit 641c2ab
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions mayfly_go_web/src/views/ops/db/component/InstanceTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
<span class="checked-schema ml20">
<el-icon>
<Coin color="#67c23a" />
</el-icon>{{ schema.name }}</span>
</el-icon>
<span v-html="schema.showName || schema.name"></span>
</span>
</template>
<!-- 第四级 01:表 -->
<el-sub-menu :index="inst.id + schema.name + '-table'">
Expand Down Expand Up @@ -77,10 +79,10 @@
<Calendar color="#409eff" />
</el-icon>
<el-tooltip v-if="tb.tableComment" effect="customized"
:content="tb.tableComment" placement="right">
{{ tb.tableName }}
:content="tb.tableComment" placement="right" >
<span v-html="tb.showName || tb.tableName"></span>
</el-tooltip>
<span v-else>{{ tb.tableName }}</span>
<span v-else v-html="tb.showName || tb.tableName"></span>
</div>
</template>
</el-menu-item>
Expand Down Expand Up @@ -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('###','<span style="color: red">')
showName = showName.replaceAll('!!!','</span>')
return {match: true, showName}
}
}
return {match: false, showName: ''}
}
/**
Expand Down

0 comments on commit 641c2ab

Please sign in to comment.