2021-10-29 14:02:01 +08:00
|
|
|
|
Vue.component("datepicker", {
|
2022-10-03 19:25:20 +08:00
|
|
|
|
props: ["value", "v-name", "name", "v-value", "v-bottom-left", "placeholder"],
|
2021-10-29 14:02:01 +08:00
|
|
|
|
mounted: function () {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
teaweb.datepicker(this.$refs.dayInput, function (v) {
|
|
|
|
|
|
that.day = v
|
|
|
|
|
|
that.change()
|
|
|
|
|
|
}, !!this.vBottomLeft)
|
|
|
|
|
|
},
|
|
|
|
|
|
data: function () {
|
|
|
|
|
|
let name = this.vName
|
2022-10-03 19:25:20 +08:00
|
|
|
|
if (name == null) {
|
|
|
|
|
|
name = this.name
|
|
|
|
|
|
}
|
2021-10-29 14:02:01 +08:00
|
|
|
|
if (name == null) {
|
|
|
|
|
|
name = "day"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let day = this.vValue
|
|
|
|
|
|
if (day == null) {
|
2022-10-03 19:25:20 +08:00
|
|
|
|
day = this.value
|
|
|
|
|
|
if (day == null) {
|
|
|
|
|
|
day = ""
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let placeholder = "YYYY-MM-DD"
|
|
|
|
|
|
if (this.placeholder != null) {
|
|
|
|
|
|
placeholder = this.placeholder
|
2021-10-29 14:02:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
2022-10-03 19:25:20 +08:00
|
|
|
|
realName: name,
|
|
|
|
|
|
realPlaceholder: placeholder,
|
2021-10-29 14:02:01 +08:00
|
|
|
|
day: day
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-10-03 19:25:20 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
value: function (v) {
|
|
|
|
|
|
this.day = v
|
2022-11-04 14:35:32 +08:00
|
|
|
|
|
|
|
|
|
|
let picker = this.$refs.dayInput.picker
|
|
|
|
|
|
if (picker != null) {
|
|
|
|
|
|
if (v != null && /^\d+-\d+-\d+$/.test(v)) {
|
|
|
|
|
|
picker.setDate(v)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-03 19:25:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-10-29 14:02:01 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
change: function () {
|
2022-10-03 19:25:20 +08:00
|
|
|
|
this.$emit("input", this.day) // support v-model,事件触发需要在 change 之前
|
2021-10-29 14:02:01 +08:00
|
|
|
|
this.$emit("change", this.day)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
template: `<div style="display: inline-block">
|
2022-10-03 19:25:20 +08:00
|
|
|
|
<input type="text" :name="realName" v-model="day" :placeholder="realPlaceholder" style="width:8.6em" maxlength="10" @input="change" ref="dayInput" autocomplete="off"/>
|
2021-10-29 14:02:01 +08:00
|
|
|
|
</div>`
|
|
|
|
|
|
})
|