feat:修改endpoint 搜索asset列表的接口

This commit is contained in:
zhangyu
2021-04-15 11:47:44 +08:00
parent 1c130e1cb2
commit 783f22b880
25 changed files with 2052 additions and 2310 deletions

View File

@@ -24,226 +24,64 @@
</el-select>
</el-form-item>
<!--asset和endpoint-->
<div class="right-box-form-row right-child-boxes" style="height: calc(100% - 190px);">
<div class="right-child-box assets-box">
<!--begin--标题-->
<div class="right-child-box-title">{{$t('asset.asset')}}</div>
<!--end--标题-->
<!-- begin--table-->
<div class="endpoint-sub-table" v-loading="assetLoading">
<div ref="assetScrollbar" style="overflow: auto; height: 100%; width: 100%;">
<div class="endpoint-sub-table-head">
<div @click.stop v-if="!currentModuleCopy.id" class="endpoint-sub-table-body-dialog"></div>
<div class="endpoint-sub-table-col" style="width: 15px;position: relative">
<el-checkbox v-model="assetListAll" :indeterminate="assetListHalf"
@change="assetListSelAll"></el-checkbox>
</div>
<div class="endpoint-sub-table-col">Host</div>
<div class="endpoint-sub-table-col">SN</div>
<div class="endpoint-sub-table-col">Model</div>
<div class="endpoint-sub-table-col">DC</div>
<div class="endpoint-sub-table-col">Type</div>
</div>
<div class="line-100"></div>
<div class="endpoint-sub-table-body">
<div v-for="(item, index) in assetList" :id="'select-asset-'+item.id" :key="index" :data="item.id" class="endpoint-sub-table-row">
<el-popover trigger="hover" placement="left-start">
<div class="asset-tip" style="display: table">
<div class="tip-row">
<span class="tip-cell">Host</span>
<span class="tip-cell">{{item.host}}</span>
</div>
<div class="tip-row">
<span class="tip-cell">SN</span>
<span class="tip-cell">{{item.sn}}</span>
</div>
<div class="tip-row">
<span class="tip-cell">Model</span>
<span class="tip-cell">{{item.model.name}}</span>
</div>
<div class="tip-row">
<span class="tip-cell">DC</span>
<span class="tip-cell">{{item.idc.name}}</span>
</div>
<div class="tip-row">
<span class="tip-cell">Type</span>
<span class="tip-cell">{{item.model.type.value}}</span>
</div>
</div>
<span slot="reference">
<div class="endpoint-sub-table-col" style="width: 15px;">
<el-checkbox v-model="item.sel" @change="selectAsset"></el-checkbox>
</div>
<div class="endpoint-sub-table-col">{{item.host}}</div>
<div class="endpoint-sub-table-col">{{item.sn}}</div>
<div class="endpoint-sub-table-col">{{item.model.name}}</div>
<div class="endpoint-sub-table-col">{{item.idc.name}}</div>
<div class="endpoint-sub-table-col">{{item.model.type.value}}</div>
</span>
</el-popover>
</div>
</div>
</div>
</div>
<div class="line-100" style="border-color:#dcdfe6"></div>
<div class="asset-and-endponit">
<div class="right-box-asset-table">
<div>
<button type="button" @click="addToEndpointList"
class="nz-btn nz-btn-size-small-new nz-btn-style-light-new endpoints-clear-btn" style="margin-top: 3px;" id="add-endpoint-add-asset">
{{$t('overall.addAssetList')}}
</button>
<span style="display: inline-block; font-size: 14px; float: right;padding-right: 15px;margin-top: 3px;">All: {{this.assetList.length}}</span>
<search-input ref="searchInput" :inTransform="bottomBox.inTransform" :searchMsg="searchMsg" @search="search"></search-input>
</div>
<!--end--table-->
<el-table
ref="multipleTable"
:data="assetTableData"
tooltip-effect="dark"
style="width: 100%"
height="100%"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in assetTableTitle"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:width="`${item.width}`"
class="data-column"
>
<template slot="header">
<span>{{item.label}}</span>
<div class="col-resize-area"></div>
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop == 'brand'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<template v-else-if="item.prop == 'model'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<template v-else-if="item.prop == 'dc'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<template v-else-if="item.prop == 'cabinet'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<template v-else-if="item.prop == 'type'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<template v-else-if="item.prop == 'state'">
<span>{{scope.row[item.prop].name}}</span>
</template>
<span v-else>{{scope.row[item.prop] ? scope.row[item.prop] : ''}}</span>
</template>
</el-table-column>
</el-table>
</div>
<!--右侧endpoint列表-->
<div class="right-child-box endpoints-box" :class="{'endpoints-box-snmp': currentModuleCopy.type && currentModuleCopy.type.toLowerCase() == 'snmp'}">
<!--module-->
<div class="endpoints-box-module-info">
<div class="title">{{$t('project.endpoint.moduleParameter')}}:</div>
<el-input class="module-info module-info-port input-x-mini-22" :class="{'module-info-port-snmp': currentModuleCopy.type && currentModuleCopy.type.toLowerCase() == 'snmp'}" v-model="currentModuleCopy.port" id="add-endpoint-module-port"></el-input>
<el-popover
placement="bottom"
width="100"
trigger="hover"
v-if="currentModuleCopy.type && currentModuleCopy.type.toLowerCase() == 'http'"
>
<div class="endpoint-param-pop">
<div v-for="(item, index) in currentModuleCopy.paramObj" :key="index">{{item.key}}={{item.value}}</div>
</div>
<el-input id="add-endpoint-module-param" @click.native.stop="showEditParamBox(true, currentModuleCopy, 1, $event)" slot="reference" disabled class="module-info module-info-param input-x-mini-22" v-model="currentModuleCopy.param" ></el-input>
</el-popover>
<div class="right-box-endpoint-table">
<el-popover
placement="bottom"
width="100"
trigger="hover"
>
<div class="endpoint-param-pop">
<div v-for="(item, index) in currentModuleCopy.labelModule" :key="index">{{item.key}}={{item.value}}</div>
</div>
<el-input id="edit-labels" @click.native.stop="showEditLabelsBox(true, currentModuleCopy, 1, $event)" slot="reference" disabled class="module-info module-info-param module-info-labels input-x-mini-22" :class="{'module-info-labels-snmp': currentModuleCopy.type && currentModuleCopy.type.toLowerCase() == 'snmp'}" v-model="currentModuleCopy.labels"></el-input>
</el-popover>
<el-input v-if="currentModuleCopy.type && currentModuleCopy.type.toLowerCase() == 'http'" class="module-info module-info-path input-x-mini-22" v-model="currentModuleCopy.path" id="add-endpoint-module-path"></el-input>
<button type="button" id="cover-param" @click="coverEndpoint" class="nz-btn nz-btn-size-small nz-btn-style-light module-info module-info-cover"><i class="nz-icon nz-icon-override"></i></button>
</div>
<!--endpoints-->
<div class="endpoints-box-endpoints" :style="{borderColor: endpointTouch ? paramBorderColor : '#dcdfe6'}">
<el-table
:data="endpointList"
ref="endpointTable"
style="width: 100%;border-radius: 4px;"
height="calc(100% - 36px)"
:row-class-name="setRowIndex"
id="add-endpoint-asset-table"
empty-text=" ">
<el-table-column
type="selection"
width="25"
style="padding: 0 1px;">
</el-table-column>
<el-table-column
label-class-name="endpoints-box-endpoints-title"
v-for="(title, index) in endpointTableTitle"
v-if="title.show"
:width="title.width"
:key="`col-${index}`"
:label="title.label"
>
<template slot-scope="scope" :column="title">
<span v-if="title.prop == 'asset' && scope.row[title.prop]">{{scope.row[title.prop].host}}</span>
<span v-else-if="title.prop == 'param'">
<el-popover
v-if="!scope.row.isEdit"
placement="bottom"
width="200"
trigger="hover"
>
<div class="endpoint-param-pop">
<div v-for="p in scope.row.paramObj" :key="p.key">{{p.key}}={{p.value}}</div>
</div>
<span slot="reference">
<span @mousedown.stop>{{scope.row.param.length > 8 ? scope.row.param.substring(0, 8) + '...' : scope.row.param}}</span>
</span>
</el-popover>
<span @mousedown.stop v-else @click.stop="showEditParamBox(true, scope.row, 2, $event)">
<el-form-item :prop="'endpointList[' + scope.row.index + '].param'" :rules="{required: false, message: $t('validate.required'), trigger: 'blur'}">
<el-input readonly class="endpoint-info endpoint-info-param input-x-mini-22" v-model="scope.row.param"></el-input>
</el-form-item>
</span>
</span>
<span v-else-if="title.prop == 'labels'">
<el-popover
v-if="!scope.row.isEdit"
placement="bottom"
width="200"
trigger="hover"
>
<div class="endpoint-param-pop">
<div v-for="p in scope.row.labelModule" :key="p.key">{{p.key}}={{p.value}}</div>
</div>
<span slot="reference">
<span @mousedown.stop>{{scope.row.labels.length > 8 ? scope.row.labels.substring(0, 8) + '...' : scope.row.labels}}</span>
</span>
</el-popover>
<span @mousedown.stop v-else @click.stop="showEditLabelsBox(true, scope.row, 2, $event)">
<el-form-item :prop="'endpointList[' + scope.row.index + '].param'" :rules="{required: false, message: $t('validate.required'), trigger: 'blur'}">
<el-input readonly class="endpoint-info endpoint-info-param input-x-mini-22" v-model="scope.row.labels"></el-input>
</el-form-item>
</span>
</span>
<span v-else-if="title.prop == 'path'">
<el-popover
placement="bottom"
width="100"
trigger="hover"
:content="scope.row[title.prop]"
v-if="!scope.row.isEdit"
>
<span slot="reference" >
<span>{{scope.row.path.length > 5 ? scope.row.path.substring(0, 5) + '...' : scope.row.path}}</span>
</span>
</el-popover>
<span @mousedown.stop v-else>
<el-form-item :prop="'endpointList[' + scope.row.index + '].path'" :rules="{required: true, message: $t('validate.required'), trigger: 'blur'}">
<el-input class="endpoint-info input-x-mini-22" v-model="scope.row.path"></el-input>
</el-form-item>
</span>
</span>
<span v-else-if="title.prop == 'port'">
<span v-if="!scope.row.isEdit">{{scope.row.port}}</span>
<span @mousedown.stop v-else>
<el-form-item :prop="'endpointList[' + scope.row.index + '].port'" :rules="{required: true, message: $t('validate.required'), trigger: 'blur'}">
<el-input class="endpoint-info input-x-mini-22" v-model="scope.row.port"></el-input>
</el-form-item>
</span>
</span>
<span v-else-if="title.prop == 'host'">
<span v-if="!scope.row.isEdit">{{scope.row.host}}</span>
<span @mousedown.stop v-else>
<el-form-item :prop="'endpointList[' + scope.row.index + '].host'" :rules="{required: true, message: $t('validate.required'), trigger: 'blur'}">
<el-input class="endpoint-info input-x-mini-22" v-model="scope.row.host"></el-input>
</el-form-item>
</span>
</span>
</template>
</el-table-column>
<el-table-column label="" width="56">
<template slot-scope="scope" :column="title">
<div>
<span :id="'ep-asset-toedit-'+scope.row.assetId" v-if="!scope.row.isEdit" class="endpoint-box-row-symbol" @mousedown.stop @click="toEditEndpoint(scope.row)"><i class="el-icon-edit-outline"></i></span>
<span :id="'ep-asset-edit-'+scope.row.assetId" v-else class="endpoint-box-row-symbol" @mousedown.stop @click="editEndpoint(scope.row)"><i class="nz-icon nz-icon-check"></i></span>
<!--<span :id="'ep-asset-remove-'+scope.row.assetId" class="endpoint-box-row-symbol" @click="removeEndpoint(scope.row)"><i class="nz-icon nz-icon-shanchu1"></i></span>-->
</div>
</template>
</el-table-column>
</el-table>
<div class="el-form-item__error" :style="{opacity: endpointTouch && this.endpointList.length == 0 ? '1' : '0'}" style="left: unset; transition: all .2s">{{$t('validate.required')}}</div>
<div>
<button id="clear-select-asset" type="button" @click="clearSelection" class="nz-btn nz-btn-size-small-new nz-btn-style-light-new endpoints-clear-btn">{{$t('overall.clear')}}</button>
<span style="display: inline-block; font-size: 14px; float: right;line-height: 35px;padding-right: 15px;">All: {{this.endpointList.length}}</span>
</div>
</div>
</div>
</div>
</el-form>
@@ -315,6 +153,10 @@ export default {
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
]
},
pageObj: {
pageNo: 1,
pageSize: 10
},
vendorAndModelOptionData: [],
paramBorderColor: '#dcdfe6',
endpointTouch: false,
@@ -332,7 +174,7 @@ export default {
editLabelsBox: { show: false, top: 0, left: 0, type: 0 }, // param编辑弹框
moduleParamShow: false, // module默认参数param悬浮窗
assetSearch: { host: '', sn: '', text: '', label: 'Host', typeIds: '', modelId: '', idcId: '', dropdownShow: false }, // 侧滑框中asset的搜索相关
assetPageObj: { pageNo: 1, pageSize: -1 },
assetPageObj: { pageNo: 1, pageSize: 10 },
selectedAssets: [], // 侧滑框中选中的asset
projectList: [],
moduleList: [],
@@ -373,9 +215,68 @@ export default {
],
assetListAll: false,
assetListHalf: false,
assetTableTitle: [
{
label: this.$t('asset.tableTitle.sn'),
prop: 'sn',
show: true
},
{
label: this.$t('asset.tableTitle.name'),
prop: 'name',
show: false,
allowed: true
}, {
label: this.$t('asset.tableTitle.manageIp'),
prop: 'manageIp',
show: true
}, {
label: this.$t('asset.tableTitle.brand'),
prop: 'brand',
show: true
}, {
label: this.$t('asset.tableTitle.model'),
prop: 'model',
show: true
}, {
label: this.$t('asset.tableTitle.dc'),
prop: 'dc',
show: true
}, {
label: this.$t('asset.tableTitle.cabinet'),
prop: 'cabinet',
show: true
}, {
label: this.$t('asset.tableTitle.type'),
prop: 'type',
show: true
}, {
label: this.$t('asset.tableTitle.state'),
prop: 'state',
show: true
}],
typeList: [],
dcList: [],
modelList: []
modelList: [],
assetTableData: [],
seachLabel: [],
searchMsg: { // 给搜索框子组件传递的信息
zheze_none: true,
searchLabelList: [{
id: 10,
name: 'Project name',
type: 'input',
label: 'name',
disabled: false
},
{
id: 10,
name: 'Project id',
type: 'input',
label: 'id',
disabled: false
}]
}
}
},
methods: {
@@ -596,41 +497,16 @@ export default {
})
},
/* 获取类型列表 */
getTypeList () {
this.$get('sys/dict/all', { pageSize: -1, pageNo: 1, type: 'assetType' }).then(response => {
if (response.code === 200) {
this.typeList = response.data
}
})
},
/* 获取DC列表 */
getDCList () {
this.$get('idc', { pageSize: -1, pageNo: 1 }).then(response => {
if (response.code === 200) {
this.dcList = response.data.list
}
})
},
// 获取endpoint弹框中的asset子弹框里asset列表数据
getAssetList () {
this.assetLoading = true
this.$get('asset', this.assetPageObj).then(response => {
const params = {
...this.assetPageObj,
...this.seachLabel
}
this.$get('asset/asset', params).then(response => {
if (response.code === 200) {
const respData = response.data.list
for (let i = 0; i < respData.length; i++) {
respData[i].sel = false
for (let j = 0; j < this.endpointList.length; j++) {
if (respData[i].id == this.endpointList[j].assetId) {
respData.splice(i, 1)
i--
break
}
}
}
this.assetList = response.data.list
this.assetTableData = response.data.list
}
}).finally(() => {
setTimeout(() => {
@@ -684,88 +560,6 @@ export default {
this.tempParamObj = []
},
// 清空勾选的endpoint
clearSelection () {
const selections = this.$refs.endpointTable.selection
if (selections && selections.length > 0) {
for (let i = 0; i < selections.length; i++) {
this.removeEndpoint(selections[i])
}
}
},
// endpoint弹框中的asset子弹框里asset选择事件
selectAsset () {
this.$nextTick(() => {
let index = 0
this.assetList.forEach(item => {
if (item.sel) {
index++
}
})
if (index == 0) {
this.assetListAll = false
this.assetListHalf = false
} else if (index < this.assetList.length) {
this.assetListAll = true
this.assetListHalf = true
} else {
this.assetListAll = true
this.assetListHalf = false
}
})
},
// 批量添加到endpoint
addToEndpointList () {
const arr = []
this.assetListAll = false
this.assetListHalf = false
this.endpointTouch = true
this.endpointTouch = true
this.endpoint.projectId = this.currentProjectCopy.id
this.endpoint.moduleId = this.currentModuleCopy.id
this.assetList = this.assetList.filter(item => {
const flag = item.sel
if (flag) {
item.sel = false
const obj = {
isEdit: false,
assetId: item.id,
asset: item,
host: item.host,
param: this.currentModuleCopy.param ? this.currentModuleCopy.param : '',
paramObj: this.currentModuleCopy.paramObj ? this.currentModuleCopy.paramObj : {},
labels: this.currentModuleCopy.labels ? this.currentModuleCopy.labels : '',
labelModule: this.currentModuleCopy.labelModule ? this.currentModuleCopy.labelModule : {},
port: this.currentModuleCopy.port,
path: this.currentModuleCopy.path,
moduleId: this.currentModuleCopy.id
}
arr.push(obj)
}
return !flag
})
this.endpointList = this.endpointList.concat(arr)
},
// 全选的checkbox的事件
assetListSelAll (flag) {
if (flag) {
this.assetListHalf = false
this.assetList.forEach(item => {
item.sel = flag
})
} else if (!flag && !this.assetListHalf) {
this.assetList.forEach(item => {
item.sel = flag
})
} else if (!flag && this.assetListHalf) {
this.assetListHalf = false
this.assetListAll = true
this.assetList.forEach(item => {
item.sel = !flag
})
}
},
// 将param转为json字符串格式
paramToJson (param) {
const tempParam = {}
@@ -782,7 +576,7 @@ export default {
// 获取endpoint弹框中module下拉框数据
getModuleList (projectId) {
this.$get('module', { projectIds: projectId, pageSize: -1 }).then(response => {
this.$get('monitor/module', { projectIds: projectId, pageSize: -1 }).then(response => {
if (response.code === 200) {
for (let i = 0; i < response.data.list.length; i++) {
try {
@@ -826,7 +620,7 @@ export default {
})
this.$refs.addEndpoint.validate((valid) => {
if (valid) {
this.$post('endpoint', endpointList).then(response => {
this.$post('monitor/endpoint', endpointList).then(response => {
this.prevent_opt.save = false
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
@@ -878,64 +672,6 @@ export default {
}).catch(() => {
this.prevent_opt.save = false
})
},
// endpoint弹框的asset子弹框顶部搜索条件选中事件
dropdownSelect (label) {
this.assetSearch.text = ''
if (this.assetSearch.label !== label) {
this.assetSearch.host = ''
this.assetSearch.sn = ''
this.assetSearch.modelId = ''
this.assetSearch.typeIds = ''
this.assetSearch.idcId = ''
}
this.assetSearch.label = label
this.assetSearch.dropdownShow = false
},
clearEndpoints () {
this.getAssetList()
this.endpointList = []
this.assetSearch = { host: '', sn: '', text: '', label: 'Host', dropdownShow: false }
},
setRowIndex ({ row, rowIndex }) {
row.index = rowIndex
},
filterDCValue (input, callback) {
const result = this.dcList.filter(item => {
return item.name.toLowerCase().indexOf(input.toLowerCase()) != -1
})
console.info(input, result)
callback(result)
},
filterModelValue (input, callback) {
const result = this.modelList.filter(item => {
return item.name.toLowerCase().indexOf(input.toLowerCase()) != -1
})
callback(result)
},
filterTypeValue (input, callback) {
const result = this.typeList.filter(item => {
return item.name.toLowerCase().indexOf(input.toLowerCase()) != -1
})
callback(result)
},
selectDC (select) {
this.assetSearch.idcId = select.id
this.assetSearch.modelId = ''
this.assetSearch.typeIds = ''
},
selectModel (select) {
this.assetSearch.modelId = select
this.assetSearch.idcId = ''
this.assetSearch.typeIds = ''
},
selectType (select) {
this.assetSearch.typeIds = select.id
this.assetSearch.idcId = ''
this.assetSearch.modelId = ''
}
},
created () {
@@ -1271,6 +1007,24 @@ export default {
.endpoints-clear-btn {
margin: 6px 0 0 7px;
}
.asset-and-endponit{
width: 100%;
display: flex;
height: 480px;
}
.right-box-asset-table{
width: 37.5%;
margin-right: 2%;
background: #FFFFFF;
border: 1px solid #E7EAED;
border-radius: 2px;
}
.right-box-endpoint-table{
flex: 1;
background: #FFFFFF;
border: 1px solid #E7EAED;
border-radius: 2px;
}
/* end--table*/
/* end--子弹框*/