2020-07-15 20:43:19 +08:00
|
|
|
<template>
|
2021-04-13 20:33:12 +08:00
|
|
|
<div v-clickoutside="{obj:editPromServer,func:clickOutside}" class="right-box right-box-prom">
|
2020-07-15 20:43:19 +08:00
|
|
|
<!-- begin--标题-->
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box__header">
|
2021-05-11 10:37:58 +08:00
|
|
|
<div class="header__title">{{editPromServer.id ? ($t("config.agent.editProm")) : $t("config.agent.createProm")}}</div>
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="header__operation">
|
|
|
|
|
<span v-cancel="{obj: editPromServer, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-07-15 20:43:19 +08:00
|
|
|
<!-- end--标题-->
|
|
|
|
|
<!-- 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">
|
2021-04-30 17:02:43 +08:00
|
|
|
<el-form ref="agentForm" :model="editPromServer" :rules="rules" label-position = "top" label-width="120px">
|
2021-04-30 12:59:36 +08:00
|
|
|
<!--DC-->
|
2021-04-30 17:02:43 +08:00
|
|
|
<el-form-item :label="$t('config.agent.name')" prop="name">
|
2021-04-30 12:59:36 +08:00
|
|
|
<div class="right-box-form-content">
|
|
|
|
|
<el-select id="prom-box-input-dc" v-model="editPromServer.dc" placeholder="" class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside" size="small" value-key="id">
|
|
|
|
|
<el-option v-for="item in dcData" :id="'prom-edit-dc-op-'+item.id" :key="item.id" :label="item.name" :value="item">
|
|
|
|
|
<span class="config-dropdown-label-txt">{{item.name}}</span>
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</div>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<!--host-->
|
|
|
|
|
<el-form-item label="Host" prop="host">
|
|
|
|
|
<el-input id="prom-box-input-host" v-model="editPromServer.host" placeholder="" size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<!--Port-->
|
|
|
|
|
<el-form-item label="Port" prop="port">
|
|
|
|
|
<el-input id="prom-box-input-port" v-model.number="editPromServer.port" placeholder="" size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<!--type-->
|
2021-04-30 17:02:43 +08:00
|
|
|
<el-form-item :label="$t('config.agent.type')" prop="type">
|
2021-04-30 12:59:36 +08:00
|
|
|
<!-- <el-cascader-->
|
|
|
|
|
<!-- id="prom-box-input-type"-->
|
|
|
|
|
<!-- style="width: 100%"-->
|
|
|
|
|
<!-- v-model="editPromServer.type"-->
|
|
|
|
|
<!-- placeholder=""-->
|
|
|
|
|
<!-- size="small"-->
|
2021-04-30 17:02:43 +08:00
|
|
|
<!-- :options="$CONSTANTS.agent.theData"-->
|
2021-04-30 12:59:36 +08:00
|
|
|
<!-- :props="{ multiple: false, checkStrictly: false ,emitPath:false}"-->
|
|
|
|
|
<!-- clearable></el-cascader>-->
|
|
|
|
|
<el-select v-model="editPromServer.type" :disabled="editPromServer.id != null&& editPromServer.id != ''" placeholder="" class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside" size="small" value-key="value">
|
|
|
|
|
<el-option v-for="item in agent2.theData" :key="item.value" :label="item.label" :value="item.value" :disabled="federationEnabled && item.value == 2">
|
|
|
|
|
<span class="panel-dropdown-label-txt" >{{item.label}}</span>
|
2020-07-15 20:43:19 +08:00
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
2021-04-30 12:59:36 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="Token" prop="token">
|
|
|
|
|
<el-input id="prom-box-input-token" v-model="editPromServer.token" class="right-box-row-with-btn" placeholder="" size="small" type="text">
|
|
|
|
|
<i slot="suffix" class="nz-icon nz-icon-refresh" @click="refreshToken"></i>
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
2021-05-11 10:37:58 +08:00
|
|
|
|
2020-12-14 20:25:24 +08:00
|
|
|
</div>
|
2020-07-15 20:43:19 +08:00
|
|
|
<!-- end--表单-->
|
|
|
|
|
<!--底部按钮-->
|
2021-05-11 10:37:58 +08:00
|
|
|
<div class="right-box__footer">
|
2021-04-13 20:33:12 +08:00
|
|
|
<button id="prom-esc" v-cancel="{obj:editPromServer,func:esc}"
|
2021-05-11 10:37:58 +08:00
|
|
|
class="footer__btn footer__btn--light">
|
2020-07-15 20:43:19 +08:00
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
2021-04-13 20:33:12 +08:00
|
|
|
<button id="prom-save" :class="{'nz-btn-disabled':prevent_opt.save}"
|
2021-05-11 10:37:58 +08:00
|
|
|
:disabled="prevent_opt.save" class="footer__btn" @click="save">
|
2020-07-15 20:43:19 +08:00
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
2021-03-19 18:52:19 +08:00
|
|
|
import { host, port } from '../../common/js/validate'
|
2021-04-13 20:33:12 +08:00
|
|
|
import { agent2 } from '@/components/common/js/constants'
|
2021-03-19 18:52:19 +08:00
|
|
|
export default {
|
2021-04-13 20:33:12 +08:00
|
|
|
name: 'agentBox',
|
2021-03-19 18:52:19 +08:00
|
|
|
props: {
|
2021-04-30 17:02:43 +08:00
|
|
|
agent: Object
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2021-04-13 20:33:12 +08:00
|
|
|
agent2: agent2,
|
2021-04-27 20:31:54 +08:00
|
|
|
agentPrometheusEnabled: localStorage.getItem('nz-prometheus-federation-enabled'),
|
2021-03-19 18:52:19 +08:00
|
|
|
rules: {
|
2021-04-13 20:33:12 +08:00
|
|
|
'dc.name': [
|
2021-03-19 18:52:19 +08:00
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
|
|
|
|
],
|
|
|
|
|
host: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
|
|
|
|
{ validator: host, trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
port: [
|
|
|
|
|
{ validator: port, trigger: 'blur' },
|
|
|
|
|
{ required: true, message: this.$t('validate.required') }
|
|
|
|
|
],
|
|
|
|
|
type: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
editPromServer: {},
|
2021-04-29 17:35:07 +08:00
|
|
|
dcData: [], // data center数据
|
|
|
|
|
federationEnabled: !Number(localStorage.getItem('nz-prometheus-federation-enabled'))
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2021-04-09 13:01:10 +08:00
|
|
|
refreshToken: function () {
|
2021-04-15 11:47:44 +08:00
|
|
|
if (!this.editPromServer.token || this.editPromServer.token == '') {
|
|
|
|
|
this.$message.error('The token is empty')
|
|
|
|
|
return
|
2021-04-09 13:01:10 +08:00
|
|
|
}
|
2021-04-15 11:47:44 +08:00
|
|
|
this.$post('agent/token/refresh', this.editPromServer).then(response => {
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
this.editPromServer.token = response.data.token
|
|
|
|
|
} else {
|
2021-04-09 13:01:10 +08:00
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
/* 关闭弹框 */
|
|
|
|
|
esc (refresh) {
|
|
|
|
|
this.$emit('close', refresh)
|
2020-07-15 20:43:19 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
clickOutside () {
|
|
|
|
|
this.esc(false)
|
2020-07-15 20:43:19 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
/* 保存 */
|
|
|
|
|
save () {
|
2021-04-30 17:02:43 +08:00
|
|
|
this.$refs.agentForm.validate(valid => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (valid) {
|
|
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
if (this.editPromServer.id) {
|
2021-04-30 17:02:43 +08:00
|
|
|
this.$put('agent', this.editPromServer).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
2020-07-15 20:43:19 +08:00
|
|
|
} else {
|
2021-04-30 17:02:43 +08:00
|
|
|
this.$post('agent', this.editPromServer).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
}
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
})
|
2020-07-15 20:43:19 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
} else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/* 删除 */
|
|
|
|
|
del () {
|
|
|
|
|
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('agent?ids=' + this.editPromServer.id).then(response => {
|
2020-07-15 20:43:19 +08:00
|
|
|
if (response.code === 200) {
|
2021-03-19 18:52:19 +08:00
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
this.esc(true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error(response.msg)
|
2020-07-15 20:43:19 +08:00
|
|
|
}
|
|
|
|
|
})
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
2020-07-15 20:43:19 +08:00
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
// 获取dc下拉列表数据
|
|
|
|
|
getDcData () {
|
2021-04-13 20:33:12 +08:00
|
|
|
this.$get('dc', { pageSize: -1 }).then(response => {
|
2021-03-19 18:52:19 +08:00
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.dcData = response.data.list
|
2020-07-15 20:43:19 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
// 将prop里的user转为组件内部对象
|
2021-04-30 17:02:43 +08:00
|
|
|
agent: {
|
2021-03-19 18:52:19 +08:00
|
|
|
immediate: true,
|
|
|
|
|
deep: true,
|
|
|
|
|
handler (n) {
|
|
|
|
|
this.editPromServer = JSON.parse(JSON.stringify(n))
|
|
|
|
|
}
|
2020-07-15 20:43:19 +08:00
|
|
|
},
|
2021-04-13 20:33:12 +08:00
|
|
|
'editPromServer.dc': function (n, o) {
|
|
|
|
|
this.editPromServer.dcId = n.id
|
2020-07-15 20:43:19 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
this.getDcData()
|
2020-07-15 20:43:19 +08:00
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
}
|
2020-07-15 20:43:19 +08:00
|
|
|
</script>
|