@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.
Files changed (54) hide show
  1. package/README.md +96 -96
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/Alert.vue +53 -53
  4. package/dist/runtime/components/BarcodeReader.vue +98 -98
  5. package/dist/runtime/components/ExportCSV.vue +55 -55
  6. package/dist/runtime/components/FileBtn.vue +62 -62
  7. package/dist/runtime/components/ImportCSV.vue +64 -64
  8. package/dist/runtime/components/SplitterPanel.vue +59 -59
  9. package/dist/runtime/components/TabsGroup.vue +32 -32
  10. package/dist/runtime/components/TextBarcode.vue +52 -52
  11. package/dist/runtime/components/dialog/Confirm.vue +100 -100
  12. package/dist/runtime/components/dialog/Index.vue +72 -72
  13. package/dist/runtime/components/dialog/Loading.vue +39 -39
  14. package/dist/runtime/components/document/TemplateBuilder.vue +203 -216
  15. package/dist/runtime/components/form/Birthdate.vue +216 -216
  16. package/dist/runtime/components/form/CodeEditor.vue +37 -37
  17. package/dist/runtime/components/form/Date.vue +163 -163
  18. package/dist/runtime/components/form/DateTime.vue +107 -107
  19. package/dist/runtime/components/form/Dialog.vue +138 -138
  20. package/dist/runtime/components/form/File.vue +187 -187
  21. package/dist/runtime/components/form/Hidden.vue +32 -32
  22. package/dist/runtime/components/form/Login.vue +131 -131
  23. package/dist/runtime/components/form/Pad.vue +217 -217
  24. package/dist/runtime/components/form/SignPad.vue +186 -186
  25. package/dist/runtime/components/form/Table.vue +266 -266
  26. package/dist/runtime/components/form/Time.vue +158 -158
  27. package/dist/runtime/components/form/images/Capture.vue +230 -230
  28. package/dist/runtime/components/form/images/Edit.vue +114 -114
  29. package/dist/runtime/components/label/Date.vue +29 -29
  30. package/dist/runtime/components/label/Field.vue +42 -42
  31. package/dist/runtime/components/label/FormatMoney.vue +29 -29
  32. package/dist/runtime/components/label/Mask.vue +38 -38
  33. package/dist/runtime/components/master/Autocomplete.vue +159 -159
  34. package/dist/runtime/components/master/Combobox.vue +84 -84
  35. package/dist/runtime/components/master/RadioGroup.vue +78 -78
  36. package/dist/runtime/components/master/Select.vue +82 -82
  37. package/dist/runtime/components/model/Pad.vue +122 -122
  38. package/dist/runtime/components/model/Table.vue +242 -240
  39. package/dist/runtime/components/model/iterator.vue +312 -312
  40. package/dist/runtime/components/pdf/Print.vue +63 -63
  41. package/dist/runtime/components/pdf/View.vue +104 -104
  42. package/dist/runtime/composables/graphqlModel.mjs +1 -1
  43. package/dist/runtime/labs/Calendar.vue +99 -99
  44. package/dist/runtime/labs/form/EditMobile.vue +152 -152
  45. package/dist/runtime/labs/form/TextFieldMask.vue +43 -43
  46. package/dist/runtime/types/alert.d.ts +11 -11
  47. package/dist/runtime/types/formDialog.d.ts +4 -4
  48. package/dist/runtime/types/graphqlOperation.d.ts +23 -23
  49. package/dist/runtime/types/menu.d.ts +25 -25
  50. package/dist/runtime/types/modules.d.ts +7 -7
  51. package/package.json +120 -119
  52. package/scripts/postInstall.cjs +70 -70
  53. package/templates/.codegen/codegen.ts +32 -32
  54. package/templates/.codegen/plugin-schema-object.js +154 -154
