forked from verdnatura/salix-front
Reviewed-on: verdnatura/salix-front#632 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
172c238ac3
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { watch, computed, ref, nextTick } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@ const props = defineProps({
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const initialDate = ref(model.value);
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
|
const requiredFieldRule = (val) => !!val || t('globals.fieldRequired');
|
||||||
|
|
||||||
const dateFormat = 'HH:mm';
|
const dateFormat = 'HH:mm';
|
||||||
const isPopupOpen = ref();
|
const isPopupOpen = ref();
|
||||||
const hover = ref();
|
const hover = ref();
|
||||||
const inputRef = ref();
|
|
||||||
|
|
||||||
const styleAttrs = computed(() => {
|
const styleAttrs = computed(() => {
|
||||||
return props.isOutlined
|
return props.isOutlined
|
||||||
|
@ -50,7 +50,8 @@ const formattedTime = computed({
|
||||||
}
|
}
|
||||||
if (!props.timeOnly) {
|
if (!props.timeOnly) {
|
||||||
const [hh, mm] = time.split(':');
|
const [hh, mm] = time.split(':');
|
||||||
const date = new Date(model.value ? model.value : null);
|
|
||||||
|
const date = new Date(model.value ? model.value : initialDate.value);
|
||||||
date.setHours(hh, mm, 0);
|
date.setHours(hh, mm, 0);
|
||||||
time = date?.toISOString();
|
time = date?.toISOString();
|
||||||
}
|
}
|
||||||
|
@ -62,37 +63,10 @@ const formattedTime = computed({
|
||||||
function dateToTime(newDate) {
|
function dateToTime(newDate) {
|
||||||
return date.formatDate(new Date(newDate), dateFormat);
|
return date.formatDate(new Date(newDate), dateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => model.value,
|
|
||||||
(val) => (formattedTime.value = val),
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => formattedTime.value,
|
|
||||||
async (val) => {
|
|
||||||
let position = 3;
|
|
||||||
const input = inputRef.value?.getNativeElement();
|
|
||||||
if (!val || !input) return;
|
|
||||||
|
|
||||||
let [hh, mm] = val.split(':');
|
|
||||||
hh = parseInt(hh);
|
|
||||||
if (hh >= 10 || mm != '00') return;
|
|
||||||
|
|
||||||
await nextTick();
|
|
||||||
await nextTick();
|
|
||||||
if (!hh) position = 0;
|
|
||||||
input.setSelectionRange(position, position);
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div @mouseover="hover = true" @mouseleave="hover = false">
|
<div @mouseover="hover = true" @mouseleave="hover = false">
|
||||||
<QInput
|
<QInput
|
||||||
ref="inputRef"
|
|
||||||
class="vn-input-time"
|
class="vn-input-time"
|
||||||
mask="##:##"
|
mask="##:##"
|
||||||
placeholder="--:--"
|
placeholder="--:--"
|
||||||
|
@ -102,7 +76,7 @@ watch(
|
||||||
style="min-width: 100px"
|
style="min-width: 100px"
|
||||||
:rules="$attrs.required ? [requiredFieldRule] : null"
|
:rules="$attrs.required ? [requiredFieldRule] : null"
|
||||||
@click="isPopupOpen = false"
|
@click="isPopupOpen = false"
|
||||||
@focus="inputRef.getNativeElement().setSelectionRange(0, 0)"
|
type="time"
|
||||||
>
|
>
|
||||||
<template #append>
|
<template #append>
|
||||||
<QIcon
|
<QIcon
|
||||||
|
@ -149,6 +123,11 @@ watch(
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
:deep(input[type='time']::-webkit-calendar-picker-indicator) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
Open time: Abrir tiempo
|
Open time: Abrir tiempo
|
||||||
|
|
Loading…
Reference in New Issue