cmc-web/webs/cmp-web/src/views/resource/switch/page/alias.vue

294 lines
9.8 KiB
Vue
Raw Normal View History

2024-08-20 12:11:31 +00:00
<template>
<div>
<el-card class="wrapper" v-if="!detailFlag">
<table-search :configs="searchConfigs" :onSearch="handleSearch" ref="search">
<template v-slot:operate>
<el-button type="primary" @click="handleCreate()"></el-button>
</template>
</table-search>
<cb-table :data="tableData" :params="params" :get-list="getList" :total="total">
<el-table-column label="名称" show-overflow-tooltip prop="name"></el-table-column>
<el-table-column label="所属交换机" show-overflow-tooltip prop="fabricName"></el-table-column>
<el-table-column label="成员" show-overflow-tooltip>
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.members" :key="index">
2024-08-21 01:17:14 +00:00
<span style="display: inline-block; width: 80px">类型{{ item.type | switchType }}</span> 地址{{ item.name }}
2024-08-20 12:11:31 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button type="text" @click="handleDelete(scope.row.id)"><i class="el-icon-delete"></i> 删除</el-button>
</template>
</el-table-column>
</cb-table>
<el-dialog title="新增" :visible.sync="addFlag" v-if="addFlag" width="60%">
<el-row>
<cb-form ref="addData" :model="addData" :cb-status-icon="true" label-width="110px">
<el-col :span="24">
<cb-form-item label="交换机:" prop="fabricId" :rules="[required]">
<el-select clearable v-model="addData.fabricId" @change="changeFabric">
2024-08-21 01:17:14 +00:00
<el-option v-for="item in fabricData" :key="item.id" :label="item.name" :value="item.id"> </el-option>
2024-08-20 12:11:31 +00:00
</el-select>
</cb-form-item>
</el-col>
<el-col :span="24">
<cb-form-item label="名称:" prop="name" :rules="[required]">
<el-input v-model="addData.name"></el-input>
</cb-form-item>
</el-col>
<el-col :span="24">
<cb-form-item label="添加成员:">
<el-card>
<cb-form ref="member" :model="member" :cb-status-icon="true" label-width="80px">
<el-col :span="10">
<cb-form-item label="类型:" prop="type">
<el-select v-model="member.type" @change="changeType">
<el-option label="wwn" value="wwn"></el-option>
<el-option label="端口号" value="switch_port"></el-option>
</el-select>
</cb-form-item>
</el-col>
<el-col :span="10">
<cb-form-item v-if="member.type == 'wwn'" :key="1" label="地址:" prop="name" :rules="[wwpn]">
<el-input v-model="member.name"></el-input>
</cb-form-item>
<cb-form-item v-else :key="2" label="地址:" prop="name">
<el-tooltip class="item" effect="dark" content="格式为domain id, port id" placement="top-start">
<el-input v-model="member.name" label="格式为domain id, port id"></el-input>
</el-tooltip>
</cb-form-item>
</el-col>
<el-col :span="3">
<el-button class="m-l" type="ghost" @click="addPort"></el-button>
</el-col>
</cb-form>
</el-card>
</cb-form-item>
</el-col>
<el-col :span="24">
<cb-form-item>
<cb-table :data="membersData">
<el-table-column label="类型" prop="type">
<template slot-scope="scope">
2024-08-21 01:17:14 +00:00
{{ scope.row.type }}
2024-08-20 12:11:31 +00:00
</template>
</el-table-column>
<el-table-column label="地址" prop="name">
<template slot-scope="scope">
2024-08-21 01:17:14 +00:00
{{ scope.row.name }}
2024-08-20 12:11:31 +00:00
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button type="text" @click="deletePort(scope.$index)"></el-button>
</template>
</el-table-column>
<div slot="pagination"></div>
</cb-table>
</cb-form-item>
</el-col>
</cb-form>
</el-row>
<span slot="footer" class="dialog-footer">
2024-08-21 01:17:14 +00:00
<el-button type="ghost" @click.native="addFlag = false"> </el-button>
<el-button type="primary" @click.native="addSubmit"> </el-button>
</span>
2024-08-20 12:11:31 +00:00
</el-dialog>
</el-card>
</div>
</template>
<script>
import validate from '@/validate'
import { getZone, createZone, removeZone, getSwitches } from '../services/switch'
export default {
props: {
platformObject: {
type: Object,
default: function () {
return {
vendorId: -1,
operate: -1
}
}
}
},
2024-08-21 01:17:14 +00:00
data() {
2024-08-20 12:11:31 +00:00
return {
required: validate.required,
wwpn: validate.wwpn,
searchConfigs: [
{ type: 'Input', label: '名称', value: 'name' },
{ type: 'Const', value: 'vendorId', initValue: this.platformObject.vendorId },
{ type: 'Const', value: 'type', initValue: 'alias' }
],
params: {
page: 1,
rows: 10
},
listQuery: {
name: ''
},
tableData: [],
total: 0,
detailFlag: false,
addFlag: false,
addData: {},
fabricData: [],
portNum: 0,
member: {},
membersData: []
}
},
methods: {
2024-08-21 01:17:14 +00:00
changeFabric(value) {
2024-08-20 12:11:31 +00:00
this.fabricData.forEach(item => {
if (item.id == value) {
this.portNum = item.portNum - 1
}
})
},
2024-08-21 01:17:14 +00:00
changeType(value) {
2024-08-20 12:11:31 +00:00
if (!this.addData.fabricId) {
this.member.type = ''
return this.$message.error('请先选择交换机!')
}
this.member.name = ''
},
2024-08-21 01:17:14 +00:00
getList() {
2024-08-20 12:11:31 +00:00
getZone(this.params).then(data => {
if (data.success) {
this.tableData = data.data.rows
this.total = data.data.total
}
})
},
2024-08-21 01:17:14 +00:00
handleSearch(params) {
2024-08-20 12:11:31 +00:00
this.params.page = 1
this.params.params = params || this.params.params
if (this.platformObject.vendorId > -1) {
2024-08-21 01:17:14 +00:00
this.getList()
2024-08-20 12:11:31 +00:00
}
},
2024-08-21 01:17:14 +00:00
handleCreate() {
2024-08-20 12:11:31 +00:00
this.member = {
type: '',
name: ''
}
this.portNum = 0
this.addData = {
vendorId: this.platformObject.vendorId,
fabricId: ''
}
2024-08-21 01:17:14 +00:00
this.membersData = []
this.getFabricData()
this.addFlag = true
2024-08-20 12:11:31 +00:00
},
2024-08-21 01:17:14 +00:00
addPort() {
this.$refs.member.validate(valid => {
2024-08-20 12:11:31 +00:00
if (valid) {
if (this.member.type == '' || this.member.name == '') {
return this.$message.error('成员信息输入不完整!')
}
const membersData = []
for (let i = 0; i < this.membersData.length; i++) {
const obj = this.membersData[i]
membersData.push({
type: obj.type,
name: obj.name.toString().toLowerCase()
})
}
const member = JSON.stringify({
type: this.member.type,
name: this.member.name.toString().toLowerCase()
})
if (JSON.stringify(membersData).indexOf(member) == -1) {
this.membersData.push(this.member)
this.member = {
type: '',
name: ''
2024-08-21 01:17:14 +00:00
}
2024-08-20 12:11:31 +00:00
} else {
return this.$message.info('同一个成员不能添加多次wwn不区分大小写')
}
}
})
},
2024-08-21 01:17:14 +00:00
deletePort(index) {
2024-08-20 12:11:31 +00:00
this.membersData.splice(index, 1)
},
2024-08-21 01:17:14 +00:00
addSubmit() {
this.$refs.addData.validate(valid => {
2024-08-20 12:11:31 +00:00
if (valid) {
if (!this.membersData.length) {
return this.$message.error('新增别名,至少需要一个成员')
}
2024-08-21 01:17:14 +00:00
const addData = [
{
vendorId: this.addData.vendorId,
fabricId: this.addData.fabricId,
type: 'alias',
name: this.addData.name,
members: this.membersData
}
]
2024-08-20 12:11:31 +00:00
createZone(addData).then(data => {
if (data.success) {
this.$notify({
message: data.message,
type: 'success'
2024-08-21 01:17:14 +00:00
})
this.addFlag = false
this.getList()
2024-08-20 12:11:31 +00:00
}
})
}
})
},
2024-08-21 01:17:14 +00:00
getFabricData() {
2024-08-20 12:11:31 +00:00
getSwitches({
simple: true,
params: JSON.stringify([{ param: { vendorId: this.platformObject.vendorId }, sign: 'EQ' }])
}).then(data => {
if (data.success) {
this.fabricData = data.data.rows
}
})
},
2024-08-21 01:17:14 +00:00
handleDelete(id) {
2024-08-20 12:11:31 +00:00
this.$confirm('您确认要删除吗?', '提示', {
confirmButtonClass: 'el-button--danger',
type: 'warning'
})
2024-08-21 01:17:14 +00:00
.then(() => {
removeZone(id).then(data => {
if (data.success) {
this.$message.success({
message: data.message,
type: 'success'
})
this.getList()
}
})
})
.catch(() => {})
2024-08-20 12:11:31 +00:00
}
},
2024-08-21 01:17:14 +00:00
created() {},
mounted() {},
2024-08-20 12:11:31 +00:00
watch: {
platformObject: {
2024-08-21 01:17:14 +00:00
handler(newVal, oldVal) {
2024-08-20 12:11:31 +00:00
this.searchConfigs = [
{ type: 'Input', label: '名称', value: 'name' },
{ type: 'Const', value: 'vendorId', initValue: newVal.vendorId },
{ type: 'Const', value: 'type', initValue: 'alias' }
]
},
deep: true
}
}
}
</script>