hy-app 0.2.9 → 0.2.10
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/common/index.ts +1 -0
- package/common/queue.ts +34 -0
- package/components/hy-popover/hy-popover.vue +8 -0
- package/package.json +2 -2
package/common/index.ts
CHANGED
package/common/queue.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2023-07-02 22:51:06
|
|
4
|
+
* @LastEditTime: 2024-03-16 19:59:07
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/common/clickoutside.ts
|
|
8
|
+
* 记得注释
|
|
9
|
+
*/
|
|
10
|
+
let queue: any[] = []
|
|
11
|
+
|
|
12
|
+
export function pushToQueue(comp: any) {
|
|
13
|
+
queue.push(comp)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function removeFromQueue(comp: any) {
|
|
17
|
+
queue = queue.filter((item) => {
|
|
18
|
+
return item.$.uid !== comp.$.uid
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function closeOther(comp: any) {
|
|
23
|
+
queue.forEach((item) => {
|
|
24
|
+
if (item.$.uid !== comp.$.uid) {
|
|
25
|
+
item.$.exposed.close()
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function closeOutside() {
|
|
31
|
+
queue.forEach((item) => {
|
|
32
|
+
item.$.exposed.close()
|
|
33
|
+
})
|
|
34
|
+
}
|
|
@@ -111,6 +111,7 @@ import defaultProps from './props'
|
|
|
111
111
|
import IProps, { type PopoverExpose } from './typing'
|
|
112
112
|
import { isArray } from '../../utils'
|
|
113
113
|
import { type Queue, queueKey, usePopover } from '../../composables'
|
|
114
|
+
import { closeOther, pushToQueue, removeFromQueue } from '../../common'
|
|
114
115
|
|
|
115
116
|
// 组件
|
|
116
117
|
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
@@ -157,8 +158,11 @@ watch(
|
|
|
157
158
|
(newValue) => {
|
|
158
159
|
if (newValue) {
|
|
159
160
|
popover.control(placement.value, props.offset)
|
|
161
|
+
// provide/inject在微信小程序不能使用,所以执行两个保存方法
|
|
160
162
|
if (queue && queue.closeOther) {
|
|
161
163
|
queue.closeOther(proxy)
|
|
164
|
+
} else {
|
|
165
|
+
closeOther(proxy)
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
popover.showStyle.value = newValue ? 'display: inline-block;' : 'display: none;'
|
|
@@ -174,6 +178,8 @@ onMounted(() => {
|
|
|
174
178
|
onBeforeMount(() => {
|
|
175
179
|
if (queue && queue.pushToQueue) {
|
|
176
180
|
queue.pushToQueue(proxy)
|
|
181
|
+
} else {
|
|
182
|
+
pushToQueue(proxy)
|
|
177
183
|
}
|
|
178
184
|
popover.showStyle.value = showPopover.value ? 'opacity: 1;' : 'opacity: 0;'
|
|
179
185
|
})
|
|
@@ -181,6 +187,8 @@ onBeforeMount(() => {
|
|
|
181
187
|
onBeforeUnmount(() => {
|
|
182
188
|
if (queue && queue.removeFromQueue) {
|
|
183
189
|
queue.removeFromQueue(proxy)
|
|
190
|
+
} else {
|
|
191
|
+
removeFromQueue(proxy)
|
|
184
192
|
}
|
|
185
193
|
})
|
|
186
194
|
|