2020-02-21 17:57:19 +08:00
|
|
|
<template>
|
2021-12-20 11:00:00 +08:00
|
|
|
<div v-clickoutside="{obj:editDc, func: esc}" class="right-box right-box-dc">
|
2020-02-21 17:57:19 +08:00
|
|
|
<!-- begin--标题-->
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box__header">
|
2022-06-21 18:14:21 +08:00
|
|
|
<div class="header__title">{{editDc.id ? ($t("config.dc.editDc")) : $t("overall.createDatacenter")}}</div>
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="header__operation">
|
|
|
|
|
<span v-cancel="{obj: editDc, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-02-21 17:57:19 +08:00
|
|
|
<!-- begin--表单-->
|
2021-04-29 10:56:41 +08:00
|
|
|
<div class="right-box__container">
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="container__form">
|
|
|
|
|
<el-form label-width="120px" size="small" :model="editDc" label-position = "top" :rules="rules" ref="dcForm">
|
|
|
|
|
<el-form-item :label='$t("overall.name")' prop="name">
|
|
|
|
|
<el-input placeholder="" maxlength="64" show-word-limit v-model="editDc.name" size="small" id="dc-box-input-name"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label='$t("asset.location")' prop="location">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input placeholder="" maxlength="256" show-word-limit v-model="editDc.location" size="small" id="dc-box-input-location"></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
2022-06-16 15:58:17 +08:00
|
|
|
<el-form-item :label='$t("config.dc.tel")' prop="tel">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input placeholder="" maxlength="128" show-word-limit v-model="editDc.tel" size="small" id="dc-box-input-tel"></el-input>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
2022-06-16 15:58:17 +08:00
|
|
|
<el-form-item :label='$t("config.dc.principal")' prop="principal">
|
2021-10-29 14:25:59 +08:00
|
|
|
<el-select value-key="id" class="right-box__select" popper-class="right-box-select-top right-public-box-dropdown-top prevent-clickoutside" v-model="editDc.principal" placeholder="" size="small" id="dc-box-input-principal">
|
2021-09-24 14:29:19 +08:00
|
|
|
<el-option v-for="item in userData" :key="item.id" :label="item.name" :value="item.id" style="width: 620px">
|
|
|
|
|
<span class="user-name" :title="item.name">{{item.name}}</span><span class="user-username" :title="item.username">@{{item.username}}</span>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2022-06-23 16:58:18 +08:00
|
|
|
<el-form-item :label="$t('config.system.basic.lnglat')" prop="lnglat">
|
2021-11-05 20:19:26 +08:00
|
|
|
<div style="display: flex">
|
|
|
|
|
<el-input v-model="editDc.lnglat" maxlength="256" placeholder="" size="small" style="width: calc(100% - 50px);margin-right: 20px;"></el-input>
|
|
|
|
|
<latlng-picker
|
|
|
|
|
ref="latlngPicker"
|
|
|
|
|
:append-to-body="false"
|
|
|
|
|
:init-data='editDc.lnglat'
|
|
|
|
|
:show-zoom="false"
|
|
|
|
|
@lnglatChange="lnglatChange"
|
|
|
|
|
></latlng-picker>
|
|
|
|
|
</div>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
2022-06-16 15:58:17 +08:00
|
|
|
<el-form-item :label='$t("overall.state")' prop="state">
|
2021-04-30 12:59:36 +08:00
|
|
|
<el-switch
|
|
|
|
|
id="dc-box-input-name"
|
|
|
|
|
v-model="editDc.state"
|
|
|
|
|
active-value="ON"
|
2021-11-30 16:08:02 +08:00
|
|
|
inactive-value="OFF">
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-switch>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
2020-12-14 20:25:24 +08:00
|
|
|
</div>
|
2020-02-21 17:57:19 +08:00
|
|
|
<!--底部按钮-->
|
2021-05-11 10:37:58 +08:00
|
|
|
<div class="right-box__footer">
|
|
|
|
|
<button v-cancel="{obj:editDc,func:esc}" id="dc-box-esc" class="footer__btn footer__btn--light">
|
2020-02-21 17:57:19 +08:00
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
2021-05-11 10:37:58 +08:00
|
|
|
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="footer__btn" id="dc-box-save">
|
2020-02-21 17:57:19 +08:00
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2020-02-24 20:27:14 +08:00
|
|
|
|
2020-02-21 17:57:19 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-31 11:10:04 +08:00
|
|
|
import latlngPicker from '../latlngPicker'
|
2021-07-05 14:43:47 +08:00
|
|
|
import editRigthBox from '../mixin/editRigthBox'
|
2021-11-05 20:19:26 +08:00
|
|
|
import { noSpecialChar, latlng } from '@/components/common/js/validate'
|
2021-07-05 14:43:47 +08:00
|
|
|
|
2021-11-15 14:05:54 +08:00
|
|
|
const latitudeNum = /^[\-\+]?([1-8]?\d{1}\.\d{1,7}|90\.0{1,7}|[1-8]?\d{1}|90)$/ // 纬度正则验证
|
|
|
|
|
const longitudeNum = /^[\-\+]?(0?\d{1,2}\.\d{1,7}|1[0-7]?\d{1}\.\d{1,7}|180\.0{1,7}|0?\d{1,2}|1[0-7]?\d{1}|180)$/ // 经度正则验证
|
2021-05-28 13:12:05 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'dcBox',
|
2021-03-31 11:10:04 +08:00
|
|
|
components: { latlngPicker },
|
2021-03-19 18:52:19 +08:00
|
|
|
props: {
|
2021-05-11 16:46:16 +08:00
|
|
|
obj: {
|
|
|
|
|
type: Object
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
userData: Array
|
|
|
|
|
},
|
2021-07-05 14:43:47 +08:00
|
|
|
mixins: [editRigthBox],
|
2021-03-19 18:52:19 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
editDc: {},
|
|
|
|
|
rules: {
|
|
|
|
|
name: [
|
2021-11-04 14:24:42 +08:00
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
2021-11-05 20:19:26 +08:00
|
|
|
{ validator: noSpecialChar, trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
lnglat: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
|
|
|
|
{ validator: latlng, trigger: 'blur' }
|
2021-03-19 18:52:19 +08:00
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
areaData: [],
|
|
|
|
|
coordinateFlag: false
|
|
|
|
|
}
|
2021-05-11 16:46:16 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
methods: {
|
|
|
|
|
/* 关闭弹框 */
|
|
|
|
|
esc (refresh) {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
this.$emit('close', refresh)
|
2020-02-21 17:57:19 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
clickOutside () {
|
|
|
|
|
this.esc(false)
|
2020-07-16 17:33:20 +08:00
|
|
|
},
|
2020-02-24 20:27:14 +08:00
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
/* 保存 */
|
2021-05-11 16:46:16 +08:00
|
|
|
save () {
|
2021-03-25 19:33:48 +08:00
|
|
|
if (this.prevent_opt.save) {
|
|
|
|
|
return
|
2021-11-05 20:19:26 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
this.$refs.dcForm.validate((valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
if (this.editDc.id) {
|
2021-03-31 11:10:04 +08:00
|
|
|
const param = { ...this.editDc }
|
|
|
|
|
const attr = this.$refs.latlngPicker.getAttribute()
|
|
|
|
|
param.latitude = attr.latitude
|
|
|
|
|
param.longitude = attr.longitude
|
2021-05-11 16:46:16 +08:00
|
|
|
this.$put('/dc', param).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (response.code === 200) {
|
2022-06-22 11:18:27 +08:00
|
|
|
this.messageShow(this.$t('tip.saveSuccess'), '', { dcId: response.data.id, cabinetBoxShow: true }, false, 'overall.createCabinet', 'addCabinet')
|
2021-03-19 18:52:19 +08:00
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
2020-11-11 13:59:37 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2020-02-21 17:57:19 +08:00
|
|
|
} else {
|
2021-03-31 11:10:04 +08:00
|
|
|
const param = { ...this.editDc }
|
2021-03-19 18:52:19 +08:00
|
|
|
if (param.area) {
|
|
|
|
|
param.areaId = param.area.id
|
2020-02-21 17:57:19 +08:00
|
|
|
}
|
2021-08-23 09:37:09 +08:00
|
|
|
const attr = this.$refs.latlngPicker.getAttribute()
|
|
|
|
|
param.latitude = attr.latitude
|
|
|
|
|
param.longitude = attr.longitude
|
2021-11-15 14:05:54 +08:00
|
|
|
if (!longitudeNum.test(param.longitude)) {
|
2021-03-19 18:52:19 +08:00
|
|
|
param.longitude = null
|
|
|
|
|
}
|
2021-11-15 14:05:54 +08:00
|
|
|
if (!latitudeNum.test(param.latitude)) {
|
2021-03-19 18:52:19 +08:00
|
|
|
param.latitude = null
|
|
|
|
|
}
|
2021-05-11 16:46:16 +08:00
|
|
|
this.$post('/dc', param).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (response.code === 200) {
|
2022-06-22 11:18:27 +08:00
|
|
|
this.messageShow(this.$t('tip.saveSuccess'), '', { dcId: response.data.id, cabinetBoxShow: true }, true, 'overall.createCabinet', 'addCabinet')
|
2021-03-19 18:52:19 +08:00
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
return false
|
2020-11-12 10:42:49 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2020-02-21 17:57:19 +08:00
|
|
|
},
|
2021-11-05 20:19:26 +08:00
|
|
|
lnglatChange (lnglat) {
|
|
|
|
|
this.editDc.lnglat = lnglat
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
/* 删除 */
|
|
|
|
|
del () {
|
2021-11-05 20:19:26 +08:00
|
|
|
if (this.prevent_opt.save) { return }
|
2021-03-19 18:52:19 +08:00
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
2021-05-11 16:46:16 +08:00
|
|
|
this.$delete('/dc' + this.editDc.id).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
2020-02-21 17:57:19 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
selectArea (area) {
|
|
|
|
|
this.editDc.area.id = area.id
|
|
|
|
|
this.editDc.area.name = area.name
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
2021-05-11 16:46:16 +08:00
|
|
|
obj: {
|
2021-03-19 18:52:19 +08:00
|
|
|
immediate: true,
|
|
|
|
|
deep: true,
|
|
|
|
|
handler (n, o) {
|
2021-07-15 11:56:25 +08:00
|
|
|
this.isEdit = true
|
2021-11-05 20:19:26 +08:00
|
|
|
if (!n.id) {
|
2021-12-21 18:28:54 +08:00
|
|
|
this.editDc = { ...JSON.parse(JSON.stringify(n)), lnglat: `${n.longitude},${n.latitude}` }
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.$refs.latlngPicker.setLnglat(this.editDc.latitude, this.editDc.longitude)
|
2021-11-05 20:19:26 +08:00
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.editDc = { ...JSON.parse(JSON.stringify(n)), lnglat: `${n.longitude},${n.latitude}` }
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.$refs.latlngPicker.setLnglat(this.editDc.latitude, this.editDc.longitude)
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
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>
|