@ramathibodi/nuxt-commons 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -96
- package/dist/module.json +1 -1
- package/dist/runtime/components/Alert.vue +53 -53
- package/dist/runtime/components/BarcodeReader.vue +98 -98
- package/dist/runtime/components/ExportCSV.vue +55 -55
- package/dist/runtime/components/FileBtn.vue +62 -62
- package/dist/runtime/components/ImportCSV.vue +64 -64
- package/dist/runtime/components/SplitterPanel.vue +59 -59
- package/dist/runtime/components/TabsGroup.vue +32 -32
- package/dist/runtime/components/TextBarcode.vue +52 -52
- package/dist/runtime/components/dialog/Confirm.vue +100 -100
- package/dist/runtime/components/dialog/Index.vue +72 -72
- package/dist/runtime/components/dialog/Loading.vue +39 -39
- package/dist/runtime/components/document/TemplateBuilder.vue +203 -216
- package/dist/runtime/components/form/Birthdate.vue +216 -216
- package/dist/runtime/components/form/CodeEditor.vue +37 -37
- package/dist/runtime/components/form/Date.vue +163 -163
- package/dist/runtime/components/form/DateTime.vue +107 -107
- package/dist/runtime/components/form/Dialog.vue +138 -138
- package/dist/runtime/components/form/File.vue +187 -187
- package/dist/runtime/components/form/Hidden.vue +32 -32
- package/dist/runtime/components/form/Login.vue +131 -131
- package/dist/runtime/components/form/Pad.vue +217 -217
- package/dist/runtime/components/form/SignPad.vue +186 -186
- package/dist/runtime/components/form/Table.vue +266 -266
- package/dist/runtime/components/form/Time.vue +158 -158
- package/dist/runtime/components/form/images/Capture.vue +230 -230
- package/dist/runtime/components/form/images/Edit.vue +114 -114
- package/dist/runtime/components/label/Date.vue +29 -29
- package/dist/runtime/components/label/Field.vue +42 -42
- package/dist/runtime/components/label/FormatMoney.vue +29 -29
- package/dist/runtime/components/label/Mask.vue +38 -38
- package/dist/runtime/components/master/Autocomplete.vue +159 -159
- package/dist/runtime/components/master/Combobox.vue +84 -84
- package/dist/runtime/components/master/RadioGroup.vue +78 -78
- package/dist/runtime/components/master/Select.vue +82 -82
- package/dist/runtime/components/model/Pad.vue +122 -122
- package/dist/runtime/components/model/Table.vue +242 -240
- package/dist/runtime/components/model/iterator.vue +312 -312
- package/dist/runtime/components/pdf/Print.vue +63 -63
- package/dist/runtime/components/pdf/View.vue +104 -104
- package/dist/runtime/composables/graphqlModel.mjs +1 -1
- package/dist/runtime/labs/Calendar.vue +99 -99
- package/dist/runtime/labs/form/EditMobile.vue +152 -152
- package/dist/runtime/labs/form/TextFieldMask.vue +43 -43
- package/dist/runtime/types/alert.d.ts +11 -11
- package/dist/runtime/types/formDialog.d.ts +4 -4
- package/dist/runtime/types/graphqlOperation.d.ts +23 -23
- package/dist/runtime/types/menu.d.ts +25 -25
- package/dist/runtime/types/modules.d.ts +7 -7
- package/package.json +120 -119
- package/scripts/postInstall.cjs +70 -70
- package/templates/.codegen/codegen.ts +32 -32
- package/templates/.codegen/plugin-schema-object.js +154 -154
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import Datepicker from '@vuepic/vue-datepicker'
|
|
3
|
-
import '@vuepic/vue-datepicker/dist/main.css'
|
|
4
|
-
import { ref, watch, watchEffect, nextTick } from 'vue'
|
|
5
|
-
import { type dateFormat, Datetime } from '../../utils/datetime'
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
readonly?: boolean
|
|
9
|
-
locale?: 'TH' | 'EN'
|
|
10
|
-
format?: dateFormat | string
|
|
11
|
-
modelValue?: string | null
|
|
12
|
-
holiday?: object[] | undefined
|
|
13
|
-
minDate?: Date | string
|
|
14
|
-
maxDate?: Date | string
|
|
15
|
-
pickerOnly?: boolean
|
|
16
|
-
flow?: ('month' | 'year' | 'calendar' | 'time' | 'minutes' | 'hours' | 'seconds')[]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
20
|
-
readonly: false,
|
|
21
|
-
locale: 'TH',
|
|
22
|
-
format: 'shortDate',
|
|
23
|
-
pickerOnly: false,
|
|
24
|
-
flow: () => [],
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const emit = defineEmits(['update:modelValue'])
|
|
28
|
-
|
|
29
|
-
const selectedDate = ref<string | null>(null)
|
|
30
|
-
const displayedDate = ref<string | null>(null)
|
|
31
|
-
|
|
32
|
-
const isMenuOpen = ref(false)
|
|
33
|
-
const isTextFieldFocused = ref(false)
|
|
34
|
-
const hasTextFieldInput = ref(false)
|
|
35
|
-
|
|
36
|
-
function handleTextFieldFocus(event: Event) {
|
|
37
|
-
isTextFieldFocused.value = true
|
|
38
|
-
nextTick(() => {
|
|
39
|
-
(event.target as HTMLInputElement).select()
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function handleTextFieldInput() {
|
|
44
|
-
if (!hasTextFieldInput.value) {
|
|
45
|
-
hasTextFieldInput.value = true
|
|
46
|
-
isMenuOpen.value = false
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function handleTextFieldBlur() {
|
|
51
|
-
if (hasTextFieldInput.value) {
|
|
52
|
-
updateDate(displayedDate.value)
|
|
53
|
-
hasTextFieldInput.value = false
|
|
54
|
-
}
|
|
55
|
-
isTextFieldFocused.value = false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function handleTextFieldEnterKey() {
|
|
59
|
-
handleTextFieldBlur()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function updateDatePicker(dateString: string | null) {
|
|
63
|
-
isMenuOpen.value = false
|
|
64
|
-
updateDate(dateString)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function updateDate(dateString: string | null) {
|
|
68
|
-
const dateTime = Datetime().fromString(dateString, undefined, props.locale)
|
|
69
|
-
if (!dateTime.luxonDateTime.isValid) {
|
|
70
|
-
displayedDate.value = null
|
|
71
|
-
selectedDate.value = null
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
selectedDate.value = dateTime.toFormat('yyyy-MM-dd', 'EN')
|
|
75
|
-
displayedDate.value = selectedDate.value
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!isTextFieldFocused.value) displayedDate.value = formatDate(displayedDate.value)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function formatDate(dateString: string | null) {
|
|
82
|
-
if (!dateString) return null
|
|
83
|
-
|
|
84
|
-
const dateTime = Datetime().fromString(dateString, undefined, props.locale)
|
|
85
|
-
return dateTime.toFormat(props.format, props.locale)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function handleTextFieldClear() {
|
|
89
|
-
resetDatePicker()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function resetDatePicker() {
|
|
93
|
-
selectedDate.value = null
|
|
94
|
-
displayedDate.value = null
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
watchEffect(() => {
|
|
98
|
-
if (!isTextFieldFocused.value && selectedDate.value) {
|
|
99
|
-
const dateTime = Datetime().fromString(selectedDate.value, undefined, props.locale)
|
|
100
|
-
displayedDate.value = dateTime.toFormat(props.format, props.locale)
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
displayedDate.value = selectedDate.value
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
watch(selectedDate, (newValue) => {
|
|
108
|
-
emit('update:modelValue', newValue)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
watch(() => props.modelValue, () => {
|
|
112
|
-
updateDate(props.modelValue || null)
|
|
113
|
-
}, { immediate: true })
|
|
114
|
-
|
|
115
|
-
function toggleMenuOpen(trigger: string) {
|
|
116
|
-
if ((trigger === 'textField' && props.pickerOnly) || (trigger === 'icon' && !props.pickerOnly)) {
|
|
117
|
-
isMenuOpen.value = true
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
</script>
|
|
121
|
-
|
|
122
|
-
<template>
|
|
123
|
-
<v-menu
|
|
124
|
-
v-model="isMenuOpen"
|
|
125
|
-
:open-on-click="false"
|
|
126
|
-
>
|
|
127
|
-
<template #activator="{ props: activatorProps }">
|
|
128
|
-
<v-text-field
|
|
129
|
-
ref="textField"
|
|
130
|
-
v-model="displayedDate"
|
|
131
|
-
:readonly="readonly"
|
|
132
|
-
v-bind="$attrs"
|
|
133
|
-
@focus="handleTextFieldFocus"
|
|
134
|
-
@blur="handleTextFieldBlur"
|
|
135
|
-
@keydown="handleTextFieldInput"
|
|
136
|
-
@keyup.enter="handleTextFieldEnterKey"
|
|
137
|
-
@click:clear="handleTextFieldClear"
|
|
138
|
-
@click="toggleMenuOpen('textField')"
|
|
139
|
-
>
|
|
140
|
-
<template #append-inner>
|
|
141
|
-
<v-icon
|
|
142
|
-
v-bind="activatorProps"
|
|
143
|
-
@click="toggleMenuOpen('icon')"
|
|
144
|
-
>
|
|
145
|
-
fa:fa-regular fa-calendar
|
|
146
|
-
</v-icon>
|
|
147
|
-
</template>
|
|
148
|
-
</v-text-field>
|
|
149
|
-
</template>
|
|
150
|
-
<Datepicker
|
|
151
|
-
v-model="selectedDate"
|
|
152
|
-
model-type="yyyy-MM-dd"
|
|
153
|
-
:enable-time-picker="false"
|
|
154
|
-
:flow="flow"
|
|
155
|
-
:min-date="props.minDate"
|
|
156
|
-
:max-date="props.maxDate"
|
|
157
|
-
auto-apply
|
|
158
|
-
inline
|
|
159
|
-
:locale="locale"
|
|
160
|
-
@update:model-value="updateDatePicker"
|
|
161
|
-
/>
|
|
162
|
-
</v-menu>
|
|
163
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import Datepicker from '@vuepic/vue-datepicker'
|
|
3
|
+
import '@vuepic/vue-datepicker/dist/main.css'
|
|
4
|
+
import { ref, watch, watchEffect, nextTick } from 'vue'
|
|
5
|
+
import { type dateFormat, Datetime } from '../../utils/datetime'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
readonly?: boolean
|
|
9
|
+
locale?: 'TH' | 'EN'
|
|
10
|
+
format?: dateFormat | string
|
|
11
|
+
modelValue?: string | null
|
|
12
|
+
holiday?: object[] | undefined
|
|
13
|
+
minDate?: Date | string
|
|
14
|
+
maxDate?: Date | string
|
|
15
|
+
pickerOnly?: boolean
|
|
16
|
+
flow?: ('month' | 'year' | 'calendar' | 'time' | 'minutes' | 'hours' | 'seconds')[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
20
|
+
readonly: false,
|
|
21
|
+
locale: 'TH',
|
|
22
|
+
format: 'shortDate',
|
|
23
|
+
pickerOnly: false,
|
|
24
|
+
flow: () => [],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const emit = defineEmits(['update:modelValue'])
|
|
28
|
+
|
|
29
|
+
const selectedDate = ref<string | null>(null)
|
|
30
|
+
const displayedDate = ref<string | null>(null)
|
|
31
|
+
|
|
32
|
+
const isMenuOpen = ref(false)
|
|
33
|
+
const isTextFieldFocused = ref(false)
|
|
34
|
+
const hasTextFieldInput = ref(false)
|
|
35
|
+
|
|
36
|
+
function handleTextFieldFocus(event: Event) {
|
|
37
|
+
isTextFieldFocused.value = true
|
|
38
|
+
nextTick(() => {
|
|
39
|
+
(event.target as HTMLInputElement).select()
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function handleTextFieldInput() {
|
|
44
|
+
if (!hasTextFieldInput.value) {
|
|
45
|
+
hasTextFieldInput.value = true
|
|
46
|
+
isMenuOpen.value = false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleTextFieldBlur() {
|
|
51
|
+
if (hasTextFieldInput.value) {
|
|
52
|
+
updateDate(displayedDate.value)
|
|
53
|
+
hasTextFieldInput.value = false
|
|
54
|
+
}
|
|
55
|
+
isTextFieldFocused.value = false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function handleTextFieldEnterKey() {
|
|
59
|
+
handleTextFieldBlur()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function updateDatePicker(dateString: string | null) {
|
|
63
|
+
isMenuOpen.value = false
|
|
64
|
+
updateDate(dateString)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function updateDate(dateString: string | null) {
|
|
68
|
+
const dateTime = Datetime().fromString(dateString, undefined, props.locale)
|
|
69
|
+
if (!dateTime.luxonDateTime.isValid) {
|
|
70
|
+
displayedDate.value = null
|
|
71
|
+
selectedDate.value = null
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
selectedDate.value = dateTime.toFormat('yyyy-MM-dd', 'EN')
|
|
75
|
+
displayedDate.value = selectedDate.value
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!isTextFieldFocused.value) displayedDate.value = formatDate(displayedDate.value)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function formatDate(dateString: string | null) {
|
|
82
|
+
if (!dateString) return null
|
|
83
|
+
|
|
84
|
+
const dateTime = Datetime().fromString(dateString, undefined, props.locale)
|
|
85
|
+
return dateTime.toFormat(props.format, props.locale)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleTextFieldClear() {
|
|
89
|
+
resetDatePicker()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resetDatePicker() {
|
|
93
|
+
selectedDate.value = null
|
|
94
|
+
displayedDate.value = null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
watchEffect(() => {
|
|
98
|
+
if (!isTextFieldFocused.value && selectedDate.value) {
|
|
99
|
+
const dateTime = Datetime().fromString(selectedDate.value, undefined, props.locale)
|
|
100
|
+
displayedDate.value = dateTime.toFormat(props.format, props.locale)
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
displayedDate.value = selectedDate.value
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
watch(selectedDate, (newValue) => {
|
|
108
|
+
emit('update:modelValue', newValue)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
watch(() => props.modelValue, () => {
|
|
112
|
+
updateDate(props.modelValue || null)
|
|
113
|
+
}, { immediate: true })
|
|
114
|
+
|
|
115
|
+
function toggleMenuOpen(trigger: string) {
|
|
116
|
+
if ((trigger === 'textField' && props.pickerOnly) || (trigger === 'icon' && !props.pickerOnly)) {
|
|
117
|
+
isMenuOpen.value = true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<template>
|
|
123
|
+
<v-menu
|
|
124
|
+
v-model="isMenuOpen"
|
|
125
|
+
:open-on-click="false"
|
|
126
|
+
>
|
|
127
|
+
<template #activator="{ props: activatorProps }">
|
|
128
|
+
<v-text-field
|
|
129
|
+
ref="textField"
|
|
130
|
+
v-model="displayedDate"
|
|
131
|
+
:readonly="readonly"
|
|
132
|
+
v-bind="$attrs"
|
|
133
|
+
@focus="handleTextFieldFocus"
|
|
134
|
+
@blur="handleTextFieldBlur"
|
|
135
|
+
@keydown="handleTextFieldInput"
|
|
136
|
+
@keyup.enter="handleTextFieldEnterKey"
|
|
137
|
+
@click:clear="handleTextFieldClear"
|
|
138
|
+
@click="toggleMenuOpen('textField')"
|
|
139
|
+
>
|
|
140
|
+
<template #append-inner>
|
|
141
|
+
<v-icon
|
|
142
|
+
v-bind="activatorProps"
|
|
143
|
+
@click="toggleMenuOpen('icon')"
|
|
144
|
+
>
|
|
145
|
+
fa:fa-regular fa-calendar
|
|
146
|
+
</v-icon>
|
|
147
|
+
</template>
|
|
148
|
+
</v-text-field>
|
|
149
|
+
</template>
|
|
150
|
+
<Datepicker
|
|
151
|
+
v-model="selectedDate"
|
|
152
|
+
model-type="yyyy-MM-dd"
|
|
153
|
+
:enable-time-picker="false"
|
|
154
|
+
:flow="flow"
|
|
155
|
+
:min-date="props.minDate"
|
|
156
|
+
:max-date="props.maxDate"
|
|
157
|
+
auto-apply
|
|
158
|
+
inline
|
|
159
|
+
:locale="locale"
|
|
160
|
+
@update:model-value="updateDatePicker"
|
|
161
|
+
/>
|
|
162
|
+
</v-menu>
|
|
163
|
+
</template>
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { ref, computed, watch, watchEffect } from 'vue'
|
|
3
|
-
import { union } from 'lodash-es'
|
|
4
|
-
import { type dateFormat, Datetime } from '../../utils/datetime'
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
modelValue?: string | null
|
|
8
|
-
format?: dateFormat | string
|
|
9
|
-
label?: string
|
|
10
|
-
enableSeconds?: boolean
|
|
11
|
-
rules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
12
|
-
dateRules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
13
|
-
timeRules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
14
|
-
dense?: boolean
|
|
15
|
-
pickerOnly?: boolean
|
|
16
|
-
minDate?: Date | string
|
|
17
|
-
maxDate?: Date | string
|
|
18
|
-
readonly?: boolean
|
|
19
|
-
locale?: 'TH' | 'EN'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
23
|
-
dense: false,
|
|
24
|
-
locale: 'TH',
|
|
25
|
-
enableSeconds: false,
|
|
26
|
-
format: 'shortDate',
|
|
27
|
-
pickerOnly: false,
|
|
28
|
-
readonly: false,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const emit = defineEmits(['update:modelValue'])
|
|
32
|
-
|
|
33
|
-
const computedDateRules = computed(() => union(props.rules, props.dateRules))
|
|
34
|
-
const computedTimeRules = computed(() => union(props.rules, props.timeRules))
|
|
35
|
-
|
|
36
|
-
const datePart = ref<string | null>(null)
|
|
37
|
-
const timePart = ref<string | null>(null)
|
|
38
|
-
const pauseEmit = ref(false)
|
|
39
|
-
|
|
40
|
-
function reset() {
|
|
41
|
-
datePart.value = null
|
|
42
|
-
timePart.value = null
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
watchEffect(() => {
|
|
46
|
-
if (!pauseEmit.value) {
|
|
47
|
-
if (datePart.value && timePart.value) {
|
|
48
|
-
emit('update:modelValue', Datetime().fromString(`${datePart.value}T${timePart.value}`).toISO())
|
|
49
|
-
}
|
|
50
|
-
else if (!datePart.value) {
|
|
51
|
-
emit('update:modelValue', null)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
watch(() => props.modelValue, () => {
|
|
57
|
-
pauseEmit.value = true
|
|
58
|
-
if (!props.modelValue) {
|
|
59
|
-
reset()
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const dateTime = Datetime().fromString(props.modelValue)
|
|
63
|
-
if (dateTime.luxonDateTime.isValid) {
|
|
64
|
-
datePart.value = dateTime.toFormat('yyyy-MM-dd')
|
|
65
|
-
timePart.value = dateTime.toFormat('HH:mm:ss')
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
reset()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
pauseEmit.value = false
|
|
72
|
-
}, { immediate: true })
|
|
73
|
-
</script>
|
|
74
|
-
|
|
75
|
-
<template>
|
|
76
|
-
<v-container
|
|
77
|
-
:fluid="true"
|
|
78
|
-
class="pa-0"
|
|
79
|
-
>
|
|
80
|
-
<v-row :dense="dense">
|
|
81
|
-
<v-col cols="8">
|
|
82
|
-
<FormDate
|
|
83
|
-
v-model="datePart"
|
|
84
|
-
:rules="computedDateRules"
|
|
85
|
-
:label="label"
|
|
86
|
-
:format="format"
|
|
87
|
-
:picker-only="pickerOnly"
|
|
88
|
-
:readonly="readonly"
|
|
89
|
-
:min-date="minDate"
|
|
90
|
-
:max-date="maxDate"
|
|
91
|
-
v-bind="$attrs"
|
|
92
|
-
/>
|
|
93
|
-
</v-col>
|
|
94
|
-
<v-col cols="4">
|
|
95
|
-
<FormTime
|
|
96
|
-
v-model="timePart"
|
|
97
|
-
:rules="computedTimeRules"
|
|
98
|
-
:label="label"
|
|
99
|
-
:enable-seconds="enableSeconds"
|
|
100
|
-
:picker-only="pickerOnly"
|
|
101
|
-
:readonly="readonly"
|
|
102
|
-
v-bind="$attrs"
|
|
103
|
-
/>
|
|
104
|
-
</v-col>
|
|
105
|
-
</v-row>
|
|
106
|
-
</v-container>
|
|
107
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ref, computed, watch, watchEffect } from 'vue'
|
|
3
|
+
import { union } from 'lodash-es'
|
|
4
|
+
import { type dateFormat, Datetime } from '../../utils/datetime'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
modelValue?: string | null
|
|
8
|
+
format?: dateFormat | string
|
|
9
|
+
label?: string
|
|
10
|
+
enableSeconds?: boolean
|
|
11
|
+
rules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
12
|
+
dateRules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
13
|
+
timeRules?: typeof import('vuetify/components')['VTextField']['rules']
|
|
14
|
+
dense?: boolean
|
|
15
|
+
pickerOnly?: boolean
|
|
16
|
+
minDate?: Date | string
|
|
17
|
+
maxDate?: Date | string
|
|
18
|
+
readonly?: boolean
|
|
19
|
+
locale?: 'TH' | 'EN'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
23
|
+
dense: false,
|
|
24
|
+
locale: 'TH',
|
|
25
|
+
enableSeconds: false,
|
|
26
|
+
format: 'shortDate',
|
|
27
|
+
pickerOnly: false,
|
|
28
|
+
readonly: false,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const emit = defineEmits(['update:modelValue'])
|
|
32
|
+
|
|
33
|
+
const computedDateRules = computed(() => union(props.rules, props.dateRules))
|
|
34
|
+
const computedTimeRules = computed(() => union(props.rules, props.timeRules))
|
|
35
|
+
|
|
36
|
+
const datePart = ref<string | null>(null)
|
|
37
|
+
const timePart = ref<string | null>(null)
|
|
38
|
+
const pauseEmit = ref(false)
|
|
39
|
+
|
|
40
|
+
function reset() {
|
|
41
|
+
datePart.value = null
|
|
42
|
+
timePart.value = null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
watchEffect(() => {
|
|
46
|
+
if (!pauseEmit.value) {
|
|
47
|
+
if (datePart.value && timePart.value) {
|
|
48
|
+
emit('update:modelValue', Datetime().fromString(`${datePart.value}T${timePart.value}`).toISO())
|
|
49
|
+
}
|
|
50
|
+
else if (!datePart.value) {
|
|
51
|
+
emit('update:modelValue', null)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
watch(() => props.modelValue, () => {
|
|
57
|
+
pauseEmit.value = true
|
|
58
|
+
if (!props.modelValue) {
|
|
59
|
+
reset()
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const dateTime = Datetime().fromString(props.modelValue)
|
|
63
|
+
if (dateTime.luxonDateTime.isValid) {
|
|
64
|
+
datePart.value = dateTime.toFormat('yyyy-MM-dd')
|
|
65
|
+
timePart.value = dateTime.toFormat('HH:mm:ss')
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
reset()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
pauseEmit.value = false
|
|
72
|
+
}, { immediate: true })
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<v-container
|
|
77
|
+
:fluid="true"
|
|
78
|
+
class="pa-0"
|
|
79
|
+
>
|
|
80
|
+
<v-row :dense="dense">
|
|
81
|
+
<v-col cols="8">
|
|
82
|
+
<FormDate
|
|
83
|
+
v-model="datePart"
|
|
84
|
+
:rules="computedDateRules"
|
|
85
|
+
:label="label"
|
|
86
|
+
:format="format"
|
|
87
|
+
:picker-only="pickerOnly"
|
|
88
|
+
:readonly="readonly"
|
|
89
|
+
:min-date="minDate"
|
|
90
|
+
:max-date="maxDate"
|
|
91
|
+
v-bind="$attrs"
|
|
92
|
+
/>
|
|
93
|
+
</v-col>
|
|
94
|
+
<v-col cols="4">
|
|
95
|
+
<FormTime
|
|
96
|
+
v-model="timePart"
|
|
97
|
+
:rules="computedTimeRules"
|
|
98
|
+
:label="label"
|
|
99
|
+
:enable-seconds="enableSeconds"
|
|
100
|
+
:picker-only="pickerOnly"
|
|
101
|
+
:readonly="readonly"
|
|
102
|
+
v-bind="$attrs"
|
|
103
|
+
/>
|
|
104
|
+
</v-col>
|
|
105
|
+
</v-row>
|
|
106
|
+
</v-container>
|
|
107
|
+
</template>
|