NEZ-389 feat:asset tag 功能修改

This commit is contained in:
wangwenrui
2020-09-08 11:18:18 +08:00
parent aa05a8c111
commit 74cacb33ae
5 changed files with 183 additions and 10 deletions

View File

@@ -472,6 +472,9 @@ li{
padding-top: 24px; padding-top: 24px;
font-size: 14px; font-size: 14px;
} }
.orange-font{
color:#FA901C;
}
.content-left .sidebar-info-item { .content-left .sidebar-info-item {
line-height: 20px; line-height: 20px;
padding: 0 0 0 10px; padding: 0 0 0 10px;

View File

@@ -8,14 +8,17 @@
v-for="(item,index) in custom" v-for="(item,index) in custom"
:key="index" :key="index"
class="custom-label" class="custom-label"
:class="!allowedAll&&!item.allowed && (index==0 || index == 1 || item.NotSet) ? 'custom-label-disabled' : ''"
@click="handler(item,index)" @click="handler(item,index)"
:id="'element-set-el-'+index" :id="'element-set-el-'+index"
:class="{'custom-title orange-font':item.type == 'title','custom-label-disabled':!allowedAll&&!item.allowed && (index==0 || index == 1 || item.NotSet)}"
> >
<i class="el-icon-check" v-if="!allowedAll&&!item.allowed&&(index==0||index==1||item.visibility=='disabled')"></i> <i class="el-icon-check" v-if="!allowedAll&&!item.allowed&&(index==0||index==1||item.visibility=='disabled')"></i>
<i v-else class="el-icon-check" v-show="item.show"></i> <i v-else class="el-icon-check" v-show="item.show"></i>
<span>{{item.label}}</span> <span>{{item.label}}</span>
</div> </div>
</el-scrollbar> </el-scrollbar>
</div> </div>
<div class="custom-bottom-btns"> <div class="custom-bottom-btns">
@@ -160,6 +163,9 @@ export default {
cursor: default; cursor: default;
font-size: 14px; font-size: 14px;
} }
.custom-title{
padding: 2px 0 2px 2px;
}
.custom-label-disabled { .custom-label-disabled {
cursor: not-allowed; cursor: not-allowed;
background: #f1f3f4; background: #f1f3f4;

View File

@@ -101,6 +101,28 @@
</el-checkbox-group> </el-checkbox-group>
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
<!--tag 过滤-->
<div class="sidebar-title too-long-split orange-font">
Tag
</div>
<el-collapse v-model="activeTag" class="left-menu-bg">
<el-collapse-item :name="item.key" :title="item.key" v-for="item in tagData">
<el-checkbox-group v-model="tagCheckList" size="small" >
<el-checkbox class="sidebar-info-item" v-for="tag in item.values" :key="tag.value" :label="tag.value" @change="changeTagCheckBox(item,tag.value)">
<div class="sidebar-info-item-txt">
<el-popover v-if="tag.value.length > 14" trigger="hover" placement="top-start" :content="tag.value" >
<span slot="reference">{{tag.value}}</span>
</el-popover>
<span v-else>{{tag.value}}</span>
</div>
<el-tooltip :content="''+tag.total" placement="top" effect="light" :disabled="tag.total<99">
<el-badge class="mark" :value="tag.total" :max="99"/>
</el-tooltip>
</el-checkbox>
</el-checkbox-group>
</el-collapse-item>
</el-collapse>
</template> </template>
<template v-else> <template v-else>
<div v-for="menu in $CONSTANTS.staticMenus[parentMenu].menu" class="sidebar-info-item" :class="{'sidebar-info-item-active': menu.route == route}" @click="jumpTo(menu.route)"> <div v-for="menu in $CONSTANTS.staticMenus[parentMenu].menu" class="sidebar-info-item" :class="{'sidebar-info-item-active': menu.route == route}" @click="jumpTo(menu.route)">
@@ -151,6 +173,7 @@
//asset相关 //asset相关
activeType: 'dataCenter', activeType: 'dataCenter',
activeTag:'',
dcData: [], dcData: [],
dcCheckList: [], dcCheckList: [],
assetTypeData: [], assetTypeData: [],
@@ -159,6 +182,10 @@
vendorCheckList: [], vendorCheckList: [],
pingData: [], pingData: [],
pingCheckList: [], pingCheckList: [],
tagData:[],
tagCheckList:[],
tagCheckMap:{},
lastCheckSize:0,
assetPingSwitch:true, assetPingSwitch:true,
} }
}, },
@@ -183,9 +210,9 @@
return ""; return "";
} }
}, },
currentProjectChange() { checkedTagCount(){
return this.$store.state.currentProject; return this.tagCheckList.length;
}, }
}, },
watch: { watch: {
route: { route: {
@@ -410,6 +437,9 @@
item.value = item.status; item.value = item.status;
return item; return item;
}); });
this.tagData = response.data.tag
} }
resolve(); resolve();
}); });
@@ -444,7 +474,35 @@
bus.$emit("asset-filter-change", "pingStates", ""); bus.$emit("asset-filter-change", "pingStates", "");
} }
}, },
changeTagCheckBox(tag,value){
console.log(tag,value,this.tagCheckList)
let checked=this.tagCheckMap[tag.key];
if(!checked){
checked=[];
}
if(this.lastCheckSize < this.tagCheckList.length){
checked.push(value)
}else{
let index=checked.findIndex(item=>{
return item == value
})
checked.splice(index,1)
}
if(checked.length>0){
this.tagCheckMap[tag.key] = checked;
}else{
if(this.tagCheckMap[tag.key]){
delete this.tagCheckMap[tag.key]
}
}
this.lastCheckSize = this.tagCheckList.length;
if(Object.keys(this.tagCheckMap).length > 0){
bus.$emit("asset-filter-change", "tags", JSON.stringify(this.tagCheckMap));
}else{
bus.$emit("asset-filter-change", "tags", '');
}
},
indOf(a, b) { indOf(a, b) {
let c = []; let c = [];
for (let i = 0; i < a.length; i++) { for (let i = 0; i < a.length; i++) {

View File

@@ -96,11 +96,11 @@
</div> </div>
<el-scrollbar ref="tagEditBoxScrollbar" style="height: calc(100% - 32px);"> <el-scrollbar ref="tagEditBoxScrollbar" style="height: calc(100% - 32px);">
<div class="tag-edit-box-body" v-for="(item, index) in editAsset.tags"> <div class="tag-edit-box-body" v-for="(item, index) in editAsset.tags">
<el-form-item class="tag-edit tag-edit-tag" :rules="{required: true, message: $t('validate.required'), trigger: 'blur'}" :prop="'tags.' + index + '.tag'"> <el-form-item class="tag-edit tag-edit-tag" :rules="{required: true, message: $t('validate.required'), trigger: 'change'}" :prop="'tags.' + index + '.tag'">
<el-input placeholder="tag" size="mini" v-model="item.tag"></el-input> <el-autocomplete placeholder="tag" size="mini" v-model="item.tag" :fetch-suggestions="filterKey" @blur="loadValues(item)" @select="loadValues" popper-class="no-style-class"></el-autocomplete>
</el-form-item> </el-form-item>
<el-form-item class="tag-edit tag-edit-value" :rules="{required: true, message: $t('validate.required'), trigger: 'blur'}" :prop="'tags.' + index + '.value'"> <el-form-item class="tag-edit tag-edit-value" :rules="{required: true, message: $t('validate.required'), trigger: 'change'}" :prop="'tags.' + index + '.value'">
<el-input placeholder="value" size="mini" v-model="item.value"></el-input> <el-autocomplete placeholder="value" size="mini" v-model="item.value" :fetch-suggestions="filterValue" popper-class="no-style-class"></el-autocomplete>
</el-form-item> </el-form-item>
<div class="param-box-row-symbol" :id="'asset-tag-remove-'+index" @click.stop="removeTag(index)"><i class="nz-icon nz-icon-minus-square"></i></div> <div class="param-box-row-symbol" :id="'asset-tag-remove-'+index" @click.stop="removeTag(index)"><i class="nz-icon nz-icon-minus-square"></i></div>
</div> </div>
@@ -251,7 +251,10 @@
formData:null, formData:null,
accountValidResult: true, accountValidResult: true,
changeProtocolSwitch: true, changeProtocolSwitch: true,
exporterDisableSwitch: false exporterDisableSwitch: false,
tagKeys:[],
tagValues:[],
tagValuesCache:new Map(),
} }
}, },
watch: { watch: {
@@ -618,13 +621,61 @@
}else{ }else{
this.exporterDisableSwitch = false; this.exporterDisableSwitch = false;
} }
},
loadKeys:function(){
this.$get('/asset/tagKey').then(res=>{
if(res.code == 200){
this.tagKeys = res.data.list.map(item=>{
return {value:item}
})
} }
})
},
loadValues:function(tag){
let tagVal=tag.tag && tag.tag!=''?tag.tag:tag.value
if(!tagVal || tagVal ==''){this.tagValues=[]; return; }
let value = this.tagValuesCache.get(tagVal)
if(!value){
value = [];
this.$get('/asset/tagValue?key='+tagVal).then(res => {
if(res.code == 200){
value = res.data.list.map(item=>{
return {value:item}
})
this.tagValues=Object.assign([],value)
this.tagValuesCache.set(tag.tag,Object.assign([],value))
}
})
}else{
this.tagValues=Object.assign([],value)
}
},
filterKey:function(input,callback){
if(!input || input == ''){
callback(this.tagKeys)
}else{
let result=this.tagKeys.filter(item=>{return item.value.toLowerCase().indexOf(input.toLowerCase()) != -1})
callback(result)
}
},
filterValue:function(input,callback){
console.log(this.tagValues)
if(!input || input == ''){
callback(this.tagValues)
}else{
let result=this.tagValues.filter(item=>{return item.value.toLowerCase().indexOf(input.toLowerCase()) != -1})
callback(result)
}
},
}, },
mounted() { mounted() {
this.getUserData(); this.getUserData();
this.getVendorData(); this.getVendorData();
this.getAssetTypeData(); this.getAssetTypeData();
this.getDcData(); this.getDcData();
this.loadKeys();
this.showAccountOp = false; this.showAccountOp = false;
} }
} }

