@ramathibodi/nuxt-commons 0.0.6 → 0.0.8
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 +6 -6
- package/dist/module.json +1 -1
- package/dist/runtime/components/Alert.vue +14 -14
- package/dist/runtime/components/Camera.vue +23 -10
- package/dist/runtime/components/Pdf/View.vue +25 -25
- package/dist/runtime/components/form/File.vue +1 -1
- package/dist/runtime/components/form/SignPad.vue +2 -2
- package/dist/runtime/components/form/images/CameraCrop.vue +1 -1
- package/dist/runtime/components/form/images/Edit.vue +3 -3
- package/dist/runtime/components/label/Field.vue +6 -9
- package/dist/runtime/components/label/Mask.vue +38 -0
- package/dist/runtime/composables/utils/validation.d.ts +2 -0
- package/dist/runtime/composables/utils/validation.mjs +3 -1
- package/dist/runtime/labs/Calendar.vue +1 -1
- package/dist/runtime/utils/object.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Find and replace all on all files (CMD+SHIFT+F):
|
|
|
6
6
|
- Package name: @ramahis/common-components
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
|
-
#
|
|
9
|
+
# @ramathibodi/nuxt-commons
|
|
10
10
|
|
|
11
11
|
[![npm version][npm-version-src]][npm-version-href]
|
|
12
12
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
@@ -16,17 +16,17 @@ Find and replace all on all files (CMD+SHIFT+F):
|
|
|
16
16
|
|
|
17
17
|
## Quick Setup
|
|
18
18
|
|
|
19
|
-
1. Add
|
|
19
|
+
1. Add `'@ramathibodi/nuxt-commons'` dependency to your project
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
# Using pnpm
|
|
23
|
-
pnpm add -D @
|
|
23
|
+
pnpm add -D @ramathibodi/nuxt-commons
|
|
24
24
|
|
|
25
25
|
# Using yarn
|
|
26
|
-
yarn add --dev @
|
|
26
|
+
yarn add --dev @ramathibodi/nuxt-commons
|
|
27
27
|
|
|
28
28
|
# Using npm
|
|
29
|
-
npm install --save-dev @
|
|
29
|
+
npm install --save-dev @ramathibodi/nuxt-commons
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
2. Add `my-module` to the `modules` section of `nuxt.config.ts`
|
|
@@ -34,7 +34,7 @@ npm install --save-dev @deverloprama/common-components
|
|
|
34
34
|
```js
|
|
35
35
|
export default defineNuxtConfig({
|
|
36
36
|
modules: [
|
|
37
|
-
'@
|
|
37
|
+
'@ramathibodi/nuxt-commons'
|
|
38
38
|
]
|
|
39
39
|
})
|
|
40
40
|
```
|
package/dist/module.json
CHANGED
|
@@ -29,23 +29,23 @@ watch(() => alert?.hasAlert(), (hasAlert) => {
|
|
|
29
29
|
|
|
30
30
|
<template>
|
|
31
31
|
<VSnackbar
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
v-if="currentItem"
|
|
33
|
+
v-model="isAlertOpen"
|
|
34
|
+
:timeout="timeout"
|
|
35
|
+
location="center"
|
|
36
|
+
multi-line
|
|
37
|
+
variant="text"
|
|
38
|
+
@update:model-value="renewAlert()"
|
|
39
39
|
>
|
|
40
40
|
<!-- @vue-expected-error Type conversion problem -->
|
|
41
41
|
<VAlert
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
v-model="isAlertOpen"
|
|
43
|
+
closable
|
|
44
|
+
:type="currentItem.alertType"
|
|
45
|
+
elevation="2"
|
|
46
|
+
theme="dark"
|
|
47
|
+
variant="flat"
|
|
48
|
+
@click:close="renewAlert()"
|
|
49
49
|
>
|
|
50
50
|
{{ currentItem.statusCode ? currentItem.statusCode + ' ' : '' }} {{ currentItem.message }} {{ !isEmpty(currentItem.data) ? currentItem.data : '' }}
|
|
51
51
|
</VAlert>
|
|
@@ -93,23 +93,36 @@ onMounted(() => {
|
|
|
93
93
|
</v-card-title>
|
|
94
94
|
<v-card-text class="d-flex justify-center">
|
|
95
95
|
<video
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
ref="videoRef"
|
|
97
|
+
autoplay
|
|
98
|
+
style="max-width: 1024px"
|
|
99
99
|
/>
|
|
100
100
|
<div style="z-index: 2000; position: relative; bottom: -410px; left: -80px; height: 50px">
|
|
101
101
|
<FileBtn
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
accept="image/*"
|
|
103
|
+
icon="mdi mdi-image-plus"
|
|
104
|
+
icon-only
|
|
105
|
+
@update:model-value="loadImageFile"
|
|
106
106
|
/>
|
|
107
107
|
</div>
|
|
108
108
|
</v-card-text>
|
|
109
109
|
<v-card-actions class="d-flex justify-center">
|
|
110
|
-
<v-btn
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
<v-btn
|
|
111
|
+
icon
|
|
112
|
+
size="x-large"
|
|
113
|
+
variant="tonal"
|
|
114
|
+
@click="captureImage()"
|
|
115
|
+
>
|
|
116
|
+
<v-icon
|
|
117
|
+
icon="fa:fa-solid fa-circle"
|
|
118
|
+
size="x-large"
|
|
119
|
+
/>
|
|
120
|
+
<v-tooltip
|
|
121
|
+
activator="parent"
|
|
122
|
+
location="top"
|
|
123
|
+
>
|
|
124
|
+
ถ่ายภาพ
|
|
125
|
+
</v-tooltip>
|
|
113
126
|
</v-btn>
|
|
114
127
|
</v-card-actions>
|
|
115
128
|
</v-card>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import PDF from 'pdf-vue3'
|
|
3
|
-
import { uid } from 'uid'
|
|
4
|
-
import { useAlert } from '../../composables/alert'
|
|
2
|
+
import PDF from 'pdf-vue3'
|
|
3
|
+
import { uid } from 'uid'
|
|
5
4
|
import printJS from 'print-js'
|
|
6
|
-
import {ref, computed} from 'vue'
|
|
5
|
+
import { ref, computed } from 'vue'
|
|
6
|
+
import { useAlert } from '../../composables/alert'
|
|
7
7
|
|
|
8
8
|
const props = defineProps<{
|
|
9
9
|
base64String?: string
|
|
@@ -40,7 +40,7 @@ const downloadPdf = (): void => {
|
|
|
40
40
|
anchorElement.click()
|
|
41
41
|
URL.revokeObjectURL(link)
|
|
42
42
|
document.body.removeChild(anchorElement)
|
|
43
|
-
base64.value =
|
|
43
|
+
base64.value = ''
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const printPdf = () => {
|
|
@@ -53,16 +53,16 @@ const printPdf = () => {
|
|
|
53
53
|
alert?.addAlert({ message: error, alertType: 'error' })
|
|
54
54
|
},
|
|
55
55
|
})
|
|
56
|
-
base64.value =
|
|
56
|
+
base64.value = ''
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const endLoadPdf = () => {
|
|
60
60
|
emit('closeDialog', false)
|
|
61
|
-
base64.value =
|
|
61
|
+
base64.value = ''
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const isMobile = computed(() => {
|
|
65
|
-
if(/Android|Mobi|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Macintosh/i.test(navigator.userAgent)){
|
|
65
|
+
if (/Android|Mobi|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Macintosh/i.test(navigator.userAgent)) {
|
|
66
66
|
return true
|
|
67
67
|
}
|
|
68
68
|
})
|
|
@@ -74,31 +74,31 @@ const isMobile = computed(() => {
|
|
|
74
74
|
<v-toolbar-title>{{ props.title }}</v-toolbar-title>
|
|
75
75
|
<v-spacer />
|
|
76
76
|
<v-btn
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
v-if="!isMobile"
|
|
78
|
+
icon="mdi mdi-printer"
|
|
79
|
+
variant="plain"
|
|
80
|
+
@click="printPdf"
|
|
81
81
|
/>
|
|
82
82
|
<v-btn
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
v-if="!props.disabled"
|
|
84
|
+
icon="mdi mdi-download"
|
|
85
|
+
variant="plain"
|
|
86
|
+
@click="downloadPdf"
|
|
87
87
|
/>
|
|
88
88
|
<v-btn
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
icon="mdi mdi-close"
|
|
90
|
+
variant="plain"
|
|
91
|
+
@click="endLoadPdf"
|
|
92
92
|
/>
|
|
93
93
|
</v-toolbar>
|
|
94
94
|
<v-card-text class="justify-center">
|
|
95
95
|
<PDF
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
:show-progress="true"
|
|
97
|
+
pdf-width="100%"
|
|
98
|
+
:src="base64"
|
|
99
|
+
:show-page-tooltip="false"
|
|
100
|
+
:show-back-to-top-btn="false"
|
|
101
101
|
/>
|
|
102
102
|
</v-card-text>
|
|
103
103
|
</v-card>
|
|
104
|
-
</template>
|
|
104
|
+
</template>
|
|
@@ -127,7 +127,7 @@ onBeforeUnmount(() => {
|
|
|
127
127
|
<v-icon>fa-solid fa-trash</v-icon>
|
|
128
128
|
</v-btn>
|
|
129
129
|
<v-menu>
|
|
130
|
-
<template #activator="{ props
|
|
130
|
+
<template #activator="{ props: activatorProps }">
|
|
131
131
|
<v-btn
|
|
132
132
|
:color="selectedColor"
|
|
133
133
|
:icon="true"
|
|
@@ -141,11 +141,11 @@ onBeforeUnmount(() => {
|
|
|
141
141
|
<v-col class="text-center">
|
|
142
142
|
<v-avatar
|
|
143
143
|
v-for="(color, index) in colorOptions"
|
|
144
|
+
:key="index"
|
|
144
145
|
:color="color"
|
|
145
146
|
:value="color"
|
|
146
147
|
class="mr-1"
|
|
147
148
|
@click="changePenColor(color)"
|
|
148
|
-
:key="index"
|
|
149
149
|
>
|
|
150
150
|
<v-icon color="white">
|
|
151
151
|
{{ selectedColor === color ? 'fa-solid fa-check' : '' }}
|
|
@@ -56,13 +56,13 @@ const handleCrop = () => {
|
|
|
56
56
|
if (croppedCanvas) {
|
|
57
57
|
const dataURL = croppedCanvas.toDataURL()
|
|
58
58
|
emit('update:modelValue', dataURL)
|
|
59
|
-
emit(
|
|
59
|
+
emit('closeDialog', false)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const resetCrop = () => {
|
|
64
|
-
emit(
|
|
65
|
-
emit(
|
|
64
|
+
emit('closeDialog', false)
|
|
65
|
+
emit('openCamera', true)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const close = () => {
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
|
|
3
|
-
|
|
4
2
|
interface Props {
|
|
5
|
-
label: string
|
|
6
|
-
value?: string |
|
|
3
|
+
label: string
|
|
4
|
+
value?: string | string | null | undefined
|
|
7
5
|
}
|
|
8
6
|
|
|
9
7
|
const props = withDefaults(defineProps<Props>(), {
|
|
10
|
-
label: '', value: ''
|
|
11
|
-
})
|
|
12
|
-
|
|
8
|
+
label: '', value: '',
|
|
9
|
+
})
|
|
13
10
|
</script>
|
|
11
|
+
|
|
14
12
|
<template>
|
|
15
13
|
<v-card variant="flat">
|
|
16
14
|
<VCardSubtitle class="ma-0 pa-0">
|
|
17
15
|
<slot name="label">
|
|
18
16
|
{{ label }}
|
|
19
17
|
</slot>
|
|
20
|
-
|
|
18
|
+
</VCardSubtitle>
|
|
21
19
|
<VCardText class="text-h6 pa-0 mb-2">
|
|
22
20
|
<slot name="value">
|
|
23
21
|
{{ value }}
|
|
24
22
|
</slot>
|
|
25
|
-
|
|
26
23
|
</VCardText>
|
|
27
24
|
</v-card>
|
|
28
25
|
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
modelValue: string
|
|
6
|
+
variant?: 'mobilePhone' | 'homePhone' | 'citizenId' | 'creditCard'
|
|
7
|
+
hideContent?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
11
|
+
hideContent: false,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const labelMask = computed(() => {
|
|
15
|
+
if (!props.hideContent) {
|
|
16
|
+
if (props.variant == 'mobilePhone') return props.modelValue.length == 10 ? `${props.modelValue.substring(0, 3)}-${props.modelValue.substring(3, 6)}-${props.modelValue.substring(6, 10)}` : 'invalid format'
|
|
17
|
+
if (props.variant == 'homePhone') return props.modelValue.length == 9 ? `${props.modelValue.substring(0, 2)}-${props.modelValue.substring(2, 5)}-${props.modelValue.substring(5, 9)}` : 'invalid format'
|
|
18
|
+
if (props.variant == 'citizenId') return props.modelValue.length == 13 ? `${props.modelValue.substring(0, 1)}-${props.modelValue.substring(1, 5)}-${props.modelValue.substring(5, 10)}-${props.modelValue.substring(10, 12)}-${props.modelValue.substring(12, 13)}` : 'invalid format'
|
|
19
|
+
if (props.variant == 'creditCard') return props.modelValue.length == 16 ? `${props.modelValue.substring(0, 4)}-${props.modelValue.substring(4, 8)}-${props.modelValue.substring(8, 12)}-${props.modelValue.substring(12, 16)}` : 'invalid format'
|
|
20
|
+
|
|
21
|
+
const middlePart = 'x'.repeat(props.modelValue.length - 6)
|
|
22
|
+
return `${props.modelValue.substring(0, 3)}${middlePart}${props.modelValue.slice(-3)}`
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (props.variant == 'mobilePhone') return props.modelValue.length == 10 ? `${props.modelValue.substring(0, 2)}x-xxx-${props.modelValue.substring(6, 10)}` : 'invalid format'
|
|
26
|
+
if (props.variant == 'homePhone') return props.modelValue.length == 9 ? `${props.modelValue.substring(0, 2)}-xxx-${props.modelValue.substring(5, 9)}` : 'invalid format'
|
|
27
|
+
if (props.variant == 'citizenId') return props.modelValue.length == 13 ? `${props.modelValue.substring(0, 1)}-xxxx-xxxxx-${props.modelValue.substring(10, 12)}-${props.modelValue.substring(12, 13)}` : 'invalid format'
|
|
28
|
+
if (props.variant == 'creditCard') return props.modelValue.length == 16 ? `xxxx-xxxx-xxxx-${props.modelValue.substring(12, 16)}` : 'invalid format'
|
|
29
|
+
|
|
30
|
+
const middlePart = 'x'.repeat(props.modelValue.length - 6)
|
|
31
|
+
return `${props.modelValue.substring(0, 3)}${middlePart}${props.modelValue.slice(-3)}`
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
{{ labelMask }}
|
|
38
|
+
</template>
|
|
@@ -13,6 +13,7 @@ export declare function useRules(): {
|
|
|
13
13
|
telephone: (customError?: string) => (value: any) => string | true;
|
|
14
14
|
email: (customError?: string) => (value: any) => string | true;
|
|
15
15
|
regex: (regex: string, customError?: string) => (value: any) => string | true;
|
|
16
|
+
idcard: (customError?: string) => (value: any) => string | true;
|
|
16
17
|
rules: import("vue").Ref<{
|
|
17
18
|
require: (customError?: string) => (value: any) => string | true;
|
|
18
19
|
requireIf: (conditionIf: boolean, customError?: string) => (value: any) => string | true;
|
|
@@ -28,5 +29,6 @@ export declare function useRules(): {
|
|
|
28
29
|
telephone: (customError?: string) => (value: any) => string | true;
|
|
29
30
|
email: (customError?: string) => (value: any) => string | true;
|
|
30
31
|
regex: (regex: string, customError?: string) => (value: any) => string | true;
|
|
32
|
+
idcard: (customError?: string) => (value: any) => string | true;
|
|
31
33
|
}>;
|
|
32
34
|
};
|
|
@@ -16,6 +16,7 @@ export function useRules() {
|
|
|
16
16
|
const telephone = (customError = "Invalid telephone number") => (value) => condition(!value || /^(?:\s*(?:0[23457][0-9]{7}|0[689][0-9]{8})(?:#[0-9]{1,5})?\s*(?:\([^()]+\))?\s*(?:,(?=.+))?)*$/.test(value), customError);
|
|
17
17
|
const email = (customError = "Invalid email address") => (value) => condition(!value || /^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5})$/.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 idcard") => (value) => condition(/^\d{13}$/.test(value) && (11 - [...value].slice(0, 12).reduce((sum, n, i) => sum + +n * (13 - i), 0) % 11) % 10 === +value[12], customError);
|
|
19
20
|
const rules = ref({
|
|
20
21
|
require,
|
|
21
22
|
requireIf,
|
|
@@ -30,7 +31,8 @@ export function useRules() {
|
|
|
30
31
|
lengthLess,
|
|
31
32
|
telephone,
|
|
32
33
|
email,
|
|
33
|
-
regex
|
|
34
|
+
regex,
|
|
35
|
+
idcard
|
|
34
36
|
});
|
|
35
37
|
return { rules, ...rules.value };
|
|
36
38
|
}
|
|
@@ -68,7 +68,7 @@ const eventContentDay = (arg: any) => {
|
|
|
68
68
|
return { domNodes: [list] }
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
// @ts-
|
|
71
|
+
// @ts-expect-error
|
|
72
72
|
const calendarOptions = ref<CalendarOptions>({
|
|
73
73
|
plugins: [dayGridPlugin, timeGridPlugin, listPlugin, interactionPlugin],
|
|
74
74
|
initialView: props.mode,
|
|
@@ -9,7 +9,7 @@ export function classAttributes(cls) {
|
|
|
9
9
|
return Object.keys(new cls());
|
|
10
10
|
}
|
|
11
11
|
export function onlyAttributes(keys, object) {
|
|
12
|
-
|
|
12
|
+
const returnObject = cloneDeep(object);
|
|
13
13
|
Object.keys(object).forEach((localKey) => {
|
|
14
14
|
if (!keys.includes(localKey))
|
|
15
15
|
delete returnObject[localKey];
|
|
@@ -17,7 +17,7 @@ export function onlyAttributes(keys, object) {
|
|
|
17
17
|
return returnObject;
|
|
18
18
|
}
|
|
19
19
|
export function renameAttributes(object, mapper) {
|
|
20
|
-
|
|
20
|
+
const returnObject = cloneDeep(object);
|
|
21
21
|
Object.keys(mapper).forEach((key) => {
|
|
22
22
|
if (returnObject.hasOwnProperty(key)) {
|
|
23
23
|
returnObject[mapper[key]] = cloneDeep(returnObject[key]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramathibodi/nuxt-commons",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Ramathibodi Nuxt modules for common components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"uid": "^2.0.2",
|
|
65
65
|
"vue": "^3.4.25",
|
|
66
66
|
"vue-signature-pad": "^3.0.2",
|
|
67
|
-
"vuetify": "^3.6.
|
|
67
|
+
"vuetify": "^3.6.8",
|
|
68
68
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|