@cmstops/pro-compo 0.1.81 → 0.1.83

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.
@@ -1,7 +1,7 @@
1
1
  import { defineComponent, ref, watch, onMounted, openBlock, createElementBlock, createElementVNode, withDirectives, createVNode, unref, withModifiers, withCtx, createTextVNode, vShow, renderSlot } from "vue";
2
2
  import { Button } from "@arco-design/web-vue";
3
3
  import { IconCaretDown } from "@arco-design/web-vue/es/icon";
4
- import { createPopper } from "@popperjs/core";
4
+ import usePopper from "../../hooks/usePopper.js";
5
5
  const _hoisted_1 = { class: "filter-view-container" };
6
6
  const _hoisted_2 = { class: "more-btn" };
7
7
  const _hoisted_3 = { class: "right-prefix" };
@@ -14,120 +14,89 @@ const _hoisted_6 = {
14
14
  const _sfc_main = defineComponent({
15
15
  __name: "FilterGroup",
16
16
  setup(__props) {
17
- const documentWidth = ref(0);
18
- const overflowWidth = ref(0);
19
- watch(
20
- () => documentWidth.value,
21
- (n) => checkOverflow()
22
- );
23
- watch(
24
- () => overflowWidth.value,
25
- (n) => setPannelItem()
26
- );
27
- const initDocWidthListener = function() {
28
- window.onresize = (() => {
29
- return () => {
30
- documentWidth.value = document.body.clientWidth;
31
- };
32
- })();
17
+ const getRect = (el) => {
18
+ if (!el || !el.getClientRects())
19
+ return { right: 0, width: 0 };
20
+ const [{ right, width }] = el.getClientRects();
21
+ return {
22
+ right,
23
+ width
24
+ };
33
25
  };
34
- const filterItemsRef = ref();
35
26
  const moreBtnRef = ref();
36
27
  const dpPannelRef = ref();
37
- const initPopper = function() {
38
- createPopper(moreBtnRef.value, dpPannelRef.value, {
39
- placement: "bottom-start"
40
- });
28
+ const { initPopper, show, visible } = usePopper(dpPannelRef, moreBtnRef);
29
+ const filterItemsRef = ref();
30
+ const windowWidth = ref(0);
31
+ const filterWidth = ref(0);
32
+ const filterBorder = ref(0);
33
+ const initWidth = () => {
34
+ var _a;
35
+ windowWidth.value = ((_a = document.body) == null ? void 0 : _a.clientWidth) || 0;
36
+ if (filterItemsRef.value) {
37
+ filterWidth.value = filterItemsRef.value.clientWidth || 0;
38
+ filterBorder.value = getRect(filterItemsRef.value).right;
39
+ }
41
40
  };
42
- const popperShowFlag = ref(false);
43
- function showPopper() {
44
- popperShowFlag.value = true;
45
- window.onclick = hidePopper;
46
- }
47
- function hidePopper() {
48
- popperShowFlag.value = false;
49
- }
50
- const itemNodeArr = ref([]);
51
- const itemWidthArr = ref([]);
52
- const itemArr = ref([]);
53
- function checkOverflow() {
54
- if (!filterItemsRef.value)
41
+ const initDocWidthListener = () => window.onresize = () => initWidth();
42
+ const hideElementList = ref([]);
43
+ const inNode = (el) => {
44
+ var _a, _b;
45
+ hideElementList.value.push({ width: getRect(el).width, el });
46
+ (_a = filterItemsRef.value) == null ? void 0 : _a.removeChild(el);
47
+ (_b = dpPannelRef.value) == null ? void 0 : _b.appendChild(el);
48
+ };
49
+ const outNode = () => {
50
+ var _a, _b;
51
+ if (!hideElementList.value.length || !filterItemsRef.value)
55
52
  return;
56
- const parent = filterItemsRef.value.parentNode;
57
- if (!itemNodeArr.value.length) {
58
- itemNodeArr.value = mapNodes(filterItemsRef.value.childNodes);
59
- itemWidthArr.value = itemNodeArr.value.map((node) => node.clientWidth + 10);
60
- itemArr.value = itemWidthArr.value.map((_, idx) => idx);
61
- }
62
- const parentWidth = parent.clientWidth;
63
- const leftWidth = getArrWidth(itemWidthArr.value);
64
- const rightWidth = parent.childNodes[parent.childNodes.length - 1].clientWidth;
65
- overflowWidth.value = leftWidth + rightWidth - parentWidth;
66
- }
67
- function mapNodes(nodes) {
68
- const nodeArr = [];
69
- for (let i = 0; i < nodes.length; i++) {
70
- const element = nodes[i];
71
- nodeArr.push(element);
53
+ const popEl = hideElementList.value.pop();
54
+ if (!popEl)
55
+ return;
56
+ const { width, el } = popEl;
57
+ el.style.width = `${width}px`;
58
+ (_a = dpPannelRef.value) == null ? void 0 : _a.removeChild(el);
59
+ (_b = filterItemsRef.value) == null ? void 0 : _b.appendChild(el);
60
+ hideElementList.value.splice(-1, 0);
61
+ };
62
+ const checkOverflow = () => {
63
+ if (!filterItemsRef.value)
64
+ return -1;
65
+ const elements = Array.from(filterItemsRef.value.childNodes);
66
+ let rightBorder = 0;
67
+ elements.forEach((item) => {
68
+ if (item.className !== "filter-item-view")
69
+ return;
70
+ const { right } = getRect(item);
71
+ if (right <= filterBorder.value) {
72
+ rightBorder = right;
73
+ return;
74
+ }
75
+ inNode(item);
76
+ });
77
+ return rightBorder;
78
+ };
79
+ const refreshPanel = () => {
80
+ const border = checkOverflow();
81
+ if (hideElementList.value.length && border !== -1) {
82
+ const spaceWidth = filterBorder.value - border;
83
+ const { width } = hideElementList.value[hideElementList.value.length - 1];
84
+ if (spaceWidth > width + 20) {
85
+ outNode();
86
+ }
72
87
  }
73
- return nodeArr.filter((item) => item.clientWidth);
74
- }
75
- function getArrWidth(arr) {
76
- return arr.reduce((prev, cur) => prev + cur, 0);
77
- }
78
- const pannelArray = ref("");
88
+ };
79
89
  watch(
80
- () => pannelArray.value,
81
- (n, o) => refreshPannel(n, o)
90
+ () => windowWidth.value,
91
+ () => refreshPanel()
82
92
  );
83
- function refreshPannel(newStr, oldStr) {
84
- const nArr = newStr ? newStr.split(",") : [];
85
- const oArr = oldStr ? oldStr.split(",") : [];
86
- if (nArr.length && nArr.length > oArr.length) {
87
- diff(nArr, oArr).forEach((index) => inNode(parseInt(index, 10)));
88
- } else if (nArr.length >= 0 && nArr.length < oArr.length) {
89
- diff(oArr, nArr).forEach((index) => outNode(parseInt(index, 10)));
90
- }
91
- }
92
- const diff = (arr1, arr2) => {
93
- const diff2 = [];
94
- for (let i = 0; i < arr1.length; i++) {
95
- const item = arr1[i];
96
- if (!arr2.includes(item))
97
- diff2.push(item);
98
- }
99
- return diff2;
100
- };
101
- function inNode(index) {
102
- var _a, _b, _c;
103
- const node = mapNodes((_a = filterItemsRef.value) == null ? void 0 : _a.childNodes)[index];
104
- const temp = document.createElement("div");
105
- temp.style.width = `${itemWidthArr.value[index]}px`;
106
- temp.style.position = "absolute";
107
- temp.style.left = `${50}px`;
108
- (_b = filterItemsRef.value) == null ? void 0 : _b.replaceChild(temp, node);
109
- (_c = dpPannelRef.value) == null ? void 0 : _c.appendChild(node);
110
- }
111
- function outNode(index) {
112
- var _a;
113
- const node = itemNodeArr.value[index];
114
- (_a = filterItemsRef.value) == null ? void 0 : _a.replaceChild(
115
- node,
116
- mapNodes(filterItemsRef.value.childNodes)[index]
117
- );
118
- }
119
- function setPannelItem() {
120
- let inPannelNum = 0;
121
- if (overflowWidth.value > 0) {
122
- const avgWidth = 120;
123
- inPannelNum = Math.ceil((overflowWidth.value + 200) / avgWidth);
124
- }
125
- pannelArray.value = itemArr.value.slice(0, inPannelNum).join(",");
126
- }
127
93
  onMounted(() => {
128
94
  initDocWidthListener();
129
95
  initPopper();
130
- setTimeout(() => checkOverflow());
96
+ initWidth();
97
+ setTimeout(() => {
98
+ refreshPanel();
99
+ });
131
100
  });
132
101
  return (_ctx, _cache) => {
133
102
  return openBlock(), createElementBlock("div", _hoisted_1, [
@@ -137,7 +106,7 @@ const _sfc_main = defineComponent({
137
106
  ref: moreBtnRef
138
107
  }, [
139
108
  withDirectives(createVNode(unref(Button), {
140
- onClick: withModifiers(showPopper, ["stop"])
109
+ onClick: _cache[0] || (_cache[0] = withModifiers(() => unref(show)(), ["stop"]))
141
110
  }, {
142
111
  default: withCtx(() => [
143
112
  createElementVNode("span", _hoisted_3, [
@@ -147,7 +116,7 @@ const _sfc_main = defineComponent({
147
116
  ]),
148
117
  _: 1
149
118
  }, 512), [
150
- [vShow, pannelArray.value]
119
+ [vShow, hideElementList.value.length]
151
120
  ])
152
121
  ], 512),
153
122
  withDirectives(createElementVNode("div", {
@@ -156,7 +125,7 @@ const _sfc_main = defineComponent({
156
125
  ref: dpPannelRef,
157
126
  class: "filter-pannel"
158
127
  }, null, 512), [
159
- [vShow, popperShowFlag.value]
128
+ [vShow, unref(visible)]
160
129
  ])
161
130
  ]),
162
131
  createElementVNode("div", _hoisted_4, [
@@ -1,60 +1,53 @@
1
1
  // FilterGroup 内部样式
2
2
  .filter-view-container {
3
3
  display: flex;
4
+ gap: 10px;
4
5
  align-items: center;
6
+ justify-content: space-between;
7
+ width: 100%;
5
8
  margin-bottom: 10px;
6
9
  font-size: 14px;
7
10
 
8
- .filter-search {
9
- display: flex;
10
- gap: 10px;
11
- width: 180px;
12
- margin-right: 10px;
11
+ .more-btn {
12
+ .right-prefix {
13
+ display: flex;
14
+ gap: 10px;
15
+ align-items: center;
16
+ }
17
+
18
+ .filter-pannel {
19
+ z-index: 1002;
20
+ display: flex;
21
+ gap: 10px;
22
+ padding: 10px;
23
+ background-color: white;
24
+ border-radius: 6px;
25
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
26
+ }
13
27
  }
14
28
 
15
29
  .filter-content {
16
- position: relative;
17
30
  display: flex;
18
31
  flex: 1;
19
32
  align-items: center;
20
33
  justify-content: space-between;
21
- }
22
34
 
23
- .left {
24
- display: flex;
25
- gap: 10px;
26
- align-items: center;
27
- }
35
+ .left {
36
+ display: flex;
37
+ flex: 1;
38
+ gap: 10px;
39
+ width: 100px;
40
+ overflow: hidden;
41
+ background-color: #fff;
42
+ }
28
43
 
29
- .right {
30
- position: absolute;
31
- right: 0;
32
- z-index: 1;
33
- display: flex;
34
- flex-wrap: nowrap;
35
- align-items: center;
36
- height: 100%;
37
- padding-left: 20px;
38
- background: white;
39
- }
40
-
41
- .more-btn {
42
- z-index: 10;
43
- margin-right: 10px;
44
- }
45
-
46
- .right-prefix {
47
- display: flex;
48
- gap: 10px;
49
- align-items: center;
50
- }
51
-
52
- .filter-pannel {
53
- display: flex;
54
- gap: 10px;
55
- padding: 10px;
56
- background-color: white;
57
- border-radius: 6px;
58
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
44
+ .right {
45
+ display: flex;
46
+ flex-wrap: nowrap;
47
+ align-items: center;
48
+ height: 100%;
49
+ padding-left: 20px;
50
+ background: white;
51
+ }
59
52
  }
60
53
  }
@@ -1,31 +1,41 @@
1
1
  .filter-view-container {
2
2
  display: flex;
3
+ gap: 10px;
3
4
  align-items: center;
5
+ justify-content: space-between;
6
+ width: 100%;
4
7
  margin-bottom: 10px;
5
8
  font-size: 14px;
6
9
  }
7
- .filter-view-container .filter-search {
10
+ .filter-view-container .more-btn .right-prefix {
11
+ display: flex;
12
+ gap: 10px;
13
+ align-items: center;
14
+ }
15
+ .filter-view-container .more-btn .filter-pannel {
16
+ z-index: 1002;
8
17
  display: flex;
9
18
  gap: 10px;
10
- width: 180px;
11
- margin-right: 10px;
19
+ padding: 10px;
20
+ background-color: white;
21
+ border-radius: 6px;
22
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
12
23
  }
13
24
  .filter-view-container .filter-content {
14
- position: relative;
15
25
  display: flex;
16
26
  flex: 1;
17
27
  align-items: center;
18
28
  justify-content: space-between;
19
29
  }
20
- .filter-view-container .left {
30
+ .filter-view-container .filter-content .left {
21
31
  display: flex;
32
+ flex: 1;
22
33
  gap: 10px;
23
- align-items: center;
34
+ width: 100px;
35
+ overflow: hidden;
36
+ background-color: #fff;
24
37
  }
25
- .filter-view-container .right {
26
- position: absolute;
27
- right: 0;
28
- z-index: 1;
38
+ .filter-view-container .filter-content .right {
29
39
  display: flex;
30
40
  flex-wrap: nowrap;
31
41
  align-items: center;
@@ -33,23 +43,6 @@
33
43
  padding-left: 20px;
34
44
  background: white;
35
45
  }
36
- .filter-view-container .more-btn {
37
- z-index: 10;
38
- margin-right: 10px;
39
- }
40
- .filter-view-container .right-prefix {
41
- display: flex;
42
- gap: 10px;
43
- align-items: center;
44
- }
45
- .filter-view-container .filter-pannel {
46
- display: flex;
47
- gap: 10px;
48
- padding: 10px;
49
- background-color: white;
50
- border-radius: 6px;
51
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
52
- }
53
46
  .base-filter-container {
54
47
  display: flex;
55
48
  align-items: center;
@@ -1,4 +1,11 @@
1
1
  import { Ref } from 'vue';
2
+ /**
3
+ * @deprecated 改为其他方式实现
4
+ * @param filterItemsRef
5
+ * @param dpPannelRef
6
+ * @param moreBtnRef
7
+ * @returns
8
+ */
2
9
  export default function useCalcWidth(filterItemsRef: Ref<HTMLElement | undefined>, dpPannelRef: Ref<HTMLElement | undefined>, moreBtnRef: Ref<HTMLElement | undefined>): {
3
10
  pannelArray: Ref<string>;
4
11
  popperShowFlag: Ref<boolean>;
@@ -0,0 +1,7 @@
1
+ import { Placement } from '@popperjs/core';
2
+ import { Ref } from 'vue';
3
+ export default function usePopper(pannel: Ref<HTMLElement | undefined>, triggerEl: Ref<HTMLElement | undefined>): {
4
+ initPopper: (placement?: Placement) => void;
5
+ show: () => void;
6
+ visible: Ref<boolean>;
7
+ };
@@ -0,0 +1,25 @@
1
+ import { createPopper } from "@popperjs/core";
2
+ import { ref } from "vue";
3
+ function usePopper(pannel, triggerEl) {
4
+ const visible = ref(false);
5
+ const show = () => {
6
+ visible.value = true;
7
+ window.onclick = (e) => {
8
+ visible.value = false;
9
+ window.onclick = null;
10
+ };
11
+ };
12
+ const initPopper = (placement = "bottom-start") => {
13
+ if (!pannel.value || !triggerEl.value)
14
+ return;
15
+ createPopper(triggerEl.value, pannel.value, {
16
+ placement
17
+ });
18
+ };
19
+ return {
20
+ initPopper,
21
+ show,
22
+ visible
23
+ };
24
+ }
25
+ export { usePopper as default };
package/es/index.css CHANGED
@@ -3498,32 +3498,42 @@
3498
3498
  }
3499
3499
  .filter-view-container {
3500
3500
  display: flex;
3501
+ gap: 10px;
3501
3502
  align-items: center;
3503
+ justify-content: space-between;
3504
+ width: 100%;
3502
3505
  margin-bottom: 10px;
3503
3506
  font-size: 14px;
3504
3507
  }
3505
- .filter-view-container .filter-search {
3508
+ .filter-view-container .more-btn .right-prefix {
3506
3509
  display: flex;
3507
3510
  gap: 10px;
3508
- width: 180px;
3509
- margin-right: 10px;
3511
+ align-items: center;
3512
+ }
3513
+ .filter-view-container .more-btn .filter-pannel {
3514
+ z-index: 1002;
3515
+ display: flex;
3516
+ gap: 10px;
3517
+ padding: 10px;
3518
+ background-color: white;
3519
+ border-radius: 6px;
3520
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
3510
3521
  }
3511
3522
  .filter-view-container .filter-content {
3512
- position: relative;
3513
3523
  display: flex;
3514
3524
  flex: 1;
3515
3525
  align-items: center;
3516
3526
  justify-content: space-between;
3517
3527
  }
3518
- .filter-view-container .left {
3528
+ .filter-view-container .filter-content .left {
3519
3529
  display: flex;
3530
+ flex: 1;
3520
3531
  gap: 10px;
3521
- align-items: center;
3532
+ width: 100px;
3533
+ overflow: hidden;
3534
+ background-color: #fff;
3522
3535
  }
3523
- .filter-view-container .right {
3524
- position: absolute;
3525
- right: 0;
3526
- z-index: 1;
3536
+ .filter-view-container .filter-content .right {
3527
3537
  display: flex;
3528
3538
  flex-wrap: nowrap;
3529
3539
  align-items: center;
@@ -3531,23 +3541,6 @@
3531
3541
  padding-left: 20px;
3532
3542
  background: white;
3533
3543
  }
3534
- .filter-view-container .more-btn {
3535
- z-index: 10;
3536
- margin-right: 10px;
3537
- }
3538
- .filter-view-container .right-prefix {
3539
- display: flex;
3540
- gap: 10px;
3541
- align-items: center;
3542
- }
3543
- .filter-view-container .filter-pannel {
3544
- display: flex;
3545
- gap: 10px;
3546
- padding: 10px;
3547
- background-color: white;
3548
- border-radius: 6px;
3549
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
3550
- }
3551
3544
  .base-filter-container {
3552
3545
  display: flex;
3553
3546
  align-items: center;
@@ -126,6 +126,12 @@ const _sfc_main = vue.defineComponent({
126
126
  );
127
127
  return (_ctx, _cache) => {
128
128
  return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
129
+ vue.createElementVNode("div", {
130
+ id: "base-filter-popup-container",
131
+ style: { "position": "relative", "z-index": "1001" },
132
+ onClick: _cache[0] || (_cache[0] = vue.withModifiers(() => {
133
+ }, ["stop"]))
134
+ }),
129
135
  vue.createVNode(FilterGroup, null, {
130
136
  left: vue.withCtx(() => [
131
137
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(renderColumns.value, (item, index) => {
@@ -147,6 +153,7 @@ const _sfc_main = vue.defineComponent({
147
153
  key: 1,
148
154
  modelValue: form.value[item.key],
149
155
  "onUpdate:modelValue": ($event) => form.value[item.key] = $event,
156
+ "popup-container": "#base-filter-popup-container",
150
157
  "allow-clear": "",
151
158
  style: vue.normalizeStyle({ width: styleWidth(columnsMap.value[item.key]) }),
152
159
  placeholder: `\u8BF7\u9009\u62E9${item.label}`
@@ -168,7 +175,8 @@ const _sfc_main = vue.defineComponent({
168
175
  "onUpdate:modelValue": ($event) => form.value[item.key].range = $event,
169
176
  style: vue.normalizeStyle({ width: styleWidth(form.value[item.key]) }),
170
177
  "value-format": "timestamp",
171
- onClick: _cache[0] || (_cache[0] = vue.withModifiers(() => {
178
+ "popup-container": "#base-filter-popup-container",
179
+ onClick: _cache[1] || (_cache[1] = vue.withModifiers(() => {
172
180
  }, ["stop"]))
173
181
  }, null, 8, ["modelValue", "onUpdate:modelValue", "style"])) : vue.createCommentVNode("v-if", true)
174
182
  ]),
@@ -180,9 +188,8 @@ const _sfc_main = vue.defineComponent({
180
188
  vue.renderSlot(_ctx.$slots, "right")
181
189
  ]),
182
190
  _: 3
183
- }),
184
- vue.createCommentVNode(' <div class="base-filter-container">\n <div class="left">\n <div v-if="render" class="form-ul">\n <template v-for="(item, index) in renderColumns" :key="index">\n <filter-item :active="hasValue(item.key)">\n <a-input-search\n v-if="item.component === \'input\'"\n v-model="form[item.key]"\n :style="{ width: styleWidth(columnsMap[item.key]) }"\n allow-clear\n size="medium"\n :placeholder="`\u8BF7\u8F93\u5165${item.label}`"\n />\n <a-select\n v-if="item.component === \'select\'"\n v-model="form[item.key]"\n allow-clear\n :style="{ width: styleWidth(columnsMap[item.key]) }"\n :placeholder="`\u8BF7\u9009\u62E9${item.label}`"\n >\n <template v-for="opt in getOptions(item)" :key="opt.value">\n <a-option :label="opt.label" :value="opt.value"></a-option\n ></template>\n </a-select>\n <a-range-picker\n v-if="item.component === \'range-picker\'"\n v-model="form[item.key].range"\n :style="{ width: styleWidth(form[item.key]) }"\n value-format="timestamp"\n @click.stop\n />\n </filter-item>\n </template>\n </div>\n </div>\n <div class="right">\n <slot name="right"></slot>\n </div>\n </div> ')
185
- ], 2112);
191
+ })
192
+ ], 64);
186
193
  };
187
194
  }
188
195
  });