@lx-frontend/wrap-element-ui 0.4.5 → 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.5",
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,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,238 @@
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<TableData>(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
63
  <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>
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] }}
61
68
  </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))}}
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
+ }}
66
102
  </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>
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>
92
130
  </div>
93
131
  <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>
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] }}
101
136
  </div>
102
- <!-- 字段formatters存在,数据过滤-->
103
- <span
104
- v-else-if="getFieldFromConfig(keys[index], 'formatters')">
105
- {{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]]) }}
106
162
  </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>
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>
131
174
  </div>
132
175
  </template>
133
176
  </ElTableColumn>
134
-
135
-
136
- </FElTable>
177
+ </el-table>
137
178
  <ElPagination
138
179
  @current-change="handleCurrentChange"
139
180
  :background="background"
140
181
  :current-page="currentPage"
141
182
  :page-size="pageSize"
142
183
  :total="totals"
143
- layout="total, prev, pager, next, jumper, slot" v-if="currentPage">
184
+ layout="total, prev, pager, next, jumper, slot"
185
+ v-if="currentPage"
186
+ >
144
187
  </ElPagination>
145
188
  </div>
146
189
  </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
- }
190
+ <script lang="ts" setup generic="K = any, TableData = Record<string, any>">
191
+ import Ellipsis from "../../Ellipsis";
177
192
 
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
- }
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}`;
274
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
+ };
275
272
  </script>
276
273
  <style type="scss">
277
- .table-content .el-pagination {
278
- text-align: right;
279
- padding: 14px 0;
280
- }
274
+ .table-content .el-pagination {
275
+ text-align: right;
276
+ padding: 14px 0;
277
+ }
281
278
  </style>
282
-