This commit is contained in:
zhangyu
2022-01-26 18:34:51 +08:00
7 changed files with 74 additions and 42 deletions

View File

@@ -54,6 +54,7 @@
font-size: 20px;
color: #333;
padding: 0;
border-bottom: none;
}
.chart-header__title {
max-width: calc(100% - 100px);

View File

@@ -81,15 +81,19 @@
.search__history {
position: absolute;
display: flex;
padding: 10px 0;
padding: 10px 0 0 0;
flex-direction: column;
width: 100%;
max-width: 1000px;
z-index: 2;
top: 47px;
border: 1px solid rgba(206,206,206,0.20);
border-radius: 2px;
background-color: white;
.history__items {
max-height: 300px;
overflow: auto;
.history__item {
height: 35px;
display: flex;
@@ -97,6 +101,7 @@
padding-left: 30px;
font-weight: normal;
font-size: 14px;
flex-shrink: 0;
&.clear-all span {
cursor: pointer;
@@ -117,15 +122,26 @@
color: #444;
}
}
.history__item:not(.clear-all) {
.history__item {
cursor: pointer;
}
.history__item:hover:not(.clear-all) {
.history__item:hover {
background-color: #ecf5ff;
color: #66b1ff;
}
.history__item.clear-all {
}
.clear-all {
padding-left: 30px;
font-weight: normal;
font-size: 14px;
height: 35px;
display: flex;
align-items: center;
color: #3976CB;
span {
cursor: pointer;
}
}
}
}

View File

@@ -66,6 +66,9 @@ export default {
this.$emit('search')
}
},
focus () {
this.codeMirror.focus()
},
changeMode () {
const originalSql = this.codeMirror.getValue()
const parser = new SqlParser(originalSql, this.columnList)

View File

@@ -190,13 +190,13 @@ export default class SqlParser extends SqlParserVisitor {
// 字段或值
visitExpressionAtomPredicate (ctx) {
const constant = ctx.getText().toLowerCase()
const constant = ctx.getText()
this.buildMeta('expression', constant)
}
// 操作符
visitComparisonOperator (ctx) {
const comparisonOperator = ctx.getText().toLowerCase()
const comparisonOperator = ctx.getText()
this.buildMeta('operator', comparisonOperator)
}
@@ -208,13 +208,13 @@ export default class SqlParser extends SqlParserVisitor {
// in语句
visitInPredicate (ctx) {
const inPredicate = ctx.getText().toLowerCase()
const inPredicate = ctx.getText()
this.buildMeta('in', inPredicate)
}
// like语句
visitLikePredicate (ctx) {
const likePredicate = ctx.getText().toLowerCase()
const likePredicate = ctx.getText()
this.buildMeta('like', likePredicate)
}
}

View File

@@ -213,6 +213,8 @@ export default {
if (chartParams && chartParams.dataKey) {
if (response.data.result && (response.data.result[chartParams.dataKey] || response.data.result[chartParams.dataKey] === 0)) {
this.chartData = response.data.result[chartParams.dataKey]
} else {
this.chartData = null
}
}
}

View File

@@ -452,7 +452,7 @@ export default {
const entityTypeMeta = metaList.find(meta => {
return meta.column && meta.column.name === 'entity_type'
})
if (entityTypeMeta) {
if (entityTypeMeta && entityTypeMeta.operator.value === '=') {
let entityType = ''
this.limitFilterType = false
if (entityTypeMeta.value.value === "'ip'") {

View File

@@ -28,11 +28,13 @@
</div>
<transition name="el-zoom-in-top">
<div class="search__history" v-show="showHistory" v-ele-click-outside="esc">
<div class="history__items">
<div class="history__item" v-for="(h, i) in history" :key="i" @click="selectHistory(h.sql)">
<span class="item-date">{{h.date}}</span>
<div class="item-value" :title="h.sql">{{h.sql}}</div>
</div>
<div class="history__item clear-all">
</div>
<div class="clear-all">
<span @click="clearHistory" v-if="!$_.isEmpty(history)">{{$t('overall.clear')}}</span>
<div v-else>暂无记录</div>
</div>
@@ -196,7 +198,7 @@ export default {
methods: {
search (metaList, formatSql) {
let sql = formatSql
if (metaList) {
if (metaList && this.$_.isArray(metaList)) {
// 全文搜索处理
const hasFullText = metaList.some(meta => {
return meta.column && meta.column.type === columnType.fullText
@@ -207,7 +209,7 @@ export default {
}
}
this.$emit('search', metaList, sql)
// 加入搜索记录
// 加入搜索记录将记录数量控制在30以内
if (sql) {
const oldHistory = localStorage.getItem(storageKey.entitySearchHistory)
let arr = []
@@ -216,6 +218,9 @@ export default {
const oldArr = JSON.parse(oldHistory)
oldArr.unshift(newItem)
arr = [...oldArr]
if (arr.length > 30) {
arr = arr.slice(0, 30)
}
} else {
arr.push(newItem)
}
@@ -228,6 +233,11 @@ export default {
selectHistory (sql) {
this.$refs.search.setSql(sql)
this.showHistory = false
this.$nextTick(() => {
if (this.$refs.search.$refs.textMode) {
this.$refs.search.$refs.textMode.focus()
}
})
},
clearHistory () {
localStorage.setItem(storageKey.entitySearchHistory, '')