@lx-frontend/wrap-element-ui 0.4.0-beta.3 → 0.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,281 +1,281 @@
1
-
2
- <!--
3
- @row-click="handleRowClick" 当某一行被点击时会触发该事件
4
- @cell-click="handleCellClick" 当某个单元格被点击时会触发该事件
5
- @sort-change="sortChange" 排序触发事件
6
- sortable 配置排序
7
- default-sort: prop默认字段 order排序方式
8
- slot='key_header' scopeHeader 支持表头可自定义
9
- highlightCurrentRow 单行选中状态
10
- -->
11
- <template>
12
- <div class="table-content">
13
- <FElTable
14
- v-loading="loading"
15
- ref="lxTableRef"
16
- :data="tableData"
17
- :empty-text="(customConfig || {}).emptyText || ''"
18
- @selection-change="handleSelectionChange"
19
- @row-click="handleRowClick"
20
- @cell-click="handleCellClick"
21
- @sort-change="sortChange"
22
- :highlight-current-row="highlightCurrentRow"
23
- :row-class-name="tableRowClassName"
24
- :default-sort="(customConfig || {}).sortValue || defaultSort">
25
- <ElTableColumn v-if="customConfig.selection && customConfig.selection.isOpenSelection" type="selection" :width="customConfig.selection.width">
26
- </ElTableColumn>
27
- <ElTableColumn
28
- v-for="(item, index) in cloumns"
29
- :key="`${item}_${index}`"
30
- :label="item"
31
- :prop="keys[index]"
32
- :sortable="getFieldFromConfig(keys[index], 'sortable')"
33
- :width="getFieldFromConfig(keys[index], 'width')"
34
- :min-width="getFieldFromConfig(keys[index], 'minWidth')"
35
- :fixed="getFieldFromConfig(keys[index], 'fixed')">
36
- <template slot="header" slot-scope="scope">
37
- <slot template
38
- :name="`${keys[index]}_header`"
39
- :keys="keys[index]"
40
- :row="scope.row"
41
- :lable="scope.column"
42
- :column="scope.$index"
43
- v-if="getFieldFromConfig(keys[index], 'scopeHeader')"
44
- >
45
- </slot>
46
- <span v-else>
47
- {{item}}
48
- </span>
49
- </template>
50
- <template slot-scope="scope">
51
- <!-- 支持keys字段为'car.id'或者'id' -->
52
- <div v-if="keys[index].indexOf('.') != -1">
53
- <!-- 一个td需要展示多个字段名 -->
54
- <div v-if="Array.isArray(keys[index])">
55
- <div
56
- v-for="(array, i) in keys[index]"
57
- :key="i">
58
- {{scope.row[array]}}
59
- </div>
60
- </div>
61
- <!-- 字段formatters存在,数据过滤-->
62
- <span
63
- v-else-if="getFieldFromConfig(keys[index], 'formatters')">
64
- {{formatterMethods(scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]], (customConfig[keys[index]].formatters))}}
65
- </span>
66
- <!-- 复杂情况需要自定义---当前keys存在于customConfig.template数据定义中,传入slot的name作为唯一标识符 -->
67
- <slot template
68
- :name="keys[index]"
69
- :keys="keys[index]"
70
- :row="scope.row"
71
- :lable="scope.column"
72
- :column="scope.$index"
73
- v-else-if="getFieldFromConfig(keys[index], 'template')"
74
- >
75
- </slot>
76
- <div v-else>
77
- <!-- 传入不需要截取的列 -->
78
- <span v-if="getFieldFromConfig(keys[index], 'templateCutOut')">
79
- {{scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]] | formateValue}}
80
- </span>
81
- <Ellipsis
82
- v-else
83
- :popoverName="popoverName"
84
- :lineCount="getFieldFromConfig(keys[index], 'lineCount')"
85
- :content="[`${scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]]}`] | formateValue">
86
- <div slot="popover">
87
- <div>{{scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]] | formateValue}}</div>
88
- </div>
89
- </Ellipsis>
90
- </div>
91
- </div>
92
- <div v-else>
93
- <!-- 一个td需要展示多个字段名 -->
94
- <div v-if="Array.isArray(keys[index])">
95
- <div
96
- v-for="(array, i) in keys[index]"
97
- :key="i">
98
- {{scope.row[array]}}
99
- </div>
100
- </div>
101
- <!-- 字段formatters存在,数据过滤-->
102
- <span
103
- v-else-if="getFieldFromConfig(keys[index], 'formatters')">
104
- {{formatterMethods(scope.row[keys[index]], (customConfig[keys[index]].formatters))}}
105
- </span>
106
- <!-- 复杂情况需要自定义---当前keys存在于customConfig.template数据定义中,传入slot的name作为唯一标识符 -->
107
- <slot template
108
- :name="keys[index]"
109
- :keys="keys[index]"
110
- :row="scope.row"
111
- :lable="scope.column"
112
- :column="scope.$index"
113
- v-else-if="getFieldFromConfig(keys[index], 'template')">
114
- </slot>
115
- <div v-else>
116
- <!-- 传入不需要截取的列 -->
117
- <span v-if="getFieldFromConfig(keys[index], 'templateCutOut')">
118
- {{scope.row[keys[index]] | formateValue}}
119
- </span>
120
- <Ellipsis
121
- v-else
122
- :popoverName="popoverName"
123
- :lineCount="getFieldFromConfig(keys[index], 'lineCount')"
124
- :content="[`${scope.row[keys[index]]}`] | formateValue">
125
- <div slot="popover">
126
- <div>{{scope.row[keys[index]] | formateValue}}</div>
127
- </div>
128
- </Ellipsis>
129
- </div>
130
- </div>
131
- </template>
132
- </ElTableColumn>
133
-
134
-
135
- </FElTable>
136
- <ElPagination
137
- @current-change="handleCurrentChange"
138
- :background="background"
139
- :current-page="currentPage"
140
- :page-size="pageSize"
141
- :total="totals"
142
- layout="total, prev, pager, next, jumper, slot" v-if="currentPage">
143
- </ElPagination>
144
- </div>
145
- </template>
146
- <script>
147
- import Ellipsis from '../../Ellipsis';
148
- import { Table } from 'element-ui'
149
- const FElTable = {
150
- extends: Table,
151
- methods: {
152
- doLayout (...args) {
153
- Table.methods.doLayout.call(this, ...args)
154
- this.fixLayout() // Looks like we can do it once?
155
- },
156
- fixLayout () {
157
- // Safari header/content misalign fix (possible other browsers?)
158
- this.columns.forEach(c => {
159
- // element-ui/packages/table/src/layout-observer.js:49
160
- const width = c.realWidth || c.width
161
- let th = this.$el.querySelector(`table.el-table__header th.${c.id}`)
162
- if (th) {
163
- if (th.offsetWidth !== width) {
164
- th.style = `min-width: ${width}px; max-width: ${width}px;`
165
- }
166
- let td
167
- for (td of this.$el.querySelectorAll(`table.el-table__body td.${c.id}`)) {
168
- if (td.offsetWidth === width) break
169
- td.style = `min-width: ${width}px; max-width: ${width}px;`
170
- }
171
- }
172
- })
173
- }
174
- }
175
- }
176
-
177
- export default {
178
- name: 'LxTable',
179
- components: {
180
- Ellipsis,
181
- FElTable
182
- },
183
- data() {
184
- return {
185
- scope: 'scope',
186
- };
187
- },
188
- props: {
189
- tableData: {
190
- type : Array,
191
- default: () => [],
192
- },
193
- cloumns: {
194
- type : Array,
195
- default: () => [],
196
- },
197
- customConfig: Object,
198
- keys: {
199
- type : Array,
200
- default: () => [],
201
- },
202
- defaultSort: {
203
- prop: '',
204
- order: null,
205
- },
206
- stripe: {
207
- type: Boolean,
208
- default: true,
209
- },
210
- loading: {
211
- type: Boolean,
212
- default: false,
213
- },
214
- background: {
215
- type: Boolean,
216
- default: true,
217
- },
218
- totals: Number,
219
- pageSize: Number,
220
- currentPage: Number,
221
- popoverName: String,
222
- parentFn: {
223
- type : String,
224
- default: '',
225
- },
226
- highlightCurrentRow: {
227
- type: Boolean,
228
- default: true,
229
- },
230
- tableRowClassName: {},
231
- },
232
- filters: {
233
- formateValue (val) {
234
- if (Array.isArray(val) && (val[0] === 'null' || val[0] === '')) {
235
- val = '';
236
- }
237
- return (val || val === 0) ? val : '--';
238
- },
239
- },
240
- methods: {
241
- handleCurrentChange(val) {
242
- this.$emit('handleCurrentChange', val);
243
- },
244
- handleSelectionChange(val) {
245
- this.$emit('handleSelectionChange', val);
246
- },
247
- handleRowClick(row, column, cell, event) {
248
- this.$emit('handleRowClick', row, column, cell, event);
249
- },
250
- handleCellClick(row, column, cell, event){
251
- this.$emit('handleCellClick', row, column, cell, event);
252
- },
253
- sortChange(column, prop, order) {
254
- this.$emit('sortChange', column, prop, order);
255
- },
256
- formatterMethods(key, keyData) {
257
- // 返回数据,可类型转换; 可添加单位;
258
- let value = '--';
259
- if (key || key === 0) {
260
- const keyValue = keyData[key] || key;
261
- const unit = keyData.unit || '';
262
- value = `${keyValue}${unit}`;
263
- }
264
- return value;
265
- },
266
- formateValue (val) {
267
- return val || val === 0 ? val : '--';
268
- },
269
- getFieldFromConfig(index, name) {
270
- return this.customConfig && this.customConfig[index] && this.customConfig[index][name];
271
- },
272
- }
273
- }
274
- </script>
275
- <style type="scss">
276
- .table-content .el-pagination {
277
- text-align: right;
278
- padding: 14px 0;
279
- }
280
- </style>
281
-
1
+
2
+ <!--
3
+ @row-click="handleRowClick" 当某一行被点击时会触发该事件
4
+ @cell-click="handleCellClick" 当某个单元格被点击时会触发该事件
5
+ @sort-change="sortChange" 排序触发事件
6
+ sortable 配置排序
7
+ default-sort: prop默认字段 order排序方式
8
+ slot='key_header' scopeHeader 支持表头可自定义
9
+ highlightCurrentRow 单行选中状态
10
+ -->
11
+ <template>
12
+ <div class="table-content">
13
+ <FElTable
14
+ v-loading="loading"
15
+ ref="lxTableRef"
16
+ :data="tableData"
17
+ :empty-text="(customConfig || {}).emptyText || ''"
18
+ @selection-change="handleSelectionChange"
19
+ @row-click="handleRowClick"
20
+ @cell-click="handleCellClick"
21
+ @sort-change="sortChange"
22
+ :highlight-current-row="highlightCurrentRow"
23
+ :row-class-name="tableRowClassName"
24
+ :default-sort="(customConfig || {}).sortValue || defaultSort">
25
+ <ElTableColumn v-if="customConfig.selection && customConfig.selection.isOpenSelection" type="selection" :width="customConfig.selection.width">
26
+ </ElTableColumn>
27
+ <ElTableColumn
28
+ v-for="(item, index) in cloumns"
29
+ :key="`${item}_${index}`"
30
+ :label="item"
31
+ :prop="keys[index]"
32
+ :sortable="getFieldFromConfig(keys[index], 'sortable')"
33
+ :width="getFieldFromConfig(keys[index], 'width')"
34
+ :min-width="getFieldFromConfig(keys[index], 'minWidth')"
35
+ :fixed="getFieldFromConfig(keys[index], 'fixed')">
36
+ <template slot="header" slot-scope="scope">
37
+ <slot template
38
+ :name="`${keys[index]}_header`"
39
+ :keys="keys[index]"
40
+ :row="scope.row"
41
+ :lable="scope.column"
42
+ :column="scope.$index"
43
+ v-if="getFieldFromConfig(keys[index], 'scopeHeader')"
44
+ >
45
+ </slot>
46
+ <span v-else>
47
+ {{item}}
48
+ </span>
49
+ </template>
50
+ <template slot-scope="scope">
51
+ <!-- 支持keys字段为'car.id'或者'id' -->
52
+ <div v-if="keys[index].indexOf('.') != -1">
53
+ <!-- 一个td需要展示多个字段名 -->
54
+ <div v-if="Array.isArray(keys[index])">
55
+ <div
56
+ v-for="(array, i) in keys[index]"
57
+ :key="i">
58
+ {{scope.row[array]}}
59
+ </div>
60
+ </div>
61
+ <!-- 字段formatters存在,数据过滤-->
62
+ <span
63
+ v-else-if="getFieldFromConfig(keys[index], 'formatters')">
64
+ {{formatterMethods(scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]], (customConfig[keys[index]].formatters))}}
65
+ </span>
66
+ <!-- 复杂情况需要自定义---当前keys存在于customConfig.template数据定义中,传入slot的name作为唯一标识符 -->
67
+ <slot template
68
+ :name="keys[index]"
69
+ :keys="keys[index]"
70
+ :row="scope.row"
71
+ :lable="scope.column"
72
+ :column="scope.$index"
73
+ v-else-if="getFieldFromConfig(keys[index], 'template')"
74
+ >
75
+ </slot>
76
+ <div v-else>
77
+ <!-- 传入不需要截取的列 -->
78
+ <span v-if="getFieldFromConfig(keys[index], 'templateCutOut')">
79
+ {{scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]] | formateValue}}
80
+ </span>
81
+ <Ellipsis
82
+ v-else
83
+ :popoverName="popoverName"
84
+ :lineCount="getFieldFromConfig(keys[index], 'lineCount')"
85
+ :content="[`${scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]]}`] | formateValue">
86
+ <div slot="popover">
87
+ <div>{{scope.row[keys[index].split('.')[0]][keys[index].split('.')[1]] | formateValue}}</div>
88
+ </div>
89
+ </Ellipsis>
90
+ </div>
91
+ </div>
92
+ <div v-else>
93
+ <!-- 一个td需要展示多个字段名 -->
94
+ <div v-if="Array.isArray(keys[index])">
95
+ <div
96
+ v-for="(array, i) in keys[index]"
97
+ :key="i">
98
+ {{scope.row[array]}}
99
+ </div>
100
+ </div>
101
+ <!-- 字段formatters存在,数据过滤-->
102
+ <span
103
+ v-else-if="getFieldFromConfig(keys[index], 'formatters')">
104
+ {{formatterMethods(scope.row[keys[index]], (customConfig[keys[index]].formatters))}}
105
+ </span>
106
+ <!-- 复杂情况需要自定义---当前keys存在于customConfig.template数据定义中,传入slot的name作为唯一标识符 -->
107
+ <slot template
108
+ :name="keys[index]"
109
+ :keys="keys[index]"
110
+ :row="scope.row"
111
+ :lable="scope.column"
112
+ :column="scope.$index"
113
+ v-else-if="getFieldFromConfig(keys[index], 'template')">
114
+ </slot>
115
+ <div v-else>
116
+ <!-- 传入不需要截取的列 -->
117
+ <span v-if="getFieldFromConfig(keys[index], 'templateCutOut')">
118
+ {{scope.row[keys[index]] | formateValue}}
119
+ </span>
120
+ <Ellipsis
121
+ v-else
122
+ :popoverName="popoverName"
123
+ :lineCount="getFieldFromConfig(keys[index], 'lineCount')"
124
+ :content="[`${scope.row[keys[index]]}`] | formateValue">
125
+ <div slot="popover">
126
+ <div>{{scope.row[keys[index]] | formateValue}}</div>
127
+ </div>
128
+ </Ellipsis>
129
+ </div>
130
+ </div>
131
+ </template>
132
+ </ElTableColumn>
133
+
134
+
135
+ </FElTable>
136
+ <ElPagination
137
+ @current-change="handleCurrentChange"
138
+ :background="background"
139
+ :current-page="currentPage"
140
+ :page-size="pageSize"
141
+ :total="totals"
142
+ layout="total, prev, pager, next, jumper, slot" v-if="currentPage">
143
+ </ElPagination>
144
+ </div>
145
+ </template>
146
+ <script>
147
+ import Ellipsis from '../../Ellipsis';
148
+ import { Table } from 'element-ui'
149
+ const FElTable = {
150
+ extends: Table,
151
+ methods: {
152
+ doLayout (...args) {
153
+ Table.methods.doLayout.call(this, ...args)
154
+ this.fixLayout() // Looks like we can do it once?
155
+ },
156
+ fixLayout () {
157
+ // Safari header/content misalign fix (possible other browsers?)
158
+ this.columns.forEach(c => {
159
+ // element-ui/packages/table/src/layout-observer.js:49
160
+ const width = c.realWidth || c.width
161
+ let th = this.$el.querySelector(`table.el-table__header th.${c.id}`)
162
+ if (th) {
163
+ if (th.offsetWidth !== width) {
164
+ th.style = `min-width: ${width}px; max-width: ${width}px;`
165
+ }
166
+ let td
167
+ for (td of this.$el.querySelectorAll(`table.el-table__body td.${c.id}`)) {
168
+ if (td.offsetWidth === width) break
169
+ td.style = `min-width: ${width}px; max-width: ${width}px;`
170
+ }
171
+ }
172
+ })
173
+ }
174
+ }
175
+ }
176
+
177
+ export default {
178
+ name: 'LxTable',
179
+ components: {
180
+ Ellipsis,
181
+ FElTable
182
+ },
183
+ data() {
184
+ return {
185
+ scope: 'scope',
186
+ };
187
+ },
188
+ props: {
189
+ tableData: {
190
+ type : Array,
191
+ default: () => [],
192
+ },
193
+ cloumns: {
194
+ type : Array,
195
+ default: () => [],
196
+ },
197
+ customConfig: Object,
198
+ keys: {
199
+ type : Array,
200
+ default: () => [],
201
+ },
202
+ defaultSort: {
203
+ prop: '',
204
+ order: null,
205
+ },
206
+ stripe: {
207
+ type: Boolean,
208
+ default: true,
209
+ },
210
+ loading: {
211
+ type: Boolean,
212
+ default: false,
213
+ },
214
+ background: {
215
+ type: Boolean,
216
+ default: true,
217
+ },
218
+ totals: Number,
219
+ pageSize: Number,
220
+ currentPage: Number,
221
+ popoverName: String,
222
+ parentFn: {
223
+ type : String,
224
+ default: '',
225
+ },
226
+ highlightCurrentRow: {
227
+ type: Boolean,
228
+ default: true,
229
+ },
230
+ tableRowClassName: {},
231
+ },
232
+ filters: {
233
+ formateValue (val) {
234
+ if (Array.isArray(val) && (val[0] === 'null' || val[0] === '')) {
235
+ val = '';
236
+ }
237
+ return (val || val === 0) ? val : '--';
238
+ },
239
+ },
240
+ methods: {
241
+ handleCurrentChange(val) {
242
+ this.$emit('handleCurrentChange', val);
243
+ },
244
+ handleSelectionChange(val) {
245
+ this.$emit('handleSelectionChange', val);
246
+ },
247
+ handleRowClick(row, column, cell, event) {
248
+ this.$emit('handleRowClick', row, column, cell, event);
249
+ },
250
+ handleCellClick(row, column, cell, event){
251
+ this.$emit('handleCellClick', row, column, cell, event);
252
+ },
253
+ sortChange(column, prop, order) {
254
+ this.$emit('sortChange', column, prop, order);
255
+ },
256
+ formatterMethods(key, keyData) {
257
+ // 返回数据,可类型转换; 可添加单位;
258
+ let value = '--';
259
+ if (key || key === 0) {
260
+ const keyValue = keyData[key] || key;
261
+ const unit = keyData.unit || '';
262
+ value = `${keyValue}${unit}`;
263
+ }
264
+ return value;
265
+ },
266
+ formateValue (val) {
267
+ return val || val === 0 ? val : '--';
268
+ },
269
+ getFieldFromConfig(index, name) {
270
+ return this.customConfig && this.customConfig[index] && this.customConfig[index][name];
271
+ },
272
+ }
273
+ }
274
+ </script>
275
+ <style type="scss">
276
+ .table-content .el-pagination {
277
+ text-align: right;
278
+ padding: 14px 0;
279
+ }
280
+ </style>
281
+