vue2-client 1.4.3 → 1.4.5

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,543 +1,546 @@
1
- <template>
2
- <a-skeleton :loading="mainLoading">
3
- <template v-if="loaded">
4
- <x-add-form
5
- :business-title="businessTitle"
6
- :business-type="businessType"
7
- :fixedAddForm="fixedAddForm"
8
- :json-data="formItems"
9
- :service-name="serviceName"
10
- :loading="loading"
11
- :modify-model-data="modifyModelData"
12
- :visible.sync="modelVisible"
13
- @onSubmit="onAddOrModify"/>
14
- <x-form
15
- :is-show="isFormShow"
16
- :json-data="formItems"
17
- :service-name="serviceName"
18
- style="margin-bottom: 14px;"
19
- @onSubmit="onSubmit">
20
- <slot></slot>
21
- </x-form>
22
- <x-table
23
- ref="xTable"
24
- :buttonState="buttonState"
25
- :fixedQueryForm="fixedQueryForm"
26
- :form="form"
27
- :json-data="tableColumns"
28
- :queryParams="queryParams"
29
- :queryParamsName="queryParamsName"
30
- :show-pagination="showPagination"
31
- @action="action"
32
- @loadData="loadData"
33
- @selectRow="selectRow"
34
- @toggleIsFormShow="toggleIsFormShow">
35
- <template slot="expand">
36
- <a-space>
37
- <a-button v-if="!buttonState || buttonState.add" type="primary" @click="addItem">
38
- <a-icon :style="iconStyle" type="plus"/>新增
39
- </a-button>
40
- <a-button
41
- v-if="!buttonState || buttonState.edit"
42
- :disabled="!isModify"
43
- :loading="editDataLoading"
44
- class="btn-success"
45
- type="dashed"
46
- @click="editItem">
47
- <a-icon :style="iconStyle" type="edit"/>修改
48
- </a-button>
49
- <a-button v-if="!buttonState || buttonState.delete" :disabled="!isDelete" type="danger" @click="deleteItem">
50
- <a-icon :style="iconStyle" type="delete"/>删除
51
- </a-button>
52
- <a-button v-if="!buttonState || buttonState.import" type="dashed" @click="$refs.importExcel.importExcelHandleOpen()">
53
- <a-icon :style="iconStyle" type="import" />导入
54
- </a-button>
55
- <a-dropdown v-if="!buttonState || buttonState.export">
56
- <a-menu slot="overlay">
57
- <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport(true)"><a-icon :style="iconStyle" type="ordered-list" />导出选中数据</a-menu-item>
58
- <a-menu-item key="2" @click="handleExport(false)"><a-icon :style="iconStyle" type="snippets" />导出本页数据</a-menu-item>
59
- <a-menu-item key="3" @click="handleExportByQuery"><a-icon :style="iconStyle" type="download" />导出所有符合条件的数据</a-menu-item>
60
- </a-menu>
61
- <a-button>导出 <a-icon type="down" /> </a-button>
62
- </a-dropdown>
63
- <slot :selectedRowKeys="selectedRowKeys" name="button"></slot>
64
- </a-space>
65
- <slot name="expand"></slot>
66
- </template>
67
- </x-table>
68
- <!-- 上传文件 -->
69
- <x-import-excel
70
- ref="importExcel"
71
- @ok="refreshTable"
72
- :title="title"
73
- :service-name="serviceName"
74
- :query-params-name="queryParamsName"
75
- />
76
- </template>
77
- </a-skeleton>
78
- </template>
79
- <script>
80
- import XForm from '@vue2-client/base-client/components/common/XForm'
81
- import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
82
- import XTable from '@vue2-client/base-client/components/common/XTable'
83
- import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
84
- import { query, download, commonApi, addOrModify, remove, queryWithResource } from '@vue2-client/services/api/common'
85
- import { indexedDB } from '@vue2-client/utils/indexedDB'
86
- import { mapState } from 'vuex'
87
- import { Modal } from 'ant-design-vue'
88
- import { post } from '@vue2-client/services/api/restTools'
89
- import { CommonTempTable } from '@vue2-client/services/api/commonTempTable'
90
- import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
91
-
92
- export default {
93
- name: 'XFormTable',
94
- components: {
95
- XTable,
96
- XForm,
97
- XAddForm,
98
- XImportExcel
99
- },
100
- data () {
101
- return {
102
- // Query参数文件内容加载中
103
- mainLoading: false,
104
- // Query参数文件内容加载完成
105
- loaded: false,
106
- // 是否展示表单
107
- isFormShow: true,
108
- // 当使用logic获取到表单表格配置时, 将配置对象直接传入到x-table用于查询
109
- queryParams: null,
110
- // 服务名称
111
- serviceName: 'af-system',
112
- // 表格列集合
113
- tableColumns: [],
114
- // 操作按钮集合
115
- buttonState: {},
116
- // 表格选择列Key集合
117
- selectedRowKeys: [],
118
- // 表单项集合
119
- formItems: [],
120
- // 表单
121
- form: {},
122
- // 图标样式
123
- iconStyle: {
124
- position: 'relative',
125
- top: '1px'
126
- },
127
- // 当前业务类型:新增,修改
128
- businessType: '',
129
- // 是否显示新增/修改模态框
130
- modelVisible: false,
131
- // 修改业务时查询的单条业务数据
132
- modifyModelData: {},
133
- // 是否允许修改
134
- isModify: false,
135
- // 是否允许删除
136
- isDelete: false,
137
- // 新增,修改业务执行状态
138
- loading: false,
139
- // 被修改数据加载状态
140
- editDataLoading: false,
141
- // 是否为临时表
142
- isTableTemp: false
143
- }
144
- },
145
- computed: {
146
- ...mapState('setting', ['isMobile']),
147
- businessTitle () {
148
- return this.businessType + this.title
149
- }
150
- },
151
- props: {
152
- // 业务名称
153
- title: {
154
- type: String,
155
- default: ''
156
- },
157
- // 查询配置文件名
158
- queryParamsName: {
159
- type: String,
160
- default: null
161
- },
162
- // 查询配置文件Json,用于查询配置生成器的预览
163
- queryParamsJson: {
164
- type: Object,
165
- default: null
166
- },
167
- // 业务逻辑名称, 通过logic获取表单表格配置
168
- logicName: {
169
- type: String,
170
- default: null
171
- },
172
- // 执行logic传递的参数
173
- logicParam: {
174
- type: Object,
175
- default: () => {}
176
- },
177
- // 固定新增表单
178
- fixedAddForm: {
179
- type: Object,
180
- default: () => {
181
- return {}
182
- }
183
- },
184
- // 固定查询表单
185
- fixedQueryForm: {
186
- type: Object,
187
- default: () => {
188
- return {}
189
- }
190
- },
191
- // 预览模式
192
- viewMode: {
193
- type: Boolean,
194
- default: () => {
195
- return false
196
- }
197
- },
198
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
199
- showPagination: {
200
- type: Boolean,
201
- default: true
202
- }
203
- },
204
- watch: {
205
- logicParam: {
206
- handler () {
207
- this.getColumnJsonByLogic()
208
- },
209
- deep: true
210
- },
211
- fixedQueryForm: {
212
- handler () {
213
- this.form = {}
214
- },
215
- deep: true
216
- },
217
- queryParamsJson: {
218
- handler () {
219
- this.getColumnsJsonBySource()
220
- },
221
- deep: true
222
- }
223
- },
224
- created () {
225
- if (this.queryParamsName) {
226
- this.getColumnsJson()
227
- } else if (this.queryParamsJson) {
228
- this.getColumnsJsonBySource()
229
- }
230
- },
231
- methods: {
232
- refreshTable () {
233
- this.$refs.xTable.refresh(true)
234
- },
235
- clearRowKeys () {
236
- this.$refs.xTable.clearRowKeys()
237
- },
238
- setParams (res) {
239
- // 深拷贝json,避免筛选列报错
240
- this.tableColumns = JSON.parse(JSON.stringify(res.columnJson))
241
- this.formItems = res.formJson
242
- this.buttonState = res.buttonState
243
- this.serviceName = res.serviceName
244
- this.mainLoading = false
245
- this.loaded = true
246
- },
247
- getColumnsJson () {
248
- this.form = {}
249
- this.mainLoading = true
250
- indexedDB.getByWeb(this.queryParamsName, commonApi.getColumnsJson, { str: this.queryParamsName }, (ret) => {
251
- this.setParams(ret)
252
- })
253
- },
254
- getColumnsJsonBySource () {
255
- this.form = {}
256
- this.mainLoading = true
257
- post(commonApi.getColumnsJson, { queryObject: this.queryParamsJson }).then(res => {
258
- this.queryParams = res
259
- this.setParams(res)
260
- })
261
- },
262
- getColumnJsonByLogic () {
263
- this.form = {}
264
- this.mainLoading = true
265
- indexedDB.getByWeb(`${this.logicName}_${JSON.stringify(this.logicParam)}`, commonApi.getColumnsJson, { logic: this.logicName, logicParam: this.logicParam }, (ret) => {
266
- this.queryParams = ret
267
- this.setParams(ret)
268
- })
269
- },
270
- // 查询表单提交
271
- onSubmit (res) {
272
- if (res.valid) {
273
- // 表单赋值
274
- this.form = res.form
275
- // commit
276
- this.$emit('afterSearchSubmit', res)
277
- } else {
278
- return false
279
- }
280
- },
281
- // 新增/修改数据表单提交
282
- onAddOrModify (res) {
283
- if (this.viewMode) {
284
- this.$message.info('预览模式禁止新增和修改')
285
- return false
286
- }
287
- // 如果是临时表
288
- if (this.isTableTemp) {
289
- this.$emit('tempTableModify', res)
290
- return
291
- }
292
- if (res.valid) {
293
- return false
294
- }
295
- this.loading = true
296
- const requestParameters = {
297
- queryParamsName: this.queryParamsName,
298
- form: {}
299
- }
300
- if (this.businessType === '修改') {
301
- // 将更新需要的主键值加入到表单中
302
- const key = this.tableColumns[0].dataIndex
303
- const realKey = this.getRealKey(key)
304
- requestParameters.form[realKey] = this.selectedRowKeys[0]
305
- }
306
- for (const key of Object.keys(res.form)) {
307
- const realKey = this.getRealKey(key)
308
- requestParameters.form[realKey] = res.form[key]
309
- }
310
- addOrModify(requestParameters, this.serviceName).then(res => {
311
- this.$message.success(this.businessType + '成功!')
312
- this.loading = false
313
- this.modelVisible = false
314
- this.$refs.xTable.refresh(true)
315
- // commit
316
- this.$emit('afterSubmit', { type: this.businessType, id: res.id, form: requestParameters.form })
317
- }).catch(e => {
318
- this.loading = false
319
- this.modelVisible = false
320
- this.$message.error(this.businessType + '失败!')
321
- })
322
- },
323
- // 刷新加载表格数据
324
- loadData (requestParameters, callback) {
325
- let result = {}
326
- if (this.queryParamsJson) {
327
- if (this.queryParamsJson.tableName.startsWith('##')) {
328
- this.isTableTemp = true
329
- result = this.initTempTable(requestParameters)
330
- }
331
- }
332
- if (!this.isTableTemp) {
333
- result = query(requestParameters, this.serviceName)
334
- }
335
- this.$emit('afterQuery', result)
336
- callback(result)
337
- },
338
- // 详情按钮事件
339
- action (record, id) {
340
- this.$emit('action', record, id)
341
- },
342
- // 获取数据字段实际值
343
- getRealKey (key) {
344
- return key.substring(key.indexOf('_') + 1)
345
- },
346
- // 新增业务
347
- addItem () {
348
- this.businessType = '新增'
349
- this.modifyModelData = {}
350
- this.modelVisible = true
351
- },
352
- // 修改业务
353
- editItem () {
354
- this.businessType = '修改'
355
- const requestParameters = {
356
- queryParamsName: this.queryParamsName,
357
- conditionParams: {},
358
- pageNo: 1,
359
- pageSize: 1
360
- }
361
- requestParameters.conditionParams[this.tableColumns[0].dataIndex] = this.selectedRowKeys[0]
362
- requestParameters.f_businessid = this.selectedRowKeys[0]
363
- if (this.isTableTemp) {
364
- this.$emit('tempTableEdit', requestParameters)
365
- return
366
- }
367
- this.editDataLoading = true
368
- queryWithResource(requestParameters, this.serviceName).then(res => {
369
- this.modifyModelData = { data: res.data[0], images: res.images, files: res.files }
370
- this.modelVisible = true
371
- this.editDataLoading = false
372
- })
373
- },
374
- // 删除业务
375
- deleteItem () {
376
- if (this.viewMode) {
377
- this.$message.info('预览模式禁止删除')
378
- return
379
- }
380
- Modal.confirm({
381
- title: '提示',
382
- content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
383
- confirmLoading: this.loading,
384
- zIndex: 1001,
385
- onOk: () => {
386
- this.loading = true
387
- const requestParameters = {
388
- queryParamsName: this.queryParamsName,
389
- idList: this.selectedRowKeys
390
- }
391
- remove(requestParameters, this.serviceName).then(res => {
392
- this.loading = false
393
- this.$message.success('删除成功!')
394
- this.$refs.xTable.clearRowKeys()
395
- this.$refs.xTable.refresh(true)
396
- // afterDelete
397
- this.$emit('afterDelete', { idList: requestParameters.idList })
398
- }).catch(e => {
399
- this.loading = false
400
- this.$message.error('删除失败!')
401
- })
402
- },
403
- onCancel () {}
404
- })
405
- },
406
- // 导出选中或本页数据
407
- handleExport (isSelected) {
408
- const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
409
- const filterVal = this.tableColumns.map(res => res.dataIndex)
410
- let exportData
411
- if (isSelected) {
412
- exportData = this.$refs.xTable.selectedRows
413
- } else {
414
- exportData = this.$refs.xTable.dataSource
415
- }
416
- const data = this.formatJson(filterVal, exportData)
417
- exportJson(tHeader, data, this.title + `数据_${new Date().toLocaleString()}`)
418
- },
419
- formatJson (filterVal, jsonData) {
420
- return jsonData.map(v => filterVal.map(j => v[j]))
421
- },
422
- // 导出符合条件的数据
423
- handleExportByQuery () {
424
- const that = this
425
- this.$confirm({
426
- title: '是否确认导出?',
427
- content: '此操作将导出当前条件下所有数据而非选中数据',
428
- onOk () {
429
- download({
430
- queryParamsName: that.queryParamsName,
431
- form: that.form,
432
- type: 'exportData'
433
- }, that.title + `数据_${new Date().toLocaleString()}.xlsx`, that.serviceName)
434
- },
435
- onCancel () {}
436
- })
437
- },
438
- // 查询表单部分显示/隐藏切换
439
- toggleIsFormShow () {
440
- this.isFormShow = !this.isFormShow
441
- },
442
- // 控制业务操作按钮组的显示
443
- selectRow (rowKeys) {
444
- this.selectedRowKeys = rowKeys
445
- this.isModify = this.selectedRowKeys.length === 1
446
- this.isDelete = this.selectedRowKeys.length > 0
447
- this.$emit('selectRow', this.selectedRowKeys)
448
- },
449
- // 创建临时表sql生成
450
- createTempTable (defineJson) {
451
- const tableName = defineJson.tableName
452
- const define = defineJson.column
453
- return post(CommonTempTable.createTempTable, {
454
- define: define,
455
- tableName: tableName
456
- })
457
- .then(
458
- res => {
459
- return res
460
- },
461
- err => {
462
- console.log(err)
463
- }
464
- )
465
- },
466
- // 插入临时表数据sql生成
467
- insertTempTableData (defineJson) {
468
- const tableName = defineJson.tableName
469
- const params = {}
470
- params.define = defineJson.column
471
- params.applyId = defineJson.applyId
472
- params.stepName = defineJson.stepName
473
- params.tableName = tableName
474
- return post(CommonTempTable.insertDataToTempTable, {
475
- tempTableData: params
476
- })
477
- .then(
478
- res => {
479
- return res
480
- }
481
- )
482
- },
483
- // 初始化临时表
484
- async initTempTable (json) {
485
- await this.createTempTable(this.queryParamsJson)
486
- await this.insertTempTableData(this.queryParamsJson)
487
- let result = {}
488
- await post(CommonTempTable.initApplySubTable, {
489
- define: json
490
- })
491
- .then(
492
- res => {
493
- console.log('子表临时表已创建')
494
- result = res
495
- }
496
- )
497
- return result
498
- }
499
- }
500
- }
501
- </script>
502
- <style lang="less" scoped>
503
- .btn-success {
504
- color: #ffffff;
505
- }
506
- .btn-success:hover {
507
- color: #ffffff !important;
508
- }
509
- .btn-success:focus {
510
- color: #ffffff !important;
511
- }
512
- .btn-success:enabled:hover {
513
- background-color: #85CE61 !important;
514
- border-color: #85CE61 !important;
515
- }
516
- .btn-success:enabled {
517
- background-color: #67c23a;
518
- border-color: #67c23a;
519
- }
520
- .btn-success:disabled {
521
- color: rgba(0, 0, 0, 0.25);
522
- }
523
- .btn-warn {
524
- color: #ffffff;
525
- }
526
- .btn-warn:hover {
527
- color: #ffffff !important;
528
- }
529
- .btn-warn:focus {
530
- color: #ffffff !important;
531
- }
532
- .btn-warn:enabled:hover {
533
- background-color: #ffc833 !important;
534
- border-color: #ffc833 !important;
535
- }
536
- .btn-warn:enabled {
537
- background-color: #ffba00;
538
- border-color: #ffba00;
539
- }
540
- .btn-warn:disabled {
541
- color: rgba(0, 0, 0, 0.25);
542
- }
543
- </style>
1
+ <template>
2
+ <a-skeleton :loading="mainLoading">
3
+ <template v-if="loaded">
4
+ <x-add-form
5
+ :business-title="businessTitle"
6
+ :business-type="businessType"
7
+ :fixedAddForm="fixedAddForm"
8
+ :json-data="formItems"
9
+ :service-name="serviceName"
10
+ :loading="loading"
11
+ :modify-model-data="modifyModelData"
12
+ :visible.sync="modelVisible"
13
+ @onSubmit="onAddOrModify"/>
14
+ <x-form
15
+ :is-show="isFormShow"
16
+ :json-data="formItems"
17
+ :service-name="serviceName"
18
+ style="margin-bottom: 14px;"
19
+ @onSubmit="onSubmit">
20
+ <slot></slot>
21
+ </x-form>
22
+ <x-table
23
+ ref="xTable"
24
+ :buttonState="buttonState"
25
+ :fixedQueryForm="fixedQueryForm"
26
+ :form="form"
27
+ :json-data="tableColumns"
28
+ :queryParams="queryParams"
29
+ :queryParamsName="queryParamsName"
30
+ :show-pagination="showPagination"
31
+ @action="action"
32
+ @loadData="loadData"
33
+ @selectRow="selectRow"
34
+ @toggleIsFormShow="toggleIsFormShow">
35
+ <template slot="expand">
36
+ <a-space>
37
+ <a-button v-if="!buttonState || buttonState.add" type="primary" @click="addItem">
38
+ <a-icon :style="iconStyle" type="plus"/>新增
39
+ </a-button>
40
+ <a-button
41
+ v-if="!buttonState || buttonState.edit"
42
+ :disabled="!isModify"
43
+ :loading="editDataLoading"
44
+ class="btn-success"
45
+ type="dashed"
46
+ @click="editItem">
47
+ <a-icon :style="iconStyle" type="edit"/>修改
48
+ </a-button>
49
+ <a-button v-if="!buttonState || buttonState.delete" :disabled="!isDelete" type="danger" @click="deleteItem">
50
+ <a-icon :style="iconStyle" type="delete"/>删除
51
+ </a-button>
52
+ <a-button v-if="!buttonState || buttonState.import" type="dashed" @click="$refs.importExcel.importExcelHandleOpen()">
53
+ <a-icon :style="iconStyle" type="import" />导入
54
+ </a-button>
55
+ <a-dropdown v-if="!buttonState || buttonState.export">
56
+ <a-menu slot="overlay">
57
+ <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport(true)"><a-icon :style="iconStyle" type="ordered-list" />导出选中数据</a-menu-item>
58
+ <a-menu-item key="2" @click="handleExport(false)"><a-icon :style="iconStyle" type="snippets" />导出本页数据</a-menu-item>
59
+ <a-menu-item key="3" @click="handleExportByQuery"><a-icon :style="iconStyle" type="download" />导出所有符合条件的数据</a-menu-item>
60
+ </a-menu>
61
+ <a-button>导出 <a-icon type="down" /> </a-button>
62
+ </a-dropdown>
63
+ <slot :selectedRowKeys="selectedRowKeys" name="button"></slot>
64
+ </a-space>
65
+ <slot name="expand"></slot>
66
+ </template>
67
+ <template slot="footer">
68
+ <slot name="footer"></slot>
69
+ </template>
70
+ </x-table>
71
+ <!-- 上传文件 -->
72
+ <x-import-excel
73
+ ref="importExcel"
74
+ @ok="refreshTable"
75
+ :title="title"
76
+ :service-name="serviceName"
77
+ :query-params-name="queryParamsName"
78
+ />
79
+ </template>
80
+ </a-skeleton>
81
+ </template>
82
+ <script>
83
+ import XForm from '@vue2-client/base-client/components/common/XForm'
84
+ import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
85
+ import XTable from '@vue2-client/base-client/components/common/XTable'
86
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
87
+ import { query, download, commonApi, addOrModify, remove, queryWithResource } from '@vue2-client/services/api/common'
88
+ import { indexedDB } from '@vue2-client/utils/indexedDB'
89
+ import { mapState } from 'vuex'
90
+ import { Modal } from 'ant-design-vue'
91
+ import { post } from '@vue2-client/services/api/restTools'
92
+ import { CommonTempTable } from '@vue2-client/services/api/commonTempTable'
93
+ import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
94
+
95
+ export default {
96
+ name: 'XFormTable',
97
+ components: {
98
+ XTable,
99
+ XForm,
100
+ XAddForm,
101
+ XImportExcel
102
+ },
103
+ data () {
104
+ return {
105
+ // Query参数文件内容加载中
106
+ mainLoading: false,
107
+ // Query参数文件内容加载完成
108
+ loaded: false,
109
+ // 是否展示表单
110
+ isFormShow: true,
111
+ // 当使用logic获取到表单表格配置时, 将配置对象直接传入到x-table用于查询
112
+ queryParams: null,
113
+ // 服务名称
114
+ serviceName: 'af-system',
115
+ // 表格列集合
116
+ tableColumns: [],
117
+ // 操作按钮集合
118
+ buttonState: {},
119
+ // 表格选择列Key集合
120
+ selectedRowKeys: [],
121
+ // 表单项集合
122
+ formItems: [],
123
+ // 表单
124
+ form: {},
125
+ // 图标样式
126
+ iconStyle: {
127
+ position: 'relative',
128
+ top: '1px'
129
+ },
130
+ // 当前业务类型:新增,修改
131
+ businessType: '',
132
+ // 是否显示新增/修改模态框
133
+ modelVisible: false,
134
+ // 修改业务时查询的单条业务数据
135
+ modifyModelData: {},
136
+ // 是否允许修改
137
+ isModify: false,
138
+ // 是否允许删除
139
+ isDelete: false,
140
+ // 新增,修改业务执行状态
141
+ loading: false,
142
+ // 被修改数据加载状态
143
+ editDataLoading: false,
144
+ // 是否为临时表
145
+ isTableTemp: false
146
+ }
147
+ },
148
+ computed: {
149
+ ...mapState('setting', ['isMobile']),
150
+ businessTitle () {
151
+ return this.businessType + this.title
152
+ }
153
+ },
154
+ props: {
155
+ // 业务名称
156
+ title: {
157
+ type: String,
158
+ default: ''
159
+ },
160
+ // 查询配置文件名
161
+ queryParamsName: {
162
+ type: String,
163
+ default: null
164
+ },
165
+ // 查询配置文件Json,用于查询配置生成器的预览
166
+ queryParamsJson: {
167
+ type: Object,
168
+ default: null
169
+ },
170
+ // 业务逻辑名称, 通过logic获取表单表格配置
171
+ logicName: {
172
+ type: String,
173
+ default: null
174
+ },
175
+ // 执行logic传递的参数
176
+ logicParam: {
177
+ type: Object,
178
+ default: () => {}
179
+ },
180
+ // 固定新增表单
181
+ fixedAddForm: {
182
+ type: Object,
183
+ default: () => {
184
+ return {}
185
+ }
186
+ },
187
+ // 固定查询表单
188
+ fixedQueryForm: {
189
+ type: Object,
190
+ default: () => {
191
+ return {}
192
+ }
193
+ },
194
+ // 预览模式
195
+ viewMode: {
196
+ type: Boolean,
197
+ default: () => {
198
+ return false
199
+ }
200
+ },
201
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
202
+ showPagination: {
203
+ type: Boolean,
204
+ default: true
205
+ }
206
+ },
207
+ watch: {
208
+ logicParam: {
209
+ handler () {
210
+ this.getColumnJsonByLogic()
211
+ },
212
+ deep: true
213
+ },
214
+ fixedQueryForm: {
215
+ handler () {
216
+ this.form = {}
217
+ },
218
+ deep: true
219
+ },
220
+ queryParamsJson: {
221
+ handler () {
222
+ this.getColumnsJsonBySource()
223
+ },
224
+ deep: true
225
+ }
226
+ },
227
+ created () {
228
+ if (this.queryParamsName) {
229
+ this.getColumnsJson()
230
+ } else if (this.queryParamsJson) {
231
+ this.getColumnsJsonBySource()
232
+ }
233
+ },
234
+ methods: {
235
+ refreshTable () {
236
+ this.$refs.xTable.refresh(true)
237
+ },
238
+ clearRowKeys () {
239
+ this.$refs.xTable.clearRowKeys()
240
+ },
241
+ setParams (res) {
242
+ // 深拷贝json,避免筛选列报错
243
+ this.tableColumns = JSON.parse(JSON.stringify(res.columnJson))
244
+ this.formItems = res.formJson
245
+ this.buttonState = res.buttonState
246
+ this.serviceName = res.serviceName
247
+ this.mainLoading = false
248
+ this.loaded = true
249
+ },
250
+ getColumnsJson () {
251
+ this.form = {}
252
+ this.mainLoading = true
253
+ indexedDB.getByWeb(this.queryParamsName, commonApi.getColumnsJson, { str: this.queryParamsName }, (ret) => {
254
+ this.setParams(ret)
255
+ })
256
+ },
257
+ getColumnsJsonBySource () {
258
+ this.form = {}
259
+ this.mainLoading = true
260
+ post(commonApi.getColumnsJson, { queryObject: this.queryParamsJson }).then(res => {
261
+ this.queryParams = res
262
+ this.setParams(res)
263
+ })
264
+ },
265
+ getColumnJsonByLogic () {
266
+ this.form = {}
267
+ this.mainLoading = true
268
+ indexedDB.getByWeb(`${this.logicName}_${JSON.stringify(this.logicParam)}`, commonApi.getColumnsJson, { logic: this.logicName, logicParam: this.logicParam }, (ret) => {
269
+ this.queryParams = ret
270
+ this.setParams(ret)
271
+ })
272
+ },
273
+ // 查询表单提交
274
+ onSubmit (res) {
275
+ if (res.valid) {
276
+ // 表单赋值
277
+ this.form = res.form
278
+ // commit
279
+ this.$emit('afterSearchSubmit', res)
280
+ } else {
281
+ return false
282
+ }
283
+ },
284
+ // 新增/修改数据表单提交
285
+ onAddOrModify (res) {
286
+ if (this.viewMode) {
287
+ this.$message.info('预览模式禁止新增和修改')
288
+ return false
289
+ }
290
+ // 如果是临时表
291
+ if (this.isTableTemp) {
292
+ this.$emit('tempTableModify', res)
293
+ return
294
+ }
295
+ if (!res.valid) {
296
+ return false
297
+ }
298
+ this.loading = true
299
+ const requestParameters = {
300
+ queryParamsName: this.queryParamsName,
301
+ form: {}
302
+ }
303
+ if (this.businessType === '修改') {
304
+ // 将更新需要的主键值加入到表单中
305
+ const key = this.tableColumns[0].dataIndex
306
+ const realKey = this.getRealKey(key)
307
+ requestParameters.form[realKey] = this.selectedRowKeys[0]
308
+ }
309
+ for (const key of Object.keys(res.form)) {
310
+ const realKey = this.getRealKey(key)
311
+ requestParameters.form[realKey] = res.form[key]
312
+ }
313
+ addOrModify(requestParameters, this.serviceName).then(res => {
314
+ this.$message.success(this.businessType + '成功!')
315
+ this.loading = false
316
+ this.modelVisible = false
317
+ this.$refs.xTable.refresh(true)
318
+ // commit
319
+ this.$emit('afterSubmit', { type: this.businessType, id: res.id, form: requestParameters.form })
320
+ }).catch(e => {
321
+ this.loading = false
322
+ this.modelVisible = false
323
+ this.$message.error(this.businessType + '失败!')
324
+ })
325
+ },
326
+ // 刷新加载表格数据
327
+ loadData (requestParameters, callback) {
328
+ let result = {}
329
+ if (this.queryParamsJson) {
330
+ if (this.queryParamsJson.tableName.startsWith('##')) {
331
+ this.isTableTemp = true
332
+ result = this.initTempTable(requestParameters)
333
+ }
334
+ }
335
+ if (!this.isTableTemp) {
336
+ result = query(requestParameters, this.serviceName)
337
+ }
338
+ this.$emit('afterQuery', result)
339
+ callback(result)
340
+ },
341
+ // 详情按钮事件
342
+ action (record, id) {
343
+ this.$emit('action', record, id)
344
+ },
345
+ // 获取数据字段实际值
346
+ getRealKey (key) {
347
+ return key.substring(key.indexOf('_') + 1)
348
+ },
349
+ // 新增业务
350
+ addItem () {
351
+ this.businessType = '新增'
352
+ this.modifyModelData = {}
353
+ this.modelVisible = true
354
+ },
355
+ // 修改业务
356
+ editItem () {
357
+ this.businessType = '修改'
358
+ const requestParameters = {
359
+ queryParamsName: this.queryParamsName,
360
+ conditionParams: {},
361
+ pageNo: 1,
362
+ pageSize: 1
363
+ }
364
+ requestParameters.conditionParams[this.tableColumns[0].dataIndex] = this.selectedRowKeys[0]
365
+ requestParameters.f_businessid = this.selectedRowKeys[0]
366
+ if (this.isTableTemp) {
367
+ this.$emit('tempTableEdit', requestParameters)
368
+ return
369
+ }
370
+ this.editDataLoading = true
371
+ queryWithResource(requestParameters, this.serviceName).then(res => {
372
+ this.modifyModelData = { data: res.data[0], images: res.images, files: res.files }
373
+ this.modelVisible = true
374
+ this.editDataLoading = false
375
+ })
376
+ },
377
+ // 删除业务
378
+ deleteItem () {
379
+ if (this.viewMode) {
380
+ this.$message.info('预览模式禁止删除')
381
+ return
382
+ }
383
+ Modal.confirm({
384
+ title: '提示',
385
+ content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
386
+ confirmLoading: this.loading,
387
+ zIndex: 1001,
388
+ onOk: () => {
389
+ this.loading = true
390
+ const requestParameters = {
391
+ queryParamsName: this.queryParamsName,
392
+ idList: this.selectedRowKeys
393
+ }
394
+ remove(requestParameters, this.serviceName).then(res => {
395
+ this.loading = false
396
+ this.$message.success('删除成功!')
397
+ this.$refs.xTable.clearRowKeys()
398
+ this.$refs.xTable.refresh(true)
399
+ // afterDelete
400
+ this.$emit('afterDelete', { idList: requestParameters.idList })
401
+ }).catch(e => {
402
+ this.loading = false
403
+ this.$message.error('删除失败!')
404
+ })
405
+ },
406
+ onCancel () {}
407
+ })
408
+ },
409
+ // 导出选中或本页数据
410
+ handleExport (isSelected) {
411
+ const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
412
+ const filterVal = this.tableColumns.map(res => res.dataIndex)
413
+ let exportData
414
+ if (isSelected) {
415
+ exportData = this.$refs.xTable.selectedRows
416
+ } else {
417
+ exportData = this.$refs.xTable.dataSource
418
+ }
419
+ const data = this.formatJson(filterVal, exportData)
420
+ exportJson(tHeader, data, this.title + `数据_${new Date().toLocaleString()}`)
421
+ },
422
+ formatJson (filterVal, jsonData) {
423
+ return jsonData.map(v => filterVal.map(j => v[j]))
424
+ },
425
+ // 导出符合条件的数据
426
+ handleExportByQuery () {
427
+ const that = this
428
+ this.$confirm({
429
+ title: '是否确认导出?',
430
+ content: '此操作将导出当前条件下所有数据而非选中数据',
431
+ onOk () {
432
+ download({
433
+ queryParamsName: that.queryParamsName,
434
+ form: that.form,
435
+ type: 'exportData'
436
+ }, that.title + `数据_${new Date().toLocaleString()}.xlsx`, that.serviceName)
437
+ },
438
+ onCancel () {}
439
+ })
440
+ },
441
+ // 查询表单部分显示/隐藏切换
442
+ toggleIsFormShow () {
443
+ this.isFormShow = !this.isFormShow
444
+ },
445
+ // 控制业务操作按钮组的显示
446
+ selectRow (rowKeys) {
447
+ this.selectedRowKeys = rowKeys
448
+ this.isModify = this.selectedRowKeys.length === 1
449
+ this.isDelete = this.selectedRowKeys.length > 0
450
+ this.$emit('selectRow', this.selectedRowKeys)
451
+ },
452
+ // 创建临时表sql生成
453
+ createTempTable (defineJson) {
454
+ const tableName = defineJson.tableName
455
+ const define = defineJson.column
456
+ return post(CommonTempTable.createTempTable, {
457
+ define: define,
458
+ tableName: tableName
459
+ })
460
+ .then(
461
+ res => {
462
+ return res
463
+ },
464
+ err => {
465
+ console.log(err)
466
+ }
467
+ )
468
+ },
469
+ // 插入临时表数据sql生成
470
+ insertTempTableData (defineJson) {
471
+ const tableName = defineJson.tableName
472
+ const params = {}
473
+ params.define = defineJson.column
474
+ params.applyId = defineJson.applyId
475
+ params.stepName = defineJson.stepName
476
+ params.tableName = tableName
477
+ return post(CommonTempTable.insertDataToTempTable, {
478
+ tempTableData: params
479
+ })
480
+ .then(
481
+ res => {
482
+ return res
483
+ }
484
+ )
485
+ },
486
+ // 初始化临时表
487
+ async initTempTable (json) {
488
+ await this.createTempTable(this.queryParamsJson)
489
+ await this.insertTempTableData(this.queryParamsJson)
490
+ let result = {}
491
+ await post(CommonTempTable.initApplySubTable, {
492
+ define: json
493
+ })
494
+ .then(
495
+ res => {
496
+ console.log('子表临时表已创建')
497
+ result = res
498
+ }
499
+ )
500
+ return result
501
+ }
502
+ }
503
+ }
504
+ </script>
505
+ <style lang="less" scoped>
506
+ .btn-success {
507
+ color: #ffffff;
508
+ }
509
+ .btn-success:hover {
510
+ color: #ffffff !important;
511
+ }
512
+ .btn-success:focus {
513
+ color: #ffffff !important;
514
+ }
515
+ .btn-success:enabled:hover {
516
+ background-color: #85CE61 !important;
517
+ border-color: #85CE61 !important;
518
+ }
519
+ .btn-success:enabled {
520
+ background-color: #67c23a;
521
+ border-color: #67c23a;
522
+ }
523
+ .btn-success:disabled {
524
+ color: rgba(0, 0, 0, 0.25);
525
+ }
526
+ .btn-warn {
527
+ color: #ffffff;
528
+ }
529
+ .btn-warn:hover {
530
+ color: #ffffff !important;
531
+ }
532
+ .btn-warn:focus {
533
+ color: #ffffff !important;
534
+ }
535
+ .btn-warn:enabled:hover {
536
+ background-color: #ffc833 !important;
537
+ border-color: #ffc833 !important;
538
+ }
539
+ .btn-warn:enabled {
540
+ background-color: #ffba00;
541
+ border-color: #ffba00;
542
+ }
543
+ .btn-warn:disabled {
544
+ color: rgba(0, 0, 0, 0.25);
545
+ }
546
+ </style>