@zscreate/zhxy-app-component 1.0.267 → 1.0.269

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.
@@ -40,28 +40,7 @@
40
40
  computed: {
41
41
  // 整个form是否有*号,为了保证label对齐,而不是和*号对齐
42
42
  hasRequiredAsterisk() {
43
- if (this.hideRequiredAsterisk) {
44
- return false
45
- }
46
- if (this.mRules) {
47
- const values = Object.values(this.mRules)
48
- if (values && values.length > 0) {
49
- for (let i = 0; i < values.length; i++) {
50
- const value = values[i]
51
- if (Array.isArray(value) && value.length > 0) {
52
- const requiredItem = value.find((v) => v.required === true)
53
- if (requiredItem) {
54
- return true
55
- }
56
- } else {
57
- if (value && value.required) {
58
- return true
59
- }
60
- }
61
- }
62
- }
63
- }
64
- return false
43
+ return true
65
44
  }
66
45
  },
67
46
  watch: {
@@ -92,7 +71,24 @@
92
71
  utils.validateField(this.model, this.mRules, props, callback, {
93
72
  showMessage: this.showMessage
94
73
  })
95
- }
74
+ },
75
+ clearValidation (component, model) {
76
+ if (typeof component.clearValidate === 'function' && (model ? model === component.widget.model : true)) {
77
+ console.log('clearValidate: ', component)
78
+ component.clearValidate();
79
+ }
80
+ if (component.$children && component.$children.length > 0) {
81
+ component.$children.forEach((child) => {
82
+ this.clearValidation(child, model);
83
+ });
84
+ }
85
+ },
86
+ clearValidate (props) {
87
+ this.$children.forEach((child) => {
88
+ this.clearValidation(child, props);
89
+ });
90
+ // this.clearValidation(this.$children, props);
91
+ }
96
92
  }
97
93
  }
98
94
  </script>
@@ -121,7 +121,7 @@ const utils = {
121
121
  title: message,
122
122
  icon: 'none'
123
123
  })
124
- }
124
+ },
125
125
  }
126
126
 
127
127
  export default utils
@@ -415,7 +415,10 @@
415
415
  {{ widget.name }}
416
416
  </view>
417
417
  <view class="evan-form-item-container__main" :style="mContentStyle" @click="handleSeclet(widget.options.multiple)">
418
- <div class="option-font-size">{{ dataModelShow ? dataModelShow : widget.options.placeholder }}</div>
418
+ <view class="form-input" style="display: flex">
419
+ <view class="option-font-size">{{ dataModelShow ? dataModelShow : widget.options.placeholder }}</view>
420
+ <uni-icons style="margin-left: auto; margin-right: 20rpx; height: 60rpx; line-height: 60rpx" @click.native.stop="handleClear" v-if="!widget.options.disabled && dataModelShow" type="clear" color="#e1e1e1" size="14"></uni-icons>
421
+ </view>
419
422
  </view>
420
423
  <!-- <icon type="clear" size="14" v-if="widget.options.canView" />-->
421
424
  </view>
