@jetlinks-web/components 2.6.23 → 2.6.24

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.
@@ -23,15 +23,12 @@ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]
23
23
  "get": "setup-maybe-ref",
24
24
  "omit": "setup-maybe-ref",
25
25
  "Empty": "setup-maybe-ref",
26
- "useTableInject": "setup-maybe-ref",
27
26
  "props": "setup-reactive-const",
28
27
  "slots": "setup-maybe-ref",
29
- "_rowSelection": "setup-maybe-ref",
30
28
  "_columns": "setup-ref",
31
29
  "_slots": "setup-ref",
32
30
  "_scroll": "setup-ref",
33
- "gridTemplateColumns": "setup-ref",
34
- "onClick": "setup-const"
31
+ "gridTemplateColumns": "setup-ref"
35
32
  } */
36
33
  import { defineComponent as _defineComponent } from 'vue';
37
34
  import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, mergeProps as _mergeProps, renderSlot as _renderSlot, normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createCommentVNode as _createCommentVNode, unref as _unref, createVNode as _createVNode, normalizeProps as _normalizeProps, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, withCtx as _withCtx, createSlots as _createSlots, createBlock as _createBlock } from "vue";
@@ -40,8 +37,7 @@ const _hoisted_2 = {
40
37
  key: 0,
41
38
  class: "jtable-card"
42
39
  };
