vue2-client 1.14.48 → 1.14.50

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.
@@ -1,1410 +1,1553 @@
1
- <template>
2
- <div v-show="tableColumns.length > 0">
3
- <a-row :gutter="48">
4
- <a-col v-show="showLeftOperaBtn">
5
- <span :style="{ float: 'left', marginBottom: '8px' }">
6
- <a-space>
7
- <!-- <a-button v-if="eventState.customDelete" type="primary" @click="custom('customDelete')">-->
8
- <!-- <a-icon type="delete"/>删除-->
9
- <!-- </a-button>-->
10
- <!-- <a-button v-if="eventState.customSave" type="primary" @click="custom('customSave')">-->
11
- <!-- <a-icon type="save"/>保存-->
12
- <!-- </a-button>-->
13
- <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
14
- <a-button v-if="buttonState.add && buttonRendering('add')" type="primary" @click="add">
15
- <a-icon type="plus"/>新增
16
- </a-button>
17
- <a-button v-if="buttonState.move && buttonRendering('move')" type="primary" @click="move">
18
- <a-icon type="plus"/>添加
19
- </a-button>
20
- <a-button
21
- v-if="buttonState.choose && buttonRendering('choose')"
22
- :disabled="!isChoose"
23
- type="primary"
24
- @click="choose">
25
- <a-icon type="check-square"/>选择
26
- </a-button>
27
- <a-button
28
- v-if="buttonState.edit && buttonRendering('edit')"
29
- :disabled="!isModify"
30
- :loading="editLoading"
31
- class="btn-success"
32
- type="dashed"
33
- @click="edit()">
34
- <a-icon :style="iconStyle" type="form"/>修改
35
- </a-button>
36
- <template
37
- v-if="buttonState.editRow && buttonRendering('editRow')">
38
- <a-button
39
- v-if="isEditMode"
40
- class="ant-btn-hover"
41
- @click="editRowSave">
42
- <a-icon :style="iconStyle" type="save"/>保存
43
- </a-button>
44
- <a-button
45
- v-else
46
- @click="openEditMode">
47
- <a-icon :style="iconStyle" type="edit"/>行编辑
48
- </a-button>
49
- </template>
50
- <a-button
51
- v-if="buttonState.delete && buttonRendering('delete')"
52
- :disabled="!isDelete"
53
- type="danger"
54
- @click="deleteItem">
55
- <a-icon :style="iconStyle" type="delete"/>删除
56
- </a-button>
57
- <a-button
58
- v-if="buttonState.import && buttonRendering('import')"
59
- type="dashed"
60
- @click="importData">
61
- <a-icon :style="iconStyle" type="import"/>导入
62
- </a-button>
63
- <a-dropdown v-if="!buttonState || buttonState.export && buttonRendering('export')">
64
- <a-menu slot="overlay">
65
- <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport('selected')"><a-icon
66
- :style="iconStyle"
67
- type="ordered-list"/>导出选中数据</a-menu-item>
68
- <a-menu-item key="2" @click="handleExport('curPage')"><a-icon :style="iconStyle" type="snippets"/>导出本页数据</a-menu-item>
69
- <a-menu-item key="3" @click="handleExport('exportByQuery')"><a-icon :style="iconStyle" type="download"/>导出所有符合条件的数据</a-menu-item>
70
- </a-menu>
71
- <a-button>导出 <a-icon type="down" :style="iconStyle"/> </a-button>
72
- </a-dropdown>
73
- <a-dropdown v-if="!buttonState || buttonState.print && buttonRendering('print')">
74
- <a-menu slot="overlay">
75
- <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handlePrint('selected')"><a-icon
76
- :style="iconStyle"
77
- type="ordered-list"/>打印选中数据</a-menu-item>
78
- <a-menu-item key="2" @click="handlePrint('curPage')"><a-icon :style="iconStyle" type="snippets"/>打印本页数据</a-menu-item>
79
- <a-menu-item key="3" @click="handlePrint('exportByQuery')"><a-icon :style="iconStyle" type="download"/>打印所有符合条件的数据</a-menu-item>
80
- </a-menu>
81
- <a-button>打印 <a-icon type="printer" :style="iconStyle"/> </a-button>
82
- </a-dropdown>
83
- <!-- 遍历按钮配置数组,动态生成按钮 -->
84
- <a-button
85
- v-for="(button, index) in editButtonStateData"
86
- :key="index"
87
- :type="button.type || 'dashed'"
88
- @click="editButtonStateDataClick(index)"
89
- class="btn-success"
90
- >
91
- <a-icon type="dashed" :style="iconStyle"/>
92
- {{ button.buttonName }}
93
- </a-button>
94
- <a-button
95
- v-if="allowedCardMode && !simpleMode"
96
- @click="changeViewMode"
97
- :type="isTableMode ? '' : 'primary'">
98
- 看板模式
99
- </a-button>
100
- <a-badge
101
- v-if="selectRowMode === 'listView'"
102
- :count="selectedRows.length"
103
- :number-style="{ backgroundColor:theme.color }"
104
- >
105
- <a-button
106
- type="dashed"
107
- @click="showTempData">
108
- <a-icon :style="iconStyle" type="monitor"/>已选择
109
- </a-button>
110
- </a-badge>
111
- <!-- 头部附加栅格 -->
112
- <x-report
113
- v-if="attachGrid"
114
- :env="env"
115
- :isWidget="true"
116
- :use-oss-for-img="false"
117
- :config-name="attachGrid"
118
- :show-img-in-cell="true"
119
- :display-only="true"
120
- :edit-mode="false"
121
- :show-save-button="false"
122
- :dont-format="true"/>
123
-
124
- <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
125
- </a-space>
126
-
127
- </span>
128
- </a-col>
129
- <a-col v-show="showRightTools && !simpleMode">
130
- <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
131
- <a-button-group>
132
- <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
133
- <a-tooltip title="汇总" placement="bottom">
134
- <a-button @click="showDrawer">
135
- <a-icon :style="iconStyle" type="project"/>
136
- </a-button>
137
- </a-tooltip>
138
- <a-tooltip title="重新查询" placement="bottom">
139
- <a-button @click="refresh(true)">
140
- <a-icon :style="iconStyle" type="reload"/>
141
- </a-button>
142
- </a-tooltip>
143
- <a-tooltip title="列展示/排序" placement="bottom">
144
- <table-setting v-if="columnSelectLoaded" v-model="tableColumns"/>
145
- </a-tooltip>
146
- </a-button-group>
147
- </span>
148
- </a-col>
149
- </a-row>
150
- <!-- 如果当前是表格模式 -->
151
- <template v-if="isTableMode">
152
- <x-table-wrapper
153
- ref="table"
154
- @rowClick="handleRowClick"
155
- @beforeDataChange="beforeDataChange"
156
- @expand="onExpand">
157
- <template slot="expandedRowRender">
158
- <!-- 列扩展栅格 -->
159
- <x-report
160
- v-if="expandedGrid"
161
- :env="env"
162
- ref="report"
163
- :isWidget="true"
164
- :use-oss-for-img="false"
165
- :config-name="expandedGrid"
166
- :show-img-in-cell="true"
167
- :display-only="true"
168
- :edit-mode="false"
169
- :show-save-button="false"
170
- :dont-format="true"/>
171
- </template>
172
- <template slot="footer">
173
- <slot
174
- name="footer"
175
- :selectedRowKeys="selectedRowKeys"
176
- :selectedRows="selectedRows"></slot>
177
- </template>
178
- </x-table-wrapper>
179
- </template>
180
- <!-- 如果当前是看板模式 -->
181
- <template v-else>
182
- <XDataCard
183
- ref="table"
184
- @cardEmit="handleCardEmit"
185
- :tableColumns="tableColumns"
186
- :card-config="cardModeConfig"
187
- :show-pagination="!simpleMode"
188
- :prePageSize="simpleMode ? 1000 : undefined"
189
- :serviceName="serviceName"
190
- :card-data="loadData"
191
- :env="env"
192
- :createdQuery="createdQuery"
193
- :simple-mode="simpleMode"/>
194
- </template>
195
- <!-- 上传文件 -->
196
- <a-drawer
197
- title="汇总信息"
198
- placement="right"
199
- :closable="false"
200
- :visible="summaryDrawerVisible"
201
- :z-index="2000"
202
- :width="`${summaryDrawerWidth}vw`"
203
- :after-visible-change="afterVisibleChange"
204
- @close="onClose"
205
- >
206
- <template>
207
- <a-row>
208
- <a-col :span="8" v-for="(f,index) in summaryData" :key="index">
209
- <a-statistic
210
- :title="f.title + ':'"
211
- :value="f.value"
212
- :precision="2">
213
- <template #prefix>
214
- <a-spin :spinning="f.loading">
215
- </a-spin>
216
- </template>
217
- <template #suffix>
218
- <a-icon
219
- v-show="!f.loading"
220
- :type="f.success !== false ? 'check-circle' : 'close-circle'"
221
- :style="{color: f.success !== false ? 'green' : 'red'}"/>
222
- </template>
223
- </a-statistic>
224
- </a-col>
225
- <a-col
226
- :span="item.span"
227
- v-for="(item,index) in chartsConfigArray"
228
- :key="index"
229
- style="height: 20rem; margin-bottom: 3rem">
230
- <div class="custom-chart-title" v-if="item.config.title">{{ item.config.title }}</div>
231
- <div class="custom-chart-desc" v-if="item.config.description">{{ item.config.description }}</div>
232
- <g2Charts
233
- :key="index"
234
- :chatsKey="index"
235
- :is-dev="env === 'dev'"
236
- :config="item.config"
237
- :requestParameters="requestParameters"/>
238
- </a-col>
239
- </a-row>
240
- </template>
241
- </a-drawer>
242
- <x-import-excel
243
- ref="importExcel"
244
- @ok="importExcelOk"
245
- :title="title"
246
- :service-name="serviceName"
247
- :env="env"
248
- :query-params-name="queryParamsName"
249
- >
250
- <template #importExcelSlot>
251
- <slot name="importExcelSlot"></slot>
252
- </template>
253
- </x-import-excel>
254
- <ExportExcel
255
- ref="exportExcel"
256
- />
257
- <a-modal @cancel="$refs.table.refresh()" v-model="selectedRowModalVisible" width="80vw" title="已选中数据" :footer="null">
258
- <x-table-wrapper
259
- ref="selectedDataTable"
260
- :load-selected-data="true"
261
- @beforeDataChange="beforeDataChange"
262
- @rowClick="handleRowClick">
263
- </x-table-wrapper>
264
- </a-modal>
265
- </div>
266
- </template>
267
- <script>
268
- import { STable } from '@vue2-client/components'
269
- import { getChangedData, setDataByRealKey } from '@vue2-client/utils/util'
270
- import * as util from '@vue2-client/utils/util'
271
- import TableSetting from '@vue2-client/components/TableSetting/TableSetting'
272
- import {
273
- query,
274
- querySummary,
275
- queryWithResource,
276
- remove,
277
- getConfigByNameAsync,
278
- editRowSave,
279
- runLogic
280
- } from '@vue2-client/services/api/common'
281
- import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
282
- import { Modal } from 'ant-design-vue'
283
- import { mapState } from 'vuex'
284
- import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
285
- import debounce from 'lodash.debounce'
286
- import XDataCard from '@vue2-client/base-client/components/common/XDataCard/XDataCard.vue'
287
- import { getRealKeyData } from '@vue2-client/utils/formatter'
288
- import ReportTableHome from '../../../../pages/report/ReportTableHome.vue'
289
- import CustomFuncCel from '@vue2-client/base-client/components/common/XTable/CustomFuncCel.vue'
290
- import ExportExcel from '@vue2-client/base-client/components/common/XTable/ExportExcel.vue'
291
- import g2Charts from '@vue2-client/components/g2Charts/index.vue'
292
- import moment from 'moment/moment'
293
- import XTableWrapper from './XTableWrapper.vue'
294
-
295
- export default {
296
- name: 'XTable',
297
- components: {
298
- ExportExcel,
299
- CustomFuncCel,
300
- XDataCard,
301
- TableSetting,
302
- STable,
303
- XImportExcel,
304
- g2Charts,
305
- XReport: () => import('@vue2-client/base-client/components/common/XReportGrid/XReport.vue'),
306
- ReportTableHome,
307
- XTableWrapper
308
- },
309
- inject: ['getSelf'],
310
- provide () {
311
- return {
312
- tableContext: this
313
- }
314
- },
315
- data () {
316
- return {
317
- uniqueId: `x-table-${this._uid}`, // 使用 _uid 生成唯一 ID
318
- // 筛选列加载状态
319
- columnSelectLoaded: false,
320
- // 预览模式
321
- viewMode: false,
322
- // 本地编辑模式
323
- localEditMode: false,
324
- // 本地编辑表单提交方式
325
- formSubmitTypeInLocalEditMode: 'cover',
326
- // 本地编辑模式所用数据源
327
- localEditModeDataSource: [],
328
- // 本地编辑模式数据源是否已由外部加载
329
- isLocalDataSourceLoadedExternally: false,
330
- // 行选择模式
331
- rowSelectMode: false,
332
- // 行选择模式-允许选中行数量,0:任意数量行,大于0:指定值数量的行
333
- allowSelectRowNum: 0,
334
- // 头部附件的栅格配置名
335
- attachGrid: '',
336
- // 表格行扩展区域的栅格配置名
337
- expandedGrid: '',
338
- // 是否展示右侧工具栏
339
- showRightTools: true,
340
- // 是否展示左边按钮栏
341
- showLeftOperaBtn: true,
342
- // 加载数据方法 必须为 Promise 对象
343
- loadData: parameter => {
344
- // 取到表格携带的表单参数
345
- const requestParameters = Object.assign({}, parameter)
346
- // 取到父组件传入的表单参数
347
- const conditionParams = {}
348
- Object.assign(conditionParams, this.fixedQueryForm)
349
- Object.assign(conditionParams, this.form)
350
- // 如果传了燃气公司字段,则进行数据处理
351
- if (conditionParams.orgName) {
352
- requestParameters.orgName = conditionParams.orgName
353
- delete conditionParams.orgName
354
- }
355
- Object.keys(conditionParams).forEach(key => {
356
- if (Array.isArray(conditionParams[key])) {
357
- // 检查数组中是否包含 null
358
- const hasNull = conditionParams[key].every(item => item === '') || conditionParams[key].length === 0
359
- // 如果包含 null,则删除该属性
360
- if (hasNull) {
361
- delete conditionParams[key]
362
- }
363
- }
364
- })
365
- requestParameters.conditionParams = conditionParams
366
- requestParameters.queryParamsName = this.queryParamsName
367
- requestParameters.queryParams = this.queryParams && Object.keys(this.queryParams).length > 0 ? this.queryParams : undefined
368
- this.requestParameters = requestParameters
369
- // 加载数据
370
- return this.loadTableData(requestParameters)
371
- },
372
- requestParameters: {},
373
- rowKey: undefined,
374
- // x滚动条宽度
375
- scrollXWidth: 1600,
376
- // y滚动条高度
377
- scrollYHeight: 'calc(100vh - 31rem)',
378
- // 表格选择列Key集合
379
- selectedRowKeys: [],
380
- // 表格选择Row集合
381
- selectedRows: [],
382
- // 表格选择列Key集合
383
- innerSelectedRowKeys: [],
384
- // 表格选择Row集合
385
- innerSelectedRows: [],
386
- // 禁止表格选择Row集合
387
- selectedDisableRows: [],
388
- // 业务标题
389
- title: '',
390
- // 数据列
391
- tableColumns: [],
392
- // 查询用表单
393
- form: {},
394
- oldForm: {},
395
- // 是否允许修改
396
- isModify: false,
397
- // 是否允许删除
398
- isDelete: false,
399
- // 是否允许选择
400
- isChoose: false,
401
- // 选中用于修改的id
402
- selectId: undefined,
403
- // 是否显示展示列抽屉
404
- visible: false,
405
- // 编辑按钮加载状态
406
- editLoading: false,
407
- // 按钮状态
408
- buttonState: {},
409
- // eventBtnState
410
- eventState: {},
411
- // 自定义按钮数组
412
- editButtonStateData: [],
413
- // 按钮权限
414
- buttonPermissions: [],
415
- // 是否展示汇总
416
- showSummary: false,
417
- // 自定义汇总
418
- showCustomSummary: false,
419
- summaryData: [],
420
- // 图标样式
421
- iconStyle: {
422
- position: 'relative',
423
- top: '1px'
424
- },
425
- // 当前环境
426
- env: 'prod',
427
- // 预览模式(表格 or 看板)
428
- isTableMode: true,
429
- // 汇总抽屉是否显示
430
- summaryDrawerVisible: false,
431
- // 汇总更新标志
432
- summaryUpdate: false,
433
- customSummaryArray: [],
434
- formItems: [],
435
- // 是否为行编辑模式
436
- isEditMode: false,
437
- // 定义主键
438
- primaryKey: '',
439
- // 是否进行初始化查询
440
- createdQuery: false,
441
- // 允许看板模式
442
- allowedCardMode: false,
443
- // 看板模式配置
444
- cardModeConfig: undefined,
445
- // 暂存行编辑前数据 用于比较哪些变化了才需要保存
446
- editRowBeforeData: [],
447
- // 是否简易模式
448
- simpleMode: false,
449
- // crud打印模板配置
450
- printTemplate: false,
451
- queryParams: {},
452
- // 定义总行数
453
- totalCount: 0,
454
- user: {},
455
- chartsConfigArray: [],
456
- summaryDrawerWidth: 35,
457
- // 行选择模式
458
- selectRowMode: 'default',
459
- tableSize: 'default',
460
- clearSelectRowAfterQuery: false,
461
- selectedRowModalVisible: false
462
- }
463
- },
464
- props: {
465
- // 查询配置文件名
466
- queryParamsName: {
467
- type: String,
468
- default: () => {
469
- return ''
470
- }
471
- },
472
- // 查询配置文件名
473
- serviceName: {
474
- type: String,
475
- default: () => {
476
- return ''
477
- }
478
- },
479
- // 查询配置文件Json
480
- queryParamsJson: {
481
- type: Object,
482
- default: null
483
- },
484
- // 固定查询表单
485
- fixedQueryForm: {
486
- type: Object,
487
- default: () => {
488
- return {}
489
- }
490
- },
491
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
492
- showPagination: {
493
- type: Boolean,
494
- default: true
495
- },
496
- // 是否自定义删除功能
497
- customDelete: {
498
- type: Boolean,
499
- default: false
500
- },
501
- // 自适应底部边距
502
- extraHeight: {
503
- type: Number,
504
- default: 80
505
- },
506
- pageMaxSize: {
507
- type: Number,
508
- default: null
509
- }
510
- },
511
- computed: {
512
- ...mapState('setting', ['theme']),
513
- rowSelection () {
514
- return this.selectRowMode === 'disabled' ? undefined : {
515
- selectedRowKeys: this.innerSelectedRowKeys,
516
- onChange: this.onSelectChange,
517
- onSelect: this.selectRowMode === 'listView' ? this.onSelect : undefined,
518
- onSelectAll: this.selectRowMode === 'listView' ? this.onSelectAll : undefined,
519
- getCheckboxProps: record => ({
520
- props: {
521
- disabled: this.selectedDisableRows.includes(record[this.rowKey]), // Column configuration not to be checked
522
- name: record.name,
523
- },
524
- }),
525
- }
526
- },
527
- ...mapState('account', { currUser: 'user' }),
528
- ...mapState('setting', ['compatible'])
529
- },
530
- watch: {
531
- pageMaxSize: {
532
- handler (val) {
533
- this.tableContext.pageMaxSize = val
534
- },
535
- immediate: true
536
- }
537
- },
538
- mounted () {
539
- window.addEventListener('resize', this.handleResize)
540
- },
541
- beforeDestroy () {
542
- // 销毁页面查询定时器
543
- if (this.queryTimer) {
544
- clearInterval(this.queryTimer)
545
- }
546
- window.removeEventListener('resize', this.handleResize)
547
- },
548
- methods: {
549
- showTempData () {
550
- this.selectedRowModalVisible = true
551
- this.$nextTick(() => {
552
- this.$refs.selectedDataTable.refresh(true)
553
- this.$refs.selectedDataTable.updateSelect(this.selectedRowKeys, this.selectedRows)
554
- })
555
- },
556
- customFunctionShow (customFunction, record, cIndex) {
557
- return executeStrFunctionByContext(this, customFunction, [record, cIndex])
558
- },
559
- getConfigByNameAsync,
560
- runLogic,
561
- executeStrFunctionByContext,
562
- columnClick (key, value, record) {
563
- this.$emit('columnClick', key, value, record)
564
- },
565
- gotoUserDetail (key, value, record) {
566
- this.$emit('gotoUserDetail', key, value, record)
567
- },
568
- // 打开行编辑
569
- openEditMode () {
570
- this.isEditMode = true
571
- this.editRowBeforeData = JSON.parse(JSON.stringify(this.getTableData()))
572
- },
573
- // 标记行保存
574
- editRowSave () {
575
- // 获取最新数据
576
- const editRowAfterData = this.getTableData()
577
- const changeData = getChangedData(this.editRowBeforeData, editRowAfterData)
578
- if (this.eventState?.customSave) {
579
- this.custom('customSave', {
580
- tableData: editRowAfterData,
581
- changeData
582
- })
583
- return
584
- }
585
- if (changeData.length === 0) {
586
- this.$message.info('没有数据发生变化')
587
- } else {
588
- Modal.confirm({
589
- title: '是否确认保存?',
590
- content: `此操作将保存当前行编辑的数据,共修改${changeData.length}条数据`,
591
- zIndex: 1001,
592
- onOk: () => {
593
- return new Promise((resolve, reject) => {
594
- const requestParameters = {
595
- queryParamsName: this.queryParamsName,
596
- changeData: changeData.map(h => getRealKeyData(h)),
597
- operaInfo: this.currUser.operaInfo
598
- }
599
- editRowSave(requestParameters, this.serviceName, this.env === 'dev').then(res => {
600
- this.$message.success('行内数据保存成功')
601
- this.isEditMode = false
602
- this.refresh()
603
- resolve(res)
604
- }).catch(e => {
605
- reject(e)
606
- this.$message.error('保存失败!')
607
- })
608
- })
609
- },
610
- onCancel () {
611
- }
612
- })
613
- }
614
- },
615
- importExcelOk (data) {
616
- this.refresh(true)
617
- this.$emit('importExcelOk', data)
618
- },
619
- /**
620
- * 行选择事件
621
- * @param row 选中行集合
622
- * @param attr 表单项属性
623
- */
624
- async rowChoose (row, attr, callback, record) {
625
- // 如果配置了自定义函数
626
- if (attr.dataChangeFunc) {
627
- await executeStrFunction(attr.dataChangeFunc, [record, this.setForm, {
628
- ...attr,
629
- selectRows: row
630
- }, util, this.getSelf(), this.mode, runLogic, getConfigByNameAsync])
631
- } else {
632
- // 默认填充选中行数据到当前表单
633
- setDataByRealKey(record, row[0])
634
- }
635
- if (callback) {
636
- callback()
637
- }
638
- },
639
- setForm (record, obj) {
640
- Object.assign(record, obj)
641
- this.$forceUpdate()
642
- },
643
- handleResize () {
644
- debounce(() => {
645
- this.setScrollYHeight({})
646
- }, 100)()
647
- },
648
- isInAModal () {
649
- let parent = this.$parent
650
- while (parent) {
651
- // 检查组件名称,这里假设a-modal组件的名称为AModal,根据实际情况可能需要调整
652
- if (parent.$options.name === 'AModal') {
653
- return true
654
- }
655
- parent = parent.$parent
656
- }
657
- return false
658
- },
659
- executeStrFunction,
660
- // 切换看板模式和表格模式
661
- changeViewMode () {
662
- this.isTableMode = !this.isTableMode
663
- // 看板切换回表格模式 刷新列表
664
- this.refresh(true)
665
- },
666
- /**
667
- * 初始化表格参数
668
- */
669
- init (params) {
670
- const {
671
- // 查询参数对象, 用于没有对应查询配置文件名时
672
- queryParams,
673
- tableColumns,
674
- attachGrid,
675
- expandedGrid,
676
- buttonState,
677
- eventState = {},
678
- buttonPermissions,
679
- editButtonStateData = [],
680
- title,
681
- form,
682
- tableSummaryMap = {},
683
- customTableSummaryArray = [],
684
- viewMode,
685
- localEditMode,
686
- formSubmitTypeInLocalEditMode = 'cover',
687
- rowSelectMode,
688
- allowSelectRowNum = 0,
689
- formItems,
690
- env = 'prod',
691
- createdQuery = true,
692
- createdEditMode = false,
693
- primaryKey,
694
- allowedCardMode = false,
695
- simpleMode = false,
696
- showRightTools = true,
697
- cardModeConfig,
698
- summaryUpdate,
699
- summaryDrawerWidth = 35,
700
- chartsConfigArray = [],
701
- printTemplate = 'DEFAULT_CRUD_PRINT_TEMPLATE',
702
- selectRowMode = 'default',
703
- tableSize = 'default',
704
- clearSelectRowAfterQuery = false
705
- } = params
706
- this.showSummary = Object.keys(tableSummaryMap).length > 0
707
- if (this.showSummary) {
708
- Object.keys(tableSummaryMap).forEach(item => {
709
- this.summaryData.push({
710
- key: item,
711
- title: tableSummaryMap[item],
712
- value: ' ',
713
- loading: true,
714
- success: false
715
- })
716
- })
717
- }
718
- if (customTableSummaryArray.length > 0) {
719
- customTableSummaryArray.forEach(item => {
720
- this.summaryData.push({
721
- key: item.key,
722
- title: item.title,
723
- value: ' ',
724
- loading: true,
725
- success: false
726
- })
727
- })
728
- this.showCustomSummary = true
729
- this.customSummaryArray = customTableSummaryArray
730
- }
731
- this.queryParams = queryParams
732
- this.tableColumns = JSON.parse(JSON.stringify(tableColumns))
733
- if (this.tableColumns.length === 0) {
734
- return
735
- }
736
- this.attachGrid = attachGrid
737
- this.expandedGrid = expandedGrid
738
- this.viewMode = viewMode
739
- this.localEditMode = localEditMode
740
- this.formSubmitTypeInLocalEditMode = formSubmitTypeInLocalEditMode
741
- this.rowSelectMode = rowSelectMode
742
- this.allowSelectRowNum = allowSelectRowNum
743
- this.simpleMode = simpleMode
744
- this.formItems = formItems
745
- this.user = this.currUser
746
- this.createdQuery = createdQuery
747
- this.primaryKey = primaryKey
748
- this.buttonState = buttonState
749
- this.eventState = eventState
750
- this.showRightTools = showRightTools
751
- this.printTemplate = printTemplate
752
- this.summaryDrawerWidth = summaryDrawerWidth
753
- this.chartsConfigArray = chartsConfigArray
754
- this.selectRowMode = selectRowMode
755
- this.tableSize = tableSize
756
- this.clearSelectRowAfterQuery = clearSelectRowAfterQuery
757
- if (this.chartsConfigArray.length > 0) {
758
- // 循环chartsConfigArray,将每个配置的数据请求参数赋值给requestParameters
759
- this.chartsConfigArray.forEach(item => {
760
- item.config.queryParams = JSON.parse(JSON.stringify(this.queryParams))
761
- item.config.queryParamsName = this.queryParamsName
762
- })
763
- }
764
- if (this.localEditMode) {
765
- this.localEditModeDataSource = []
766
- if (this.formSubmitTypeInLocalEditMode === 'append') {
767
- this.isLocalDataSourceLoadedExternally = true
768
- const defaultItem = {}
769
- defaultItem['序号'] = 0
770
- this.localEditModeDataSource.push(defaultItem)
771
- } else {
772
- this.isLocalDataSourceLoadedExternally = false
773
- }
774
- this.buttonState.import = false
775
- this.buttonState.export = false
776
- this.showRightTools = false
777
- }
778
- if (this.rowSelectMode) {
779
- this.buttonState = {
780
- choose: true
781
- }
782
- this.showRightTools = false
783
- }
784
- this.buttonPermissions = buttonPermissions
785
- this.editButtonStateData = editButtonStateData
786
- this.title = title
787
- this.env = env
788
- this.rowKey = this.getPrimaryKeyName()
789
- this.allowedCardMode = allowedCardMode
790
- this.cardModeConfig = cardModeConfig
791
- this.summaryUpdate = summaryUpdate
792
- this.isEditMode = createdEditMode
793
- let totalWidth = 0
794
- for (let i = 0; i < this.tableColumns.length; i++) {
795
- const item = this.tableColumns[i]
796
- // 设置操作列
797
- if (item.slotType === 'action') {
798
- item.fixed = 'right'
799
- item.width = 70
800
- }
801
- // 设置表格宽度
802
- if (item.width) {
803
- totalWidth = totalWidth + item.width
804
- } else {
805
- totalWidth = totalWidth + 180
806
- }
807
- }
808
- // 横向滚动长度大于所有宽度,才能实现固定表头
809
- this.scrollXWidth = totalWidth
810
- // 加载筛选列完成
811
- this.columnSelectLoaded = true
812
- this.setQueryForm(form || {})
813
- // 简易模式,并且是看板模式,默认直接进入看板模式
814
- if (this.allowedCardMode && this.simpleMode) {
815
- this.isTableMode = false
816
- }
817
- if (params.queryInterval) {
818
- this.queryTimer = setInterval(() => {
819
- this.refresh()
820
- }, params.queryInterval * 1000)
821
- }
822
- },
823
- // 操作面板按钮渲染
824
- buttonRendering (button) {
825
- if (!this.buttonPermissions) {
826
- return true
827
- }
828
- try {
829
- const existingItem = this.buttonPermissions.find(item => item.btnName === button)
830
- const rolestr = this.currUser.rolestr?.split(',')
831
- if (existingItem?.state) {
832
- const currUserRole = existingItem.roleStr
833
- return rolestr.some(item => currUserRole && currUserRole.includes(item))
834
- } else {
835
- return true
836
- }
837
- } catch (e) {
838
- console.error(e)
839
- return false
840
- }
841
- },
842
- // 防止查询多次点击处理
843
- loadTableData (requestParameters) {
844
- if (this.queryPromise) {
845
- return this.queryPromise
846
- }
847
- this.queryPromise = this.loadTableDataGen(requestParameters).finally(() => {
848
- this.queryPromise = undefined
849
- })
850
- return this.queryPromise
851
- },
852
- /**
853
- * 加载表格数据
854
- * @param requestParameters 请求参数
855
- */
856
- async loadTableDataGen (requestParameters) {
857
- let result
858
- if (this.localEditMode) {
859
- if (!this.isLocalDataSourceLoadedExternally && requestParameters?.conditionParams && Object.keys(requestParameters?.conditionParams).length > 0) {
860
- const result = await query(Object.assign(requestParameters, { userId: this.currUser?.id }),
861
- this.serviceName, this.env === 'dev')
862
- if (result.data) {
863
- let no = 0
864
- this.localEditModeDataSource = result.data.map(item => {
865
- item['序号'] = no
866
- no++
867
- return item
868
- })
869
- }
870
- this.isLocalDataSourceLoadedExternally = true
871
- }
872
- result = new Promise((resolve) => {
873
- resolve({
874
- data: this.localEditModeDataSource
875
- })
876
- })
877
- } else {
878
- result = query(Object.assign(requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
879
- result.then(res => {
880
- this.totalCount = res.totalCount || 0
881
- })
882
- }
883
-
884
- if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery) {
885
- this.$refs.table.updateSelect(this.selectedRowKeys, this.selectedRows)
886
- } else if (this.isTableMode && !this.simpleMode) {
887
- this.clearRowKeys()
888
- }
889
- this.$emit('afterQuery', result, requestParameters.conditionParams)
890
- return result
891
- },
892
- /**
893
- * 操作列事件
894
- * @param record 本条数据
895
- * @param actionType 操作类型
896
- * @param func 事件默认 action
897
- * @param index 行下标
898
- */
899
- action (record, actionType, func = 'action', index) {
900
- this.$emit('action', record, record[this.getPrimaryKeyName()], actionType, func, index)
901
- },
902
- // 看板点击事件
903
- handleCardEmit (data, eventName) {
904
- this.action(data, undefined, eventName)
905
- },
906
- /**
907
- * 选择列勾选改变事件
908
- * @param record 被选择的列数据
909
- * @param selected 是否选中
910
- * @param selectedRows 被选择的列集合
911
- * @param nativeEvent 原生事件
912
- */
913
- onSelect (record, selected, selectedRows, nativeEvent) {
914
- if (this.selectRowMode === 'listView') {
915
- // 获取主键数据
916
- const primaryData = record[this.primaryKey]
917
- // 取消勾选时
918
- if (!selected) {
919
- this.selectedRowKeys = this.selectedRowKeys.filter(item => item !== primaryData)
920
- this.selectedRows = this.selectedRows.filter(item => item[this.primaryKey] !== primaryData)
921
- }
922
- }
923
- },
924
- /**
925
- * 选择列全选事件
926
- * @param selected 是否选中
927
- * @param selectedRows 被选择的列集合
928
- * @param changeRows 改变的行集合
929
- */
930
- onSelectAll (selected, selectedRows, changeRows) {
931
- console.log('onSelectAll', selected, selectedRows, changeRows)
932
- if (this.selectRowMode === 'listView') {
933
- if (!selected) {
934
- // 获取所有改变的key
935
- const changeKeys = changeRows.map(item => item[this.primaryKey])
936
- this.selectedRowKeys = this.selectedRowKeys.filter(item => !changeKeys.includes(item))
937
- this.selectedRows = this.selectedRows.filter(item => !changeKeys.includes(item[this.primaryKey]))
938
- }
939
- }
940
- },
941
- /**
942
- * 选择列数据改变事件
943
- * @param selectedRowKeys 被选择的列Key集合
944
- * @param selectedRows 被选择的列集合
945
- */
946
- onSelectChange (selectedRowKeys, selectedRows) {
947
- this.innerSelectedRowKeys = selectedRowKeys
948
- this.innerSelectedRows = selectedRows
949
- if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery) {
950
- if (this.primaryKey) {
951
- // 找出被取消选中的行
952
- const deselectedKeys = this.selectedRowKeys.filter(key => !selectedRowKeys.includes(key))
953
- // 从已选中的行中移除被取消选中的行
954
- if (deselectedKeys.length > 0) {
955
- this.selectedRowKeys = this.selectedRowKeys.filter(key => !deselectedKeys.includes(key))
956
- this.selectedRows = this.selectedRows.filter(row => !deselectedKeys.includes(row[this.primaryKey]))
957
- }
958
- // 添加新选中的行(去重)
959
- const newSelectedKeys = selectedRowKeys.filter(key => !this.selectedRowKeys.includes(key))
960
- const newSelectedRows = selectedRows.filter(row => newSelectedKeys.includes(row[this.primaryKey]))
961
- this.selectedRowKeys = [...this.selectedRowKeys, ...newSelectedKeys]
962
- this.selectedRows = [...this.selectedRows, ...newSelectedRows]
963
- } else {
964
- // 如果没有主键,则直接使用当前选中的行
965
- this.selectedRowKeys = selectedRowKeys
966
- this.selectedRows = selectedRows
967
- }
968
- } else {
969
- this.selectedRowKeys = this.innerSelectedRowKeys
970
- this.selectedRows = this.innerSelectedRows
971
- }
972
- this.isModify = this.innerSelectedRowKeys.length === 1
973
- this.isDelete = this.innerSelectedRowKeys.length > 0
974
- this.isChoose = this.allowSelectRowNum === 0 ? this.innerSelectedRowKeys.length > 0 : this.innerSelectedRowKeys.length === this.allowSelectRowNum
975
- this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
976
- },
977
- /**
978
- * 清除表格选中项
979
- */
980
- clearRowKeys () {
981
- this.$refs.table.clearSelected()
982
- },
983
- /**
984
- * 为表格附加查询条件
985
- */
986
- setQueryForm (form = {}) {
987
- this.form = form
988
- if (this.createdQuery) {
989
- this.refresh(true)
990
- } else {
991
- this.createdQuery = true
992
- }
993
- },
994
- /**
995
- * 表格重新加载方法
996
- * 如果参数为 true, 则强制刷新到第一页
997
- */
998
- refresh (bool) {
999
- this.$nextTick(() => {
1000
- this.$refs.table.refresh(bool)
1001
- })
1002
- },
1003
- setScrollYHeight ({ extraHeight = this.extraHeight, id = this.uniqueId, type = '' }) {
1004
- this.$nextTick(() => {
1005
- setTimeout(() => {
1006
- const curDocument = window?.rawDocument || document
1007
- const innerHeight = window?.rawWindow?.innerHeight || window.innerHeight || 0
1008
- if (typeof extraHeight == 'undefined') {
1009
- // 默认底部分页32 + 边距48
1010
- extraHeight = 48 + 32
1011
- }
1012
- let tHeader = null
1013
- if (id) {
1014
- tHeader = curDocument.getElementById(id) ? curDocument.getElementById(id).getElementsByClassName('ant-table-thead')[0] : null
1015
- } else {
1016
- tHeader = curDocument.getElementsByClassName('ant-table-thead')[0]
1017
- }
1018
- // 表格内容距离顶部的距离
1019
- let tHeaderBottom = 0
1020
- if (tHeader) {
1021
- tHeaderBottom = tHeader.getBoundingClientRect().bottom
1022
- }
1023
- if (tHeaderBottom === 0) {
1024
- this.scrollYHeight = 'calc(100vh - 31rem)'
1025
- if (window.__MICRO_APP_ENVIRONMENT__) {
1026
- this.scrollYHeight = 'calc(100vh - 28.5rem)'
1027
- }
1028
- return
1029
- }
1030
-
1031
- // 判断是否在 modal 中
1032
- if (this.isInAModal()) {
1033
- let modalElement = null
1034
- if (tHeader) {
1035
- modalElement = tHeader.closest('.ant-modal-body')
1036
- } else {
1037
- modalElement = curDocument.querySelector('.ant-modal-body')
1038
- }
1039
- if (modalElement) {
1040
- const modalRect = modalElement.getBoundingClientRect()
1041
- // 48 是 modal 通常的边距 32 是分页
1042
- extraHeight = innerHeight - modalRect.bottom + 32 + 48
1043
- }
1044
- }
1045
- if (innerHeight - (tHeaderBottom + extraHeight) < 210) {
1046
- this.scrollYHeight = 'calc(100vh - 31rem)'
1047
- return
1048
- }
1049
- // 窗体高度-表格内容顶部的高度-表格内容底部的高度
1050
- // this.scrollYHeight = document.body.clientHeight - tHeaderBottom - extraHeight
1051
- this.scrollYHeight = `calc(100vh - ${tHeaderBottom + extraHeight}px)`
1052
- }, 60)
1053
- })
1054
- },
1055
- /**
1056
- * 获取主键列名称
1057
- */
1058
- getPrimaryKeyName () {
1059
- if (this.primaryKey) {
1060
- return this.primaryKey
1061
- }
1062
- const indexColumn = this.tableColumns.find(i => i?.slotType === 'index')
1063
- return indexColumn ? indexColumn.dataIndex : this.tableColumns[0].dataIndex
1064
- },
1065
- handleExport (type) {
1066
- this.$refs.exportExcel.handleExport(type, this.title)
1067
- },
1068
- handlePrint (type) {
1069
- const printData = {
1070
- title: this.title,
1071
- form: this.form,
1072
- operaInfo: this.currUser.operaInfo,
1073
- operaTime: moment().format('YYYY-MM-DD HH:mm:ss'),
1074
- summary: this.retrieveSummaryData
1075
- }
1076
- this.$refs.exportExcel.handlePrint(type, printData)
1077
- },
1078
- validateTableAndSyncData (currRow, defaultAppendRowData) {
1079
- let isLastRow = false
1080
- if (this.localEditModeDataSource.length === 0) {
1081
- isLastRow = true
1082
- } else if (currRow['序号'] === this.localEditModeDataSource[this.localEditModeDataSource.length - 1]['序号']) {
1083
- isLastRow = true
1084
- }
1085
- if (isLastRow) {
1086
- this.appendLocalData(defaultAppendRowData)
1087
- }
1088
- },
1089
- // 新增业务
1090
- add () {
1091
- if (this.eventState?.customAdd) {
1092
- this.custom('customAdd', {})
1093
- return
1094
- }
1095
- if (this.localEditMode && this.isEditMode) {
1096
- this.appendLocalData({})
1097
- } else {
1098
- this.$emit('add')
1099
- }
1100
- },
1101
- // 添加业务
1102
- move () {
1103
- this.$emit('move')
1104
- },
1105
- // 通用事件业务
1106
- custom (func) {
1107
- this.$emit('customEvent', func)
1108
- },
1109
- // 编辑业务
1110
- edit (id) {
1111
- this.editLoading = true
1112
- this.getEditData(id).then(modifyModelData => {
1113
- if (this.eventState?.customEdit) {
1114
- this.custom('customEdit', { id, modifyModelData })
1115
- return
1116
- }
1117
- this.$emit('edit', modifyModelData)
1118
- this.editLoading = false
1119
- })
1120
- },
1121
- // 行选择业务
1122
- choose () {
1123
- if (this.isChoose) {
1124
- // 如果配置了自定义函数
1125
- this.$emit('rowChoose', this.selectedRows)
1126
- } else {
1127
- this.$message.warning(this.allowSelectRowNum === 0 ? '请选择数据' : `请选择${this.allowSelectRowNum}条数据`)
1128
- }
1129
- },
1130
- // 自定义按钮点击
1131
- editButtonStateDataClick (index) {
1132
- this.$emit('editButtonStateDataClick', this.editButtonStateData[index].functionName, this.selectedRows)
1133
- },
1134
- // 获取被编辑的数据
1135
- getEditData (id) {
1136
- if (!id) {
1137
- this.selectId = this.selectedRowKeys[0]
1138
- } else {
1139
- this.selectId = id
1140
- }
1141
- const primaryKeyName = this.getPrimaryKeyName()
1142
- if (this.tableColumns[0].dataIndex !== primaryKeyName) {
1143
- this.selectId = this.selectedRows[0][primaryKeyName]
1144
- }
1145
- // 将更新需要的主键值加入到primaryKeyData中
1146
- const primaryKeyData = {}
1147
- primaryKeyData[primaryKeyName] = this.selectId
1148
- if (this.localEditMode) {
1149
- return new Promise((resolve) => {
1150
- const modifyData = this.getDataByRowKeyValue(this.selectId)
1151
- resolve({
1152
- data: modifyData,
1153
- primaryKeyData: primaryKeyData
1154
- })
1155
- })
1156
- }
1157
- const requestParameters = {
1158
- queryParamsName: this.queryParamsName,
1159
- queryParams: this.queryParams && Object.keys(this.queryParams).length > 0 ? this.queryParams : undefined,
1160
- conditionParams: {},
1161
- pageNo: 1,
1162
- pageSize: 1
1163
- }
1164
- requestParameters.conditionParams[primaryKeyName] = this.selectId
1165
- requestParameters.f_businessid = this.selectId
1166
- return queryWithResource(requestParameters, this.serviceName, this.env === 'dev').then(res => {
1167
- return { data: res.data[0], primaryKeyData: primaryKeyData, images: res.images, files: res.files }
1168
- })
1169
- },
1170
- // 删除业务
1171
- deleteItem () {
1172
- if (this.viewMode) {
1173
- this.$message.info('预览模式禁止删除')
1174
- return
1175
- }
1176
- Modal.confirm({
1177
- title: '提示',
1178
- content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
1179
- zIndex: 1001,
1180
- onOk: () => {
1181
- const requestParameters = {
1182
- queryParamsName: this.queryParamsName,
1183
- idList: this.selectedRowKeys
1184
- }
1185
- if (this.eventState?.customDelete) {
1186
- this.custom('customDelete', {
1187
- selectedRowKeys: this.selectedRowKeys,
1188
- selectedRows: this.selectedRows
1189
- })
1190
- return
1191
- }
1192
- return new Promise((resolve, reject) => {
1193
- if (this.localEditMode) {
1194
- this.localEditModeDataSource = this.getLocalData().filter(item => !this.selectedRowKeys.includes(item[this.rowKey]))
1195
- resolve(200)
1196
- this.$message.success('删除成功!')
1197
- this.refresh(true)
1198
- // afterDelete
1199
- this.$emit('afterDelete', requestParameters)
1200
- } else if (this.customDelete) {
1201
- this.$emit('del', this.selectedRows, resolve)
1202
- } else {
1203
- remove(requestParameters, this.serviceName, this.env === 'dev').then(res => {
1204
- resolve(res)
1205
- this.$message.success('删除成功!')
1206
- this.refresh(true)
1207
- // afterDelete
1208
- this.$emit('afterDelete', requestParameters)
1209
- }).catch(e => {
1210
- reject(e)
1211
- this.$message.error('删除失败!')
1212
- })
1213
- }
1214
- })
1215
- },
1216
- onCancel () {
1217
- }
1218
- })
1219
- },
1220
- // 导入业务
1221
- importData () {
1222
- this.$refs.importExcel.importExcelHandleOpen()
1223
- },
1224
- afterVisibleChange (val) {
1225
- if (val) {
1226
- this.retrieveSummaryData()
1227
- }
1228
- },
1229
- async retrieveSummaryData () {
1230
- const promises = []
1231
-
1232
- if (this.requestParameters.querySummary) {
1233
- const querySummaryPromise = querySummary(Object.assign(this.requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
1234
- .then(res => {
1235
- if (this.compatible === 'V3') {
1236
- res = res.data
1237
- }
1238
- if (res.length > 0) {
1239
- this.summaryData.forEach(item => {
1240
- res.forEach(summary => {
1241
- if (item.title === summary.title) {
1242
- item.value = summary.value
1243
- item.success = true
1244
- item.loading = false
1245
- }
1246
- })
1247
- })
1248
- }
1249
- })
1250
- promises.push(querySummaryPromise)
1251
- }
1252
-
1253
- if (this.showCustomSummary) {
1254
- this.customSummaryArray.forEach(item => {
1255
- const runLogicPromise = runLogic(item.source, Object.assign(this.requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
1256
- .then(res => {
1257
- this.summaryData.forEach(summary => {
1258
- if (item.key === summary.key) {
1259
- summary.value = res.value
1260
- summary.success = true
1261
- summary.loading = false
1262
- }
1263
- })
1264
- })
1265
- .catch(e => {
1266
- this.summaryData.forEach(summary => {
1267
- if (item.key === summary.key) {
1268
- summary.value = 0
1269
- summary.success = false
1270
- summary.loading = false
1271
- }
1272
- })
1273
- })
1274
- promises.push(runLogicPromise)
1275
- })
1276
- }
1277
-
1278
- await Promise.all(promises)
1279
- return this.summaryData
1280
- },
1281
- showDrawer () {
1282
- if (this.summaryUpdate) {
1283
- this.summaryData.forEach(item => {
1284
- item.loading = true
1285
- item.success = false
1286
- item.value = ' '
1287
- })
1288
- this.summaryDrawerVisible = true
1289
- } else {
1290
- this.$message.warning('请查询后再来查看')
1291
- }
1292
- },
1293
- onClose () {
1294
- this.summaryDrawerVisible = false
1295
- },
1296
- // 获取表格内所有数据
1297
- getTableData () {
1298
- return this.$refs.table.localDataSource
1299
- },
1300
- // 设置表格内数据
1301
- setTableData (data) {
1302
- if (this.localEditMode) {
1303
- // 本地编辑模式下,需要修改 localEditModeDataSource
1304
- this.localEditModeDataSource = data.map((item, index) => ({
1305
- ...item,
1306
- 序号: index + 1
1307
- }))
1308
- this.$nextTick(() => {
1309
- this.$refs.table?.refresh()
1310
- })
1311
- } else {
1312
- // 普通模式
1313
- this.$nextTick(() => {
1314
- if (this.$refs.table) {
1315
- this.$refs.table.setLocalDataSource(data)
1316
- }
1317
- })
1318
- }
1319
- },
1320
- // 获取所有本地数据
1321
- getLocalData () {
1322
- return this.localEditModeDataSource
1323
- },
1324
- // 获取指定rowKey的value的本地数据
1325
- getDataByRowKeyValue (rowKeyValue) {
1326
- return this.getLocalData().find(item => {
1327
- return item[this.rowKey] === rowKeyValue
1328
- })
1329
- },
1330
- // 修改本地数据
1331
- modifyLocalData (rowKeyValue, data) {
1332
- const modifyItem = this.getDataByRowKeyValue(rowKeyValue)
1333
- if (modifyItem) {
1334
- Object.assign(modifyItem, data)
1335
- }
1336
- },
1337
- // 追加本地数据
1338
- appendLocalData (item) {
1339
- if (this.localEditModeDataSource.length === 0) {
1340
- item['序号'] = 1
1341
- } else {
1342
- item['序号'] = this.localEditModeDataSource[this.localEditModeDataSource.length - 1]['序号'] + 1
1343
- }
1344
- this.localEditModeDataSource.push(item)
1345
- },
1346
- handleRowClick (record) {
1347
- this.$emit('rowClick', record)
1348
- },
1349
- beforeDataChange (record) {
1350
- this.$emit('beforeDataChange', record)
1351
- },
1352
- onExpand (expanded, record) {
1353
- this.$emit('expand', expanded, record)
1354
- }
1355
- }
1356
- }
1357
- </script>
1358
- <style lang="less" scoped>
1359
-
1360
- .custom-chart-title {
1361
- font-size: 16px;
1362
- font-weight: 700;
1363
- margin-bottom: 8px;
1364
- }
1365
-
1366
- .custom-chart-desc {
1367
- font-size: 12px;
1368
- color: rgba(0, 0, 0, .45);
1369
- margin-bottom: 16px;
1370
- }
1371
-
1372
- :deep(.ant-table-thead > tr > th) {
1373
- font-weight: 600;
1374
- }
1375
-
1376
- :deep(.table-wrapper .ant-pagination) {
1377
- display: flex;
1378
- flex-direction: row;
1379
- align-items: center;
1380
- padding: 0;
1381
- }
1382
-
1383
- :deep(.table-wrapper .ant-pagination .ant-pagination-total-text) {
1384
- white-space: nowrap;
1385
- }
1386
-
1387
- :deep(.ant-table td) {
1388
- white-space: nowrap;
1389
- }
1390
-
1391
- .footer_sum_title {
1392
- color: @primary-color;
1393
- font-weight: bold;
1394
- }
1395
-
1396
- .footer_sum_item {
1397
- white-space: nowrap;
1398
- }
1399
-
1400
- .ant-btn-hover {
1401
- border-color: @primary-color;
1402
- color: @primary-color;
1403
- }
1404
-
1405
- .innerTable {
1406
- :deep(.ant-form-item) {
1407
- margin: 0;
1408
- }
1409
- }
1410
- </style>
1
+ <template>
2
+ <div v-show="tableColumns.length > 0">
3
+ <a-row :gutter="48">
4
+ <a-col v-show="showLeftOperaBtn">
5
+ <span :style="{ float: 'left', marginBottom: '8px' }">
6
+ <a-space>
7
+ <!-- <a-button v-if="eventState.customDelete" type="primary" @click="custom('customDelete')">-->
8
+ <!-- <a-icon type="delete"/>删除-->
9
+ <!-- </a-button>-->
10
+ <!-- <a-button v-if="eventState.customSave" type="primary" @click="custom('customSave')">-->
11
+ <!-- <a-icon type="save"/>保存-->
12
+ <!-- </a-button>-->
13
+ <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
14
+ <a-button v-if="buttonState.add && buttonRendering('add')" type="primary" @click="add">
15
+ <a-icon type="plus"/>新增
16
+ </a-button>
17
+ <a-button v-if="buttonState.move && buttonRendering('move')" type="primary" @click="move">
18
+ <a-icon type="plus"/>添加
19
+ </a-button>
20
+ <a-button
21
+ v-if="buttonState.choose && buttonRendering('choose')"
22
+ :disabled="!isChoose"
23
+ type="primary"
24
+ @click="choose">
25
+ <a-icon type="check-square"/>选择
26
+ </a-button>
27
+ <a-button
28
+ v-if="buttonState.edit && buttonRendering('edit')"
29
+ :disabled="!isModify"
30
+ :loading="editLoading"
31
+ class="btn-success"
32
+ type="dashed"
33
+ @click="edit()">
34
+ <a-icon :style="iconStyle" type="form"/>修改
35
+ </a-button>
36
+ <template
37
+ v-if="buttonState.editRow && buttonRendering('editRow')">
38
+ <a-button
39
+ v-if="isEditMode"
40
+ class="ant-btn-hover"
41
+ @click="editRowSave">
42
+ <a-icon :style="iconStyle" type="save"/>保存
43
+ </a-button>
44
+ <a-button
45
+ v-else
46
+ @click="openEditMode">
47
+ <a-icon :style="iconStyle" type="edit"/>行编辑
48
+ </a-button>
49
+ </template>
50
+ <a-button
51
+ v-if="buttonState.delete && buttonRendering('delete')"
52
+ :disabled="!isDelete"
53
+ type="danger"
54
+ @click="deleteItem">
55
+ <a-icon :style="iconStyle" type="delete"/>删除
56
+ </a-button>
57
+ <a-button
58
+ v-if="buttonState.import && buttonRendering('import')"
59
+ type="dashed"
60
+ @click="importData">
61
+ <a-icon :style="iconStyle" type="import"/>导入
62
+ </a-button>
63
+ <a-dropdown v-if="!buttonState || buttonState.export && buttonRendering('export')">
64
+ <a-menu slot="overlay">
65
+ <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport('selected')"><a-icon
66
+ :style="iconStyle"
67
+ type="ordered-list"/>导出选中数据</a-menu-item>
68
+ <a-menu-item key="2" @click="handleExport('curPage')"><a-icon :style="iconStyle" type="snippets"/>导出本页数据</a-menu-item>
69
+ <a-menu-item key="3" @click="handleExport('exportByQuery')"><a-icon :style="iconStyle" type="download"/>导出所有符合条件的数据</a-menu-item>
70
+ </a-menu>
71
+ <a-button>导出 <a-icon type="down" :style="iconStyle"/> </a-button>
72
+ </a-dropdown>
73
+ <a-dropdown v-if="!buttonState || buttonState.print && buttonRendering('print')">
74
+ <a-menu slot="overlay">
75
+ <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handlePrint('selected')"><a-icon
76
+ :style="iconStyle"
77
+ type="ordered-list"/>打印选中数据</a-menu-item>
78
+ <a-menu-item key="2" @click="handlePrint('curPage')"><a-icon :style="iconStyle" type="snippets"/>打印本页数据</a-menu-item>
79
+ <a-menu-item key="3" @click="handlePrint('exportByQuery')"><a-icon :style="iconStyle" type="download"/>打印所有符合条件的数据</a-menu-item>
80
+ </a-menu>
81
+ <a-button>打印 <a-icon type="printer" :style="iconStyle"/> </a-button>
82
+ </a-dropdown>
83
+ <!-- 遍历按钮配置数组,动态生成按钮 -->
84
+ <a-button
85
+ v-for="(button, index) in editButtonStateData"
86
+ :key="index"
87
+ :type="button.type || 'dashed'"
88
+ @click="editButtonStateDataClick(index)"
89
+ class="btn-success"
90
+ >
91
+ <a-icon type="dashed" :style="iconStyle"/>
92
+ {{ button.buttonName }}
93
+ </a-button>
94
+ <a-button
95
+ v-if="allowedCardMode && !simpleMode"
96
+ @click="changeViewMode"
97
+ :type="isTableMode ? '' : 'primary'">
98
+ 看板模式
99
+ </a-button>
100
+ <a-badge
101
+ v-if="selectRowMode === 'listView'"
102
+ :count="selectedRows.length"
103
+ :number-style="{ backgroundColor:theme.color }"
104
+ >
105
+ <a-button
106
+ type="dashed"
107
+ @click="showTempData">
108
+ <a-icon :style="iconStyle" type="monitor"/>已选择
109
+ </a-button>
110
+ </a-badge>
111
+ <!-- 头部附加栅格 -->
112
+ <x-report
113
+ v-if="attachGrid"
114
+ :env="env"
115
+ :isWidget="true"
116
+ :use-oss-for-img="false"
117
+ :config-name="attachGrid"
118
+ :show-img-in-cell="true"
119
+ :display-only="true"
120
+ :edit-mode="false"
121
+ :show-save-button="false"
122
+ :dont-format="true"/>
123
+
124
+ <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
125
+ </a-space>
126
+
127
+ </span>
128
+ </a-col>
129
+ <a-col v-show="showRightTools && !simpleMode">
130
+ <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
131
+ <a-button-group>
132
+ <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
133
+ <a-tooltip title="汇总" placement="bottom">
134
+ <a-button @click="showDrawer">
135
+ <a-icon :style="iconStyle" type="project"/>
136
+ </a-button>
137
+ </a-tooltip>
138
+ <a-tooltip title="重新查询" placement="bottom">
139
+ <a-button @click="refresh(true)">
140
+ <a-icon :style="iconStyle" type="reload"/>
141
+ </a-button>
142
+ </a-tooltip>
143
+ <a-tooltip title="列展示/排序" placement="bottom">
144
+ <table-setting v-if="columnSelectLoaded" v-model="tableColumns"/>
145
+ </a-tooltip>
146
+ </a-button-group>
147
+ </span>
148
+ </a-col>
149
+ </a-row>
150
+ <!-- 如果当前是表格模式 -->
151
+ <template v-if="isTableMode">
152
+ <x-table-wrapper
153
+ ref="table"
154
+ @rowClick="handleRowClick"
155
+ @beforeDataChange="beforeDataChange"
156
+ @expand="onExpand">
157
+ <template slot="expandedRowRender">
158
+ <!-- 列扩展栅格 -->
159
+ <x-report
160
+ v-if="expandedGrid"
161
+ :env="env"
162
+ ref="report"
163
+ :isWidget="true"
164
+ :use-oss-for-img="false"
165
+ :config-name="expandedGrid"
166
+ :show-img-in-cell="true"
167
+ :display-only="true"
168
+ :edit-mode="false"
169
+ :show-save-button="false"
170
+ :dont-format="true"/>
171
+ </template>
172
+ <template slot="footer">
173
+ <slot
174
+ name="footer"
175
+ :selectedRowKeys="selectedRowKeys"
176
+ :selectedRows="selectedRows"></slot>
177
+ </template>
178
+ </x-table-wrapper>
179
+ </template>
180
+ <!-- 如果当前是看板模式 -->
181
+ <template v-else>
182
+ <XDataCard
183
+ ref="table"
184
+ @cardEmit="handleCardEmit"
185
+ :tableColumns="tableColumns"
186
+ :card-config="cardModeConfig"
187
+ :show-pagination="!simpleMode"
188
+ :prePageSize="simpleMode ? 1000 : undefined"
189
+ :serviceName="serviceName"
190
+ :card-data="loadData"
191
+ :env="env"
192
+ :createdQuery="createdQuery"
193
+ :simple-mode="simpleMode"/>
194
+ </template>
195
+ <!-- 上传文件 -->
196
+ <a-drawer
197
+ title="汇总信息"
198
+ placement="right"
199
+ :closable="false"
200
+ :visible="summaryDrawerVisible"
201
+ :z-index="2000"
202
+ :width="`${summaryDrawerWidth}vw`"
203
+ :after-visible-change="afterVisibleChange"
204
+ @close="onClose"
205
+ >
206
+ <template>
207
+ <a-row>
208
+ <a-col :span="8" v-for="(f,index) in summaryData" :key="index">
209
+ <a-statistic
210
+ :title="f.title + ':'"
211
+ :value="f.value"
212
+ :precision="2">
213
+ <template #prefix>
214
+ <a-spin :spinning="f.loading">
215
+ </a-spin>
216
+ </template>
217
+ <template #suffix>
218
+ <a-icon
219
+ v-show="!f.loading"
220
+ :type="f.success !== false ? 'check-circle' : 'close-circle'"
221
+ :style="{color: f.success !== false ? 'green' : 'red'}"/>
222
+ </template>
223
+ </a-statistic>
224
+ </a-col>
225
+ <a-col
226
+ :span="item.span"
227
+ v-for="(item,index) in chartsConfigArray"
228
+ :key="index"
229
+ style="height: 20rem; margin-bottom: 3rem">
230
+ <div class="custom-chart-title" v-if="item.config.title">{{ item.config.title }}</div>
231
+ <div class="custom-chart-desc" v-if="item.config.description">{{ item.config.description }}</div>
232
+ <g2Charts
233
+ :key="index"
234
+ :chatsKey="index"
235
+ :is-dev="env === 'dev'"
236
+ :config="item.config"
237
+ :requestParameters="requestParameters"/>
238
+ </a-col>
239
+ </a-row>
240
+ </template>
241
+ </a-drawer>
242
+ <x-import-excel
243
+ ref="importExcel"
244
+ @ok="importExcelOk"
245
+ :title="title"
246
+ :service-name="serviceName"
247
+ :env="env"
248
+ :query-params-name="queryParamsName"
249
+ >
250
+ <template #importExcelSlot>
251
+ <slot name="importExcelSlot"></slot>
252
+ </template>
253
+ </x-import-excel>
254
+ <ExportExcel
255
+ ref="exportExcel"
256
+ />
257
+ <a-modal @cancel="$refs.table.refresh()" v-model="selectedRowModalVisible" width="80vw" title="已选中数据" :footer="null">
258
+ <x-table-wrapper
259
+ ref="selectedDataTable"
260
+ :load-selected-data="true"
261
+ @beforeDataChange="beforeDataChange"
262
+ @rowClick="handleRowClick">
263
+ </x-table-wrapper>
264
+ </a-modal>
265
+ </div>
266
+ </template>
267
+ <script>
268
+ import { STable } from '@vue2-client/components'
269
+ import { getChangedData, setDataByRealKey } from '@vue2-client/utils/util'
270
+ import * as util from '@vue2-client/utils/util'
271
+ import TableSetting from '@vue2-client/components/TableSetting/TableSetting'
272
+ import {
273
+ query,
274
+ querySummary,
275
+ queryWithResource,
276
+ remove,
277
+ getConfigByNameAsync,
278
+ editRowSave,
279
+ runLogic
280
+ } from '@vue2-client/services/api/common'
281
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
282
+ import { Modal } from 'ant-design-vue'
283
+ import { mapState } from 'vuex'
284
+ import { executeStrFunction, executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
285
+ import debounce from 'lodash.debounce'
286
+ import XDataCard from '@vue2-client/base-client/components/common/XDataCard/XDataCard.vue'
287
+ import { getRealKeyData } from '@vue2-client/utils/formatter'
288
+ import ReportTableHome from '../../../../pages/report/ReportTableHome.vue'
289
+ import CustomFuncCel from '@vue2-client/base-client/components/common/XTable/CustomFuncCel.vue'
290
+ import ExportExcel from '@vue2-client/base-client/components/common/XTable/ExportExcel.vue'
291
+ import g2Charts from '@vue2-client/components/g2Charts/index.vue'
292
+ import moment from 'moment/moment'
293
+ import XTableWrapper from './XTableWrapper.vue'
294
+
295
+ export default {
296
+ name: 'XTable',
297
+ components: {
298
+ ExportExcel,
299
+ CustomFuncCel,
300
+ XDataCard,
301
+ TableSetting,
302
+ STable,
303
+ XImportExcel,
304
+ g2Charts,
305
+ XReport: () => import('@vue2-client/base-client/components/common/XReportGrid/XReport.vue'),
306
+ ReportTableHome,
307
+ XTableWrapper
308
+ },
309
+ inject: ['getSelf'],
310
+ provide () {
311
+ return {
312
+ tableContext: this
313
+ }
314
+ },
315
+ data () {
316
+ return {
317
+ uniqueId: `x-table-${this._uid}`, // 使用 _uid 生成唯一 ID
318
+ // 筛选列加载状态
319
+ columnSelectLoaded: false,
320
+ // 预览模式
321
+ viewMode: false,
322
+ // 本地编辑模式
323
+ localEditMode: false,
324
+ // 本地编辑表单提交方式
325
+ formSubmitTypeInLocalEditMode: 'cover',
326
+ // 本地编辑模式所用数据源
327
+ localEditModeDataSource: [],
328
+ // 本地编辑模式数据源是否已由外部加载
329
+ isLocalDataSourceLoadedExternally: false,
330
+ // 行选择模式
331
+ rowSelectMode: false,
332
+ // 行选择模式-允许选中行数量,0:任意数量行,大于0:指定值数量的行
333
+ allowSelectRowNum: 0,
334
+ // 头部附件的栅格配置名
335
+ attachGrid: '',
336
+ // 表格行扩展区域的栅格配置名
337
+ expandedGrid: '',
338
+ // 是否展示右侧工具栏
339
+ showRightTools: true,
340
+ // 是否展示左边按钮栏
341
+ showLeftOperaBtn: true,
342
+ // 加载数据方法 必须为 Promise 对象
343
+ loadData: parameter => {
344
+ // 取到表格携带的表单参数
345
+ const requestParameters = Object.assign({}, parameter)
346
+ // 取到父组件传入的表单参数
347
+ const conditionParams = {}
348
+ Object.assign(conditionParams, this.fixedQueryForm)
349
+ Object.assign(conditionParams, this.form)
350
+ // 如果传了燃气公司字段,则进行数据处理
351
+ if (conditionParams.orgName) {
352
+ requestParameters.orgName = conditionParams.orgName
353
+ delete conditionParams.orgName
354
+ }
355
+ Object.keys(conditionParams).forEach(key => {
356
+ if (Array.isArray(conditionParams[key])) {
357
+ // 检查数组中是否包含 null
358
+ const hasNull = conditionParams[key].every(item => item === '') || conditionParams[key].length === 0
359
+ // 如果包含 null,则删除该属性
360
+ if (hasNull) {
361
+ delete conditionParams[key]
362
+ }
363
+ }
364
+ })
365
+ requestParameters.conditionParams = conditionParams
366
+ requestParameters.queryParamsName = this.queryParamsName
367
+ requestParameters.queryParams = this.queryParams && Object.keys(this.queryParams).length > 0 ? this.queryParams : undefined
368
+ this.requestParameters = requestParameters
369
+ // 加载数据
370
+ return this.loadTableData(requestParameters)
371
+ },
372
+ requestParameters: {},
373
+ rowKey: undefined,
374
+ // x滚动条宽度
375
+ scrollXWidth: 1600,
376
+ // y滚动条高度
377
+ scrollYHeight: 'calc(100vh - 31rem)',
378
+ // 表格选择列Key集合
379
+ selectedRowKeys: [],
380
+ // 表格选择Row集合
381
+ selectedRows: [],
382
+ // 表格选择列Key集合
383
+ innerSelectedRowKeys: [],
384
+ // 表格选择Row集合
385
+ innerSelectedRows: [],
386
+ // 禁止表格选择Row集合
387
+ selectedDisableRows: [],
388
+ // 业务标题
389
+ title: '',
390
+ // 数据列
391
+ tableColumns: [],
392
+ // 查询用表单
393
+ form: {},
394
+ oldForm: {},
395
+ // 是否允许修改
396
+ isModify: false,
397
+ // 是否允许删除
398
+ isDelete: false,
399
+ // 是否允许选择
400
+ isChoose: false,
401
+ // 选中用于修改的id
402
+ selectId: undefined,
403
+ // 是否显示展示列抽屉
404
+ visible: false,
405
+ // 编辑按钮加载状态
406
+ editLoading: false,
407
+ // 按钮状态
408
+ buttonState: {},
409
+ // eventBtnState
410
+ eventState: {},
411
+ // 自定义按钮数组
412
+ editButtonStateData: [],
413
+ // 按钮权限
414
+ buttonPermissions: [],
415
+ // 是否展示汇总
416
+ showSummary: false,
417
+ // 自定义汇总
418
+ showCustomSummary: false,
419
+ summaryData: [],
420
+ // 图标样式
421
+ iconStyle: {
422
+ position: 'relative',
423
+ top: '1px'
424
+ },
425
+ // 当前环境
426
+ env: 'prod',
427
+ // 预览模式(表格 or 看板)
428
+ isTableMode: true,
429
+ // 汇总抽屉是否显示
430
+ summaryDrawerVisible: false,
431
+ // 汇总更新标志
432
+ summaryUpdate: false,
433
+ customSummaryArray: [],
434
+ formItems: [],
435
+ // 是否为行编辑模式
436
+ isEditMode: false,
437
+ // 定义主键
438
+ primaryKey: '',
439
+ // 是否进行初始化查询
440
+ createdQuery: false,
441
+ // 允许看板模式
442
+ allowedCardMode: false,
443
+ // 看板模式配置
444
+ cardModeConfig: undefined,
445
+ // 暂存行编辑前数据 用于比较哪些变化了才需要保存
446
+ editRowBeforeData: [],
447
+ // 是否简易模式
448
+ simpleMode: false,
449
+ // crud打印模板配置
450
+ printTemplate: false,
451
+ queryParams: {},
452
+ // 定义总行数
453
+ totalCount: 0,
454
+ user: {},
455
+ chartsConfigArray: [],
456
+ summaryDrawerWidth: 35,
457
+ // 行选择模式
458
+ selectRowMode: 'default',
459
+ tableSize: 'default',
460
+ clearSelectRowAfterQuery: false,
461
+ selectedRowModalVisible: false
462
+ }
463
+ },
464
+ props: {
465
+ // 查询配置文件名
466
+ queryParamsName: {
467
+ type: String,
468
+ default: () => {
469
+ return ''
470
+ }
471
+ },
472
+ // 查询配置文件名
473
+ serviceName: {
474
+ type: String,
475
+ default: () => {
476
+ return ''
477
+ }
478
+ },
479
+ // 查询配置文件Json
480
+ queryParamsJson: {
481
+ type: Object,
482
+ default: null
483
+ },
484
+ // 固定查询表单
485
+ fixedQueryForm: {
486
+ type: Object,
487
+ default: () => {
488
+ return {}
489
+ }
490
+ },
491
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
492
+ showPagination: {
493
+ type: Boolean,
494
+ default: true
495
+ },
496
+ // 是否自定义删除功能
497
+ customDelete: {
498
+ type: Boolean,
499
+ default: false
500
+ },
501
+ // 自适应底部边距
502
+ extraHeight: {
503
+ type: Number,
504
+ default: 80
505
+ },
506
+ pageMaxSize: {
507
+ type: Number,
508
+ default: null
509
+ },
510
+ // 外部传入的选中行keys
511
+ externalSelectedRowKeys: {
512
+ type: Array,
513
+ default: () => []
514
+ }
515
+ },
516
+ computed: {
517
+ ...mapState('setting', ['theme']),
518
+ rowSelection () {
519
+ return this.selectRowMode === 'disabled' ? undefined : {
520
+ selectedRowKeys: this.innerSelectedRowKeys,
521
+ onChange: this.onSelectChange,
522
+ onSelect: this.selectRowMode === 'listView' ? this.onSelect : undefined,
523
+ onSelectAll: this.selectRowMode === 'listView' ? this.onSelectAll : undefined,
524
+ getCheckboxProps: record => ({
525
+ props: {
526
+ disabled: this.selectedDisableRows.includes(record[this.rowKey]), // Column configuration not to be checked
527
+ name: record.name,
528
+ },
529
+ }),
530
+ }
531
+ },
532
+ ...mapState('account', { currUser: 'user' }),
533
+ ...mapState('setting', ['compatible'])
534
+ },
535
+ watch: {
536
+ pageMaxSize: {
537
+ handler (val) {
538
+ this.tableContext.pageMaxSize = val
539
+ },
540
+ immediate: true
541
+ },
542
+ externalSelectedRowKeys: {
543
+ handler (newVal) {
544
+ // 如果新值和当前值相同,则不处理
545
+ if (JSON.stringify(newVal) === JSON.stringify(this.selectedRowKeys)) {
546
+ return
547
+ }
548
+ if (newVal && newVal.length > 0) {
549
+ this.$nextTick(() => {
550
+ this.updateTableSelection(newVal)
551
+ })
552
+ }
553
+ }
554
+ }
555
+ },
556
+ mounted () {
557
+ window.addEventListener('resize', this.handleResize)
558
+ // 初始化时如果有外部选中值,等待 table 准备好后设置
559
+ if (this.externalSelectedRowKeys && this.externalSelectedRowKeys.length > 0) {
560
+ this.$nextTick(() => {
561
+ this.updateTableSelection(this.externalSelectedRowKeys)
562
+ })
563
+ }
564
+ },
565
+ beforeDestroy () {
566
+ // 销毁页面查询定时器
567
+ if (this.queryTimer) {
568
+ clearInterval(this.queryTimer)
569
+ }
570
+ window.removeEventListener('resize', this.handleResize)
571
+ },
572
+ methods: {
573
+ showTempData () {
574
+ this.selectedRowModalVisible = true
575
+ this.$nextTick(() => {
576
+ if (this.$refs.selectedDataTable) {
577
+ // 确保数据已经准备好
578
+ const selectedData = this.selectedRows.map(row => ({ ...row }))
579
+ this.$refs.selectedDataTable.refresh(true)
580
+ // 等待数据加载完成后再更新选中状态
581
+ setTimeout(() => {
582
+ if (this.$refs.selectedDataTable) {
583
+ this.$refs.selectedDataTable.updateSelect(
584
+ selectedData.map(row => row[this.primaryKey || this.rowKey]),
585
+ selectedData
586
+ )
587
+ }
588
+ }, 100)
589
+ }
590
+ })
591
+ },
592
+ customFunctionShow (customFunction, record, cIndex) {
593
+ return executeStrFunctionByContext(this, customFunction, [record, cIndex])
594
+ },
595
+ getConfigByNameAsync,
596
+ runLogic,
597
+ executeStrFunctionByContext,
598
+ columnClick (key, value, record) {
599
+ this.$emit('columnClick', key, value, record)
600
+ },
601
+ gotoUserDetail (key, value, record) {
602
+ this.$emit('gotoUserDetail', key, value, record)
603
+ },
604
+ // 打开行编辑
605
+ openEditMode () {
606
+ this.isEditMode = true
607
+ this.editRowBeforeData = JSON.parse(JSON.stringify(this.getTableData()))
608
+ },
609
+ // 标记行保存
610
+ editRowSave () {
611
+ // 获取最新数据
612
+ const editRowAfterData = this.getTableData()
613
+ const changeData = getChangedData(this.editRowBeforeData, editRowAfterData)
614
+ if (this.eventState?.customSave) {
615
+ this.custom('customSave', {
616
+ tableData: editRowAfterData,
617
+ changeData
618
+ })
619
+ return
620
+ }
621
+ if (changeData.length === 0) {
622
+ this.$message.info('没有数据发生变化')
623
+ } else {
624
+ Modal.confirm({
625
+ title: '是否确认保存?',
626
+ content: `此操作将保存当前行编辑的数据,共修改${changeData.length}条数据`,
627
+ zIndex: 1001,
628
+ onOk: () => {
629
+ return new Promise((resolve, reject) => {
630
+ const requestParameters = {
631
+ queryParamsName: this.queryParamsName,
632
+ changeData: changeData.map(h => getRealKeyData(h)),
633
+ operaInfo: this.currUser.operaInfo
634
+ }
635
+ editRowSave(requestParameters, this.serviceName, this.env === 'dev').then(res => {
636
+ this.$message.success('行内数据保存成功')
637
+ this.isEditMode = false
638
+ this.refresh()
639
+ resolve(res)
640
+ }).catch(e => {
641
+ reject(e)
642
+ this.$message.error('保存失败!')
643
+ })
644
+ })
645
+ },
646
+ onCancel () {
647
+ }
648
+ })
649
+ }
650
+ },
651
+ importExcelOk (data) {
652
+ this.refresh(true)
653
+ this.$emit('importExcelOk', data)
654
+ },
655
+ /**
656
+ * 行选择事件
657
+ * @param row 选中行集合
658
+ * @param attr 表单项属性
659
+ */
660
+ async rowChoose (row, attr, callback, record) {
661
+ // 如果配置了自定义函数
662
+ if (attr.dataChangeFunc) {
663
+ await executeStrFunction(attr.dataChangeFunc, [record, this.setForm, {
664
+ ...attr,
665
+ selectRows: row
666
+ }, util, this.getSelf(), this.mode, runLogic, getConfigByNameAsync])
667
+ } else {
668
+ // 默认填充选中行数据到当前表单
669
+ setDataByRealKey(record, row[0])
670
+ }
671
+ if (callback) {
672
+ callback()
673
+ }
674
+ },
675
+ setForm (record, obj) {
676
+ Object.assign(record, obj)
677
+ this.$forceUpdate()
678
+ },
679
+ handleResize () {
680
+ debounce(() => {
681
+ this.setScrollYHeight({})
682
+ }, 100)()
683
+ },
684
+ isInAModal () {
685
+ let parent = this.$parent
686
+ while (parent) {
687
+ // 检查组件名称,这里假设a-modal组件的名称为AModal,根据实际情况可能需要调整
688
+ if (parent.$options.name === 'AModal') {
689
+ return true
690
+ }
691
+ parent = parent.$parent
692
+ }
693
+ return false
694
+ },
695
+ executeStrFunction,
696
+ // 切换看板模式和表格模式
697
+ changeViewMode () {
698
+ this.isTableMode = !this.isTableMode
699
+ // 看板切换回表格模式 刷新列表
700
+ this.refresh(true)
701
+ },
702
+ /**
703
+ * 初始化表格参数
704
+ */
705
+ init (params) {
706
+ const {
707
+ // 查询参数对象, 用于没有对应查询配置文件名时
708
+ queryParams,
709
+ tableColumns,
710
+ attachGrid,
711
+ expandedGrid,
712
+ buttonState,
713
+ eventState = {},
714
+ buttonPermissions,
715
+ editButtonStateData = [],
716
+ title,
717
+ form,
718
+ tableSummaryMap = {},
719
+ customTableSummaryArray = [],
720
+ viewMode,
721
+ localEditMode,
722
+ formSubmitTypeInLocalEditMode = 'cover',
723
+ rowSelectMode,
724
+ allowSelectRowNum = 0,
725
+ formItems,
726
+ env = 'prod',
727
+ createdQuery = true,
728
+ createdEditMode = false,
729
+ primaryKey,
730
+ allowedCardMode = false,
731
+ simpleMode = false,
732
+ showRightTools = true,
733
+ cardModeConfig,
734
+ summaryUpdate,
735
+ summaryDrawerWidth = 35,
736
+ chartsConfigArray = [],
737
+ printTemplate = 'DEFAULT_CRUD_PRINT_TEMPLATE',
738
+ selectRowMode = 'default',
739
+ tableSize = 'default',
740
+ clearSelectRowAfterQuery = false
741
+ } = params
742
+ this.showSummary = Object.keys(tableSummaryMap).length > 0
743
+ if (this.showSummary) {
744
+ Object.keys(tableSummaryMap).forEach(item => {
745
+ this.summaryData.push({
746
+ key: item,
747
+ title: tableSummaryMap[item],
748
+ value: ' ',
749
+ loading: true,
750
+ success: false
751
+ })
752
+ })
753
+ }
754
+ if (customTableSummaryArray.length > 0) {
755
+ customTableSummaryArray.forEach(item => {
756
+ this.summaryData.push({
757
+ key: item.key,
758
+ title: item.title,
759
+ value: ' ',
760
+ loading: true,
761
+ success: false
762
+ })
763
+ })
764
+ this.showCustomSummary = true
765
+ this.customSummaryArray = customTableSummaryArray
766
+ }
767
+ this.queryParams = queryParams
768
+ this.tableColumns = JSON.parse(JSON.stringify(tableColumns))
769
+ if (this.tableColumns.length === 0) {
770
+ return
771
+ }
772
+ this.attachGrid = attachGrid
773
+ this.expandedGrid = expandedGrid
774
+ this.viewMode = viewMode
775
+ this.localEditMode = localEditMode
776
+ this.formSubmitTypeInLocalEditMode = formSubmitTypeInLocalEditMode
777
+ this.rowSelectMode = rowSelectMode
778
+ this.allowSelectRowNum = allowSelectRowNum
779
+ this.simpleMode = simpleMode
780
+ this.formItems = formItems
781
+ this.user = this.currUser
782
+ this.createdQuery = createdQuery
783
+ this.primaryKey = primaryKey
784
+ this.buttonState = buttonState
785
+ this.eventState = eventState
786
+ this.showRightTools = showRightTools
787
+ this.printTemplate = printTemplate
788
+ this.summaryDrawerWidth = summaryDrawerWidth
789
+ this.chartsConfigArray = chartsConfigArray
790
+ this.selectRowMode = selectRowMode
791
+ this.tableSize = tableSize
792
+ this.clearSelectRowAfterQuery = clearSelectRowAfterQuery
793
+ if (this.chartsConfigArray.length > 0) {
794
+ // 循环chartsConfigArray,将每个配置的数据请求参数赋值给requestParameters
795
+ this.chartsConfigArray.forEach(item => {
796
+ item.config.queryParams = JSON.parse(JSON.stringify(this.queryParams))
797
+ item.config.queryParamsName = this.queryParamsName
798
+ })
799
+ }
800
+ if (this.localEditMode) {
801
+ this.localEditModeDataSource = []
802
+ if (this.formSubmitTypeInLocalEditMode === 'append') {
803
+ this.isLocalDataSourceLoadedExternally = true
804
+ const defaultItem = {}
805
+ defaultItem['序号'] = 0
806
+ this.localEditModeDataSource.push(defaultItem)
807
+ } else {
808
+ this.isLocalDataSourceLoadedExternally = false
809
+ }
810
+ this.buttonState.import = false
811
+ this.buttonState.export = false
812
+ this.showRightTools = false
813
+ }
814
+ if (this.rowSelectMode) {
815
+ this.buttonState = {
816
+ choose: true
817
+ }
818
+ this.showRightTools = false
819
+ }
820
+ this.buttonPermissions = buttonPermissions
821
+ this.editButtonStateData = editButtonStateData
822
+ this.title = title
823
+ this.env = env
824
+ this.rowKey = this.getPrimaryKeyName()
825
+ this.allowedCardMode = allowedCardMode
826
+ this.cardModeConfig = cardModeConfig
827
+ this.summaryUpdate = summaryUpdate
828
+ this.isEditMode = createdEditMode
829
+ let totalWidth = 0
830
+ for (let i = 0; i < this.tableColumns.length; i++) {
831
+ const item = this.tableColumns[i]
832
+ // 设置操作列
833
+ if (item.slotType === 'action') {
834
+ item.fixed = 'right'
835
+ item.width = 70
836
+ }
837
+ // 设置表格宽度
838
+ if (item.width) {
839
+ totalWidth = totalWidth + item.width
840
+ } else {
841
+ totalWidth = totalWidth + 180
842
+ }
843
+ }
844
+ // 横向滚动长度大于所有宽度,才能实现固定表头
845
+ this.scrollXWidth = totalWidth
846
+ // 加载筛选列完成
847
+ this.columnSelectLoaded = true
848
+ this.setQueryForm(form || {})
849
+ // 简易模式,并且是看板模式,默认直接进入看板模式
850
+ if (this.allowedCardMode && this.simpleMode) {
851
+ this.isTableMode = false
852
+ }
853
+ if (params.queryInterval) {
854
+ this.queryTimer = setInterval(() => {
855
+ this.refresh()
856
+ }, params.queryInterval * 1000)
857
+ }
858
+ },
859
+ // 操作面板按钮渲染
860
+ buttonRendering (button) {
861
+ if (!this.buttonPermissions) {
862
+ return true
863
+ }
864
+ try {
865
+ const existingItem = this.buttonPermissions.find(item => item.btnName === button)
866
+ const rolestr = this.currUser.rolestr?.split(',')
867
+ if (existingItem?.state) {
868
+ const currUserRole = existingItem.roleStr
869
+ return rolestr.some(item => currUserRole && currUserRole.includes(item))
870
+ } else {
871
+ return true
872
+ }
873
+ } catch (e) {
874
+ console.error(e)
875
+ return false
876
+ }
877
+ },
878
+ // 防止查询多次点击处理
879
+ loadTableData (requestParameters) {
880
+ if (this.queryPromise) {
881
+ return this.queryPromise
882
+ }
883
+ this.queryPromise = this.loadTableDataGen(requestParameters).finally(() => {
884
+ this.queryPromise = undefined
885
+ })
886
+ return this.queryPromise
887
+ },
888
+ /**
889
+ * 加载表格数据
890
+ * @param requestParameters 请求参数
891
+ */
892
+ async loadTableDataGen (requestParameters) {
893
+ let result
894
+ if (this.localEditMode) {
895
+ if (!this.isLocalDataSourceLoadedExternally && requestParameters?.conditionParams && Object.keys(requestParameters?.conditionParams).length > 0) {
896
+ const result = await query(Object.assign(requestParameters, { userId: this.currUser?.id }),
897
+ this.serviceName, this.env === 'dev')
898
+ if (result.data) {
899
+ let no = 0
900
+ this.localEditModeDataSource = result.data.map(item => {
901
+ item['序号'] = no
902
+ no++
903
+ return item
904
+ })
905
+ }
906
+ this.isLocalDataSourceLoadedExternally = true
907
+ }
908
+ result = new Promise((resolve) => {
909
+ resolve({
910
+ data: this.localEditModeDataSource
911
+ })
912
+ })
913
+ } else {
914
+ result = query(Object.assign(requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
915
+ result.then(res => {
916
+ this.totalCount = res.totalCount || 0
917
+ // 在数据加载完成后,立即检查并更新选中状态
918
+ if (this.selectRowMode !== 'disabled' && !this.clearSelectRowAfterQuery) {
919
+ // 找出当前页中应该被选中的行
920
+ const currentPageSelectedRows = res.data.filter(row =>
921
+ this.selectedRowKeys.includes(row[this.primaryKey || this.rowKey])
922
+ )
923
+ // 更新表格的选中状态
924
+ this.$nextTick(() => {
925
+ // 更新内部选中状态
926
+ this.innerSelectedRowKeys = currentPageSelectedRows.map(row => row[this.primaryKey || this.rowKey])
927
+ this.innerSelectedRows = currentPageSelectedRows
928
+ // 更新表格显示
929
+ this.$refs.table.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
930
+ // 更新总选中状态
931
+ if (currentPageSelectedRows.length > 0) {
932
+ // 保留不在当前页面的已选中行
933
+ const otherPageSelectedRows = this.selectedRows.filter(row =>
934
+ !currentPageSelectedRows.some(currentRow =>
935
+ currentRow[this.primaryKey || this.rowKey] === row[this.primaryKey || this.rowKey]
936
+ )
937
+ )
938
+ // 合并当前页面和其他页面的选中行
939
+ this.selectedRows = [...otherPageSelectedRows, ...currentPageSelectedRows]
940
+ }
941
+ this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
942
+ })
943
+ }
944
+ })
945
+ }
946
+
947
+ if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery) {
948
+ this.$refs.table.updateSelect(this.selectedRowKeys, this.selectedRows)
949
+ } else if (this.isTableMode && !this.simpleMode) {
950
+ this.clearRowKeys()
951
+ }
952
+ this.$emit('afterQuery', result, requestParameters.conditionParams)
953
+ return result
954
+ },
955
+ /**
956
+ * 操作列事件
957
+ * @param record 本条数据
958
+ * @param actionType 操作类型
959
+ * @param func 事件默认 action
960
+ * @param index 行下标
961
+ */
962
+ action (record, actionType, func = 'action', index) {
963
+ this.$emit('action', record, record[this.getPrimaryKeyName()], actionType, func, index)
964
+ },
965
+ // 看板点击事件
966
+ handleCardEmit (data, eventName) {
967
+ this.action(data, undefined, eventName)
968
+ },
969
+ /**
970
+ * 选择列勾选改变事件
971
+ * @param record 被选择的列数据
972
+ * @param selected 是否选中
973
+ * @param selectedRows 被选择的列集合
974
+ * @param nativeEvent 原生事件
975
+ */
976
+ onSelect (record, selected, selectedRows, nativeEvent) {
977
+ if (this.selectRowMode === 'listView') {
978
+ // 获取主键数据
979
+ const primaryData = record[this.primaryKey]
980
+ // 取消勾选时
981
+ if (!selected) {
982
+ this.selectedRowKeys = this.selectedRowKeys.filter(item => item !== primaryData)
983
+ this.selectedRows = this.selectedRows.filter(item => item[this.primaryKey] !== primaryData)
984
+ }
985
+ }
986
+ },
987
+ /**
988
+ * 选择列全选事件
989
+ * @param selected 是否选中
990
+ * @param selectedRows 被选择的列集合
991
+ * @param changeRows 改变的行集合
992
+ */
993
+ onSelectAll (selected, selectedRows, changeRows) {
994
+ console.log('onSelectAll', selected, selectedRows, changeRows)
995
+ if (this.selectRowMode === 'listView') {
996
+ if (!selected) {
997
+ // 获取所有改变的key
998
+ const changeKeys = changeRows.map(item => item[this.primaryKey])
999
+ this.selectedRowKeys = this.selectedRowKeys.filter(item => !changeKeys.includes(item))
1000
+ this.selectedRows = this.selectedRows.filter(item => !changeKeys.includes(item[this.primaryKey]))
1001
+ }
1002
+ }
1003
+ },
1004
+ /**
1005
+ * 选择列数据改变事件
1006
+ * @param currentPageSelectedKeys 被选择的列Key集合
1007
+ * @param currentPageSelectedRows 被选择的列集合
1008
+ */
1009
+ onSelectChange (currentPageSelectedKeys, currentPageSelectedRows) {
1010
+ console.log('currentPageSelectedKeys', currentPageSelectedKeys)
1011
+ // 这里的 currentPageSelectedKeys 和 currentPageSelectedRows 是当前页选中状态改变后的数据
1012
+ if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery) {
1013
+ if (this.primaryKey) {
1014
+ const primaryKeyName = this.primaryKey || this.rowKey
1015
+ // 获取当前页面所有行的key
1016
+ const currentPageAllKeys = this.$refs.table.localDataSource.map(row => row[primaryKeyName])
1017
+ // 找出当前页新选中的 keys (之前未选中但现在选中了)
1018
+ const newlySelectedKeysOnPage = currentPageSelectedKeys.filter(key => !this.selectedRowKeys.includes(key))
1019
+ // 找出当前页被取消选中的 keys (之前选中但现在未选中了)
1020
+ const deselectedKeysOnPage = this.selectedRowKeys.filter(key => currentPageAllKeys.includes(key) && !currentPageSelectedKeys.includes(key))
1021
+ // 更新总的 selectedRowKeys: 移除被取消选中的,添加新选中的
1022
+ this.selectedRowKeys = this.selectedRowKeys.filter(key => !deselectedKeysOnPage.includes(key))
1023
+ this.selectedRowKeys = [...this.selectedRowKeys, ...newlySelectedKeysOnPage]
1024
+ // 更新总的 selectedRows: 移除被取消选中的行对象,添加新选中的行对象
1025
+ // 从当前页数据源中找到被取消选中的行对象
1026
+ const deselectedRowsOnPage = this.$refs.table.localDataSource.filter(row => deselectedKeysOnPage.includes(row[primaryKeyName]))
1027
+ // 移除被取消选中的行对象
1028
+ const selectedRowsWithoutDeselected = this.selectedRows.filter(row => !deselectedRowsOnPage.some(deselectedRow => deselectedRow[primaryKeyName] === row[primaryKeyName]))
1029
+ // 从当前页数据源中找到新选中的行对象
1030
+ const newlySelectedRowsOnPage = this.$refs.table.localDataSource.filter(row => newlySelectedKeysOnPage.includes(row[primaryKeyName]))
1031
+ // 添加新选中的行对象 (需要去重,以防其他页面已包含此行)
1032
+ const finalSelectedRows = [...selectedRowsWithoutDeselected]
1033
+ const finalSelectedRowKeysMap = new Map()
1034
+ for (const row of finalSelectedRows) {
1035
+ finalSelectedRowKeysMap.set(row[primaryKeyName], true)
1036
+ }
1037
+
1038
+ for (const row of newlySelectedRowsOnPage) {
1039
+ const key = row[primaryKeyName]
1040
+ if (!finalSelectedRowKeysMap.has(key)) {
1041
+ finalSelectedRowKeysMap.set(key, true)
1042
+ finalSelectedRows.push(row)
1043
+ }
1044
+ }
1045
+ this.selectedRows = finalSelectedRows
1046
+ } else {
1047
+ // 如果没有主键,则直接使用当前选中的行(此情况可能无法跨页选中,但为了兼容保留)
1048
+ this.selectedRowKeys = currentPageSelectedKeys
1049
+ this.selectedRows = currentPageSelectedRows
1050
+ }
1051
+ } else {
1052
+ // 非 listView 模式或 clearSelectRowAfterQuery 为 true,直接使用当前页的选中状态作为总状态
1053
+ this.selectedRowKeys = currentPageSelectedKeys
1054
+ this.selectedRows = currentPageSelectedRows
1055
+ }
1056
+
1057
+ // 更新内部状态和表格显示 (即使在 listView 模式下,内部状态也需要同步以更新表格显示)
1058
+ this.innerSelectedRowKeys = currentPageSelectedKeys
1059
+ this.innerSelectedRows = currentPageSelectedRows
1060
+ // 确保在DOM更新后调用 updateSelect,以正确反映当前页的选中状态
1061
+ this.$nextTick(() => {
1062
+ this.$refs.table.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
1063
+ })
1064
+
1065
+ // 更新按钮状态基于总选中数量
1066
+ this.isModify = this.selectedRowKeys.length === 1
1067
+ this.isDelete = this.selectedRowKeys.length > 0
1068
+ this.isChoose = this.allowSelectRowNum === 0 ? this.selectedRowKeys.length > 0 : this.selectedRowKeys.length === this.allowSelectRowNum
1069
+
1070
+ // 触发选择事件,传递总的选中数据
1071
+ this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
1072
+ },
1073
+ /**
1074
+ * 清除表格选中项
1075
+ */
1076
+ clearRowKeys () {
1077
+ this.$refs.table.clearSelected()
1078
+ },
1079
+ /**
1080
+ * 为表格附加查询条件
1081
+ */
1082
+ setQueryForm (form = {}) {
1083
+ this.form = form
1084
+ if (this.createdQuery) {
1085
+ this.refresh(true)
1086
+ } else {
1087
+ this.createdQuery = true
1088
+ }
1089
+ },
1090
+ /**
1091
+ * 表格重新加载方法
1092
+ * 如果参数为 true, 则强制刷新到第一页
1093
+ */
1094
+ refresh (bool) {
1095
+ this.$nextTick(() => {
1096
+ this.$refs.table.refresh(bool)
1097
+ })
1098
+ },
1099
+ setScrollYHeight ({ extraHeight = this.extraHeight, id = this.uniqueId, type = '' }) {
1100
+ this.$nextTick(() => {
1101
+ setTimeout(() => {
1102
+ const curDocument = window?.rawDocument || document
1103
+ const innerHeight = window?.rawWindow?.innerHeight || window.innerHeight || 0
1104
+ if (typeof extraHeight == 'undefined') {
1105
+ // 默认底部分页32 + 边距48
1106
+ extraHeight = 48 + 32
1107
+ }
1108
+ let tHeader = null
1109
+ if (id) {
1110
+ tHeader = curDocument.getElementById(id) ? curDocument.getElementById(id).getElementsByClassName('ant-table-thead')[0] : null
1111
+ } else {
1112
+ tHeader = curDocument.getElementsByClassName('ant-table-thead')[0]
1113
+ }
1114
+ // 表格内容距离顶部的距离
1115
+ let tHeaderBottom = 0
1116
+ if (tHeader) {
1117
+ tHeaderBottom = tHeader.getBoundingClientRect().bottom
1118
+ }
1119
+ if (tHeaderBottom === 0) {
1120
+ this.scrollYHeight = 'calc(100vh - 31rem)'
1121
+ if (window.__MICRO_APP_ENVIRONMENT__) {
1122
+ this.scrollYHeight = 'calc(100vh - 28.5rem)'
1123
+ }
1124
+ return
1125
+ }
1126
+
1127
+ // 判断是否在 modal
1128
+ if (this.isInAModal()) {
1129
+ let modalElement = null
1130
+ if (tHeader) {
1131
+ modalElement = tHeader.closest('.ant-modal-body')
1132
+ } else {
1133
+ modalElement = curDocument.querySelector('.ant-modal-body')
1134
+ }
1135
+ if (modalElement) {
1136
+ const modalRect = modalElement.getBoundingClientRect()
1137
+ // 48 是 modal 通常的边距 32 是分页
1138
+ extraHeight = innerHeight - modalRect.bottom + 32 + 48
1139
+ }
1140
+ }
1141
+ if (innerHeight - (tHeaderBottom + extraHeight) < 210) {
1142
+ this.scrollYHeight = 'calc(100vh - 31rem)'
1143
+ return
1144
+ }
1145
+ // 窗体高度-表格内容顶部的高度-表格内容底部的高度
1146
+ // this.scrollYHeight = document.body.clientHeight - tHeaderBottom - extraHeight
1147
+ this.scrollYHeight = `calc(100vh - ${tHeaderBottom + extraHeight}px)`
1148
+ }, 60)
1149
+ })
1150
+ },
1151
+ /**
1152
+ * 获取主键列名称
1153
+ */
1154
+ getPrimaryKeyName () {
1155
+ if (this.primaryKey) {
1156
+ return this.primaryKey
1157
+ }
1158
+ const indexColumn = this.tableColumns.find(i => i?.slotType === 'index')
1159
+ return indexColumn ? indexColumn.dataIndex : this.tableColumns[0].dataIndex
1160
+ },
1161
+ handleExport (type) {
1162
+ this.$refs.exportExcel.handleExport(type, this.title)
1163
+ },
1164
+ handlePrint (type) {
1165
+ const printData = {
1166
+ title: this.title,
1167
+ form: this.form,
1168
+ operaInfo: this.currUser.operaInfo,
1169
+ operaTime: moment().format('YYYY-MM-DD HH:mm:ss'),
1170
+ summary: this.retrieveSummaryData
1171
+ }
1172
+ this.$refs.exportExcel.handlePrint(type, printData)
1173
+ },
1174
+ validateTableAndSyncData (currRow, defaultAppendRowData) {
1175
+ let isLastRow = false
1176
+ if (this.localEditModeDataSource.length === 0) {
1177
+ isLastRow = true
1178
+ } else if (currRow['序号'] === this.localEditModeDataSource[this.localEditModeDataSource.length - 1]['序号']) {
1179
+ isLastRow = true
1180
+ }
1181
+ if (isLastRow) {
1182
+ this.appendLocalData(defaultAppendRowData)
1183
+ }
1184
+ },
1185
+ // 新增业务
1186
+ add () {
1187
+ if (this.eventState?.customAdd) {
1188
+ this.custom('customAdd', {})
1189
+ return
1190
+ }
1191
+ if (this.localEditMode && this.isEditMode) {
1192
+ this.appendLocalData({})
1193
+ } else {
1194
+ this.$emit('add')
1195
+ }
1196
+ },
1197
+ // 添加业务
1198
+ move () {
1199
+ this.$emit('move')
1200
+ },
1201
+ // 通用事件业务
1202
+ custom (func) {
1203
+ this.$emit('customEvent', func)
1204
+ },
1205
+ // 编辑业务
1206
+ edit (id) {
1207
+ this.editLoading = true
1208
+ this.getEditData(id).then(modifyModelData => {
1209
+ if (this.eventState?.customEdit) {
1210
+ this.custom('customEdit', { id, modifyModelData })
1211
+ return
1212
+ }
1213
+ this.$emit('edit', modifyModelData)
1214
+ this.editLoading = false
1215
+ })
1216
+ },
1217
+ // 行选择业务
1218
+ choose () {
1219
+ if (this.isChoose) {
1220
+ // 如果配置了自定义函数
1221
+ this.$emit('rowChoose', this.selectedRows)
1222
+ } else {
1223
+ this.$message.warning(this.allowSelectRowNum === 0 ? '请选择数据' : `请选择${this.allowSelectRowNum}条数据`)
1224
+ }
1225
+ },
1226
+ // 自定义按钮点击
1227
+ editButtonStateDataClick (index) {
1228
+ this.$emit('editButtonStateDataClick', this.editButtonStateData[index].functionName, this.selectedRows)
1229
+ },
1230
+ // 获取被编辑的数据
1231
+ getEditData (id) {
1232
+ if (!id) {
1233
+ this.selectId = this.selectedRowKeys[0]
1234
+ } else {
1235
+ this.selectId = id
1236
+ }
1237
+ const primaryKeyName = this.getPrimaryKeyName()
1238
+ if (this.tableColumns[0].dataIndex !== primaryKeyName) {
1239
+ this.selectId = this.selectedRows[0][primaryKeyName]
1240
+ }
1241
+ // 将更新需要的主键值加入到primaryKeyData中
1242
+ const primaryKeyData = {}
1243
+ primaryKeyData[primaryKeyName] = this.selectId
1244
+ if (this.localEditMode) {
1245
+ return new Promise((resolve) => {
1246
+ const modifyData = this.getDataByRowKeyValue(this.selectId)
1247
+ resolve({
1248
+ data: modifyData,
1249
+ primaryKeyData: primaryKeyData
1250
+ })
1251
+ })
1252
+ }
1253
+ const requestParameters = {
1254
+ queryParamsName: this.queryParamsName,
1255
+ queryParams: this.queryParams && Object.keys(this.queryParams).length > 0 ? this.queryParams : undefined,
1256
+ conditionParams: {},
1257
+ pageNo: 1,
1258
+ pageSize: 1
1259
+ }
1260
+ requestParameters.conditionParams[primaryKeyName] = this.selectId
1261
+ requestParameters.f_businessid = this.selectId
1262
+ return queryWithResource(requestParameters, this.serviceName, this.env === 'dev').then(res => {
1263
+ return { data: res.data[0], primaryKeyData: primaryKeyData, images: res.images, files: res.files }
1264
+ })
1265
+ },
1266
+ // 删除业务
1267
+ deleteItem () {
1268
+ if (this.viewMode) {
1269
+ this.$message.info('预览模式禁止删除')
1270
+ return
1271
+ }
1272
+ Modal.confirm({
1273
+ title: '提示',
1274
+ content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
1275
+ zIndex: 1001,
1276
+ onOk: () => {
1277
+ const requestParameters = {
1278
+ queryParamsName: this.queryParamsName,
1279
+ idList: this.selectedRowKeys
1280
+ }
1281
+ if (this.eventState?.customDelete) {
1282
+ this.custom('customDelete', {
1283
+ selectedRowKeys: this.selectedRowKeys,
1284
+ selectedRows: this.selectedRows
1285
+ })
1286
+ return
1287
+ }
1288
+ return new Promise((resolve, reject) => {
1289
+ if (this.localEditMode) {
1290
+ this.localEditModeDataSource = this.getLocalData().filter(item => !this.selectedRowKeys.includes(item[this.rowKey]))
1291
+ resolve(200)
1292
+ this.$message.success('删除成功!')
1293
+ this.refresh(true)
1294
+ // afterDelete
1295
+ this.$emit('afterDelete', requestParameters)
1296
+ } else if (this.customDelete) {
1297
+ this.$emit('del', this.selectedRows, resolve)
1298
+ } else {
1299
+ remove(requestParameters, this.serviceName, this.env === 'dev').then(res => {
1300
+ resolve(res)
1301
+ this.$message.success('删除成功!')
1302
+ this.refresh(true)
1303
+ // afterDelete
1304
+ this.$emit('afterDelete', requestParameters)
1305
+ }).catch(e => {
1306
+ reject(e)
1307
+ this.$message.error('删除失败!')
1308
+ })
1309
+ }
1310
+ })
1311
+ },
1312
+ onCancel () {
1313
+ }
1314
+ })
1315
+ },
1316
+ // 导入业务
1317
+ importData () {
1318
+ this.$refs.importExcel.importExcelHandleOpen()
1319
+ },
1320
+ afterVisibleChange (val) {
1321
+ if (val) {
1322
+ this.retrieveSummaryData()
1323
+ }
1324
+ },
1325
+ async retrieveSummaryData () {
1326
+ const promises = []
1327
+
1328
+ if (this.requestParameters.querySummary) {
1329
+ const querySummaryPromise = querySummary(Object.assign(this.requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
1330
+ .then(res => {
1331
+ if (this.compatible === 'V3') {
1332
+ res = res.data
1333
+ }
1334
+ if (res.length > 0) {
1335
+ this.summaryData.forEach(item => {
1336
+ res.forEach(summary => {
1337
+ if (item.title === summary.title) {
1338
+ item.value = summary.value
1339
+ item.success = true
1340
+ item.loading = false
1341
+ }
1342
+ })
1343
+ })
1344
+ }
1345
+ })
1346
+ promises.push(querySummaryPromise)
1347
+ }
1348
+
1349
+ if (this.showCustomSummary) {
1350
+ this.customSummaryArray.forEach(item => {
1351
+ const runLogicPromise = runLogic(item.source, Object.assign(this.requestParameters, { userId: this.currUser?.id }), this.serviceName, this.env === 'dev')
1352
+ .then(res => {
1353
+ this.summaryData.forEach(summary => {
1354
+ if (item.key === summary.key) {
1355
+ summary.value = res.value
1356
+ summary.success = true
1357
+ summary.loading = false
1358
+ }
1359
+ })
1360
+ })
1361
+ .catch(e => {
1362
+ this.summaryData.forEach(summary => {
1363
+ if (item.key === summary.key) {
1364
+ summary.value = 0
1365
+ summary.success = false
1366
+ summary.loading = false
1367
+ }
1368
+ })
1369
+ })
1370
+ promises.push(runLogicPromise)
1371
+ })
1372
+ }
1373
+
1374
+ await Promise.all(promises)
1375
+ return this.summaryData
1376
+ },
1377
+ showDrawer () {
1378
+ if (this.summaryUpdate) {
1379
+ this.summaryData.forEach(item => {
1380
+ item.loading = true
1381
+ item.success = false
1382
+ item.value = ' '
1383
+ })
1384
+ this.summaryDrawerVisible = true
1385
+ } else {
1386
+ this.$message.warning('请查询后再来查看')
1387
+ }
1388
+ },
1389
+ onClose () {
1390
+ this.summaryDrawerVisible = false
1391
+ },
1392
+ // 获取表格内所有数据
1393
+ getTableData () {
1394
+ return this.$refs.table.localDataSource
1395
+ },
1396
+ // 设置表格内数据
1397
+ setTableData (data) {
1398
+ if (this.localEditMode) {
1399
+ // 本地编辑模式下,需要修改 localEditModeDataSource
1400
+ this.localEditModeDataSource = data.map((item, index) => ({
1401
+ ...item,
1402
+ 序号: index + 1
1403
+ }))
1404
+ this.$nextTick(() => {
1405
+ this.$refs.table?.refresh()
1406
+ })
1407
+ } else {
1408
+ // 普通模式
1409
+ this.$nextTick(() => {
1410
+ if (this.$refs.table) {
1411
+ this.$refs.table.setLocalDataSource(data)
1412
+ }
1413
+ })
1414
+ }
1415
+ },
1416
+ // 获取所有本地数据
1417
+ getLocalData () {
1418
+ return this.localEditModeDataSource
1419
+ },
1420
+ // 获取指定rowKey的value的本地数据
1421
+ getDataByRowKeyValue (rowKeyValue) {
1422
+ return this.getLocalData().find(item => {
1423
+ return item[this.rowKey] === rowKeyValue
1424
+ })
1425
+ },
1426
+ // 修改本地数据
1427
+ modifyLocalData (rowKeyValue, data) {
1428
+ const modifyItem = this.getDataByRowKeyValue(rowKeyValue)
1429
+ if (modifyItem) {
1430
+ Object.assign(modifyItem, data)
1431
+ }
1432
+ },
1433
+ // 追加本地数据
1434
+ appendLocalData (item) {
1435
+ if (this.localEditModeDataSource.length === 0) {
1436
+ item['序号'] = 1
1437
+ } else {
1438
+ item['序号'] = this.localEditModeDataSource[this.localEditModeDataSource.length - 1]['序号'] + 1
1439
+ }
1440
+ this.localEditModeDataSource.push(item)
1441
+ },
1442
+ handleRowClick (record) {
1443
+ this.$emit('rowClick', record)
1444
+ },
1445
+ beforeDataChange (record) {
1446
+ this.$emit('beforeDataChange', record)
1447
+ },
1448
+ onExpand (expanded, record) {
1449
+ this.$emit('expand', expanded, record)
1450
+ },
1451
+ // 添加新方法处理表格选中状态
1452
+ updateTableSelection (selectedKeys) {
1453
+ console.log('selectedKeys', selectedKeys)
1454
+ if (!this.$refs.table) {
1455
+ return
1456
+ }
1457
+
1458
+ // 检查数据是否已加载
1459
+ if (!this.$refs.table.localDataSource || this.$refs.table.localDataSource.length === 0) {
1460
+ // 等待数据加载完成后再处理
1461
+ const checkDataLoaded = () => {
1462
+ if (this.$refs.table.localDataSource && this.$refs.table.localDataSource.length > 0) {
1463
+ this.doUpdateTableSelection(selectedKeys)
1464
+ } else {
1465
+ setTimeout(checkDataLoaded, 100)
1466
+ }
1467
+ }
1468
+ checkDataLoaded()
1469
+ return
1470
+ }
1471
+
1472
+ this.doUpdateTableSelection(selectedKeys)
1473
+ },
1474
+
1475
+ // 实际执行更新选中状态的方法
1476
+ doUpdateTableSelection (selectedKeys) {
1477
+ // 更新内部选中状态
1478
+ this.selectedRowKeys = [...selectedKeys]
1479
+ this.innerSelectedRowKeys = [...selectedKeys]
1480
+ // 根据 selectedRowKeys 找到对应的行数据
1481
+ this.selectedRows = this.$refs.table.localDataSource.filter(row =>
1482
+ selectedKeys.includes(row[this.primaryKey || this.rowKey])
1483
+ )
1484
+ // 更新表格选中状态
1485
+ if (this.selectRowMode !== 'disabled' && !this.clearSelectRowAfterQuery) {
1486
+ this.$refs.table.updateSelect(this.selectedRowKeys, this.selectedRows)
1487
+ } else if (this.isTableMode && !this.simpleMode) {
1488
+ this.clearRowKeys()
1489
+ }
1490
+ // 更新按钮状态
1491
+ this.isModify = this.innerSelectedRowKeys.length === 1
1492
+ this.isDelete = this.innerSelectedRowKeys.length > 0
1493
+ this.isChoose = this.allowSelectRowNum === 0 ? this.innerSelectedRowKeys.length > 0 : this.innerSelectedRowKeys.length === this.allowSelectRowNum
1494
+
1495
+ // 触发选择事件
1496
+ this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
1497
+ }
1498
+ }
1499
+ }
1500
+ </script>
1501
+ <style lang="less" scoped>
1502
+
1503
+ .custom-chart-title {
1504
+ font-size: 16px;
1505
+ font-weight: 700;
1506
+ margin-bottom: 8px;
1507
+ }
1508
+
1509
+ .custom-chart-desc {
1510
+ font-size: 12px;
1511
+ color: rgba(0, 0, 0, .45);
1512
+ margin-bottom: 16px;
1513
+ }
1514
+
1515
+ :deep(.ant-table-thead > tr > th) {
1516
+ font-weight: 600;
1517
+ }
1518
+
1519
+ :deep(.table-wrapper .ant-pagination) {
1520
+ display: flex;
1521
+ flex-direction: row;
1522
+ align-items: center;
1523
+ padding: 0;
1524
+ }
1525
+
1526
+ :deep(.table-wrapper .ant-pagination .ant-pagination-total-text) {
1527
+ white-space: nowrap;
1528
+ }
1529
+
1530
+ :deep(.ant-table td) {
1531
+ white-space: nowrap;
1532
+ }
1533
+
1534
+ .footer_sum_title {
1535
+ color: @primary-color;
1536
+ font-weight: bold;
1537
+ }
1538
+
1539
+ .footer_sum_item {
1540
+ white-space: nowrap;
1541
+ }
1542
+
1543
+ .ant-btn-hover {
1544
+ border-color: @primary-color;
1545
+ color: @primary-color;
1546
+ }
1547
+
1548
+ .innerTable {
1549
+ :deep(.ant-form-item) {
1550
+ margin: 0;
1551
+ }
1552
+ }
1553
+ </style>