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/page/config/dc.vue

354 lines
13 KiB
Vue
Raw Normal View History

2020-02-21 17:57:19 +08:00
<template>
<div style="height: 100%">
<nz-data-list
ref="dataList"
:components="['searchInput', 'elementSet']"
:custom-table-title.sync="tools.customTableTitle"
:from="fromRoute.dc"
:search-msg="searchMsg"
:table-id="tableId"
:table-title="tableTitle">
<template v-slot:top-tool-right>
<button id="dc-add" v-has="'dc_toAdd'" :title="$t('overall.createDatacenter')" class="top-tool-btn margin-l-20"
type="button" @click="add">
<i class="nz-icon-create-square nz-icon"></i>
</button>
<delete-button id="account-list-batch-delete" v-has="'dc_delete'" :delete-objs="batchDeleteObjs" api="dc" @after="getTableData" @before="delFlag=true"></delete-button>
</template>
<template v-slot:default="slotProps">
<el-table
id="dc-list-table"
ref="dataTable"
v-loading="tools.loading"
:data="tableData"
:height="mainTableHeight"
:cell-class-name="assetStatClassName"
border
@header-dragend="dragend"
@sort-change="tableDataSort"
@selection-change="(selection)=>{batchDeleteObjs=selection}"
>
<el-table-column
:resizable="false"
align="center"
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in tools.customTableTitle"
v-if="item.show"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:sortable="sortableShow(item.prop, fromRoute.dc)"
:width="`${item.width}`"
class="data-column"
>
<template slot="header">
<span>
<span>{{item.label}}</span>
<div class="col-resize-area"></div>
</span>
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop === 'principal'">
<template v-if="scope.row.principal">
<template v-for="item in userData">
<template v-if="scope.row.principal == item.userId">{{item.username}}</template>
</template>
2020-03-25 18:38:13 +08:00
</template>
<template v-else>-</template>
2020-02-21 17:57:19 +08:00
</template>
<template v-else-if="item.prop === 'state'">
<el-switch
v-model="scope.row.state"
:disabled="!hasButton('dc_toEdit') || !hasButton('dc_toEdit')"
active-color="#ee9d3f"
active-value="ON"
inactive-value="OFF"
@change="(val)=>{statusChange(scope.row)}"
/>
</template>
<template v-else-if="item.prop === 'longitude'">
<template v-if="regNumTest(scope.row.longitude)">{{scope.row.longitude}}</template>
<template v-else>-</template>
</template>
<template v-else-if="item.prop === 'latitude'">
<template v-if="regNumTest(scope.row.latitude)">{{scope.row.latitude}}</template>
<template v-else>-</template>
</template>
<template v-else-if="item.prop === 'assetStat' && scope.row.assetStat">
<el-popover
:content="$t('overall.result.total') + '' + scope.row.assetStat.total + '' + $t('asset.inStock') + '' + scope.row.assetStat.inStock + '' + $t('asset.notInStock') + '' + scope.row.assetStat.outStock + '' + $t('asset.suspended') + '' + scope.row.assetStat.suspended"
placement="top"
trigger="hover">
<div slot="reference" class="dc-asset-states">
<span class="dc-asset-state dc-asset-state-total">{{scope.row.assetStat.total}}</span>
<span class="dc-asset-state dc-asset-state-in">{{scope.row.assetStat.inStock}}</span>
<span class="dc-asset-state dc-asset-state-out">{{scope.row.assetStat.outStock}}</span>
<span class="dc-asset-state dc-asset-state-suspended">{{scope.row.assetStat.suspended}}</span>
</div>
</el-popover>
</template >
<template v-else-if="item.prop === 'cabinetNum'">
<span class="link" @click="$refs.dataList.showBottomBox('cabinet', scope.row)">{{scope.row[item.prop]}}</span>
</template>
<template v-else-if="scope.row[item.prop]">{{scope.row[item.prop]}}</template>
<template v-else>-</template>
2020-07-16 17:33:20 +08:00
</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="$refs.dataList.showBottomBox('operationLog', scope.row)"><i class="nz-icon nz-icon-view1"></i></button>
<el-dropdown size="medium" trigger="hover" @command="tableOperation">
<div class="table-operation-item table-operation-item--more">
<span></span><i class="nz-icon nz-icon-arrow-down"></i>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="['edit', scope.row]" :disabled="isBuildIn(scope.row)"><i class="nz-icon nz-icon-edit"></i><span class="operation-dropdown-text">{{$t('overall.edit')}}</span></el-dropdown-item>
<el-dropdown-item :command="['delete', scope.row, `dc?ids=${scope.row.id}`]" :disabled="isBuildIn(scope.row)"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('overall.delete')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
</el-table>
<!-- 回到table顶部的按钮 -->
<button v-show="tools.showTopBtn && slotProps.mainResizeShow" id="dc-list-totop" :class="{'to-top-is-hover': tools.tableHover}" :style="{top: tools.toTopBtnTop}" class="to-top" @click="toTop(scrollbarWrap)"><i class="nz-icon nz-icon-top"></i></button>
</template>
<!-- 分页组件 -->
<template v-slot:pagination>
<Pagination ref="Pagination" :pageObj="pageObj" :tableId="tableId" @pageNo='pageNo' @pageSize='pageSize'></Pagination>
</template>
</nz-data-list>
2020-07-16 17:33:20 +08:00
<transition name="right-box">
<dc-box v-if="rightBox.dc.show" :dc="object" :user-data="userData" @close="closeDcBox" @reload="getTableData"></dc-box>
2020-07-16 17:33:20 +08:00
</transition>
<transition name="right-box">
<traffic-setting-box v-if="rightBox.trafficSetting.show" ref="trafficBox" :dc="object" @close="closeTrafficBox"></traffic-setting-box>
2020-07-16 17:33:20 +08:00
</transition>
<span v-if="dcDataRefresh" style="display: none"></span>
2021-04-08 19:36:14 +08:00
2020-07-16 17:33:20 +08:00
</div>
2020-02-21 17:57:19 +08:00
</template>
<script>
import bus from '@/libs/bus'
import dcBox from '@/components/common/rightBox/dcBox' // dc弹框
import trafficSettingBox from '@/components/common/rightBox/trafficSetting/trafficSettingBox'
import deleteButton from '@/components/common/deleteButton'
import nzDataList from '@/components/common/table/nzDataList'
import tableMixin from '@/components/common/mixin/table'
2021-03-19 18:52:19 +08:00
const regNum = /^[0-9]+.?[0-9]*/
export default {
name: 'dc',
components: {
trafficSettingBox,
dcBox,
deleteButton,
nzDataList
2021-03-19 18:52:19 +08:00
},
mixins: [tableMixin],
2021-03-19 18:52:19 +08:00
data () {
return {
tableId: 'dcTable', // 需要分页的table的id用于记录每页数量
object: {},
blankObject: {
2021-03-19 18:52:19 +08:00
id: '',
name: '',
location: '',
tel: '',
principal: '',
state: 'ON',
longitude: undefined,
latitude: undefined
2020-02-21 17:57:19 +08:00
},
2021-03-19 18:52:19 +08:00
rightBox: {
dc: { show: false },
trafficSetting: { show: false }
2020-02-21 17:57:19 +08:00
},
2021-03-19 18:52:19 +08:00
tableTitle: [
{
label: 'ID',
prop: 'id',
show: true,
width: 80
}, {
label: this.$t('overall.name'),
prop: 'name',
show: true
}, {
label: this.$t('asset.location'),
prop: 'location',
show: true
}, {
label: this.$t('config.dc.cabinetNum'),
prop: 'cabinetNum',
show: true
}, {
label: this.$t('config.dc.assets'),
prop: 'assetStat',
show: true
}, {
label: this.$t('asset.tel'),
prop: 'tel',
show: true
}, {
label: this.$t('asset.principal'),
prop: 'principal',
show: true
}, {
label: this.$t('config.dc.longitude'),
prop: 'longitude',
show: false
}, {
label: this.$t('config.dc.latitude'),
prop: 'latitude',
show: false
}, {
label: this.$t('config.dc.state'),
prop: 'state',
show: true
2020-02-24 20:27:14 +08:00
}
2021-03-19 18:52:19 +08:00
],
searchMsg: { // 给搜索框子组件传递的信息
zheze_none: true,
searchLabelList: [{
id: 10,
name: this.$t('overall.name'),
type: 'input',
label: 'name',
disabled: false
}]
},
2021-03-19 18:52:19 +08:00
tabShow: 1, // 控制显示一级页面和二级页面 1 dc 2cabinet
2021-04-08 19:36:14 +08:00
delFlag: false,
userData: []
2021-03-19 18:52:19 +08:00
}
},
computed: {
dcDataRefresh () { // 通过vuex更新dc 需要该属性到页面 否则不被监听
if (this.$store.getters.getDcDataRefresh) {
this.getTableData()
}
return this.$store.getters.getDcDataRefresh
}
},
methods: {
assetStatClassName (param) {
if (param.column.label == this.$t('config.dc.assets')) {
return 'asset-state'
}
return ''
},
edit (u) {
this.dc = JSON.parse(JSON.stringify(u))
if (!regNum.test(this.dc.longitude)) {
this.dc.longitude = undefined
}
if (!regNum.test(this.dc.latitude)) {
this.dc.latitude = undefined
}
if (!this.dc.area) {
this.$set(this.dc, 'area', { id: '', name: '' })
}
this.rightBox.dc.show = true
},
detail (u) {
this.bottomBox.object = JSON.parse(JSON.stringify(u))
if (!this.bottomBox.object.area) {
this.$set(this.bottomBox.object, 'area', { id: '', name: '' })
2021-03-19 18:52:19 +08:00
}
this.bottomBox.targetTab = 'detail'
this.bottomBox.showSubList = true
},
add () {
this.object = this.newObject()
2021-03-19 18:52:19 +08:00
this.rightBox.dc.show = true
},
closeDcBox (refresh) {
this.rightBox.dc.show = false
if (refresh) {
this.delFlag = true
this.getTableData()
}
},
closeTrafficBox (refresh) {
this.rightBox.trafficSetting.show = false
if (refresh) {
this.delFlag = true
this.getTableData()
}
},
statusChange (idc) {
2021-04-08 19:36:14 +08:00
this.$put('dc', idc).then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.rightBox.show = false
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
} else {
this.$message.error(response.msg)
}
2021-03-19 18:52:19 +08:00
this.getTableData()
})
2020-03-25 18:38:13 +08:00
},
2021-03-19 18:52:19 +08:00
getTableData () {
if (!this.hasButton('dc_view')) {
this.$message.error(this.$t('tip.noAccess'))
return
}
this.$set(this.searchLabel, 'pageNo', this.pageObj.pageNo)
this.$set(this.searchLabel, 'pageSize', this.pageObj.pageSize)
this.tools.loading = true
this.$get('dc', this.searchLabel).then(response => {
2021-03-19 18:52:19 +08:00
this.tools.loading = false
if (response.code === 200) {
this.tableData = response.data.list
this.pageObj.total = response.data.total
if (!this.scrollbarWrap) {
this.$nextTick(() => {
this.scrollbarWrap = this.$refs.dataTable.bodyWrapper
2021-03-19 18:52:19 +08:00
this.toTopBtnHandler(this.scrollbarWrap)
})
2020-07-16 17:33:20 +08:00
}
2020-03-27 15:41:26 +08:00
}
2021-03-19 18:52:19 +08:00
})
},
getUserData () {
return new Promise(resolve => {
2021-04-08 19:36:14 +08:00
this.$get('sys/user', { pageSize: -1, pageNo: 1 }).then(response => {
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.userData = response.data.list
}
2021-03-19 18:52:19 +08:00
resolve()
})
})
},
regNumTest (val) { // 校验是否是数字
return regNum.test(val)
},
initEvent () {
bus.$on('dc-list-change', () => {
this.getTableData()
})
}
},
beforeDestroy () {
bus.$off('dc-list-change')
},
mounted () {
this.getUserData()
2020-02-21 17:57:19 +08:00
}
2021-03-19 18:52:19 +08:00
}
2020-02-21 17:57:19 +08:00
</script>
2020-10-12 13:46:31 +08:00
<style scoped>
/deep/ td .nz-icon-gear:before{
2020-10-12 13:46:31 +08:00
color: #606266;
}
</style>