@lx-frontend/wrap-element-ui 0.4.3 → 0.4.6-beta.0

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