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/panelBox.vue

136 lines
4.0 KiB
Vue
Raw Normal View History

2021-03-19 18:52:19 +08:00
<template>
2021-05-11 22:29:14 +08:00
<div v-clickoutside="{obj:editPanel,func:clickOutside}" class="right-box right-box-panel">
<!-- begin--标题-->
<div class="right-box__header">
<div class="header__title">{{editPanel.id ? ($t("dashboard.panel.editPanelTitle")) : $t("dashboard.panel.createPanelTitle")}}</div>
2021-05-11 22:29:14 +08:00
<div class="header__operation">
<span v-cancel="{obj: editPanel, 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 ref="form" :model="editPanel" :rules="rules" label-position = "top" label-width="120px" size="small">
<el-form-item :label='$t("overall.name")' prop="name">
<el-input id="dc-box-input-name" v-model="editPanel.name" maxlength="64" placeholder="" show-word-limit size="small"></el-input>
2020-01-20 17:32:03 +08:00
</el-form-item>
</el-form>
2020-12-14 20:25:24 +08:00
</div>
</div>
2021-05-11 22:29:14 +08:00
<!--底部按钮-->
<div class="right-box__footer">
<button id="dc-box-esc" v-cancel="{obj:editPanel, func:esc}" class="footer__btn footer__btn--light">
<span>{{$t('overall.cancel')}}</span>
</button>
<button id="dc-box-save" :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" class="footer__btn" @click="save">
<span>{{$t('overall.save')}}</span>
</button>
</div>
</div>
</template>
2021-05-11 22:29:14 +08:00
<script>
2021-07-05 14:43:47 +08:00
import editRigthBox from '../mixin/editRigthBox'
2021-03-19 18:52:19 +08:00
export default {
name: 'panelBox',
props: {
2021-05-11 22:29:14 +08:00
obj: {
type: Object
}
2021-03-19 18:52:19 +08:00
},
2021-07-05 14:43:47 +08:00
mixins: [editRigthBox],
2021-03-19 18:52:19 +08:00
data () {
return {
2021-05-12 16:19:43 +08:00
url: 'visual/panel',
2021-05-11 22:29:14 +08:00
editPanel: {},
rules: {
name: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
]
}
2021-03-19 18:52:19 +08:00
}
},
methods: {
2021-05-11 22:29:14 +08:00
/* 关闭弹框 */
esc (refresh) {
this.prevent_opt.save = false
this.$emit('close', refresh)
2021-03-19 18:52:19 +08:00
},
2021-05-11 22:29:14 +08:00
clickOutside () {
this.esc(false)
},
2021-05-11 22:29:14 +08:00
/* 保存 */
save () {
if (this.prevent_opt.save) {
return
}
this.prevent_opt.save = true
this.$refs.form.validate((valid) => {
2021-03-19 18:52:19 +08:00
if (valid) {
2021-05-11 22:29:14 +08:00
if (this.editPanel.id) {
this.$put(this.url, this.editPanel).then(response => {
this.prevent_opt.save = false
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
2021-05-11 22:29:14 +08:00
this.esc(true)
2021-03-19 18:52:19 +08:00
} else {
this.$message.error(response.msg)
}
})
} else {
2021-05-11 22:29:14 +08:00
this.$post(this.url, this.editPanel).then(response => {
this.prevent_opt.save = false
2021-03-19 18:52:19 +08:00
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
2021-05-11 22:29:14 +08:00
this.esc(true)
2021-03-19 18:52:19 +08:00
} else {
this.$message.error(response.msg)
}
})
}
} else {
2021-05-11 22:29:14 +08:00
this.prevent_opt.save = false
2021-03-19 18:52:19 +08:00
return false
}
})
},
2021-05-11 22:29:14 +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(() => {
this.$delete(`${this.url}?ids=${this.editPanel.id}`).then(response => {
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
})
2021-03-19 18:52:19 +08:00
}
},
watch: {
2021-05-11 22:29:14 +08:00
obj: {
immediate: true,
deep: true,
handler (n, o) {
2021-07-05 14:43:47 +08:00
if (n.id) {
this.isEdit = true
}
2021-05-11 22:29:14 +08:00
this.editPanel = JSON.parse(JSON.stringify(n))
}
}
}
2021-03-19 18:52:19 +08:00
}
</script>