vue2-client 1.10.16 → 1.10.17

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