vue2-client 1.13.26 → 1.13.27

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