vue2-client 1.14.50 → 1.14.52

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