three-trees-ui 1.0.77 → 1.0.78

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,12 @@ 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
+ defaultQuerys: [],
15
+ isInit: true,
13
16
  bpmRunTime: this.$requestConfig.flowUrl,
14
17
  fileList: [],
15
18
  tableData: { selectRows: [], querys: '' },
@@ -77,6 +80,8 @@ export default {
77
80
  pageSize: 30,
78
81
  total: 0,
79
82
  },
83
+ lastPage: 1, //上一次输入的分页数、默认为1
84
+ total: 0,
80
85
  rows: [],
81
86
  queryParam: {},
82
87
  allSummaryConfig: {},
@@ -84,15 +89,54 @@ export default {
84
89
  summaryTableData: [],
85
90
  needRequestTotal: false, // 需不需要后端统计列表全部数据
86
91
  tableDataTotal: {},
92
+ loadingTotal: false, //统计按钮加载中
93
+ pageSizeArray: [
94
+ {
95
+ label: '10条/页',
96
+ value: 10,
97
+ },
98
+ {
99
+ label: '20条/页',
100
+ value: 20,
101
+ },
102
+ {
103
+ label: '30条/页',
104
+ value: 30,
105
+ },
106
+ {
107
+ label: '40条/页',
108
+ value: 40,
109
+ },
110
+ {
111
+ label: '50条/页',
112
+ value: 50,
113
+ },
114
+ {
115
+ label: '100条/页',
116
+ value: 100,
117
+ },
118
+ {
119
+ label: '200条/页',
120
+ value: 200,
121
+ },
122
+ {
123
+ label: '300条/页',
124
+ value: 300,
125
+ },
126
+ {
127
+ label: '500条/页',
128
+ value: 500,
129
+ },
130
+ ],
87
131
  }
88
132
  },
