bri-components 1.2.34 → 1.2.36

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.
@@ -5,6 +5,7 @@
5
5
  :model="formData"
6
6
  :rules="showRules ? rules : {}"
7
7
  @submit.native.prevent
8
+ @on-validate="validateCb"
8
9
  >
9
10
  <Row>
10
11
  <template v-if="displayFormList.length">
@@ -21,7 +22,7 @@
21
22
  @click.native="clickControl(formItem)"
22
23
  >
23
24
  <dsh-form-unit
24
- ref="dshFormItem"
25
+ ref="dshFormUnit"
25
26
  :canEdit="canEdit"
26
27
  :formData="formData"
27
28
  :formItem="formItem"
@@ -99,11 +100,11 @@
99
100
  DshFormUnit
100
101
  },
101
102
  props: {
102
- // 启用该参数后,查看状态时,空值字段不显示
103
- notShowEmpty: {
104
- type: Boolean,
105
- default: false
106
- },
103
+ // // 启用该参数后,查看状态时,空值字段不显示
104
+ // notShowEmpty: {
105
+ // type: Boolean,
106
+ // default: false
107
+ // },
107
108
  canEdit: {
108
109
  type: Boolean,
109
110
  default: true
@@ -158,6 +159,10 @@
158
159
  data () {
159
160
  return {
160
161
  rules: {},
162
+ errorObj: {
163
+ errors: []
164
+ },
165
+
161
166
  forceValidateTypes: [
162
167
  "select", "cascader", "regions", "cascaders", "file", "coordinates", "editor",
163
168
  "users", "departments", "labels", "flatTable", "reference", "referenceBy"
@@ -204,13 +209,57 @@
204
209
  getFormVDom () {
205
210
  return this.$refs.form;
206
211
  },
207
- // 控件校验
208
- validate (callback) {
212
+ submit () {
213
+ this.errorObj = {
214
+ errors: []
215
+ };
216
+
217
+ this.$refs.form.validate(valid => {
218
+ // 此函数有时早于某些字段的validateCb,不稳定,所以加setTimeout目的确保最后执行
219
+ setTimeout(() => {
220
+ // if (!valid) {
221
+ // this.displayFormList.forEach(formItem => {
222
+ // const resultObj = this.$getFieldRuleResult(formItem, this.formData);
223
+ // if (resultObj.bool === false) {
224
+ // this.errorObj.errors.push(resultObj);
225
+ // }
226
+ // });
227
+ // }
228
+ const selfValid = this.selfValidate((valid, errorFormList) => {
229
+ if (valid === false) {
230
+ errorFormList.forEach(formItem => {
231
+ this.errorObj.errors.push({
232
+ bool: false,
233
+ message: `${formItem._name} 内部校验不正确!`
234
+ });
235
+ });
236
+ }
237
+ });
238
+
239
+ if (valid && selfValid) {
240
+ this.rulesSuccess({});
241
+ } else {
242
+ this.rulesFailed(this.errorObj);
243
+ }
244
+ }, 0);
245
+ });
246
+ },
247
+ // iview的校验回调
248
+ validateCb (prop, status, error) {
249
+ if (status === false) {
250
+ this.errorObj.errors.push({
251
+ bool: false,
252
+ message: error
253
+ });
254
+ }
255
+ },
256
+ // 控件自己的校验
257
+ selfValidate (callback) {
209
258
  let bool = true;
210
259
  let errorRefs = [];
211
260
 
212
- if (this.$refs.dshFormItem) {
213
- errorRefs = this.$refs.dshFormItem.filter(refItem => !refItem.validate());
261
+ if (this.$refs.dshFormUnit) {
262
+ errorRefs = this.$refs.dshFormUnit.filter(refItem => !refItem.validate());
214
263
  bool = !errorRefs.length;
215
264
  } else {
216
265
  bool = true;
@@ -219,6 +268,14 @@
219
268
 
220
269
  return bool;
221
270
  },
271
+ // 校验成功
272
+ rulesSuccess (obj) {
273
+ this.$emit("rulesSuccess", obj);
274
+ },
275
+ // 校验失败
276
+ rulesFailed (errorObj) {
277
+ this.$emit("rulesFailed", errorObj);
278
+ },
222
279
 
223
280
  // 点击控件
224
281
  clickControl (formItem) {
@@ -260,7 +317,7 @@
260
317
  // 格式校验 (不依赖必填)
261
318
  if (ruleConfig.regs.length) {
262
319
  rules.push({
263
- message: formItem._regMessage || `${formItem._name}格式不正确`,
320
+ message: formItem._regMessage || `${formItem._name} 格式不正确!`,
264
321
  trigger: "blur",
265
322
  transform: (val) => {
266
323
  if (this.$isEmptyData(val)) {
@@ -280,7 +337,7 @@
280
337
  fields: {
281
338
  lnglat: {
282
339
  required: true,
283
- message: `${formItem._name}为必填项`,
340
+ message: `${formItem._name} 为必填项!`,
284
341
  type: "array"
285
342
  }
286
343
  }
@@ -289,7 +346,7 @@
289
346
  fields: {
290
347
  list: {
291
348
  required: true,
292
- message: `${formItem._name}不能为空行!`,
349
+ message: `${formItem._name} 不能为空行!`,
293
350
  type: "array"
294
351
  }
295
352
  }
@@ -297,7 +354,7 @@
297
354
  referenceBy: {
298
355
  fields: {
299
356
  count: {
300
- message: `${formItem._name}必须关联数据!`,
357
+ message: `${formItem._name} 必须关联数据!`,
301
358
  type: "number",
302
359
  transform: (val) => {
303
360
  if (val && val > 0) {
@@ -313,7 +370,7 @@
313
370
 
314
371
  rules.push({
315
372
  required: true,
316
- message: `${formItem._name}为必填项!`,
373
+ message: `${formItem._name} 为必填项!`,
317
374
  trigger: "blur, change",
318
375
  type: "string",
319
376
  ...(subFieldsMap[formItem._type] || {}),
@@ -423,22 +423,7 @@
423
423
  // 是否显示 单元格校验提示文字
424
424
  getRuleResult (col, row, showRuleMessage = this.showRuleMessage) {
425
425
  if ((this.ruleRecordMap[`${row._id}dsh${col._key}`] || {}).showRuleMessage || showRuleMessage) {
426
- const val = row[col._key];
427
- const ruleConfig = this.$getFieldRuleConfig(col);
428
- // 为空 校验必填;不为空 格式校验 (不是必填也要校验格式)
429
- return this.$isEmptyData(val)
430
- ? {
431
- bool: !col._required,
432
- message: `${col._name}为必填项`
433
- }
434
- : ruleConfig.regs && ruleConfig.regs.length
435
- ? {
436
- bool: ruleConfig.regs.every(regItem => regItem.test(val)),
437
- message: col._regMessage || `${col._name}格式不正确`
438
- }
439
- : {
440
- bool: true
441
- };
426
+ return this.$getFieldRuleResult(col, row);
442
427
  } else {
443
428
  return {
444
429
  bool: true
@@ -11,7 +11,7 @@
11
11
  <div class="DshButtons-flex-left">
12
12
  <bri-button
13
13
  v-for="(operationItem, index) in leftFlatList"
14
- :key="operationItem.type"
14
+ :key="operationItem._key || operationItem.type"
15
15
  :style="operationItem.style"
16
16
  :class="[
17
17
  index ? 'dsh-margin-left8' : undefined,
@@ -56,7 +56,7 @@
56
56
 
57
57
  <bri-button
58
58
  v-for="(operationItem, index) in rightList"
59
- :key="operationItem.type"
59
+ :key="operationItem._key || operationItem.type"
60
60
  :style="operationItem.style"
61
61
  :class="[
62
62
  index ? 'dsh-margin-left8' : undefined,
@@ -79,7 +79,7 @@
79
79
  <template v-else>
80
80
  <bri-button
81
81
  v-for="(operationItem, index) in flatList"
82
- :key="operationItem.type"
82
+ :key="operationItem._key || operationItem.type"
83
83
  :style="operationItem.style"
84
84
  :class="[
85
85
  index ? 'dsh-margin-left8' : undefined,