hy-app 0.2.8 → 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 +39 -11
- 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
|
+
}
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
<!-- 使用插槽时无法获取正确宽高 -->
|
|
4
4
|
<view class="hy-popover__pos hy-popover__hidden" id="pos">
|
|
5
5
|
<view class="hy-popover__container">
|
|
6
|
-
<view v-if="mode === 'normal'" class="hy-popover__inner">
|
|
6
|
+
<view v-if="!slots.content && mode === 'normal'" class="hy-popover__inner">
|
|
7
7
|
{{ content }}
|
|
8
8
|
</view>
|
|
9
|
-
<view
|
|
9
|
+
<view
|
|
10
|
+
v-if="!slots.content && mode === 'menu' && typeof content === 'object'"
|
|
11
|
+
class="hy-popover__menu"
|
|
12
|
+
>
|
|
10
13
|
<view
|
|
11
14
|
v-for="(item, index) in content"
|
|
12
15
|
:key="index"
|
|
@@ -17,6 +20,9 @@
|
|
|
17
20
|
<text>{{ item.content }}</text>
|
|
18
21
|
</view>
|
|
19
22
|
</view>
|
|
23
|
+
|
|
24
|
+
<!-- 用户自定义样式 -->
|
|
25
|
+
<slot name="content" v-else />
|
|
20
26
|
</view>
|
|
21
27
|
</view>
|
|
22
28
|
<hy-transition
|
|
@@ -35,13 +41,13 @@
|
|
|
35
41
|
<!-- 三角形 -->
|
|
36
42
|
|
|
37
43
|
<!-- 普通模式 -->
|
|
38
|
-
<view v-if="mode === 'normal'" class="hy-popover__inner">
|
|
44
|
+
<view v-if="!slots.content && mode === 'normal'" class="hy-popover__inner">
|
|
39
45
|
{{ content }}
|
|
40
46
|
</view>
|
|
41
47
|
<!-- 普通模式 -->
|
|
42
48
|
|
|
43
49
|
<!-- 列表模式 -->
|
|
44
|
-
<view v-if="mode === 'menu'" class="hy-popover__menu">
|
|
50
|
+
<view v-if="!slots.content && mode === 'menu'" class="hy-popover__menu">
|
|
45
51
|
<view
|
|
46
52
|
v-for="(item, index) in content"
|
|
47
53
|
:key="index"
|
|
@@ -90,11 +96,22 @@ export default {
|
|
|
90
96
|
</script>
|
|
91
97
|
|
|
92
98
|
<script lang="ts" setup>
|
|
93
|
-
import {
|
|
99
|
+
import {
|
|
100
|
+
getCurrentInstance,
|
|
101
|
+
onMounted,
|
|
102
|
+
onBeforeMount,
|
|
103
|
+
onBeforeUnmount,
|
|
104
|
+
ref,
|
|
105
|
+
toRefs,
|
|
106
|
+
useSlots,
|
|
107
|
+
watch,
|
|
108
|
+
inject,
|
|
109
|
+
} from 'vue'
|
|
94
110
|
import defaultProps from './props'
|
|
95
111
|
import IProps, { type PopoverExpose } from './typing'
|
|
96
112
|
import { isArray } from '../../utils'
|
|
97
113
|
import { type Queue, queueKey, usePopover } from '../../composables'
|
|
114
|
+
import { closeOther, pushToQueue, removeFromQueue } from '../../common'
|
|
98
115
|
|
|
99
116
|
// 组件
|
|
100
117
|
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
@@ -104,6 +121,7 @@ const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
|
104
121
|
const { modelValue, content, mode, placement } = toRefs(props)
|
|
105
122
|
const emit = defineEmits(['update:modelValue', 'menuClick', 'change', 'open', 'close'])
|
|
106
123
|
|
|
124
|
+
const slots = useSlots()
|
|
107
125
|
const queue = inject<Queue | null>(queueKey, null)
|
|
108
126
|
const selector: string = 'popover'
|
|
109
127
|
const { proxy } = getCurrentInstance() as any
|
|
@@ -140,10 +158,12 @@ watch(
|
|
|
140
158
|
(newValue) => {
|
|
141
159
|
if (newValue) {
|
|
142
160
|
popover.control(placement.value, props.offset)
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
161
|
+
// provide/inject在微信小程序不能使用,所以执行两个保存方法
|
|
162
|
+
if (queue && queue.closeOther) {
|
|
163
|
+
queue.closeOther(proxy)
|
|
164
|
+
} else {
|
|
165
|
+
closeOther(proxy)
|
|
166
|
+
}
|
|
147
167
|
}
|
|
148
168
|
popover.showStyle.value = newValue ? 'display: inline-block;' : 'display: none;'
|
|
149
169
|
emit('change', { show: newValue })
|
|
@@ -156,12 +176,20 @@ onMounted(() => {
|
|
|
156
176
|
})
|
|
157
177
|
|
|
158
178
|
onBeforeMount(() => {
|
|
159
|
-
queue.pushToQueue
|
|
179
|
+
if (queue && queue.pushToQueue) {
|
|
180
|
+
queue.pushToQueue(proxy)
|
|
181
|
+
} else {
|
|
182
|
+
pushToQueue(proxy)
|
|
183
|
+
}
|
|
160
184
|
popover.showStyle.value = showPopover.value ? 'opacity: 1;' : 'opacity: 0;'
|
|
161
185
|
})
|
|
162
186
|
|
|
163
187
|
onBeforeUnmount(() => {
|
|
164
|
-
queue.removeFromQueue
|
|
188
|
+
if (queue && queue.removeFromQueue) {
|
|
189
|
+
queue.removeFromQueue(proxy)
|
|
190
|
+
} else {
|
|
191
|
+
removeFromQueue(proxy)
|
|
192
|
+
}
|
|
165
193
|
})
|
|
166
194
|
|
|
167
195
|
const menuClick = (index: number) => {
|