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