vue2-client 1.8.21 → 1.8.23

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,525 +1,531 @@
1
- <template>
2
- <div v-show="tableColumns.length > 0">
3
- <a-row :gutter="48">
4
- <a-col>
5
- <span :style="{ float: 'left', overflow: 'hidden', marginBottom: '8px' }">
6
- <a-space>
7
- <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
8
- <a-button v-if="!buttonState || buttonState.add" type="primary" @click="add">
9
- <a-icon :style="iconStyle" type="plus"/>新增
10
- </a-button>
11
- <a-button
12
- v-if="!buttonState || buttonState.edit"
13
- :disabled="!isModify"
14
- :loading="editLoading"
15
- class="btn-success"
16
- type="dashed"
17
- @click="edit()">
18
- <a-icon :style="iconStyle" type="edit"/>修改
19
- </a-button>
20
- <a-button v-if="!buttonState || buttonState.delete" :disabled="!isDelete" type="danger" @click="deleteItem">
21
- <a-icon :style="iconStyle" type="delete"/>删除
22
- </a-button>
23
- <a-button v-if="!buttonState || buttonState.import" type="dashed" @click="importData">
24
- <a-icon :style="iconStyle" type="import" />导入
25
- </a-button>
26
- <a-dropdown v-if="!buttonState || buttonState.export">
27
- <a-menu slot="overlay">
28
- <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport(true)"><a-icon :style="iconStyle" type="ordered-list" />导出选中数据</a-menu-item>
29
- <a-menu-item key="2" @click="handleExport(false)"><a-icon :style="iconStyle" type="snippets" />导出本页数据</a-menu-item>
30
- <a-menu-item key="3" @click="handleExportByQuery"><a-icon :style="iconStyle" type="download" />导出所有符合条件的数据</a-menu-item>
31
- </a-menu>
32
- <a-button>导出 <a-icon type="down" /> </a-button>
33
- </a-dropdown>
34
- <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
35
- </a-space>
36
- </span>
37
- </a-col>
38
- <a-col>
39
- <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
40
- <a-button-group>
41
- <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
42
- <a-button @click="refresh(true)">
43
- <a-icon :style="iconStyle" type="reload" />
44
- </a-button>
45
- <table-setting v-if="columnSelectLoaded" v-model="tableColumns" />
46
- </a-button-group>
47
- </span>
48
- </a-col>
49
- </a-row>
50
- <s-table
51
- ref="table"
52
- :alert="true"
53
- :columns="tableColumns"
54
- :data="loadData"
55
- :rowKey="rowKey"
56
- :rowSelection="rowSelection"
57
- :scroll="{ x: scrollXWidth, y: scrollYHeight }"
58
- :showPagination="showPagination"
59
- size="default"
60
- >
61
- <template
62
- v-for="(item, index) in tableColumns"
63
- :slot="item.dataIndex"
64
- slot-scope="text, record">
65
- <!-- 文本溢出省略(ellipsis) -->
66
- <span v-if="item.slotType === 'ellipsis'" :key="index">
67
- <ellipsis :length="item.slotValue" tooltip>{{ text === '' ? '--' : text }}</ellipsis>
68
- </span>
69
- <!-- 徽标(badge) -->
70
- <span v-else-if="item.slotType === 'badge'" :key="index">
71
- <x-badge v-if="text !== null && text !== undefined" :badge-key="item.slotKeyMap" :value="text" />
72
- </span>
73
- <!-- 日期(date) -->
74
- <span v-else-if="item.slotType === 'date'" :key="index">
75
- {{ format(text,'yyyy-MM-dd') }}
76
- </span>
77
- <!-- 日期时间(datetime) -->
78
- <span v-else-if="item.slotType === 'dateTime'" :key="index">
79
- {{ format(text,'yyyy-MM-dd hh:mm:ss') }}
80
- </span>
81
- <!-- 操作列(action) -->
82
- <span v-else-if="item.slotType === 'action'" :key="index">
83
- <a @click="action(record, item.dataIndex)">{{ item.slotValue }}</a>
84
- </span>
85
- </template>
86
- <template slot="footer">
87
- <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
88
- </template>
89
- </s-table>
90
- <!-- 上传文件 -->
91
- <x-import-excel
92
- ref="importExcel"
93
- @ok="refresh(true)"
94
- :title="title"
95
- :service-name="serviceName"
96
- :query-params-name="queryParamsName"
97
- />
98
- </div>
99
- </template>
100
- <script>
101
- import { Ellipsis, STable } from '@vue2-client/components'
102
- import { formatDate } from '@vue2-client/utils/util'
103
- import XBadge from '@vue2-client/base-client/components/common/XBadge'
104
- import TableSetting from '@vue2-client/components/TableSetting/TableSetting'
105
- import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
106
- import { exportData, query, queryWithResource, remove } from '@vue2-client/services/api/common'
107
- import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
108
- import { Modal } from 'ant-design-vue'
109
- import { post } from '@vue2-client/services/api'
110
- import { CommonTempTable } from '@vue2-client/services/api/commonTempTable'
111
-
112
- export default {
113
- name: 'XTable',
114
- components: {
115
- TableSetting,
116
- STable,
117
- Ellipsis,
118
- XBadge,
119
- XImportExcel
120
- },
121
- data () {
122
- return {
123
- // 筛选列加载状态
124
- columnSelectLoaded: false,
125
- // 预览模式
126
- viewMode: false,
127
- // 加载数据方法 必须为 Promise 对象
128
- loadData: parameter => {
129
- // 取到表格携带的表单参数
130
- const requestParameters = Object.assign({}, parameter)
131
- // 取到父组件传入的表单参数
132
- const conditionParams = {}
133
- Object.assign(conditionParams, this.fixedQueryForm)
134
- Object.assign(conditionParams, this.form)
135
- // 如果传了燃气公司字段,则进行数据处理
136
- if (conditionParams.orgName) {
137
- requestParameters.orgName = conditionParams.orgName
138
- delete conditionParams.orgName
139
- }
140
- requestParameters.conditionParams = conditionParams
141
- requestParameters.queryParamsName = this.queryParamsName
142
- requestParameters.queryParams = this.queryParams
143
- // 加载数据
144
- return this.loadTableData(requestParameters)
145
- },
146
- rowKey: undefined,
147
- // x滚动条宽度
148
- scrollXWidth: 1600,
149
- // y滚动条高度
150
- scrollYHeight: 437,
151
- // 表格选择列Key集合
152
- selectedRowKeys: [],
153
- // 表格选择Row集合
154
- selectedRows: [],
155
- // 业务标题
156
- title: '',
157
- // 数据列
158
- tableColumns: [],
159
- // 查询用表单
160
- form: {},
161
- // 是否允许修改
162
- isModify: false,
163
- // 是否允许删除
164
- isDelete: false,
165
- // 服务名称
166
- serviceName: undefined,
167
- // 选中用于修改的id
168
- selectId: undefined,
169
- // 是否为临时表
170
- isTableTemp: false,
171
- // 是否显示展示列抽屉
172
- visible: false,
173
- // 编辑按钮加载状态
174
- editLoading: false,
175
- // 按钮状态
176
- buttonState: {},
177
- // 图标样式
178
- iconStyle: {
179
- position: 'relative',
180
- top: '1px'
181
- }
182
- }
183
- },
184
- props: {
185
- // 查询配置文件名
186
- queryParamsName: {
187
- type: String,
188
- default: () => {
189
- return ''
190
- }
191
- },
192
- // 查询配置文件Json
193
- queryParamsJson: {
194
- type: Object,
195
- default: null
196
- },
197
- // 固定查询表单
198
- fixedQueryForm: {
199
- type: Object,
200
- default: () => {
201
- return {}
202
- }
203
- },
204
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
205
- showPagination: {
206
- type: Boolean,
207
- default: true
208
- }
209
- },
210
- computed: {
211
- rowSelection () {
212
- return {
213
- selectedRowKeys: this.selectedRowKeys,
214
- onChange: this.onSelectChange
215
- }
216
- }
217
- },
218
- mounted () {},
219
- methods: {
220
- /**
221
- * 初始化表格参数
222
- */
223
- init (params) {
224
- const {
225
- // 查询参数对象, 用于没有对应查询配置文件名时
226
- queryParams,
227
- tableColumns,
228
- buttonState,
229
- title,
230
- serviceName,
231
- viewMode
232
- } = params
233
- this.queryParams = queryParams
234
- this.tableColumns = JSON.parse(JSON.stringify(tableColumns))
235
- if (this.tableColumns.length === 0) {
236
- return
237
- }
238
- this.buttonState = buttonState
239
- this.title = title
240
- this.serviceName = serviceName
241
- this.viewMode = viewMode
242
- this.rowKey = this.tableColumns[0].dataIndex
243
- let totalWidth = 0
244
- // 设置表格宽度
245
- for (let i = 0; i < this.tableColumns.length; i++) {
246
- const item = this.tableColumns[i]
247
- if (item.slotType === 'action') {
248
- item.fixed = 'right'
249
- item.width = 70
250
- }
251
- if (item.width) {
252
- totalWidth = totalWidth + item.width
253
- } else {
254
- totalWidth = totalWidth + 180
255
- }
256
- }
257
- // 设置表格高度
258
- // const height = document.documentElement.clientHeight
259
- // if (height >= 1070) {
260
- // this.scrollYHeight = 'calc(100vh - 526px)'
261
- // } else {
262
- // this.scrollYHeight = 'calc(100vh - 398px)'
263
- // }
264
- // 设置表格高度为固定值
265
- this.scrollYHeight = 'calc(100vh - 33rem)'
266
- // 横向滚动长度大于所有宽度,才能实现固定表头
267
- this.scrollXWidth = totalWidth
268
- // 加载筛选列完成
269
- this.columnSelectLoaded = true
270
- this.setQueryForm({})
271
- },
272
- /**
273
- * 加载表格数据
274
- * @param requestParameters 请求参数
275
- */
276
- loadTableData (requestParameters) {
277
- let result = {}
278
- if (this.queryParamsJson) {
279
- if (this.queryParamsJson.tableName.startsWith('##')) {
280
- this.isTableTemp = true
281
- result = this.initTempTable(requestParameters)
282
- }
283
- }
284
- if (!this.isTableTemp) {
285
- result = query(requestParameters, this.serviceName)
286
- }
287
- this.clearRowKeys()
288
- this.$emit('afterQuery', result, requestParameters.conditionParams)
289
- return result
290
- },
291
- /**
292
- * 操作列事件
293
- * @param record 本条数据
294
- * @param actionType 操作类型
295
- */
296
- action (record, actionType) {
297
- this.$emit('action', record, record[this.getPrimaryKeyName()], actionType)
298
- },
299
- /**
300
- * 选择列事件
301
- * @param selectedRowKeys 被选择的列Key集合
302
- * @param selectedRows 被选择的列集合
303
- */
304
- onSelectChange (selectedRowKeys, selectedRows) {
305
- this.selectedRowKeys = selectedRowKeys
306
- this.selectedRows = selectedRows
307
- this.isModify = this.selectedRowKeys.length === 1
308
- this.isDelete = this.selectedRowKeys.length > 0
309
- this.$emit('selectRow', selectedRowKeys, selectedRows)
310
- },
311
- /**
312
- * 清除表格选中项
313
- */
314
- clearRowKeys () {
315
- this.$refs.table.clearSelected()
316
- },
317
- /**
318
- * 为表格附加查询条件
319
- */
320
- setQueryForm (form = {}) {
321
- this.form = form
322
- this.refresh(true)
323
- },
324
- /**
325
- * 表格重新加载方法
326
- * 如果参数为 true, 则强制刷新到第一页
327
- */
328
- refresh (bool) {
329
- this.$nextTick(() => {
330
- this.$refs.table.refresh(bool)
331
- })
332
- },
333
- /**
334
- * 格式化日期
335
- * @param date 日期字符串
336
- * @param format 格式化方式
337
- */
338
- format (date, format) {
339
- return formatDate(date, format)
340
- },
341
- /**
342
- * 获取主键列名称
343
- */
344
- getPrimaryKeyName () {
345
- return this.tableColumns[0].dataIndex
346
- },
347
- // 导出选中或本页数据
348
- handleExport (isSelected) {
349
- const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
350
- const filterVal = this.tableColumns.map(res => res.dataIndex)
351
- let exportData
352
- if (isSelected) {
353
- exportData = this.selectedRows
354
- } else {
355
- exportData = this.$refs.table.localDataSource
356
- }
357
- exportJson(tHeader, exportData.map(v => filterVal.map(j => v[j])), this.title + `数据_${new Date().toLocaleString()}`)
358
- },
359
- // 导出符合条件的数据
360
- handleExportByQuery () {
361
- const that = this
362
- const conditionParams = Object.assign(that.form, that.fixedQueryForm)
363
- this.$confirm({
364
- title: '是否确认导出?',
365
- content: '此操作将导出当前条件下所有数据而非选中数据',
366
- onOk () {
367
- exportData({
368
- queryParamsName: that.queryParamsName,
369
- queryParams: that.queryParams,
370
- form: conditionParams
371
- }, that.serviceName).then(res => {
372
- window.open('/res/excel/export/' + res)
373
- })
374
- },
375
- onCancel () {}
376
- })
377
- },
378
- // 新增业务
379
- add () {
380
- this.$emit('add')
381
- },
382
- // 编辑业务
383
- edit (id) {
384
- this.editLoading = true
385
- this.getEditData(id).then(modifyModelData => {
386
- this.$emit('edit', modifyModelData)
387
- this.editLoading = false
388
- })
389
- },
390
- // 获取被编辑的数据
391
- getEditData (id) {
392
- const requestParameters = {
393
- queryParamsName: this.queryParamsName,
394
- queryParams: this.queryParams,
395
- conditionParams: {},
396
- pageNo: 1,
397
- pageSize: 1
398
- }
399
- if (!id) {
400
- this.selectId = this.selectedRowKeys[0]
401
- } else {
402
- this.selectId = id
403
- }
404
- const primaryKeyName = this.getPrimaryKeyName()
405
- requestParameters.conditionParams[primaryKeyName] = this.selectId
406
- requestParameters.f_businessid = this.selectId
407
- if (this.isTableTemp) {
408
- this.$emit('tempTableEdit', requestParameters)
409
- return
410
- }
411
- return queryWithResource(requestParameters, this.serviceName).then(res => {
412
- // 将更新需要的主键值加入到primaryKeyData中
413
- const primaryKeyData = {}
414
- primaryKeyData[primaryKeyName] = this.selectId
415
- return { data: res.data[0], primaryKeyData: primaryKeyData, images: res.images, files: res.files }
416
- })
417
- },
418
- // 删除业务
419
- deleteItem () {
420
- if (this.viewMode) {
421
- this.$message.info('预览模式禁止删除')
422
- return
423
- }
424
- Modal.confirm({
425
- title: '提示',
426
- content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
427
- zIndex: 1001,
428
- onOk: () => {
429
- return new Promise((resolve, reject) => {
430
- const requestParameters = {
431
- queryParamsName: this.queryParamsName,
432
- idList: this.selectedRowKeys
433
- }
434
- remove(requestParameters, this.serviceName).then(res => {
435
- resolve(res)
436
- this.$message.success('删除成功!')
437
- this.refresh(true)
438
- // afterDelete
439
- this.$emit('afterDelete', requestParameters)
440
- }).catch(e => {
441
- reject(e)
442
- this.$message.error('删除失败!')
443
- })
444
- })
445
- },
446
- onCancel () {}
447
- })
448
- },
449
- // 导入业务
450
- importData () {
451
- this.$refs.importExcel.importExcelHandleOpen()
452
- },
453
- // 初始化临时表
454
- async initTempTable (json) {
455
- await this.createTempTable(this.queryParamsJson)
456
- await this.insertTempTableData(this.queryParamsJson)
457
- let result = {}
458
- await post(CommonTempTable.initApplySubTable, {
459
- define: json
460
- }).then(res => {
461
- console.log('子表临时表已创建')
462
- result = res
463
- })
464
- return result
465
- },
466
- // 创建临时表sql生成
467
- createTempTable (defineJson) {
468
- const tableName = defineJson.tableName
469
- const define = defineJson.column
470
- return post(CommonTempTable.createTempTable, {
471
- define: define,
472
- tableName: tableName
473
- }).then(res => {
474
- return res
475
- }, err => {
476
- console.log(err)
477
- })
478
- },
479
- // 插入临时表数据sql生成
480
- insertTempTableData (defineJson) {
481
- const tableName = defineJson.tableName
482
- const params = {}
483
- params.define = defineJson.column
484
- params.applyId = defineJson.applyId
485
- params.stepName = defineJson.stepName
486
- params.tableName = tableName
487
- return post(CommonTempTable.insertDataToTempTable, {
488
- tempTableData: params
489
- }).then(res => {
490
- return res
491
- })
492
- }
493
- }
494
- }
495
- </script>
496
- <style lang="less" scoped>
497
- .btn-success {
498
- color: #ffffff;
499
- }
500
- .btn-success:enabled:hover {
501
- background-color: #85CE61 !important;
502
- border-color: #85CE61 !important;
503
- }
504
- .btn-success:enabled {
505
- background-color: #67c23a;
506
- border-color: #67c23a;
507
- }
508
- .btn-success:disabled {
509
- color: rgba(0, 0, 0, 0.25);
510
- }
511
- .btn-warn {
512
- color: #ffffff;
513
- }
514
- .btn-warn:enabled:hover {
515
- background-color: #ffc833 !important;
516
- border-color: #ffc833 !important;
517
- }
518
- .btn-warn:enabled {
519
- background-color: #ffba00;
520
- border-color: #ffba00;
521
- }
522
- .btn-warn:disabled {
523
- color: rgba(0, 0, 0, 0.25);
524
- }
525
- </style>
1
+ <template>
2
+ <div v-show="tableColumns.length > 0">
3
+ <a-row :gutter="48">
4
+ <a-col>
5
+ <span :style="{ float: 'left', overflow: 'hidden', marginBottom: '8px' }">
6
+ <a-space>
7
+ <slot name="leftButton" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
8
+ <a-button v-if="!buttonState || buttonState.add" type="primary" @click="add">
9
+ <a-icon :style="iconStyle" type="plus"/>新增
10
+ </a-button>
11
+ <a-button
12
+ v-if="!buttonState || buttonState.edit"
13
+ :disabled="!isModify"
14
+ :loading="editLoading"
15
+ class="btn-success"
16
+ type="dashed"
17
+ @click="edit()">
18
+ <a-icon :style="iconStyle" type="edit"/>修改
19
+ </a-button>
20
+ <a-button v-if="!buttonState || buttonState.delete" :disabled="!isDelete" type="danger" @click="deleteItem">
21
+ <a-icon :style="iconStyle" type="delete"/>删除
22
+ </a-button>
23
+ <a-button v-if="!buttonState || buttonState.import" type="dashed" @click="importData">
24
+ <a-icon :style="iconStyle" type="import" />导入
25
+ </a-button>
26
+ <a-dropdown v-if="!buttonState || buttonState.export">
27
+ <a-menu slot="overlay">
28
+ <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport(true)"><a-icon :style="iconStyle" type="ordered-list" />导出选中数据</a-menu-item>
29
+ <a-menu-item key="2" @click="handleExport(false)"><a-icon :style="iconStyle" type="snippets" />导出本页数据</a-menu-item>
30
+ <a-menu-item key="3" @click="handleExportByQuery"><a-icon :style="iconStyle" type="download" />导出所有符合条件的数据</a-menu-item>
31
+ </a-menu>
32
+ <a-button>导出 <a-icon type="down" /> </a-button>
33
+ </a-dropdown>
34
+ <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
35
+ </a-space>
36
+ </span>
37
+ </a-col>
38
+ <a-col>
39
+ <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
40
+ <a-button-group>
41
+ <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
42
+ <a-button @click="refresh(true)">
43
+ <a-icon :style="iconStyle" type="reload" />
44
+ </a-button>
45
+ <table-setting v-if="columnSelectLoaded" v-model="tableColumns" />
46
+ </a-button-group>
47
+ </span>
48
+ </a-col>
49
+ </a-row>
50
+ <s-table
51
+ ref="table"
52
+ :alert="true"
53
+ :columns="tableColumns"
54
+ :data="loadData"
55
+ :rowKey="rowKey"
56
+ :rowSelection="rowSelection"
57
+ :scroll="{ x: scrollXWidth, y: scrollYHeight }"
58
+ :showPagination="showPagination"
59
+ size="default"
60
+ >
61
+ <template
62
+ v-for="(item, index) in tableColumns"
63
+ :slot="item.dataIndex"
64
+ slot-scope="text, record">
65
+ <!-- 文本溢出省略(ellipsis) -->
66
+ <span v-if="item.slotType === 'ellipsis'" :key="index">
67
+ <ellipsis :length="item.slotValue" tooltip>{{ text === '' ? '--' : text }}</ellipsis>
68
+ </span>
69
+ <!-- 徽标(badge) -->
70
+ <span v-else-if="item.slotType === 'badge'" :key="index">
71
+ <x-badge v-if="text !== null && text !== undefined" :badge-key="item.slotKeyMap" :value="text" />
72
+ </span>
73
+ <!-- 日期(date) -->
74
+ <span v-else-if="item.slotType === 'date'" :key="index">
75
+ {{ format(text,'yyyy-MM-dd') }}
76
+ </span>
77
+ <!-- 日期时间(datetime) -->
78
+ <span v-else-if="item.slotType === 'dateTime'" :key="index">
79
+ {{ format(text,'yyyy-MM-dd hh:mm:ss') }}
80
+ </span>
81
+ <!-- 操作列(action) -->
82
+ <span v-else-if="item.slotType === 'action'" :key="index">
83
+ <a @click="action(record, item.dataIndex)">{{ item.slotValue }}</a>
84
+ </span>
85
+ </template>
86
+ <template slot="footer">
87
+ <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
88
+ </template>
89
+ </s-table>
90
+ <!-- 上传文件 -->
91
+ <x-import-excel
92
+ ref="importExcel"
93
+ @ok="refresh(true)"
94
+ :title="title"
95
+ :service-name="serviceName"
96
+ :query-params-name="queryParamsName"
97
+ />
98
+ </div>
99
+ </template>
100
+ <script>
101
+ import { Ellipsis, STable } from '@vue2-client/components'
102
+ import { formatDate } from '@vue2-client/utils/util'
103
+ import XBadge from '@vue2-client/base-client/components/common/XBadge'
104
+ import TableSetting from '@vue2-client/components/TableSetting/TableSetting'
105
+ import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
106
+ import { exportData, query, queryWithResource, remove } from '@vue2-client/services/api/common'
107
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
108
+ import { Modal } from 'ant-design-vue'
109
+ import { post } from '@vue2-client/services/api'
110
+ import { CommonTempTable } from '@vue2-client/services/api/commonTempTable'
111
+ import { mapState } from 'vuex'
112
+
113
+ export default {
114
+ name: 'XTable',
115
+ components: {
116
+ TableSetting,
117
+ STable,
118
+ Ellipsis,
119
+ XBadge,
120
+ XImportExcel
121
+ },
122
+ data () {
123
+ return {
124
+ // 筛选列加载状态
125
+ columnSelectLoaded: false,
126
+ // 预览模式
127
+ viewMode: false,
128
+ // 加载数据方法 必须为 Promise 对象
129
+ loadData: parameter => {
130
+ // 取到表格携带的表单参数
131
+ const requestParameters = Object.assign({}, parameter)
132
+ // 取到父组件传入的表单参数
133
+ const conditionParams = {}
134
+ Object.assign(conditionParams, this.fixedQueryForm)
135
+ Object.assign(conditionParams, this.form)
136
+ // 如果传了燃气公司字段,则进行数据处理
137
+ if (conditionParams.orgName) {
138
+ requestParameters.orgName = conditionParams.orgName
139
+ delete conditionParams.orgName
140
+ }
141
+ requestParameters.conditionParams = conditionParams
142
+ requestParameters.queryParamsName = this.queryParamsName
143
+ requestParameters.queryParams = this.queryParams
144
+ // 加载数据
145
+ return this.loadTableData(requestParameters)
146
+ },
147
+ rowKey: undefined,
148
+ // x滚动条宽度
149
+ scrollXWidth: 1600,
150
+ // y滚动条高度
151
+ scrollYHeight: 437,
152
+ // 表格选择列Key集合
153
+ selectedRowKeys: [],
154
+ // 表格选择Row集合
155
+ selectedRows: [],
156
+ // 业务标题
157
+ title: '',
158
+ // 数据列
159
+ tableColumns: [],
160
+ // 查询用表单
161
+ form: {},
162
+ // 是否允许修改
163
+ isModify: false,
164
+ // 是否允许删除
165
+ isDelete: false,
166
+ // 服务名称
167
+ serviceName: undefined,
168
+ // 选中用于修改的id
169
+ selectId: undefined,
170
+ // 是否为临时表
171
+ isTableTemp: false,
172
+ // 是否显示展示列抽屉
173
+ visible: false,
174
+ // 编辑按钮加载状态
175
+ editLoading: false,
176
+ // 按钮状态
177
+ buttonState: {},
178
+ // 图标样式
179
+ iconStyle: {
180
+ position: 'relative',
181
+ top: '1px'
182
+ }
183
+ }
184
+ },
185
+ props: {
186
+ // 查询配置文件名
187
+ queryParamsName: {
188
+ type: String,
189
+ default: () => {
190
+ return ''
191
+ }
192
+ },
193
+ // 查询配置文件Json
194
+ queryParamsJson: {
195
+ type: Object,
196
+ default: null
197
+ },
198
+ // 固定查询表单
199
+ fixedQueryForm: {
200
+ type: Object,
201
+ default: () => {
202
+ return {}
203
+ }
204
+ },
205
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
206
+ showPagination: {
207
+ type: Boolean,
208
+ default: true
209
+ }
210
+ },
211
+ computed: {
212
+ rowSelection () {
213
+ return {
214
+ selectedRowKeys: this.selectedRowKeys,
215
+ onChange: this.onSelectChange
216
+ }
217
+ },
218
+ ...mapState('setting', ['compatible'])
219
+ },
220
+ mounted () {},
221
+ methods: {
222
+ /**
223
+ * 初始化表格参数
224
+ */
225
+ init (params) {
226
+ const {
227
+ // 查询参数对象, 用于没有对应查询配置文件名时
228
+ queryParams,
229
+ tableColumns,
230
+ buttonState,
231
+ title,
232
+ serviceName,
233
+ viewMode
234
+ } = params
235
+ this.queryParams = queryParams
236
+ this.tableColumns = JSON.parse(JSON.stringify(tableColumns))
237
+ if (this.tableColumns.length === 0) {
238
+ return
239
+ }
240
+ this.buttonState = buttonState
241
+ this.title = title
242
+ this.serviceName = serviceName
243
+ this.viewMode = viewMode
244
+ this.rowKey = this.tableColumns[0].dataIndex
245
+ let totalWidth = 0
246
+ // 设置表格宽度
247
+ for (let i = 0; i < this.tableColumns.length; i++) {
248
+ const item = this.tableColumns[i]
249
+ if (item.slotType === 'action') {
250
+ item.fixed = 'right'
251
+ item.width = 70
252
+ }
253
+ if (item.width) {
254
+ totalWidth = totalWidth + item.width
255
+ } else {
256
+ totalWidth = totalWidth + 180
257
+ }
258
+ }
259
+ // 设置表格高度
260
+ // const height = document.documentElement.clientHeight
261
+ // if (height >= 1070) {
262
+ // this.scrollYHeight = 'calc(100vh - 526px)'
263
+ // } else {
264
+ // this.scrollYHeight = 'calc(100vh - 398px)'
265
+ // }
266
+ // 设置表格高度为固定值
267
+ this.scrollYHeight = 'calc(100vh - 33rem)'
268
+ // 横向滚动长度大于所有宽度,才能实现固定表头
269
+ this.scrollXWidth = totalWidth
270
+ // 加载筛选列完成
271
+ this.columnSelectLoaded = true
272
+ this.setQueryForm({})
273
+ },
274
+ /**
275
+ * 加载表格数据
276
+ * @param requestParameters 请求参数
277
+ */
278
+ loadTableData (requestParameters) {
279
+ let result = {}
280
+ if (this.queryParamsJson) {
281
+ if (this.queryParamsJson.tableName.startsWith('##')) {
282
+ this.isTableTemp = true
283
+ result = this.initTempTable(requestParameters)
284
+ }
285
+ }
286
+ if (!this.isTableTemp) {
287
+ result = query(requestParameters, this.serviceName)
288
+ }
289
+ this.clearRowKeys()
290
+ this.$emit('afterQuery', result, requestParameters.conditionParams)
291
+ return result
292
+ },
293
+ /**
294
+ * 操作列事件
295
+ * @param record 本条数据
296
+ * @param actionType 操作类型
297
+ */
298
+ action (record, actionType) {
299
+ this.$emit('action', record, record[this.getPrimaryKeyName()], actionType)
300
+ },
301
+ /**
302
+ * 选择列事件
303
+ * @param selectedRowKeys 被选择的列Key集合
304
+ * @param selectedRows 被选择的列集合
305
+ */
306
+ onSelectChange (selectedRowKeys, selectedRows) {
307
+ this.selectedRowKeys = selectedRowKeys
308
+ this.selectedRows = selectedRows
309
+ this.isModify = this.selectedRowKeys.length === 1
310
+ this.isDelete = this.selectedRowKeys.length > 0
311
+ this.$emit('selectRow', selectedRowKeys, selectedRows)
312
+ },
313
+ /**
314
+ * 清除表格选中项
315
+ */
316
+ clearRowKeys () {
317
+ this.$refs.table.clearSelected()
318
+ },
319
+ /**
320
+ * 为表格附加查询条件
321
+ */
322
+ setQueryForm (form = {}) {
323
+ this.form = form
324
+ this.refresh(true)
325
+ },
326
+ /**
327
+ * 表格重新加载方法
328
+ * 如果参数为 true, 则强制刷新到第一页
329
+ */
330
+ refresh (bool) {
331
+ this.$nextTick(() => {
332
+ this.$refs.table.refresh(bool)
333
+ })
334
+ },
335
+ /**
336
+ * 格式化日期
337
+ * @param date 日期字符串
338
+ * @param format 格式化方式
339
+ */
340
+ format (date, format) {
341
+ return formatDate(date, format)
342
+ },
343
+ /**
344
+ * 获取主键列名称
345
+ */
346
+ getPrimaryKeyName () {
347
+ return this.tableColumns[0].dataIndex
348
+ },
349
+ // 导出选中或本页数据
350
+ handleExport (isSelected) {
351
+ const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
352
+ const filterVal = this.tableColumns.map(res => res.dataIndex)
353
+ let exportData
354
+ if (isSelected) {
355
+ exportData = this.selectedRows
356
+ } else {
357
+ exportData = this.$refs.table.localDataSource
358
+ }
359
+ exportJson(tHeader, exportData.map(v => filterVal.map(j => v[j])), this.title + `数据_${new Date().toLocaleString()}`)
360
+ },
361
+ // 导出符合条件的数据
362
+ handleExportByQuery () {
363
+ const that = this
364
+ const conditionParams = Object.assign(that.form, that.fixedQueryForm)
365
+ this.$confirm({
366
+ title: '是否确认导出?',
367
+ content: '此操作将导出当前条件下所有数据而非选中数据',
368
+ onOk () {
369
+ exportData({
370
+ queryParamsName: that.queryParamsName,
371
+ queryParams: that.queryParams,
372
+ form: conditionParams
373
+ }, that.serviceName).then(res => {
374
+ let value = res
375
+ if (that.compatible === 'V4') {
376
+ value = res.value
377
+ }
378
+ window.open('/res/excel/export/' + value)
379
+ })
380
+ },
381
+ onCancel () {}
382
+ })
383
+ },
384
+ // 新增业务
385
+ add () {
386
+ this.$emit('add')
387
+ },
388
+ // 编辑业务
389
+ edit (id) {
390
+ this.editLoading = true
391
+ this.getEditData(id).then(modifyModelData => {
392
+ this.$emit('edit', modifyModelData)
393
+ this.editLoading = false
394
+ })
395
+ },
396
+ // 获取被编辑的数据
397
+ getEditData (id) {
398
+ const requestParameters = {
399
+ queryParamsName: this.queryParamsName,
400
+ queryParams: this.queryParams,
401
+ conditionParams: {},
402
+ pageNo: 1,
403
+ pageSize: 1
404
+ }
405
+ if (!id) {
406
+ this.selectId = this.selectedRowKeys[0]
407
+ } else {
408
+ this.selectId = id
409
+ }
410
+ const primaryKeyName = this.getPrimaryKeyName()
411
+ requestParameters.conditionParams[primaryKeyName] = this.selectId
412
+ requestParameters.f_businessid = this.selectId
413
+ if (this.isTableTemp) {
414
+ this.$emit('tempTableEdit', requestParameters)
415
+ return
416
+ }
417
+ return queryWithResource(requestParameters, this.serviceName).then(res => {
418
+ // 将更新需要的主键值加入到primaryKeyData中
419
+ const primaryKeyData = {}
420
+ primaryKeyData[primaryKeyName] = this.selectId
421
+ return { data: res.data[0], primaryKeyData: primaryKeyData, images: res.images, files: res.files }
422
+ })
423
+ },
424
+ // 删除业务
425
+ deleteItem () {
426
+ if (this.viewMode) {
427
+ this.$message.info('预览模式禁止删除')
428
+ return
429
+ }
430
+ Modal.confirm({
431
+ title: '提示',
432
+ content: '您本次要删除共' + this.selectedRowKeys.length + '条数据,确定操作吗?',
433
+ zIndex: 1001,
434
+ onOk: () => {
435
+ return new Promise((resolve, reject) => {
436
+ const requestParameters = {
437
+ queryParamsName: this.queryParamsName,
438
+ idList: this.selectedRowKeys
439
+ }
440
+ remove(requestParameters, this.serviceName).then(res => {
441
+ resolve(res)
442
+ this.$message.success('删除成功!')
443
+ this.refresh(true)
444
+ // afterDelete
445
+ this.$emit('afterDelete', requestParameters)
446
+ }).catch(e => {
447
+ reject(e)
448
+ this.$message.error('删除失败!')
449
+ })
450
+ })
451
+ },
452
+ onCancel () {}
453
+ })
454
+ },
455
+ // 导入业务
456
+ importData () {
457
+ this.$refs.importExcel.importExcelHandleOpen()
458
+ },
459
+ // 初始化临时表
460
+ async initTempTable (json) {
461
+ await this.createTempTable(this.queryParamsJson)
462
+ await this.insertTempTableData(this.queryParamsJson)
463
+ let result = {}
464
+ await post(CommonTempTable.initApplySubTable, {
465
+ define: json
466
+ }).then(res => {
467
+ console.log('子表临时表已创建')
468
+ result = res
469
+ })
470
+ return result
471
+ },
472
+ // 创建临时表sql生成
473
+ createTempTable (defineJson) {
474
+ const tableName = defineJson.tableName
475
+ const define = defineJson.column
476
+ return post(CommonTempTable.createTempTable, {
477
+ define: define,
478
+ tableName: tableName
479
+ }).then(res => {
480
+ return res
481
+ }, err => {
482
+ console.log(err)
483
+ })
484
+ },
485
+ // 插入临时表数据sql生成
486
+ insertTempTableData (defineJson) {
487
+ const tableName = defineJson.tableName
488
+ const params = {}
489
+ params.define = defineJson.column
490
+ params.applyId = defineJson.applyId
491
+ params.stepName = defineJson.stepName
492
+ params.tableName = tableName
493
+ return post(CommonTempTable.insertDataToTempTable, {
494
+ tempTableData: params
495
+ }).then(res => {
496
+ return res
497
+ })
498
+ }
499
+ }
500
+ }
501
+ </script>
502
+ <style lang="less" scoped>
503
+ .btn-success {
504
+ color: #ffffff;
505
+ }
506
+ .btn-success:enabled:hover {
507
+ background-color: #85CE61 !important;
508
+ border-color: #85CE61 !important;
509
+ }
510
+ .btn-success:enabled {
511
+ background-color: #67c23a;
512
+ border-color: #67c23a;
513
+ }
514
+ .btn-success:disabled {
515
+ color: rgba(0, 0, 0, 0.25);
516
+ }
517
+ .btn-warn {
518
+ color: #ffffff;
519
+ }
520
+ .btn-warn:enabled:hover {
521
+ background-color: #ffc833 !important;
522
+ border-color: #ffc833 !important;
523
+ }
524
+ .btn-warn:enabled {
525
+ background-color: #ffba00;
526
+ border-color: #ffba00;
527
+ }
528
+ .btn-warn:disabled {
529
+ color: rgba(0, 0, 0, 0.25);
530
+ }
531
+ </style>