View File

@@ -59,6 +59,10 @@
:prop="$tableSet.propTitle(item.prop,'asset')" :prop="$tableSet.propTitle(item.prop,'asset')"
:sort-orders="['ascending', 'descending']" :sort-orders="['ascending', 'descending']"
> >
<template slot-scope="scope" slot="header">
<span v-if="item.type == 'tag'"><span>{{item.label}}</span><span style="color:orange;">&nbsp;[Tag]</span></span>
<span v-else><span>{{item.label}}</span></span>
</template>
<template slot-scope="scope" :column="item"> <template slot-scope="scope" :column="item">
<div v-if="item.prop=='ID'"> <div v-if="item.prop=='ID'">
<span>{{scope.row.id}}</span> <span>{{scope.row.id}}</span>
@@ -118,6 +122,9 @@
<div v-if="item.prop=='tel'"> <div v-if="item.prop=='tel'">
<span>{{scope.row.idc.tel}}</span> <span>{{scope.row.idc.tel}}</span>
</div> </div>
<template v-if="item.prop == 'tags'">
<span>{{filterTags(scope)}}</span>
</template>
<template v-if="item.prop == 'option'"> <template v-if="item.prop == 'option'">
<span :title="$t('overall.view')" @click.stop="detail(scope.row)" class="content-right-option" :id="'asset-detail-'+scope.row.id"><i <span :title="$t('overall.view')" @click.stop="detail(scope.row)" class="content-right-option" :id="'asset-detail-'+scope.row.id"><i
class="el-icon-view"></i> class="el-icon-view"></i>
@@ -358,6 +365,7 @@
}, },
assetPingSwitch: localStorage.getItem('nz-sys-asset-ping-switch'), assetPingSwitch: localStorage.getItem('nz-sys-asset-ping-switch'),
tagKeys:[],
} }
}, },
watch: { watch: {
@@ -497,6 +505,7 @@
if (refresh) { if (refresh) {
this.getTableData(); this.getTableData();
bus.$emit('asset-list-change') bus.$emit('asset-list-change')
this.loadKeys();
} }
}, },
pageNo(val) { pageNo(val) {
@@ -642,6 +651,47 @@
this.$nextTick(()=>{ this.$nextTick(()=>{
bus.$emit(event,param) bus.$emit(event,param)
}) })
},
loadKeys:function(){
this.$get('/asset/tagKey').then(res=>{
if(res.code == 200){
this.tagKeys = res.data.list.map(item=>{
return {label:item,prop:'tags',show:false,allowed: true,type:'tag'}
})
this.resetTableTitle()
}
})
},
resetTableTitle:function(){
let title = this.tools.customTableTitle;
let tableTitle = title.slice(0,this.tableTitle.length);
let tagTitle = title.slice(this.tableTitle.length,title.length);
let $self=this;
let newTags = this.tagKeys.filter(item=>{ return !tagTitle.find(t =>{return item.label == t.label})})
let keepTags = tagTitle.filter(item=>{ return $self.tagKeys.find(t =>{return item.label == t.label})})
let result = tableTitle.concat([{label:'Tag',show:false,NotSet:true,type:'title',prop:'table-tag'}])
result = result.concat(keepTags).concat(newTags)
this.tools.customTableTitle = JSON.parse(JSON.stringify(result))
},
filterTags:function(scope){
console.log(scope)
let tag=scope.column.label.split(' [Tag]')[0]
let tagVals=scope.row.tags
if(tagVals){
console.log('tags',tagVals,tag)
let showTag=tagVals.find(item=>{return item.tag == tag})
if(showTag){
return showTag.value
}
}
} }
}, },
@@ -672,6 +722,11 @@
} }
} }
this.tools.customTableTitle = tableTitle; this.tools.customTableTitle = tableTitle;
this.loadKeys();
console.log('load end')
//初始化数据 //初始化数据
this.getUserData(); this.getUserData();
this.getTableData(); this.getTableData();