@@ -672,7 +675,12 @@ export default {
672
675
  isCorrect: [Number, String, null],
673
676
  widget: Object,
674
677
  labelStyle: Object,
675
- rules: [Object, Array],
678
+ rules: {
679
+ type: Object,
680
+ default: () => {
681
+ return {}
682
+ }
683
+ },
676
684
  label: String,
677
685
  contentStyle: {
678
686
  type: Object,
@@ -750,6 +758,7 @@ export default {
750
758
  },
751
759
  data() {
752
760
  return {
761
+ showRequiredAsterisk: false,
753
762
  hiddenLineTypes: ['hidden'],
754
763
  nameSign: '',
755
764
  isClickByUser: false, //是否用户点击
@@ -776,6 +785,8 @@ export default {
776
785
  created() {
777
786
  this.updateDataModel();
778
787
  this.pubsubScribe();
788
+ this.initFormLinkage(); //初始化联动
789
+
779
790
  this.showFormData(); //非 v-model值回显
780
791
  //下拉框联动的时候重新选择清空联动的数据
781
792
  if (this.widget.type == 'select') {
@@ -828,9 +839,22 @@ export default {
828
839
  uni.$off(this.widget.model);
829
840
  },
830
841
  methods: {
842
+ clearValidate() {
843
+ this.showFalse = false
844
+ },
831
845
  handleClear() {
832
846
  this.dataModel = []
833
847
  this.dataModelShow = ''
848
+ if (this.widget.type === 'select') {
849
+ this.clearAllLinkageSelect(this.widget.options?.linkage)
850
+ }
851
+ },
852
+ clearAllLinkageSelect(linkage) {
853
+ linkage?.forEach(link_model => {
854
+ uni.$emit(link_model)
855
+ const link_widget = this.dataObj().list.find(item => item.model === link_model)
856
+ if (link_widget) this.clearAllLinkageSelect(link_widget.options?.linkage)
857
+ })
834
858
  },
835
859
  correctOldValue(oldValue) {
836
860
  const type = this.widget.type
@@ -1108,7 +1132,8 @@ export default {
1108
1132
  },
1109
1133
 
1110
1134
  updateRadioOrCheckboxModel(arr) {
1111
- if (!arr) return;
1135
+
1136
+ if (!arr) return global.dictData[this.widget.model] = [];
1112
1137
  this.checkboxAndRadioOptions = JSON.parse(JSON.stringify(arr));
1113
1138
  if (!this.dataModel) return false;
1114
1139
  this.checkboxAndRadioOptions.forEach(item => {
@@ -1281,14 +1306,20 @@ export default {
1281
1306
  })
1282
1307
  this.dataModelShow = str.substr(1);
1283
1308
  },
1284
- updatedSelectModal() {
1309
+ async updatedSelectModal() {
1310
+
1311
+ if (!global.dictData) global.dictData = {
1312
+ [this.widget.model]: null
1313
+ }
1285
1314
  let options = this.widget.options
1286
1315
  if (this.widget.options.dictCode || this.widget.options.dictName) {
1287
1316
  //根据字典Code, 初始化字典数组
1288
- this.$u.get(
1317
+ await this.$u.get(
1289
1318
  `/sys/dict/getDictItems/${this.widget.options.dictCode ? this.widget.options.dictCode : this.widget.options.dictName}`,
1290
1319
  ).then(res => {
1291
1320
  if (res.success) {
1321
+ const dictData = this.arrFindDictOrTable(res.result, 'dictCode')
1322
+ global.dictData[this.widget.model] = dictData
1292
1323
  if (this.widget.type == 'select') {
1293
1324
  this.arrFindOptionLabel(res.result)
1294
1325
  } else if (this.widget.type == 'radio' || this.widget.type == 'checkbox') {
@@ -1300,12 +1331,14 @@ export default {
1300
1331
  let params = {
1301
1332
  tableName: this.widget.options.dictTable
1302
1333
  };
1303
- this.$u.get(`/form/formdesiger/getDataCenterDict`, params).then(res => {
1334
+ await this.$u.get(`/form/formdesiger/getDataCenterDict`, params).then(res => {
1304
1335
  if (res.success) {
1336
+ const dictData = this.arrFindDictOrTable(res.result, 'dictTable')
1337
+ global.dictData[this.widget.model] = dictData
1305
1338
  if (this.widget.type == 'select') {
1306
1339
  this.arrFindOptionLabel(res.result)
1307
1340
  } else if (this.widget.type == 'radio' || this.widget.type == 'checkbox') {
1308
- this.updateRadioOrCheckboxModel(this.arrFindDictOrTable(res.result, 'dictTable'))
1341
+ this.updateRadioOrCheckboxModel(dictData)
1309
1342
  }
1310
1343
  }
1311
1344
  })
@@ -1317,7 +1350,7 @@ export default {
1317
1350
  id: this.linkage[this.widget.model],
1318
1351
  applyId: this.applyId
1319
1352
  }
1320
- this.getSelectUrl(options.dictUrl, params)
1353
+ await this.getSelectUrl(options.dictUrl, params)
1321
1354
  } else if (options.dictUrl.indexOf("?") != -1) {
1322
1355
  let list = options.dictUrl.split("?");
1323
1356
  let url = list[0];
@@ -1325,11 +1358,12 @@ export default {
1325
1358
  if (this.applyId) {
1326
1359
  params.applyId = this.applyId;
1327
1360
  }
1328
- this.getSelectUrl(url, params)
1361
+ await this.getSelectUrl(url, params)
1329
1362
  } else {
1330
- this.getSelectUrl(options.dictUrl, this.applyId ? { applyId: this.applyId } : {});
1363
+ await this.getSelectUrl(options.dictUrl, this.applyId ? { applyId: this.applyId } : {});
1331
1364
  }
1332
1365
  } else {
1366
+ global.dictData[this.widget.model] = this.widget.options.options
1333
1367
  if (this.widget.type == 'select') {
1334
1368
  this.arrFindOptionLabel(this.widget.options.options)
1335
1369
  } else if (this.widget.type == 'radio' || this.widget.type == 'checkbox') {
@@ -1340,12 +1374,21 @@ export default {
1340
1374
  },
1341
1375
  //处理下拉框接口地址数据
1342
1376
  getSelectUrl(url, params) {
1343
- this.$u.get(url, params).then(res => {
1377
+ return this.$u.get(url, params).then(res => {
1344
1378
  if (res.success) {
1379
+ let arr = res.result
1380
+ global.dictData[this.widget.model] = arr.map(item => {
1381
+ return {
1382
+ value: item.dataValue || item.id,
1383
+ label: item.dataKey || item.departName,
1384
+ text: item.dataKey || item.departName
1385
+ }
1386
+ })
1345
1387
  if (this.widget.type == 'select') {
1346
- let arr = res.result
1388
+
1347
1389
  if (!Array.isArray(arr)) return;
1348
1390
  let showLabel = ''
1391
+
1349
1392
  for (let i = 0; i < arr.length; i++) {
1350
1393
  const Code = arr[i].dataKey || arr[i].departName;
1351
1394
  const Value = arr[i].dataValue || arr[i].id;
@@ -1382,14 +1425,16 @@ export default {
1382
1425
  newArr = arr.map(item => {
1383
1426
  return {
1384
1427
  value: item.dictValue,
1385
- label: item.dictLabel
1428
+ label: item.dictLabel,
1429
+ text: item.dictLabel,
1386
1430
  }
1387
1431
  })
1388
1432
  } else {
1389
1433
  newArr = arr.map(item => {
1390
1434
  return {
1391
1435
  value: item.value,
1392
- label: item.text
1436
+ label: item.text,
1437
+ text: item.text
1393
1438
  }
1394
1439
  })
1395
1440
  }
@@ -1421,9 +1466,9 @@ export default {
1421
1466
  /**点击表单后 代表确认已知晓验证不通过**/
1422
1467
  resetShowFalse() {
1423
1468
  this.showFalse = false;
1424
- this.$emit("update:models", {
1425
- ...this.models
1426
- })
1469
+ // this.$emit("update:models", {
1470
+ // ...this.models
1471
+ // })
1427
1472
  },
1428
1473
  updateDataModel() {
1429
1474
  if (this.tableKey) {
@@ -1494,18 +1539,6 @@ export default {
1494
1539
  // // this.dataModel = data[this.widget.model];//dataModel
1495
1540
  // })
1496
1541
  // },
1497
- // 当前formItem是否显示*号
1498
- showRequiredAsteriskFun() {
1499
- // console.log(this.rules, '----')
1500
- const rules = this.rules[this.widget.model];
1501
- // console.log('rules', rules)
1502
- if (rules && rules.length > 0) {
1503
- if (rules.find((rule) => rule.required === true)) {
1504
- return true
1505
- }
1506
- }
1507
- return false
1508
- },
1509
1542
  // 选择人员
1510
1543
  selectUser(flag) {
1511
1544
  if (this.widget.options.disabled) return
@@ -1629,15 +1662,7 @@ export default {
1629
1662
  var PubsubSign = String(Math.random()).split('.')[1];
1630
1663
  Pubsub.subscribe(PubsubSign, (msg, data) => {
1631
1664
  console.log(data)
1632
- this.widget.options?.linkage?.forEach(link_model => {
1633
- uni.$emit(link_model)
1634
- const link_widget = this.dataObj().list.find(item => item.model === link_model)
1635
- if (link_widget) {
1636
- link_widget.options?.linkage?.forEach(link_model => {
1637
- uni.$emit(link_model)
1638
- })
1639
- }
1640
- })
1665
+ this.clearAllLinkageSelect(this.widget.options?.linkage)
1641
1666
  this.isClickByUser = true
1642
1667
  // this.dataModel = data.map(item => item.value)
1643
1668
  const value = data.map(item => item.value) || []
@@ -1712,12 +1737,12 @@ export default {
1712
1737
  formRules = formRules ? formRules[this.prop] : [];
1713
1738
  return [].concat(formRules || []);
1714
1739
  },
1715
- validateField(props, callback) {
1716
- // console.log('---p', props)
1717
- utils.validateField(this.model, this.mRules, props, callback, {
1718
- showMessage: this.showMessage
1719
- })
1720
- },
1740
+ // validateField(props, callback) {
1741
+ // // console.log('---p', props)
1742
+ // utils.validateField(this.model, this.mRules, props, callback, {
1743
+ // showMessage: this.showMessage
1744
+ // })
1745
+ // },
1721
1746
  //打开级联选择器
1722
1747
  openCascdar() {
1723
1748
  this.$refs.picker.show()
@@ -1864,6 +1889,13 @@ export default {
1864
1889
  },
1865
1890
  },
1866
1891
  watch: {
1892
+ currRules: {
1893
+ deep: true,
1894
+ immediate: true,
1895
+ handler(v) {
1896
+ this.showRequiredAsterisk = [].concat(this.currRules || []).some(item => item.required)
1897
+ }
1898
+ },
1867
1899
  models: {
1868
1900
  deep: true,
1869
1901
  handler(v) {
@@ -1946,7 +1978,7 @@ export default {
1946
1978
  }
1947
1979
 
1948
1980
  }
1949
- this.models[this.widget.model] = v
1981
+ // this.models[this.widget.model] = v
1950
1982
 
1951
1983
  this.$emit("update:models", {
1952
1984
  ...this.models,
@@ -29,16 +29,10 @@ export const computedMixin = {
29
29
  }
30
30
  return false
31
31
  },
32
- showRequiredAsterisk() {
33
- /**子表单必选要深入下一层rules**/
34
- const rules = this.tableKey ? this.rules[this.tableKey][this.widget.model] : this.rules[this.widget
35
- .model];
36
- if (rules && rules.length > 0) {
37
- if (rules.find((rule) => rule.required === true)) {
38
- return true
39
- }
40
- }
41
- return false
42
- }
32
+
33
+ currRules() {
34
+ return this.tableKey ? this.rules[this.tableKey][this.widget.model] : this.rules[this.widget
35
+ .model]
36
+ },
43
37
  }
44
38
  }
@@ -172,7 +172,17 @@ export const pubSubMixin = {
172
172
  });
173
173
  }
174
174
  },
175
-
175
+ initFormLinkage() {
176
+ this.publish_linkage = Pubsub.subscribe('formLinkage_' + this.widget.model, (key, data) => {
177
+ // console.log(key, data)
178
+ if (data.type === 'update') {
179
+ this.dataModel = data.updateValue
180
+ }
181
+ if (data.type === 'show') {
182
+ this.widget.options.canView = data.updateValue
183
+ }
184
+ })
185
+ },
176
186
  resetByflag(flag) {
177
187
  if (flag) {
178
188
  this.resetDataModel();
@@ -194,5 +204,13 @@ export const pubSubMixin = {
194
204
  this.dataModel = value
195
205
  },
196
206
 
207
+ },
208
+ destroyed() {
209
+ if (this.pubsubSign) {
210
+ Pubsub.unsubscribe(this.pubsubSign)
211
+ }
212
+ if (this.publish_linkage) {
213
+ Pubsub.unsubscribe(this.publish_linkage);
214
+ }
197
215
  }
198
216
  }
@@ -66,16 +66,6 @@ export const validateFormMixin = {
66
66
  }
67
67
  utils.validateItem(rules, props, tempModel[this.widget.model], callback)
68
68
  },
69
- // 当前formItem是否显示*号
70
- showRequiredAsteriskFun() {
71
- const rules = this.rules[this.widget.model];
72
- // console.log('rules', rules)
73
- if (rules && rules.length > 0) {
74
- if (rules.find((rule) => rule.required === true)) {
75
- return true
76
- }
77
- }
78
- return false
79
- },
69
+
80
70
  }
81
71
  }
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <view class="evan-form-show" >
3
- <evan-form :hide-required-asterisk="hideRequiredAsterisk" ref="form">
4
- <template v-for="(item, index) in dataObj.list">
3
+ <evan-form :hide-required-asterisk="hideRequiredAsterisk" ref="Form" >
4
+ <template v-for="(item, index) in data.list">
5
5
  <template v-if="item.type === 'table' && item.options.canView">
6
6
  <view class="table-wrapper" :key="index">
7
7
  <view class="table-header">
@@ -28,7 +28,7 @@
28
28
  @upDateWidget="data => upDateTableWidget(data, tableItemIndex, item.model, tableCIndex)" :itemkey="tableItemIndex"
29
29
  :tableKey="item.model" :tableIndex="tableCIndex" :prop="tableItem.model"
30
30
  :ref="String(Math.random()).split('.')[1]" :models.sync="models"
31
- :rules="rules" :widget="tableItem" :isDraft="isDraft" :formId="formId"
31
+ :rules="rules" :widget.sync="tableItem" :isDraft="isDraft" :formId="formId"
32
32
  :linkage="linkage" :isApply="isApply" :applyId="applyId">
33
33
  </evan-form-item>
34
34
  </view>
@@ -43,10 +43,10 @@
43
43
 
44
44
  <view v-else-if="item.type === 'all-lay-out'" v-show="item.options.canView" class="form_layout">
45
45
  <view v-for="(colItem, colIndex) in item.columns" :key="colIndex" class="form-item-container">
46
- <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex">
46
+ <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex" v-show="col.options.canView">
47
47
  <evan-form-item :isCorrect="isCorrect" :labelPosition="labelPosition" :prop="col.model"
48
48
  :ref="String(Math.random()).split('.')[1]" :models.sync="models" :rules="rules"
49
- :widget="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
49
+ :widget.sync="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
50
50
  </evan-form-item>
51
51
  </view>
52
52
  </view>
@@ -54,7 +54,7 @@
54
54
 
55
55
  <view v-else-if="item.type === 'grid-lay-out'" v-show="item.options.canView" class="form_layout">
56
56
  <view v-for="(colItem, colIndex) in item.columns" :key="colIndex" class="form-item-container ">
57
- <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex">
57
+ <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex" v-show="col.options.canView">
58
58
  <template v-if="col.type == 'hnkj-verify' && item.options.canView">
59
59
  <view class="verify">
60
60
  <view class="verify-step">
@@ -102,7 +102,7 @@
102
102
  <evan-form-item :isCorrect="isCorrect" :prop="col.model"
103
103
  :labelPosition="labelPosition"
104
104
  :ref="String(Math.random()).split('.')[1]" :models.sync="models" :rules="rules"
105
- :widget="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
105
+ :widget.sync="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
106
106
  </evan-form-item>
107
107
  </template>
108
108
  </view>
@@ -111,10 +111,10 @@
111
111
 
112
112
  <view v-else-if="item.type === 'grid'" v-show="item.options.canView" class="form_layout">
113
113
  <view class="form-item-container" v-for="(colItem, colIndex) in item.columns" :key="colIndex">
114
- <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex">
114
+ <view v-for="(col, itemIndex) in colItem.list" :key="itemIndex" v-show="col.options.canView">
115
115
  <evan-form-item :isCorrect="isCorrect" :labelPosition="labelPosition" :prop="col.model"
116
116
  :ref="String(Math.random()).split('.')[1]" :models.sync="models" :rules="rules"
117
- :widget="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
117
+ :widget.sync="col" :isDraft="isDraft" :formId="formId" :linkage="linkage" :isApply="isApply" :applyId="applyId">
118
118
  </evan-form-item>
119
119
  </view>
120
120
  </view>
@@ -196,13 +196,15 @@
196
196
 
197
197
  <template v-else>
198
198
  <view :key="index" class="form-item-container" v-show="item.options.canView" >
199
+
199
200
  <evan-form-item @upDateWidget="data => upDateWidget(data, index)" :labelPosition="labelPosition" :isCorrect="isCorrect" :prop="item.model"
200
201
  :ref="String(Math.random()).split('.')[1]" :models.sync="models" :rules="rules"
201
- :widget="item" :itemkey="index" :isDraft="isDraft" :formId="formId" :linkage="linkage" :formData="value"
202
+ :widget.sync="item" :itemkey="index" :isDraft="isDraft" :formId="formId" :linkage="linkage" :formData="value"
202
203
  :isApply="isApply" :applyId="applyId">
203
204
  </evan-form-item>
204
205
  </view>
205
206
  </template>
207
+ <!-- {{ item.options.canView? 1 : 0 }}-->
206
208
  </template>
207
209
 
208
210
  </evan-form>
@@ -220,7 +222,17 @@ import evanForm from "../evan-form/evan-form";
220
222
  import mTextarea from "../m-textarea/m-textarea";
221
223
  import packageJson from '../../package.json'
222
224
  import { run } from "../../utils/formula_run"
225
+ import {intersection, isEqual, isEqualWith, reduce, cloneDeep} from "lodash";
226
+ import {getRecursionWidget} from "../../utils/util";
223
227
  console.log('zhxy-app-component: ', packageJson.version)
228
+
229
+ function timeout(ms) {
230
+ return new Promise(resolve => {
231
+ setTimeout(() => {
232
+ resolve()
233
+ }, ms)
234
+ })
235
+ }
224
236
  export default {
225
237
  options: { styleIsolation: 'shared' },
226
238
  name: 'formContainer',
@@ -253,6 +265,7 @@ export default {
253
265
  tableFlag: {
254
266
 
255
267
  },
268
+ data: {},
256
269
  userSignature: undefined,
257
270
  // dataObj:dataObj,
258
271
  isScroll: true,
@@ -295,6 +308,12 @@ export default {
295
308
  // // console.log(this.models)
296
309
  // this.isScroll = true;
297
310
  // },
311
+ "dataObj.config"(val) {
312
+ if (val?.linkage_config) {
313
+ this.data.config = val
314
+ this.handleLinkAge()
315
+ }
316
+ },
298
317
  verifyNode: {
299
318
  handler(val) {
300
319
  if (val) {
@@ -311,25 +330,30 @@ export default {
311
330
  },
312
331
  dataObj: {
313
332
  handler(v) {
333
+ if (this._currObjId && this._currObjId !== this.dataObj._currObjId) return
334
+ this.data = v
314
335
  if (this.dataObj && this.dataObj.list) {
336
+ this.data = v
337
+ this.dataObj._currObjId = this._currObjId = Math.random()
315
338
  this.rules = {};
316
- this.generateModle(this.dataObj.list);
339
+ this.generateModle(this.data.list);
317
340
  this.updateFormDataToModels()
318
341
  console.log(JSON.stringify(this.models))
319
342
  }
320
343
  },
321
- immediate: true
344
+ immediate: true
345
+ },
346
+ data: {
347
+ handler(val) {
348
+ this.dataObj = val
349
+ },
350
+ deep: true
322
351
  },
323
352
  value: {
324
353
  handler(v) {
325
- if (this.dataObj && this.dataObj.list) {
326
- this.rules = {};
327
- this.generateModle(this.dataObj.list);
328
-
329
- this.updateFormDataToModels()
330
- console.log(this.models)
331
- console.log(JSON.stringify(this.models))
332
- }
354
+ if (v) {
355
+ this.updateFormDataToModels()
356
+ }
333
357
  },
334
358
  immediate: true
335
359
  },
@@ -638,9 +662,253 @@ export default {
638
662
  // console.log('tableData',this.tableData)
639
663
  // console.log(this.models)
640
664
  },
665
+ async or(...args) {
666
+ for (const argsKey in args) {
667
+ if (await args[argsKey]) return true
668
+ }
669
+ return false
670
+ },
671
+ async and(...args) {
672
+ for (const argsKey in args) {
673
+ if (!await args[argsKey]) return false
674
+ }
675
+ return true
676
+ },
677
+ async handleLinkAge() {
678
+ // console.log(this.data.config.linkage_config)
679
+ const that = this
680
+ if (!this.data?.config?.linkage_config) return
681
+ if (this.formFunctions) return
682
+ this.formFunctions = {
683
+ async call_func(list, models) {
684
+ const widgetList = getRecursionWidget(that.data.list)
685
+ const linkageWidget = widgetList.filter(item => list.map(item => item.model).includes(item.model))
686
+ return list.map(item => this[item.type](models[item.model] ,item.value, linkageWidget.find(widget => widget.model === item.model)))
687
+ },
688
+ all_same(currVal, targetVal, widget) {
689
+ if (Array.isArray(currVal) && Array.isArray(targetVal)) {
690
+ return intersection(targetVal, currVal).length === targetVal.length
691
+ }
692
+ return false
693
+ },
694
+ same(currVal, targetVal, widget) {
695
+ console.log(widget)
696
+ const { format } = widget.options
697
+
698
+ if (widget.type === 'date') {
699
+ return moment(currVal).format(format) === moment(targetVal).format(format)
700
+ }
701
+ if (Array.isArray(currVal)) {
702
+ if (Array.isArray(targetVal)) {
703
+ if (currVal.length !== targetVal.length) return false
704
+ return isEqual(currVal.sort(), targetVal.sort()) || isEqualWith(currVal.sort(), targetVal.sort(), (a, b) => { if (!a.id) return false; return a.id === b.id})
705
+ }
706
+ }
707
+ return currVal == targetVal
708
+ },
709
+ not_same(currVal, targetVal, widget) {
710
+ const { format } = widget.options
711
+ if (widget.type === 'date') {
712
+ return moment(currVal).format(format) === moment(targetVal).format(format)
713
+ }
714
+ if (Array.isArray(currVal)) {
715
+ return currVal.every(item => {
716
+ return targetVal == item?.id || targetVal == item
717
+ })
718
+ }
719
+ return currVal != targetVal
720
+ },
721
+ gt(currVal, targetVal, widget) {
722
+ const { format } = widget.options
723
+ if (widget.type === 'date') {
724
+ return moment(currVal).isAfter(moment(targetVal))
725
+ }
726
+ return currVal > targetVal
727
+ },
728
+ gte(currVal, targetVal, widget) {
729
+ const { format } = widget.options
730
+ if (widget.type === 'date') {
731
+ return moment(currVal).isSameOrAfter(moment(targetVal))
732
+ }
733
+ return currVal >= targetVal
734
+ },
735
+ lt(currVal, targetVal, widget) {
736
+ if (widget.type === 'date') {
737
+ return moment(currVal).isBefore(moment(targetVal))
738
+ }
739
+ return currVal < targetVal
740
+ },
741
+ lte(currVal, targetVal, widget) {
742
+ const { format } = widget.options
743
+ if (widget.type === 'date') {
744
+ return moment(currVal).isSameOrBefore(moment(targetVal))
745
+ }
746
+ return currVal <= targetVal
747
+ },
748
+ same_some(currVal, targetVal, widget) {
749
+ if (Array.isArray(targetVal) && targetVal.includes('[未填写]')) {
750
+ targetVal = targetVal.concat(undefined, null, '')
751
+ }
752
+ if (Array.isArray(currVal) && !currVal.length) currVal = undefined
753
+
754
+ return [].concat(currVal).some(item => targetVal.includes(item))
755
+ // return targetVal.includes(currVal)
756
+ },
757
+ not_same_some(currVal, targetVal, widget) {
758
+ if (Array.isArray(targetVal) && targetVal.includes('[未填写]')) {
759
+ targetVal = targetVal.concat(undefined, null, '')
760
+ }
761
+ if (Array.isArray(currVal) && !currVal.length) currVal = undefined
762
+ return [].concat(currVal).some(item => !targetVal.includes(item))
763
+ // return !targetVal.includes(currVal)
764
+ },
765
+ EMPTY(currVal, targetVal, widget) {
766
+ if (Array.isArray(currVal)) return !currVal.length
767
+ return !currVal
768
+ },
769
+ NOT_EMPTY(currVal, targetVal, widget) {
770
+ if (Array.isArray(currVal)) return !!currVal.length
771
+ return !!currVal
772
+ },
773
+ async include(currVal, targetVal, widget) {
774
+ if ([undefined, null, ''].includes(currVal)) return false
775
+ if (['checkbox', 'select', 'radio'].includes(widget.type) && global.dictData[widget.model] == null || Array.isArray(global.dictData[widget.model])) {
776
+ for (let i = 0; i < 10; i++) {
777
+ if (Array.isArray(global.dictData[widget.model])) {
778
+ return global.dictData[widget.model].filter(item => item.value == currVal)?.some( item => item.text.includes(targetVal || undefined) || item.value.includes(targetVal || undefined))
779
+ }
780
+ await timeout(300)
781
+ }
782
+ }
783
+ return currVal.includes(targetVal || undefined)
784
+ },
785
+ async not_include(currVal, targetVal, widget) {
786
+ return !(await this.include(currVal, targetVal, widget))
787
+ },
788
+ }
789
+ this.formFunctions._init = true
790
+ await this.$nextTick()
791
+ this.$watch('models', async (newVal, oldVal) => {
792
+ await timeout(0)
793
+ let diffModels = reduce(newVal, function(result, value, key) {
794
+ return isEqual(value, oldVal?.[key]) ?
795
+ result : result.concat(key);
796
+ }, []);
797
+ if (!diffModels?.length && (this.formFunctions._init && newVal && oldVal)) {
798
+ diffModels = Object.keys(newVal)
799
+ this.formFunctions._init = false
800
+ }
801
+ // const differenceObj = difference(cloneDeep(newVal), cloneDeep(oldVal))
802
+ console.log('diffModels', diffModels)
803
+ const widgetList = getRecursionWidget(this.data?.list)
804
+ this.data?.config?.linkage_config?.forEach(item => {
805
+ let { toTypeSelect, toWidgetList, typeSelect, list, updateValue, hideClearValue, forceClearValue } = item
806
+ // 表单详情会导致可编辑
807
+ if (['update', 'disabled'].includes(toTypeSelect) && this.$route?.query?.type === 'detail') return
808
+ toWidgetList.forEach(async toWidgetModel => {
809
+ const widget = widgetList.find(item => item.model === toWidgetModel)
810
+ const changeModelList = list.some(item => diffModels.includes(item.model)) ? list : []
811
+ if (changeModelList.length === 0) return
812
+
813
+ const flag = await this[typeSelect].apply(this, await this.formFunctions.call_func(changeModelList, newVal))
814
+ switch (toTypeSelect) {
815
+ case 'show':
816
+ if (widget.parentType === 'table') {
817
+ this.$set(widget.options, 'canView', flag)
818
+ }
819
+ Pubsub.publish('formLinkage_' + widget.model, {
820
+ type: 'show',
821
+ updateValue: flag,
822
+ })
823
+ if (!flag && hideClearValue) {
824
+ Pubsub.publish('formLinkage_' + widget.model, {
825
+ type: 'update',
826
+ updateValue: '',
827
+ })
828
+ setTimeout(() => {
829
+ const isAllFlag = widgetList.filter(item => item.parentModel === widget.parentModel).every( item => item.options.canView === flag)
830
+ if (!flag && isAllFlag) {
831
+ // 删除所有行
832
+ that.tableData = []
833
+ }
834
+ }, 100)
835
+ }
836
+ // this.$set(widget.options, 'canView', flag)
837
+ // this.data.list = cloneDeep(this.data.list)
838
+ break
839
+ case 'required':
840
+ let rules = this.rules
841
+ if (widget.parentType === 'table') {
842
+ if (!rules[widget.parentModel]) rules[widget.parentModel] = {}
843
+ rules = rules[widget.parentModel]
844
+ }
845
+ if (!rules[widget.model]) rules[widget.model] = []
846
+ const hasRequiredConfig = rules[widget.model].some(item => {
847
+ if (item?.required !== undefined) {
848
+ item.required = flag
849
+ return true
850
+ }
851
+ return false
852
+ })
853
+ if (!hasRequiredConfig) {
854
+ rules[widget.model].push( {
855
+ required: flag,
856
+ trigger: 'change',
857
+ message: `${(widget.name || "").replaceAll(' ', '')}必须填写`,
858
+ })
859
+ }
860
+ this.$set(widget.options, 'required', flag)
861
+
862
+ !flag && this.$refs.Form.clearValidate(widget.model)
863
+
864
+ this.$set(widget, 'rules', rules[widget.model])
865
+ this.generateRules(widget, this.data?.list?.find(item => item.model === widget.parentModel))
866
+ break
867
+ case 'update':
868
+ updateValue = String(updateValue)
869
+ if (isNaN(updateValue)) {
870
+ try {
871
+ updateValue = JSON.parse(updateValue)
872
+ } catch (e) {
873
+
874
+ }
875
+ }
876
+ if (widget.type === 'rate') updateValue = !isNaN(updateValue) ? Number(updateValue) : updateValue
877
+ // if (['responsibility', 'switch'].includes(widget.type)) updateValue = Boolean(updateValue) || updateValue === 'true'
878
+ if (widget.parentType === 'table') {
879
+ if (!Array.isArray(this.models[widget.parentModel])) this.models[widget.parentModel] = []
880
+ return this.models[widget.parentModel]?.forEach((item,idx) => {
881
+ this.models[widget.parentModel][idx][widget.model] = flag ? updateValue : ''
882
+ })
883
+ }
884
+ // 不符合时, 如果 未勾选 “不符合时清除值”, 就不用清理
885
+ if (!flag && !forceClearValue) break
886
+ Pubsub.publish('formLinkage_' + widget.model, {
887
+ type: 'update',
888
+ updateValue: flag ? updateValue : '',
889
+ })
890
+ // setTimeout(() => {
891
+ // this.$set(this.models, widget.model, flag ? updateValue : undefined)
892
+ // // this.models[widget.model] = flag ? updateValue : ''
893
+ // }, 1000)
894
+ break
895
+ case 'disabled':
896
+ this.$set(widget.options, 'disabled', flag)
897
+ break
898
+ }
899
+ })
900
+
901
+ })
902
+ },
903
+ {
904
+ immediate: true,
905
+ deep: true
906
+ })
907
+ },
641
908
  /***初始化models***/
642
909
  generateModle(genList) {
643
- if (!genList || genList.length === 0) return;
910
+ if (!genList || genList.length === 0) return;
911
+ this.handleLinkAge()
644
912
  for (let i = 0; i < genList.length; i++) {
645
913
  if (["grid", 'grid-lay-out', 'all-lay-out', 'table'].includes(genList[i].type)) {
646
914
  let subscribeKey = genList[i].options.subscribeOptions ?
@@ -749,14 +1017,22 @@ export default {
749
1017
  } else {
750
1018
  if (this.rules[genList[i].model]) {
751
1019
  if (genList[i].rules) {
752
- this.rules[genList[i].model] = [
1020
+ this.$set(this.rules, genList[i].model, [
753
1021
  ...this.rules[genList[i].model],
754
1022
  ...genList[i].rules.map(item => {
755
1023
  return {
756
1024
  ...item
757
1025
  };
758
1026
  })
759
- ];
1027
+ ]);
1028
+ // this.rules[genList[i].model] = [
1029
+ // ...this.rules[genList[i].model],
1030
+ // ...genList[i].rules.map(item => {
1031
+ // return {
1032
+ // ...item
1033
+ // };
1034
+ // })
1035
+ // ];
760
1036
  }
761
1037
  } else {
762
1038
  if (genList[i].rules) {
@@ -776,6 +1052,15 @@ export default {
776
1052
  this.$emit('formUpdated')
777
1053
  })
778
1054
  },
1055
+ generateRules(widget, parentWidget) {
1056
+ if (parentWidget && parentWidget.columns) {
1057
+ if (!this.rules[parentWidget.model]) this.rules[parentWidget.model] = {}
1058
+ this.rules[parentWidget.model][widget.model] = widget.rules;
1059
+ return
1060
+ }
1061
+ this.$set(this.rules, widget.model, widget.rules)
1062
+ this.rules = cloneDeep(this.rules)
1063
+ },
779
1064
  validateTable() {
780
1065
 
781
1066
  // 查找所有的table 子表单的配置组件
@@ -912,13 +1197,7 @@ export default {
912
1197
  // })
913
1198
  },
914
1199
  saveForm2() {
915
- this.$refs.form.validateField(['sub', 'phone'], (res) => {
916
- if (res) {
917
- uni.showToast({
918
- title: '验证通过'
919
- })
920
- }
921
- })
1200
+
922
1201
  // this.$refs.form2.validate((res) => {
923
1202
  // if (res) {
924
1203
  // uni.showToast({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zscreate/zhxy-app-component",
3
- "version": "1.0.267",
3
+ "version": "1.0.269",
4
4
  "private": false,
5
5
  "description": "zhxy-app-component",
6
6
  "main": "index.js",
package/utils/util.js CHANGED
@@ -17,6 +17,43 @@ function formatTime(time) {
17
17
  }).join(':')
18
18
  }
19
19
 
20
+ /**
21
+ * 遍历所有组件(包括布局组件中)
22
+ * @param widgetList
23
+ * @returns {*[]}
24
+ */
25
+ function getRecursionWidget(widgetList) {
26
+ const res_list = []
27
+
28
+ let func = (res_list ,val) => {
29
+ if (val instanceof Array && val.length > 0) {
30
+ val.forEach((item) => {
31
+ if (["grid", "grid-lay-out", "all-lay-out"].includes(item.type)) {
32
+ // columns.list
33
+ item.columns.forEach((columnsItem) => {
34
+ columnsItem.list.type = item.type
35
+ columnsItem.list.p_type = item.type
36
+ columnsItem.list.p_model = item.model
37
+ func(res_list, columnsItem.list);
38
+ });
39
+ } else if (["table"].includes(item.type)) {
40
+ // columns
41
+ item.columns.p_type = item.type
42
+ item.columns.p_model = item.model
43
+ func(res_list, item.columns);
44
+ } else {
45
+ item.parentType = val.p_type
46
+ item.parentModel = val.p_model
47
+ res_list.push(item);
48
+ }
49
+ });
50
+ }
51
+ }
52
+ func(res_list, widgetList)
53
+ func = null
54
+ return res_list
55
+ }
56
+
20
57
  function formatLocation(longitude, latitude) {
21
58
  if (typeof longitude === 'string' && typeof latitude === 'string') {
22
59
  longitude = parseFloat(longitude)
@@ -251,6 +288,7 @@ module.exports = {
251
288
  downloadFile,
252
289
  getParentData,
253
290
  getParentFunc,
291
+ getRecursionWidget,
254
292
  getDictInfo,
255
293
  h5PreviewFile,
256
294
  getOpenId