@dhccmobile/vue3-lo-form 0.1.0

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 (160) hide show
  1. package/.eslintrc.js +29 -0
  2. package/README.md +62 -0
  3. package/babel.config.js +3 -0
  4. package/dist/demo.html +10 -0
  5. package/dist/vue3-lo-form.common.js +119725 -0
  6. package/dist/vue3-lo-form.common.js.map +1 -0
  7. package/dist/vue3-lo-form.css +1 -0
  8. package/dist/vue3-lo-form.umd.js +119735 -0
  9. package/dist/vue3-lo-form.umd.js.map +1 -0
  10. package/dist/vue3-lo-form.umd.min.js +38 -0
  11. package/dist/vue3-lo-form.umd.min.js.map +1 -0
  12. package/package.json +61 -0
  13. package/public/favicon.ico +0 -0
  14. package/public/index.html +17 -0
  15. package/src/App.vue +715 -0
  16. package/src/components/form/DvForm.vue +586 -0
  17. package/src/components/form/DvFormLayout.vue +1568 -0
  18. package/src/components/form/StretchText.vue +77 -0
  19. package/src/components/index.ts +3 -0
  20. package/src/constants/config/form-template.config.ts +32 -0
  21. package/src/constants/config/form.config.ts +4 -0
  22. package/src/constants/config/storage.config.ts +4 -0
  23. package/src/constants/encode-assets/icons.ts +0 -0
  24. package/src/constants/encode-assets/svg.ts +9 -0
  25. package/src/constants/enum/builtIn-label.enum.ts +5 -0
  26. package/src/constants/enum/cache-type.enum.ts +7 -0
  27. package/src/constants/enum/control-format-type.enum.ts +9 -0
  28. package/src/constants/enum/dynamic-option-type.enum.ts +6 -0
  29. package/src/constants/enum/form-bus-attr.enum.ts +8 -0
  30. package/src/constants/enum/form-field-class.enum.ts +7 -0
  31. package/src/constants/enum/form-field-type.enum.ts +25 -0
  32. package/src/constants/enum/form-type.enum.ts +5 -0
  33. package/src/constants/enum/index.ts +19 -0
  34. package/src/constants/enum/lateral-arrangement.enum.ts +9 -0
  35. package/src/constants/enum/money-unit.enum.ts +6 -0
  36. package/src/constants/enum/option-type.enum.ts +5 -0
  37. package/src/constants/enum/submitted-type.enum.ts +12 -0
  38. package/src/constants/enum/support-upload-type.enum.ts +5 -0
  39. package/src/constants/enum/switch.enum.ts +5 -0
  40. package/src/constants/enum/upload-type.enum.ts +17 -0
  41. package/src/constants/enum/validate-rules.enum.ts +25 -0
  42. package/src/constants/enum/validate-status.enum.ts +8 -0
  43. package/src/constants/enum/vertical-arrangement.enum.ts +7 -0
  44. package/src/constants/enum/zoom-type.ts +6 -0
  45. package/src/constants/index.ts +3 -0
  46. package/src/core/FormApi.ts +865 -0
  47. package/src/core/index.ts +1 -0
  48. package/src/domain/AbstractControl.ts +6 -0
  49. package/src/domain/Control.ts +14 -0
  50. package/src/domain/CustomFormat.ts +6 -0
  51. package/src/domain/DesForm.ts +48 -0
  52. package/src/domain/DesFormControl.ts +223 -0
  53. package/src/domain/DesFormLayout.ts +51 -0
  54. package/src/domain/FieldChangeHistory.ts +9 -0
  55. package/src/domain/FormConfig.ts +12 -0
  56. package/src/domain/FormControl.ts +125 -0
  57. package/src/domain/FormEnum.ts +9 -0
  58. package/src/domain/FormGroup.ts +42 -0
  59. package/src/domain/FormRestfulResponse.ts +6 -0
  60. package/src/domain/ProvideInjectData.ts +9 -0
  61. package/src/domain/SysDictDetail.ts +25 -0
  62. package/src/domain/SysDictInfo.ts +31 -0
  63. package/src/domain/SysDictTreeDetail.ts +43 -0
  64. package/src/domain/index.ts +12 -0
  65. package/src/filtres/amount-capitalization.filter.ts +136 -0
  66. package/src/filtres/extract-options.filter.ts +53 -0
  67. package/src/filtres/generate-grid-column-end.filter.ts +22 -0
  68. package/src/filtres/generate-grid-template-columns.filter.ts +24 -0
  69. package/src/filtres/switch-enum-convert.filter.ts +18 -0
  70. package/src/filtres/zoom-multiple.filter.ts +32 -0
  71. package/src/index.ts +67 -0
  72. package/src/main.ts +17 -0
  73. package/src/services/api.service.ts +73 -0
  74. package/src/services/clean-local-forage.service.ts +58 -0
  75. package/src/services/dict-local-forage.service.ts +58 -0
  76. package/src/services/form-bean-utils.service.ts +41 -0
  77. package/src/services/form-local-forage.service.ts +59 -0
  78. package/src/services/form-tools.service.ts +497 -0
  79. package/src/services/form-tree-node-convert.service.ts +216 -0
  80. package/src/services/form-validate.service.ts +103 -0
  81. package/src/services/index.ts +9 -0
  82. package/src/services/router.service.ts +96 -0
  83. package/src/services/validate-generator.service.ts +710 -0
  84. package/src/shims-vue.d.ts +6 -0
  85. package/src/store/dict.store.ts +63 -0
  86. package/src/store/form.store.ts +32 -0
  87. package/src/store/index.ts +2 -0
  88. package/src/styles/index.scss +167 -0
  89. package/src/types/vfForm.ts +11 -0
  90. package/tsconfig.json +40 -0
  91. package/types/components/index.d.ts +3 -0
  92. package/types/constants/config/form-template.config.d.ts +30 -0
  93. package/types/constants/config/form.config.d.ts +4 -0
  94. package/types/constants/config/storage.config.d.ts +4 -0
  95. package/types/constants/encode-assets/icons.d.ts +0 -0
  96. package/types/constants/encode-assets/svg.d.ts +5 -0
  97. package/types/constants/enum/builtIn-label.enum.d.ts +7 -0
  98. package/types/constants/enum/cache-type.enum.d.ts +15 -0
  99. package/types/constants/enum/control-format-type.enum.d.ts +23 -0
  100. package/types/constants/enum/dynamic-option-type.enum.d.ts +11 -0
  101. package/types/constants/enum/form-bus-attr.enum.d.ts +19 -0
  102. package/types/constants/enum/form-field-class.enum.d.ts +18 -0
  103. package/types/constants/enum/form-field-type.enum.d.ts +111 -0
  104. package/types/constants/enum/form-type.enum.d.ts +11 -0
  105. package/types/constants/enum/index.d.ts +19 -0
  106. package/types/constants/enum/lateral-arrangement.enum.d.ts +23 -0
  107. package/types/constants/enum/money-unit.enum.d.ts +15 -0
  108. package/types/constants/enum/option-type.enum.d.ts +11 -0
  109. package/types/constants/enum/submitted-type.enum.d.ts +35 -0
  110. package/types/constants/enum/support-upload-type.enum.d.ts +11 -0
  111. package/types/constants/enum/switch.enum.d.ts +11 -0
  112. package/types/constants/enum/upload-type.enum.d.ts +59 -0
  113. package/types/constants/enum/validate-rules.enum.d.ts +2 -0
  114. package/types/constants/enum/validate-status.enum.d.ts +2 -0
  115. package/types/constants/enum/vertical-arrangement.enum.d.ts +21 -0
  116. package/types/constants/enum/zoom-type.d.ts +15 -0
  117. package/types/constants/index.d.ts +3 -0
  118. package/types/core/FormApi.d.ts +326 -0
  119. package/types/core/index.d.ts +1 -0
  120. package/types/domain/AbstractControl.d.ts +5 -0
  121. package/types/domain/Control.d.ts +13 -0
  122. package/types/domain/CustomFormat.d.ts +5 -0
  123. package/types/domain/DesForm.d.ts +32 -0
  124. package/types/domain/DesFormControl.d.ts +148 -0
  125. package/types/domain/DesFormLayout.d.ts +33 -0
  126. package/types/domain/FieldChangeHistory.d.ts +9 -0
  127. package/types/domain/FormConfig.d.ts +12 -0
  128. package/types/domain/FormControl.d.ts +60 -0
  129. package/types/domain/FormEnum.d.ts +10 -0
  130. package/types/domain/FormGroup.d.ts +27 -0
  131. package/types/domain/FormRestfulResponse.d.ts +6 -0
  132. package/types/domain/ProvideInjectData.d.ts +9 -0
  133. package/types/domain/SysDictDetail.d.ts +16 -0
  134. package/types/domain/SysDictInfo.d.ts +20 -0
  135. package/types/domain/SysDictTreeDetail.d.ts +28 -0
  136. package/types/domain/index.d.ts +12 -0
  137. package/types/filtres/amount-capitalization.filter.d.ts +7 -0
  138. package/types/filtres/extract-options.filter.d.ts +13 -0
  139. package/types/filtres/generate-grid-column-end.filter.d.ts +11 -0
  140. package/types/filtres/generate-grid-template-columns.filter.d.ts +11 -0
  141. package/types/filtres/switch-enum-convert.filter.d.ts +2 -0
  142. package/types/filtres/zoom-multiple.filter.d.ts +3 -0
  143. package/types/index.d.ts +12 -0
  144. package/types/main.d.ts +2 -0
  145. package/types/services/api.service.d.ts +25 -0
  146. package/types/services/clean-local-forage.service.d.ts +28 -0
  147. package/types/services/dict-local-forage.service.d.ts +28 -0
  148. package/types/services/form-bean-utils.service.d.ts +23 -0
  149. package/types/services/form-local-forage.service.d.ts +28 -0
  150. package/types/services/form-tools.service.d.ts +109 -0
  151. package/types/services/form-tree-node-convert.service.d.ts +94 -0
  152. package/types/services/form-validate.service.d.ts +32 -0
  153. package/types/services/index.d.ts +9 -0
  154. package/types/services/router.service.d.ts +40 -0
  155. package/types/services/validate-generator.service.d.ts +154 -0
  156. package/types/store/dict.store.d.ts +29 -0
  157. package/types/store/form.store.d.ts +17 -0
  158. package/types/store/index.d.ts +2 -0
  159. package/types/types/vfForm.d.ts +10 -0
  160. package/vue.config.js +29 -0