@@ -1,117 +1,117 @@
1
- <script lang="ts" setup>
2
- import {ref,computed} from 'vue'
3
- import Cropper from 'cropperjs'
4
- import 'cropperjs/dist/cropper.css'
5
- import type {ImageFormat} from "exif-rotate-js"
6
-
7
- interface Props {
8
- imageFormat?: ImageFormat
9
- maxHeight?: string | number
10
- maxWidth?: string | number
11
- aspectRatio?: number
12
- }
13
-
14
- const props = withDefaults(defineProps<Props>(), {
15
- imageFormat: "image/jpeg",
16
- maxWidth: 1024
17
- })
18
-
19
- const imageData = defineModel<string>()
20
-
21
- const cropper = ref<Cropper>()
22
- const imageRef = ref<HTMLImageElement>()
23
- const dragMode = ref<string>("crop")
24
-
25
- function loadCropper() {
26
- if (cropper.value) cropper.value?.destroy()
27
- if (imageRef.value) {
28
- cropper.value = new Cropper(<HTMLImageElement>imageRef.value,{
29
- aspectRatio: props.aspectRatio
30
- })
31
- }
32
- }
33
-
34
- const dragMove = () => {
35
- cropper.value?.setDragMode('move')
36
- }
37
- const dragCrop = () => {
38
- cropper.value?.setDragMode('crop')
39
- }
40
- const rotateLeft90 = () => cropper.value?.rotate(-90)
41
- const rotateLeft = () => cropper.value?.rotate(-5)
42
- const rotateRight = () => cropper.value?.rotate(5)
43
- const rotateRight90 = () => cropper.value?.rotate(90)
44
- const flipHorizontal = () => cropper.value?.scaleX(cropper.value.getData().scaleX * -1)
45
- const flipVertical = () => cropper.value?.scaleY(cropper.value.getData().scaleY * -1)
46
- const zoomIn = () => cropper.value?.zoom(0.1)
47
- const zoomOut = () => cropper.value?.zoom(-0.1)
48
- const moveUp = () => cropper.value?.move(0, -10)
49
- const moveDown = () => cropper.value?.move(0, 10)
50
- const moveLeft = () => cropper.value?.move(-10, 0)
51
- const moveRight = () => cropper.value?.move(10, 0)
52
- const accept = () => {
53
- const croppedCanvas = cropper.value?.getCroppedCanvas()
54
- console.log(props.imageFormat)
55
- imageData.value = croppedCanvas?.toDataURL(props.imageFormat,1)
56
- }
57
- const reset = () => cropper.value?.reset()
58
-
59
- const computedMaxWidth = computed(() => {
60
- if (typeof props.maxWidth === 'number') {
61
- return `${props.maxWidth}px`
62
- } else if (!isNaN(Number(props.maxWidth))) {
63
- return `${props.maxWidth}px`
64
- }
65
- return props.maxWidth
66
- })
67
-
68
- const computedMaxHeight = computed(() => {
69
- if (typeof props.maxHeight === 'number') {
70
- return `${props.maxHeight}px`
71
- } else if (!isNaN(Number(props.maxHeight))) {
72
- return `${props.maxHeight}px`
73
- }
74
- return props.maxHeight
75
- })
76
- </script>
77
- <template>
78
- <div :style="{maxWidth:computedMaxWidth,maxHeight:computedMaxHeight}">
79
- <v-card>
80
- <v-toolbar color="primary" dark>
81
- <v-btn-toggle v-model="dragMode" class="ml-1">
82
- <v-btn value="move" icon="mdi mdi-cursor-move" @click="dragMove"></v-btn>
83
- <v-btn value="crop" icon="mdi mdi-crop" @click="dragCrop"></v-btn>
84
- </v-btn-toggle>
85
- <v-btn-group class="ml-1">
86
- <v-btn value="rotateLeft" icon="mdi mdi-rotate-left-variant" @click="rotateLeft90"></v-btn>
87
- <v-btn value="rotateRight" icon="mdi mdi-rotate-left" @click="rotateLeft"></v-btn>
88
- <v-btn value="rotateRight" icon="mdi mdi-rotate-right" @click="rotateRight"></v-btn>
89
- <v-btn value="rotateRight" icon="mdi mdi-rotate-right-variant" @click="rotateRight90"></v-btn>
90
- </v-btn-group>
91
- <v-btn-group class="ml-1">
92
- <v-btn value="flipHorizontal" icon="mdi mdi-flip-horizontal" @click="flipHorizontal"></v-btn>
93
- <v-btn value="flipVertical" icon="mdi mdi-flip-vertical" @click="flipVertical"></v-btn>
94
- </v-btn-group>
95
- <v-btn-group class="ml-1">
96
- <v-btn value="flipHorizontal" icon="mdi mdi-magnify-plus-outline" @click="zoomIn"></v-btn>
97
- <v-btn value="flipVertical" icon="mdi mdi-magnify-minus-outline" @click="zoomOut"></v-btn>
98
- </v-btn-group>
99
- <v-btn-group class="ml-1">
100
- <v-btn value="moveUp" icon="mdi mdi-arrow-up" @click="moveUp"></v-btn>
101
- <v-btn value="moveDown" icon="mdi mdi-arrow-down" @click="moveDown"></v-btn>
102
- <v-btn value="moveLeft" icon="mdi mdi-arrow-left" @click="moveLeft"></v-btn>
103
- <v-btn value="moveRight" icon="mdi mdi-arrow-right" @click="moveRight"></v-btn>
104
- </v-btn-group>
105
- <v-spacer></v-spacer>
106
- <v-btn icon="mdi mdi-check" @click="accept"></v-btn>
107
- <v-btn icon="mdi mdi-refresh" @click="reset"></v-btn>
108
- </v-toolbar>
109
- <v-card-text class="ma-0 pa-0">
110
- <img ref="imageRef" :src="imageData" alt="" @load="loadCropper" style="display: block; max-width: 100%">
111
- </v-card-text>
112
- </v-card>
113
- </div>
114
- </template>
1
+ <script lang="ts" setup>
2
+ import {ref,computed} from 'vue'
3
+ import Cropper from 'cropperjs'
4
+ import 'cropperjs/dist/cropper.css'
5
+ import type {ImageFormat} from "exif-rotate-js"
6
+
7
+ interface Props {
8
+ imageFormat?: ImageFormat
9
+ maxHeight?: string | number
10
+ maxWidth?: string | number
11
+ aspectRatio?: number
12
+ }
13
+
14
+ const props = withDefaults(defineProps<Props>(), {
15
+ imageFormat: "image/jpeg",
16
+ maxWidth: 1024
17
+ })
18
+
19
+ const imageData = defineModel<string>()
20
+
21
+ const cropper = ref<Cropper>()
22
+ const imageRef = ref<HTMLImageElement>()
23
+ const dragMode = ref<string>("crop")
24
+
25
+ function loadCropper() {
26
+ if (cropper.value) cropper.value?.destroy()
27
+ if (imageRef.value) {
28
+ cropper.value = new Cropper(<HTMLImageElement>imageRef.value,{
29
+ aspectRatio: props.aspectRatio
30
+ })
31
+ }
32
+ }
33
+
34
+ const dragMove = () => {
35
+ cropper.value?.setDragMode('move')
36
+ }
37
+ const dragCrop = () => {
38
+ cropper.value?.setDragMode('crop')
39
+ }
40
+ const rotateLeft90 = () => cropper.value?.rotate(-90)
41
+ const rotateLeft = () => cropper.value?.rotate(-5)
42
+ const rotateRight = () => cropper.value?.rotate(5)
43
+ const rotateRight90 = () => cropper.value?.rotate(90)
44
+ const flipHorizontal = () => cropper.value?.scaleX(cropper.value.getData().scaleX * -1)
45
+ const flipVertical = () => cropper.value?.scaleY(cropper.value.getData().scaleY * -1)
46
+ const zoomIn = () => cropper.value?.zoom(0.1)
47
+ const zoomOut = () => cropper.value?.zoom(-0.1)
48
+ const moveUp = () => cropper.value?.move(0, -10)
49
+ const moveDown = () => cropper.value?.move(0, 10)
50
+ const moveLeft = () => cropper.value?.move(-10, 0)
51
+ const moveRight = () => cropper.value?.move(10, 0)
52
+ const accept = () => {
53
+ const croppedCanvas = cropper.value?.getCroppedCanvas()
54
+ console.log(props.imageFormat)
55
+ imageData.value = croppedCanvas?.toDataURL(props.imageFormat,1)
56
+ }
57
+ const reset = () => cropper.value?.reset()
58
+
59
+ const computedMaxWidth = computed(() => {
60
+ if (typeof props.maxWidth === 'number') {
61
+ return `${props.maxWidth}px`
62
+ } else if (!isNaN(Number(props.maxWidth))) {
63
+ return `${props.maxWidth}px`
64
+ }
65
+ return props.maxWidth
66
+ })
67
+
68
+ const computedMaxHeight = computed(() => {
69
+ if (typeof props.maxHeight === 'number') {
70
+ return `${props.maxHeight}px`
71
+ } else if (!isNaN(Number(props.maxHeight))) {
72
+ return `${props.maxHeight}px`
73
+ }
74
+ return props.maxHeight
75
+ })
76
+ </script>
77
+ <template>
78
+ <div :style="{maxWidth:computedMaxWidth,maxHeight:computedMaxHeight}">
79
+ <v-card>
80
+ <v-toolbar color="primary" dark>
81
+ <v-btn-toggle v-model="dragMode" class="ml-1">
82
+ <v-btn value="move" icon="mdi mdi-cursor-move" @click="dragMove"></v-btn>
83
+ <v-btn value="crop" icon="mdi mdi-crop" @click="dragCrop"></v-btn>
84
+ </v-btn-toggle>
85
+ <v-btn-group class="ml-1">
86
+ <v-btn value="rotateLeft" icon="mdi mdi-rotate-left-variant" @click="rotateLeft90"></v-btn>
87
+ <v-btn value="rotateRight" icon="mdi mdi-rotate-left" @click="rotateLeft"></v-btn>
88
+ <v-btn value="rotateRight" icon="mdi mdi-rotate-right" @click="rotateRight"></v-btn>
89
+ <v-btn value="rotateRight" icon="mdi mdi-rotate-right-variant" @click="rotateRight90"></v-btn>
90
+ </v-btn-group>
91
+ <v-btn-group class="ml-1">
92
+ <v-btn value="flipHorizontal" icon="mdi mdi-flip-horizontal" @click="flipHorizontal"></v-btn>
93
+ <v-btn value="flipVertical" icon="mdi mdi-flip-vertical" @click="flipVertical"></v-btn>
94
+ </v-btn-group>
95
+ <v-btn-group class="ml-1">
96
+ <v-btn value="flipHorizontal" icon="mdi mdi-magnify-plus-outline" @click="zoomIn"></v-btn>
97
+ <v-btn value="flipVertical" icon="mdi mdi-magnify-minus-outline" @click="zoomOut"></v-btn>
98
+ </v-btn-group>
99
+ <v-btn-group class="ml-1">
100
+ <v-btn value="moveUp" icon="mdi mdi-arrow-up" @click="moveUp"></v-btn>
101
+ <v-btn value="moveDown" icon="mdi mdi-arrow-down" @click="moveDown"></v-btn>
102
+ <v-btn value="moveLeft" icon="mdi mdi-arrow-left" @click="moveLeft"></v-btn>
103
+ <v-btn value="moveRight" icon="mdi mdi-arrow-right" @click="moveRight"></v-btn>
104
+ </v-btn-group>
105
+ <v-spacer></v-spacer>
106
+ <v-btn icon="mdi mdi-check" @click="accept"></v-btn>
107
+ <v-btn icon="mdi mdi-refresh" @click="reset"></v-btn>
108
+ </v-toolbar>
109
+ <v-card-text class="ma-0 pa-0">
110
+ <img ref="imageRef" :src="imageData" alt="" @load="loadCropper" style="display: block; max-width: 100%">
111
+ </v-card-text>
112
+ </v-card>
113
+ </div>
114
+ </template>
115
115
  <style>
