Vue.component("node-schedule-conds-box", { props: ["value", "v-params", "v-operators"], mounted: function () { this.formatConds(this.condsConfig.conds) this.$forceUpdate() }, data: function () { let condsConfig = this.value if (condsConfig == null) { condsConfig = { conds: [], connector: "and" } } if (condsConfig.conds == null) { condsConfig.conds = [] } let paramMap = {} this.vParams.forEach(function (param) { paramMap[param.code] = param }) let operatorMap = {} this.vOperators.forEach(function (operator) { operatorMap[operator.code] = operator.name }) return { condsConfig: condsConfig, params: this.vParams, paramMap: paramMap, operatorMap: operatorMap, operator: "", isAdding: false, paramCode: "", param: null, valueBandwidth: { count: 100, unit: "mb" }, valueTraffic: { count: 1, unit: "gb" }, valueCPU: 80, valueMemory: 90, valueLoad: 20, valueRate: 0 } }, watch: { paramCode: function (code) { if (code.length == 0) { this.param = null } else { this.param = this.params.$find(function (k, v) { return v.code == code }) } this.$emit("changeparam", this.param) } }, methods: { add: function () { this.isAdding = true }, confirm: function () { if (this.param == null) { teaweb.warn("请选择参数") return } if (this.param.operators != null && this.param.operators.length > 0 && this.operator.length == 0) { teaweb.warn("请选择操作符") return } if (this.param.operators == null || this.param.operators.length == 0) { this.operator = "" } let value = null switch (this.param.valueType) { case "bandwidth": { if (this.valueBandwidth.unit.length == 0) { teaweb.warn("请选择带宽单位") return } let count = parseInt(this.valueBandwidth.count.toString()) if (isNaN(count)) { count = 0 } if (count < 0) { count = 0 } value = { count: count, unit: this.valueBandwidth.unit } } break case "traffic": { if (this.valueTraffic.unit.length == 0) { teaweb.warn("请选择带宽单位") return } let count = parseInt(this.valueTraffic.count.toString()) if (isNaN(count)) { count = 0 } if (count < 0) { count = 0 } value = { count: count, unit: this.valueTraffic.unit } } break case "cpu": let cpu = parseInt(this.valueCPU.toString()) if (isNaN(cpu)) { cpu = 0 } if (cpu < 0) { cpu = 0 } if (cpu > 100) { cpu = 100 } value = cpu break case "memory": let memory = parseInt(this.valueMemory.toString()) if (isNaN(memory)) { memory = 0 } if (memory < 0) { memory = 0 } if (memory > 100) { memory = 100 } value = memory break case "load": let load = parseInt(this.valueLoad.toString()) if (isNaN(load)) { load = 0 } if (load < 0) { load = 0 } value = load break case "rate": let rate = parseInt(this.valueRate.toString()) if (isNaN(rate)) { rate = 0 } if (rate < 0) { rate = 0 } value = rate break } this.condsConfig.conds.push({ param: this.param.code, operator: this.operator, value: value }) this.formatConds(this.condsConfig.conds) this.cancel() }, cancel: function () { this.isAdding = false this.paramCode = "" this.param = null }, remove: function (index) { this.condsConfig.conds.$remove(index) }, formatConds: function (conds) { let that = this conds.forEach(function (cond) { switch (that.paramMap[cond.param].valueType) { case "bandwidth": cond.valueFormat = cond.value.count + cond.value.unit[0].toUpperCase() + cond.value.unit.substring(1) + "ps" return case "traffic": cond.valueFormat = cond.value.count + cond.value.unit.toUpperCase() return case "cpu": cond.valueFormat = cond.value + "%" return case "memory": cond.valueFormat = cond.value + "%" return case "load": cond.valueFormat = cond.value return case "rate": cond.valueFormat = cond.value + "/秒" return } }) } }, template: `
{{paramMap[cond.param].name}} {{operatorMap[cond.operator]}} {{cond.valueFormat}}     
参数

{{param.description}}

操作符
{{param.valueName}}
%
%
/秒
  取消
` })