free-fe-core-modules 0.0.3 → 0.0.4

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.
@@ -1,328 +0,0 @@
1
- <template>
2
- <div class="row input-field-image">
3
- <span
4
- :class="`field-label ${(Field.Label && Field.Label.trim().length)
5
- ? '' : 'field-label-empty'} ${Field.Required ? 'required' : ''}`"
6
- v-if="Field.Label && !Field.dense">
7
- <q-tooltip v-if="Field.Description" anchor="top right">
8
- {{
9
- Field.Description
10
- }}
11
- </q-tooltip>
12
- {{ Field.Label || '' }}
13
- <span v-if="Field.Required" class="required-mark">*</span>
14
- </span>
15
- <q-uploader
16
- @uploaded="uploaded"
17
- @removed="
18
- fieldData = '';
19
- $emit('input');
20
- "
21
- @added="fileAdded"
22
- @rejected="filesRejected"
23
- ref="uploader"
24
- :factory="factoryFn"
25
- auto-upload
26
- :max-file-size="maxFileSize"
27
- :class="(Field.dense ?
28
- `no-shadow dense` : `${Field.onlyIcon ? 'only-icon' : ''}`)
29
- + (hasError ? ' input-field--error' : '')"
30
- >
31
- <template v-slot:list="scope">
32
- <div class="uploader-btns row no-wrap items-center" v-if="!Field.dense && !onlyIcon">
33
- <q-spinner v-if="scope.isUploading" class="q-uploader__spinner" />
34
- <q-btn
35
- v-if="!scope.isUploading"
36
- type="a"
37
- icon="cloud_upload"
38
- dense
39
- flat
40
- class="upload-btn"
41
- label="点击上传"
42
- :disabled="Field.ReadOnly"
43
- >
44
- <q-uploader-add-trigger v-if="!Field.ReadOnly" />
45
- </q-btn>
46
- <q-btn
47
- v-if="scope.isUploading"
48
- icon="clear"
49
- @click="scope.abort"
50
- round
51
- class="clear-btn"
52
- dense
53
- flat
54
- :disabled="Field.ReadOnly"
55
- ></q-btn>
56
- <slot name="warning"></slot>
57
- </div>
58
-
59
- <q-btn
60
- v-if="onlyIcon && scope.files.length <= 0"
61
- type="a"
62
- :icon="scope.files.length ? 'check' : 'cloud_upload'"
63
- dense
64
- flat
65
- :disabled="Field.ReadOnly"
66
- >
67
- <q-uploader-add-trigger />
68
- </q-btn>
69
- <q-img
70
- v-if="onlyIcon && scope.files.length > 0"
71
- :src="$filter('serverThumb',`${scope.files[0].id}`)"
72
- style="width: 32px; max-height: 32px;"
73
- >
74
- <q-uploader-add-trigger/>
75
- </q-img>
76
-
77
- <q-item v-else-if="Field.dense" class="items-center q-pa-none">
78
- <q-item-section v-if="scope.files.length && scope.files[0].id" thumbnail>
79
- <q-img
80
- :src="`${ctx.config.thumbUrlBase}${scope.files[0].id}`"
81
- style="width: 48px; max-height: 48px;"
82
- >
83
- <q-uploader-add-trigger v-if="!Field.ReadOnly" />
84
- </q-img>
85
- </q-item-section>
86
-
87
- <q-item-section v-if="scope.files.length && scope.files[0].__img" thumbnail class="gt-xs">
88
- <q-img :src="scope.files[0].__img.src">
89
- <q-uploader-add-trigger v-if="!Field.ReadOnly" />
90
- </q-img>
91
- </q-item-section>
92
-
93
- <q-item-section v-if="!scope.files.length">
94
- <q-btn
95
- v-if="!scope.isUploading"
96
- type="a"
97
- icon="cloud_upload"
98
- class="upload-btn"
99
- dense
100
- flat
101
- :disabled="Field.ReadOnly"
102
- >
103
- <q-uploader-add-trigger v-if="!Field.ReadOnly" />
104
- </q-btn>
105
- </q-item-section>
106
- </q-item>
107
-
108
- <div v-else-if="scope.files.length" class="file-list row items-start justify-start">
109
- <q-card
110
- flat
111
- class="file-list-item"
112
- v-for="(file, index) in scope.files" :key="index">
113
- <e-icon class="file-image" :name="fileThumb(file)" thumb
114
- :relative="filePreviewType(file) !== 'image'"
115
- @click="preview(file)">
116
- <div class="view-btn-wrapper absolute-full justify-center text-center">
117
- <q-btn
118
- flat
119
- class="view-btn full-height full-width"
120
- @click="preview(file)"
121
- >查看</q-btn>
122
- </div>
123
- </e-icon>
124
- <span class="file-name full-width ellipsis">
125
- <a
126
- v-if="file && file.id"
127
- target="_blank"
128
- :href="$filter('serverPath',file.id)"
129
- :download="file.name">
130
- {{ file.name }}
131
- </a>
132
- <span v-else-if="file && file.name">
133
- {{file.name}}
134
- </span>
135
- <q-tooltip>{{ file.name }}</q-tooltip>
136
- </span>
137
-
138
- <span class="file-size full-width ellipsis">
139
- Size: {{ file.sizeLabel || file.__sizeLabel }}
140
- </span>
141
-
142
- <q-btn
143
- flat
144
- dense
145
- round
146
- class="delete-btn"
147
- icon="close"
148
- @click="scope.removeFile(file)"
149
- :disabled="Field.ReadOnly"
150
- />
151
- </q-card>
152
- </div>
153
-
154
- <div class="input-field--error-tag" v-if="hasError">
155
- <e-icon name="error"></e-icon>
156
- </div>
157
- </template>
158
- </q-uploader>
159
- <q-dialog class="image-preview-dialog"
160
- flat
161
- full-width full-height v-model="showPreview"
162
- style="background: rgba(0,0,0,0)">
163
- <div class="image-preview">
164
- <q-img
165
- v-if="previewType=== 'image'"
166
- contain :src="previewFile"
167
- @click="showPreview=false"
168
- style="height: 100%; max-width: 100%;">
169
- </q-img>
170
-
171
- <q-pdfviewer
172
- v-if="previewType === 'pdf'"
173
- v-model="showPreview"
174
- @click="showPreview=false"
175
- :src="previewFile"
176
- type="pdfjs"
177
- style="height: 100%; max-width: 100%;"
178
- />
179
- </div>
180
- </q-dialog>
181
- </div>
182
- </template>
183
-
184
- <script>
185
- import { defineComponent } from 'vue';
186
- import mixnins from 'free-fe-mixins';
187
-
188
- export default defineComponent({
189
- name: 'InputFieldImage',
190
- mixins: [mixnins.UploaderMixin, mixnins.InputFieldMixin],
191
- emits:['input'],
192
- fieldInfo: {
193
- Category: 'Upload',
194
- Label: '图片',
195
- Value: 'Image',
196
- Extra: [
197
- {
198
- Type: 'String',
199
- Label: '支持的文件类型',
200
- Name: 'Options.Ext',
201
- Default: 'jpg,png,bmp',
202
- },
203
- {
204
- Type: 'String',
205
- Label: '最大文件大小',
206
- Name: 'MaxValue',
207
- Default: '10m',
208
- },
209
- ],
210
- Description: '',
211
- },
212
- props: {
213
- dense: { type: Boolean, default: false },
214
- onlyIcon: { type: Boolean, default: false },
215
- },
216
- data() {
217
- return {
218
- hasError: false,
219
- };
220
- },
221
- watch: {
222
- fieldData() {
223
- if (this.fieldData) {
224
- try {
225
- this.$refs.uploader.files = (typeof this.fieldData === 'string') ? [JSON.parse(this.fieldData)] : [this.fieldData];
226
- } catch (ex) {
227
- //
228
- }
229
- }
230
- },
231
- },
232
- mounted() {
233
- if (this.fieldData) {
234
- try {
235
- this.$refs.uploader.files = (typeof this.fieldData === 'string') ? [JSON.parse(this.fieldData)] : [this.fieldData];
236
- } catch (ex) {
237
- //
238
- }
239
- }
240
- },
241
- methods: {
242
- validate() {
243
- if (this.Field.Required) {
244
- this.hasError = this.$refs.uploader.files.length <= 0;
245
- return this.$refs.uploader.files.length > 0;
246
- }
247
-
248
- const rules = Array.isArray(typeof this.Field.Rules) ? this.Field.Rules : [this.Field.Rules];
249
-
250
- let isValid = true;
251
- for (let i = 0; i < rules.length; i += 1) {
252
- const r = rules[i];
253
-
254
- if (typeof r === 'function') {
255
- isValid = isValid && r(this.$refs.uploader.files);
256
- }
257
- }
258
-
259
- this.hasError = !isValid;
260
- return isValid;
261
- },
262
- factoryFn() {
263
- return {
264
- url: this.Field.url || `${this.ctx.config.baseUrl}/upload`,
265
- fieldName: 'file',
266
- };
267
- },
268
- fileAdded(files) {
269
- this.$refs.uploader.files = files;
270
- },
271
- uploaded(info) {
272
- if (info && info.files && info.files.length && info.files[0].xhr) {
273
- const { xhr } = info.files[0];
274
- let res;
275
- if (xhr.response) {
276
- if (typeof xhr.response === 'string') {
277
- //
278
- res = JSON.parse(xhr.response);
279
- } else if (typeof xhr.response === 'object') {
280
- //
281
- res = xhr.response;
282
- } else {
283
- //
284
- return;
285
- }
286
-
287
- if (res && res.msg === 'OK') {
288
- // this.fieldData = JSON.stringify({
289
- // id: res.data.id,
290
- // // eslint-disable-next-line no-underscore-dangle
291
- // sizeLabel: info.files[0].__sizeLabel,
292
- // name: info.files[0].name,
293
- // size: info.files[0].size,
294
- // type: info.files[0].type,
295
- // });
296
- this.fieldData = {
297
- id: res.data.id,
298
- // eslint-disable-next-line no-underscore-dangle
299
- sizeLabel: info.files[0].__sizeLabel,
300
- name: info.files[0].name,
301
- size: info.files[0].size,
302
- type: info.files[0].type,
303
- };
304
-
305
- this.$emit('input');
306
- }
307
- }
308
- }
309
-
310
- this.validate();
311
- },
312
- },
313
- });
314
- </script>
315
-
316
- <style lang="sass">
317
- .input-field-image
318
- .only-icon
319
- text-align: center
320
- width: 32px
321
- .q-btn
322
- max-width: 32px
323
- .q-uploader__header
324
- display: none
325
- .q-uploader__list
326
- min-height: 32px
327
- padding: 0
328
- </style>
@@ -1,285 +0,0 @@
1
- <template>
2
- <div class="row input-field-image-list">
3
- <span
4
- :class="`field-label ${(Field.Label && Field.Label.trim().length)
5
- ? '' : 'field-label-empty'} ${Field.Required ? 'required' : ''}`"
6
- v-if="Field.Label !== void 0">
7
- <q-tooltip v-if="Field.Description" anchor="top right">{{Field.Description}}</q-tooltip>
8
- {{Field.Label || ''}}
9
- <span v-if="Field.Required" class="required-mark">*</span>
10
- </span>
11
- <q-uploader
12
- @finish="uploaded"
13
- @removed="uploaded"
14
- @rejected="filesRejected"
15
- :factory="factoryFn"
16
- multiple
17
- :max-files="Field.Options && Field.Options.MaxCount"
18
- :max-file-size="maxFileSize"
19
- :max-total-size="maxTotalSize"
20
- :class="`q-ma-xs ${hasError ? 'input-field--error' : ''}`"
21
- ref="uploader"
22
- >
23
- <template v-slot:list="scope">
24
- <div class="uploader-btns row no-wrap items-center">
25
- <q-spinner v-if="scope.isUploading" class="q-uploader__spinner" />
26
- <q-btn
27
- v-if="scope.canAddFiles"
28
- type="a"
29
- icon="add_box"
30
- label="点击添加"
31
- class="add-btn"
32
- dense
33
- flat
34
- :disabled="Field.ReadOnly"
35
- >
36
- <q-uploader-add-trigger v-if="!Field.ReadOnly"/>
37
- </q-btn>
38
- <q-btn
39
- v-if="scope.canUpload"
40
- icon="cloud_upload"
41
- @click="scope.upload"
42
- class="upload-btn"
43
- label="点击上传"
44
- dense
45
- flat
46
- :disabled="Field.ReadOnly"
47
- ></q-btn>
48
-
49
- <q-btn
50
- v-if="scope.isUploading"
51
- icon="clear"
52
- @click="scope.abort"
53
- class="abort-btn"
54
- round
55
- dense
56
- flat
57
- :disabled="Field.ReadOnly"
58
- ></q-btn>
59
- <slot name="warning"></slot>
60
- </div>
61
-
62
- <div v-if="scope.files.length" class="file-list row items-start justify-start q-gutter-xl">
63
- <q-card
64
- flat
65
- class="file-list-item"
66
- v-for="(file, index) in scope.files" :key="index">
67
- <e-icon class="file-image" :name="fileThumb(file)" thumb
68
- :relative="filePreviewType(file) !== 'image'"
69
- @click="preview(file)">
70
- <div class="view-btn-wrapper absolute-full justify-center text-center">
71
- <q-btn
72
- flat
73
- class="view-btn full-height full-width"
74
- @click="preview(file)"
75
- >查看</q-btn>
76
- </div>
77
- </e-icon>
78
- <span class="file-name full-width ellipsis">
79
- {{ file.name }}
80
- <q-tooltip>{{ file.name }}</q-tooltip>
81
- </span>
82
-
83
- <span class="file-size full-width ellipsis">
84
- Size: {{ file.sizeLabel || file.__sizeLabel }}
85
- </span>
86
-
87
- <q-btn
88
- flat
89
- dense
90
- round
91
- class="delete-btn"
92
- icon="close"
93
- @click="scope.removeFile(file)"
94
- :disabled="Field.ReadOnly"
95
- />
96
- </q-card>
97
- </div>
98
- <!-- <q-list separator v-if="scope.files.length">
99
- <q-item>
100
- <q-item-section v-for="(file, index) in scope.files" :key="index">
101
- <q-item-label class="full-width ellipsis">
102
- {{ file.name }}
103
- <q-tooltip>{{ file.name }}</q-tooltip>
104
- </q-item-label>
105
-
106
- <q-item-label caption>Size: {{ file.sizeLabel || file.__sizeLabel }}</q-item-label>
107
-
108
- <q-item-section v-if="file.__img" thumbnail class="gt-xs">
109
- <img :src="file.__img.src" />
110
- </q-item-section>
111
- <q-item-section v-if="file.id" thumbnail class="gt-xs">
112
- <img :src="`${ctx.config.thumbUrlBase}${file.id}`" />
113
- </q-item-section>
114
-
115
- <q-item-section side>
116
- <q-btn
117
- class="gt-xs"
118
- size="12px"
119
- flat
120
- dense
121
- round
122
- icon="delete"
123
- @click="scope.removeFile(file)"
124
- :disabled="Field.ReadOnly"
125
- />
126
- </q-item-section>
127
- </q-item-section>
128
- </q-item>
129
- </q-list> -->
130
- <!-- <div v-else class="text-center">no file selected yet</div> -->
131
- <div class="input-field--error-tag" v-if="hasError">
132
- <e-icon name="error"></e-icon>
133
- </div>
134
- </template>
135
- </q-uploader>
136
- <q-dialog class="image-preview-dialog"
137
- flat
138
- full-width full-height v-model="showPreview"
139
- style="background: rgba(0,0,0,0)">
140
- <div class="image-preview">
141
- <q-img
142
- v-if="previewType=== 'image'"
143
- contain :src="previewFile"
144
- @click="showPreview=false"
145
- style="height: 100%; max-width: 100%;">
146
- </q-img>
147
-
148
- <q-pdfviewer
149
- v-if="previewType === 'pdf'"
150
- v-model="showPreview"
151
- @click="showPreview=false"
152
- :src="previewFile"
153
- type="pdfjs"
154
- style="height: 100%; max-width: 100%;"
155
- />
156
- </div>
157
- </q-dialog>
158
- </div>
159
- </template>
160
-
161
- <script>
162
- import { defineComponent } from 'vue';
163
- import mixnins from 'free-fe-mixins';
164
-
165
- export default defineComponent({
166
- name: 'InputFieldImageList',
167
- mixins: [mixnins.UploaderMixin, mixnins.InputFieldMixin],
168
- emits:['input'],
169
- fieldInfo: {
170
- Category: 'Upload',
171
- Label: '图片列表',
172
- Value: 'ImageList',
173
- Extra: [
174
- {
175
- Type: 'String',
176
- Label: '支持的文件类型',
177
- Name: 'Options.Ext',
178
- Default: 'jpg,png,bmp',
179
- },
180
- {
181
- Type: 'String',
182
- Label: '最大文件大小',
183
- Name: 'MaxValue',
184
- Default: '10m',
185
- },
186
- {
187
- Type: 'String',
188
- Label: '最大总大小',
189
- Name: 'Options.MaxTotal',
190
- Default: '50m',
191
- },
192
- ],
193
- Description: '',
194
- },
195
- data() {
196
- return {
197
- hasError: false,
198
- };
199
- },
200
- watch: {
201
- fieldData() {
202
- if (this.fieldData) {
203
- this.$refs.uploader.files = this.fieldData;
204
- }
205
- },
206
- },
207
- mounted() {
208
- if (this.fieldData) {
209
- try {
210
- this.$refs.uploader.files = this.fieldData;
211
- } catch (ex) {
212
- //
213
- }
214
- }
215
- },
216
- methods: {
217
- validate() {
218
- if (this.Field.Required) {
219
- this.hasError = this.$refs.uploader.files.length <= 0;
220
- return this.$refs.uploader.files.length > 0;
221
- }
222
-
223
- const rules = Array.isArray(typeof this.Field.Rules) ? this.Field.Rules : [this.Field.Rules];
224
-
225
- let isValid = true;
226
- for (let i = 0; i < rules.length; i += 1) {
227
- const r = rules[i];
228
-
229
- if (typeof r === 'function') {
230
- isValid = isValid && r(this.$refs.uploader.files);
231
- }
232
- }
233
-
234
- this.hasError = !isValid;
235
- return isValid;
236
- },
237
- factoryFn() {
238
- return {
239
- url: this.Field.url || `${this.ctx.config.baseUrl}/upload`,
240
- fieldName: 'file',
241
- };
242
- },
243
- uploaded() {
244
- const uploadedFiles = [];
245
- for (let i = 0; i < this.$refs.uploader.files.length; i += 1) {
246
- const file = this.$refs.uploader.files[i];
247
-
248
- const { xhr } = file;
249
- let res;
250
- if (xhr && xhr.response) {
251
- if (typeof xhr.response === 'string') {
252
- //
253
- res = JSON.parse(xhr.response);
254
- } else if (typeof xhr.response === 'object') {
255
- //
256
- res = xhr.response;
257
- } else {
258
- //
259
- return;
260
- }
261
-
262
- if (res && res.msg === 'OK') {
263
- uploadedFiles.push({
264
- id: res.data.id,
265
- // eslint-disable-next-line no-underscore-dangle
266
- sizeLabel: file.__sizeLabel,
267
- name: file.name,
268
- size: file.size,
269
- type: file.type,
270
- });
271
- }
272
- } else if (file.id) {
273
- // old files
274
- uploadedFiles.push(file);
275
- }
276
- }
277
-
278
- this.fieldData = uploadedFiles;
279
- this.$emit('input');
280
-
281
- this.validate();
282
- },
283
- },
284
- });
285
- </script>
@@ -1,76 +0,0 @@
1
- <template>
2
- <div class="row input-field-image-list combined input-field--readonly">
3
- <span
4
- :class="`field-label ${(Field.Label && Field.Label.trim().length)
5
- ? '' : 'field-label-empty'} ${Field.Required ? 'required' : ''}`"
6
- v-if="Field.Label !== void 0">
7
- <q-tooltip v-if="Field.Description" anchor="top right">{{Field.Description}}</q-tooltip>
8
- {{Field.Label || ''}}
9
- </span>
10
- <q-uploader
11
- multiple
12
- :class="`q-ma-xs `"
13
- ref="uploader"
14
- >
15
- <template v-slot:list="scope">
16
- <div v-if="scope.files.length" class="file-list row items-start justify-start q-gutter-xl">
17
- <q-card
18
- flat
19
- class="file-list-item"
20
- v-for="(file, index) in scope.files" :key="index">
21
- <e-icon class="file-image" :name="fileThumb(file)" thumb :relative="false">
22
- <div class="view-btn-wrapper absolute-full justify-center text-center">
23
- <q-btn
24
- flat
25
- class="view-btn full-height full-width"
26
- @click="preview(file)"
27
- >查看</q-btn>
28
- </div>
29
- </e-icon>
30
- <span class="file-name full-width ellipsis">
31
- {{ file.name }}
32
- <q-tooltip>{{ file.name }}</q-tooltip>
33
- </span>
34
-
35
- <span class="file-size full-width ellipsis">
36
- Size: {{ file.sizeLabel || file.__sizeLabel }}
37
- </span>
38
- </q-card>
39
- </div>
40
- </template>
41
- </q-uploader>
42
- <q-dialog class="image-preview-dialog"
43
- flat
44
- full-width full-height v-model="showPreview"
45
- style="background: rgba(0,0,0,0)">
46
- <div class="image-preview">
47
- <q-img contain :src="previewFile"
48
- @click="showPreview=false"
49
- style="height: 100%; max-width: 100%;"></q-img>
50
- </div>
51
- </q-dialog>
52
- </div>
53
- </template>
54
-
55
- <script>
56
- import { defineComponent } from 'vue';
57
- import mixnins from 'free-fe-mixins';
58
-
59
- export default defineComponent({
60
- name: 'InputFieldImageListCombined',
61
- mixins: [mixnins.UploaderMixin, mixnins.InputFieldMixin],
62
- fieldInfo: {
63
- Category: 'Upload',
64
- Label: '合并图片列表',
65
- Value: 'ImageListCombined',
66
- Description: '',
67
- },
68
- watch: {
69
- fieldData() {
70
- if (this.fieldData) {
71
- this.$refs.uploader.files = this.fieldData;
72
- }
73
- },
74
- },
75
- });
76
- </script>