NEZ-1617 feat: IPAM 页面开发

This commit is contained in:
@changcode
2022-03-03 10:33:29 +08:00
parent 17586dc2bc
commit cc4f5698ec
9 changed files with 587 additions and 2 deletions

View File

@@ -364,6 +364,7 @@ export const fromRoute = {
menus: 'menus',
notify: 'notify',
link: 'link',
ipam: 'ipam',
apiKey: 'apiKey',
chartTemp: 'chartTemp'
}

View File

@@ -851,6 +851,114 @@ export default {
jsonKey: 'val'
}
}
} else if (path === 'ipam') {
searchKeys = {
// key: path 键
// value: vue set 参数
pageNo: { target: this.pageObj, propertyName: 'pageNo', type: 'number' },
pageSize: { target: this.pageObj, propertyName: 'pageSize', type: 'number' },
orderBy: { target: this.$data, propertyName: 'orderBy', type: 'string' },
ids: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'ids',
type: 'string',
defaultJson: {
disabled: false,
label: 'ids',
name: 'ID',
type: 'input',
val: ''
},
jsonKey: 'val'
},
name: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'name',
type: 'string',
defaultJson: {
disabled: false,
id: 'name',
label: 'name',
name: 'Name',
type: 'input',
val: ''
},
jsonKey: 'val'
},
type: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'type',
type: 'number',
defaultJson: {
disabled: false,
label: 'ipamType',
name: 'Type',
readonly: true,
type: 'select',
val: ''
},
jsonKey: 'val'
},
addr: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'addr',
type: 'string',
defaultJson: {
disabled: false,
label: 'addr',
name: 'Addr',
type: 'input',
val: ''
},
jsonKey: 'val'
},
mask: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'mask',
type: 'string',
defaultJson: {
disabled: false,
label: 'mask',
name: 'Mask',
type: 'input',
val: ''
},
jsonKey: 'val'
},
vlan: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'vlan',
type: 'string',
defaultJson: {
disabled: false,
label: 'vlan',
name: 'Vlan',
type: 'input',
val: ''
},
jsonKey: 'val'
},
dc: {
target: this.searchLabel,
isSearchInput: true,
propertyName: 'dc',
type: 'string',
defaultJson: {
disabled: false,
label: 'dcId',
name: 'Data center',
type: 'input',
val: ''
},
jsonKey: 'val'
}
}
}
this.initQueryFromPath(searchKeys)
},

View File

