feat: improve to set time
gitea/salix-front/pipeline/pr-test This commit looks good Details

This commit is contained in:
Alex Moreno 2024-07-16 10:11:27 +02:00
parent 39bf7e55c0
commit 493081254d
4 changed files with 25 additions and 8 deletions

View File

@ -54,8 +54,8 @@ const formattedDate = computed({
); );
} }
} }
let ymd = value.split('-').map((e) => parseInt(e)); const [year, month, day] = value.split('-').map((e) => parseInt(e));
newDate = new Date(ymd[0], ymd[1] - 1, ymd[2]); newDate = new Date(year, month - 1, day);
if (model.value) { if (model.value) {
const orgDate = const orgDate =
model.value instanceof Date ? model.value : new Date(model.value); model.value instanceof Date ? model.value : new Date(model.value);

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { watch, computed, ref } from 'vue'; import { watch, computed, ref, nextTick } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { date } from 'quasar'; import { date } from 'quasar';
@ -20,6 +20,7 @@ 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
@ -42,13 +43,14 @@ const formattedTime = computed({
if (time) { if (time) {
if (time?.length > 5) time = dateToTime(time); if (time?.length > 5) time = dateToTime(time);
else { else {
if (time.length == 1 && parseInt(time) > 2) time = time.padStart(2, '0');
time = time.padEnd(5, '0'); time = time.padEnd(5, '0');
if (!time.includes(':')) if (!time.includes(':'))
time = time.substring(0, 2) + ':' + time.substring(3, 4); time = time.substring(0, 2) + ':' + time.substring(3, 5);
} }
if (!props.timeOnly) { if (!props.timeOnly) {
const hours = time.split(':'); const hours = time.split(':');
const date = new Date(model.value); const date = new Date(model.value ? model.value : null);
date.setHours(hours[0] ?? 0, hours[1] ?? 0, 0); date.setHours(hours[0] ?? 0, hours[1] ?? 0, 0);
time = date?.toISOString(); time = date?.toISOString();
} }
@ -66,11 +68,28 @@ watch(
(val) => (formattedTime.value = val), (val) => (formattedTime.value = val),
{ immediate: true } { immediate: true }
); );
watch(
() => formattedTime.value,
async (val) => {
const input = inputRef.value?.getNativeElement();
if (!val || !input) return;
const [hh, mm] = val.split(':');
if (parseInt(hh) >= 10 || mm != '00') return;
await nextTick();
await nextTick();
input.setSelectionRange(3, 3);
},
{ 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="--:--"
@ -130,3 +149,4 @@ watch(
es: es:
Open time: Abrir tiempo Open time: Abrir tiempo
</i18n> </i18n>
, nextTick

View File

@ -176,8 +176,6 @@ function confirmRemove(item) {
} }
async function remove(item) { async function remove(item) {
console.log('item: ', item);
console.log('id: ', route.params.id);
await axios.post('OrderRows/removes', { await axios.post('OrderRows/removes', {
actualOrderId: route.params.id, actualOrderId: route.params.id,
rows: [item.id], rows: [item.id],

View File

@ -126,7 +126,6 @@ const columns = computed(() => [
]); ]);
async function fetchClientAddress(id, data) { async function fetchClientAddress(id, data) {
console.log('data: ', data);
const clientData = await axios.get(`Clients/${id}`); const clientData = await axios.get(`Clients/${id}`);
selectedAddress.value = clientData.data.defaultAddressFk; selectedAddress.value = clientData.data.defaultAddressFk;
data.addressId = selectedAddress.value; data.addressId = selectedAddress.value;