@lx-frontend/wrap-element-ui 1.0.1-beta.3 → 1.0.1-beta.4

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