Files
EdgeAdmin/web/public/js/components/common/time-duration-box.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-10-02 17:22:24 +08:00
Vue.component("time-duration-box", {
props: ["v-name", "v-value", "v-count", "v-unit"],
data: function () {
let v = this.vValue
if (v == null) {
v = {
count: this.vCount,
unit: this.vUnit
}
}
if (typeof (v["count"]) != "number") {
v["count"] = -1
}
return {
2020-10-04 20:38:27 +08:00
duration: v,
2020-10-02 17:22:24 +08:00
countString: (v.count >= 0) ? v.count.toString() : ""
}
},
watch: {
"countString": function (newValue) {
let value = newValue.trim()
if (value.length == 0) {
2020-10-04 20:38:27 +08:00
this.duration.count = -1
2020-10-02 17:22:24 +08:00
return
}
let count = parseInt(value)
if (!isNaN(count)) {
2020-10-04 20:38:27 +08:00
this.duration.count = count
2020-10-02 17:22:24 +08:00
}
2020-10-04 20:38:27 +08:00
this.change()
}
},
methods: {
change: function () {
this.$emit("change", this.duration)
2020-10-02 17:22:24 +08:00
}
},
template: `<div class="ui fields inline">
2020-10-04 20:38:27 +08:00
<input type="hidden" :name="vName" :value="JSON.stringify(duration)"/>
2020-10-02 17:22:24 +08:00
<div class="ui field">
<input type="text" v-model="countString" maxlength="11" size="11"/>
</div>
<div class="ui field">
2020-10-04 20:38:27 +08:00
<select class="ui dropdown" v-model="duration.unit" @change="change">
2020-10-02 17:22:24 +08:00
<option value="ms">毫秒</option>
<option value="second"></option>
<option value="minute">分钟</option>
<option value="hour">小时</option>
<option value="day"></option>
</select>
</div>
</div>`
})