@@ -213,6 +213,8 @@ export default {
url = '/dc/cabinet/cancelImport'
} else if (this.importUrl.indexOf('dc') > -1) {
url = '/dc/cancelImport'
} else if (this.importUrl.indexOf('/ipam/subnet') > -1) {
url = '/ipam/subnet/cancelImport'
}
this.$delete(url + '?seq=' + this.importResult.seq).then(response => {
if (response.code == 200) {
@@ -306,8 +308,9 @@ export default {
url = '/dc/cabinet/template'
} else if (this.importUrl.indexOf('dc') > -1) {
url = '/dc/template'
} else if (this.importUrl.indexOf('/ipam/subnet') > -1) {
url = '/ipam/subnet/template'
}
if (!url) {
console.error('no interface support')
}

View File

@@ -0,0 +1,171 @@
<template>
<div class="right-box right-box-mib" v-clickoutside="{obj:editipam,func:clickOutside}" >
<!-- begin--标题-->
<div class="right-box__header">
<div class="header__title">{{editipam.id ? ($t("overall.ipam.edit")) : $t("overall.ipam.create")}}</div>
<div class="header__operation">
<span v-cancel="{obj: editipam, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
</div>
</div>
<!-- begin--表单-->
<div class="right-box__container">
<div class="container__form">
<el-form :model="editipam" label-position = "top" label-width="120px" :rules="rules" ref="ipamForm">
<el-form-item :label="$t('overall.name')" prop="name">
<el-input maxlength="256" rows="4" show-word-limit placeholder="" v-model="editipam.name" size="small"></el-input>
</el-form-item>
<el-form-item :label="$t('overall.type')" prop="type">
<el-select id="account-input-language"
class="right-box__select"
v-model="editipam.type"
clearable
collapse-tags
placeholder=""
popper-class="right-box-select-top right-public-box-dropdown-top prevent-clickoutside"
size="small">
<template v-for="item in typeList">
<el-option :key="item.value" :label="item.label" :value="item.value"></el-option>
</template>
</el-select>
</el-form-item>
<div class="form__sub-title">CIDR</div>
<el-form-item :label="$t('overall.addr')" prop="addr">
<el-input maxlength="256" rows="4" show-word-limit placeholder="" v-model="editipam.addr" size="small"></el-input>
</el-form-item>
<el-form-item :label="$t('overall.mask')" prop="mask">
<el-input maxlength="256" rows="4" show-word-limit placeholder="" v-model="editipam.mask" size="small"></el-input>
</el-form-item>
<el-form-item :label="$t('overall.vlan')" prop="vlan">
<el-input maxlength="256" rows="4" show-word-limit placeholder="" v-model="editipam.vlan" size="small"></el-input>
</el-form-item>
<el-form-item :label="$t('overall.dc')" prop="dc">
<div class="right-box-form-content">
<el-select id="prom-box-input-dc" v-model="editipam.dc" placeholder="" class="right-box__select" popper-class="right-box-select-top right-public-box-dropdown-top prevent-clickoutside" size="small" value-key="id">
<el-option v-for="item in dcData" :id="'prom-edit-dc-op-'+item.id" :key="item.id" :label="item.name" :value="item">
<span class="config-dropdown-label-txt">{{item.name}}</span>
</el-option>
</el-select>
</div>
</el-form-item>
<el-form-item :label="$t('overall.remark')" prop="remark">
<el-input maxlength="256" rows="4" show-word-limit type="textarea" placeholder="" v-model="editipam.remark" size="small" id="mib-box-input-remark"></el-input>
</el-form-item>
</el-form>
</div>
</div>
<!--底部按钮-->
<div class="right-box__footer">
<button v-cancel="{obj:editipam,func:esc}" id="model-box-esc" class="footer__btn footer__btn--light">
<span>{{$t('overall.cancel')}}</span>
</button>
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="footer__btn" id="model-box-save">
<span>{{$t('overall.save')}}</span>
</button>
</div>
</div>
</template>
<script>
import editRigthBox from '../mixin/editRigthBox'
export default {
name: 'ipamBox',
props: {
obj: Object
},
mixins: [editRigthBox],
data () {
return {
editipam: {},
typeList: [
{ label: 'IPV4', value: 4 },
{ label: 'IPV6', value: 6 }
],
rules: {
name: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
type: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
addr: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
mask: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
dc: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
]
},
dcData: []
}
},
methods: {
clickOutside () {
this.esc(false)
},
/* 关闭弹框 */
esc (refresh) {
this.$emit('close', refresh)
},
/* 保存 */
save () {
this.$refs.ipamForm.validate((valid) => {
if (valid) {
this.prevent_opt.save = true
if (!this.editipam.id) {
this.$post('/ipam/subnet', this.editipam).then(response => {
if (response.code == 200 && response.msg == 'success') {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
} else {
this.$message.error(response.msg)
}
this.prevent_opt.save = false
})
} else {
this.$put('/ipam/subnet', this.editipam).then(response => {
if (response.code == 200 && response.msg == 'success') {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
} else {
this.$message.error(response.msg)
}
this.prevent_opt.save = false
})
}
} else {
this.prevent_opt.save = false
}
})
},
// 获取dc下拉列表数据
getDcData () {
this.$get('dc', { pageSize: -1 }).then(response => {
if (response.code === 200) {
this.dcData = response.data.list
}
})
}
},
mounted () {
this.getDcData()
},
watch: {
obj: {
immediate: true,
deep: true,
handler (n, o) {
this.isEdit = true
this.editipam = JSON.parse(JSON.stringify(n))
}
},
'editipam.dc': function (n, o) {
this.editipam.dcId = n.id
}
}
}
</script>

View File

@@ -865,7 +865,7 @@ export default {
this.select_list.forEach(val => {
if (typeof (val.val) !== 'undefined' && val.val != null) {
if (val.type === 'select') {
if (val.label === 'alertType' || val.label === 'promType') {
if (val.label === 'alertType' || val.label === 'promType' || val.label === 'ipamType') {
objectInfo.type = val.valnum
} else if (val.label === 'assetState') {
objectInfo.state = val.valnum

View File

@@ -253,6 +253,10 @@ const searchSelectInfo = { // value: 传给后台的值label显示给用
name: 'SNMP trap',
searchType: 'alertTypes'
}
],
ipamType: [
{ label: 'IPV4', value: 4 },
{ label: 'IPV6', value: 6 }
]
}
export default searchSelectInfo

View File

@@ -0,0 +1,151 @@
<template>
<el-table
id="modelTable"
ref="dataTable"
:data="tableData"
:height="height"
border
@header-dragend="dragend"
@sort-change="tableDataSort"
@selection-change="selectionChange"
>
<el-table-column
:resizable="false"
align="center"
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitle"
v-if="item.show"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:sortable="item.sortable"
:width="`${item.width}`"
>
<template slot="header">
<span class="data-column__span">{{item.label}}</span>
<div class="col-resize-area"></div>
</template>
<template slot-scope="scope" :column="item">
<span v-if="item.prop === 'dc'">{{scope.row[item.prop]?scope.row[item.prop].name:'-'}}</span>
<span v-else-if="item.prop === 'CIDR'">
<template>{{ scope.row.addr }} / {{scope.row.mask}}</template>
</span>
<span v-else-if="item.prop === 'type'">
<template v-if="scope.row.type === 4">IPV4</template>
<template v-else-if="scope.row.type === 6">IPV6</template>
</span>
<span v-else-if="scope.row[item.prop]">{{scope.row[item.prop]}}</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column
:resizable="false"
:width="operationWidth"
fixed="right">
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
<button class="table-operation-item" @click="$emit('edit', scope.row)"><i class="nz-icon nz-icon-edit"></i></button>
<el-dropdown size="medium" trigger="click" @command="tableOperation">
<div class="table-operation-item table-operation-item--more">
<i class="nz-icon nz-icon-more3"></i>
</div>
<el-dropdown-menu slot="dropdown" class="right-box-select-top right-public-box-dropdown-top">
<el-dropdown-item :command="['copy', scope.row]"><i class="nz-icon nz-icon-override"></i><span class="operation-dropdown-text">{{$t('overall.duplicate')}}</span></el-dropdown-item>
<el-dropdown-item :command="['delete', scope.row]"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('overall.delete')}}</span></el-dropdown-item>
<el-dropdown-item :command="['sync', scope.row]"><i class="nz-icon nz-icon-sync"></i><span class="operation-dropdown-text">{{$t('overall.syncChart')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
<template slot="empty">
<div v-if="!loading" class="table-no-data">
<svg class="icon" aria-hidden="true">
<use xlink:href="#nz-icon-no-data-list"></use>
</svg>
<div class="table-no-data__title">No results found</div>
</div>
<div v-else>&nbsp;</div>
</template>
</el-table>
</template>
<script>
import table from '@/components/common/mixin/table'
export default {
name: 'ipamTable',
mixins: [table],
props: {
loading: Boolean
},
data () {
return {
tableTitle: [ // 原始table列
{
label: 'ID',
prop: 'id',
show: true,
width: 80,
sortable: 'custom'
}, {
label: this.$t('overall.name'),
prop: 'name',
show: true,
minWidth: 200,
sortable: 'custom'
}, {
label: this.$t('overall.type'),
prop: 'type',
show: true,
width: 200,
sortable: 'custom'
}, {
label: 'CIDR',
prop: 'CIDR',
show: true,
minWidth: 200,
sortable: 'custom'
}, {
label: this.$t('overall.vlan'),
prop: 'vlan',
show: true,
width: 200
}, {
label: this.$t('overall.dc'),
prop: 'dc',
show: true,
width: 200,
sortable: 'custom'
}, {
label: this.$t('overall.remark'),
prop: 'remark',
minWidth: 200,
show: true
}
]
}
},
methods: {
tableDataSort (item) {
let orderBy = ''
const str = item.prop
if (str === 'dc') {
orderBy = str
}
if (item.order === 'ascending') {
orderBy = str
}
if (item.order === 'descending') {
orderBy = '-' + str
}
this.$emit('orderBy', orderBy)
}
}
}
</script>

View File

@@ -0,0 +1,143 @@
<template>
<div>
<nz-data-list
ref="dataList"
:api="url"
:custom-table-title.sync="tools.customTableTitle"
:from="fromRoute.ipam"
:layout="['searchInput', 'elementSet', 'pagination']"
:search-msg="searchMsg"
@search="search"
>
<template v-slot:top-tool-right>
<button id="account-add" :title="$t('overall.createipam')" class="top-tool-btn margin-r-10"
type="button" @click="add">
<i class="nz-icon-create-square nz-icon"></i>
</button>
<top-tool-more-options
:delete-objs="batchDeleteObjs"
ref="export"
id="ipam"
:params="searchLabel"
:permissions="{
import: 'asset_add',
export: 'asset_edit'
}"
class="top-tool-export margin-r-10"
export-file-name="ipam"
export-url="/ipam/subnet/export"
import-url="/ipam/subnet/import"
@afterImport="getTableData"
>
<template v-slot:before>
<div>
<el-dropdown-item>
<delete-button :type="'link'" :title="$t('overall.batchDel')" id="account-list-batch-delete" :api="url" :delete-objs="batchDeleteObjs" @after="getTableData" @before="delFlag=true"></delete-button>
</el-dropdown-item>
</div>
</template>
</top-tool-more-options>
</template>
<template v-slot="slotProps">
<ipam-table
ref="dataTable"
v-loading="tools.loading"
:loading="tools.loading"
:api="url"
:custom-table-title="tools.customTableTitle"
:height="mainTableHeight"
:table-data="tableData"
@del="del"
@edit="edit"
@copy="copy"
@orderBy="tableDataSort"
@reload="getTableData"
@selectionChange="selectionChange"
@showBottomBox="(targetTab, object) => { $refs.dataList.showBottomBox(targetTab, object) }"></ipam-table>
</template>
<template v-slot:pagination>
<Pagination ref="Pagination" :page-obj="pageObj" :table-id="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
</template>
</nz-data-list>
<transition name="right-box">
<ipam-box v-if="rightBox.show" :obj="object" @close="closeRightBox"></ipam-box>
</transition>
</div>
</template>
<script>
import deleteButton from '@/components/common/deleteButton'
import ipamBox from '@/components/common/rightBox/ipamBox'
import nzDataList from '@/components/common/table/nzDataList'
import dataListMixin from '@/components/common/mixin/dataList'
import ipamTable from '@/components/common/table/settings/ipamTable'
import topToolMoreOptions from '@/components/common/popBox/topToolMoreOptions'
export default {
name: 'ipam',
components: {
nzDataList,
ipamBox,
ipamTable,
deleteButton,
topToolMoreOptions
},
mixins: [dataListMixin],
data () {
return {
url: 'ipam/subnet',
blankObject: { // 空白对象
id: '',
name: '',
type: 4,
addr: '',
mask: '',
vlan: '',
remark: '',
dc: { id: '', name: '' }
},
tableId: 'ipamTable',
searchMsg: { // 给搜索框子组件传递的信息
searchLabelList: [
{
name: 'ID',
type: 'input',
label: 'ids',
disabled: false
},
{
name: this.$t('overall.name'),
type: 'input',
label: 'name',
disabled: false
}, {
name: this.$t('overall.type'),
type: 'select',
label: 'ipamType',
disabled: false
}, {
name: this.$t('overall.addr'),
type: 'input',
label: 'addr',
disabled: false
}, {
name: this.$t('overall.mask'),
type: 'input',
label: 'mask',
disabled: false
}, {
name: this.$t('overall.vlan'),
type: 'input',
label: 'vlan',
disabled: false
}, {
name: this.$t('overall.dc'),
type: 'input',
label: 'dcId',
disabled: false
}
]
}
}
}
}
</script>

View File

@@ -98,6 +98,10 @@ export default new Router({
path: '/about',
component: resolve => require(['../components/page/config/about.vue'], resolve)
},
{
path: '/ipam',
component: resolve => require(['../components/page/config/ipam.vue'], resolve)
},
{
path: '/profile',
component: resolve => require(['../components/page/config/profile.vue'], resolve)