@neatui/vue 2.15.11 → 2.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neatui/vue",
3
- "version": "2.15.11",
3
+ "version": "2.16.1",
4
4
  "description": "basic component ui",
5
5
  "main": "./src/index.ts",
6
6
  "license": "MIT",
@@ -10,13 +10,13 @@
10
10
  class="fekit-layer"
11
11
  >
12
12
  <div :ui-flex="`col ${flex}`" :style="wrapStyle" class="fekit-layer-wrap" @animationend="anim" @click="_sys_hide">
13
- <slot></slot>
13
+ <slot :param="_tasks[id]?.params"></slot>
14
14
  </div>
15
15
  </div>
16
16
  </Teleport>
17
17
  </template>
18
18
  <script lang="ts" setup>
19
- import { onBeforeUnmount, PropType, reactive, ref, watch } from 'vue';
19
+ import { onBeforeUnmount, reactive, watch } from 'vue';
20
20
  import { isFunction } from '@fekit/utils';
21
21
 
22
22
  // 弹层队列
@@ -25,39 +25,33 @@
25
25
  }
26
26
  const _tasks: any = (window as any)._FEKIT_LAYER_TASKS;
27
27
 
28
+ // 获取活跃的弹层
29
+ const getActiveLayer = () => {
30
+ return Object.values(_tasks).filter((task: any) => task.view > 0);
31
+ };
32
+
33
+ // 类型定义
34
+ interface Props {
35
+ zIndex?: string | number;
36
+ area?: string;
37
+ id: string;
38
+ am?: 'aa' | 'ab' | 'ac' | 'ad' | 'ae' | 'af' | 'ag' | 'ah' | 'ai' | 'aj' | 'ak' | 'al' | 'am' | 'an' | 'ao' | 'ap' | 'aq' | 'ar' | 'as' | 'at' | (string & {});
39
+ flex?: string;
40
+ dark?: string | number;
41
+ darkClickClose?: boolean;
42
+ wrapStyle?: string;
43
+ }
44
+
28
45
  // 弹窗入参
29
- const props: any = defineProps({
30
- zIndex: {
31
- type: [String, Number],
32
- default: '',
33
- },
34
- area: {
35
- type: String,
36
- default: '#fekit',
37
- },
38
- id: {
39
- type: String,
40
- },
41
- am: {
42
- type: String as PropType<'aa' | 'ab' | 'ac' | 'ad' | 'ae' | 'af' | 'ag' | 'ah' | 'ai' | 'aj' | 'ak' | 'al' | 'am' | 'an' | 'ao' | 'ap' | 'aq' | 'ar' | 'as' | 'at'>,
43
- default: 'as',
44
- },
45
- flex: {
46
- type: String as PropType<'lt' | 'ct' | 'rt' | 'lm' | 'cm' | 'rm' | 'lb' | 'cb' | 'rb'>,
47
- default: 'cm',
48
- },
49
- dark: {
50
- type: [String, Number],
51
- default: '',
52
- },
53
- darkClickClose: {
54
- type: Boolean,
55
- default: true,
56
- },
57
- wrapStyle: {
58
- type: String,
59
- default: '',
60
- },
46
+ const props = withDefaults(defineProps<Props>(), {
47
+ zIndex: '',
48
+ area: '#fekit',
49
+ id: '',
50
+ am: 'as',
51
+ flex: 'cm',
52
+ dark: '',
53
+ darkClickClose: true,
54
+ wrapStyle: '',
61
55
  });
62
56
 
63
57
  const _area: any = document.querySelector(props.area);
@@ -73,14 +67,18 @@
73
67
  view: 0,
74
68
  params: {},
75
69
  top: 0,
70
+ sw: 0,
76
71
  });
77
72
 
78
73
  function disableScroll() {
79
74
  state.top = document.documentElement.scrollTop;
75
+ const sw = window.innerWidth - document.documentElement.clientWidth;
76
+ state.sw = sw;
80
77
  document.body.style.overflow = 'hidden';
81
78
  document.body.style.position = 'fixed';
82
79
  document.body.style.top = `-${state.top}px`;
83
80
  document.body.style.width = '100%';
81
+ document.body.style.paddingRight = `${sw}px`;
84
82
  }
85
83
 
86
84
  function enableScroll() {
@@ -88,17 +86,30 @@
88
86
  document.body.style.removeProperty('position');
89
87
  document.body.style.removeProperty('top');
90
88
  document.body.style.removeProperty('width');
91
- window.scrollTo(0, state.top);
89
+ document.body.style.removeProperty('padding-right');
90
+ if (state.top) {
91
+ window.scrollTo(0, state.top);
92
+ }
92
93
  }
93
94
 
94
95
  watch(
95
96
  () => state.view,
96
97
  (view: any) => {
98
+ if (_tasks[props.id]) {
99
+ _tasks[props.id].view = view;
100
+ }
101
+
102
+ const active = getActiveLayer() || [];
103
+
97
104
  if (view === 2) {
98
- disableScroll();
105
+ if (active.length === 1) {
106
+ disableScroll();
107
+ }
99
108
  }
100
109
  if (view === 0) {
101
- enableScroll();
110
+ if (!active.length) {
111
+ enableScroll();
112
+ }
102
113
  }
103
114
  },
104
115
  { deep: true, immediate: true },
@@ -152,7 +163,14 @@
152
163
  // 关闭弹层(没有动画过程)
153
164
  const none = (_params: any = {}, then = () => {}) => {
154
165
  state.view = 0;
155
- on.show.push(then);
166
+ on.none.push(then);
167
+ // 立即执行回调,因为没有动画
168
+ on.none.forEach((fun: any) => {
169
+ if (isFunction(fun)) {
170
+ fun();
171
+ }
172
+ });
173
+ on.none.length = 0;
156
174
  };
157
175
 
158
176
  // 点暗层关闭
@@ -171,6 +189,7 @@
171
189
  fun();
172
190
  }
173
191
  });
192
+ on.hide.length = 0; // 清空回调数组
174
193
  }
175
194
  if (state.view === 2) {
176
195
  state.view = 3;
@@ -179,6 +198,7 @@
179
198
  fun();
180
199
  }
181
200
  });
201
+ on.show.length = 0; // 清空回调数组
182
202
  }
183
203
  };
184
204
 
@@ -200,6 +220,8 @@
200
220
  </script>
201
221
 
202
222
  <style lang="scss">
223
+ @use '@neatui/css' as neatui;
224
+
203
225
  // 弹层
204
226
  .fekit-layer {
205
227
  position: fixed;