free-fe-core-modules 0.0.16 → 0.0.17

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 (57) hide show
  1. package/components/Basic/EIcon.vue +3 -0
  2. package/free-field/Fields/AgreementCheck.js +8 -8
  3. package/free-field/Fields/ApiCall.js +1 -1
  4. package/free-field/Fields/Boolean.js +19 -52
  5. package/free-field/Fields/Category.js +1 -1
  6. package/free-field/Fields/Check.js +8 -3
  7. package/free-field/Fields/Column.vue +12 -9
  8. package/free-field/Fields/Customize.js +1 -1
  9. package/free-field/Fields/Date.js +1 -1
  10. package/free-field/Fields/DateRange.js +2 -2
  11. package/free-field/Fields/DynamicList.js +2 -1
  12. package/free-field/Fields/File.vue +393 -0
  13. package/free-field/Fields/FileList.vue +460 -0
  14. package/free-field/Fields/FileListCombined.vue +172 -0
  15. package/free-field/Fields/FixedList.vue +4 -3
  16. package/free-field/Fields/{InputFieldList.vue → FreeFieldList.vue} +34 -11
  17. package/free-field/Fields/Image.vue +361 -0
  18. package/free-field/Fields/ImageList.vue +353 -0
  19. package/free-field/Fields/ImageListCombined.vue +108 -0
  20. package/free-field/Fields/Labels.vue +3 -5
  21. package/free-field/Fields/MixedTable.vue +2 -2
  22. package/free-field/Fields/Number.js +1 -1
  23. package/free-field/Fields/NumberRange.vue +9 -8
  24. package/free-field/Fields/Password.js +1 -1
  25. package/free-field/Fields/Permission.vue +2 -2
  26. package/free-field/Fields/PermissionEditor.vue +2 -2
  27. package/free-field/Fields/QueryFilters.vue +1 -1
  28. package/free-field/Fields/RadioList.vue +3 -3
  29. package/free-field/Fields/Rich.vue +27 -4
  30. package/free-field/Fields/Row.vue +13 -10
  31. package/free-field/Fields/Search.vue +25 -25
  32. package/free-field/Fields/Select.vue +17 -13
  33. package/free-field/Fields/SelectionChain.vue +1 -1
  34. package/free-field/Fields/Separator.js +1 -1
  35. package/free-field/Fields/SingleList.vue +1 -1
  36. package/free-field/Fields/Static.js +1 -1
  37. package/free-field/Fields/String.js +15 -3
  38. package/free-field/Fields/Tabs.vue +9 -9
  39. package/free-field/Fields/Text.js +2 -1
  40. package/free-field/Fields/Time.vue +1 -1
  41. package/free-field/Fields/TimeRange.vue +2 -2
  42. package/free-field/Fields/Year.js +1 -1
  43. package/free-field/Fields/YearRange.vue +2 -2
  44. package/free-field/Fields/index.js +20 -13
  45. package/free-field/composible/fieldWrapper.js +136 -10
  46. package/free-field/composible/useFreeField.js +17 -6
  47. package/free-field/composible/useUploader.js +320 -0
  48. package/free-field/style.scss +173 -0
  49. package/i18n/en-us/index.js +3 -0
  50. package/i18n/fields/en-us/index.js +1 -0
  51. package/i18n/fields/zh-cn/index.js +1 -0
  52. package/i18n/zh-cn/index.js +3 -0
  53. package/index.js +7 -0
  54. package/package.json +1 -1
  55. package/view/menu/index.vue +6 -6
  56. package/view/system/index.vue +1 -1
  57. package/free-field/style.sass +0 -11