@@ -0,0 +1,710 @@
1
+ import { DesFormControl, FormControl, Validate } from "../domain";
2
+ import { FormFieldType, ValidateRules, ValidateStatus } from "../constants/enum";
3
+ import moment from "moment";
4
+
5
+ interface Rule {
6
+ ruleType?: any;
7
+ ruleContent?: any;
8
+ describe?: any;
9
+ }
10
+
11
+ class ValidateGeneratorService {
12
+ /**
13
+ * @description: 填充校验规则
14
+ * @author ChenRui
15
+ * @date 2021/1/27 15:07
16
+ */
17
+ fillCheckRule(formControl: FormControl, controlAttr: DesFormControl): void {
18
+ if (controlAttr.verificationRules && controlAttr.verificationRules.length > 0) {
19
+ const validates: Validate[] = [];
20
+ controlAttr.verificationRules.forEach((item: Rule) => {
21
+ const validate: Validate | undefined = this.getBuiltInValidationRules(item, controlAttr);
22
+ if (validate) {
23
+ validates.push(validate);
24
+ }
25
+ });
26
+ formControl.addValidate(validates);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * @description: 获取校验规则
32
+ * @author ChenRui
33
+ * @date 2021/7/19 17:55
34
+ */
35
+ getBuiltInValidationRules(item: Rule, controlAttr: DesFormControl): Validate | undefined {
36
+ let validate: Validate | undefined;
37
+ switch (item.ruleType) {
38
+ case ValidateRules.SameValue.code:
39
+ validate = this.genSameValue(item);
40
+ break;
41
+ case ValidateRules.MailBox.code:
42
+ validate = this.genMailBox(item);
43
+ break;
44
+ case ValidateRules.RegEx.code:
45
+ validate = this.genRegEx(item);
46
+ break;
47
+ case ValidateRules.MinTextLength.code:
48
+ validate = this.genMinTextLength(item);
49
+ break;
50
+ case ValidateRules.MaxTextLength.code:
51
+ validate = this.genMaxTextLength(item);
52
+ break;
53
+ case ValidateRules.MinValue.code:
54
+ validate = this.genMinValue(item);
55
+ break;
56
+ case ValidateRules.MaxValue.code:
57
+ validate = this.genMaxValue(item);
58
+ break;
59
+ case ValidateRules.SpecifiedValue.code:
60
+ validate = this.genSpecifiedValue(item);
61
+ break;
62
+ case ValidateRules.SpecifiedDigitsNumber.code:
63
+ validate = this.genSpecifiedDigitsNumber(item);
64
+ break;
65
+ case ValidateRules.DateNotEarlierThan.code:
66
+ validate = this.genDateNotEarlierThan(item);
67
+ break;
68
+ case ValidateRules.DateNoLaterThan.code:
69
+ validate = this.genDateNoLaterThan(item);
70
+ break;
71
+ case ValidateRules.SpecifiedRangeNumber.code:
72
+ validate = this.genSpecifiedRangeNumber(item);
73
+ break;
74
+ case ValidateRules.PhoneNumber.code:
75
+ validate = this.genPhoneNumber(item);
76
+ break;
77
+ case ValidateRules.Required.code:
78
+ validate = this.genRequired(item, controlAttr.controlType);
79
+ break;
80
+ case ValidateRules.LineUnique.code:
81
+ validate = this.genLineUnique(item);
82
+ break;
83
+ case ValidateRules.LetterSpace.code:
84
+ validate = this.genLetterSpace(item);
85
+ break;
86
+ case ValidateRules.AlphanumericUnderline.code:
87
+ validate = this.genAlphanumericUnderline(item);
88
+ break;
89
+ case ValidateRules.Alphanumeric.code:
90
+ validate = this.genAlphanumeric(item);
91
+ break;
92
+ case ValidateRules.JsMethodVerification.code:
93
+ validate = this.genJsMethodVerification(item);
94
+ break;
95
+ case ValidateRules.BackEndVerification.code:
96
+ validate = this.genBackEndVerification(item);
97
+ break;
98
+ case ValidateRules.LandlineNumber.code:
99
+ validate = this.genLandlineNumber(item);
100
+ break;
101
+ }
102
+ return validate;
103
+ }
104
+
105
+ /**
106
+ * @description: 相同的值
107
+ * @author ChenRui
108
+ * @date 2021/1/27 15:12
109
+ */
110
+ genSameValue(item: Rule): Validate {
111
+ const validate: Validate = {
112
+ name: item.ruleType,
113
+ validateFunc: (val: any) => {
114
+ if (val != null && val !== "") {
115
+ if (item.ruleContent && val != item.ruleContent) {
116
+ return {
117
+ validateStatus: ValidateStatus.Error.code,
118
+ errorMsg: `与预期值(${item.ruleContent})不符`,
119
+ };
120
+ }
121
+ }
122
+ return {
123
+ validateStatus: ValidateStatus.Success.code,
124
+ };
125
+ },
126
+ };
127
+ return validate;
128
+ }
129
+
130
+ /**
131
+ * @description: 电子邮箱
132
+ * @author ChenRui
133
+ * @date 2021/1/27 15:15
134
+ */
135
+ genMailBox(item: Rule): Validate {
136
+ const validate: Validate = {
137
+ name: item.ruleType,
138
+ validateFunc: (val: any) => {
139
+ if (val != null && val !== "") {
140
+ const emreg = /^\w{3,}(\.\w+)*@[A-z0-9]+(\.[A-z]{2,5}){1,2}$/;
141
+ if (!emreg.test(val)) {
142
+ return {
143
+ validateStatus: ValidateStatus.Error.code,
144
+ errorMsg: "电子邮件格式不正确",
145
+ };
146
+ }
147
+ }
148
+ return {
149
+ validateStatus: ValidateStatus.Success.code,
150
+ };
151
+ },
152
+ };
153
+ return validate;
154
+ }
155
+
156
+ /**
157
+ * @description: 正则匹配
158
+ * @author ChenRui
159
+ * @date 2021/1/27 15:17
160
+ */
161
+ genRegEx(item: Rule): Validate {
162
+ const validate: Validate = {
163
+ name: item.ruleType,
164
+ validateFunc: (val: any) => {
165
+ if (val != null && val !== "") {
166
+ if (item.ruleContent && !eval(item.ruleContent).test(val)) {
167
+ return {
168
+ validateStatus: ValidateStatus.Error.code,
169
+ errorMsg: item.describe ? item.describe : `'不满足正则校验'${item.ruleContent}`,
170
+ };
171
+ }
172
+ }
173
+ return {
174
+ validateStatus: ValidateStatus.Success.code,
175
+ };
176
+ },
177
+ };
178
+ return validate;
179
+ }
180
+
181
+ /**
182
+ * @description: 最小文本长度
183
+ * @author ChenRui
184
+ * @date 2021/1/27 15:18
185
+ */
186
+ genMinTextLength(item: Rule): Validate {
187
+ const validate: Validate = {
188
+ name: item.ruleType,
189
+ validateFunc: (val: any) => {
190
+ if (val != null && val !== "") {
191
+ if (item.ruleContent && val && String(val).length < Number(item.ruleContent)) {
192
+ return {
193
+ validateStatus: ValidateStatus.Error.code,
194
+ errorMsg: `内容不少于${item.ruleContent}个字`,
195
+ };
196
+ }
197
+ }
198
+ return {
199
+ validateStatus: ValidateStatus.Success.code,
200
+ };
201
+ },
202
+ };
203
+ return validate;
204
+ }
205
+
206
+ /**
207
+ * @description: 最大文本长度
208
+ * @author ChenRui
209
+ * @date 2021/1/27 15:21
210
+ */
211
+ genMaxTextLength(item: Rule): Validate {
212
+ const validate: Validate = {
213
+ name: item.ruleType,
214
+ validateFunc: (val: any) => {
215
+ if (val != null && val !== "") {
216
+ if (item.ruleContent && val && String(val).length > Number(item.ruleContent)) {
217
+ return {
218
+ validateStatus: ValidateStatus.Error.code,
219
+ errorMsg: `内容不超过${item.ruleContent}个字`,
220
+ };
221
+ }
222
+ }
223
+ return {
224
+ validateStatus: ValidateStatus.Success.code,
225
+ };
226
+ },
227
+ };
228
+ return validate;
229
+ }
230
+
231
+ /**
232
+ * @description: 最小值
233
+ * @author ChenRui
234
+ * @date 2021/1/27 15:24
235
+ */
236
+ genMinValue(item: Rule): Validate {
237
+ const validate: Validate = {
238
+ name: item.ruleType,
239
+ validateFunc: (val: any) => {
240
+ if (val != undefined && val !== "") {
241
+ if (item.ruleContent != null && val != null && val !== "" && Number(val) < Number(item.ruleContent)) {
242
+ return {
243
+ validateStatus: ValidateStatus.Error.code,
244
+ errorMsg: `数值不能小于${item.ruleContent}`,
245
+ };
246
+ }
247
+ }
248
+ return {
249
+ validateStatus: ValidateStatus.Success.code,
250
+ };
251
+ },
252
+ };
253
+ return validate;
254
+ }
255
+
256
+ /**
257
+ * @description: 最大值
258
+ * @author ChenRui
259
+ * @date 2021/1/27 15:25
260
+ */
261
+ genMaxValue(item: Rule): Validate {
262
+ const validate: Validate = {
263
+ name: item.ruleType,
264
+ validateFunc: (val: any) => {
265
+ if (val != undefined && val !== "") {
266
+ if (item.ruleContent != null && val != null && val !== "" && Number(val) > Number(item.ruleContent)) {
267
+ return {
268
+ validateStatus: ValidateStatus.Error.code,
269
+ errorMsg: `数值不能大于${item.ruleContent}`,
270
+ };
271
+ }
272
+ }
273
+ return {
274
+ validateStatus: ValidateStatus.Success.code,
275
+ };
276
+ },
277
+ };
278
+ return validate;
279
+ }
280
+
281
+ /**
282
+ * @description: 指定的值
283
+ * @author ChenRui
284
+ * @date 2021/1/27 15:27
285
+ */
286
+ genSpecifiedValue(item: Rule): Validate {
287
+ const validate: Validate = {
288
+ name: item.ruleType,
289
+ validateFunc: (val: any) => {
290
+ if (val != null && val !== "") {
291
+ if (item.ruleContent && val != item.ruleContent) {
292
+ return {
293
+ validateStatus: ValidateStatus.Error.code,
294
+ errorMsg: `与预期值(${item.ruleContent})不符`,
295
+ };
296
+ }
297
+ }
298
+ return {
299
+ validateStatus: ValidateStatus.Success.code,
300
+ };
301
+ },
302
+ };
303
+ return validate;
304
+ }
305
+
306
+ /**
307
+ * @description: 指定位数数字
308
+ * @author ChenRui
309
+ * @date 2021/1/27 15:31
310
+ */
311
+ genSpecifiedDigitsNumber(item: Rule): Validate {
312
+ const validate: Validate = {
313
+ name: item.ruleType,
314
+ validateFunc: (val: any) => {
315
+ if (val != undefined && val !== "") {
316
+ if (item.ruleContent && val) {
317
+ let countDecimals = 0;
318
+ if (Math.floor(val).toString() !== val.toString()) {
319
+ countDecimals = val.toString().split(".")[1].length || 0;
320
+ }
321
+ if (countDecimals != Number(item.ruleContent)) {
322
+ return {
323
+ validateStatus: ValidateStatus.Error.code,
324
+ errorMsg: item.ruleContent === "0" || item.ruleContent === 0 ? `请输入整数` : `请保留${item.ruleContent}位小数`,
325
+ };
326
+ }
327
+ }
328
+ }
329
+ return {
330
+ validateStatus: ValidateStatus.Success.code,
331
+ };
332
+ },
333
+ };
334
+ return validate;
335
+ }
336
+
337
+ /**
338
+ * @description: 自动补位
339
+ * @author ChenRui
340
+ * @date 2021/1/27 15:59
341
+ */
342
+ roundNumber(number: any, decimals: any): any {
343
+ let newString; // The new rounded number
344
+ decimals = Number(decimals);
345
+ if (decimals < 1) {
346
+ newString = Math.round(number).toString();
347
+ } else {
348
+ let numString = number.toString();
349
+ if (numString.lastIndexOf(".") == -1) {
350
+ // If there is no decimal point
351
+ numString += "."; // give it one at the end
352
+ }
353
+ let cutoff = numString.lastIndexOf(".") + decimals; // The point at which to truncate the number
354
+ let d1: any = Number(numString.substring(cutoff, cutoff + 1)); // The value of the last decimal place that we'll end up with
355
+ const d2 = Number(numString.substring(cutoff + 1, cutoff + 2)); // The next decimal, after the last one we want
356
+ if (d2 >= 5) {
357
+ // Do we need to round up at all? If not, the string will just be truncated
358
+ if (d1 == 9 && cutoff > 0) {
359
+ // If the last digit is 9, find a new cutoff point
360
+ while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
361
+ if (d1 != ".") {
362
+ cutoff -= 1;
363
+ d1 = Number(numString.substring(cutoff, cutoff + 1));
364
+ } else {
365
+ cutoff -= 1;
366
+ }
367
+ }
368
+ }
369
+ d1 += 1;
370
+ }
371
+ if (d1 == 10) {
372
+ numString = numString.substring(0, numString.lastIndexOf("."));
373
+ const roundedNum = Number(numString) + 1;
374
+ newString = roundedNum.toString() + ".";
375
+ } else {
376
+ newString = numString.substring(0, cutoff) + d1.toString();
377
+ }
378
+ }
379
+ if (newString.lastIndexOf(".") == -1) {
380
+ // Do this again, to the new string
381
+ newString += ".";
382
+ }
383
+ const decs = newString.substring(newString.lastIndexOf(".") + 1).length;
384
+ for (let i = 0; i < decimals - decs; i++) newString += "0";
385
+ return newString;
386
+ }
387
+
388
+ /**
389
+ * @description: 日期不早于
390
+ * @author ChenRui
391
+ * @date 2021/1/27 16:06
392
+ */
393
+ genDateNotEarlierThan(item: Rule): Validate {
394
+ const validate: Validate = {
395
+ name: item.ruleType,
396
+ validateFunc: (val: any) => {
397
+ if (val != null && val !== "") {
398
+ if (item.ruleContent && val) {
399
+ try {
400
+ if (val.toDate() > moment(item.ruleContent).toDate()) {
401
+ return {
402
+ validateStatus: ValidateStatus.Error.code,
403
+ errorMsg: `日期不早于${item.ruleContent}`,
404
+ };
405
+ }
406
+ } catch (e) {
407
+ return {
408
+ validateStatus: ValidateStatus.Error.code,
409
+ errorMsg: `最大值日期(${item.ruleContent})格式有误!`,
410
+ };
411
+ }
412
+ }
413
+ }
414
+ return {
415
+ validateStatus: ValidateStatus.Success.code,
416
+ };
417
+ },
418
+ };
419
+ return validate;
420
+ }
421
+
422
+ /**
423
+ * @description: 日期不晚于
424
+ * @author ChenRui
425
+ * @date 2021/1/27 16:08
426
+ */
427
+ genDateNoLaterThan(item: Rule): Validate {
428
+ const validate: Validate = {
429
+ name: item.ruleType,
430
+ validateFunc: (val: any) => {
431
+ if (val != null && val !== "") {
432
+ if (item.ruleContent && val) {
433
+ try {
434
+ if (val.toDate() < moment(item.ruleContent).toDate()) {
435
+ return {
436
+ validateStatus: ValidateStatus.Error.code,
437
+ errorMsg: `日期不晚于${item.ruleContent}`,
438
+ };
439
+ }
440
+ } catch (e) {
441
+ return {
442
+ validateStatus: ValidateStatus.Error.code,
443
+ errorMsg: `最小值日期(${item.ruleContent})格式有误!`,
444
+ };
445
+ }
446
+ }
447
+ }
448
+ return {
449
+ validateStatus: ValidateStatus.Success.code,
450
+ };
451
+ },
452
+ };
453
+ return validate;
454
+ }
455
+
456
+ /**
457
+ * @description: 指定范围的数字
458
+ * @author ChenRui
459
+ * @date 2021/1/27 16:35
460
+ */
461
+ genSpecifiedRangeNumber(item: Rule): Validate {
462
+ const validate: Validate = {
463
+ name: item.ruleType,
464
+ validateFunc: (val: any) => {
465
+ if (val != null && val !== "") {
466
+ if (item.ruleContent != null && val && item.ruleContent.indexOf("/") > -1) {
467
+ const arr: any[] = item.ruleContent.split("/");
468
+ if (arr && arr.length > 1) {
469
+ if (val < Number(arr[0]) || val > Number(arr[1])) {
470
+ return {
471
+ validateStatus: ValidateStatus.Error.code,
472
+ errorMsg: `数值大小应在${arr[0]}~${arr[1]}之间`,
473
+ };
474
+ }
475
+ }
476
+ }
477
+ }
478
+ return {
479
+ validateStatus: ValidateStatus.Success.code,
480
+ };
481
+ },
482
+ };
483
+ return validate;
484
+ }
485
+
486
+ /**
487
+ * @description: 手机号
488
+ * @author ChenRui
489
+ * @date 2021/1/27 16:55
490
+ */
491
+ genPhoneNumber(item: Rule): Validate {
492
+ const reg = /^0?1[3|4|5|6|7|8][0-9]\d{8}$/;
493
+ const validate: Validate = {
494
+ name: item.ruleType,
495
+ validateFunc: (val: any) => {
496
+ if (val != null && val !== "") {
497
+ if (val && !reg.test(val)) {
498
+ return {
499
+ validateStatus: ValidateStatus.Error.code,
500
+ errorMsg: "手机号不合法",
501
+ };
502
+ }
503
+ }
504
+ return {
505
+ validateStatus: ValidateStatus.Success.code,
506
+ };
507
+ },
508
+ };
509
+ return validate;
510
+ }
511
+
512
+ /**
513
+ * @description: 必填
514
+ * @author ChenRui
515
+ * @date 2021/1/27 15:28
516
+ */
517
+ genRequired(item: Rule, controlType: string): Validate {
518
+ const validate: Validate = {
519
+ name: item.ruleType,
520
+ validateFunc: (val: any) => {
521
+ if (val == null || (typeof val == "string" && val.trim() === "") || (Array.isArray(val) && val.length === 0)) {
522
+ let msg = "为必输项";
523
+ if (controlType === FormFieldType.Select.code || controlType === FormFieldType.Radio.code || controlType === FormFieldType.Checkbox.code) {
524
+ msg += ",请选择";
525
+ } else {
526
+ msg += ",请输入";
527
+ }
528
+ return {
529
+ validateStatus: ValidateStatus.Error.code,
530
+ errorMsg: msg,
531
+ };
532
+ }
533
+ return {
534
+ validateStatus: ValidateStatus.Success.code,
535
+ };
536
+ },
537
+ };
538
+ return validate;
539
+ }
540
+
541
+ /**
542
+ * @description: 唯一行
543
+ * @author ChenRui
544
+ * @date 2021/1/27 17:16
545
+ */
546
+ genLineUnique(item: Rule): Validate {
547
+ const validate: Validate = {
548
+ name: item.ruleType,
549
+ validateFunc: () => {
550
+ return {
551
+ validateStatus: ValidateStatus.Success.code,
552
+ };
553
+ },
554
+ };
555
+ return validate;
556
+ }
557
+
558
+ /**
559
+ * @description: 仅包含字母空格
560
+ * @author ChenRui
561
+ * @date 2021/1/27 17:21
562
+ */
563
+ genLetterSpace(item: Rule): Validate {
564
+ const validate: Validate = {
565
+ name: item.ruleType,
566
+ validateFunc: (val: any) => {
567
+ if (val != null && val !== "") {
568
+ const reg = /^(?!_)([A-Za-z ]+)$/;
569
+ if (val && !reg.test(val)) {
570
+ return {
571
+ validateStatus: ValidateStatus.Error.code,
572
+ errorMsg: "仅包含字母空格",
573
+ };
574
+ }
575
+ }
576
+ return {
577
+ validateStatus: ValidateStatus.Success.code,
578
+ };
579
+ },
580
+ };
581
+ return validate;
582
+ }
583
+
584
+ /**
585
+ * @description: 数字字母下划线
586
+ * @author ChenRui
587
+ * @date 2021/1/27 17:28
588
+ */
589
+ genAlphanumericUnderline(item: Rule): Validate {
590
+ const validate: Validate = {
591
+ name: item.ruleType,
592
+ validateFunc: (val: any) => {
593
+ if (val != null && val !== "") {
594
+ const reg = /^[a-zA-Z0-9_]{1,}$/;
595
+ if (val && !reg.test(val)) {
596
+ return {
597
+ validateStatus: ValidateStatus.Error.code,
598
+ errorMsg: "仅包含数字字母下划线",
599
+ };
600
+ }
601
+ }
602
+ return {
603
+ validateStatus: ValidateStatus.Success.code,
604
+ };
605
+ },
606
+ };
607
+ return validate;
608
+ }
609
+
610
+ /**
611
+ * @description: 字母数字
612
+ * @author ChenRui
613
+ * @date 2021/1/27 17:32
614
+ */
615
+ genAlphanumeric(item: Rule): Validate {
616
+ const validate: Validate = {
617
+ name: item.ruleType,
618
+ validateFunc: (val: any) => {
619
+ if (val != null && val !== "") {
620
+ const reg = /^[0-9a-zA-Z]*$/g;
621
+ if (val && !reg.test(val)) {
622
+ return {
623
+ validateStatus: ValidateStatus.Error.code,
624
+ errorMsg: "仅包含数字字母",
625
+ };
626
+ }
627
+ }
628
+ return {
629
+ validateStatus: ValidateStatus.Success.code,
630
+ };
631
+ },
632
+ };
633
+ return validate;
634
+ }
635
+
636
+ /**
637
+ * @description: JS方法校验
638
+ * @author ChenRui
639
+ * @date 2021/1/27 17:42
640
+ */
641
+ genJsMethodVerification(item: Rule): Validate {
642
+ const validate: Validate = {
643
+ name: item.ruleType,
644
+ validateFunc: (val: any) => {
645
+ if (val != null && val !== "") {
646
+ if (val && item.ruleContent) {
647
+ try {
648
+ const func = new Function(item.ruleContent);
649
+ return func(val);
650
+ } catch (e) {
651
+ return {
652
+ validateStatus: ValidateStatus.Error.code,
653
+ errorMsg: item.describe ? item.describe : `'JS校验函数不合法`,
654
+ };
655
+ }
656
+ }
657
+ }
658
+ return {
659
+ validateStatus: ValidateStatus.Success.code,
660
+ };
661
+ },
662
+ };
663
+ return validate;
664
+ }
665
+
666
+ /**
667
+ * @description: 后端校验
668
+ * @author ChenRui
669
+ * @date 2021/1/27 17:43
670
+ */
671
+ genBackEndVerification(item: Rule): Validate {
672
+ const validate: Validate = {
673
+ name: item.ruleType,
674
+ validateFunc: () => {
675
+ return {
676
+ validateStatus: ValidateStatus.Success.code,
677
+ };
678
+ },
679
+ };
680
+ return validate;
681
+ }
682
+
683
+ /**
684
+ * @description: 座机号校验
685
+ * @author ChenRui
686
+ * @date 2021/4/14 11:40
687
+ */
688
+ genLandlineNumber(item: Rule): Validate {
689
+ const reg = /^0\d{2,3}-?\d{7,8}$/;
690
+ const validate: Validate = {
691
+ name: item.ruleType,
692
+ validateFunc: (val: any) => {
693
+ if (val != null && val !== "") {
694
+ if (val && !reg.test(val)) {
695
+ return {
696
+ validateStatus: ValidateStatus.Error.code,
697
+ errorMsg: "座机号不合法",
698
+ };
699
+ }
700
+ }
701
+ return {
702
+ validateStatus: ValidateStatus.Success.code,
703
+ };
704
+ },
705
+ };
706
+ return validate;
707
+ }
708
+ }
709
+ const validateGeneratorService = new ValidateGeneratorService();
710
+ export { Rule, validateGeneratorService };
@@ -0,0 +1,6 @@
1
+ /* eslint-disable */
2
+ declare module '*.vue' {
3
+ import type { DefineComponent } from 'vue'
4
+ const component: DefineComponent<{}, {}, any>
5
+ export default component
6
+ }