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/common/rightBox/cabinetBox.vue

145 lines
4.9 KiB
Vue
Raw Normal View History

<template>
2021-01-18 18:58:57 +08:00
<div class="right-box right-box-cabinet" v-clickoutside="{obj:editCabinet,func:clickOutside}">
<!-- begin--顶部按钮-->
2020-10-15 14:27:46 +08:00
<div class="right-box-top-btns right-box-form-delete">
<button @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien" id="cab-del" type="button" v-has="'dc_cabinet_delete'" v-if="!editCabinet.id">
2020-09-10 17:00:32 +08:00
<span class="right-box-top-btn-icon"><i class="nz-icon nz-icon-delete"></i></span>
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
</button>
</div>
<!-- end--顶部按钮-->
<!-- begin--标题-->
<div class="right-box-title">{{editCabinet.id ? $t("config.dc.editCabinet") : $t("overall.createCabinet")}}</div>
<!-- end--标题-->
<!-- begin--表单-->
2020-12-14 20:25:24 +08:00
<div class="right-box-form-box">
<el-form class="right-box-form right-box-form-left" label-width="120px" label-position = "top" :model="editCabinet" ref="cabinetForm" :rules="rules">
<el-form-item :label="$t('overall.name')" prop="name">
2021-02-04 11:21:00 +08:00
<el-input size='mini' v-model="editCabinet.name" id="cabinet-box-input-name"/>
</el-form-item>
<el-form-item :label="$t('config.dc.dc')" prop="idcId">
2021-02-04 11:21:00 +08:00
<el-input size='mini' v-model="currentDc.name" disabled id="cabinet-box-input-dc"/>
</el-form-item>
<el-form-item :label="$t('asset.uSize')" prop="uSize">
2021-02-04 11:21:00 +08:00
<el-input v-model.number="editCabinet.uSize" :max="47" id="cabinet-box-input-uSize"></el-input>
</el-form-item>
<el-form-item :label="$t('config.dc.remark')">
2021-02-04 11:21:00 +08:00
<el-input size='mini' v-model="editCabinet.remark" type="textarea" :rows="2" id="cabinet-box-input-remark"/>
</el-form-item>
</el-form>
2020-12-14 20:25:24 +08:00
</div>
<!--底部按钮-->
<div class="right-box__footer">
<button v-cancel="{obj:editCabinet,func:esc}" id="cab-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="cab-box-save">
<span>{{$t('overall.save')}}</span>
</button>
</div>
</div>
</template>
<script>
2021-03-19 18:52:19 +08:00
export default {
name: 'cabinetBox',
props: {
obj: { type: Object },
2021-03-19 18:52:19 +08:00
currentDc: { type: Object }
},
data () {
return {
editCabinet: {},
rules: {
name: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
uSize: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
{ type: 'number', min: 1, max: 47, message: this.$t('validate.uSize'), trigger: 'blur' }
]
}
}
},
methods: {
clickOutside () {
this.esc(false)
},
esc (refresh) {
this.prevent_opt.save = false
this.$emit('close', refresh)
},
save () {
if (this.prevent_opt.save) { return } ;
this.prevent_opt.save = true
this.$refs.cabinetForm.validate(valid => {
if (valid) {
this.editCabinet.idcId = this.currentDc.id
if (this.editCabinet.id) {
2021-05-10 15:45:18 +08:00
this.$put('/dc/cabinet', this.editCabinet).then(res => {
2021-03-19 18:52:19 +08:00
this.prevent_opt.save = false
if (res.code === 200) {
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
} else {
2021-03-19 18:52:19 +08:00
this.$message.error(res.msg)
}
2021-03-19 18:52:19 +08:00
})
} else {
2021-05-10 15:45:18 +08:00
this.$post('/dc/cabinet', this.editCabinet).then(res => {
2021-03-19 18:52:19 +08:00
this.prevent_opt.save = false
if (res.code === 200) {
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
} else {
this.$message.error(res.msg)
}
})
2021-03-19 18:52:19 +08:00
}
} else {
this.prevent_opt.save = false
return false
}
2021-03-19 18:52:19 +08:00
})
},
del () {
if (this.prevent_opt.save) { return } ;
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-04-30 17:02:43 +08:00
this.$delete('dc/cabinet?ids=' + this.editCabinet.id).then(response => {
2021-03-19 18:52:19 +08:00
this.prevent_opt.save = false
if (response.code == 200) {
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
} else {
this.$message.error(response.msg)
}
2021-03-19 18:52:19 +08:00
})
}).catch(() => {
this.prevent_opt.save = false
})
}
},
watch: {
obj: {
2021-03-19 18:52:19 +08:00
deep: true,
immediate: true,
handler: function (n, o) {
if (n) {
this.editCabinet = JSON.parse(JSON.stringify(n))
}
}
}
2021-03-19 18:52:19 +08:00
}
}
</script>
<style >
</style>