umy-ui-table 1.2.0 → 1.2.3
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/lib/index.js +1 -1
- package/lib/u-table-column.js +1 -1
- package/lib/u-table.js +1 -1
- package/lib/umy-ui.common.js +1 -1
- package/lib/ux-grid.js +1 -1
- package/package.json +1 -1
- package/packages/u-table/index.js +9 -1
- package/packages/u-table-column/index.js +7 -5
- package/packages/ux-grid/src/ux-grid.vue +85 -24
package/package.json
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import "./revise-el-table-mixins";
|
|
2
2
|
import UTable from "./src/u-table";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// 注意:install 必须以对象属性形式挂载。若写成 `UTable.install = function...` 的赋值形式,
|
|
5
|
+
// 打包时会被死代码消除(install 属性静态分析未见读取),导致 Vue.use(UTable) 按需注册静默失败
|
|
6
|
+
const UTableWithInstall = Object.assign({}, UTable, {
|
|
7
|
+
install(Vue) {
|
|
8
|
+
Vue.component(UTable.name, UTable);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export default UTableWithInstall;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import UTableColumn from '../table/src/table-column';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Vue
|
|
6
|
-
|
|
3
|
+
// 同 u-table:install 需以对象属性形式挂载,赋值形式会被打包器死代码消除
|
|
4
|
+
const UTableColumnWithInstall = Object.assign({}, UTableColumn, {
|
|
5
|
+
install(Vue) {
|
|
6
|
+
Vue.component(UTableColumn.name, UTableColumn);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
7
9
|
|
|
8
|
-
export default
|
|
10
|
+
export default UTableColumnWithInstall;
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
:class="{ uxbeautifyTableClass: beautifyTable }"
|
|
5
5
|
:style="[plTableHeight]"
|
|
6
6
|
>
|
|
7
|
-
<vxe-
|
|
7
|
+
<vxe-grid
|
|
8
8
|
ref="singleTable"
|
|
9
9
|
class="singleTable"
|
|
10
10
|
style="width: 100%"
|
|
11
11
|
:data="data"
|
|
12
|
-
:columns="
|
|
12
|
+
:columns="tableColumns"
|
|
13
13
|
:loading="loading"
|
|
14
14
|
:show-footer="summaryMethod ? showSummary : false"
|
|
15
15
|
:max-height="newMaxHeight"
|
|
@@ -81,8 +81,7 @@
|
|
|
81
81
|
<template slot="empty">
|
|
82
82
|
<slot name="empty">{{ emptyText }}</slot>
|
|
83
83
|
</template>
|
|
84
|
-
|
|
85
|
-
</vxe-table>
|
|
84
|
+
</vxe-grid>
|
|
86
85
|
<div class="myPagination" v-if="paginationShow" ref="myPagination">
|
|
87
86
|
<el-pagination
|
|
88
87
|
@size-change="handleSizeChange"
|
|
@@ -147,17 +146,18 @@ import draggable from "vuedraggable";
|
|
|
147
146
|
import ElPagination from "../../pagination";
|
|
148
147
|
import ElCheckbox from "../../checkbox";
|
|
149
148
|
import ElButton from "../../button";
|
|
150
|
-
// 直接用 vxe-table@3.22.9 的
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
|
|
149
|
+
// 直接用 vxe-table@3.22.9 的 VxeGrid 作内核(替代原 umy-table 内置的 elx-grid)
|
|
150
|
+
// 注意:VxeGrid 3.x 不渲染默认插槽(renderTable 仅透传 scopedSlots,不渲染 children),
|
|
151
|
+
// 所以槽位式 <ux-table-column> 不会被其内部表格收集;这里在组件内解析这些槽位列 vnode,
|
|
152
|
+
// 转成 columns 配置后经 :columns 交给 VxeGrid,从而兼容原有的 <ux-table-column> 写法
|
|
153
|
+
import VxeGrid from "vxe-table/lib/grid";
|
|
154
154
|
import uxGridMixin from "../mixins";
|
|
155
155
|
import { parseHeight, isArrayFn } from "../../utils/common";
|
|
156
156
|
|
|
157
157
|
export default {
|
|
158
158
|
name: "UxGrid",
|
|
159
159
|
mixins: [uxGridMixin],
|
|
160
|
-
components: { draggable, ElPagination, ElCheckbox, ElButton,
|
|
160
|
+
components: { draggable, ElPagination, ElCheckbox, ElButton, VxeGrid },
|
|
161
161
|
data() {
|
|
162
162
|
return {
|
|
163
163
|
_times: "", // 弹框定时器
|
|
@@ -168,9 +168,15 @@ export default {
|
|
|
168
168
|
newcurrentPage: "", // 当前页
|
|
169
169
|
newHeight: null, // 表格高度
|
|
170
170
|
newMaxHeight: null, // 表格最大高度
|
|
171
|
+
slotColumns: [], // 由槽位式 <ux-table-column> 解析出的列配置(无 columns prop 时使用)
|
|
171
172
|
};
|
|
172
173
|
},
|
|
173
174
|
computed: {
|
|
175
|
+
// VxeGrid 通过 columns prop 接收列:columns prop 优先,否则使用解析出的槽位列配置
|
|
176
|
+
tableColumns() {
|
|
177
|
+
if (this.columns && this.columns.length) return this.columns;
|
|
178
|
+
return this.slotColumns;
|
|
179
|
+
},
|
|
174
180
|
// span-method 与 vxe 虚拟滚动不兼容(官方 warnLog: scrollErrProp),存在时自动关闭虚拟;
|
|
175
181
|
// merge-cells 与虚拟滚动兼容(vxe 对合并单元格行不做虚拟占位),无需关闭(用户显式传 scrollY/scrollX 且带 enabled 时尊重用户)
|
|
176
182
|
scrollYConfig() {
|
|
@@ -210,13 +216,6 @@ export default {
|
|
|
210
216
|
},
|
|
211
217
|
},
|
|
212
218
|
watch: {
|
|
213
|
-
columns: {
|
|
214
|
-
handler(val) {
|
|
215
|
-
if (val && val.length && this.$refs.singleTable) {
|
|
216
|
-
this.$refs.singleTable.loadColumn(val);
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
219
|
data: {
|
|
221
220
|
immediate: true,
|
|
222
221
|
handler(val) {
|
|
@@ -247,19 +246,81 @@ export default {
|
|
|
247
246
|
created() {
|
|
248
247
|
this.newPageSize = this.pageSize;
|
|
249
248
|
this.newcurrentPage = this.currentPage;
|
|
249
|
+
// 首次渲染前解析槽位式 <ux-table-column>(若有),使 VxeGrid 首帧即带上列
|
|
250
|
+
this.syncSlotColumns();
|
|
251
|
+
},
|
|
252
|
+
updated() {
|
|
253
|
+
// 处理 <ux-table-column v-if> 动态增减列的场景
|
|
254
|
+
this.syncSlotColumns();
|
|
250
255
|
},
|
|
251
256
|
mounted() {
|
|
252
257
|
this.$ready = true;
|
|
253
|
-
// columns prop
|
|
254
|
-
// 未传 columns 时走槽位式 ux-table-column 收集(VxeTable 原生支持,见 watch staticColumns)
|
|
255
|
-
if (this.columns && this.columns.length) {
|
|
256
|
-
this.$nextTick(() => {
|
|
257
|
-
this.$refs.singleTable &&
|
|
258
|
-
this.$refs.singleTable.loadColumn(this.columns);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
258
|
+
// VxeGrid 原生支持 columns prop(mounted 自动 loadColumn + watch 响应变化),无需手动 loadColumn
|
|
261
259
|
},
|
|
262
260
|
methods: {
|
|
261
|
+
// 解析默认插槽里的 <ux-table-column> vnode,转成 VxeGrid 的 columns 配置
|
|
262
|
+
syncSlotColumns() {
|
|
263
|
+
// columns prop 优先;仅在未传 columns 时解析槽位列
|
|
264
|
+
if (this.columns && this.columns.length) return;
|
|
265
|
+
try {
|
|
266
|
+
const slotVnodes = (this.$slots.default || []).filter(
|
|
267
|
+
(vnode) => vnode && vnode.componentOptions
|
|
268
|
+
);
|
|
269
|
+
// 用稳定签名比对,避免仅插槽函数引用变化时反复赋值导致渲染循环
|
|
270
|
+
const sig = this.columnsSig(slotVnodes);
|
|
271
|
+
if (sig === this._slotColumnsSig) return;
|
|
272
|
+
this._slotColumnsSig = sig;
|
|
273
|
+
this.slotColumns = slotVnodes.map((vnode) => this.vnodeToColumn(vnode));
|
|
274
|
+
} catch (e) {
|
|
275
|
+
// 解析异常时保持现状,避免渲染循环
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
// 把单个 <ux-table-column> vnode 转成列配置(支持嵌套分组列)
|
|
279
|
+
vnodeToColumn(vnode) {
|
|
280
|
+
if (!vnode || !vnode.componentOptions) return null;
|
|
281
|
+
const { propsData = {}, children } = vnode.componentOptions;
|
|
282
|
+
const scopedSlots = (vnode.data && vnode.data.scopedSlots) || {};
|
|
283
|
+
const column = Object.assign({}, propsData);
|
|
284
|
+
const slotKeys = Object.keys(scopedSlots).filter((k) => k.charAt(0) !== "$"); // 过滤 Vue 2 内部标记 $stable 等
|
|
285
|
+
if (slotKeys.length) {
|
|
286
|
+
column.slots = {};
|
|
287
|
+
slotKeys.forEach((key) => {
|
|
288
|
+
column.slots[key] = scopedSlots[key];
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (children && children.length) {
|
|
292
|
+
const nested = [];
|
|
293
|
+
children.forEach((child) => {
|
|
294
|
+
const sub = this.vnodeToColumn(child);
|
|
295
|
+
if (sub) nested.push(sub);
|
|
296
|
+
});
|
|
297
|
+
if (nested.length) column.children = nested;
|
|
298
|
+
}
|
|
299
|
+
return column;
|
|
300
|
+
},
|
|
301
|
+
// 生成槽位列的稳定签名(忽略函数引用差异,按值比较)
|
|
302
|
+
columnsSig(vnodes) {
|
|
303
|
+
const fnReplacer = (key, val) =>
|
|
304
|
+
typeof val === "function" ? "[fn]" : val;
|
|
305
|
+
const describe = (vnode) => {
|
|
306
|
+
if (!vnode || !vnode.componentOptions) return "";
|
|
307
|
+
const { propsData = {}, children } = vnode.componentOptions;
|
|
308
|
+
const slotKeys = Object.keys(
|
|
309
|
+
(vnode.data && vnode.data.scopedSlots) || {}
|
|
310
|
+
).join(",");
|
|
311
|
+
let sig = JSON.stringify(propsData, fnReplacer) + "{" + slotKeys + "}";
|
|
312
|
+
if (children && children.length) {
|
|
313
|
+
const childSigs = [];
|
|
314
|
+
children.forEach((child) => {
|
|
315
|
+
const sub = describe(child);
|
|
316
|
+
if (sub) childSigs.push(sub);
|
|
317
|
+
});
|
|
318
|
+
if (childSigs.length) sig += "[" + childSigs.join(";") + "]";
|
|
319
|
+
}
|
|
320
|
+
return sig;
|
|
321
|
+
};
|
|
322
|
+
return vnodes.map(describe).join("|");
|
|
323
|
+
},
|
|
263
324
|
// 自定义字段按钮事件
|
|
264
325
|
handleField(name, index, arr) {
|
|
265
326
|
switch (name) {
|