/* 流量预警 */
const trafficWarning = {
template: `
{{lang.flow_warn_text3}}
{{lang.flow_warn_text1}}{{tempValue}}%{{lang.flow_warn_text2}}
{{lang.flow_warn_text3}}
{{lang.flow_warn_text5}}
`,
data() {
return {
visible: false,
submitLoading: false,
rules: {
leave_percent: [
{required: true, message: lang.placeholder_pre2, trigger: "change"},
],
},
warningForm: {
module: "",
warning_switch: 1,
leave_percent: "",
},
tempValue: 0,
tempData: {},
};
},
computed: {},
props: {
module: {
type: String,
default: "mf_cloud", // 目前支持 mf_cloud mf_dcim
},
},
watch: {},
created() {
this.getWarningConfig();
},
methods: {
async getWarningConfig() {
try {
const res = await getTrafficWarning({
module: this.module,
});
const temp = res.data.data;
this.tempValue = temp.leave_percent;
temp.leave_percent = temp.leave_percent || "";
this.warningForm = temp;
this.tempData = JSON.parse(JSON.stringify(temp));
} catch (error) {
this.$message.error(error.message);
}
},
handleConfig() {
this.visible = true;
Object.assign(this.warningForm, this.tempData);
},
closeDialog() {
this.visible = false;
},
submit() {
this.$refs.ruleForm.validate(async (valid) => {
if (valid) {
const params = {
module: this.module,
warning_switch: this.warningForm.warning_switch,
leave_percent: this.warningForm.leave_percent,
};
if (params.warning_switch === 0) {
params.leave_percent = 0;
}
this.submitLoading = true;
const res = await saveTrafficWarning(params);
this.submitLoading = false;
this.visible = false;
this.$message.success(res.data.msg);
this.getWarningConfig();
} else {
return false;
}
});
},
},
};