vue2-client 1.4.5 → 1.4.6

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,546 +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
- <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>
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>