@ramathibodi/nuxt-commons 0.1.17 → 0.1.19
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/dist/module.json +1 -1
- package/dist/runtime/components/BarcodeReader.vue +73 -49
- package/dist/runtime/components/TextBarcode.vue +4 -2
- package/dist/runtime/components/form/Birthdate.vue +7 -2
- package/dist/runtime/components/form/Table.vue +8 -8
- package/dist/runtime/components/form/images/Capture.vue +1 -1
- package/dist/runtime/components/form/images/Edit.vue +1 -2
- package/dist/runtime/components/label/DateAgo.vue +41 -0
- package/dist/runtime/components/label/Field.vue +82 -30
- package/dist/runtime/components/master/Autocomplete.vue +22 -3
- package/dist/runtime/composables/graphqlModel.mjs +9 -15
- package/dist/runtime/composables/utils/validation.mjs +1 -1
- package/package.json +2 -2
package/dist/module.json
CHANGED
|
@@ -1,45 +1,64 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import {BrowserMultiFormatReader} from '@zxing/browser'
|
|
3
|
+
import {type IScannerControls} from '@zxing/browser/esm'
|
|
4
|
+
import type {Exception, Result} from '@zxing/library'
|
|
5
|
+
import {computed, onBeforeUnmount, onMounted, ref, watchEffect} from 'vue'
|
|
6
|
+
import {useAlert} from '../composables/alert'
|
|
7
|
+
import {useDevicesList, useUserMedia} from "@vueuse/core";
|
|
7
8
|
|
|
8
|
-
const videoElementRef = ref<HTMLVideoElement | null>(null)
|
|
9
9
|
const barcodeReader = new BrowserMultiFormatReader()
|
|
10
|
+
const barcodeReaderControl = ref()
|
|
11
|
+
|
|
10
12
|
const alert = useAlert()
|
|
11
|
-
const
|
|
13
|
+
const isLoading = ref<boolean>(false)
|
|
12
14
|
|
|
13
15
|
const emit = defineEmits<{
|
|
14
16
|
(event: 'decode', barcodeValue: string): void
|
|
15
17
|
(event: 'error', error: string | unknown): void
|
|
16
18
|
}>()
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
const devices = await navigator.mediaDevices.enumerateDevices()
|
|
20
|
-
hasCameraAvailable.value = devices.some(device => device.kind === 'videoinput')
|
|
21
|
-
}
|
|
20
|
+
const videoScreen = ref<HTMLVideoElement>()
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
const currentCameraId = ref<ConstrainDOMString | undefined>()
|
|
23
|
+
const { videoInputs: cameras } = useDevicesList({
|
|
24
|
+
requestPermissions: true,
|
|
25
|
+
constraints: { audio: false, video: true },
|
|
26
|
+
onUpdated() {
|
|
27
|
+
if (!cameras.value.find(camera => camera.deviceId === currentCameraId.value))
|
|
28
|
+
currentCameraId.value = cameras.value[0]?.deviceId
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
const hasCamera = computed(()=>{ return !!currentCameraId.value })
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const { stream, start: cameraStart, stop: cameraStop, enabled: cameraEnabled } = useUserMedia({
|
|
34
|
+
constraints: { video: { deviceId: currentCameraId.value}},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
watchEffect(() => {
|
|
38
|
+
if (videoScreen.value) videoScreen.value.srcObject = (stream.value) ? stream.value! : null
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
function startCamera() {
|
|
42
|
+
if (!cameraEnabled.value) {
|
|
43
|
+
isLoading.value = true
|
|
44
|
+
cameraStart().then(()=>{
|
|
45
|
+
barcodeReader.decodeFromVideoDevice(currentCameraId.value, videoScreen.value, (result: Result | undefined, error: Exception | undefined, controls: IScannerControls) => {
|
|
46
|
+
if (result) {
|
|
47
|
+
emit('decode', result.getText())
|
|
48
|
+
cameraStop()
|
|
49
|
+
}
|
|
50
|
+
}).then((result: any)=>{
|
|
51
|
+
barcodeReaderControl.value = result
|
|
52
|
+
})
|
|
53
|
+
}).finally(()=>{
|
|
54
|
+
isLoading.value = false
|
|
37
55
|
})
|
|
38
56
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function stopCamera() {
|
|
60
|
+
if (barcodeReaderControl.value) barcodeReaderControl.value.stop()
|
|
61
|
+
if (cameraEnabled.value) cameraStop()
|
|
43
62
|
}
|
|
44
63
|
|
|
45
64
|
function scanImageFile(selectedFile: File | File[] | undefined) {
|
|
@@ -48,42 +67,47 @@ function scanImageFile(selectedFile: File | File[] | undefined) {
|
|
|
48
67
|
return
|
|
49
68
|
}
|
|
50
69
|
|
|
70
|
+
const scanImageSingleFile: File = Array.isArray(selectedFile) ? selectedFile[0] : selectedFile
|
|
71
|
+
|
|
51
72
|
const reader = new FileReader()
|
|
52
73
|
reader.onload = async (event) => {
|
|
53
74
|
try {
|
|
54
75
|
const result = await barcodeReader.decodeFromImageUrl(event.target?.result as string)
|
|
55
76
|
emit('decode', result.getText())
|
|
56
77
|
}
|
|
57
|
-
catch (
|
|
58
|
-
|
|
78
|
+
catch (e) {
|
|
79
|
+
void e
|
|
59
80
|
}
|
|
60
81
|
}
|
|
61
|
-
const scanImageSingleFile: File = Array.isArray(selectedFile) ? selectedFile[0] : selectedFile
|
|
62
82
|
reader.readAsDataURL(scanImageSingleFile)
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
onMounted(
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
onMounted( () => {
|
|
86
|
+
startCamera()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
onBeforeUnmount( () => {
|
|
90
|
+
stopCamera()
|
|
68
91
|
})
|
|
69
92
|
</script>
|
|
70
93
|
|
|
71
94
|
<template>
|
|
72
95
|
<v-card flat>
|
|
73
|
-
<v-card-
|
|
74
|
-
<v-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
<v-card-text class="d-flex justify-center" v-if="isLoading">
|
|
97
|
+
<v-progress-circular indeterminate></v-progress-circular>
|
|
98
|
+
</v-card-text>
|
|
99
|
+
<v-card-text v-else>
|
|
100
|
+
<v-col v-if="hasCamera">
|
|
101
|
+
<div style="position: relative; display: inline-block; width: 100%;" :style="{maxWidth: '1024px'}">
|
|
102
|
+
<video autoplay ref="videoScreen" width="100%" :style="{maxWidth:'1024px'}"></video>
|
|
103
|
+
<div style="position: absolute; bottom: 10px; right: 10px; z-index: 2000;">
|
|
104
|
+
<FileBtn
|
|
105
|
+
accept="image/*"
|
|
106
|
+
icon="mdi mdi-image-plus"
|
|
107
|
+
icon-only
|
|
108
|
+
@update:model-value="scanImageFile"
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
87
111
|
</div>
|
|
88
112
|
</v-col>
|
|
89
113
|
<v-col v-else>
|
|
@@ -93,6 +117,6 @@ onMounted(async () => {
|
|
|
93
117
|
@update:model-value="scanImageFile"
|
|
94
118
|
/>
|
|
95
119
|
</v-col>
|
|
96
|
-
</v-card-
|
|
120
|
+
</v-card-text>
|
|
97
121
|
</v-card>
|
|
98
122
|
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {ref, watch} from 'vue'
|
|
3
|
+
import {useAlert} from '../composables/alert'
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
modelValue?: string
|
|
@@ -9,6 +9,7 @@ interface Props {
|
|
|
9
9
|
const props = defineProps<Props>()
|
|
10
10
|
const emit = defineEmits<{
|
|
11
11
|
(event: 'update:modelValue', value: string | undefined): void
|
|
12
|
+
(event: 'decode', value: string | undefined): void
|
|
12
13
|
}>()
|
|
13
14
|
const alert = useAlert()
|
|
14
15
|
|
|
@@ -18,6 +19,7 @@ const currentValue = ref<string>()
|
|
|
18
19
|
const handleData = (data: string) => {
|
|
19
20
|
currentValue.value = data
|
|
20
21
|
scanCode.value = false
|
|
22
|
+
emit('decode',data)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const handleError = (error: string | unknown) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import Datepicker from '@vuepic/vue-datepicker'
|
|
3
3
|
import '@vuepic/vue-datepicker/dist/main.css'
|
|
4
|
-
import {nextTick, ref, watch, watchEffect
|
|
4
|
+
import {computed, nextTick, onMounted, ref, watch, watchEffect} from 'vue'
|
|
5
5
|
import {type dateFormat, Datetime} from '../../utils/datetime'
|
|
6
6
|
|
|
7
7
|
interface IDobPrecision {
|
|
@@ -41,7 +41,12 @@ const dobPrecisionText = computed(() => {
|
|
|
41
41
|
}
|
|
42
42
|
})
|
|
43
43
|
const dobPrecisionChoice = ref<('yearMonthDay' | 'yearMonth' | 'year')[]>(['yearMonthDay', 'yearMonth', 'year'])
|
|
44
|
-
const dobPrecisionSelected = defineModel<'yearMonthDay' | 'yearMonth' | 'year'>('dobPrecision'
|
|
44
|
+
const dobPrecisionSelected = defineModel<'yearMonthDay' | 'yearMonth' | 'year'>('dobPrecision')
|
|
45
|
+
onMounted(()=>{
|
|
46
|
+
if (!dobPrecisionSelected.value) {
|
|
47
|
+
dobPrecisionSelected.value = 'yearMonthDay'
|
|
48
|
+
}
|
|
49
|
+
})
|
|
45
50
|
|
|
46
51
|
const dobPrecisionDisplay = computed(() => {
|
|
47
52
|
return (dobPrecisionSelected.value) ? dobPrecisionText.value[dobPrecisionSelected.value] : dobPrecisionText.value['yearMonthDay']
|
|
@@ -190,14 +190,14 @@ const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpIt
|
|
|
190
190
|
<slot name="toolbarItems" />
|
|
191
191
|
<ImportCSV
|
|
192
192
|
v-if="props.importable"
|
|
193
|
-
icon="mdi
|
|
193
|
+
icon="mdi:mdi-file-upload"
|
|
194
194
|
variant="flat"
|
|
195
195
|
@import="importItems"
|
|
196
196
|
:color="toolbarColor"
|
|
197
197
|
/>
|
|
198
198
|
<ExportCSV
|
|
199
199
|
v-if="props.exportable && items.length"
|
|
200
|
-
icon="mdi
|
|
200
|
+
icon="mdi:mdi-file-download"
|
|
201
201
|
variant="flat"
|
|
202
202
|
:file-name="title"
|
|
203
203
|
:model-value="items"
|
|
@@ -205,7 +205,7 @@ const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpIt
|
|
|
205
205
|
/>
|
|
206
206
|
<VBtn
|
|
207
207
|
:color="toolbarColor"
|
|
208
|
-
prepend-icon="mdi
|
|
208
|
+
prepend-icon="mdi:mdi-plus"
|
|
209
209
|
variant="flat"
|
|
210
210
|
@click="openDialog()"
|
|
211
211
|
>
|
|
@@ -239,20 +239,20 @@ const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpIt
|
|
|
239
239
|
:disabled="props.index==0"
|
|
240
240
|
variant="flat"
|
|
241
241
|
density="compact"
|
|
242
|
-
icon="mdi
|
|
242
|
+
icon="mdi:mdi-arrow-up-thick"
|
|
243
243
|
@click="moveUpItem(props.item)"
|
|
244
244
|
/>
|
|
245
245
|
<v-btn
|
|
246
246
|
variant="flat"
|
|
247
247
|
density="compact"
|
|
248
|
-
icon="fa fa-arrow-right-to-bracket"
|
|
248
|
+
icon="fa:fas fa-arrow-right-to-bracket"
|
|
249
249
|
@click="moveToItem(props.item)"
|
|
250
250
|
/>
|
|
251
251
|
<v-btn
|
|
252
252
|
:disabled="props.index==items.length-1"
|
|
253
253
|
variant="flat"
|
|
254
254
|
density="compact"
|
|
255
|
-
icon="mdi
|
|
255
|
+
icon="mdi:mdi-arrow-down-thick"
|
|
256
256
|
@click="moveDownItem(props.item)"
|
|
257
257
|
/>
|
|
258
258
|
</template>
|
|
@@ -263,13 +263,13 @@ const operation = ref({ openDialog, createItem, updateItem, deleteItem, moveUpIt
|
|
|
263
263
|
<v-btn
|
|
264
264
|
variant="flat"
|
|
265
265
|
density="compact"
|
|
266
|
-
icon="mdi
|
|
266
|
+
icon="mdi:mdi-note-edit"
|
|
267
267
|
@click="openDialog(item)"
|
|
268
268
|
/>
|
|
269
269
|
<v-btn
|
|
270
270
|
variant="flat"
|
|
271
271
|
density="compact"
|
|
272
|
-
icon="mdi
|
|
272
|
+
icon="mdi:mdi-delete"
|
|
273
273
|
@click="deleteItem(item)"
|
|
274
274
|
/>
|
|
275
275
|
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {ref
|
|
2
|
+
import {computed, ref} from 'vue'
|
|
3
3
|
import Cropper from 'cropperjs'
|
|
4
4
|
import 'cropperjs/dist/cropper.css'
|
|
5
5
|
import type {ImageFormat} from "exif-rotate-js"
|
|
@@ -51,7 +51,6 @@ const moveLeft = () => cropper.value?.move(-10, 0)
|
|
|
51
51
|
const moveRight = () => cropper.value?.move(10, 0)
|
|
52
52
|
const accept = () => {
|
|
53
53
|
const croppedCanvas = cropper.value?.getCroppedCanvas()
|
|
54
|
-
console.log(props.imageFormat)
|
|
55
54
|
imageData.value = croppedCanvas?.toDataURL(props.imageFormat,1)
|
|
56
55
|
}
|
|
57
56
|
const reset = () => cropper.value?.reset()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { DateTime, type ToRelativeOptions } from "luxon";
|
|
3
|
+
import { computed } from "vue";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
modelValue: DateTime;
|
|
7
|
+
locale?: 'TH' | 'EN';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
11
|
+
locale: 'TH',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const timeAgo = computed(() => {
|
|
15
|
+
const now = DateTime.now();
|
|
16
|
+
const diff = now.diff(props.modelValue, ['years', 'months', 'days', 'hours', 'minutes', 'seconds']).toObject();
|
|
17
|
+
|
|
18
|
+
let unit: ToRelativeOptions['unit'] = 'seconds';
|
|
19
|
+
if (diff.years && diff.years > 0) {
|
|
20
|
+
unit = 'years';
|
|
21
|
+
} else if (diff.months && diff.months > 0) {
|
|
22
|
+
unit = 'months';
|
|
23
|
+
} else if (diff.days && diff.days > 0) {
|
|
24
|
+
unit = 'days';
|
|
25
|
+
} else if (diff.hours && diff.hours > 0) {
|
|
26
|
+
unit = 'hours';
|
|
27
|
+
} else if (diff.minutes && diff.minutes > 0) {
|
|
28
|
+
unit = 'minutes';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return props.modelValue.setLocale(props.locale).toRelative({ unit });
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<span>{{ timeAgo }}</span>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<style scoped>
|
|
40
|
+
|
|
41
|
+
</style>
|
|
@@ -1,48 +1,100 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {computed} from 'vue'
|
|
2
|
+
import { computed, ref } from 'vue';
|
|
3
|
+
|
|
3
4
|
interface Props {
|
|
4
|
-
label: string
|
|
5
|
-
value?: string
|
|
6
|
-
horizontal?: boolean
|
|
7
|
-
size
|
|
5
|
+
label: string;
|
|
6
|
+
value?: string | null;
|
|
7
|
+
horizontal?: boolean;
|
|
8
|
+
size?: 'large' | 'medium';
|
|
9
|
+
truncate?: boolean;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
const props = withDefaults(defineProps<Props>(), {
|
|
11
|
-
label: '',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
13
|
+
label: '',
|
|
14
|
+
value: '',
|
|
15
|
+
horizontal: false,
|
|
16
|
+
size: 'large',
|
|
17
|
+
truncate: false,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const valueText = ref<HTMLElement | null>(null);
|
|
21
|
+
const isTooltip = ref(false);
|
|
22
|
+
|
|
23
|
+
const calSize = computed(() => (props.size === 'medium' ? 'text-subtitle-1' : 'text-h6'));
|
|
24
|
+
const calTruncate = computed(() => (props.truncate ? 'text-truncate' : ''));
|
|
25
|
+
|
|
26
|
+
const setTruncate = (event: Event) => {
|
|
27
|
+
const target = event.target as HTMLElement;
|
|
28
|
+
isTooltip.value = target.offsetWidth < target.scrollWidth;
|
|
29
|
+
};
|
|
30
|
+
|
|
17
31
|
</script>
|
|
18
32
|
|
|
19
33
|
<template>
|
|
20
|
-
<div
|
|
34
|
+
<div
|
|
35
|
+
v-if="props.horizontal"
|
|
36
|
+
class="d-flex align-top"
|
|
37
|
+
v-bind="$attrs"
|
|
38
|
+
@resize="setTruncate"
|
|
39
|
+
>
|
|
21
40
|
<div class="text-medium-emphasis text-no-wrap">
|
|
22
|
-
<slot name="label">
|
|
23
|
-
{{ label }}:
|
|
24
|
-
</slot>
|
|
41
|
+
<slot name="label">{{ props.label }}:</slot>
|
|
25
42
|
</div>
|
|
26
|
-
<div class="ml-1">
|
|
43
|
+
<div :class="`ml-1 ${calTruncate}`" ref="valueText">
|
|
27
44
|
<slot name="value">
|
|
28
|
-
{{ value }}
|
|
45
|
+
<div v-if="!props.truncate">{{ props.value }}</div>
|
|
46
|
+
<div
|
|
47
|
+
v-else
|
|
48
|
+
@mouseover="setTruncate"
|
|
49
|
+
@mouseout="isTooltip = false"
|
|
50
|
+
>
|
|
51
|
+
<v-tooltip :model-value="isTooltip" location="bottom">
|
|
52
|
+
<template #activator="{ props }">
|
|
53
|
+
<div
|
|
54
|
+
class="text-truncate"
|
|
55
|
+
v-bind="isTooltip ? props : ''"
|
|
56
|
+
>
|
|
57
|
+
{{ value }}
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
<span>{{ value }}</span>
|
|
61
|
+
</v-tooltip>
|
|
62
|
+
</div>
|
|
29
63
|
</slot>
|
|
30
64
|
</div>
|
|
31
65
|
</div>
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
{{ label }}
|
|
36
|
-
</
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
|
|
67
|
+
<v-card v-else variant="text" v-bind="$attrs">
|
|
68
|
+
<VCardSubtitle class="ma-0 pa-0 text-black">
|
|
69
|
+
<slot name="label">{{ props.label }}</slot>
|
|
70
|
+
</VCardSubtitle>
|
|
71
|
+
<VCardText :class="`pa-0 mb-2 ${calSize}`">
|
|
72
|
+
<div :class="calTruncate" ref="valueText">
|
|
73
|
+
<slot name="value">
|
|
74
|
+
<div v-if="!props.truncate">{{ props.value }}</div>
|
|
75
|
+
<div
|
|
76
|
+
v-else
|
|
77
|
+
@mouseover="setTruncate"
|
|
78
|
+
@mouseout="isTooltip = false"
|
|
79
|
+
>
|
|
80
|
+
<v-tooltip :model-value="isTooltip" location="bottom">
|
|
81
|
+
<template #activator="{ props }">
|
|
82
|
+
<div
|
|
83
|
+
class="text-truncate"
|
|
84
|
+
v-bind="isTooltip ? props : ''"
|
|
85
|
+
>
|
|
86
|
+
{{ value }}
|
|
87
|
+
</div>
|
|
88
|
+
</template>
|
|
89
|
+
<span>{{ value }}</span>
|
|
90
|
+
</v-tooltip>
|
|
91
|
+
</div>
|
|
92
|
+
</slot>
|
|
93
|
+
</div>
|
|
94
|
+
</VCardText>
|
|
95
|
+
</v-card>
|
|
44
96
|
</template>
|
|
45
97
|
|
|
46
|
-
<style
|
|
98
|
+
<style scoped>
|
|
47
99
|
|
|
48
100
|
</style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import {VAutocomplete} from 'vuetify/components/VAutocomplete'
|
|
3
|
-
import {concat, isEmpty} from 'lodash-es'
|
|
3
|
+
import {concat, isEmpty,sortBy} from 'lodash-es'
|
|
4
4
|
import {computed, ref, watch} from 'vue'
|
|
5
5
|
import {watchDebounced} from '@vueuse/core'
|
|
6
6
|
import {useFuzzy} from '../../composables/utils/fuzzy'
|
|
@@ -16,13 +16,15 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VAutocomplete['$pr
|
|
|
16
16
|
waitForFilter?: boolean
|
|
17
17
|
waitForFilterText?: string
|
|
18
18
|
modelValue?: string
|
|
19
|
+
sortBy?: 'itemCode' | 'itemValue'
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
const props = withDefaults(defineProps<Props>(), {
|
|
22
|
-
fuzzy:
|
|
23
|
+
fuzzy: false,
|
|
23
24
|
noDataText: 'ไม่พบข้อมูล',
|
|
24
25
|
lang: 'TH',
|
|
25
26
|
waitForFilter: false,
|
|
27
|
+
sortBy: 'itemValue'
|
|
26
28
|
})
|
|
27
29
|
|
|
28
30
|
const emit = defineEmits(['update:modelValue'])
|
|
@@ -112,6 +114,23 @@ const computedNoDataText = computed(() => {
|
|
|
112
114
|
if (props.waitForFilter && !props.filterText) return props.waitForFilterText
|
|
113
115
|
return props.noDataText
|
|
114
116
|
})
|
|
117
|
+
|
|
118
|
+
const computedSortBy = computed(()=>{
|
|
119
|
+
let sortByField = props.sortBy
|
|
120
|
+
if (sortByField == 'itemValue') {
|
|
121
|
+
return [itemTitleField.value,'itemValue','itemCode']
|
|
122
|
+
} else {
|
|
123
|
+
return [sortByField]
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const computedItems = computed(()=>{
|
|
128
|
+
if (pros.fuzzy && !isEmpty(searchData.value)) {
|
|
129
|
+
return items.value
|
|
130
|
+
} else {
|
|
131
|
+
return sortBy(items.value, computedSortBy.value)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
115
134
|
</script>
|
|
116
135
|
|
|
117
136
|
<template>
|
|
@@ -119,7 +138,7 @@ const computedNoDataText = computed(() => {
|
|
|
119
138
|
v-model="selectedItem"
|
|
120
139
|
v-model:search="searchData"
|
|
121
140
|
v-bind="$attrs"
|
|
122
|
-
:items="
|
|
141
|
+
:items="computedItems"
|
|
123
142
|
:no-filter="props.fuzzy"
|
|
124
143
|
:item-title="itemTitleField"
|
|
125
144
|
item-value="itemCode"
|
|
@@ -12,23 +12,17 @@ export function useGraphqlModel(props) {
|
|
|
12
12
|
const { operationCreate, operationUpdate, operationDelete, operationRead, operationReadPageable, operationSearch } = useGraphqlModelOperation(props);
|
|
13
13
|
function keyToField(key) {
|
|
14
14
|
const parts = key.split(".");
|
|
15
|
-
if (parts.length
|
|
16
|
-
const result = {};
|
|
17
|
-
let current = result;
|
|
18
|
-
for (let i = 0; i < parts.length; i++) {
|
|
19
|
-
const part = parts[i];
|
|
20
|
-
const isLast = i === parts.length - 1;
|
|
21
|
-
if (isLast) {
|
|
22
|
-
current[part] = [part];
|
|
23
|
-
} else {
|
|
24
|
-
current[part] = [{}];
|
|
25
|
-
current = current[part][0];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
} else {
|
|
15
|
+
if (parts.length <= 1)
|
|
30
16
|
return key;
|
|
17
|
+
let lastValue = parts.pop();
|
|
18
|
+
let result = {};
|
|
19
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
20
|
+
if (i == parts.length - 1)
|
|
21
|
+
result = { [parts[i]]: [lastValue] };
|
|
22
|
+
else
|
|
23
|
+
result = { [parts[i]]: result };
|
|
31
24
|
}
|
|
25
|
+
return result;
|
|
32
26
|
}
|
|
33
27
|
const fields = computed(() => {
|
|
34
28
|
const tmpFields = [];
|
|
@@ -16,7 +16,7 @@ export function useRules() {
|
|
|
16
16
|
const telephone = (customError = "Invalid telephone number") => (value) => condition(!value || /^(?:\s*(?:0[2-57]\d{7}|0[689]\d{8})(?:#\d{1,5})?\s*(?:\([^()]+\)\s*)?(?:,(?=.+))?)*$/.test(value), customError);
|
|
17
17
|
const email = (customError = "Invalid email address") => (value) => condition(!value || /^([\w\-.]+)@([\w\-.]+)\.([a-z]{2,5})$/i.test(value), customError);
|
|
18
18
|
const regex = (regex2, customError = "Invalid format") => (value) => condition(!value || new RegExp(regex2).test(value), customError);
|
|
19
|
-
const idcard = (customError = "Invalid
|
|
19
|
+
const idcard = (customError = "Invalid ID Card format") => (value) => condition(!value || /^\d{13}$/.test(value) && (11 - [...value].slice(0, 12).reduce((sum, n, i) => sum + +n * (13 - i), 0) % 11) % 10 === +value[12], customError);
|
|
20
20
|
const rules = ref({
|
|
21
21
|
require,
|
|
22
22
|
requireIf,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramathibodi/nuxt-commons",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "Ramathibodi Nuxt modules for common components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"vitest": "^1.5.1",
|
|
117
117
|
"vue-tsc": "^1.8.27"
|
|
118
118
|
},
|
|
119
|
-
"packageManager": "pnpm@9.
|
|
119
|
+
"packageManager": "pnpm@9.8.0+sha512.8e4c3550fb500e808dbc30bb0ce4dd1eb614e30b1c55245f211591ec2cdf9c611cabd34e1364b42f564bd54b3945ed0f49d61d1bbf2ec9bd74b866fcdc723276"
|
|
120
120
|
}
|