@jetlinks-web/components 3.0.1 → 3.1.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.
@@ -0,0 +1,398 @@
1
+ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) {
2
+ const op = ops[i];
3
+ const fn = ops[i + 1];
4
+ i += 2;
5
+ if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) {
6
+ return undefined;
7
+ }
8
+ if (op === 'access' || op === 'optionalAccess') {
9
+ lastAccessLHS = value;
10
+ value = fn(value);
11
+ }
12
+ else if (op === 'call' || op === 'optionalCall') {
13
+ value = fn((...args) => value.call(lastAccessLHS, ...args));
14
+ lastAccessLHS = undefined;
15
+ }
16
+ } return value; }
17
+ /* Analyzed bindings: {
18
+ "dataSource": "props",
19
+ "columns": "props",
20
+ "expandedRowKeys": "props",
21
+ "rowSelection": "props",
22
+ "rowKey": "props",
23
+ "height": "props",
24
+ "findAllChildren": "setup-maybe-ref",
25
+ "flattenTree": "setup-maybe-ref",
26
+ "isNumber": "setup-maybe-ref",
27
+ "map": "setup-maybe-ref",
28
+ "omit": "setup-maybe-ref",
29
+ "h": "setup-const",
30
+ "computed": "setup-const",
31
+ "ref": "setup-const",
32
+ "watch": "setup-const",
33
+ "onMounted": "setup-const",
34
+ "nextTick": "setup-const",
35
+ "Table": "setup-maybe-ref",
36
+ "Checkbox": "setup-maybe-ref",
37
+ "AIcon": "setup-maybe-ref",
38
+ "useVirtualTableStyle": "setup-maybe-ref",
39
+ "useLocaleReceiver": "setup-maybe-ref",
40
+ "props": "setup-reactive-const",
41
+ "emits": "setup-const",
42
+ "prefixCls": "setup-ref",
43
+ "wrapSSR": "setup-maybe-ref",
44
+ "hashId": "setup-maybe-ref",
45
+ "contextLocale": "setup-maybe-ref",
46
+ "container": "setup-ref",
47
+ "rowHeights": "setup-ref",
48
+ "prefixSum": "setup-ref",
49
+ "start": "setup-ref",
50
+ "end": "setup-ref",
51
+ "offsetY": "setup-ref",
52
+ "buffer": "literal-const",
53
+ "selectedAll": "setup-ref",
54
+ "visibleNodes": "setup-ref",
55
+ "flattenData": "setup-ref",
56
+ "firstColumn": "setup-ref",
57
+ "totalHeight": "setup-ref",
58
+ "visibleRows": "setup-ref",
59
+ "_indeterminate": "setup-ref",
60
+ "viewportHeight": "setup-ref",
61
+ "_columns": "setup-ref",
62
+ "_rowSelection": "setup-ref",
63
+ "onSelectedAllChange": "setup-const",
64
+ "onScroll": "setup-const",
65
+ "toggleExpand": "setup-const",
66
+ "updatePrefixSum": "setup-const",
67
+ "updateVisibleNodes": "setup-const"
68
+ } */
69
+ import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, toDisplayString as _toDisplayString, createElementVNode as _createElementVNode, createElementBlock as _createElementBlock, renderSlot as _renderSlot, createTextVNode as _createTextVNode, withCtx as _withCtx, createVNode as _createVNode, normalizeStyle as _normalizeStyle, Fragment as _Fragment, normalizeClass as _normalizeClass } from "vue";
70
+ const _hoisted_1 = { class: "virtual-table-header" };
71
+ const _hoisted_2 = {
72
+ key: 0,
73
+ class: "virtual-table-all-selected"
74
+ };
75
+ const _hoisted_3 = ["onClick"];
76
+ import { findAllChildren, flattenTree } from "./data";
77
+ import { isNumber, map, omit } from "lodash-es";
78
+ import { h, computed, ref, watch, onMounted, nextTick } from 'vue';
79
+ import { Table, Checkbox } from 'ant-design-vue';
80
+ import AIcon from '../Icon';
81
+ import useVirtualTableStyle from './style';
82
+ import { useLocaleReceiver } from "../LocaleReciver";
83
+ const buffer = 5;
84
+ const __sfc_main__ = Object.assign({
85
+ name: 'JVirtualTable'
86
+ }, {
87
+ props: {
88
+ dataSource: {
89
+ type: Array,
90
+ default: () => []
91
+ },
92
+ columns: {
93
+ type: Array,
94
+ default: () => []
95
+ },
96
+ expandedRowKeys: {
97
+ type: Array,
98
+ default: () => []
99
+ },
100
+ rowSelection: {
101
+ type: Object
102
+ },
103
+ rowKey: {
104
+ type: [String, Function],
105
+ default: 'id',
106
+ },
107
+ height: {
108
+ type: Number,
109
+ default: 500
110
+ }
111
+ },
112
+ emits: ['update:expandedRowKeys'],
113
+ setup(__props, { emit: __emit }) {
114
+ const props = __props;
115
+ const emits = __emit;
116
+ const prefixCls = computed(() => 'virtual-table');
117
+ const [wrapSSR, hashId] = useVirtualTableStyle(prefixCls);
118
+ const [contextLocale] = useLocaleReceiver('ProTable');
119
+ const container = ref(null);
120
+ const rowHeights = ref([]);
121
+ const prefixSum = ref([]);
122
+ const start = ref(0);
123
+ const end = ref(15);
124
+ const offsetY = ref(0);
125
+ const selectedAll = ref(false);
126
+ // 被展开的所有数据
127
+ const visibleNodes = ref([]);
128
+ const flattenData = ref([]);
129
+ const firstColumn = computed(() => props.columns[0]);
130
+ const totalHeight = computed(() => prefixSum.value.length ? prefixSum.value[prefixSum.value.length - 1] : 0);
131
+ const visibleRows = computed(() => visibleNodes.value.slice(start.value, end.value));
132
+ const _indeterminate = computed(() => !selectedAll.value && _optionalChain([props, 'access', _2 => _2.rowSelection, 'optionalAccess', _3 => _3.selectedRowKeys, 'optionalAccess', _4 => _4.length]) > 0);
133
+ const viewportHeight = computed(() => props.height || 500);
134
+ const _columns = computed(() => {
135
+ const arr = [];
136
+ if (props.rowSelection) {
137
+ const _width = props.rowSelection.columnWidth || 32;
138
+ arr.push({
139
+ key: '__selection__',
140
+ title: contextLocale.value.select.all,
141
+ dataIndex: '__selection__',
142
+ width: isNumber(_width) ? `${_width}px` : _width,
143
+ customHeaderCell: (props) => {
144
+ return {
145
+ class: 'ant-table-selection-column',
146
+ };
147
+ }
148
+ }); //
149
+ }
150
+ arr.push(...props.columns);
151
+ return arr;
152
+ });
153
+ const _rowSelection = computed(() => {
154
+ return props.rowSelection ? {
155
+ ...props.rowSelection,
156
+ onSelect: (record, selected, selectedRows, nativeEvent) => {
157
+ const _selectedRowKeys = props.rowSelection.selectedRowKeys || [];
158
+ const _set = new Set([..._selectedRowKeys]);
159
+ if (props.rowSelection.type === 'radio') {
160
+ _set.clear();
161
+ _set.add(record[props.rowKey]);
162
+ }
163
+ else {
164
+ const _checkStrictly = props.rowSelection.checkStrictly !== undefined ? props.rowSelection.checkStrictly : true;
165
+ let __arr = [];
166
+ if (_checkStrictly) { // 需要获取子
167
+ __arr = [record[props.rowKey]];
168
+ }
169
+ else {
170
+ __arr = map(findAllChildren(flattenData.value, record[props.rowKey]), props.rowKey);
171
+ __arr.push(record[props.rowKey]);
172
+ }
173
+ if (selected) {
174
+ __arr.forEach(i => _set.add(i));
175
+ }
176
+ else {
177
+ __arr.forEach(i => _set.delete(i));
178
+ }
179
+ }
180
+ const _selectedRows = flattenData.value.filter(i => _set.has(i[props.rowKey])).map(item => omit(item, ['expanded', 'hasChildren', 'visible']));
181
+ if (props.rowSelection.onSelect) {
182
+ props.rowSelection.onSelect(record, selected, _selectedRows, nativeEvent);
183
+ }
184
+ if (props.rowSelection.onChange) {
185
+ props.rowSelection.onChange([..._set], _selectedRows);
186
+ }
187
+ },
188
+ onChange: () => {
189
+ },
190
+ onSelectAll: () => {
191
+ },
192
+ onSelectNone: () => {
193
+ if (props.rowSelection.onSelectNone) {
194
+ props.rowSelection.onSelectNone();
195
+ }
196
+ }
197
+ } : undefined;
198
+ });
199
+ const onSelectedAllChange = (e) => {
200
+ const selected = e.target.checked;
201
+ const arr = flattenData.value.map(i => omit(i, ['expanded', 'hasChildren', 'visible']));
202
+ const _checked = selected;
203
+ const _selectedRowKeys = _checked ? map(arr, props.rowKey) : [];
204
+ if (props.rowSelection.onSelectAll) {
205
+ props.rowSelection.onSelectAll(_checked, _checked ? arr : []);
206
+ }
207
+ if (props.rowSelection.onChange) {
208
+ props.rowSelection.onChange(_selectedRowKeys, _checked ? arr : []);
209
+ }
210
+ };
211
+ const onScroll = (e) => {
212
+ const scrollTop = e.target.scrollTop;
213
+ const vh = viewportHeight.value || 500;
214
+ // 二分查找
215
+ let low = 0, high = prefixSum.value.length - 1;
216
+ while (low < high) {
217
+ let mid = Math.floor((low + high) / 2);
218
+ if (prefixSum.value[mid] <= scrollTop)
219
+ low = mid + 1;
220
+ else
221
+ high = mid;
222
+ }
223
+ start.value = Math.max(0, low - 1);
224
+ // 计算 end
225
+ let y = prefixSum.value[start.value] || 0;
226
+ let i = start.value;
227
+ while (i < visibleNodes.value.length && y < scrollTop + vh) {
228
+ y += rowHeights.value[i] || 40;
229
+ i++;
230
+ }
231
+ end.value = Math.min(i + buffer, visibleNodes.value.length);
232
+ offsetY.value = prefixSum.value[start.value - 1] || 0;
233
+ };
234
+ const toggleExpand = (row) => {
235
+ row.expanded = !row.expanded;
236
+ const stack = [...flattenData.value.filter(n => n.parentId === row[props.rowKey])];
237
+ while (stack.length) {
238
+ const child = stack.pop();
239
+ child.visible = row.expanded;
240
+ if (!child.visible) {
241
+ child.expanded = false;
242
+ }
243
+ if (!row.expanded && child.hasChildren) {
244
+ stack.push(...flattenData.value.filter(n => n.parentId === child[props.rowKey]));
245
+ }
246
+ }
247
+ updateVisibleNodes();
248
+ };
249
+ const updatePrefixSum = () => {
250
+ rowHeights.value = visibleNodes.value.map(() => 40); // 默认行高
251
+ prefixSum.value = [];
252
+ let sum = 0;
253
+ for (let h of rowHeights.value) {
254
+ sum += h;
255
+ prefixSum.value.push(sum);
256
+ }
257
+ };
258
+ const updateVisibleNodes = () => {
259
+ visibleNodes.value = flattenData.value.filter(i => i.visible);
260
+ updatePrefixSum();
261
+ nextTick(() => onScroll({ target: container.value }));
262
+ };
263
+ watch(() => [JSON.stringify(props.dataSource), JSON.stringify(props.expandedRowKeys)], () => {
264
+ flattenData.value = flattenTree(props.dataSource, 0, null);
265
+ flattenData.value.forEach(i => {
266
+ if (props.expandedRowKeys.includes(i[props.rowKey])) {
267
+ toggleExpand(i);
268
+ // i.expanded = true
269
+ }
270
+ });
271
+ updateVisibleNodes();
272
+ }, {
273
+ immediate: true
274
+ });
275
+ // watch(() => props.expandedRowKeys, () => {
276
+ // flattenData.value.forEach(i => {
277
+ // if (props.expandedRowKeys.includes(i[props.rowKey])) {
278
+ // toggleExpand(i)
279
+ // // i.expanded = true
280
+ // }
281
+ // })
282
+ // updateVisibleNodes()
283
+ // }, {
284
+ // immediate: true
285
+ // })
286
+ watch(() => _optionalChain([props, 'access', _5 => _5.rowSelection, 'optionalAccess', _6 => _6.selectedRowKeys]), (val) => {
287
+ if (val) {
288
+ selectedAll.value = val.length > 0 && flattenData.value.length === val.length;
289
+ }
290
+ }, {
291
+ immediate: true
292
+ });
293
+ onMounted(() => {
294
+ updateVisibleNodes();
295
+ });
296
+ return (_ctx, _cache) => {
297
+ return (_openBlock(), _createElementBlock("div", {
298
+ class: _normalizeClass(['virtual-table-wrapper', _unref(hashId)])
299
+ }, [
300
+ _createElementVNode("div", _hoisted_1, [
301
+ _createVNode(_unref(Table), {
302
+ columns: _columns.value,
303
+ pagination: false,
304
+ rowKey: __props.rowKey,
305
+ "data-source": [],
306
+ components: {
307
+ body: {
308
+ wrapper: () => h('div')
309
+ },
310
+ }
311
+ }, {
312
+ headerCell: _withCtx(({ column, title }) => [
313
+ (column.key === '__selection__')
314
+ ? (_openBlock(), _createElementBlock("span", _hoisted_2, [
315
+ (__props.rowSelection.type !== 'radio' && !__props.rowSelection.hideSelectAll)
316
+ ? (_openBlock(), _createBlock(_unref(Checkbox), {
317
+ key: 0,
318
+ checked: selectedAll.value,
319
+ "onUpdate:checked": _cache[0] || (_cache[0] = $event => ((selectedAll).value = $event)),
320
+ onChange: onSelectedAllChange,
321
+ indeterminate: _indeterminate.value,
322
+ disabled: visibleRows.value.length === 0
323
+ }, null, 8 /* PROPS */, ["checked", "indeterminate", "disabled"]))
324
+ : _createCommentVNode("v-if", true),
325
+ _createElementVNode("span", null, _toDisplayString(_optionalChain([__props, 'access', _7 => _7.rowSelection, 'optionalAccess', _8 => _8.columnTitle])), 1 /* TEXT */)
326
+ ]))
327
+ : _renderSlot(_ctx.$slots, "headerCell", {
328
+ key: 1,
329
+ title: title,
330
+ column: column
331
+ }, () => [
332
+ _createTextVNode(_toDisplayString(title), 1 /* TEXT */)
333
+ ])
334
+ ]),
335
+ _: 3 /* FORWARDED */
336
+ }, 8 /* PROPS */, ["columns", "rowKey", "components"])
337
+ ]),
338
+ _createElementVNode("div", {
339
+ class: "virtual-table-body",
340
+ ref_key: "container",
341
+ ref: container,
342
+ onScroll: onScroll,
343
+ style: _normalizeStyle({ height: `${viewportHeight.value}px` })
344
+ }, [
345
+ _createElementVNode("div", {
346
+ class: "virtual-table-height",
347
+ style: _normalizeStyle({ height: totalHeight.value + 'px' })
348
+ }, null, 4 /* STYLE */),
349
+ _createElementVNode("div", {
350
+ class: "virtual-table-visible-box",
351
+ style: _normalizeStyle({ transform: `translateY(${offsetY.value}px)`, position: 'absolute', top: 0, left: 0, right: 0 })
352
+ }, [
353
+ _createVNode(_unref(Table), {
354
+ columns: __props.columns,
355
+ rowKey: __props.rowKey,
356
+ "data-source": visibleRows.value,
357
+ showHeader: false,
358
+ pagination: false,
359
+ rowSelection: _rowSelection.value
360
+ }, {
361
+ bodyCell: _withCtx(({ text, record, index, column }) => [
362
+ (column.dataIndex === firstColumn.value.dataIndex || column.key === firstColumn.value.key)
363
+ ? (_openBlock(), _createElementBlock(_Fragment, { key: 0 }, [
364
+ _createElementVNode("span", {
365
+ class: "ant-table-row-indent indent-level-3",
366
+ style: _normalizeStyle({ paddingLeft: `${record.level * 15}px` })
367
+ }, null, 4 /* STYLE */),
368
+ _createElementVNode("span", {
369
+ class: "virtual-table-row-expand-icon",
370
+ onClick: $event => (toggleExpand(record))
371
+ }, [
372
+ (record.hasChildren)
373
+ ? (_openBlock(), _createBlock(_unref(AIcon), {
374
+ key: 0,
375
+ type: !record.expanded ? 'PlusSquareOutlined' : 'MinusSquareOutlined'
376
+ }, null, 8 /* PROPS */, ["type"]))
377
+ : _createCommentVNode("v-if", true)
378
+ ], 8 /* PROPS */, _hoisted_3)
379
+ ], 64 /* STABLE_FRAGMENT */))
380
+ : _createCommentVNode("v-if", true),
381
+ _renderSlot(_ctx.$slots, "bodyCell", {
382
+ text: text,
383
+ record: record,
384
+ index: index,
385
+ column: column
386
+ }, () => [
387
+ _createTextVNode(_toDisplayString(text || '--'), 1 /* TEXT */)
388
+ ])
389
+ ]),
390
+ _: 3 /* FORWARDED */
391
+ }, 8 /* PROPS */, ["columns", "rowKey", "data-source", "rowSelection"])
392
+ ], 4 /* STYLE */)
393
+ ], 36 /* STYLE, NEED_HYDRATION */)
394
+ ], 2 /* CLASS */));
395
+ };
396
+ }
397
+ });
398
+ export default __sfc_main__;
@@ -0,0 +1,36 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ // 扁平化数据
4
+ import { omit } from "lodash-es";
5
+ var _flattenTree = function flattenTree(tree) {
6
+ var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
7
+ var parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
8
+ return tree.flatMap(function (item) {
9
+ var _item$children;
10
+ var flatNode = _objectSpread(_objectSpread({}, omit(item, 'children')), {}, {
11
+ level: level,
12
+ parentId: parentId,
13
+ expanded: false,
14
+ hasChildren: ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0,
15
+ visible: level === 0
16
+ });
17
+ var children = item.children ? _flattenTree(item.children, level + 1, item.id) : [];
18
+ return [flatNode].concat(_toConsumableArray(children));
19
+ });
20
+ };
21
+ export { _flattenTree as flattenTree };
22
+ export var findAllChildren = function findAllChildren() {
23
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
24
+ var parentId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
25
+ var result = [];
26
+ function recursive(pid) {
27
+ data.forEach(function (item) {
28
+ if (item.parentId === pid) {
29
+ result.push(item);
30
+ recursive(item.id); // 递归查找这个子节点的孩子
31
+ }
32
+ });
33
+ }
34
+ recursive(parentId);
35
+ return result;
36
+ };
@@ -0,0 +1,5 @@
1
+ import VirtualTable from './VirtualTable.js';
2
+ VirtualTable.install = function (app) {
3
+ app.component(VirtualTable.name, VirtualTable);
4
+ };
5
+ export default VirtualTable;
@@ -0,0 +1,32 @@
1
+ import genCompoentStyle from "../../style/styleRegister";
2
+ var genVirtualTableStyle = function genVirtualTableStyle() {
3
+ return {
4
+ '.virtual-table-wrapper': {
5
+ display: 'flex',
6
+ 'flex-direction': 'column',
7
+ '.virtual-table-header': {
8
+ '.ant-table': {
9
+ '.ant-table-container': {
10
+ '.ant-table-content': {
11
+ '.ant-table-tbody': {
12
+ display: 'none'
13
+ }
14
+ }
15
+ }
16
+ }
17
+ },
18
+ '.virtual-table-body': {
19
+ 'overflow-y': 'auto',
20
+ position: 'relative',
21
+ 'min-height': '100px'
22
+ },
23
+ '.virtual-table-row-expand-icon': {
24
+ 'margin-right': '8px',
25
+ 'font-size': 'relative',
26
+ width: '16px',
27
+ display: 'inline-block'
28
+ }
29
+ }
30
+ };
31
+ };
32
+ export default genCompoentStyle([genVirtualTableStyle]);
package/es/components.js CHANGED
@@ -17,4 +17,5 @@ export { default as DragModal } from './DragModal';
17
17
  export { default as EditTable } from './EditTable';
