vue2-client 1.3.25 → 1.4.1

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,278 +1,259 @@
1
- <template>
2
- <div>
3
- <custom-columns-drawer
4
- :columns-meta="jsonData"
5
- :columns.sync="tableColumns"
6
- :visible.sync="visible"/>
7
- <a-row :gutter="48">
8
- <a-col>
9
- <span :style="{ float: 'left', overflow: 'hidden', marginBottom: '8px' }">
10
- <slot name="expand"></slot>
11
- </span>
12
- </a-col>
13
- <a-col>
14
- <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
15
- <a-button-group>
16
- <a-button @click="toggleIsFormShow">
17
- <a-icon :style="iconStyle" type="vertical-align-top"/>
18
- </a-button>
19
- <a-button @click="refresh(true)">
20
- <a-icon :style="iconStyle" type="reload" />
21
- </a-button>
22
- <a-button @click="showDrawer">
23
- <a-icon :style="iconStyle" type="table" />
24
- </a-button>
25
- <a-button v-if="!buttonState || buttonState.export" @click="exports">
26
- <a-icon :style="iconStyle" type="cloud-download"/>
27
- </a-button>
28
- </a-button-group>
29
- </span>
30
- </a-col>
31
- </a-row>
32
- <s-table
33
- ref="table"
34
- :alert="true"
35
- :columns="tableColumns"
36
- :data="loadData"
37
- :rowKey="rowKey"
38
- :rowSelection="rowSelection"
39
- :scroll="{ x: scrollXWidth, y: scrollYWidth }"
40
- :showPagination="showPagination"
41
- size="default"
42
- >
43
- <template
44
- v-for="(item, index) in tableColumns"
45
- :slot="item.dataIndex"
46
- slot-scope="text, record">
47
- <!-- 文本溢出省略(ellipsis) -->
48
- <span v-if="item.slotType === 'ellipsis'" :key="index">
49
- <ellipsis :length="item.slotValue" tooltip>{{ text === '' ? '--' : text }}</ellipsis>
50
- </span>
51
- <!-- 徽标(badge) -->
52
- <span v-else-if="item.slotType === 'badge'" :key="index">
53
- <x-badge :badge-key="item.slotKeyMap" :value="text" />
54
- </span>
55
- <!-- 日期(date) -->
56
- <span v-else-if="item.slotType === 'date'" :key="index">
57
- {{ format(text,'yyyy-MM-dd') }}
58
- </span>
59
- <!-- 日期时间(datetime) -->
60
- <span v-else-if="item.slotType === 'dateTime'" :key="index">
61
- {{ format(text,'yyyy-MM-dd hh:mm:ss') }}
62
- </span>
63
- <!-- 操作列(action) -->
64
- <span v-else-if="item.slotType === 'action'" :key="index">
65
- <a @click="action(record)">{{ item.slotValue }}</a>
66
- </span>
67
- </template>
68
- </s-table>
69
- </div>
70
- </template>
71
- <script>
72
- import { Ellipsis, STable } from '@vue2-client/components'
73
- import { formatDate } from '@vue2-client/utils/util'
74
- import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
75
- import CustomColumnsDrawer from '@vue2-client/base-client/components/common/CustomColumnsDrawer'
76
- import XBadge from '@vue2-client/base-client/components/common/XBadge'
77
-
78
- export default {
79
- name: 'XTable',
80
- components: {
81
- STable,
82
- Ellipsis,
83
- CustomColumnsDrawer,
84
- XBadge
85
- },
86
- data () {
87
- return {
88
- // 加载数据方法 必须为 Promise 对象
89
- loadData: parameter => {
90
- // 取到表格携带的表单参数
91
- const requestParameters = Object.assign({}, parameter)
92
- // 取到父组件传入的表单参数
93
- const conditionParams = Object.assign(this.fixedQueryForm, this.form)
94
- // 如果适用了综合筛选表单,则进行数据处理
95
- if (conditionParams.rowIdName) {
96
- const rowIdName = conditionParams.rowIdName
97
- const rowIdValue = conditionParams.rowIdValue
98
- delete conditionParams.rowIdName
99
- delete conditionParams.rowIdValue
100
- if (rowIdValue) {
101
- conditionParams[rowIdName] = rowIdValue
102
- }
103
- }
104
- // 如果传了燃气公司字段,则进行数据处理
105
- if (conditionParams.orgName) {
106
- requestParameters.orgName = conditionParams.orgName
107
- delete conditionParams.orgName
108
- }
109
- requestParameters.conditionParams = conditionParams
110
- requestParameters.queryParamsName = this.queryParamsName
111
- requestParameters.queryParams = this.queryParams
112
- // 加载数据
113
- return this.loadTableData(requestParameters)
114
- },
115
- rowKey: undefined,
116
- scrollXWidth: 1600,
117
- scrollYWidth: 437,
118
- selectedRowKeys: [],
119
- selectedRows: [],
120
- // 数据列
121
- tableColumns: this.jsonData,
122
- // 是否显示展示列抽屉
123
- visible: false,
124
- dataSource: [],
125
- // 图标样式
126
- iconStyle: {
127
- position: 'relative',
128
- top: '1px'
129
- }
130
- }
131
- },
132
- watch: {
133
- form (rel) {
134
- this.form = rel
135
- this.refresh(true)
136
- },
137
- jsonData () {
138
- this.initTableParams()
139
- }
140
- },
141
- props: {
142
- jsonData: {
143
- type: Array,
144
- default: () => {
145
- return []
146
- }
147
- },
148
- queryParamsName: {
149
- type: String,
150
- default: () => {
151
- return ''
152
- }
153
- },
154
- // 查询参数对象, 用于没有对应查询配置文件名时
155
- queryParams: {
156
- type: Object,
157
- default: null
158
- },
159
- form: {
160
- type: Object,
161
- default: () => {
162
- return {}
163
- }
164
- },
165
- // 固定查询表单
166
- fixedQueryForm: {
167
- type: Object,
168
- default: () => {
169
- return {}
170
- }
171
- },
172
- // 按钮
173
- buttonState: {
174
- type: Object,
175
- default: () => {
176
- return undefined
177
- }
178
- },
179
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
180
- showPagination: {
181
- type: Boolean,
182
- default: true
183
- }
184
- },
185
- computed: {
186
- rowSelection () {
187
- return {
188
- selectedRowKeys: this.selectedRowKeys,
189
- onChange: this.onSelectChange
190
- }
191
- }
192
- },
193
- mounted () {
194
- this.initTableParams()
195
- },
196
- methods: {
197
- exports () {
198
- const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
199
- const filterVal = this.tableColumns.map(res => res.dataIndex)
200
- const list = this.dataSource
201
- const data = this.formatJson(filterVal, list)
202
- exportJson(tHeader, data, new Date())
203
- },
204
- formatJson (filterVal, jsonData) {
205
- return jsonData.map(v => filterVal.map(j => v[j]))
206
- },
207
- badgeFilter (key, value) {
208
- return this.$appdata.getParam(key, value)
209
- },
210
- initTableParams () {
211
- let totalWidth = 0
212
- this.rowKey = this.tableColumns[0].dataIndex
213
- for (let i = 0; i < this.tableColumns.length; i++) {
214
- const item = this.tableColumns[i]
215
- if (item.dataIndex === 'action') {
216
- item.fixed = 'right'
217
- item.width = 70
218
- }
219
- if (item.width) {
220
- totalWidth = totalWidth + item.width
221
- } else {
222
- totalWidth = totalWidth + 180
223
- }
224
- }
225
- const width = document.documentElement.clientWidth
226
- if (width >= 1600) {
227
- this.scrollYWidth = 429
228
- } else if (width >= 1200) {
229
- this.scrollYWidth = 390
230
- } else {
231
- this.scrollYWidth = 343
232
- }
233
- // 横向滚动长度大于所有宽度,才能实现固定表头
234
- this.scrollXWidth = totalWidth
235
- },
236
- loadTableData (requestParameters) {
237
- let data = []
238
- this.$emit('loadData', requestParameters, val => {
239
- data = val
240
- })
241
- const _this = this
242
- data.then(res => {
243
- _this.dataSource = res.data
244
- })
245
- return data
246
- },
247
- action (record) {
248
- this.$emit('action', record, record[this.jsonData[0].dataIndex])
249
- },
250
- onSelectChange (selectedRowKeys, selectedRows) {
251
- this.selectedRowKeys = selectedRowKeys
252
- this.selectedRows = selectedRows
253
- this.$emit('selectRow', selectedRowKeys)
254
- },
255
- clearRowKeys () {
256
- this.$refs.table.clearSelected()
257
- },
258
- /**
259
- * 表格重新加载方法
260
- * 如果参数为 true, 则强制刷新到第一页
261
- */
262
- refresh (bool) {
263
- this.$refs.table.refresh(bool)
264
- },
265
- format (date, format) {
266
- return formatDate(date, format)
267
- },
268
- showDrawer () {
269
- this.visible = true
270
- },
271
- toggleIsFormShow () {
272
- this.$emit('toggleIsFormShow')
273
- }
274
- }
275
- }
276
- </script>
277
- <style lang="less" scoped>
278
- </style>
1
+ <template>
2
+ <div>
3
+ <a-row :gutter="48">
4
+ <a-col>
5
+ <span :style="{ float: 'left', overflow: 'hidden', marginBottom: '8px' }">
6
+ <slot name="expand"></slot>
7
+ </span>
8
+ </a-col>
9
+ <a-col>
10
+ <span :style="{ float: 'right', overflow: 'hidden', marginBottom: '8px' }">
11
+ <a-button-group>
12
+ <a-button @click="toggleIsFormShow">
13
+ <a-icon :style="iconStyle" type="vertical-align-top"/>
14
+ </a-button>
15
+ <a-button @click="refresh(true)">
16
+ <a-icon :style="iconStyle" type="reload" />
17
+ </a-button>
18
+ <table-setting v-model="tableColumns" />
19
+ </a-button-group>
20
+ </span>
21
+ </a-col>
22
+ </a-row>
23
+ <s-table
24
+ ref="table"
25
+ :alert="true"
26
+ :columns="tableColumns"
27
+ :data="loadData"
28
+ :rowKey="rowKey"
29
+ :rowSelection="rowSelection"
30
+ :scroll="{ x: scrollXWidth, y: scrollYWidth }"
31
+ :showPagination="showPagination"
32
+ size="default"
33
+ >
34
+ <template
35
+ v-for="(item, index) in tableColumns"
36
+ :slot="item.dataIndex"
37
+ slot-scope="text, record">
38
+ <!-- 文本溢出省略(ellipsis) -->
39
+ <span v-if="item.slotType === 'ellipsis'" :key="index">
40
+ <ellipsis :length="item.slotValue" tooltip>{{ text === '' ? '--' : text }}</ellipsis>
41
+ </span>
42
+ <!-- 徽标(badge) -->
43
+ <span v-else-if="item.slotType === 'badge'" :key="index">
44
+ <x-badge :badge-key="item.slotKeyMap" :value="text" />
45
+ </span>
46
+ <!-- 日期(date) -->
47
+ <span v-else-if="item.slotType === 'date'" :key="index">
48
+ {{ format(text,'yyyy-MM-dd') }}
49
+ </span>
50
+ <!-- 日期时间(datetime) -->
51
+ <span v-else-if="item.slotType === 'dateTime'" :key="index">
52
+ {{ format(text,'yyyy-MM-dd hh:mm:ss') }}
53
+ </span>
54
+ <!-- 操作列(action) -->
55
+ <span v-else-if="item.slotType === 'action'" :key="index">
56
+ <a @click="action(record)">{{ item.slotValue }}</a>
57
+ </span>
58
+ </template>
59
+ </s-table>
60
+ </div>
61
+ </template>
62
+ <script>
63
+ import { Ellipsis, STable } from '@vue2-client/components'
64
+ import { formatDate } from '@vue2-client/utils/util'
65
+ import XBadge from '@vue2-client/base-client/components/common/XBadge'
66
+ import TableSetting from '@vue2-client/components/TableSetting/TableSetting'
67
+
68
+ export default {
69
+ name: 'XTable',
70
+ components: {
71
+ TableSetting,
72
+ STable,
73
+ Ellipsis,
74
+ XBadge
75
+ },
76
+ data () {
77
+ return {
78
+ // 加载数据方法 必须为 Promise 对象
79
+ loadData: parameter => {
80
+ // 取到表格携带的表单参数
81
+ const requestParameters = Object.assign({}, parameter)
82
+ // 取到父组件传入的表单参数
83
+ const conditionParams = Object.assign(this.fixedQueryForm, this.form)
84
+ // 如果适用了综合筛选表单,则进行数据处理
85
+ if (conditionParams.rowIdName) {
86
+ const rowIdName = conditionParams.rowIdName
87
+ const rowIdValue = conditionParams.rowIdValue
88
+ delete conditionParams.rowIdName
89
+ delete conditionParams.rowIdValue
90
+ if (rowIdValue) {
91
+ conditionParams[rowIdName] = rowIdValue
92
+ }
93
+ }
94
+ // 如果传了燃气公司字段,则进行数据处理
95
+ if (conditionParams.orgName) {
96
+ requestParameters.orgName = conditionParams.orgName
97
+ delete conditionParams.orgName
98
+ }
99
+ requestParameters.conditionParams = conditionParams
100
+ requestParameters.queryParamsName = this.queryParamsName
101
+ requestParameters.queryParams = this.queryParams
102
+ // 加载数据
103
+ return this.loadTableData(requestParameters)
104
+ },
105
+ rowKey: undefined,
106
+ scrollXWidth: 1600,
107
+ scrollYWidth: 437,
108
+ selectedRowKeys: [],
109
+ selectedRows: [],
110
+ // 数据列
111
+ tableColumns: this.jsonData,
112
+ // 是否显示展示列抽屉
113
+ visible: false,
114
+ loading: false,
115
+ dataSource: [],
116
+ // 图标样式
117
+ iconStyle: {
118
+ position: 'relative',
119
+ top: '1px'
120
+ }
121
+ }
122
+ },
123
+ watch: {
124
+ form (rel) {
125
+ this.form = rel
126
+ this.refresh(true)
127
+ },
128
+ jsonData () {
129
+ this.initTableParams()
130
+ }
131
+ },
132
+ props: {
133
+ jsonData: {
134
+ type: Array,
135
+ default: () => {
136
+ return []
137
+ }
138
+ },
139
+ queryParamsName: {
140
+ type: String,
141
+ default: () => {
142
+ return ''
143
+ }
144
+ },
145
+ // 查询参数对象, 用于没有对应查询配置文件名时
146
+ queryParams: {
147
+ type: Object,
148
+ default: null
149
+ },
150
+ form: {
151
+ type: Object,
152
+ default: () => {
153
+ return {}
154
+ }
155
+ },
156
+ // 固定查询表单
157
+ fixedQueryForm: {
158
+ type: Object,
159
+ default: () => {
160
+ return {}
161
+ }
162
+ },
163
+ // 按钮
164
+ buttonState: {
165
+ type: Object,
166
+ default: () => {
167
+ return undefined
168
+ }
169
+ },
170
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
171
+ showPagination: {
172
+ type: Boolean,
173
+ default: true
174
+ }
175
+ },
176
+ computed: {
177
+ rowSelection () {
178
+ return {
179
+ selectedRowKeys: this.selectedRowKeys,
180
+ onChange: this.onSelectChange
181
+ }
182
+ }
183
+ },
184
+ mounted () {
185
+ this.initTableParams()
186
+ },
187
+ methods: {
188
+ badgeFilter (key, value) {
189
+ return this.$appdata.getParam(key, value)
190
+ },
191
+ initTableParams () {
192
+ let totalWidth = 0
193
+ this.rowKey = this.tableColumns[0].dataIndex
194
+ for (let i = 0; i < this.tableColumns.length; i++) {
195
+ const item = this.tableColumns[i]
196
+ if (item.dataIndex === 'action') {
197
+ item.fixed = 'right'
198
+ item.width = 70
199
+ }
200
+ if (item.width) {
201
+ totalWidth = totalWidth + item.width
202
+ } else {
203
+ totalWidth = totalWidth + 180
204
+ }
205
+ }
206
+ const width = document.documentElement.clientWidth
207
+ if (width >= 1600) {
208
+ this.scrollYWidth = 429
209
+ } else if (width >= 1200) {
210
+ this.scrollYWidth = 390
211
+ } else {
212
+ this.scrollYWidth = 343
213
+ }
214
+ // 横向滚动长度大于所有宽度,才能实现固定表头
215
+ this.scrollXWidth = totalWidth
216
+ },
217
+ loadTableData (requestParameters) {
218
+ let data = []
219
+ this.$emit('loadData', requestParameters, val => {
220
+ data = val
221
+ })
222
+ const _this = this
223
+ data.then(res => {
224
+ _this.dataSource = res.data
225
+ })
226
+ return data
227
+ },
228
+ action (record) {
229
+ this.$emit('action', record, record[this.jsonData[0].dataIndex])
230
+ },
231
+ onSelectChange (selectedRowKeys, selectedRows) {
232
+ this.selectedRowKeys = selectedRowKeys
233
+ this.selectedRows = selectedRows
234
+ this.$emit('selectRow', selectedRowKeys)
235
+ },
236
+ clearRowKeys () {
237
+ this.$refs.table.clearSelected()
238
+ },
239
+ /**
240
+ * 表格重新加载方法
241
+ * 如果参数为 true, 则强制刷新到第一页
242
+ */
243
+ refresh (bool) {
244
+ this.$refs.table.refresh(bool)
245
+ },
246
+ format (date, format) {
247
+ return formatDate(date, format)
248
+ },
249
+ showDrawer () {
250
+ this.visible = true
251
+ },
252
+ toggleIsFormShow () {
253
+ this.$emit('toggleIsFormShow')
254
+ }
255
+ }
256
+ }
257
+ </script>
258
+ <style lang="less" scoped>
259
+ </style>