@hostlink/nuxt-light 1.0.7 → 1.0.9
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
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { VariableType } from "json-to-graphql-query";
|
|
3
3
|
import { ref, computed, useAttrs } from "vue";
|
|
4
|
-
import { useLight, m } from '#imports';
|
|
4
|
+
import { useLight, m, q } from '#imports';
|
|
5
5
|
import { Loading, Dialog } from "quasar";
|
|
6
|
+
import { useI18n } from "vue-i18n";
|
|
6
7
|
|
|
7
8
|
const light = useLight();
|
|
9
|
+
const i18n = useI18n();
|
|
10
|
+
|
|
11
|
+
const { system } = await q({
|
|
12
|
+
system: {
|
|
13
|
+
maxUploadSize: true
|
|
14
|
+
}
|
|
15
|
+
})
|
|
8
16
|
|
|
9
17
|
export interface LFileProps {
|
|
10
18
|
modelValue?: string;
|
|
@@ -56,18 +64,39 @@ const attrs = computed(() => {
|
|
|
56
64
|
return a;
|
|
57
65
|
});
|
|
58
66
|
|
|
59
|
-
const uploadFile = ref(null);
|
|
67
|
+
const uploadFile = ref<File | null>(null);
|
|
68
|
+
const rename = ref(true);
|
|
60
69
|
|
|
61
70
|
const onUploadFile = async () => {
|
|
71
|
+
|
|
72
|
+
if (!uploadFile.value) {
|
|
73
|
+
Dialog.create({
|
|
74
|
+
title: "Error",
|
|
75
|
+
message: i18n.t("Please select a file"),
|
|
76
|
+
color: "negative"
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//check file size
|
|
82
|
+
if (uploadFile.value.size > system.maxUploadSize) {
|
|
83
|
+
Dialog.create({
|
|
84
|
+
title: "Error",
|
|
85
|
+
message: "File size is too big. Max size is " + system.maxUploadSize + " bytes",
|
|
86
|
+
color: "negative"
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
62
91
|
Loading.show({
|
|
63
|
-
message: "Uploading file...",
|
|
92
|
+
message: i18n.t("Uploading file..."),
|
|
64
93
|
});
|
|
65
94
|
|
|
66
95
|
try {
|
|
67
|
-
|
|
96
|
+
let v = await m("fsUploadFile", {
|
|
68
97
|
path: props.path,
|
|
69
98
|
file: new VariableType("file"),
|
|
70
|
-
rename:
|
|
99
|
+
rename: rename.value
|
|
71
100
|
}, [{
|
|
72
101
|
__variables: {
|
|
73
102
|
file: {
|
|
@@ -76,6 +105,12 @@ const onUploadFile = async () => {
|
|
|
76
105
|
}
|
|
77
106
|
}
|
|
78
107
|
}]);
|
|
108
|
+
|
|
109
|
+
//remove first slash if exists
|
|
110
|
+
if (v.startsWith("/")) v = v.substr(1);
|
|
111
|
+
|
|
112
|
+
localValue.value = v;
|
|
113
|
+
|
|
79
114
|
Loading.hide();
|
|
80
115
|
|
|
81
116
|
show.value = false;
|
|
@@ -83,9 +118,10 @@ const onUploadFile = async () => {
|
|
|
83
118
|
return;
|
|
84
119
|
} catch (e: any) {
|
|
85
120
|
Dialog.create({
|
|
86
|
-
title: "Error",
|
|
121
|
+
title: i18n.t("Error"),
|
|
87
122
|
message: e.message,
|
|
88
123
|
});
|
|
124
|
+
Loading.hide();
|
|
89
125
|
}
|
|
90
126
|
|
|
91
127
|
|
|
@@ -98,12 +134,14 @@ const onUploadFile = async () => {
|
|
|
98
134
|
<q-dialog v-model="show" persistent transition-show="scale" transition-hide="scale">
|
|
99
135
|
<l-card style="width:300px">
|
|
100
136
|
<q-card-section>
|
|
101
|
-
<q-file ref="file" v-model="uploadFile" name="file" label="
|
|
137
|
+
<q-file ref="file" v-model="uploadFile" name="file" :label="$t('File')" :accept="accept" :hint="`Max upload size: ${system.maxUploadSize} bytes`"></q-file>
|
|
138
|
+
<!-- q-checkbox v-model="rename" :label="$t('Rename file if exists')"></q-checkbox-->
|
|
139
|
+
|
|
140
|
+
|
|
102
141
|
</q-card-section>
|
|
103
|
-
|
|
104
142
|
<q-card-actions align="right">
|
|
105
|
-
<q-btn flat label="Cancel" color="primary" v-close-popup></q-btn>
|
|
106
|
-
<q-btn flat label="Upload" color="primary" @click="onUploadFile"></q-btn>
|
|
143
|
+
<q-btn flat :label="$t('Cancel')" color="primary" v-close-popup></q-btn>
|
|
144
|
+
<q-btn flat :label="$t('Upload')" color="primary" @click="onUploadFile"></q-btn>
|
|
107
145
|
</q-card-actions>
|
|
108
146
|
</l-card>
|
|
109
147
|
</q-dialog>
|
|
@@ -22,7 +22,7 @@ const onBlur = () => {
|
|
|
22
22
|
}
|
|
23
23
|
</script>
|
|
24
24
|
<template>
|
|
25
|
-
<l-file-upload v-model="value" :label="context.label"
|
|
25
|
+
<l-file-upload v-bind="context.attrs" v-model="value" :label="context.label" :error="error" :type="context.inputType"
|
|
26
26
|
:error-message="errorMessage" @blur="onBlur">
|
|
27
27
|
<template v-for="(s, name) in $slots" v-slot:[name]="props" :key="name">
|
|
28
28
|
<slot :name="name" v-bind="props ?? {}"></slot>
|