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