@ramathibodi/nuxt-commons 0.0.1 → 0.0.3

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 CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.0.1"
7
+ "version": "0.0.3"
8
8
  }
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" setup>
2
2
  import { ref, watch } from 'vue'
3
+ import { isEmpty } from 'lodash-es'
3
4
  import { useAlert } from '../composables/alert'
4
5
  import type { AlertItem } from '../types/alert'
5
6
 
@@ -28,25 +29,25 @@ watch(() => alert?.hasAlert(), (hasAlert) => {
28
29
 
29
30
  <template>
30
31
  <VSnackbar
31
- v-if="currentItem"
32
- v-model="isAlertOpen"
33
- :timeout="timeout"
34
- location="center"
35
- multi-line
36
- variant="text"
37
- @update:model-value="renewAlert()"
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()"
38
39
  >
39
40
  <!-- @vue-expected-error Type conversion problem -->
40
41
  <VAlert
41
- v-model="isAlertOpen"
42
- closable
43
- :type="currentItem.alertType"
44
- elevation="2"
45
- theme="dark"
46
- variant="flat"
47
- @click:close="renewAlert()"
42
+ v-model="isAlertOpen"
43
+ closable
44
+ :type="currentItem.alertType"
45
+ elevation="2"
46
+ theme="dark"
47
+ variant="flat"
48
+ @click:close="renewAlert()"
48
49
  >
49
- {{ currentItem.statusCode ? currentItem.statusCode + ' ' : '' }}{{ currentItem.message }}{{ currentItem.data ? ' ' + currentItem.data : '' }}
50
+ {{ currentItem.statusCode ? currentItem.statusCode + ' ' : '' }} {{ currentItem.message }} {{ !isEmpty(currentItem.data) ? currentItem.data : '' }}
50
51
  </VAlert>
51
52
  </VSnackbar>
52
53
  </template>
@@ -1,6 +1,9 @@
1
1
  <script setup lang="ts">
2
- import PDF from 'pdf-vue3'
3
- import { uid } from 'uid'
2
+ import PDF from 'pdf-vue3';
3
+ import { uid } from 'uid';
4
+ import { useAlert } from '../../composables/alert'
5
+ import printJS from 'print-js'
6
+ import {ref, computed} from 'vue'
4
7
 
5
8
  const props = defineProps<{
6
9
  base64String?: string
@@ -10,6 +13,8 @@ const props = defineProps<{
10
13
  }>()
11
14
 
12
15
  const emit = defineEmits(['closeDialog'])
16
+ const base64 = ref(props.base64String)
17
+ const alert = useAlert()
13
18
 
14
19
  const generateUniqueId = (): string => {
15
20
  const uniqueId: string = uid()
@@ -35,7 +40,32 @@ const downloadPdf = (): void => {
35
40
  anchorElement.click()
36
41
  URL.revokeObjectURL(link)
37
42
  document.body.removeChild(anchorElement)
43
+ base64.value = ""
38
44
  }
45
+
46
+ const printPdf = () => {
47
+ printJS({
48
+ printable: props.base64String,
49
+ type: 'pdf',
50
+ base64: true,
51
+ onPrintDialogClose: endLoadPdf,
52
+ onError: (error: any) => {
53
+ alert?.addAlert({ message: error, alertType: 'error' })
54
+ },
55
+ })
56
+ base64.value = ""
57
+ }
58
+
59
+ const endLoadPdf = () => {
60
+ emit('closeDialog', false)
61
+ base64.value = ""
62
+ }
63
+
64
+ const isMobile = computed(() => {
65
+ if(/Android|Mobi|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Macintosh/i.test(navigator.userAgent)){
66
+ return true
67
+ }
68
+ })
39
69
  </script>
40
70
 
41
71
  <template>
@@ -44,27 +74,31 @@ const downloadPdf = (): void => {
44
74
  <v-toolbar-title>{{ props.title }}</v-toolbar-title>
45
75
  <v-spacer />
46
76
  <v-btn
47
- v-if="!props.disabled"
48
- icon="mdi mdi-download"
49
- variant="plain"
50
- @click="downloadPdf"
77
+ v-if="!isMobile"
78
+ icon="mdi mdi-printer"
79
+ variant="plain"
80
+ @click="printPdf"
81
+ />
82
+ <v-btn
83
+ v-if="!props.disabled"
84
+ icon="mdi mdi-download"
85
+ variant="plain"
86
+ @click="downloadPdf"
51
87
  />
52
88
  <v-btn
53
- icon="mdi mdi-close"
54
- variant="plain"
55
- @click="emit('closeDialog', false)"
89
+ icon="mdi mdi-close"
90
+ variant="plain"
91
+ @click="endLoadPdf"
56
92
  />
57
93
  </v-toolbar>
58
- <v-card-text>
59
- <v-row justify="center">
60
- <PDF
61
- :show-progress="true"
62
- pdf-width="100%"
63
- :src="props.base64String"
64
- :show-page-tooltip="false"
65
- :show-back-to-top-btn="false"
66
- />
67
- </v-row>
94
+ <v-card-text class="justify-center">
95
+ <PDF
96
+ :show-progress="true"
97
+ pdf-width="100%"
98
+ :src="base64"
99
+ :showPageTooltip="false"
100
+ :show-back-to-top-btn="false"
101
+ />
68
102
  </v-card-text>
69
103
  </v-card>
70
- </template>
104
+ </template>
@@ -5,13 +5,19 @@ interface DialogProps {
5
5
  modelValue: boolean
6
6
  color?: string
7
7
  }
8
+ const emit = defineEmits(['update:modelValue'])
8
9
 
9
10
  const props = defineProps<DialogProps>()
10
- const dialogVisible = ref<boolean>(false)
11
+ const dialogVisible = ref<boolean>(props.modelValue)
11
12
 
12
13
  watch(() => props.modelValue, (newValue) => {
13
14
  dialogVisible.value = newValue
14
15
  })
16
+
17
+ watch(() => dialogVisible.value, (newValue) => {
18
+ console.log("dialogVisible.value = ", newValue)
19
+ emit('update:modelValue', newValue)
20
+ })
15
21
  </script>
16
22
 
17
23
  <template>
@@ -24,7 +30,7 @@ watch(() => props.modelValue, (newValue) => {
24
30
  <v-card-text>
25
31
  <v-row>
26
32
  <v-col class="text-center">
27
- กรุณารอสักครู่
33
+ <slot>กรุณารอสักครู่</slot>
28
34
  </v-col>
29
35
  </v-row>
30
36
  </v-card-text>
@@ -11,7 +11,7 @@ interface Props {
11
11
  const props = withDefaults(defineProps<Props>(), {
12
12
  modelValue: 0,
13
13
  decimal: 2,
14
- currency: 'USD',
14
+ currency: '',
15
15
  })
16
16
 
17
17
  const formattedCurrency = computed(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
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.5.17",
67
+ "vuetify": "^3.6.6",
68
68
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
69
69
  },
70
70
  "devDependencies": {
File without changes