18
18
  export { default as Markdown } from './Markdown';
19
19
  export { default as AutoComplete } from './AutoComplete';
20
- export { default as Title } from './Title';
20
+ export { default as Title } from './Title';
21
+ export { default as VirtualTable } from './VirtualTable';
@@ -46,7 +46,9 @@ export default {
46
46
  },
47
47
  ProTable: {
48
48
  pagination: {
49
- total: 'Articles {0} - {1}/Total of {2}'
49
+ page: 'Articles {0} - {1}/Total of',
50
+ total: '',
51
+ lastPage: 'It is already the last page'
50
52
  },
51
53
  alert: {
52
54
  cancelChoose: 'Cancel selection',
@@ -46,7 +46,9 @@ export default {
46
46
  },
47
47
  ProTable: {
48
48
  pagination: {
49
- total: "\u7B2C {0} - {1} \u6761/\u603B\u5171 {2} \u6761"
49
+ page: "\u7B2C {0} - {1} \u6761/\u603B\u5171",
50
+ total: '条',
51
+ lastPage: '已是最后一页'
50
52
  },
51
53
  alert: {
52
54
  cancelChoose: '取消选择',
@@ -70,8 +70,7 @@ const __sfc_main__ = _defineComponent({
70
70
  _options.value = props.options || [];
71
71
  }, { immediate: true });
72
72
  return (_ctx, _cache) => {
73
- return (_openBlock(), _createBlock(_unref(AutoComplete), _mergeProps(props, {
74
- style: { "width": "100%" },
73
+ return (_openBlock(), _createBlock(_unref(AutoComplete), _mergeProps({ style: { "width": "100%" } }, props, {
75
74
  options: _options.value,
76
75
  onSearch: onSearch,
77
76
  onDropdownVisibleChange: dropdownVisibleChange
@@ -162,7 +162,9 @@ const __sfc_main__ = Object.assign({
162
162
  ref_key: "tooltipRef",
163
163
  ref: tooltipRef,
164
164
  placement: "top"
165
- }, __props.tooltip, { visible: visible.value }), _createSlots({
165
+ }, __props.tooltip, {
166
+ visible: visible.value && __props.tooltip !== false
167
+ }), _createSlots({
166
168
  default: _withCtx(() => [
167
169
  _createElementVNode("span", _mergeProps({
168
170
  ref_key: "triggerRef",