@@ -13,6 +13,7 @@ import {
13
13
  import { freeFieldProps } from "./useFreeField";
14
14
  import { useFormValidator } from '../../composible/useFormValidator';
15
15
 
16
+ import '../style.scss';
16
17
 
17
18
  export default defineComponent({
18
19
  name: "FreeFieldWrapper",
@@ -71,6 +72,7 @@ export default defineComponent({
71
72
  // eslint-disable-next-line no-eval
72
73
  return eval(funcStr);
73
74
  } catch (ex) {
75
+ console.error(ex)
74
76
  return undefined;
75
77
  }
76
78
  };
@@ -154,13 +156,13 @@ export default defineComponent({
154
156
 
155
157
  const warningSlot = (!props.noWarning && localField.value.Warning)
156
158
  && h('span', {
157
- class: 'input-field-warning no-wrap',
159
+ class: 'free-field-warning no-wrap',
158
160
  },
159
161
  [
160
- h('span', { class: 'input-field-warning-icon' }),
161
- h('span', { class: 'input-field-warning-icon-sign-top' }),
162
- h('span', { class: 'input-field-warning-icon-sign-dot' }),
163
- h('span', { class: 'input-field-warning-text ellipsis' }, localField.value.Warning),
162
+ h('span', { class: 'free-field-warning-icon' }),
163
+ h('span', { class: 'free-field-warning-icon-sign-top' }),
164
+ h('span', { class: 'free-field-warning-icon-sign-dot' }),
165
+ h('span', { class: 'free-field-warning-text ellipsis' }, localField.value.Warning),
164
166
  ]
165
167
  );
166
168
 
@@ -169,7 +171,7 @@ export default defineComponent({
169
171
  watchEffect(() => {
170
172
  (realComponent?.value?.emits || []).forEach((em) => {
171
173
  if (!em || em === 'input') return;
172
-
174
+
173
175
  const captEm = `${em[0].toUpperCase()}${em.substring(1)}`;
174
176
  compEmits.value[`on${captEm}`] = (...args) => {
175
177
  // should not emit event directly as we were not inlucde these events in the emits list
@@ -184,7 +186,7 @@ export default defineComponent({
184
186
  });
185
187
  })
186
188
 
187
- const readComp = computed(() => realComponent.value && h(
189
+ const realComp = computed(() => realComponent.value && h(
188
190
  realComponent.value,
189
191
  {
190
192
  Field: localField.value,
@@ -204,25 +206,149 @@ export default defineComponent({
204
206
  warning: slots.warning ? slots.warning : () => warningSlot,
205
207
  }
206
208
  ));
207
-
209
+
208
210
  // const emitsRef = computed(() => realComponent?.value?.emits);
209
211
 
210
212
  const {
211
213
  validate,
212
- } = useFormValidator(readComp);
214
+ } = useFormValidator(realComp);
213
215
 
214
216
  expose ({
215
217
  // emits: emitsRef.value,
216
218
  validate: () => validate.value(props.Field.Name),
217
219
  })
218
220
 
221
+ const fieldTip = (tip) => {
222
+ if (!tip || !tip.Text) return '';
223
+ if (!tip.Links || !Array.isArray(tip.Links) || tip.Links.length <= 0) {
224
+ return [{ Text: tip.Text }];
225
+ }
226
+
227
+ // process tip with links
228
+ let linkPos = [];
229
+ tip.Links.forEach((tl) => {
230
+ if (!tl || !tl.Text) return;
231
+
232
+ const start = tip.Text.indexOf(tl.Text);
233
+ if (start >= 0) {
234
+ linkPos.push({
235
+ ...tl,
236
+ start,
237
+ end: start + tl.Text.length,
238
+ });
239
+ }
240
+ });
241
+
242
+ const textSplit = [];
243
+ let start = 0;
244
+ linkPos = linkPos.sort((a, b) => a.start - b.start);
245
+ for (let i = 0; i < linkPos.length; i += 1) {
246
+ const lp = linkPos[i];
247
+
248
+ const beforeText = tip.Text.substr(start, lp.start - start);
249
+ if (beforeText) {
250
+ textSplit.push({ Text: beforeText });
251
+ }
252
+
253
+ textSplit.push({
254
+ ...lp,
255
+ Text: tip.Text.substr(lp.start, lp.end - lp.start),
256
+ Link:
257
+ !!lp.File && lp.isFile
258
+ ? vm.$filter('serverDocument', lp.File)
259
+ : lp.Link,
260
+ });
261
+
262
+ start = lp.end;
263
+ }
264
+
265
+ const afterText = tip.Text.substr(start);
266
+ if (afterText) {
267
+ textSplit.push({
268
+ Text: afterText,
269
+ });
270
+ }
271
+
272
+ if (textSplit.length > 0) return textSplit;
273
+
274
+ return [{ Text: tip.Text }];
275
+ };
276
+
277
+ const tipsElem = !shouldHide.value && !props.noTips && (localField.value.Tips?.length > 0) && h(
278
+ "div",
279
+ {
280
+ class: "free-field-tips",
281
+ },
282
+ [
283
+ h("span", {
284
+ class: "free-field-tips-prefix",
285
+ }),
286
+ h("span", {
287
+ class: "tips-list",
288
+ },
289
+ [
290
+ localField.value.Tips.map((tip) => h("span", {
291
+ class: "free-field-tips-tip",
292
+ },
293
+ [
294
+ h("span", {
295
+ class: "free-field-tips-tip-prefix",
296
+ }),
297
+ fieldTip(tip).map(
298
+ (t) => h("span", null, [
299
+ t.Link ? h("span", {
300
+ class: "tip-link",
301
+ }, [
302
+ h("span", {
303
+ class: "tip-link-prefix",
304
+ }),
305
+ t.File ? h("a", {
306
+ href: t.Link,
307
+ target: t.target || '_blank',
308
+ download: `${t.Text}${t.File && t.File.substr(t.File.lastIndexOf('.'))}`,
309
+ }, t.Text) : h("a", {
310
+ href: t.Link,
311
+ target: t.target || '_blank',
312
+ }, t.Text),
313
+ h("span", {
314
+ class: "tip-link-postfix",
315
+ }),
316
+ ]) : (t.File ? h("span", {
317
+ class: "tip-text",
318
+ }, [
319
+ h("span", {
320
+ class: "tip-link-prefix",
321
+ }),
322
+ t.File,
323
+ h("span", {
324
+ class: "tip-link-postfix",
325
+ }),
326
+ ]) : h("span", {
327
+ class: "tip-text",
328
+ }, t.Text))
329
+ ])
330
+ ),
331
+ h("span", {
332
+ class: "free-field-tips-tip-postfix",
333
+ }),
334
+ ]
335
+ )),
336
+ ]),
337
+ h('span', {
338
+ class: 'free-field-tips-postfix',
339
+ })
340
+ ]
341
+ );
342
+
343
+
219
344
  return realComponent.value ? () => h(
220
345
  "div",
221
346
  {
222
347
  class: wrapperClass,
223
348
  },
224
349
  [
225
- readComp.value,
350
+ realComp.value,
351
+ tipsElem,
226
352
  ]
227
353
  ) : () => null;
228
354
  },
@@ -11,24 +11,28 @@ export function useFreeField(props, ctx) {
11
11
 
12
12
  watchEffect(() => {
13
13
  let realData = void 0;
14
+ let usingDft = false;
14
15
 
15
16
  if (!props.Field) {
16
17
  return;
17
18
  }
18
19
 
19
20
  if (!props.Field.Name) {
20
- realData = props.Field.Value || props.Field.Default || undefined;
21
+ realData = props.Field.Value || props.Field.Default || void 0;
22
+ usingDft = true;
21
23
  } else {
22
- if (props.Field.Info?.Dynamic && props.Field.Value) {
24
+ if (props.Field.Info?.Dynamic && props.Field.Value !== void 0) {
23
25
  realData = props.Field.Value;
26
+ usingDft = true;
24
27
  } else {
25
28
  realData = Object.nestValue(props.values, props.Field?.Name);
26
29
  }
27
30
  }
28
31
 
29
32
  // set to default if still undefined
30
- if ((realData === void 0 || realData === null) && (props.Field.Value || props.Field.Default)) {
33
+ if ((realData === void 0 || realData === null) && ((props.Field.Value !== void 0) || (props.Field.Default !== void 0))) {
31
34
  realData = props.Field.Value || props.Field.Default;
35
+ usingDft = true;
32
36
 
33
37
  // for non-dynamic field, which have refer data, we should save this data into the field
34
38
  if (props.Field.ReferTo && !props.Field.Info?.Dynamic) {
@@ -52,9 +56,16 @@ export function useFreeField(props, ctx) {
52
56
  }
53
57
  }
54
58
 
55
- // show NaN placeholder
56
- if ((realData === void 0 || realData === null || realData === '') && props.Field?.Info?.ShowNaN) {
57
- return vm.ctx.config.nanPlaceholder || '';
59
+ // // show NaN placeholder
60
+ // TODO: return the placeholder here will not work as expected
61
+ // if ((realData === void 0 || realData === null || realData === '') && props.Field?.Info?.ShowNaN) {
62
+ // return vm.ctx.config.nanPlaceholder || '';
63
+ // }
64
+
65
+ // if we are using a default value for this field, we should set the default value to the values object
66
+ // so that we can get such value from anywhere else immediately
67
+ if (usingDft) {
68
+ Object.setValue(props.values, props.Field?.Name, props.Field.Value || props.Field.Default || void 0);
58
69
  }
59
70
 
60
71
  fieldData.value = realData;
@@ -0,0 +1,320 @@
1
+ import { computed, getCurrentInstance, ref } from "vue";
2
+ import { Notify } from 'quasar';
3
+
4
+
5
+ function fileSizeStrToNumber (s) {
6
+ if (!s) return undefined;
7
+
8
+ const sizeMatch = s.match(/^([0-9]*)(k|m|g*)(b*)/);
9
+
10
+ if (sizeMatch) {
11
+ // eslint-disable-next-line no-unused-vars
12
+ // const [tmp, num, unit] = sizeMatch;
13
+ const num = sizeMatch[1];
14
+ const unit = sizeMatch[2];
15
+ if (!num || !Number(num)) return '';
16
+
17
+ let multi = 1;
18
+ switch (unit) {
19
+ case 'k':
20
+ multi = 1024;
21
+ break;
22
+ case 'm':
23
+ multi = 1024 * 1024;
24
+ break;
25
+ case 'g':
26
+ multi = 1024 * 1024 * 1024;
27
+ break;
28
+ default:
29
+ multi = 1024;
30
+ break;
31
+ }
32
+
33
+ return Number(num) * multi;
34
+ }
35
+
36
+ return undefined;
37
+ }
38
+
39
+ function fileSizeNumberToStr (s) {
40
+ if (!s) return '0K';
41
+
42
+ let sizeNum = Number(s) || 0;
43
+
44
+ if (!sizeNum || sizeNum <= 0) return '0K';
45
+
46
+ const unitList = ['B', 'K', 'M', 'G'];
47
+ let unit = 'B';
48
+ let unitIndex = 0;
49
+
50
+ while (sizeNum > 1024) {
51
+ if (unit === 'G') break;
52
+
53
+ unitIndex += 1;
54
+ unit = unitList[unitIndex];
55
+ sizeNum /= 1024;
56
+ }
57
+
58
+ return `${sizeNum.toFixed(2)}${unit}`;
59
+ }
60
+
61
+ // eslint-disable-next-line no-underscore-dangle
62
+ function _getFileType (f) {
63
+ if (!f) return {};
64
+
65
+ if (f.type) {
66
+ const fTypes = f.type.split('/');
67
+ const [fType, fExt] = fTypes;
68
+ return {
69
+ fType, fExt,
70
+ };
71
+ }
72
+
73
+ if (f.id) {
74
+ let extname = f.id.substr(f.id.lastIndexOf('.'));
75
+ if (extname.startsWith('.')) {
76
+ extname = extname.substr(1);
77
+ }
78
+
79
+ extname = extname && extname.toLowerCase();
80
+
81
+ switch (extname) {
82
+ case 'png':
83
+ case 'jpg':
84
+ case 'jpeg':
85
+ case 'bmp':
86
+ case 'gif':
87
+ return { fType: 'image', fExt: extname };
88
+ case 'wav':
89
+ case 'mp3':
90
+ return { fType: 'audio', fExt: extname };
91
+ case 'mp4':
92
+ return { fType: 'video', fExt: extname };
93
+ case 'txt':
94
+ return { fType: 'text', fExt: extname };
95
+ default:
96
+ return { fType: 'application', fExt: extname };
97
+ }
98
+ }
99
+
100
+ return {};
101
+ }
102
+
103
+ export function useUploader(props, ctx) {
104
+ const { proxy:vm } = getCurrentInstance();
105
+
106
+ const showPreview = ref(false);
107
+ const previewFile = ref(undefined);
108
+ const previewType = ref(undefined);
109
+
110
+ const maxFileSize = computed(() => {
111
+ return fileSizeStrToNumber(props.Field?.MaxValue || '10m') * 1.1;
112
+ });
113
+
114
+ const maxTotalSize = computed(() => {
115
+ return fileSizeStrToNumber((props.Field?.Options?.MaxTotal) || '10m') * 1.1;
116
+ });
117
+
118
+ const acceptedFileTypes = computed(() => {
119
+ if (!props.Field?.Options?.Ext) return '';
120
+
121
+ const extList = props.Field.Options.Ext.split(',') || [];
122
+ const typeList = [];
123
+
124
+ const MIME_TYPE_LIST = {
125
+ mp4: 'video/mp4',
126
+ avi: 'video/x-msvideo',
127
+ bmp: 'image/bmp',
128
+ doc: 'application/msword',
129
+ docx:
130
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
131
+ gif: 'image/gif',
132
+ jpe: 'image/jpeg',
133
+ jpeg: 'image/jpeg',
134
+ jpg: 'image/jpeg',
135
+ png: 'image/png',
136
+ mpeg: 'video/mpeg',
137
+ pdf: 'application/pdf',
138
+ ppt: 'application/vnd.ms-powerpoint',
139
+ pptx:
140
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
141
+ svg: 'image/svg+xml',
142
+ txt: 'text/plain',
143
+ wav: 'audio/x-wav',
144
+ xls: 'application/vnd.ms-excel',
145
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
146
+ zip: 'application/zip',
147
+ };
148
+
149
+ extList.forEach((ext) => {
150
+ let type = ext.trim().toLowerCase();
151
+ type = MIME_TYPE_LIST[type] || type;
152
+
153
+ if (type && typeList.indexOf(type) < 0) typeList.push(type);
154
+ if (ext && typeList.indexOf(ext) < 0) typeList.push(ext);
155
+ });
156
+
157
+ return typeList.join(',');
158
+ });
159
+
160
+ const fileThumb = computed(() => (file) => {
161
+ const unknownType = 'insert_drive_file';
162
+ if (!file) return unknownType;
163
+
164
+ let type = '';
165
+ // const fTypes = file.type.split('/');
166
+ // const [fType, fExt] = fTypes;
167
+ const { fType, fExt } = _getFileType(file);
168
+
169
+ switch (fType) {
170
+ case 'image':
171
+ // eslint-disable-next-line no-underscore-dangle
172
+ type = file.id || (file.__img ? file.__img.src : '');
173
+ break;
174
+ case 'audio':
175
+ type = 'far fa-file-audio';
176
+ break;
177
+ case 'video':
178
+ type = 'far fa-file-video';
179
+ break;
180
+ case 'text':
181
+ type = 'far fa-file-text';
182
+ break;
183
+ case 'application':
184
+ switch (fExt) {
185
+ case 'doc':
186
+ case 'docx':
187
+ case 'vnd.openxmlformats-officedocument.wordprocessingml.document':
188
+ type = 'far fa-file-word';
189
+ break;
190
+ case 'xls':
191
+ case 'xlsx':
192
+ case 'vnd.openxmlformats-officedocument.spreadsheetml.sheet':
193
+ type = 'far fa-file-excel';
194
+ break;
195
+ case 'ppt':
196
+ case 'pptx':
197
+ case 'vnd.openxmlformats-officedocument.presentationml.presentation':
198
+ type = 'far fa-file-powerpoint';
199
+ break;
200
+ case 'pdf':
201
+ type = 'far fa-file-pdf';
202
+ // type = 'insert_drive_file';
203
+ break;
204
+ case 'zip':
205
+ case 'rar':
206
+ case '7z':
207
+ case 'x-zip-compressed':
208
+ type = 'far fa-file-archive';
209
+ break;
210
+ default:
211
+ break;
212
+ }
213
+ break;
214
+ default:
215
+ break;
216
+ }
217
+
218
+ return type || unknownType;
219
+ });
220
+
221
+ const filePreviewType = computed(() => (file) => {
222
+ if (!file) return '';
223
+
224
+ // const fTypes = file.type.split('/');
225
+ // const [fType, fExt] = fTypes;
226
+ const { fType, fExt } = _getFileType(file);
227
+
228
+ switch (fType) {
229
+ case 'image':
230
+ return 'image';
231
+ case 'application':
232
+ switch (fExt) {
233
+ case 'doc':
234
+ case 'docx':
235
+ case 'vnd.openxmlformats-officedocument.wordprocessingml.document':
236
+ return 'word';
237
+ case 'xls':
238
+ case 'xlsx':
239
+ case 'vnd.openxmlformats-officedocument.spreadsheetml.sheet':
240
+ return 'excel';
241
+ case 'ppt':
242
+ case 'pptx':
243
+ case 'vnd.openxmlformats-officedocument.presentationml.presentation':
244
+ return 'ppt';
245
+ case 'pdf':
246
+ return 'pdf';
247
+ default:
248
+ break;
249
+ }
250
+ break;
251
+ default:
252
+ break;
253
+ }
254
+
255
+ return '';
256
+ });
257
+
258
+ const filePreview = computed(() => (file) => {
259
+ if (!file) return '';
260
+ let url = '';
261
+
262
+ const type = filePreviewType.value(file);
263
+ switch (type) {
264
+ case 'image':
265
+ if (file.id) {
266
+ url = vm.$filter('serverImage', file.id);
267
+ } else {
268
+ // eslint-disable-next-line no-underscore-dangle
269
+ url = file.__img ? file.__img.src : '';
270
+ }
271
+ break;
272
+ case 'pdf':
273
+ if (file.id) {
274
+ url = vm.$filter('serverDocument', file.id);
275
+ }
276
+ break;
277
+ default:
278
+ break;
279
+ }
280
+
281
+ return url;
282
+ });
283
+
284
+ return {
285
+ showPreview,
286
+ previewType,
287
+ previewFile,
288
+ maxFileSize,
289
+ maxTotalSize,
290
+ acceptedFileTypes,
291
+ fileThumb,
292
+ filePreviewType,
293
+ filePreview,
294
+
295
+ filesRejected (rejectedEntries) {
296
+ if (rejectedEntries && rejectedEntries.length > 0) {
297
+ const fName = rejectedEntries[0] && rejectedEntries[0].file && rejectedEntries[0].file.name;
298
+ const fSize = fileSizeNumberToStr(
299
+ rejectedEntries[0] && rejectedEntries[0].file && rejectedEntries[0].file.size,
300
+ );
301
+ // TODO: i18n
302
+ Notify.create({ message: `文件格式或大小不符合要求:${fName} (${fSize})` });
303
+ }
304
+ },
305
+ preview (file) {
306
+ if (!file) return;
307
+
308
+ previewType.value = filePreviewType.value(file);
309
+
310
+ const url = filePreview.value(file);
311
+ if (!url) {
312
+ return;
313
+ }
314
+
315
+ previewFile.value = url;
316
+
317
+ showPreview.value = true;
318
+ },
319
+ }
320
+ };