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

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-10-02 17:22:24 +08:00
Vue.component("time-duration-box", {
2023-05-17 18:41:27 +08:00
props: ["name", "v-name", "v-value", "v-count", "v-unit"],
mounted: function () {
this.change()
},
2020-10-02 17:22:24 +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
}
2023-05-17 18:41:27 +08:00
let realName = ""
if (typeof this.name == "string" && this.name.length > 0) {
realName = this.name
} else if (typeof this.vName == "string" && this.vName.length > 0) {
realName = this.vName
}
2020-10-02 17:22:24 +08:00
return {
2020-10-04 20:38:27 +08:00
duration: v,
2023-05-17 18:41:27 +08:00
countString: (v.count >= 0) ? v.count.toString() : "",
realName: realName
2020-10-02 17:22:24 +08:00
}
},
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
}
},
2020-11-07 19:40:18 +08:00
template: `<div class="ui fields inline" style="padding-bottom: 0; margin-bottom: 0">
2023-05-17 18:41:27 +08:00
<input type="hidden" :name="realName" :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" @keypress.enter.prevent="1"/>
2020-10-02 17:22:24 +08:00
</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>
<option value="week"></option>
2020-10-02 17:22:24 +08:00
</select>
</div>
</div>`
})