vue2-client 1.10.35 → 1.11.1

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,868 +1,868 @@
1
- <template>
2
- <a-row type="flex" :gutter="{ xs: 8, sm: 10, md: 12, lg: 16 }">
3
- <a-col
4
- :xs="14"
5
- :sm="14"
6
- :md="12"
7
- :lg="9"
8
- :xl="6"
9
- :xxl="5"
10
- v-if="xTreeConfigName"
11
- :style="{ maxWidth: '400px'}">
12
- <x-tree-pro
13
- :config-name="xTreeConfigName"
14
- :env="env"
15
- @action="action"
16
- @btnFuncClick="treeBtnFuncClick"
17
- @treeOnChecked="treeOnChecked"
18
- ref="xtree"
19
- ></x-tree-pro>
20
- </a-col>
21
- <a-col
22
- :xs="xTreeConfigName ? 10 : 24"
23
- :sm="xTreeConfigName ? 10 : 24"
24
- :md="xTreeConfigName ? 12 : 24"
25
- :lg="xTreeConfigName ? 15 : 24"
26
- :xl="xTreeConfigName ? 18 : 24"
27
- :xxl="xTreeConfigName ? 19 : 24">
28
- <a-skeleton :loading="loading" :paragraph="{ rows: 4 }"/>
29
- <a-row style="height: 12px" v-if="xTreeConfigName"></a-row>
30
- <div v-show="!loading">
31
- <template v-if="!loadError">
32
- <x-add-form
33
- ref="xAddForm"
34
- @onLocalSubmit="onLocalSubmit"
35
- @x-form-item-emit-func="emitFunc"
36
- @afterSubmit="onAddOrEditSubmitAfterSubmit"
37
- >
38
- <template slot="groupFormItems" slot-scope="{form, model, rules, modifyModelData}">
39
- <slot
40
- name="groupFormItems"
41
- :form="form"
42
- :model="model"
43
- :rules="rules"
44
- :modifyModelData="modifyModelData"></slot>
45
- </template>
46
- </x-add-form>
47
- <x-add-report
48
- v-if="moveType"
49
- ref="xAddReport"
50
- >
51
- </x-add-report>
52
- <div v-if="crudTitle" class="crud_title">
53
- {{ crudTitle }}
54
- </div>
55
- <x-form
56
- ref="xForm"
57
- @toggleAdvanced="toggleAdvanced"
58
- @onSubmit="onSearchSubmit">
59
- <slot name="formBtnExpand"></slot>
60
- </x-form>
61
- <x-table
62
- ref="xTable"
63
- :fixedQueryForm="fixedQueryForm"
64
- :queryParamsName="queryParamsName"
65
- :query-params-json="queryParamsJson"
66
- :show-pagination="showPagination"
67
- :customDelete="customDelete"
68
- :extraHeight="extraHeight"
69
- :serviceName="serviceName"
70
- @add="add"
71
- @move="move"
72
- @edit="edit"
73
- @del="del"
74
- @rowChoose="rowChoose"
75
- @customEvent="customEvent"
76
- @afterDelete="afterDelete"
77
- @action="action"
78
- @selectRow="selectRow"
79
- @afterQuery="afterQuery"
80
- @columnClick="columnClick"
81
- @gotoUserDetail="gotoUserDetail"
82
- @editButtonStateDataClick="editButtonStateDataClick"
83
- @importExcelOk="importExcelOk">
84
- <template slot="leftButton" slot-scope="{selectedRowKeys, selectedRows}">
85
- <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
86
- </template>
87
- <template slot="button" slot-scope="{selectedRowKeys, selectedRows}">
88
- <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
89
- </template>
90
- <template slot="rightBtnExpand" slot-scope="{selectedRowKeys, selectedRows}">
91
- <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
92
- <a-tooltip title="收起查询条件" placement="bottom">
93
- <a-button @click="toggleIsFormShow">
94
- <a-icon :style="iconStyle" :type="toggleIsFormIcon"/>
95
- </a-button>
96
- </a-tooltip>
97
- </template>
98
- <!-- 底部插槽 -->
99
- <template slot="footer" slot-scope="{selectedRowKeys, selectedRows}">
100
- <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
101
- </template>
102
- <!-- excel导入说明插槽 -->
103
- <template #importExcelSlot>
104
- <slot name="importExcelSlot"></slot>
105
- </template>
106
- </x-table>
107
- </template>
108
- <template v-else>
109
- <a-empty>
110
- <span slot="description"> 页面配置不存在,请联系系统管理员</span>
111
- </a-empty>
112
- </template>
113
- </div>
114
- </a-col>
115
- <UserInfoDetailManage ref="userInfo" @close="refresh(false)"/>
116
- </a-row>
117
- </template>
118
- <script>
119
- import XForm from '@vue2-client/base-client/components/common/XForm'
120
- import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
121
- import XAddReport from '@vue2-client/base-client/components/common/XAddReport'
122
- import XTable from '@vue2-client/base-client/components/common/XTable'
123
- import XTree from '@vue2-client/base-client/components/common/XTree'
124
- import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
125
- import {
126
- getConfigByName,
127
- getConfigByLogic,
128
- parseConfig, runLogic, getConfigByNameAsync,
129
- } from '@vue2-client/services/api/common'
130
- import { mapState } from 'vuex'
131
- import XTreePro from '@vue2-client/base-client/components/common/XTree/XTreePro.vue'
132
- import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
133
- import { getRealKeyData } from '@vue2-client/utils/util'
134
- import * as util from '@vue2-client/utils/util'
135
- import UserInfoDetailManage from '@vue2-client/pages/userInfoDetailManage/index.vue'
136
-
137
- export default {
138
- name: 'XFormTable',
139
- components: {
140
- UserInfoDetailManage,
141
- XTreePro,
142
- XTable,
143
- XForm,
144
- XTree,
145
- XAddForm,
146
- XAddReport,
147
- XImportExcel
148
- },
149
- provide () {
150
- return {
151
- getSelf: () => this,
152
- emitEvent: this.emitEvent.bind(this)
153
- }
154
- },
155
- inject: {
156
- getSelectedId: {
157
- default: () => () => {
158
- console.warn('getSelectedId is not provided.')
159
- return null
160
- },
161
- },
162
- setGlobalData: {
163
- default: () => () => {
164
- console.warn('setGlobalData is not provided.')
165
- return null
166
- },
167
- },
168
- getGlobalData: {
169
- default: () => () => {
170
- console.warn('getGlobalData is not provided.')
171
- return null
172
- },
173
- },
174
- getSelectedData: {
175
- default: () => () => {
176
- console.warn('getSelectedData is not provided.')
177
- return null
178
- },
179
- },
180
- getMixinData: {
181
- default: () => () => {
182
- console.warn('getMixinData is not provided.')
183
- return {}
184
- },
185
- },
186
- getOutEnv: {
187
- default: () => () => {
188
- console.warn('getOutEnv is not provided.')
189
- return {}
190
- },
191
- },
192
- currUser: {
193
- default: () => {
194
- console.warn('currUser is not provided.')
195
- return { id: null, name: 'Guest' }
196
- },
197
- },
198
- },
199
- data () {
200
- return {
201
- // 加载状态
202
- loading: false,
203
- // 图标样式
204
- iconStyle: {
205
- position: 'relative',
206
- top: '1px'
207
- },
208
- loadError: false,
209
- moveType: false,
210
- // 添加按钮对应的配置名
211
- moveconfig: '',
212
- // 实际查询配置内容
213
- realQueryConfig: {},
214
- toggleIsFormIcon: 'vertical-align-top',
215
- table_selectedRowKeys: [],
216
- table_selectedRows: [],
217
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
218
- showPagination: true,
219
- }
220
- },
221
- computed: {
222
- ...mapState('setting', ['isMobile'])
223
- },
224
- props: {
225
- // 业务名称
226
- title: {
227
- type: String,
228
- default: ''
229
- },
230
- // 卡片标题
231
- crudTitle: {
232
- type: String,
233
- default: null
234
- },
235
- // 查询配置文件名
236
- queryParamsName: {
237
- type: String,
238
- default: null
239
- },
240
- // 配置所属命名空间
241
- serviceName: {
242
- type: String,
243
- default: process.env.VUE_APP_SYSTEM_NAME
244
- },
245
- // 查询配置文件Json,用于查询配置生成器的预览
246
- queryParamsJson: {
247
- type: Object,
248
- default: null
249
- },
250
- // xTree 配置
251
- xTreeConfigName: {
252
- type: String,
253
- default: null
254
- },
255
- // 业务逻辑名称, 通过logic获取表单表格配置
256
- logicName: {
257
- type: String,
258
- default: null
259
- },
260
- // 执行logic传递的参数
261
- logicParam: {
262
- type: Object,
263
- default: () => {
264
- }
265
- },
266
- // 固定新增表单
267
- fixedAddForm: {
268
- type: Object,
269
- default: () => {
270
- return {}
271
- }
272
- },
273
- // 固定查询表单
274
- fixedQueryForm: {
275
- type: Object,
276
- default: () => {
277
- return {}
278
- }
279
- },
280
- // 预览模式
281
- viewMode: {
282
- type: Boolean,
283
- default: () => {
284
- return false
285
- }
286
- },
287
- // 本地编辑模式
288
- localEditMode: {
289
- type: Boolean,
290
- default: () => {
291
- return false
292
- }
293
- },
294
- // 行选择模式
295
- rowSelectMode: {
296
- type: Boolean,
297
- default: () => {
298
- return false
299
- }
300
- },
301
- // 行选择模式-允许选中行数量,0:任意数量行,大于0:指定值数量的行
302
- allowSelectRowNum: {
303
- type: Number,
304
- default: () => {
305
- return 0
306
- }
307
- },
308
- // 环境
309
- env: {
310
- type: String,
311
- default: () => {
312
- return 'prod'
313
- }
314
- },
315
- // 调用logic获取数据源的追加参数
316
- getDataParams: {
317
- type: Object,
318
- default: undefined
319
- },
320
- // 可以控制组件中导出等按钮的隐藏
321
- buttonState: {
322
- type: Object,
323
- default: undefined
324
- },
325
- // 是否自定义新增按钮的功能
326
- customAdd: {
327
- type: Boolean,
328
- default: false
329
- },
330
- reportQueryName: {
331
- type: String,
332
- default: undefined,
333
- },
334
- // 是否自定义删除按钮的功能
335
- customDelete: {
336
- type: Boolean,
337
- default: false
338
- },
339
- // 是否自定义修改按钮的功能
340
- customEdit: {
341
- type: Boolean,
342
- default: false
343
- },
344
- // 是否自定义增加按钮
345
- customMove: {
346
- type: Boolean,
347
- default: false
348
- },
349
- // 自适应底部边距
350
- extraHeight: {
351
- type: Number,
352
- default: 80
353
- }
354
- },
355
- watch: {
356
- logicParam: {
357
- handler () {
358
- this.initConfig()
359
- },
360
- deep: true
361
- },
362
- queryParamsJson: {
363
- handler () {
364
- this.initConfig()
365
- },
366
- deep: true
367
- },
368
- queryParamsName: {
369
- handler () {
370
- this.initConfig()
371
- }
372
- },
373
- serviceName: {
374
- handler () {
375
- this.initConfig()
376
- }
377
- }
378
- },
379
- methods: {
380
- runLogic,
381
- getRealKeyData,
382
- getConfigByNameAsync,
383
- getConfigByName,
384
- customEvent (func, data) {
385
- this.$emit(func, data)
386
- },
387
- columnClick (key, value, record) {
388
- this.$emit('columnClick', key, value, record)
389
- },
390
- gotoUserDetail (key, value, record) {
391
- this.$refs.userInfo.init(getRealKeyData(record))
392
- },
393
- // 获取主表的数据内容,去掉主表别名
394
- getPrimaryData (rows) {
395
- const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
396
- const prefix = `${alias}_` // 构建前缀
397
- const result = []
398
-
399
- // 遍历 rows 的每一项,提取符合条件的数据
400
- rows.forEach(row => {
401
- const itemResult = {}
402
- Object.keys(row).forEach(key => {
403
- if (key.startsWith(prefix)) {
404
- const newKey = key.slice(prefix.length) // 去掉前缀
405
- itemResult[newKey] = row[key] // 添加到结果对象中
406
- }
407
- })
408
- result.push(itemResult) // 将处理后的项添加到结果数组中
409
- })
410
-
411
- return result // 返回去掉前缀后的对象数组
412
- },
413
-
414
- // 给数据区域添加主表数据,给的数据没有主表别名,放着时添加主表别名
415
- pushPrimaryData (rows) {
416
- const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
417
- const prefix = `${alias}_` // 构建前缀
418
- const result = rows.map(row => {
419
- const itemResult = {}
420
- Object.keys(row).forEach(key => {
421
- itemResult[prefix + key] = row[key] // 复制原始数据
422
- })
423
- return itemResult // 返回添加了主表别名的数据
424
- })
425
- // 把结果添加到数据区
426
- this.getTableData().push(...result)
427
- },
428
-
429
- // 设置固定查询条件,主表别名自动带
430
- setFixedQueryForm (data) {
431
- const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
432
- const prefixedData = {}
433
-
434
- // 为每个键添加主表别名
435
- Object.keys(data).forEach(key => {
436
- prefixedData[`${alias}_${key}`] = data[key]
437
- })
438
-
439
- Object.assign(this.fixedQueryForm, prefixedData)
440
- },
441
-
442
- importExcelOk (data) {
443
- this.$emit('importExcelOk', data)
444
- },
445
- initConfig () {
446
- this.loading = true
447
- this.loadError = false
448
- if (this.queryParamsName) {
449
- this.getConfig()
450
- } else if (this.queryParamsJson) {
451
- this.getConfigBySource()
452
- } else if (this.logicName && this.logicParam) {
453
- this.getColumnJsonByLogic()
454
- } else {
455
- this.loading = false
456
- this.loadError = true
457
- }
458
- },
459
-
460
- getConfig () {
461
- getConfigByName(this.queryParamsName, this.serviceName, (res) => {
462
- if (!res) {
463
- this.loading = false
464
- this.loadError = true
465
- return
466
- }
467
- this.updateComponents(res)
468
- }, this.env === 'dev')
469
- },
470
- getConfigBySource () {
471
- parseConfig(this.queryParamsJson, 'CRUD_FORM', this.serviceName, this.env === 'dev').then(res => {
472
- if (!res) {
473
- this.loading = false
474
- this.loadError = true
475
- return
476
- }
477
- this.updateComponents(res, true)
478
- })
479
- },
480
- getColumnJsonByLogic () {
481
- getConfigByLogic(this.logicName, this.logicParam, this.serviceName, (res) => {
482
- if (!res) {
483
- this.loading = false
484
- this.loadError = true
485
- return
486
- }
487
- this.updateComponents(res, true)
488
- }, this.env === 'dev')
489
- },
490
-
491
- /**
492
- * 更新子组件
493
- * @param res 参数
494
- * @param setQueryParams 是否设置queryParams参数
495
- */
496
- updateComponents (res, setQueryParams) {
497
- this.realQueryConfig = res
498
- if (this.$refs.xTable && this.$refs.xForm && this.$refs.xAddForm) {
499
- // 设置添加按钮对应的配置名
500
- this.moveconfig = res.moveconfig
501
- this.showPagination = res.showPagination === null ? true : res.showPagination
502
- // 是否展示排序按钮控制
503
- if (res.showSortIcon !== null && !res.showSortIcon) {
504
- res.columnJson.forEach(item => {
505
- item.sorter = false
506
- })
507
- }
508
- const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
509
- const initTable = () => {
510
- // 初始化 xTable 子组件
511
- this.$refs.xTable.init({
512
- formItems: res.formJson,
513
- queryParams: setQueryParams ? res : null,
514
- tableColumns: res.columnJson,
515
- buttonState: Object.assign(res.buttonState, this.buttonState),
516
- title: this.title || res.title,
517
- viewMode: this.viewMode,
518
- localEditMode: localEditMode,
519
- rowSelectMode: this.rowSelectMode,
520
- allowSelectRowNum: this.allowSelectRowNum,
521
- tableSummaryMap: res.tableSummaryMap,
522
- serviceName: this.serviceName,
523
- env: this.env,
524
- form: this.$refs.xForm.form,
525
- summaryUpdate: true,
526
- ...res
527
- })
528
- if (this.realQueryConfig?.funcData?.pageMounted) {
529
- executeStrFunctionByContext(this, this.realQueryConfig.funcData.pageMounted, [util, runLogic, getConfigByNameAsync])
530
- }
531
- this.$emit('afterTableInit')
532
- }
533
- // 初始化 xForm 子组件
534
- if (!localEditMode && !this.rowSelectMode) {
535
- this.$refs.xForm.init({
536
- queryParamsName: this.queryParamsName || 'localConfig',
537
- formItems: res.formJson,
538
- serviceName: this.serviceName,
539
- getDataParams: this.getDataParams,
540
- simpleMode: res.simpleMode,
541
- funcData: res.funcData,
542
- env: this.env
543
- })
544
- } else {
545
- // TODO 此处应删除
546
- initTable()
547
- }
548
- // 初始化 xTable 子组件
549
- // 等待 x-from-item 的 mounted 完成
550
- this.$refs.xForm.$on('itemsMounted', initTable)
551
- }
552
- this.loading = false
553
- },
554
- // 自定义按钮
555
- editButtonStateDataClick (functionName, rows) {
556
- console.log('functionName', functionName)
557
- console.log('rows', rows)
558
- this.$emit(functionName, rows)
559
- },
560
-
561
- /**
562
- * 提交查询表单事件
563
- * @param res 参数
564
- */
565
- onSearchSubmit (res) {
566
- if (res.valid) {
567
- // 表单赋值
568
- this.$refs.xTable.setQueryForm(res.form)
569
- this.$refs.xTable.summaryUpdate = true
570
- // commit
571
- this.$emit('afterSearchSubmit', res)
572
- } else {
573
- return false
574
- }
575
- },
576
- active (props) {
577
- let num = false
578
- for (const key in props) {
579
- // eslint-disable-next-line no-prototype-builtins
580
- if (this.$props.hasOwnProperty(key)) {
581
- if (this.$props[key] instanceof Object) {
582
- this.$props[key] = JSON.parse(props[key])
583
- } else {
584
- this.$props[key] = props[key]
585
- }
586
- num = true
587
- }
588
- }
589
- if (num) {
590
- this.initConfig()
591
- }
592
- },
593
- /**
594
- * 提交新增/修改表单后事件
595
- */
596
- onAddOrEditSubmitAfterSubmit (res) {
597
- this.refreshTable(res.businessType === '新增')
598
- // commit
599
- this.$emit('afterSubmit', res)
600
- },
601
- /**
602
- * 表格查询后事件
603
- * @param res 参数
604
- * @param conditionParams 查询条件
605
- */
606
- afterQuery (res, conditionParams) {
607
- this.$emit('afterQuery', res, conditionParams)
608
- },
609
- /**
610
- * 详情按钮事件
611
- * @param record 本条数据
612
- * @param id 数据标识
613
- * @param actionType 操作类型
614
- * @param fun 向上级传递的事件
615
- */
616
- action (record, id, actionType, fun = 'action', index) {
617
- this.$emit('innerXFormTableEmit', fun, record, id, actionType, index)
618
- this.$emit(fun, record, id, actionType, index)
619
- },
620
- treeOnChecked (checkedKeys, deepNodes, deepKeys) {
621
- this.$emit('treeOnChecked', checkedKeys, deepNodes, deepKeys)
622
- },
623
- treeBtnFuncClick (index, func) {
624
- this.$emit('treeBtnFuncClick', index, func)
625
- },
626
- /**
627
- * 新增按钮事件
628
- */
629
- add () {
630
- if (this.customAdd) {
631
- this.$emit('add')
632
- } else {
633
- if (this.$listeners.curdAddBefore) {
634
- this.$emit('curdAddBefore', this.addFormInit)
635
- } else {
636
- this.addFormInit()
637
- }
638
- }
639
- },
640
- addFormInit () {
641
- const res = this.realQueryConfig
642
- const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
643
- this.$refs.xAddForm.init({
644
- businessType: '新增',
645
- title: this.title || res.title,
646
- isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
647
- configName: this.queryParamsName,
648
- configContent: this.queryParamsJson,
649
- formItems: res.formJson,
650
- viewMode: this.viewMode,
651
- localEditMode: localEditMode,
652
- isKeyHandle: !Boolean(localEditMode),
653
- serviceName: this.serviceName,
654
- fixedAddForm: this.fixedAddForm,
655
- getDataParams: this.getDataParams,
656
- layout: res.xAddFormLayout || 'horizontal',
657
- xAddFormLayoutWidth: res.xAddFormLayoutWidth,
658
- formItemLayout: res.formItemLayout || {},
659
- env: this.env
660
- })
661
- },
662
- /**
663
- * 添加按钮事件
664
- */
665
- move () {
666
- this.moveType = true
667
- this.$nextTick(
668
- () => {
669
- this.$refs.xAddReport.init({
670
- configName: this.moveconfig,
671
- selectedId: this.fixedAddForm.selected_id
672
- })
673
- }
674
- )
675
- },
676
- /**
677
- * 修改按钮事件
678
- * @param modifyModelData 修改表单数据
679
- */
680
- edit (modifyModelData) {
681
- if (this.customEdit) {
682
- this.$emit('edit')
683
- } else {
684
- const res = this.realQueryConfig
685
- const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
686
- this.$refs.xAddForm.init({
687
- businessType: '修改',
688
- title: this.title || res.title,
689
- isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
690
- configName: this.queryParamsName,
691
- configContent: this.queryParamsJson,
692
- formItems: res.formJson,
693
- viewMode: this.viewMode,
694
- localEditMode: localEditMode,
695
- isKeyHandle: !Boolean(localEditMode),
696
- serviceName: this.serviceName,
697
- fixedAddForm: this.fixedAddForm,
698
- getDataParams: this.getDataParams,
699
- modifyModelData: modifyModelData,
700
- layout: res.xAddFormLayout || 'horizontal',
701
- env: this.env
702
- })
703
- }
704
- },
705
- /**
706
- * 删除按钮事件
707
- */
708
- del (keys, callback) {
709
- if (this.customDelete) {
710
- this.$emit('del', keys, callback)
711
- }
712
- },
713
- /**
714
- * 删除后事件
715
- * @param res
716
- */
717
- afterDelete (res) {
718
- this.$emit('afterDelete', res)
719
- },
720
- /**
721
- * 行选择事件
722
- * @param row 选中行
723
- */
724
- rowChoose (row) {
725
- this.$emit('rowChoose', row)
726
- },
727
- /**
728
- * 本地编辑模式下校验表格并同步本地数据
729
- * @param currRow 当前行
730
- * @param defaultAppendRowData 默认追加的行数据
731
- */
732
- validateTableAndSyncData (currRow, defaultAppendRowData) {
733
- this.$refs.xTable.validateTableAndSyncData(currRow, defaultAppendRowData)
734
- },
735
- /**
736
- * 更多条件是否展示
737
- */
738
- toggleAdvanced () {
739
- this.$refs.xTable.setScrollYHeight({})
740
- },
741
- /**
742
- * 查询表单部分显示/隐藏切换
743
- */
744
- toggleIsFormShow () {
745
- this.toggleIsFormIcon = this.toggleIsFormIcon === 'vertical-align-top' ? 'vertical-align-bottom' : 'vertical-align-top'
746
- this.$refs.xForm.toggleVisible()
747
- this.$refs.xTable.setScrollYHeight({})
748
- },
749
- /**
750
- * 选择列事件
751
- * @param selectedRowKeys 选中列Key集合
752
- * @param selectedRows 选中列
753
- */
754
- selectRow (selectedRowKeys, selectedRows) {
755
- this.table_selectedRowKeys = selectedRowKeys
756
- this.table_selectedRows = selectedRows
757
- this.$emit('selectRow', selectedRowKeys, selectedRows)
758
- },
759
- /**
760
- * 清除勾选数据
761
- */
762
- clearRowKeys () {
763
- this.$refs.xTable.clearRowKeys()
764
- },
765
- /**
766
- * 刷新表格
767
- * @param toFirstPage 是否到第一页
768
- */
769
- refreshTable (toFirstPage = true) {
770
- this.$refs.xTable.refresh(toFirstPage)
771
- },
772
- /**
773
- * 刷新表格
774
- * @param toFirstPage 是否到第一页
775
- */
776
- refresh (toFirstPage = true) {
777
- this.$refs.xTable.refresh(toFirstPage)
778
- },
779
- /**
780
- * 获取表格数据
781
- */
782
- getTableData () {
783
- return this.$refs.xTable.getTableData()
784
- },
785
- // 在行编辑等情况下,让界面生效
786
- update () {
787
- this.getTableData().push(...[])
788
- },
789
-
790
- /**
791
- * 设置表格数据
792
- */
793
- setTableData (data) {
794
- this.$refs.xTable.setTableData(data)
795
- },
796
- /**
797
- * 表单本地提交
798
- */
799
- onLocalSubmit (res, callback) {
800
- const form = res.realForm
801
- if (res.businessType === '新增') {
802
- this.$refs.xTable.appendLocalData(form)
803
- } else {
804
- this.$refs.xTable.modifyLocalData(form['序号'], form)
805
- }
806
- this.$message.success(res.businessType + '成功!')
807
- this.onAddOrEditSubmitAfterSubmit(res, callback)
808
- if (callback) {
809
- callback()
810
- }
811
- },
812
- emitFunc (func, data, value) {
813
- this.$emit(func, data, value)
814
- },
815
- // 直接转发事件的函数
816
- emitEvent (event, ...args) {
817
- this.$emit(event, ...args)
818
- }
819
- },
820
- action: {
821
- /**
822
- * 实现doAction方法
823
- */
824
- doAction (actionType, args, data) {
825
- switch (actionType) {
826
- case 'refreshTable':
827
- for (const item in args) {
828
- console.log('item', item)
829
- }
830
- break
831
- default:
832
- break
833
- }
834
- }
835
- },
836
- mounted () {
837
- this.initConfig()
838
- if (this.getSelectedData && typeof this.getSelectedData === 'function') {
839
- const selectedId = this.getSelectedData()
840
- if (!selectedId) {
841
- return
842
- }
843
- if (typeof selectedId === 'object') {
844
- const data = JSON.parse(JSON.stringify(selectedId))
845
- if (data.selectedId) {
846
- data.selected_id = data.selectedId
847
- delete data.selectedId
848
- }
849
- Object.assign(this.fixedAddForm, data)
850
- Object.assign(this.fixedQueryForm, data)
851
- } else {
852
- Object.assign(this.fixedAddForm, { selected_id: selectedId })
853
- Object.assign(this.fixedQueryForm, { selected_id: selectedId })
854
- }
855
- }
856
- }
857
- }
858
- </script>
859
- <style lang="less" scoped>
860
- .crud_title {
861
- height: 32px;
862
- font-size: 16px;
863
- font-weight: 500;
864
- color: #000000d9;
865
- line-height: 32px;
866
- margin-bottom: 12px;
867
- }
868
- </style>
1
+ <template>
2
+ <a-row type="flex" :gutter="{ xs: 8, sm: 10, md: 12, lg: 16 }">
3
+ <a-col
4
+ :xs="14"
5
+ :sm="14"
6
+ :md="12"
7
+ :lg="9"
8
+ :xl="6"
9
+ :xxl="5"
10
+ v-if="xTreeConfigName"
11
+ :style="{ maxWidth: '400px'}">
12
+ <x-tree-pro
13
+ :config-name="xTreeConfigName"
14
+ :env="env"
15
+ @action="action"
16
+ @btnFuncClick="treeBtnFuncClick"
17
+ @treeOnChecked="treeOnChecked"
18
+ ref="xtree"
19
+ ></x-tree-pro>
20
+ </a-col>
21
+ <a-col
22
+ :xs="xTreeConfigName ? 10 : 24"
23
+ :sm="xTreeConfigName ? 10 : 24"
24
+ :md="xTreeConfigName ? 12 : 24"
25
+ :lg="xTreeConfigName ? 15 : 24"
26
+ :xl="xTreeConfigName ? 18 : 24"
27
+ :xxl="xTreeConfigName ? 19 : 24">
28
+ <a-skeleton :loading="loading" :paragraph="{ rows: 4 }"/>
29
+ <a-row style="height: 12px" v-if="xTreeConfigName"></a-row>
30
+ <div v-show="!loading">
31
+ <template v-if="!loadError">
32
+ <x-add-form
33
+ ref="xAddForm"
34
+ @onLocalSubmit="onLocalSubmit"
35
+ @x-form-item-emit-func="emitFunc"
36
+ @afterSubmit="onAddOrEditSubmitAfterSubmit"
37
+ >
38
+ <template slot="groupFormItems" slot-scope="{form, model, rules, modifyModelData}">
39
+ <slot
40
+ name="groupFormItems"
41
+ :form="form"
42
+ :model="model"
43
+ :rules="rules"
44
+ :modifyModelData="modifyModelData"></slot>
45
+ </template>
46
+ </x-add-form>
47
+ <x-add-report
48
+ v-if="moveType"
49
+ ref="xAddReport"
50
+ >
51
+ </x-add-report>
52
+ <div v-if="crudTitle" class="crud_title">
53
+ {{ crudTitle }}
54
+ </div>
55
+ <x-form
56
+ ref="xForm"
57
+ @toggleAdvanced="toggleAdvanced"
58
+ @onSubmit="onSearchSubmit">
59
+ <slot name="formBtnExpand"></slot>
60
+ </x-form>
61
+ <x-table
62
+ ref="xTable"
63
+ :fixedQueryForm="fixedQueryForm"
64
+ :queryParamsName="queryParamsName"
65
+ :query-params-json="queryParamsJson"
66
+ :show-pagination="showPagination"
67
+ :customDelete="customDelete"
68
+ :extraHeight="extraHeight"
69
+ :serviceName="serviceName"
70
+ @add="add"
71
+ @move="move"
72
+ @edit="edit"
73
+ @del="del"
74
+ @rowChoose="rowChoose"
75
+ @customEvent="customEvent"
76
+ @afterDelete="afterDelete"
77
+ @action="action"
78
+ @selectRow="selectRow"
79
+ @afterQuery="afterQuery"
80
+ @columnClick="columnClick"
81
+ @gotoUserDetail="gotoUserDetail"
82
+ @editButtonStateDataClick="editButtonStateDataClick"
83
+ @importExcelOk="importExcelOk">
84
+ <template slot="leftButton" slot-scope="{selectedRowKeys, selectedRows}">
85
+ <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
86
+ </template>
87
+ <template slot="button" slot-scope="{selectedRowKeys, selectedRows}">
88
+ <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
89
+ </template>
90
+ <template slot="rightBtnExpand" slot-scope="{selectedRowKeys, selectedRows}">
91
+ <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
92
+ <a-tooltip title="收起查询条件" placement="bottom">
93
+ <a-button @click="toggleIsFormShow">
94
+ <a-icon :style="iconStyle" :type="toggleIsFormIcon"/>
95
+ </a-button>
96
+ </a-tooltip>
97
+ </template>
98
+ <!-- 底部插槽 -->
99
+ <template slot="footer" slot-scope="{selectedRowKeys, selectedRows}">
100
+ <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
101
+ </template>
102
+ <!-- excel导入说明插槽 -->
103
+ <template #importExcelSlot>
104
+ <slot name="importExcelSlot"></slot>
105
+ </template>
106
+ </x-table>
107
+ </template>
108
+ <template v-else>
109
+ <a-empty>
110
+ <span slot="description"> 页面配置不存在,请联系系统管理员</span>
111
+ </a-empty>
112
+ </template>
113
+ </div>
114
+ </a-col>
115
+ <UserInfoDetailManage ref="userInfo" @close="refresh(false)"/>
116
+ </a-row>
117
+ </template>
118
+ <script>
119
+ import XForm from '@vue2-client/base-client/components/common/XForm'
120
+ import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
121
+ import XAddReport from '@vue2-client/base-client/components/common/XAddReport'
122
+ import XTable from '@vue2-client/base-client/components/common/XTable'
123
+ import XTree from '@vue2-client/base-client/components/common/XTree'
124
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
125
+ import {
126
+ getConfigByName,
127
+ getConfigByLogic,
128
+ parseConfig, runLogic, getConfigByNameAsync,
129
+ } from '@vue2-client/services/api/common'
130
+ import { mapState } from 'vuex'
131
+ import XTreePro from '@vue2-client/base-client/components/common/XTree/XTreePro.vue'
132
+ import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
133
+ import { getRealKeyData } from '@vue2-client/utils/util'
134
+ import * as util from '@vue2-client/utils/util'
135
+ import UserInfoDetailManage from '@vue2-client/pages/userInfoDetailManage/index.vue'
136
+
137
+ export default {
138
+ name: 'XFormTable',
139
+ components: {
140
+ UserInfoDetailManage,
141
+ XTreePro,
142
+ XTable,
143
+ XForm,
144
+ XTree,
145
+ XAddForm,
146
+ XAddReport,
147
+ XImportExcel
148
+ },
149
+ provide () {
150
+ return {
151
+ getSelf: () => this,
152
+ emitEvent: this.emitEvent.bind(this)
153
+ }
154
+ },
155
+ inject: {
156
+ getSelectedId: {
157
+ default: () => () => {
158
+ console.warn('getSelectedId is not provided.')
159
+ return null
160
+ },
161
+ },
162
+ setGlobalData: {
163
+ default: () => () => {
164
+ console.warn('setGlobalData is not provided.')
165
+ return null
166
+ },
167
+ },
168
+ getGlobalData: {
169
+ default: () => () => {
170
+ console.warn('getGlobalData is not provided.')
171
+ return null
172
+ },
173
+ },
174
+ getSelectedData: {
175
+ default: () => () => {
176
+ console.warn('getSelectedData is not provided.')
177
+ return null
178
+ },
179
+ },
180
+ getMixinData: {
181
+ default: () => () => {
182
+ console.warn('getMixinData is not provided.')
183
+ return {}
184
+ },
185
+ },
186
+ getOutEnv: {
187
+ default: () => () => {
188
+ console.warn('getOutEnv is not provided.')
189
+ return {}
190
+ },
191
+ },
192
+ currUser: {
193
+ default: () => {
194
+ console.warn('currUser is not provided.')
195
+ return { id: null, name: 'Guest' }
196
+ },
197
+ },
198
+ },
199
+ data () {
200
+ return {
201
+ // 加载状态
202
+ loading: false,
203
+ // 图标样式
204
+ iconStyle: {
205
+ position: 'relative',
206
+ top: '1px'
207
+ },
208
+ loadError: false,
209
+ moveType: false,
210
+ // 添加按钮对应的配置名
211
+ moveconfig: '',
212
+ // 实际查询配置内容
213
+ realQueryConfig: {},
214
+ toggleIsFormIcon: 'vertical-align-top',
215
+ table_selectedRowKeys: [],
216
+ table_selectedRows: [],
217
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
218
+ showPagination: true,
219
+ }
220
+ },
221
+ computed: {
222
+ ...mapState('setting', ['isMobile'])
223
+ },
224
+ props: {
225
+ // 业务名称
226
+ title: {
227
+ type: String,
228
+ default: ''
229
+ },
230
+ // 卡片标题
231
+ crudTitle: {
232
+ type: String,
233
+ default: null
234
+ },
235
+ // 查询配置文件名
236
+ queryParamsName: {
237
+ type: String,
238
+ default: null
239
+ },
240
+ // 配置所属命名空间
241
+ serviceName: {
242
+ type: String,
243
+ default: process.env.VUE_APP_SYSTEM_NAME
244
+ },
245
+ // 查询配置文件Json,用于查询配置生成器的预览
246
+ queryParamsJson: {
247
+ type: Object,
248
+ default: null
249
+ },
250
+ // xTree 配置
251
+ xTreeConfigName: {
252
+ type: String,
253
+ default: null
254
+ },
255
+ // 业务逻辑名称, 通过logic获取表单表格配置
256
+ logicName: {
257
+ type: String,
258
+ default: null
259
+ },
260
+ // 执行logic传递的参数
261
+ logicParam: {
262
+ type: Object,
263
+ default: () => {
264
+ }
265
+ },
266
+ // 固定新增表单
267
+ fixedAddForm: {
268
+ type: Object,
269
+ default: () => {
270
+ return {}
271
+ }
272
+ },
273
+ // 固定查询表单
274
+ fixedQueryForm: {
275
+ type: Object,
276
+ default: () => {
277
+ return {}
278
+ }
279
+ },
280
+ // 预览模式
281
+ viewMode: {
282
+ type: Boolean,
283
+ default: () => {
284
+ return false
285
+ }
286
+ },
287
+ // 本地编辑模式
288
+ localEditMode: {
289
+ type: Boolean,
290
+ default: () => {
291
+ return false
292
+ }
293
+ },
294
+ // 行选择模式
295
+ rowSelectMode: {
296
+ type: Boolean,
297
+ default: () => {
298
+ return false
299
+ }
300
+ },
301
+ // 行选择模式-允许选中行数量,0:任意数量行,大于0:指定值数量的行
302
+ allowSelectRowNum: {
303
+ type: Number,
304
+ default: () => {
305
+ return 0
306
+ }
307
+ },
308
+ // 环境
309
+ env: {
310
+ type: String,
311
+ default: () => {
312
+ return 'prod'
313
+ }
314
+ },
315
+ // 调用logic获取数据源的追加参数
316
+ getDataParams: {
317
+ type: Object,
318
+ default: undefined
319
+ },
320
+ // 可以控制组件中导出等按钮的隐藏
321
+ buttonState: {
322
+ type: Object,
323
+ default: undefined
324
+ },
325
+ // 是否自定义新增按钮的功能
326
+ customAdd: {
327
+ type: Boolean,
328
+ default: false
329
+ },
330
+ reportQueryName: {
331
+ type: String,
332
+ default: undefined,
333
+ },
334
+ // 是否自定义删除按钮的功能
335
+ customDelete: {
336
+ type: Boolean,
337
+ default: false
338
+ },
339
+ // 是否自定义修改按钮的功能
340
+ customEdit: {
341
+ type: Boolean,
342
+ default: false
343
+ },
344
+ // 是否自定义增加按钮
345
+ customMove: {
346
+ type: Boolean,
347
+ default: false
348
+ },
349
+ // 自适应底部边距
350
+ extraHeight: {
351
+ type: Number,
352
+ default: 80
353
+ }
354
+ },
355
+ watch: {
356
+ logicParam: {
357
+ handler () {
358
+ this.initConfig()
359
+ },
360
+ deep: true
361
+ },
362
+ queryParamsJson: {
363
+ handler () {
364
+ this.initConfig()
365
+ },
366
+ deep: true
367
+ },
368
+ queryParamsName: {
369
+ handler () {
370
+ this.initConfig()
371
+ }
372
+ },
373
+ serviceName: {
374
+ handler () {
375
+ this.initConfig()
376
+ }
377
+ }
378
+ },
379
+ methods: {
380
+ runLogic,
381
+ getRealKeyData,
382
+ getConfigByNameAsync,
383
+ getConfigByName,
384
+ customEvent (func, data) {
385
+ this.$emit(func, data)
386
+ },
387
+ columnClick (key, value, record) {
388
+ this.$emit('columnClick', key, value, record)
389
+ },
390
+ gotoUserDetail (key, value, record) {
391
+ this.$refs.userInfo.init(getRealKeyData(record))
392
+ },
393
+ // 获取主表的数据内容,去掉主表别名
394
+ getPrimaryData (rows) {
395
+ const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
396
+ const prefix = `${alias}_` // 构建前缀
397
+ const result = []
398
+
399
+ // 遍历 rows 的每一项,提取符合条件的数据
400
+ rows.forEach(row => {
401
+ const itemResult = {}
402
+ Object.keys(row).forEach(key => {
403
+ if (key.startsWith(prefix)) {
404
+ const newKey = key.slice(prefix.length) // 去掉前缀
405
+ itemResult[newKey] = row[key] // 添加到结果对象中
406
+ }
407
+ })
408
+ result.push(itemResult) // 将处理后的项添加到结果数组中
409
+ })
410
+
411
+ return result // 返回去掉前缀后的对象数组
412
+ },
413
+
414
+ // 给数据区域添加主表数据,给的数据没有主表别名,放着时添加主表别名
415
+ pushPrimaryData (rows) {
416
+ const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
417
+ const prefix = `${alias}_` // 构建前缀
418
+ const result = rows.map(row => {
419
+ const itemResult = {}
420
+ Object.keys(row).forEach(key => {
421
+ itemResult[prefix + key] = row[key] // 复制原始数据
422
+ })
423
+ return itemResult // 返回添加了主表别名的数据
424
+ })
425
+ // 把结果添加到数据区
426
+ this.getTableData().push(...result)
427
+ },
428
+
429
+ // 设置固定查询条件,主表别名自动带
430
+ setFixedQueryForm (data) {
431
+ const alias = this.realQueryConfig.tableAliasName // 获取主表的别名
432
+ const prefixedData = {}
433
+
434
+ // 为每个键添加主表别名
435
+ Object.keys(data).forEach(key => {
436
+ prefixedData[`${alias}_${key}`] = data[key]
437
+ })
438
+
439
+ Object.assign(this.fixedQueryForm, prefixedData)
440
+ },
441
+
442
+ importExcelOk (data) {
443
+ this.$emit('importExcelOk', data)
444
+ },
445
+ initConfig () {
446
+ this.loading = true
447
+ this.loadError = false
448
+ if (this.queryParamsName) {
449
+ this.getConfig()
450
+ } else if (this.queryParamsJson) {
451
+ this.getConfigBySource()
452
+ } else if (this.logicName && this.logicParam) {
453
+ this.getColumnJsonByLogic()
454
+ } else {
455
+ this.loading = false
456
+ this.loadError = true
457
+ }
458
+ },
459
+
460
+ getConfig () {
461
+ getConfigByName(this.queryParamsName, this.serviceName, (res) => {
462
+ if (!res) {
463
+ this.loading = false
464
+ this.loadError = true
465
+ return
466
+ }
467
+ this.updateComponents(res)
468
+ }, this.env === 'dev')
469
+ },
470
+ getConfigBySource () {
471
+ parseConfig(this.queryParamsJson, 'CRUD_FORM', this.serviceName, this.env === 'dev').then(res => {
472
+ if (!res) {
473
+ this.loading = false
474
+ this.loadError = true
475
+ return
476
+ }
477
+ this.updateComponents(res, true)
478
+ })
479
+ },
480
+ getColumnJsonByLogic () {
481
+ getConfigByLogic(this.logicName, this.logicParam, this.serviceName, (res) => {
482
+ if (!res) {
483
+ this.loading = false
484
+ this.loadError = true
485
+ return
486
+ }
487
+ this.updateComponents(res, true)
488
+ }, this.env === 'dev')
489
+ },
490
+
491
+ /**
492
+ * 更新子组件
493
+ * @param res 参数
494
+ * @param setQueryParams 是否设置queryParams参数
495
+ */
496
+ updateComponents (res, setQueryParams) {
497
+ this.realQueryConfig = res
498
+ if (this.$refs.xTable && this.$refs.xForm && this.$refs.xAddForm) {
499
+ // 设置添加按钮对应的配置名
500
+ this.moveconfig = res.moveconfig
501
+ this.showPagination = res.showPagination === null ? true : res.showPagination
502
+ // 是否展示排序按钮控制
503
+ if (res.showSortIcon !== null && !res.showSortIcon) {
504
+ res.columnJson.forEach(item => {
505
+ item.sorter = false
506
+ })
507
+ }
508
+ const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
509
+ const initTable = () => {
510
+ // 初始化 xTable 子组件
511
+ this.$refs.xTable.init({
512
+ formItems: res.formJson,
513
+ queryParams: setQueryParams ? res : null,
514
+ tableColumns: res.columnJson,
515
+ buttonState: Object.assign(res.buttonState, this.buttonState),
516
+ title: this.title || res.title,
517
+ viewMode: this.viewMode,
518
+ localEditMode: localEditMode,
519
+ rowSelectMode: this.rowSelectMode,
520
+ allowSelectRowNum: this.allowSelectRowNum,
521
+ tableSummaryMap: res.tableSummaryMap,
522
+ serviceName: this.serviceName,
523
+ env: this.env,
524
+ form: this.$refs.xForm.form,
525
+ summaryUpdate: true,
526
+ ...res
527
+ })
528
+ if (this.realQueryConfig?.funcData?.pageMounted) {
529
+ executeStrFunctionByContext(this, this.realQueryConfig.funcData.pageMounted, [util, runLogic, getConfigByNameAsync])
530
+ }
531
+ this.$emit('afterTableInit')
532
+ }
533
+ // 初始化 xForm 子组件
534
+ if (!localEditMode && !this.rowSelectMode) {
535
+ this.$refs.xForm.init({
536
+ queryParamsName: this.queryParamsName || 'localConfig',
537
+ formItems: res.formJson,
538
+ serviceName: this.serviceName,
539
+ getDataParams: this.getDataParams,
540
+ simpleMode: res.simpleMode,
541
+ funcData: res.funcData,
542
+ env: this.env
543
+ })
544
+ } else {
545
+ // TODO 此处应删除
546
+ initTable()
547
+ }
548
+ // 初始化 xTable 子组件
549
+ // 等待 x-from-item 的 mounted 完成
550
+ this.$refs.xForm.$on('itemsMounted', initTable)
551
+ }
552
+ this.loading = false
553
+ },
554
+ // 自定义按钮
555
+ editButtonStateDataClick (functionName, rows) {
556
+ console.log('functionName', functionName)
557
+ console.log('rows', rows)
558
+ this.$emit(functionName, rows)
559
+ },
560
+
561
+ /**
562
+ * 提交查询表单事件
563
+ * @param res 参数
564
+ */
565
+ onSearchSubmit (res) {
566
+ if (res.valid) {
567
+ // 表单赋值
568
+ this.$refs.xTable.setQueryForm(res.form)
569
+ this.$refs.xTable.summaryUpdate = true
570
+ // commit
571
+ this.$emit('afterSearchSubmit', res)
572
+ } else {
573
+ return false
574
+ }
575
+ },
576
+ active (props) {
577
+ let num = false
578
+ for (const key in props) {
579
+ // eslint-disable-next-line no-prototype-builtins
580
+ if (this.$props.hasOwnProperty(key)) {
581
+ if (this.$props[key] instanceof Object) {
582
+ this.$props[key] = JSON.parse(props[key])
583
+ } else {
584
+ this.$props[key] = props[key]
585
+ }
586
+ num = true
587
+ }
588
+ }
589
+ if (num) {
590
+ this.initConfig()
591
+ }
592
+ },
593
+ /**
594
+ * 提交新增/修改表单后事件
595
+ */
596
+ onAddOrEditSubmitAfterSubmit (res) {
597
+ this.refreshTable(res.businessType === '新增')
598
+ // commit
599
+ this.$emit('afterSubmit', res)
600
+ },
601
+ /**
602
+ * 表格查询后事件
603
+ * @param res 参数
604
+ * @param conditionParams 查询条件
605
+ */
606
+ afterQuery (res, conditionParams) {
607
+ this.$emit('afterQuery', res, conditionParams)
608
+ },
609
+ /**
610
+ * 详情按钮事件
611
+ * @param record 本条数据
612
+ * @param id 数据标识
613
+ * @param actionType 操作类型
614
+ * @param fun 向上级传递的事件
615
+ */
616
+ action (record, id, actionType, fun = 'action', index) {
617
+ this.$emit('innerXFormTableEmit', fun, record, id, actionType, index)
618
+ this.$emit(fun, record, id, actionType, index)
619
+ },
620
+ treeOnChecked (checkedKeys, deepNodes, deepKeys) {
621
+ this.$emit('treeOnChecked', checkedKeys, deepNodes, deepKeys)
622
+ },
623
+ treeBtnFuncClick (index, func) {
624
+ this.$emit('treeBtnFuncClick', index, func)
625
+ },
626
+ /**
627
+ * 新增按钮事件
628
+ */
629
+ add () {
630
+ if (this.customAdd) {
631
+ this.$emit('add')
632
+ } else {
633
+ if (this.$listeners.curdAddBefore) {
634
+ this.$emit('curdAddBefore', this.addFormInit)
635
+ } else {
636
+ this.addFormInit()
637
+ }
638
+ }
639
+ },
640
+ addFormInit () {
641
+ const res = this.realQueryConfig
642
+ const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
643
+ this.$refs.xAddForm.init({
644
+ businessType: '新增',
645
+ title: this.title || res.title,
646
+ isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
647
+ configName: this.queryParamsName,
648
+ configContent: this.queryParamsJson,
649
+ formItems: res.formJson,
650
+ viewMode: this.viewMode,
651
+ localEditMode: localEditMode,
652
+ isKeyHandle: !Boolean(localEditMode),
653
+ serviceName: this.serviceName,
654
+ fixedAddForm: this.fixedAddForm,
655
+ getDataParams: this.getDataParams,
656
+ layout: res.xAddFormLayout || 'horizontal',
657
+ xAddFormLayoutWidth: res.xAddFormLayoutWidth,
658
+ formItemLayout: res.formItemLayout || {},
659
+ env: this.env
660
+ })
661
+ },
662
+ /**
663
+ * 添加按钮事件
664
+ */
665
+ move () {
666
+ this.moveType = true
667
+ this.$nextTick(
668
+ () => {
669
+ this.$refs.xAddReport.init({
670
+ configName: this.moveconfig,
671
+ selectedId: this.fixedAddForm.selected_id
672
+ })
673
+ }
674
+ )
675
+ },
676
+ /**
677
+ * 修改按钮事件
678
+ * @param modifyModelData 修改表单数据
679
+ */
680
+ edit (modifyModelData) {
681
+ if (this.customEdit) {
682
+ this.$emit('edit')
683
+ } else {
684
+ const res = this.realQueryConfig
685
+ const localEditMode = !this.localEditMode ? res.localEditMode : this.localEditMode
686
+ this.$refs.xAddForm.init({
687
+ businessType: '修改',
688
+ title: this.title || res.title,
689
+ isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
690
+ configName: this.queryParamsName,
691
+ configContent: this.queryParamsJson,
692
+ formItems: res.formJson,
693
+ viewMode: this.viewMode,
694
+ localEditMode: localEditMode,
695
+ isKeyHandle: !Boolean(localEditMode),
696
+ serviceName: this.serviceName,
697
+ fixedAddForm: this.fixedAddForm,
698
+ getDataParams: this.getDataParams,
699
+ modifyModelData: modifyModelData,
700
+ layout: res.xAddFormLayout || 'horizontal',
701
+ env: this.env
702
+ })
703
+ }
704
+ },
705
+ /**
706
+ * 删除按钮事件
707
+ */
708
+ del (keys, callback) {
709
+ if (this.customDelete) {
710
+ this.$emit('del', keys, callback)
711
+ }
712
+ },
713
+ /**
714
+ * 删除后事件
715
+ * @param res
716
+ */
717
+ afterDelete (res) {
718
+ this.$emit('afterDelete', res)
719
+ },
720
+ /**
721
+ * 行选择事件
722
+ * @param row 选中行
723
+ */
724
+ rowChoose (row) {
725
+ this.$emit('rowChoose', row)
726
+ },
727
+ /**
728
+ * 本地编辑模式下校验表格并同步本地数据
729
+ * @param currRow 当前行
730
+ * @param defaultAppendRowData 默认追加的行数据
731
+ */
732
+ validateTableAndSyncData (currRow, defaultAppendRowData) {
733
+ this.$refs.xTable.validateTableAndSyncData(currRow, defaultAppendRowData)
734
+ },
735
+ /**
736
+ * 更多条件是否展示
737
+ */
738
+ toggleAdvanced () {
739
+ this.$refs.xTable.setScrollYHeight({})
740
+ },
741
+ /**
742
+ * 查询表单部分显示/隐藏切换
743
+ */
744
+ toggleIsFormShow () {
745
+ this.toggleIsFormIcon = this.toggleIsFormIcon === 'vertical-align-top' ? 'vertical-align-bottom' : 'vertical-align-top'
746
+ this.$refs.xForm.toggleVisible()
747
+ this.$refs.xTable.setScrollYHeight({})
748
+ },
749
+ /**
750
+ * 选择列事件
751
+ * @param selectedRowKeys 选中列Key集合
752
+ * @param selectedRows 选中列
753
+ */
754
+ selectRow (selectedRowKeys, selectedRows) {
755
+ this.table_selectedRowKeys = selectedRowKeys
756
+ this.table_selectedRows = selectedRows
757
+ this.$emit('selectRow', selectedRowKeys, selectedRows)
758
+ },
759
+ /**
760
+ * 清除勾选数据
761
+ */
762
+ clearRowKeys () {
763
+ this.$refs.xTable.clearRowKeys()
764
+ },
765
+ /**
766
+ * 刷新表格
767
+ * @param toFirstPage 是否到第一页
768
+ */
769
+ refreshTable (toFirstPage = true) {
770
+ this.$refs.xTable.refresh(toFirstPage)
771
+ },
772
+ /**
773
+ * 刷新表格
774
+ * @param toFirstPage 是否到第一页
775
+ */
776
+ refresh (toFirstPage = true) {
777
+ this.$refs.xTable.refresh(toFirstPage)
778
+ },
779
+ /**
780
+ * 获取表格数据
781
+ */
782
+ getTableData () {
783
+ return this.$refs.xTable.getTableData()
784
+ },
785
+ // 在行编辑等情况下,让界面生效
786
+ update () {
787
+ this.getTableData().push(...[])
788
+ },
789
+
790
+ /**
791
+ * 设置表格数据
792
+ */
793
+ setTableData (data) {
794
+ this.$refs.xTable.setTableData(data)
795
+ },
796
+ /**
797
+ * 表单本地提交
798
+ */
799
+ onLocalSubmit (res, callback) {
800
+ const form = res.realForm
801
+ if (res.businessType === '新增') {
802
+ this.$refs.xTable.appendLocalData(form)
803
+ } else {
804
+ this.$refs.xTable.modifyLocalData(form['序号'], form)
805
+ }
806
+ this.$message.success(res.businessType + '成功!')
807
+ this.onAddOrEditSubmitAfterSubmit(res, callback)
808
+ if (callback) {
809
+ callback()
810
+ }
811
+ },
812
+ emitFunc (func, data, value) {
813
+ this.$emit(func, data, value)
814
+ },
815
+ // 直接转发事件的函数
816
+ emitEvent (event, ...args) {
817
+ this.$emit(event, ...args)
818
+ }
819
+ },
820
+ action: {
821
+ /**
822
+ * 实现doAction方法
823
+ */
824
+ doAction (actionType, args, data) {
825
+ switch (actionType) {
826
+ case 'refreshTable':
827
+ for (const item in args) {
828
+ console.log('item', item)
829
+ }
830
+ break
831
+ default:
832
+ break
833
+ }
834
+ }
835
+ },
836
+ mounted () {
837
+ this.initConfig()
838
+ if (this.getSelectedData && typeof this.getSelectedData === 'function') {
839
+ const selectedId = this.getSelectedData()
840
+ if (!selectedId) {
841
+ return
842
+ }
843
+ if (typeof selectedId === 'object') {
844
+ const data = JSON.parse(JSON.stringify(selectedId))
845
+ if (data.selectedId) {
846
+ data.selected_id = data.selectedId
847
+ delete data.selectedId
848
+ }
849
+ Object.assign(this.fixedAddForm, data)
850
+ Object.assign(this.fixedQueryForm, data)
851
+ } else {
852
+ Object.assign(this.fixedAddForm, { selected_id: selectedId })
853
+ Object.assign(this.fixedQueryForm, { selected_id: selectedId })
854
+ }
855
+ }
856
+ }
857
+ }
858
+ </script>
859
+ <style lang="less" scoped>
860
+ .crud_title {
861
+ height: 32px;
862
+ font-size: 16px;
863
+ font-weight: 500;
864
+ color: #000000d9;
865
+ line-height: 32px;
866
+ margin-bottom: 12px;
867
+ }
868
+ </style>