fix:ci relation add type filter (#208)

This commit is contained in:
wang-liang0615 2023-10-18 14:06:28 +08:00 committed by GitHub
parent 2a5091c51a
commit e0e2ca6294
1 changed files with 35 additions and 19 deletions

View File

@ -549,11 +549,11 @@ export default {
q = q.slice(1) q = q.slice(1)
} }
if (this.treeKeys.length === 0) { if (this.treeKeys.length === 0) {
await this.judgeCITypes(q)
if (!refreshType) { if (!refreshType) {
this.loadRoot() this.loadRoot()
} }
await this.judgeCITypes(q)
const fuzzySearch = (this.$refs['search'] || {}).fuzzySearch || '' const fuzzySearch = (this.$refs['search'] || {}).fuzzySearch || ''
if (fuzzySearch) { if (fuzzySearch) {
q = `q=_type:${this.currentTypeId[0]},*${fuzzySearch}*,` + q q = `q=_type:${this.currentTypeId[0]},*${fuzzySearch}*,` + q
@ -635,6 +635,7 @@ export default {
statisticsCIRelation({ statisticsCIRelation({
root_ids: key.split('%')[0], root_ids: key.split('%')[0],
level: this.treeKeys.length - index, level: this.treeKeys.length - index,
type_ids: this.showTypes.map((type) => type.id).join(','),
}).then((res) => { }).then((res) => {
let result let result
const getTreeItem = (data, id) => { const getTreeItem = (data, id) => {
@ -689,6 +690,7 @@ export default {
} }
const promises = _showTypeIds.map((typeId) => { const promises = _showTypeIds.map((typeId) => {
const _q = (`q=_type:${typeId},` + q).replace(/count=\d*/, 'count=1') const _q = (`q=_type:${typeId},` + q).replace(/count=\d*/, 'count=1')
console.log(_q)
if (this.treeKeys.length === 0) { if (this.treeKeys.length === 0) {
return searchCI2(_q).then((res) => { return searchCI2(_q).then((res) => {
if (res.numfound !== 0) { if (res.numfound !== 0) {
@ -739,7 +741,11 @@ export default {
level = idx + 1 level = idx + 1
} }
}) })
return statisticsCIRelation({ root_ids: ciIds.join(','), level: level }).then((num) => { return statisticsCIRelation({
root_ids: ciIds.join(','),
level: level,
type_ids: this.showTypes.map((type) => type.id).join(','),
}).then((num) => {
facet.forEach((item, idx) => { facet.forEach((item, idx) => {
item[1] += num[ciIds[idx] + ''] item[1] += num[ciIds[idx] + '']
}) })
@ -752,7 +758,12 @@ export default {
async loadNoRoot(rootIdAndTypeId, level) { async loadNoRoot(rootIdAndTypeId, level) {
const rootId = rootIdAndTypeId.split('%')[0] const rootId = rootIdAndTypeId.split('%')[0]
searchCIRelation(`root_id=${rootId}&level=1&count=10000`).then(async (res) => { const typeId = Number(rootIdAndTypeId.split('%')[1])
const topo_flatten = this.relationViews?.views[this.$route.meta.name]?.topo_flatten ?? []
const index = topo_flatten.findIndex((id) => id === typeId)
const _type = topo_flatten[index + 1]
if (_type) {
searchCIRelation(`q=_type:${_type}&root_id=${rootId}&level=1&count=10000`).then(async (res) => {
const facet = [] const facet = []
const ciIds = [] const ciIds = []
res.result.forEach((item) => { res.result.forEach((item) => {
@ -761,7 +772,11 @@ export default {
}) })
const promises = level.map((_level) => { const promises = level.map((_level) => {
if (_level > 1) { if (_level > 1) {
return statisticsCIRelation({ root_ids: ciIds.join(','), level: _level - 1 }).then((num) => { return statisticsCIRelation({
root_ids: ciIds.join(','),
level: _level - 1,
type_ids: this.showTypes.map((type) => type.id).join(','),
}).then((num) => {
facet.forEach((item, idx) => { facet.forEach((item, idx) => {
item[1] += num[ciIds[idx] + ''] item[1] += num[ciIds[idx] + '']
}) })
@ -771,6 +786,7 @@ export default {
await Promise.all(promises) await Promise.all(promises)
this.wrapTreeData(facet, 'loadNoRoot') this.wrapTreeData(facet, 'loadNoRoot')
}) })
}
}, },
onNodeClick(keys) { onNodeClick(keys) {