1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<script lang="ts" setup>
import { onMounted, ref, computed } from 'vue';
import { date } from 'quasar';
import { isEmpty } from 'src/common/utils';
interface Props {
modelValue: string | null;
format24h?: boolean;
dense?: boolean;
disable?: boolean;
readonly?: boolean;
config?: any;
}
const props = withDefaults(defineProps<Props>(), {
// modelValue: date.formatDate(Date.now(), 'YYYY/MM/DD HH:mm'),
modelValue: null,
format24h: false,
dense: false,
disable: false,
readonly: false,
config: () => {
return {};
},
});
const emit = defineEmits<{
(e: 'update:modelValue', value: string): void;
}>();
const dates = computed({
set(value: any) {
emit('update:modelValue', value);
},
get() {
return props.modelValue;
},
});
const timeMask = computed(() => {
let obj = {
time: 'HH:mm:ss',
};
if (!isEmpty(props.config) && props.config.timeMask) {
obj.time = props.config.timeMask;
}
return obj;
});
const isWithSeconds = computed(() => {
return timeMask.value.time.length > 6;
});
const timeProxyDate = ref<any>(null);
onMounted(() => {
getNowDate();
});
function getNowDate() {
timeProxyDate.value = date.formatDate(Date.now(), timeMask.value.time);
}
function updateProxy() {
timeProxyDate.value = dates.value;
}
function onClickDate() {
dates.value = timeProxyDate.value;
}
</script>
<template>
<div class="hcy-datetime-pick">
<q-input
v-model="dates"
v-bind="config"
:dense="config.dense === undefined ? props.dense : config.dense"
:disable="config.disable === undefined ? props.disable : config.disable"
:readonly="
config.readonly === undefined ? props.readonly : config.readonly
"
>
<template v-slot:append>
<q-icon name="access_time" class="cursor-pointer">
<q-popup-proxy
v-if="!props.readonly"
@before-show="updateProxy"
transition-show="scale"
transition-hide="scale"
class="row"
>
<q-time
flat
square
v-model="timeProxyDate"
:mask="timeMask.time"
:format24h="format24h"
:with-seconds="isWithSeconds"
text-color="primary"
class="my-time"
>
<div class="row items-center justify-end q-gutter-sm">
<q-btn
label="此刻"
size="sm"
color="primary"
flat
@click="getNowDate"
/>
<q-btn
unelevated
label="确定"
size="sm"
color="primary"
@click="onClickDate"
v-close-popup
/>
</div>
</q-time>
</q-popup-proxy>
</q-icon>
</template>
</q-input>
</div>
</template>
<style lang="scss" scoped>
.my-time {
:deep(.q-time__header) {
background-color: white;
}
:deep(.q-time__main
.q-time__content
.q-time__container-child
.q-time__clock
.q-time__clock-circle
.q-time__clock-position--active) {
color: white !important;
}
}
</style>