three-trees-ui 1.0.83 → 1.0.84

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.
@@ -7,9 +7,14 @@ import { decode } from '@/util/base64'
7
7
  import Vue from 'vue'
8
8
  import $ from 'jquery'
9
9
  import _ from 'lodash'
10
+ import moment from 'moment'
10
11
  export default {
11
12
  data() {
12
13
  return {
14
+ bindKey: {},
15
+ bindValue: {},
16
+ defaultQuerys: [],
17
+ isInit: true,
13
18
  bpmRunTime: this.$requestConfig.flowUrl,
14
19
  fileList: [],
15
20
  tableData: { selectRows: [], querys: '' },
@@ -77,6 +82,8 @@ export default {
77
82
  pageSize: 30,
78
83
  total: 0,
79
84
  },
85
+ lastPage: 1, //上一次输入的分页数、默认为1
86
+ total: 0,
80
87
  rows: [],
81
88
  queryParam: {},
82
89
  allSummaryConfig: {},
@@ -84,15 +91,54 @@ export default {
84
91
  summaryTableData: [],
85
92
  needRequestTotal: false, // 需不需要后端统计列表全部数据
86
93
  tableDataTotal: {},
94
+ loadingTotal: false, //统计按钮加载中
95
+ pageSizeArray: [
96
+ {
97
+ label: '10条/页',
98
+ value: 10,
99
+ },
100
+ {
101
+ label: '20条/页',
102
+ value: 20,
103
+ },
104
+ {
105
+ label: '30条/页',
106
+ value: 30,
107
+ },
108
+ {
109
+ label: '40条/页',
110
+ value: 40,
111
+ },
112
+ {
113
+ label: '50条/页',
114
+ value: 50,
115
+ },
116
+ {
117
+ label: '100条/页',
118
+ value: 100,
119
+ },
120
+ {
121
+ label: '200条/页',
122
+ value: 200,
123
+ },
124
+ {
125
+ label: '300条/页',
126
+ value: 300,
127
+ },
128
+ {
129
+ label: '500条/页',
130
+ value: 500,
131
+ },
132
+ ],
87
133
  }
88
134
  },
89
135
  watch: {
90
- formKey: function (newVal) {
136
+ formKey: function(newVal) {
91
137
  if (newVal) {
92
138
  this.init()
93
139
  }
94
140
  },
95
- 'tableData.selectRows': function (newVal) {
141
+ 'tableData.selectRows': function(newVal) {
96
142
  if (newVal.length > 0) {
97
143
  let me_ = this
98
144
  me_.uploadParams.id = []
@@ -160,7 +206,29 @@ export default {
160
206
  deep: true,
161
207
  },
162
208
  },
209
+ created() {
210
+ if (this.queryView.jsScript) {
211
+ // 执行js脚本
212
+ this.handleDiyScript(this.queryView.jsScript)
213
+ }
214
+ },
163
215
  methods: {
216
+ handleDiyScript(scriptValue) {
217
+ //执行前置脚本内容
218
+ const _this = this
219
+ // 用户信息
220
+ const account = this.$requestConfig.getAccount()
221
+ const userId = this.$requestConfig.getUserId()
222
+ const userName = this.$requestConfig.getUsername()
223
+ const preScript = `const scriptFunction = function(_this, account, userId, userName){
224
+ ${scriptValue}
225
+ };`
226
+ try {
227
+ eval(`${preScript}scriptFunction(_this, account, userId, userName);`)
228
+ } catch (err) {
229
+ this.$message.error(`脚本事件执行错误:${err}`)
230
+ }
231
+ },
164
232
  handelBindFiledValua() {
165
233
  //数据视图控件
166
234
  let _me = this
@@ -209,7 +277,7 @@ export default {
209
277
  selectList[i].selectValue = value
210
278
 
211
279
  //添加监听
212
- pInst.$watch(path, function (newVal, oldVal) {
280
+ pInst.$watch(path, function(newVal, oldVal) {
213
281
  _.debounce(() => {
214
282
  if (newVal !== oldVal) {
215
283
  _me.queryViewOptions.selectList[i].selectValue = newVal
@@ -353,7 +421,7 @@ export default {
353
421
  this.$router.push(url)
354
422
  },
355
423
 
356
- handleSizeChange: function (size) {
424
+ handleSizeChange: function(size) {
357
425
  //每页下拉显示数据
358
426
  this.pagination.pageSize = size
359
427
  if (this.$refs.queryViewList) {
@@ -362,9 +430,9 @@ export default {
362
430
  this.search()
363
431
  }
364
432
  },
365
- handleCurrentChange: function (currentPage) {
433
+ handleCurrentChange: function(currentPage) {
366
434
  //点击第几页
367
- this.pagination.page = currentPage
435
+ this.pagination.page = currentPage ? currentPage : this.lastPage
368
436
  if (this.$refs.queryViewList) {
369
437
  this.$refs.queryViewList.load()
370
438
  } else {
@@ -372,14 +440,126 @@ export default {
372
440
  }
373
441
  },
374
442
  //回车查询
375
- searchEnterFun: function (e) {
443
+ searchEnterFun: function(e) {
376
444
  let keyCode = window.event ? e.keyCode : e.which
377
445
  if (keyCode == 13) {
378
446
  this.pagination.page = 1
379
447
  this.search()
380
448
  }
381
449
  },
382
- search(param, cb, isSearchBtn, needRequestTotal = false) {
450
+ getQueryDataViewOperation(key) {
451
+ switch (key) {
452
+ case 'EQ':
453
+ return 'EQUAL'
454
+ case 'NE':
455
+ return 'NOT_EQUAL'
456
+ case 'LK':
457
+ return 'LIKE'
458
+ case 'LFK':
459
+ return 'LEFT_LIKE'
460
+ case 'RHK':
461
+ return 'RIGHT_LIKE'
462
+ case 'BETWEEN':
463
+ return 'BETWEEN'
464
+ default:
465
+ return 'LIKE'
466
+ }
467
+ },
468
+ async buildDefaultQuerys() {
469
+ let querys = []
470
+ let conditions = JSON.parse(this.queryView.conditions)
471
+ //条件字段默认值判断
472
+ for (let i = 0; i < conditions.length; i++) {
473
+ let condition = conditions[i]
474
+ if (condition.defaultValue) {
475
+ let defaultValue = condition.isScriptDefault
476
+ ? await this.getScriptDefaultValue(condition.defaultValue)
477
+ : condition.defaultValue
478
+ if (condition.dataType == 'number') {
479
+ defaultValue = parseFloat(defaultValue)
480
+ }
481
+ this.$set(this.searchForm, condition.fieldName, defaultValue)
482
+
483
+ querys.push({
484
+ property: condition.fieldName,
485
+ value: defaultValue,
486
+ group: 'main',
487
+ operation: this.getQueryDataViewOperation(condition.operate),
488
+ relation: 'AND',
489
+ })
490
+ }
491
+ }
492
+ this.defaultQuerys = querys
493
+ return querys
494
+ },
495
+ getScriptDefaultValue(scriptValue) {
496
+ return new Promise((resolve) => {
497
+ //执行前置脚本内容
498
+ const _this = this
499
+ // 用户信息
500
+ const account = this.$requestConfig.getAccount()
501
+ const userId = this.$requestConfig.getUserId()
502
+ const userName = this.$requestConfig.getUsername()
503
+ const _moment = moment
504
+ const preScript = `const scriptFunction = function(_this, account, userId, userName, _moment){
505
+ ${scriptValue}
506
+ };`
507
+ let result = ''
508
+ try {
509
+ result = eval(
510
+ `${preScript}scriptFunction(_this, account, userId, userName, _moment);`
511
+ )
512
+ if (result && result.then && typeof result.then === 'function') {
513
+ result.then(
514
+ (t) => {
515
+ resolve(t)
516
+ },
517
+ (fail) => {
518
+ //接口返回失败则终止按钮操作,并输出错误信息
519
+ resolve('')
520
+ }
521
+ )
522
+ } else {
523
+ resolve(result)
524
+ }
525
+ } catch (err) {
526
+ resolve('')
527
+ this.$message.error(`查询值默认脚本事件执行错误:${err}`)
528
+ }
529
+ })
530
+ },
531
+ validateSearchRequired(querys = []) {
532
+ let errorMsg = ''
533
+ let conditions = JSON.parse(this.queryView.conditions)
534
+ if (conditions && querys) {
535
+ conditions.forEach((item) => {
536
+ if (item.isRequired) {
537
+ let index = querys.findIndex((k) => {
538
+ return k.property == item.fieldName
539
+ })
540
+ if (index == -1) {
541
+ errorMsg = `字段【${item.fieldDesc}】为必填查询字段,不能为空!`
542
+ }
543
+ }
544
+ })
545
+ }
546
+ return errorMsg
547
+ },
548
+ checkHaveRequired() {
549
+ let haveRequired = false
550
+ try {
551
+ let conditions = JSON.parse(this.queryView.conditions)
552
+ if (conditions) {
553
+ haveRequired = conditions.some((item) => {
554
+ return item.isRequired
555
+ })
556
+ }
557
+ } catch (e) {
558
+ console.log(e)
559
+ }
560
+ return haveRequired
561
+ },
562
+ async search(param, cb, isSearchBtn, needRequestTotal = false) {
383
563
  // 不需要请求后端接口统计列表数据
384
564
  this.needRequestTotal = needRequestTotal
385
565
  !param && (param = {})
@@ -387,6 +567,38 @@ export default {
387
567
  const dataTemplateQueryVo = {
388
568
  queryFilter: param,
389
569
  }
570
+ //初始化时,把查询字段的默认值加进去
571
+ if (this.isInit) {
572
+ let querys = await this.buildDefaultQuerys()
573
+ dataTemplateQueryVo.queryFilter.querys =
574
+ dataTemplateQueryVo.queryFilter.querys || []
575
+ dataTemplateQueryVo.queryFilter.querys = dataTemplateQueryVo.queryFilter.querys.concat(
576
+ querys
577
+ )
578
+ }
579
+ // 非高级查询时,将默认值带上
580
+ if (!isSearchBtn) {
581
+ dataTemplateQueryVo.queryFilter.querys =
582
+ dataTemplateQueryVo.queryFilter.querys || []
583
+ dataTemplateQueryVo.queryFilter.querys = dataTemplateQueryVo.queryFilter.querys.concat(
584
+ this.defaultQuerys
585
+ )
586
+ }
587
+ // 检查是否有必填字段
588
+ if (this.checkHaveRequired() && this.isInit) {
589
+ this.$refs.queryViewList.showAdvancedSearch = true
590
+ }
591
+ // 查询字段 校验是否必填,如果是必填没数据,需返回提示
592
+ let errorMsg = this.validateSearchRequired(
593
+ dataTemplateQueryVo.queryFilter.querys
594
+ )
595
+ if (errorMsg) {
596
+ !this.isInit && this.$message.warning(errorMsg)
597
+ cb && cb()
598
+ this.isInit = false
599
+ return
600
+ }
601
+ this.isInit = false
390
602
  //保存查询参数,用于作为导出的查询参数
391
603
  if (this.queryViewOptions) {
392
604
  //关联查询字段
@@ -403,8 +615,34 @@ export default {
403
615
  alias: this.alias || this.queryView.alias,
404
616
  param: dataTemplateQueryVo,
405
617
  }
618
+ // 自定义对话框查询参数修改
619
+ if (isSearchBtn) {
620
+ obj.param = this.makeCustomDialogParam(obj.param)
621
+ }
406
622
  this.getQuerySqlViewByPagination(obj, cb)
407
623
  },
624
+ // 高级查询 自定义对话框查询参数修改
625
+ makeCustomDialogParam(data) {
626
+ //处理绑定字段
627
+ this.bindValue = this.searchForm.bindValue || this.bindValue
628
+ this.bindKey = this.searchForm.bindKey || this.bindKey
629
+ //记录后再删除
630
+ delete this.searchForm.bindValue
631
+ delete this.searchForm.bindKey
632
+ if (data.queryFilter && data.queryFilter.querys) {
633
+ data.queryFilter.querys.forEach((k) => {
634
+ Object.keys(this.bindKey).forEach((key) => {
635
+ if (key === k.property) {
636
+ let valueKey = this.bindKey[key]
637
+ if (this.bindValue[key] && this.bindValue[key][valueKey]) {
638
+ k.value = this.bindValue[key][valueKey]
639
+ }
640
+ }
641
+ })
642
+ })
643
+ }
644
+ return data
645
+ },
408
646
  getQuerySqlViewByPagination(param, cb) {
409
647
  if (this.needRequestTotal) {
410
648
  // 调用后端接口更新 tableDataTotal
@@ -419,13 +657,17 @@ export default {
419
657
  })
420
658
  }
421
659
  this.$requestConfig
422
- .getQueryViewDataList(param)
660
+ .getQueryViewDataListWithoutTotal(param)
423
661
  .then((response) => {
424
662
  this.rows = response.rows
425
- this.pagination.total = response.total
663
+ // this.pagination.total = response.total
426
664
  this.pagination.page = response.page
427
665
  this.pagination.pageSize = response.pageSize
428
666
  this.filterOldSummaryValByType('currentPage')
667
+ //每次请求后不再统计总数,而是在统计按钮中去统计,当数量统计过一次后,再重新设置到当前页
668
+ if (this.total) {
669
+ this.$set(this.pagination, 'total', this.total)
670
+ }
429
671
  this.summaryTableData.push({
430
672
  project: '当前页汇总',
431
673
  key: 'currentPage',
@@ -445,12 +687,31 @@ export default {
445
687
  cb && cb()
446
688
  })
447
689
  },
690
+ getQuerySqlViewByPaginationTotal(param, cb) {
691
+ this.loadingTotal = true
692
+ this.$requestConfig
693
+ .getQueryViewDataListWithTotal(param)
694
+ .then((response) => {
695
+ this.total = response.value
696
+ //每次请求后不再统计总数,而是在统计按钮中去统计,当数量统计过一次后,再重新设置到当前页
697
+ if (this.total) {
698
+ this.$set(this.pagination, 'total', this.total)
699
+ }
700
+ this.loadingTotal = false
701
+ this.$nextTick(() => {
702
+ this.$refs.queryViewList && this.$refs.queryViewList.doLayout()
703
+ })
704
+ })
705
+ .finally(() => {
706
+ this.loadingTotal = false
707
+ cb && cb()
708
+ })
709
+ },
448
710
  getQueryFilter() {
449
711
  let operationMap = this.getSearchItems() //查询条件类型
450
712
  // let fieldQueryMap = this.getFieldQuery() //查询条件字段
451
713
  let specialMap = this.getSpecialMap() //获取特殊查询情况(自定义对话框)
452
714
  let querys = [] //查询条件
453
- let queryFilter = {}
454
715
  let pageBean = { pageBean: this.pagination }
455
716
  let params = {
456
717
  sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
@@ -458,8 +719,18 @@ export default {
458
719
  }
459
720
  params.pagination = pageBean
460
721
  if ($.isEmptyObject(this.searchForm)) {
722
+ if (this.$refs.queryViewList && this.$refs.queryViewList.querys) {
723
+ querys.push(...this.$refs.queryViewList.querys)
724
+ }
725
+ params = { pageBean: this.pagination, querys }
461
726
  return params
462
727
  } else {
728
+ //处理绑定字段
729
+ this.bindValue = this.searchForm.bindValue || this.bindValue
730
+ this.bindKey = this.searchForm.bindKey || this.bindKey
731
+ //记录后再删除
732
+ delete this.searchForm.bindValue
733
+ delete this.searchForm.bindKey
463
734
  for (var key in this.searchForm) {
464
735
  if (
465
736
  typeof this.searchForm[key] != 'undefined' &&
@@ -490,7 +761,12 @@ export default {
490
761
  })
491
762
  }
492
763
  }
493
- } else if (this.searchForm[key].includes(',') && !specialMap[key]) {
764
+ } else if (
765
+ this.searchForm[key] &&
766
+ typeof this.searchForm[key] === 'string' &&
767
+ this.searchForm[key].includes(',') &&
768
+ !specialMap[key]
769
+ ) {
494
770
  let arr = this.searchForm[key].split(',')
495
771
  for (let i = 0; i < arr.length; i++) {
496
772
  if (
@@ -512,9 +788,20 @@ export default {
512
788
  })
513
789
  })
514
790
  } else {
791
+ let value = this.searchForm[key]
792
+ //在表单列表的查询字段中添加的对话框控件 此处逻辑对应 packages/CustomDialog/src/customDialog.vue:1920行
793
+ if (
794
+ this.bindValue &&
795
+ Object.keys(this.bindValue).length &&
796
+ this.bindValue[key] &&
797
+ Object.keys(this.bindKey).length
798
+ ) {
799
+ //获得绑定字段的值
800
+ value = this.bindValue[key][this.bindKey[key]]
801
+ }
515
802
  querys.push({
516
803
  property: key,
517
- value: this.searchForm[key],
804
+ value: value,
518
805
  group: 'main',
519
806
  operation: operationMap[key],
520
807
  relation: 'AND',
@@ -522,9 +809,10 @@ export default {
522
809
  }
523
810
  }
524
811
  }
525
- queryFilter = { pageBean: this.pagination, querys }
526
- params.pagination = queryFilter
527
- return params
812
+ if (this.$refs.queryViewList && this.$refs.queryViewList.querys) {
813
+ querys.push(...this.$refs.queryViewList.querys)
814
+ }
815
+ return { pageBean: this.pagination, querys }
528
816
  }
529
817
  },
530
818
  //获取查询条件类型
@@ -554,11 +842,19 @@ export default {
554
842
  ? operationType[operation]
555
843
  : operation
556
844
  } else if (
557
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
845
+ typeof $(searchItems[i])
846
+ .children()
847
+ .attr('ht-query') != 'undefined'
558
848
  ) {
559
849
  //查询条件类型
560
- operation = $(searchItems[i]).children().attr('operation')
561
- operationMap[$(searchItems[i]).children().attr('ht-query')] =
850
+ operation = $(searchItems[i])
851
+ .children()
852
+ .attr('operation')
853
+ operationMap[
854
+ $(searchItems[i])
855
+ .children()
856
+ .attr('ht-query')
857
+ ] =
562
858
  typeof operationType[operation] != 'undefined'
563
859
  ? operationType[operation]
564
860
  : operation
@@ -580,12 +876,16 @@ export default {
580
876
  searchItems[i]
581
877
  ).attr('field-query')
582
878
  } else if (
583
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
879
+ typeof $(searchItems[i])
880
+ .children()
881
+ .attr('ht-query') != 'undefined'
584
882
  ) {
585
883
  //查询条件字段
586
- fieldQueryMap[$(searchItems[i]).children().attr('ht-query')] = $(
587
- searchItems[i]
588
- )
884
+ fieldQueryMap[
885
+ $(searchItems[i])
886
+ .children()
887
+ .attr('ht-query')
888
+ ] = $(searchItems[i])
589
889
  .children()
590
890
  .attr('field-query')
591
891
  }
@@ -607,12 +907,19 @@ export default {
607
907
  ? true
608
908
  : false
609
909
  } else if (
610
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
910
+ typeof $(searchItems[i])
911
+ .children()
912
+ .attr('ht-query') != 'undefined'
611
913
  ) {
612
914
  //查询条件字段
613
- fieldQueryMap[$(searchItems[i]).children().attr('ht-query')] =
614
- typeof $(searchItems[i]).children().attr('special-query') !=
615
- 'undefined'
915
+ fieldQueryMap[
916
+ $(searchItems[i])
917
+ .children()
918
+ .attr('ht-query')
919
+ ] =
920
+ typeof $(searchItems[i])
921
+ .children()
922
+ .attr('special-query') != 'undefined'
616
923
  ? true
617
924
  : false
618
925
  }
@@ -766,6 +1073,14 @@ export default {
766
1073
  dataTemplateQueryVo.selectList = this.queryViewOptions.selectList
767
1074
  }
768
1075
  }
1076
+ // 查询字段 校验是否必填,如果是必填没数据,需返回提示
1077
+ let errorMsg = this.validateSearchRequired(
1078
+ dataTemplateQueryVo.queryFilter.querys
1079
+ )
1080
+ if (errorMsg) {
1081
+ this.$message.warning(errorMsg)
1082
+ return
1083
+ }
769
1084
 
770
1085
  let data = {
771
1086
  sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
@@ -778,15 +1093,22 @@ export default {
778
1093
  let loadingInstance = Loading.service({ fullscreen: true }) //开始
779
1094
  this.$requestConfig
780
1095
  .querySqlViewExport(data)
781
- .then(({ data, headers }) => {
782
- const fileName = decodeURIComponent(
783
- headers['content-disposition'].split(';')[1].split('filename=')[1]
784
- )
785
- const blob = new Blob([data])
786
- saveAs(blob, fileName)
1096
+ // .then(({ data, headers }) => {
1097
+ // const fileName = decodeURIComponent(
1098
+ // headers['content-disposition'].split(';')[1].split('filename=')[1]
1099
+ // )
1100
+ // const blob = new Blob([data])
1101
+ // saveAs(blob, fileName)
1102
+ // })
1103
+ // .finally(() => {
1104
+ // loadingInstance.close() // 结束
1105
+ // this.dialogExportVisible = false
1106
+ // })
1107
+ .then(() => {
1108
+ this.$message.success('正在导出,请稍后前往报表附件管理查看')
787
1109
  })
788
1110
  .finally(() => {
789
- loadingInstance.close() // 结束
1111
+ loadingInstance.close()
790
1112
  this.dialogExportVisible = false
791
1113
  })
792
1114
  },
@@ -1097,5 +1419,56 @@ export default {
1097
1419
  this.search()
1098
1420
  })
1099
1421
  },
1422
+ countPageTotal() {
1423
+ this.searchCountTotal(this.getQueryFilter())
1424
+ },
1425
+ searchCountTotal(param, cb, isSearchBtn, needRequestTotal = false) {
1426
+ // 不需要请求后端接口统计列表数据
1427
+ this.needRequestTotal = needRequestTotal
1428
+ !param && (param = {})
1429
+ param.pageBean = this.pagination
1430
+ const dataTemplateQueryVo = {
1431
+ queryFilter: param,
1432
+ }
1433
+ //保存查询参数,用于作为导出的查询参数
1434
+ if (this.queryViewOptions) {
1435
+ //关联查询字段
1436
+ if (
1437
+ this.queryViewOptions.selectList &&
1438
+ this.queryViewOptions.selectList.length > 0
1439
+ ) {
1440
+ dataTemplateQueryVo.selectList = this.queryViewOptions.selectList
1441
+ }
1442
+ }
1443
+ this.queryParam = { ...param }
1444
+ let obj = {
1445
+ sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
1446
+ alias: this.alias || this.queryView.alias,
1447
+ param: dataTemplateQueryVo,
1448
+ }
1449
+
1450
+ this.getQuerySqlViewByPaginationTotal(obj, cb)
1451
+ },
1452
+ switchPage(type) {
1453
+ if (type == 'prev') this.pagination.page--
1454
+ if (type == 'next') this.pagination.page++
1455
+ this.handleCurrentChange(this.pagination.page)
1456
+ },
1457
+ handleInput(value) {
1458
+ if (!value) {
1459
+ return
1460
+ }
1461
+ // 使用正则表达式匹配正整数
1462
+ const regex = /^[1-9]\d*$/
1463
+
1464
+ // 如果输入的值不符合正整数的模式,则将其重置为1
1465
+ if (!regex.test(value)) {
1466
+ //如果上一次输入的页数有值,则用上一次输入的页数,否则默认为1
1467
+ this.pagination.page = this.lastPage ? this.lastPage : 1
1468
+ } else {
1469
+ //本次分页数,赋值给上一次分页数
1470
+ this.lastPage = this.pagination.page
1471
+ }
1472
+ },
1100
1473
  },
1101
1474
  }