This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/detailView/detailViewTopSearch.vue

307 lines
11 KiB
Vue
Raw Normal View History

2021-10-12 16:53:59 +08:00
<template>
<div style="line-height: 32px;">
2021-10-18 17:40:21 +08:00
<div class="search-detail-box" :class="[selectValue[item.key].length?'select-dropdown':'',detailSearchListCopy[key].dropShow?'show-my-dropdpwn':'']" v-for="(item,key) in detailSearchListCopy" :key='key' v-show="item.children.length">
<span v-if="item.type === 'checkBox'">
2021-10-12 16:53:59 +08:00
<el-dropdown
2021-10-18 17:40:21 +08:00
:placement="'bottom-start'"
class="detail-dropdown"
2021-10-12 16:53:59 +08:00
type="primary"
:trigger="'click'"
:hide-on-click="false"
2021-10-14 14:14:25 +08:00
@visible-change="(val)=>{showDropDown(val, key)}"
2021-10-12 16:53:59 +08:00
>
2021-10-18 17:40:21 +08:00
<div style="padding-left: 10px;">
<span class="search-detail-title" v-if="!selectValue[item.key].length">{{item.label}} :</span>
<div class="detail-top-search" v-if="selectValue[item.key].length">
<span v-for="(item2,index2) in selectValue[item.key]" :key="item2" class="search-value">
{{item.oldChildren.find(dc=>dc.id==item2).name}}<span v-if="index2+1 !== selectValue[item.key].length">,</span>
2021-10-12 16:53:59 +08:00
</span>
</div>
<div class="detail-top-search" style="text-align: center" v-else>
All
</div>
2021-10-12 16:53:59 +08:00
<i class="nz-icon nz-icon-arrow-down search-value"/>
</div>
<el-dropdown-menu slot="dropdown" class="right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown">
<div style="text-align: center;"><el-input style="width: calc(100% - 40px)" size="small" v-model="searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search"/></div>
<el-checkbox-group v-model="selectValue[item.key]">
2021-10-12 16:53:59 +08:00
<el-dropdown-item v-for="(item3,index3) in item.children" :key="index3" :title="item3.name">
<el-checkbox :label="item3.id">{{item3.name}}</el-checkbox>
</el-dropdown-item>
</el-checkbox-group>
</el-dropdown-menu>
</el-dropdown>
</span>
<span v-else-if="item.type === 'dropdownCheckBox'&& key !== 'assetLabel' && key !== 'state'">
<el-dropdown
2021-10-18 17:40:21 +08:00
:placement="'bottom-start'"
class="detail-dropdown"
type="primary"
:trigger="'click'"
:hide-on-click="false"
@visible-change="searchStr = detailSearchListCopy[key].searchStr"
>
2021-10-18 17:40:21 +08:00
<div style="padding-left: 10px;">
<span class="search-detail-title" v-if="!selectValue[item.key].length">{{item.label}} :</span>
<div class="detail-top-search" v-if="selectValue[item.key].length">
<span v-for="(item2,index2) in selectValue[item.key]" :key="item2" class="search-value">
{{getSearchStr(item.oldChildren,item2)}}<span v-if="index2+1 !== selectValue[item.key].length">,</span>
</span>
</div>
<div class="detail-top-search" style="text-align: center" v-else>
All
</div>
<i class="nz-icon nz-icon-arrow-down search-value"/>
</div>
<el-dropdown-menu slot="dropdown" class="right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown">
<div style="text-align: center;"><el-input style="width: calc(100% - 40px)" size="small" v-model="searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search"/></div>
<el-checkbox-group v-model="selectValue[item.key]">
<el-dropdown-item v-for="(item3,index3) in item.children" :key="index3" >
2021-10-15 10:22:02 +08:00
<!-- <span :title="item3.name" class="children-title-name"> {{item3.name}}</span>-->
<el-checkbox :label="item3.id+'-'+item4.id" :key="index4" v-for="(item4,index4) in item3.children" :title="item3.name+'/'+item4.name">{{item3.name+'/'+item4.name}}</el-checkbox>
</el-dropdown-item>
</el-checkbox-group>
</el-dropdown-menu>
</el-dropdown>
</span>
<span v-else-if="item.type === 'dropdownCheckBox'&& (key === 'assetLabel' || key === 'state')">
2021-10-15 15:59:46 +08:00
<el-dropdown
2021-10-18 17:40:21 +08:00
:placement="'bottom-start'"
2021-10-15 15:59:46 +08:00
class="detail-dropdown"
type="primary"
:trigger="'click'"
:hide-on-click="false"
@visible-change="searchStr = detailSearchListCopy[key].searchStr"
>
2021-10-18 17:40:21 +08:00
<div style="padding-left: 10px;">
<span class="search-detail-title" v-if="!selectValue[item.key].length">{{item.label}} :</span>
2021-10-15 15:59:46 +08:00
<div class="detail-top-search" v-if="selectValue[item.key].length">
<span v-for="(item2,index2) in selectValue[item.key]" :key="item2" class="search-value">
{{getSearchStr(item.oldChildren,item2,key)}}<span v-if="index2+1 !== selectValue[item.key].length">,</span>
</span>
</div>
<div class="detail-top-search" style="text-align: center" v-else>
All
</div>
<i class="nz-icon nz-icon-arrow-down search-value"/>
</div>
<el-dropdown-menu slot="dropdown" class="right-public-box-select-top right-public-box-dropdown-top detail-top-search-dropdown">
2021-10-15 15:59:46 +08:00
<div style="text-align: center;"><el-input style="width: calc(100% - 40px)" size="small" v-model="searchStr" @input="(val)=>{searchStrChange(val,key)}" suffix-icon="el-icon-search"/></div>
<el-checkbox-group v-model="selectValue[item.key]">
<el-dropdown-item v-for="(item3,index3) in item.children" :key="index3" >
<span :title="item3.name" class="children-title-name"> {{item3.name}}</span>
<el-checkbox :label="item3.id+'-'+item4.id" :key="index4" v-for="(item4,index4) in item3.children" :title="item4.name" :a="item3.id+'-'+item4.id">{{item4.name}}</el-checkbox>
2021-10-15 15:59:46 +08:00
</el-dropdown-item>
</el-checkbox-group>
</el-dropdown-menu>
</el-dropdown>
</span>
2021-10-12 16:53:59 +08:00
</div>
</div>
</template>
<script>
export default {
name: 'detailViewTopSearch',
props: {
detailSearchList: {
/*
* project: {
label: 'Project', // 显示的label
key: 'projectIds', // 搜索使用的key
type: 'checkBox', // 类型
children: [] // 需要展示的子集
showMore: false, // 是否需要显示更多
index: 最大宽度的个数, // 是否需要显示更多
},
* */
type: Object,
default () {
return {
project: {
label: 'Project', // 显示的label
key: 'projectIds', // 搜索使用的key
type: 'checkBox', // 类型
children: [], // 需要展示的子集
show: false,
showMore: false,
index: 10 // 是否需要显示更多
}
}
}
},
selectValue: {
2021-10-12 16:53:59 +08:00
type: Object
}
},
computed: {
},
2021-10-12 16:53:59 +08:00
data () {
return {
detailSearchListCopy: {},
searchStr: ''
}
},
methods: {
searchStrChange (val, key) {
if (this.detailSearchListCopy[key].type === 'checkBox') {
this.detailSearchListCopy[key].searchStr = val
this.detailSearchListCopy[key].children = this.detailSearchListCopy[key].oldChildren.filter(children => children.name.indexOf(val) !== -1)
} else {
this.detailSearchListCopy[key].searchStr = val
const arr = []
this.detailSearchListCopy[key].oldChildren.forEach(item => {
const children = item.children.filter(children => children.name.indexOf(val) !== -1)
if (children && children.length) {
arr.push({ ...item, children: children })
}
})
this.detailSearchListCopy[key].children = arr
}
},
2021-10-15 15:59:46 +08:00
getSearchStr (oldChildren, label, key) {
const arr = label.split('-')
const obj = oldChildren.find(item => item.id == arr[0])
const children = obj.children.find(item => item.id == arr[1])
2021-10-15 15:59:46 +08:00
if (key !== 'assetLabel') {
return obj.name + '/' + children.name
} else {
return children.name
}
2021-10-14 14:14:25 +08:00
},
showDropDown (val, key) {
this.searchStr = this.detailSearchListCopy[key].searchStr
this.detailSearchListCopy[key].dropShow = val
2021-10-12 16:53:59 +08:00
}
},
watch: {
detailSearchList: {
immediate: true,
deep: true,
handler (n) {
this.detailSearchListCopy = JSON.parse(JSON.stringify(n))
Object.keys(this.detailSearchListCopy).forEach(key => {
this.detailSearchListCopy[key].searchStr = ''
this.detailSearchListCopy[key].oldChildren = JSON.parse(JSON.stringify(this.detailSearchListCopy[key].children))
})
2021-10-12 16:53:59 +08:00
}
},
selectValue: {
2021-10-12 16:53:59 +08:00
deep: true,
handler (n) {
this.$emit('reload', n)
}
}
}
}
</script>
2021-10-14 14:14:25 +08:00
<style scoped lang="scss">
.search-detail-box{
display: inline-block;
margin-right: 20px;
transition: background-color .1s ease-out;
border-radius: 2px;
}
.search-detail-box:hover{
2021-10-15 10:22:02 +08:00
background: #F9F9F9;
2021-10-14 14:14:25 +08:00
}
.search-detail-box.select-dropdown{
2021-10-15 10:22:02 +08:00
background: #F9F9F9;
2021-10-14 14:14:25 +08:00
}
2021-10-15 10:22:02 +08:00
/*.search-detail-box.show-my-dropdpwn{*/
/* background-color: #344563;*/
/* color: #fff;*/
/* .search-detail-title{*/
/* color: #fff;*/
/* }*/
/* .detail-top-search{*/
/* color: #fff;*/
/* }*/
/* .search-value{*/
/* color: #fff;*/
/* }*/
/*}*/
.detail-dropdown{
padding: 0 10px;
height: 30px;
line-height: 30px;
border-radius: 2px;
}
.search-detail-title {
2021-10-12 16:53:59 +08:00
font-size: 14px;
color: #333333;
letter-spacing: 0;
line-height: 14px;
font-weight: 600;
2021-10-18 17:40:21 +08:00
margin-right: 10px;
2021-10-12 16:53:59 +08:00
}
.search-value{
font-size: 14px;
color: #666666;
letter-spacing: 0;
line-height: 14px;
font-weight: 400;
}
.detail-top-search {
display: inline-block;
vertical-align: bottom;
overflow: hidden;
text-overflow:ellipsis;
white-space:nowrap;
2021-10-14 14:14:25 +08:00
max-width: 100px;
2021-10-12 16:53:59 +08:00
}
</style>
<style lang="scss">
.detail-top-search-dropdown{
max-height: 300px;
overflow-y: auto;
.el-dropdown-menu__item{
background: #fff !important;
2021-10-12 16:53:59 +08:00
padding: 0;
max-width: 200px;
overflow: hidden;
text-overflow:ellipsis;
white-space:nowrap;
.el-checkbox{
width: calc(100% - 20px);
height: 36px;
padding: 0 0 0 20px;
display: flex;
align-items: center;
.el-checkbox__label{
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.el-checkbox:hover{
color: #fa901c;
background-color: #fafafa !important;
}
.children-title-name{
width: calc(100% - 20px);
height: 36px;
padding-left: 20px;
font-size: 12px;
color: #909399;
line-height: 30px;
}
}
.el-dropdown-menu__item:not(.is-disabled):hover{
color: #606266;
background: #fff !important;
2021-10-12 16:53:59 +08:00
}
}
.clear-all-select{
padding: 0 20px;
2021-10-12 17:09:59 +08:00
padding-left: 42px;
2021-10-12 16:53:59 +08:00
color: #0052cc;
font-size: 12px;
}
.clear-all-select:hover{
text-decoration: underline;
}
</style>