89
133
  watch: {
90
- formKey: function (newVal) {
134
+ formKey: function(newVal) {
91
135
  if (newVal) {
92
136
  this.init()
93
137
  }
94
138
  },
95
- 'tableData.selectRows': function (newVal) {
139
+ 'tableData.selectRows': function(newVal) {
96
140
  if (newVal.length > 0) {
97
141
  let me_ = this
98
142
  me_.uploadParams.id = []
@@ -160,7 +204,29 @@ export default {
160
204
  deep: true,
161
205
  },
162
206
  },
207
+ created() {
208
+ if (this.queryView.jsScript) {
209
+ // 执行js脚本
210
+ this.handleDiyScript(this.queryView.jsScript)
211
+ }
212
+ },
163
213
  methods: {
214
+ handleDiyScript(scriptValue) {
215
+ //执行前置脚本内容
216
+ const _this = this
217
+ // 用户信息
218
+ const account = this.$requestConfig.getAccount()
219
+ const userId = this.$requestConfig.getUserId()
220
+ const userName = this.$requestConfig.getUsername()
221
+ const preScript = `const scriptFunction = function(_this, account, userId, userName){
222
+ ${scriptValue}
223
+ };`
224
+ try {
225
+ eval(`${preScript}scriptFunction(_this, account, userId, userName);`)
226
+ } catch (err) {
227
+ this.$message.error(`脚本事件执行错误:${err}`)
228
+ }
229
+ },
164
230
  handelBindFiledValua() {
165
231
  //数据视图控件
166
232
  let _me = this
@@ -209,7 +275,7 @@ export default {
209
275
  selectList[i].selectValue = value
210
276
 
211
277
  //添加监听
212
- pInst.$watch(path, function (newVal, oldVal) {
278
+ pInst.$watch(path, function(newVal, oldVal) {
213
279
  _.debounce(() => {
214
280
  if (newVal !== oldVal) {
215
281
  _me.queryViewOptions.selectList[i].selectValue = newVal
@@ -353,7 +419,7 @@ export default {
353
419
  this.$router.push(url)
354
420
  },
355
421
 
356
- handleSizeChange: function (size) {
422
+ handleSizeChange: function(size) {
357
423
  //每页下拉显示数据
358
424
  this.pagination.pageSize = size
359
425
  if (this.$refs.queryViewList) {
@@ -362,9 +428,9 @@ export default {
362
428
  this.search()
363
429
  }
364
430
  },
365
- handleCurrentChange: function (currentPage) {
431
+ handleCurrentChange: function(currentPage) {
366
432
  //点击第几页
367
- this.pagination.page = currentPage
433
+ this.pagination.page = currentPage ? currentPage : this.lastPage
368
434
  if (this.$refs.queryViewList) {
369
435
  this.$refs.queryViewList.load()
370
436
  } else {
@@ -372,14 +438,126 @@ export default {
372
438
  }
373
439
  },
374
440
  //回车查询
375
- searchEnterFun: function (e) {
441
+ searchEnterFun: function(e) {
376
442
  let keyCode = window.event ? e.keyCode : e.which
377
443
  if (keyCode == 13) {
378
444
  this.pagination.page = 1
379
445
  this.search()
380
446
  }
381
447
  },
382
- search(param, cb, isSearchBtn, needRequestTotal = false) {
448
+ getQueryDataViewOperation(key) {
449
+ switch (key) {
450
+ case 'EQ':
451
+ return 'EQUAL'
452
+ case 'NE':
453
+ return 'NOT_EQUAL'
454
+ case 'LK':
455
+ return 'LIKE'
456
+ case 'LFK':
457
+ return 'LEFT_LIKE'
458
+ case 'RHK':
459
+ return 'RIGHT_LIKE'
460
+ case 'BETWEEN':
461
+ return 'BETWEEN'
462
+ default:
463
+ return 'LIKE'
464
+ }
465
+ },
466
+ async buildDefaultQuerys() {
467
+ let querys = []
468
+ let conditions = JSON.parse(this.queryView.conditions)
469
+ //条件字段默认值判断
470
+ for (let i = 0; i < conditions.length; i++) {
471
+ let condition = conditions[i]
472
+ if (condition.defaultValue) {
473
+ let defaultValue = condition.isScriptDefault
474
+ ? await this.getScriptDefaultValue(condition.defaultValue)
475
+ : condition.defaultValue
476
+ if (condition.dataType == 'number') {
477
+ defaultValue = parseFloat(defaultValue)
478
+ }
479
+ this.$set(this.searchForm, condition.fieldName, defaultValue)
480
+
481
+ querys.push({
482
+ property: condition.fieldName,
483
+ value: defaultValue,
484
+ group: 'main',
485
+ operation: this.getQueryDataViewOperation(condition.operate),
486
+ relation: 'AND',
487
+ })
488
+ }
489
+ }
490
+ this.defaultQuerys = querys
491
+ return querys
492
+ },
493
+ getScriptDefaultValue(scriptValue) {
494
+ return new Promise((resolve) => {
495
+ //执行前置脚本内容
496
+ const _this = this
497
+ // 用户信息
498
+ const account = this.$requestConfig.getAccount()
499
+ const userId = this.$requestConfig.getUserId()
500
+ const userName = this.$requestConfig.getUsername()
501
+ const _moment = moment
502
+ const preScript = `const scriptFunction = function(_this, account, userId, userName, _moment){
503
+ ${scriptValue}
504
+ };`
505
+ let result = ''
506
+ try {
507
+ result = eval(
508
+ `${preScript}scriptFunction(_this, account, userId, userName, _moment);`
509
+ )
510
+ if (result && result.then && typeof result.then === 'function') {
511
+ result.then(
512
+ (t) => {
513
+ resolve(t)
514
+ },
515
+ (fail) => {
516
+ //接口返回失败则终止按钮操作,并输出错误信息
517
+ resolve('')
518
+ }
519
+ )
520
+ } else {
521
+ resolve(result)
522
+ }
523
+ } catch (err) {
524
+ resolve('')
525
+ this.$message.error(`查询值默认脚本事件执行错误:${err}`)
526
+ }
527
+ })
528
+ },
529
+ validateSearchRequired(querys = []) {
530
+ let errorMsg = ''
531
+ let conditions = JSON.parse(this.queryView.conditions)
532
+ if (conditions && querys) {
533
+ conditions.forEach((item) => {
534
+ if (item.isRequired) {
535
+ let index = querys.findIndex((k) => {
536
+ return k.property == item.fieldName
537
+ })
538
+ if (index == -1) {
539
+ errorMsg = `字段【${item.fieldDesc}】为必填查询字段,不能为空!`
540
+ }
541
+ }
542
+ })
543
+ }
544
+ return errorMsg
545
+ },
546
+ checkHaveRequired() {
547
+ let haveRequired = false
548
+ try {
549
+ let conditions = JSON.parse(this.queryView.conditions)
550
+ if (conditions) {
551
+ haveRequired = conditions.some((item) => {
552
+ return item.isRequired
553
+ })
554
+ }
555
+ } catch (e) {
556
+ console.log(e)
557
+ }
558
+ return haveRequired
559
+ },
560
+ async search(param, cb, isSearchBtn, needRequestTotal = false) {
383
561
  // 不需要请求后端接口统计列表数据
384
562
  this.needRequestTotal = needRequestTotal
385
563
  !param && (param = {})
@@ -387,6 +565,38 @@ export default {
387
565
  const dataTemplateQueryVo = {
388
566
  queryFilter: param,
389
567
  }
568
+ //初始化时,把查询字段的默认值加进去
569
+ if (this.isInit) {
570
+ let querys = await this.buildDefaultQuerys()
571
+ dataTemplateQueryVo.queryFilter.querys =
572
+ dataTemplateQueryVo.queryFilter.querys || []
573
+ dataTemplateQueryVo.queryFilter.querys = dataTemplateQueryVo.queryFilter.querys.concat(
574
+ querys
575
+ )
576
+ }
577
+ // 非高级查询时,将默认值带上
578
+ if (!isSearchBtn) {
579
+ dataTemplateQueryVo.queryFilter.querys =
580
+ dataTemplateQueryVo.queryFilter.querys || []
581
+ dataTemplateQueryVo.queryFilter.querys = dataTemplateQueryVo.queryFilter.querys.concat(
582
+ this.defaultQuerys
583
+ )
584
+ }
585
+ // 检查是否有必填字段
586
+ if (this.checkHaveRequired() && this.isInit) {
587
+ this.$refs.queryViewList.showAdvancedSearch = true
588
+ }
589
+ // 查询字段 校验是否必填,如果是必填没数据,需返回提示
590
+ let errorMsg = this.validateSearchRequired(
591
+ dataTemplateQueryVo.queryFilter.querys
592
+ )
593
+ if (errorMsg) {
594
+ !this.isInit && this.$message.warning(errorMsg)
595
+ cb && cb()
596
+ this.isInit = false
597
+ return
598
+ }
599
+ this.isInit = false
390
600
  //保存查询参数,用于作为导出的查询参数
391
601
  if (this.queryViewOptions) {
392
602
  //关联查询字段
@@ -419,13 +629,17 @@ export default {
419
629
  })
420
630
  }
421
631
  this.$requestConfig
422
- .getQueryViewDataList(param)
632
+ .getQueryViewDataListWithoutTotal(param)
423
633
  .then((response) => {
424
634
  this.rows = response.rows
425
- this.pagination.total = response.total
635
+ // this.pagination.total = response.total
426
636
  this.pagination.page = response.page
427
637
  this.pagination.pageSize = response.pageSize
428
638
  this.filterOldSummaryValByType('currentPage')
639
+ //每次请求后不再统计总数,而是在统计按钮中去统计,当数量统计过一次后,再重新设置到当前页
640
+ if (this.total) {
641
+ this.$set(this.pagination, 'total', this.total)
642
+ }
429
643
  this.summaryTableData.push({
430
644
  project: '当前页汇总',
431
645
  key: 'currentPage',
@@ -445,12 +659,31 @@ export default {
445
659
  cb && cb()
446
660
  })
447
661
  },
662
+ getQuerySqlViewByPaginationTotal(param, cb) {
663
+ this.loadingTotal = true
664
+ this.$requestConfig
665
+ .getQueryViewDataListWithTotal(param)
666
+ .then((response) => {
667
+ this.total = response.value
668
+ //每次请求后不再统计总数,而是在统计按钮中去统计,当数量统计过一次后,再重新设置到当前页
669
+ if (this.total) {
670
+ this.$set(this.pagination, 'total', this.total)
671
+ }
672
+ this.loadingTotal = false
673
+ this.$nextTick(() => {
674
+ this.$refs.queryViewList && this.$refs.queryViewList.doLayout()
675
+ })
676
+ })
677
+ .finally(() => {
678
+ this.loadingTotal = false
679
+ cb && cb()
680
+ })
681
+ },
448
682
  getQueryFilter() {
449
683
  let operationMap = this.getSearchItems() //查询条件类型
450
684
  // let fieldQueryMap = this.getFieldQuery() //查询条件字段
451
685
  let specialMap = this.getSpecialMap() //获取特殊查询情况(自定义对话框)
452
686
  let querys = [] //查询条件
453
- let queryFilter = {}
454
687
  let pageBean = { pageBean: this.pagination }
455
688
  let params = {
456
689
  sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
@@ -458,6 +691,10 @@ export default {
458
691
  }
459
692
  params.pagination = pageBean
460
693
  if ($.isEmptyObject(this.searchForm)) {
694
+ if (this.$refs.queryViewList && this.$refs.queryViewList.querys) {
695
+ querys.push(...this.$refs.queryViewList.querys)
696
+ }
697
+ params = { pageBean: this.pagination, querys }
461
698
  return params
462
699
  } else {
463
700
  for (var key in this.searchForm) {
@@ -522,9 +759,10 @@ export default {
522
759
  }
523
760
  }
524
761
  }
525
- queryFilter = { pageBean: this.pagination, querys }
526
- params.pagination = queryFilter
527
- return params
762
+ if (this.$refs.queryViewList && this.$refs.queryViewList.querys) {
763
+ querys.push(...this.$refs.queryViewList.querys)
764
+ }
765
+ return { pageBean: this.pagination, querys }
528
766
  }
529
767
  },
530
768
  //获取查询条件类型
@@ -554,11 +792,19 @@ export default {
554
792
  ? operationType[operation]
555
793
  : operation
556
794
  } else if (
557
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
795
+ typeof $(searchItems[i])
796
+ .children()
797
+ .attr('ht-query') != 'undefined'
558
798
  ) {
559
799
  //查询条件类型
560
- operation = $(searchItems[i]).children().attr('operation')
561
- operationMap[$(searchItems[i]).children().attr('ht-query')] =
800
+ operation = $(searchItems[i])
801
+ .children()
802
+ .attr('operation')
803
+ operationMap[
804
+ $(searchItems[i])
805
+ .children()
806
+ .attr('ht-query')
807
+ ] =
562
808
  typeof operationType[operation] != 'undefined'
563
809
  ? operationType[operation]
564
810
  : operation
@@ -580,12 +826,16 @@ export default {
580
826
  searchItems[i]
581
827
  ).attr('field-query')
582
828
  } else if (
583
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
829
+ typeof $(searchItems[i])
830
+ .children()
831
+ .attr('ht-query') != 'undefined'
584
832
  ) {
585
833
  //查询条件字段
586
- fieldQueryMap[$(searchItems[i]).children().attr('ht-query')] = $(
587
- searchItems[i]
588
- )
834
+ fieldQueryMap[
835
+ $(searchItems[i])
836
+ .children()
837
+ .attr('ht-query')
838
+ ] = $(searchItems[i])
589
839
  .children()
590
840
  .attr('field-query')
591
841
  }
@@ -607,12 +857,19 @@ export default {
607
857
  ? true
608
858
  : false
609
859
  } else if (
610
- typeof $(searchItems[i]).children().attr('ht-query') != 'undefined'
860
+ typeof $(searchItems[i])
861
+ .children()
862
+ .attr('ht-query') != 'undefined'
611
863
  ) {
612
864
  //查询条件字段
613
- fieldQueryMap[$(searchItems[i]).children().attr('ht-query')] =
614
- typeof $(searchItems[i]).children().attr('special-query') !=
615
- 'undefined'
865
+ fieldQueryMap[
866
+ $(searchItems[i])
867
+ .children()
868
+ .attr('ht-query')
869
+ ] =
870
+ typeof $(searchItems[i])
871
+ .children()
872
+ .attr('special-query') != 'undefined'
616
873
  ? true
617
874
  : false
618
875
  }
@@ -766,6 +1023,14 @@ export default {
766
1023
  dataTemplateQueryVo.selectList = this.queryViewOptions.selectList
767
1024
  }
768
1025
  }
1026
+ // 查询字段 校验是否必填,如果是必填没数据,需返回提示
1027
+ let errorMsg = this.validateSearchRequired(
1028
+ dataTemplateQueryVo.queryFilter.querys
1029
+ )
1030
+ if (errorMsg) {
1031
+ this.$message.warning(errorMsg)
1032
+ return
1033
+ }
769
1034
 
770
1035
  let data = {
771
1036
  sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
@@ -778,15 +1043,22 @@ export default {
778
1043
  let loadingInstance = Loading.service({ fullscreen: true }) //开始
779
1044
  this.$requestConfig
780
1045
  .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)
1046
+ // .then(({ data, headers }) => {
1047
+ // const fileName = decodeURIComponent(
1048
+ // headers['content-disposition'].split(';')[1].split('filename=')[1]
1049
+ // )
1050
+ // const blob = new Blob([data])
1051
+ // saveAs(blob, fileName)
1052
+ // })
1053
+ // .finally(() => {
1054
+ // loadingInstance.close() // 结束
1055
+ // this.dialogExportVisible = false
1056
+ // })
1057
+ .then(() => {
1058
+ this.$message.success('正在导出,请稍后前往报表附件管理查看')
787
1059
  })
788
1060
  .finally(() => {
789
- loadingInstance.close() // 结束
1061
+ loadingInstance.close()
790
1062
  this.dialogExportVisible = false
791
1063
  })
792
1064
  },
@@ -1097,5 +1369,55 @@ export default {
1097
1369
  this.search()
1098
1370
  })
1099
1371
  },
1372
+ countPageTotal() {
1373
+ this.searchCountTotal(this.getQueryFilter())
1374
+ },
1375
+ searchCountTotal(param, cb, isSearchBtn, needRequestTotal = false) {
1376
+ // 不需要请求后端接口统计列表数据
1377
+ this.needRequestTotal = needRequestTotal
1378
+ !param && (param = {})
1379
+ param.pageBean = this.pagination
1380
+ const dataTemplateQueryVo = {
1381
+ queryFilter: param,
1382
+ }
1383
+ //保存查询参数,用于作为导出的查询参数
1384
+ if (this.queryViewOptions) {
1385
+ //关联查询字段
1386
+ if (
1387
+ this.queryViewOptions.selectList &&
1388
+ this.queryViewOptions.selectList.length > 0
1389
+ ) {
1390
+ dataTemplateQueryVo.selectList = this.queryViewOptions.selectList
1391
+ }
1392
+ }
1393
+ this.queryParam = { ...param }
1394
+ let obj = {
1395
+ sqlAlias: this.sqlAlias || this.queryView.sqlAlias,
1396
+ alias: this.alias || this.queryView.alias,
1397
+ param: dataTemplateQueryVo,
1398
+ }
1399
+ this.getQuerySqlViewByPaginationTotal(obj, cb)
1400
+ },
1401
+ switchPage(type) {
1402
+ if (type == 'prev') this.pagination.page--
1403
+ if (type == 'next') this.pagination.page++
1404
+ this.handleCurrentChange(this.pagination.page)
1405
+ },
1406
+ handleInput(value) {
1407
+ if (!value) {
1408
+ return
1409
+ }
1410
+ // 使用正则表达式匹配正整数
1411
+ const regex = /^[1-9]\d*$/
1412
+
1413
+ // 如果输入的值不符合正整数的模式,则将其重置为1
1414
+ if (!regex.test(value)) {
1415
+ //如果上一次输入的页数有值,则用上一次输入的页数,否则默认为1
1416
+ this.pagination.page = this.lastPage ? this.lastPage : 1
1417
+ } else {
1418
+ //本次分页数,赋值给上一次分页数
1419
+ this.lastPage = this.pagination.page
1420
+ }
1421
+ },
1100
1422
  },
1101
1423
  }