Files
EdgeAdmin/web/public/js/components/common/size-capacity-box.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-09-16 09:09:10 +08:00
Vue.component("size-capacity-box", {
props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength"],
2020-09-16 09:09:10 +08:00
data: function () {
let v = this.vValue
if (v == null) {
v = {
count: this.vCount,
unit: this.vUnit
}
}
if (typeof (v["count"]) != "number") {
v["count"] = -1
}
let vSize = this.size
if (vSize == null) {
vSize = 6
}
let vMaxlength = this.maxlength
if (vMaxlength == null) {
vMaxlength = 10
}
2020-09-16 09:09:10 +08:00
return {
capacity: v,
countString: (v.count >= 0) ? v.count.toString() : "",
vSize: vSize,
vMaxlength: vMaxlength
2020-09-16 09:09:10 +08:00
}
},
watch: {
"countString": function (newValue) {
let value = newValue.trim()
if (value.length == 0) {
this.capacity.count = -1
2020-10-04 20:38:27 +08:00
this.change()
2020-09-16 09:09:10 +08:00
return
}
let count = parseInt(value)
if (!isNaN(count)) {
this.capacity.count = count
2020-09-16 09:09:10 +08:00
}
2020-10-04 20:38:27 +08:00
this.change()
}
},
methods: {
change: function () {
this.$emit("change", this.capacity)
2020-09-16 09:09:10 +08:00
}
},
template: `<div class="ui fields inline">
<input type="hidden" :name="vName" :value="JSON.stringify(capacity)"/>
2020-09-16 09:09:10 +08:00
<div class="ui field">
<input type="text" v-model="countString" :maxlength="vMaxlength" :size="vSize"/>
2020-09-16 09:09:10 +08:00
</div>
<div class="ui field">
<select class="ui dropdown" v-model="capacity.unit" @change="change">
2020-09-16 09:09:10 +08:00
<option value="byte">字节</option>
<option value="kb">KB</option>
<option value="mb">MB</option>
<option value="gb">GB</option>
<option value="tb">TB</option>
<option value="pb">PB</option>
2020-09-16 09:09:10 +08:00
</select>
</div>
</div>`
})