CN-574 feat: 搜索组件重新实现
This commit is contained in:
@@ -154,6 +154,7 @@ import { get } from '@/utils/http'
|
||||
import { api } from '@/utils/api'
|
||||
import { getNowTime, getSecond } from '@/utils/date-util'
|
||||
import { ref } from 'vue'
|
||||
import _ from 'lodash'
|
||||
import Pagination from '@/components/common/Pagination'
|
||||
import Loading from '@/components/common/Loading'
|
||||
|
||||
@@ -403,13 +404,13 @@ export default {
|
||||
]
|
||||
let result = sql
|
||||
columns.forEach(c => {
|
||||
result = this.$_.replace(result, c.original, c.target)
|
||||
result = _.replace(result, c.original, c.target)
|
||||
})
|
||||
return result
|
||||
},
|
||||
search (metaList, formatSql) {
|
||||
if (formatSql) {
|
||||
this.q = this.specialColumnHandle(formatSql)
|
||||
search ({ q, metaList }) {
|
||||
if (q) {
|
||||
this.q = this.specialColumnHandle(q)
|
||||
this.metaList = metaList
|
||||
} else {
|
||||
this.q = ''
|
||||
@@ -425,7 +426,7 @@ export default {
|
||||
this.pageObj.resetPageNo = true
|
||||
}
|
||||
// 带参数时,只查询对应类型的entity;不带参数时,3种entity都查
|
||||
if (formatSql) {
|
||||
if (q) {
|
||||
// entity_type处理,不查其他两种entity_type对应的左侧筛选
|
||||
const entityTypeMeta = metaList.find(meta => {
|
||||
return meta.column && meta.column.name === 'entity_type'
|
||||
@@ -470,12 +471,12 @@ export default {
|
||||
},
|
||||
pageSize (val) {
|
||||
this.pageObj.pageSize = val
|
||||
this.search(this.metaList, this.q)
|
||||
this.search({ metaList: this.metaList, q: this.q })
|
||||
},
|
||||
pageNo (val) {
|
||||
this.pageObj.pageNo = val
|
||||
this.pageObj.resetPageNo = false
|
||||
this.search(this.metaList, this.q)
|
||||
this.search({ metaList: this.metaList, q: this.q })
|
||||
},
|
||||
// 点击上一页箭头
|
||||
prev () {
|
||||
@@ -698,7 +699,7 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
timeFilter (n) {
|
||||
this.search(this.metaList, this.q)
|
||||
this.search({ metaList: this.metaList, q: this.q })
|
||||
}
|
||||
},
|
||||
setup () {
|
||||
|
||||
@@ -62,14 +62,6 @@ export default {
|
||||
custom: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
totalCount2 () {
|
||||
return function (row) {
|
||||
console.info(this.totalCount, row, (this.totalCount === 0 ? 0 : parseFloat(row.count / this.totalCount) * 100).toFixed(2))
|
||||
return (this.totalCount === 0 ? 0 : parseFloat(row.count / this.totalCount) * 100).toFixed(2)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
indexMethod (index) {
|
||||
return index + 1
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
<transition name="el-zoom-in-top">
|
||||
<div class="search__history" v-show="showHistory">
|
||||
<div class="history__items">
|
||||
<div class="history__item" v-for="(h, i) in history" :key="i" @click="selectHistory(h.sql)">
|
||||
<div class="history__item" v-for="(h, i) in history" :key="i" @click="selectHistory(h.str)">
|
||||
<span class="item-date">{{h.date}}</span>
|
||||
<div class="item-value" :title="h.sql">{{h.sql}}</div>
|
||||
<div class="item-value" :title="h.str">{{h.str}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear-all">
|
||||
@@ -47,8 +47,7 @@
|
||||
|
||||
<script>
|
||||
import AdvancedSearch from '@/components/advancedSearch/Index'
|
||||
import { columnType } from '@/components/advancedSearch/meta/meta'
|
||||
import SqlParser from '@/components/advancedSearch/meta/sql-parser'
|
||||
import _ from 'lodash'
|
||||
import { storageKey } from '@/utils/constants'
|
||||
export default {
|
||||
name: 'CnSearch',
|
||||
@@ -256,14 +255,13 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search (metaList, formatSql) {
|
||||
let sql = formatSql
|
||||
// 加入搜索记录,将记录数量控制在30以内
|
||||
if (sql) {
|
||||
search ({ str, q, metaList }) {
|
||||
if (str) {
|
||||
// 加入搜索记录,将记录数量控制在30以内
|
||||
const oldHistory = localStorage.getItem(storageKey.entitySearchHistory)
|
||||
let arr = []
|
||||
const newItem = { sql, date: this.dateFormatByAppearance(new Date()) }
|
||||
if (!this.$_.isEmpty(oldHistory)) {
|
||||
const newItem = { str, date: this.dateFormatByAppearance(new Date()) }
|
||||
if (!_.isEmpty(oldHistory)) {
|
||||
const oldArr = JSON.parse(oldHistory)
|
||||
oldArr.unshift(newItem)
|
||||
arr = [...oldArr]
|
||||
@@ -275,23 +273,13 @@ export default {
|
||||
}
|
||||
localStorage.setItem(storageKey.entitySearchHistory, JSON.stringify(arr))
|
||||
}
|
||||
// 全文搜索处理
|
||||
if (metaList && this.$_.isArray(metaList)) {
|
||||
const hasFullText = metaList.some(meta => {
|
||||
return meta.column && meta.column.type === columnType.fullText
|
||||
})
|
||||
if (hasFullText) {
|
||||
const parser = new SqlParser(metaList, this.columnList)
|
||||
sql = parser.parseMetaToSql(metaList, true)
|
||||
}
|
||||
}
|
||||
this.$emit('search', metaList, sql)
|
||||
this.$emit('search', { q, metaList })
|
||||
},
|
||||
addParams (params) {
|
||||
this.$refs.search.addParams(params)
|
||||
},
|
||||
selectHistory (sql) {
|
||||
this.$refs.search.setSql(sql)
|
||||
selectHistory (str) {
|
||||
this.$refs.search.setStr(str)
|
||||
this.showHistory = false
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.search.$refs.textMode) {
|
||||
@@ -307,7 +295,7 @@ export default {
|
||||
this.showHistory = !this.showHistory
|
||||
if (this.showHistory) {
|
||||
const history = localStorage.getItem(storageKey.entitySearchHistory)
|
||||
if (!this.$_.isEmpty(history)) {
|
||||
if (!_.isEmpty(history)) {
|
||||
this.history = JSON.parse(history)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user