116
116
  .cropper-bg{background-repeat:repeat!important}
117
117
  </style>
@@ -1,29 +1,29 @@
1
- <script lang="ts" setup>
2
- import { computed } from 'vue'
3
- import { type dateFormat, type dateTimeFormat, Datetime } from '../../utils/datetime'
4
-
5
- interface Props {
6
- modelValue?: string
7
- locale?: 'TH' | 'EN'
8
- fromFormat?: string
9
- format?: dateFormat | dateTimeFormat | string
10
- }
11
-
12
- const props = withDefaults(defineProps<Props>(), {
13
- locale: 'TH',
14
- format: 'shortDate',
15
- })
16
-
17
- const formattedDate = computed(() => {
18
- if (!props.modelValue) {
19
- return null
20
- }
21
-
22
- const dateTime = Datetime().fromString(props.modelValue, props.fromFormat)
23
- return dateTime.luxonDateTime.isValid ? dateTime.toFormat(props.format, props.locale) : props.modelValue
24
- })
25
- </script>
26
-
27
- <template>
28
- {{ formattedDate }}
29
- </template>
1
+ <script lang="ts" setup>
2
+ import { computed } from 'vue'
3
+ import { type dateFormat, type dateTimeFormat, Datetime } from '../../utils/datetime'
4
+
5
+ interface Props {
6
+ modelValue?: string
7
+ locale?: 'TH' | 'EN'
8
+ fromFormat?: string
9
+ format?: dateFormat | dateTimeFormat | string
10
+ }
11
+
12
+ const props = withDefaults(defineProps<Props>(), {
13
+ locale: 'TH',
14
+ format: 'shortDate',
15
+ })
16
+
17
+ const formattedDate = computed(() => {
18
+ if (!props.modelValue) {
19
+ return null
20
+ }
21
+
22
+ const dateTime = Datetime().fromString(props.modelValue, props.fromFormat)
23
+ return dateTime.luxonDateTime.isValid ? dateTime.toFormat(props.format, props.locale) : props.modelValue
24
+ })
25
+ </script>
26
+
27
+ <template>
28
+ {{ formattedDate }}
29
+ </template>
@@ -1,42 +1,42 @@
1
- <script lang="ts" setup>
2
- interface Props {
3
- label: string
4
- value?: string | null | undefined
5
- horizontal?: boolean
6
- }
7
-
8
- const props = withDefaults(defineProps<Props>(), {
9
- label: '', value: '',
10
- })
11
- </script>
12
-
13
- <template>
14
- <div v-if="horizontal" class="d-flex align-end" :="$attrs">
15
- <div class="text-medium-emphasis">
16
- <slot name="label">
17
- {{ label }}:
18
- </slot>
19
- </div>
20
- <div class="ml-1">
21
- <slot name="value">
22
- {{ value }}
23
- </slot>
24
- </div>
25
- </div>
26
- <v-card v-else variant="flat" :="$attrs">
27
- <VCardSubtitle class="ma-0 pa-0 text-black">
28
- <slot name="label">
29
- {{ label }}
30
- </slot>
31
- </VCardSubtitle>
32
- <VCardText class="text-h6 pa-0 mb-2">
33
- <slot name="value">
34
- {{ value }}
35
- </slot>
36
- </VCardText>
37
- </v-card>
38
- </template>
39
-
40
- <style lang="">
41
-
42
- </style>
1
+ <script lang="ts" setup>
2
+ interface Props {
3
+ label: string
4
+ value?: string | null | undefined
5
+ horizontal?: boolean
6
+ }
7
+
8
+ const props = withDefaults(defineProps<Props>(), {
9
+ label: '', value: '',
10
+ })
11
+ </script>
12
+
13
+ <template>
14
+ <div v-if="horizontal" class="d-flex align-end" :="$attrs">
15
+ <div class="text-medium-emphasis">
16
+ <slot name="label">
17
+ {{ label }}:
18
+ </slot>
19
+ </div>
20
+ <div class="ml-1">
21
+ <slot name="value">
22
+ {{ value }}
23
+ </slot>
24
+ </div>
25
+ </div>
26
+ <v-card v-else variant="flat" :="$attrs">
27
+ <VCardSubtitle class="ma-0 pa-0 text-black">
28
+ <slot name="label">
29
+ {{ label }}
30
+ </slot>
31
+ </VCardSubtitle>
32
+ <VCardText class="text-h6 pa-0 mb-2">
33
+ <slot name="value">
34
+ {{ value }}
35
+ </slot>
36
+ </VCardText>
37
+ </v-card>
38
+ </template>
39
+
40
+ <style lang="">
41
+
42
+ </style>
@@ -1,29 +1,29 @@
1
- <script lang="ts" setup>
2
- import currency from 'currency.js'
3
- import { computed } from 'vue'
4
-
5
- interface Props {
6
- modelValue: number
7
- decimal?: number
8
- currency?: string
9
- }
10
-
11
- const props = withDefaults(defineProps<Props>(), {
12
- modelValue: 0,
13
- decimal: 2,
14
- currency: '',
15
- })
16
-
17
- const formattedCurrency = computed(() => {
18
- return currency(props.modelValue, {
19
- pattern: `# !`,
20
- symbol: props.currency,
21
- separator: ',',
22
- precision: props.decimal,
23
- }).format()
24
- })
25
- </script>
26
-
27
- <template>
28
- {{ formattedCurrency }}
29
- </template>
1
+ <script lang="ts" setup>
2
+ import currency from 'currency.js'
3
+ import { computed } from 'vue'
4
+
5
+ interface Props {
6
+ modelValue: number
7
+ decimal?: number
8
+ currency?: string
9
+ }
10
+
11
+ const props = withDefaults(defineProps<Props>(), {
12
+ modelValue: 0,
13
+ decimal: 2,
14
+ currency: '',
15
+ })
16
+
17
+ const formattedCurrency = computed(() => {
18
+ return currency(props.modelValue, {
19
+ pattern: `# !`,
20
+ symbol: props.currency,
21
+ separator: ',',
22
+ precision: props.decimal,
23
+ }).format()
24
+ })
25
+ </script>
26
+
27
+ <template>
28
+ {{ formattedCurrency }}
29
+ </template>
@@ -1,38 +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>
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>