43
- const _hoisted_3 = ["onClick"];
44
- const _hoisted_4 = {
40
+ const _hoisted_3 = {
45
41
  key: 1,
46
42
  class: "j-table-empty"
47
43
  };
@@ -50,7 +46,6 @@ import { _contentProps } from "./setting";
50
46
  import { Table } from 'ant-design-vue/es/';
51
47
  import { get, omit } from 'lodash-es';
52
48
  import Empty from '../Empty';
53
- import { useTableInject } from './hooks';
54
49
  const __sfc_main__ = _defineComponent({
55
50
  ...{
56
51
  name: 'Content'
@@ -65,7 +60,6 @@ const __sfc_main__ = _defineComponent({
65
60
  setup(__props) {
66
61
  const props = __props;
67
62
  const slots = useSlots();
68
- const _rowSelection = useTableInject();
69
63
  const _columns = computed(() => props.columns.filter((i) => !_optionalChain([i, 'optionalAccess', _2 => _2.hideInTable])));
70
64
  const _slots = computed(() => {
71
65
  return omit(slots, ['emptyText', 'bodyCell']);
@@ -85,12 +79,6 @@ const __sfc_main__ = _defineComponent({
85
79
  const gridTemplateColumns = computed(() => {
86
80
  return `repeat(${props.column}, 1fr)`;
87
81
  });
88
- const onClick = (item) => {
89
- if (_rowSelection && _rowSelection.value) {
90
- const _selected = _optionalChain([_rowSelection, 'access', _3 => _3.value, 'access', _4 => _4.selectedRowKeys, 'optionalAccess', _5 => _5.includes, 'call', _6 => _6(item[props.rowKey])]);
91
- _optionalChain([_rowSelection, 'access', _7 => _7.value, 'access', _8 => _8.onSelect, 'optionalCall', _9 => _9(item, !_selected)]);
92
- }
93
- };
94
82
  return (_ctx, _cache) => {
95
83
  return (_openBlock(), _createElementBlock("div", _hoisted_1, [
96
84
  (_ctx.mode === 'CARD')
@@ -104,35 +92,34 @@ const __sfc_main__ = _defineComponent({
104
92
  (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.dataSource, (item) => {
105
93
  return (_openBlock(), _createElementBlock("div", {
106
94
  class: _normalizeClass(['jtable-card-item', props.cardBodyClass]),
107
- key: item[props.rowKey],
108
- onClick: ($event) => (onClick(item))
95
+ key: item[props.rowKey]
109
96
  }, [
110
97
  _renderSlot(_ctx.$slots, "card", _mergeProps({ ref_for: true }, item))
111
- ], 10 /* CLASS, PROPS */, _hoisted_3));
98
+ ], 2 /* CLASS */));
112
99
  }), 128 /* KEYED_FRAGMENT */))
113
100
  ], 4 /* STYLE */))
114
- : (_openBlock(), _createElementBlock("div", _hoisted_4, [
101
+ : (_openBlock(), _createElementBlock("div", _hoisted_3, [
115
102
  _renderSlot(_ctx.$slots, "emptyText", {}, () => [
116
103
  _createVNode(_unref(Empty))
117
104
  ])
118
105
  ]))
119
106
  ]))
120
107
  : (_openBlock(), _createBlock(_unref(Table), _mergeProps({ key: 1 }, props, {
121
- "row-selection": _ctx.rowSelection || _unref(_rowSelection),
108
+ "row-selection": _ctx.rowSelection,
122
109
  dataSource: _ctx.dataSource,
123
110
  columns: _columns.value,
124
111
  pagination: false,
125
112
  scroll: _scroll.value,
126
- class: { 'j-table-scroll': !_optionalChain([props, 'access', _10 => _10.scroll, 'optionalAccess', _11 => _11.y]) }
113
+ class: { 'j-table-scroll': !_optionalChain([props, 'access', _3 => _3.scroll, 'optionalAccess', _4 => _4.y]) }
127
114
  }), _createSlots({
128
115
  bodyCell: _withCtx(({ column, record, index }) => [
129
- ((_optionalChain([column, 'optionalAccess', _12 => _12.key]) || _optionalChain([column, 'optionalAccess', _13 => _13.dataIndex])) && _optionalChain([column, 'optionalAccess', _14 => _14.scopedSlots]) && (_optionalChain([_slots, 'access', _15 => _15.value, 'optionalAccess', _16 => _16[_optionalChain([column, 'optionalAccess', _17 => _17.dataIndex])]]) || _optionalChain([_slots, 'access', _18 => _18.value, 'optionalAccess', _19 => _19[_optionalChain([column, 'optionalAccess', _20 => _20.key])]])))
130
- ? _renderSlot(_ctx.$slots, _optionalChain([column, 'optionalAccess', _21 => _21.key]) || _optionalChain([column, 'optionalAccess', _22 => _22.dataIndex]), _mergeProps({ key: 0 }, record, {
116
+ ((_optionalChain([column, 'optionalAccess', _5 => _5.key]) || _optionalChain([column, 'optionalAccess', _6 => _6.dataIndex])) && _optionalChain([column, 'optionalAccess', _7 => _7.scopedSlots]) && (_optionalChain([_slots, 'access', _8 => _8.value, 'optionalAccess', _9 => _9[_optionalChain([column, 'optionalAccess', _10 => _10.dataIndex])]]) || _optionalChain([_slots, 'access', _11 => _11.value, 'optionalAccess', _12 => _12[_optionalChain([column, 'optionalAccess', _13 => _13.key])]])))
117
+ ? _renderSlot(_ctx.$slots, _optionalChain([column, 'optionalAccess', _14 => _14.key]) || _optionalChain([column, 'optionalAccess', _15 => _15.dataIndex]), _mergeProps({ key: 0 }, record, {
131
118
  index: index,
132
119
  column: column
133
120
  }))
134
121
  : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
135
- _createTextVNode(_toDisplayString(_unref(get)(record, _optionalChain([column, 'optionalAccess', _23 => _23.dataIndex]) || _optionalChain([column, 'optionalAccess', _24 => _24.key])) || '--'), 1 /* TEXT */)
122
+ _createTextVNode(_toDisplayString(_unref(get)(record, _optionalChain([column, 'optionalAccess', _16 => _16.dataIndex]) || _optionalChain([column, 'optionalAccess', _17 => _17.key])) || '--'), 1 /* TEXT */)
136
123
  ], 64 /* STABLE_FRAGMENT */))
137
124
  ]),
138
125
  emptyText: _withCtx(() => [
@@ -146,7 +133,7 @@ const __sfc_main__ = _defineComponent({
146
133
  return {
147
134
  name: slotKey,
148
135
  fn: _withCtx((slotProps) => [
149
- (!((_optionalChain([__props, 'access', _25 => _25.column, 'optionalAccess', _26 => _26.key]) || _optionalChain([__props, 'access', _27 => _27.column, 'optionalAccess', _28 => _28.dataIndex])) && _optionalChain([__props, 'access', _29 => _29.column, 'optionalAccess', _30 => _30.scopedSlots]) && (_optionalChain([_slots, 'access', _31 => _31.value, 'optionalAccess', _32 => _32[_optionalChain([__props, 'access', _33 => _33.column, 'optionalAccess', _34 => _34.dataIndex])]]) || _optionalChain([_slots, 'access', _35 => _35.value, 'optionalAccess', _36 => _36[_optionalChain([__props, 'access', _37 => _37.column, 'optionalAccess', _38 => _38.key])]]))))
136
+ (!((_optionalChain([__props, 'access', _18 => _18.column, 'optionalAccess', _19 => _19.key]) || _optionalChain([__props, 'access', _20 => _20.column, 'optionalAccess', _21 => _21.dataIndex])) && _optionalChain([__props, 'access', _22 => _22.column, 'optionalAccess', _23 => _23.scopedSlots]) && (_optionalChain([_slots, 'access', _24 => _24.value, 'optionalAccess', _25 => _25[_optionalChain([__props, 'access', _26 => _26.column, 'optionalAccess', _27 => _27.dataIndex])]]) || _optionalChain([_slots, 'access', _28 => _28.value, 'optionalAccess', _29 => _29[_optionalChain([__props, 'access', _30 => _30.column, 'optionalAccess', _31 => _31.key])]]))))
150
137
  ? _renderSlot(_ctx.$slots, slotKey, _normalizeProps(_mergeProps({ key: 0 }, slotProps)))
151
138
  : _createCommentVNode("v-if", true)
152
139
  ])
@@ -0,0 +1,5 @@
1
+ import { PROTABLE_ROW_SELECTION_KEY } from "./useTableSelection";
2
+ import { inject } from "vue";
3
+ export var useTableInject = function useTableInject() {
4
+ return inject(PROTABLE_ROW_SELECTION_KEY, null);
5
+ };
@@ -0,0 +1,95 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import { ref, provide, watch, unref, computed } from "vue";
4
+ import { omit } from "lodash-es";
5
+ export var PROTABLE_ROW_SELECTION_KEY = Symbol('protable-row-selection-key');
6
+ export var useTableSelection = function useTableSelection() {
7
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
8
+ type: 'checkbox',
9
+ rowKey: "id",
10
+ isCheck: true
11
+ };
12
+ var _options$type = options.type,
13
+ type = _options$type === void 0 ? 'checkbox' : _options$type,
14
+ _options$rowKey = options.rowKey,
15
+ rowKey = _options$rowKey === void 0 ? 'id' : _options$rowKey;
16
+ var selectedRowKeys = ref([]);
17
+ var selectedRows = ref([]);
18
+ var selectionObj = ref(null);
19
+ var isCheckRef = computed(function () {
20
+ return unref(options.isCheck);
21
+ });
22
+ var onSelect = function onSelect(record, selected) {
23
+ if (type === 'checkbox') {
24
+ if (selected) {
25
+ selectedRows.value.push(record);
26
+ } else {
27
+ selectedRows.value = selectedRows.value.filter(function (i) {
28
+ return i[rowKey] !== record[rowKey];
29
+ });
30
+ }
31
+ selectedRowKeys.value = selectedRows.value.map(function (i) {
32
+ return i[rowKey];
33
+ });
34
+ }
35
+ };
36
+ // 单选
37
+ var onChange = function onChange(_selectedRowKeys, _selectedRows) {
38
+ if (type === 'radio') {
39
+ selectedRowKeys.value = _selectedRowKeys;
40
+ selectedRows.value = _selectedRows;
41
+ }
42
+ };
43
+ var onSelectAll = function onSelectAll(selected, _selectedRows, changeRows) {
44
+ if (selected) {
45
+ var _selectedRows$value;
46
+ (_selectedRows$value = selectedRows.value).push.apply(_selectedRows$value, _toConsumableArray(changeRows));
47
+ } else {
48
+ var arr = changeRows.map(function (item) {
49
+ return item[rowKey];
50
+ });
51
+ selectedRows.value = selectedRows.value.filter(function (i) {
52
+ return !arr.includes(i[rowKey]);
53
+ });
54
+ }
55
+ selectedRowKeys.value = selectedRows.value.map(function (i) {
56
+ return i[rowKey];
57
+ });
58
+ };
59
+ var onSelectNone = function onSelectNone() {
60
+ selectedRowKeys.value = [];
61
+ selectedRows.value = [];
62
+ };
63
+ var updateSelection = function updateSelection() {
64
+ if (isCheckRef.value) {
65
+ // 提供选择上下文
66
+ selectionObj.value = type === 'checkbox' ? _objectSpread(_objectSpread({}, omit(options, ['isCheck'])), {}, {
67
+ selectedRowKeys: selectedRowKeys,
68
+ onSelect: onSelect,
69
+ onSelectAll: onSelectAll,
70
+ onSelectNone: onSelectNone
71
+ }) : _objectSpread(_objectSpread({}, omit(options, ['isCheck'])), {}, {
72
+ selectedRowKeys: selectedRowKeys,
73
+ onChange: onChange,
74
+ onSelectNone: onSelectNone
75
+ });
76
+ } else {
77
+ // 清空选择状态
78
+ onSelectNone();
79
+ selectionObj.value = null;
80
+ }
81
+ };
82
+ watch(isCheckRef, function () {
83
+ updateSelection();
84
+ }, {
85
+ immediate: true,
86
+ deep: false
87
+ } // 注意:deep 设为 false
88
+ );
89
+ provide(PROTABLE_ROW_SELECTION_KEY, selectionObj);
90
+ return {
91
+ selectedRowKeys: selectedRowKeys,
92
+ selectedRows: selectedRows,
93
+ onSelectNone: onSelectNone
94
+ };
95
+ };
@@ -23,15 +23,12 @@ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]
23
23
  "get": "setup-maybe-ref",
24
24
  "omit": "setup-maybe-ref",
25
25
  "Empty": "setup-maybe-ref",
26
- "useTableInject": "setup-maybe-ref",
27
26
  "props": "setup-reactive-const",
28
27
  "slots": "setup-maybe-ref",
29
- "_rowSelection": "setup-maybe-ref",
30
28
  "_columns": "setup-ref",
31
29
  "_slots": "setup-ref",
32
30
  "_scroll": "setup-ref",
33
- "gridTemplateColumns": "setup-ref",
34
- "onClick": "setup-const"
31
+ "gridTemplateColumns": "setup-ref"
35
32
  } */
36
33
  import { defineComponent as _defineComponent } from 'vue';
37
34
  import { renderList as _renderList, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock, mergeProps as _mergeProps, renderSlot as _renderSlot, normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, createCommentVNode as _createCommentVNode, unref as _unref, createVNode as _createVNode, normalizeProps as _normalizeProps, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, withCtx as _withCtx, createSlots as _createSlots, createBlock as _createBlock } from "vue";
@@ -40,8 +37,7 @@ const _hoisted_2 = {
40
37
  key: 0,
41
38
  class: "jtable-card"
42
39
  };
43
- const _hoisted_3 = ["onClick"];
44
- const _hoisted_4 = {
40
+ const _hoisted_3 = {
45
41
  key: 1,
46
42
  class: "j-table-empty"
47
43
  };
@@ -50,7 +46,6 @@ import { _contentProps } from "./setting";
50
46
  import { Table } from 'ant-design-vue/lib/';
51
47
  import { get, omit } from 'lodash-es';
52
48
  import Empty from '../Empty';
53
- import { useTableInject } from './hooks';
54
49
  const __sfc_main__ = _defineComponent({
55
50
  ...{
56
51
  name: 'Content'
@@ -65,7 +60,6 @@ const __sfc_main__ = _defineComponent({
65
60
  setup(__props) {
66
61
  const props = __props;
67
62
  const slots = useSlots();
68
- const _rowSelection = useTableInject();
69
63
  const _columns = computed(() => props.columns.filter((i) => !_optionalChain([i, 'optionalAccess', _2 => _2.hideInTable])));
70
64
  const _slots = computed(() => {
71
65
  return omit(slots, ['emptyText', 'bodyCell']);
@@ -85,12 +79,6 @@ const __sfc_main__ = _defineComponent({
85
79
  const gridTemplateColumns = computed(() => {
86
80
  return `repeat(${props.column}, 1fr)`;
87
81
  });
88
- const onClick = (item) => {
89
- if (_rowSelection && _rowSelection.value) {
90
- const _selected = _optionalChain([_rowSelection, 'access', _3 => _3.value, 'access', _4 => _4.selectedRowKeys, 'optionalAccess', _5 => _5.includes, 'call', _6 => _6(item[props.rowKey])]);
91
- _optionalChain([_rowSelection, 'access', _7 => _7.value, 'access', _8 => _8.onSelect, 'optionalCall', _9 => _9(item, !_selected)]);
92
- }
93
- };
94
82
  return (_ctx, _cache) => {
95
83
  return (_openBlock(), _createElementBlock("div", _hoisted_1, [
96
84
  (_ctx.mode === 'CARD')
@@ -104,35 +92,34 @@ const __sfc_main__ = _defineComponent({
104
92
  (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.dataSource, (item) => {
105
93
  return (_openBlock(), _createElementBlock("div", {
106
94
  class: _normalizeClass(['jtable-card-item', props.cardBodyClass]),
107
- key: item[props.rowKey],
108
- onClick: ($event) => (onClick(item))
95
+ key: item[props.rowKey]
109
96
  }, [
110
97
  _renderSlot(_ctx.$slots, "card", _mergeProps({ ref_for: true }, item))
111
- ], 10 /* CLASS, PROPS */, _hoisted_3));
98
+ ], 2 /* CLASS */));
112
99
  }), 128 /* KEYED_FRAGMENT */))
113
100
  ], 4 /* STYLE */))
114
- : (_openBlock(), _createElementBlock("div", _hoisted_4, [
101
+ : (_openBlock(), _createElementBlock("div", _hoisted_3, [
115
102
  _renderSlot(_ctx.$slots, "emptyText", {}, () => [
116
103
  _createVNode(_unref(Empty))
117
104
  ])
118
105
  ]))
119
106
  ]))
120
107
  : (_openBlock(), _createBlock(_unref(Table), _mergeProps({ key: 1 }, props, {
121
- "row-selection": _ctx.rowSelection || _unref(_rowSelection),
108
+ "row-selection": _ctx.rowSelection,
122
109
  dataSource: _ctx.dataSource,
123
110
  columns: _columns.value,
124
111
  pagination: false,
125
112
  scroll: _scroll.value,
126
- class: { 'j-table-scroll': !_optionalChain([props, 'access', _10 => _10.scroll, 'optionalAccess', _11 => _11.y]) }
113
+ class: { 'j-table-scroll': !_optionalChain([props, 'access', _3 => _3.scroll, 'optionalAccess', _4 => _4.y]) }
127
114
  }), _createSlots({
128
115
  bodyCell: _withCtx(({ column, record, index }) => [
129
- ((_optionalChain([column, 'optionalAccess', _12 => _12.key]) || _optionalChain([column, 'optionalAccess', _13 => _13.dataIndex])) && _optionalChain([column, 'optionalAccess', _14 => _14.scopedSlots]) && (_optionalChain([_slots, 'access', _15 => _15.value, 'optionalAccess', _16 => _16[_optionalChain([column, 'optionalAccess', _17 => _17.dataIndex])]]) || _optionalChain([_slots, 'access', _18 => _18.value, 'optionalAccess', _19 => _19[_optionalChain([column, 'optionalAccess', _20 => _20.key])]])))
130
- ? _renderSlot(_ctx.$slots, _optionalChain([column, 'optionalAccess', _21 => _21.key]) || _optionalChain([column, 'optionalAccess', _22 => _22.dataIndex]), _mergeProps({ key: 0 }, record, {
116
+ ((_optionalChain([column, 'optionalAccess', _5 => _5.key]) || _optionalChain([column, 'optionalAccess', _6 => _6.dataIndex])) && _optionalChain([column, 'optionalAccess', _7 => _7.scopedSlots]) && (_optionalChain([_slots, 'access', _8 => _8.value, 'optionalAccess', _9 => _9[_optionalChain([column, 'optionalAccess', _10 => _10.dataIndex])]]) || _optionalChain([_slots, 'access', _11 => _11.value, 'optionalAccess', _12 => _12[_optionalChain([column, 'optionalAccess', _13 => _13.key])]])))
117
+ ? _renderSlot(_ctx.$slots, _optionalChain([column, 'optionalAccess', _14 => _14.key]) || _optionalChain([column, 'optionalAccess', _15 => _15.dataIndex]), _mergeProps({ key: 0 }, record, {
131
118
  index: index,
132
119
  column: column
133
120
  }))
134
121
  : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [
135
- _createTextVNode(_toDisplayString(_unref(get)(record, _optionalChain([column, 'optionalAccess', _23 => _23.dataIndex]) || _optionalChain([column, 'optionalAccess', _24 => _24.key])) || '--'), 1 /* TEXT */)
122
+ _createTextVNode(_toDisplayString(_unref(get)(record, _optionalChain([column, 'optionalAccess', _16 => _16.dataIndex]) || _optionalChain([column, 'optionalAccess', _17 => _17.key])) || '--'), 1 /* TEXT */)
136
123
  ], 64 /* STABLE_FRAGMENT */))
137
124
  ]),
138
125
  emptyText: _withCtx(() => [
@@ -146,7 +133,7 @@ const __sfc_main__ = _defineComponent({
146
133
  return {
147
134
  name: slotKey,
148
135
  fn: _withCtx((slotProps) => [
149
- (!((_optionalChain([__props, 'access', _25 => _25.column, 'optionalAccess', _26 => _26.key]) || _optionalChain([__props, 'access', _27 => _27.column, 'optionalAccess', _28 => _28.dataIndex])) && _optionalChain([__props, 'access', _29 => _29.column, 'optionalAccess', _30 => _30.scopedSlots]) && (_optionalChain([_slots, 'access', _31 => _31.value, 'optionalAccess', _32 => _32[_optionalChain([__props, 'access', _33 => _33.column, 'optionalAccess', _34 => _34.dataIndex])]]) || _optionalChain([_slots, 'access', _35 => _35.value, 'optionalAccess', _36 => _36[_optionalChain([__props, 'access', _37 => _37.column, 'optionalAccess', _38 => _38.key])]]))))
136
+ (!((_optionalChain([__props, 'access', _18 => _18.column, 'optionalAccess', _19 => _19.key]) || _optionalChain([__props, 'access', _20 => _20.column, 'optionalAccess', _21 => _21.dataIndex])) && _optionalChain([__props, 'access', _22 => _22.column, 'optionalAccess', _23 => _23.scopedSlots]) && (_optionalChain([_slots, 'access', _24 => _24.value, 'optionalAccess', _25 => _25[_optionalChain([__props, 'access', _26 => _26.column, 'optionalAccess', _27 => _27.dataIndex])]]) || _optionalChain([_slots, 'access', _28 => _28.value, 'optionalAccess', _29 => _29[_optionalChain([__props, 'access', _30 => _30.column, 'optionalAccess', _31 => _31.key])]]))))
150
137
  ? _renderSlot(_ctx.$slots, slotKey, _normalizeProps(_mergeProps({ key: 0 }, slotProps)))
151
138
  : _createCommentVNode("v-if", true)
152
139
  ])
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTableInject = void 0;
7
+ var _useTableSelection = require("./useTableSelection");
8
+ var _vue = require("vue");
9
+ var useTableInject = exports.useTableInject = function useTableInject() {
10
+ return (0, _vue.inject)(_useTableSelection.PROTABLE_ROW_SELECTION_KEY, null);
11
+ };
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useTableSelection = exports.PROTABLE_ROW_SELECTION_KEY = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _vue = require("vue");
11
+ var _lodashEs = require("lodash");
12
+ var PROTABLE_ROW_SELECTION_KEY = exports.PROTABLE_ROW_SELECTION_KEY = Symbol('protable-row-selection-key');
13
+ var useTableSelection = exports.useTableSelection = function useTableSelection() {
14
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
15
+ type: 'checkbox',
16
+ rowKey: "id",
17
+ isCheck: true
18
+ };
19
+ var _options$type = options.type,
20
+ type = _options$type === void 0 ? 'checkbox' : _options$type,
21
+ _options$rowKey = options.rowKey,
22
+ rowKey = _options$rowKey === void 0 ? 'id' : _options$rowKey;
23
+ var selectedRowKeys = (0, _vue.ref)([]);
24
+ var selectedRows = (0, _vue.ref)([]);
25
+ var selectionObj = (0, _vue.ref)(null);
26
+ var isCheckRef = (0, _vue.computed)(function () {
27
+ return (0, _vue.unref)(options.isCheck);
28
+ });
29
+ var onSelect = function onSelect(record, selected) {
30
+ if (type === 'checkbox') {
31
+ if (selected) {
32
+ selectedRows.value.push(record);
33
+ } else {
34
+ selectedRows.value = selectedRows.value.filter(function (i) {
35
+ return i[rowKey] !== record[rowKey];
36
+ });
37
+ }
38
+ selectedRowKeys.value = selectedRows.value.map(function (i) {
39
+ return i[rowKey];
40
+ });
41
+ }
42
+ };
43
+ // 单选
44
+ var onChange = function onChange(_selectedRowKeys, _selectedRows) {
45
+ if (type === 'radio') {
46
+ selectedRowKeys.value = _selectedRowKeys;
47
+ selectedRows.value = _selectedRows;
48
+ }
49
+ };
50
+ var onSelectAll = function onSelectAll(selected, _selectedRows, changeRows) {
51
+ if (selected) {
52
+ var _selectedRows$value;
53
+ (_selectedRows$value = selectedRows.value).push.apply(_selectedRows$value, (0, _toConsumableArray2.default)(changeRows));
54
+ } else {
55
+ var arr = changeRows.map(function (item) {
56
+ return item[rowKey];
57
+ });
58
+ selectedRows.value = selectedRows.value.filter(function (i) {
59
+ return !arr.includes(i[rowKey]);
60
+ });
61
+ }
62
+ selectedRowKeys.value = selectedRows.value.map(function (i) {
63
+ return i[rowKey];
64
+ });
65
+ };
66
+ var onSelectNone = function onSelectNone() {
67
+ selectedRowKeys.value = [];
68
+ selectedRows.value = [];
69
+ };
70
+ var updateSelection = function updateSelection() {
71
+ if (isCheckRef.value) {
72
+ // 提供选择上下文
73
+ selectionObj.value = type === 'checkbox' ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _lodashEs.omit)(options, ['isCheck'])), {}, {
74
+ selectedRowKeys: selectedRowKeys,
75
+ onSelect: onSelect,
76
+ onSelectAll: onSelectAll,
77
+ onSelectNone: onSelectNone
78
+ }) : (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _lodashEs.omit)(options, ['isCheck'])), {}, {
79
+ selectedRowKeys: selectedRowKeys,
80
+ onChange: onChange,
81
+ onSelectNone: onSelectNone
82
+ });
83
+ } else {
84
+ // 清空选择状态
85
+ onSelectNone();
86
+ selectionObj.value = null;
87
+ }
88
+ };
89
+ (0, _vue.watch)(isCheckRef, function () {
90
+ updateSelection();
91
+ }, {
92
+ immediate: true,
93
+ deep: false
94
+ } // 注意:deep 设为 false
95
+ );
96
+ (0, _vue.provide)(PROTABLE_ROW_SELECTION_KEY, selectionObj);
97
+ return {
98
+ selectedRowKeys: selectedRowKeys,
99
+ selectedRows: selectedRows,
100
+ onSelectNone: onSelectNone
101
+ };
102
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetlinks-web/components",
3
- "version": "2.6.23",
3
+ "version": "2.6.24",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -45,8 +45,8 @@
45
45
  "resize-observer-polyfill": "^1.5.1",
46
46
  "sortablejs": "^1.15.2",
47
47
  "@jetlinks-web/constants": "1.0.9",
48
- "@jetlinks-web/utils": "1.2.12",
49
- "@jetlinks-web/hooks": "1.0.29"
48
+ "@jetlinks-web/hooks": "1.0.29",
49
+ "@jetlinks-web/utils": "1.2.12"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@babel/cli": "^7.8.4",