Skip to content

Commit 5801859

Browse files
feat: 横竖屏切换时height侦听事件增加 (#3284)
* feat: 横竖屏切换时height侦听事件增加 * feat: 收敛到 swiper 中修改 * feat: taro 多端 --------- Co-authored-by: hanyuxinting <[email protected]>
1 parent ec2c855 commit 5801859

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/packages/__VUE/imagepreview/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export default create({
112112
}
113113
return props.images
114114
})
115+
115116
// 设置当前选中第几个
116117
const setActive = (active: number) => {
117118
if (active !== state.active) {
@@ -126,10 +127,10 @@ export default create({
126127
done: () => closeDone()
127128
})
128129
}
130+
129131
// 执行关闭
130132
const closeDone = () => {
131133
state.showPop = false
132-
133134
emit('close')
134135
}
135136

src/packages/__VUE/swiper/index.taro.vue

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
computed,
3838
ref,
3939
watch,
40+
onMounted,
41+
onUnmounted,
4042
VNode
4143
} from 'vue'
4244
import { createComponent } from '@/packages/utils/create'
@@ -461,6 +463,33 @@ export default create({
461463
}
462464
)
463465
466+
// 横竖屏切换
467+
const width = ref(window.innerWidth)
468+
const height = ref(window.innerHeight)
469+
const updateDimensions = () => {
470+
width.value = window.innerWidth
471+
height.value = window.innerHeight
472+
}
473+
474+
// 监听 width 和 height 的变化
475+
watch([width, height], () => {
476+
Taro.nextTick(() => {
477+
init()
478+
})
479+
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
480+
init()
481+
})
482+
})
483+
484+
onMounted(() => {
485+
window.addEventListener('resize', updateDimensions)
486+
updateDimensions() // 初始化尺寸
487+
})
488+
489+
onUnmounted(() => {
490+
window.removeEventListener('resize', updateDimensions)
491+
})
492+
464493
return {
465494
state,
466495
refRandomId,

src/packages/__VUE/swiper/index.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
nextTick,
3737
ref,
3838
watch,
39+
onMounted,
40+
onUnmounted,
3941
VNode
4042
} from 'vue'
4143
import { createComponent } from '@/packages/utils/create'
@@ -442,6 +444,30 @@ export default create({
442444
}
443445
)
444446
447+
// 横竖屏切换
448+
const width = ref(window.innerWidth)
449+
const height = ref(window.innerHeight)
450+
const updateDimensions = () => {
451+
width.value = window.innerWidth
452+
height.value = window.innerHeight
453+
}
454+
455+
// 监听 width 和 height 的变化
456+
watch([width, height], () => {
457+
nextTick(() => {
458+
init()
459+
})
460+
})
461+
462+
onMounted(() => {
463+
window.addEventListener('resize', updateDimensions)
464+
updateDimensions() // 初始化尺寸
465+
})
466+
467+
onUnmounted(() => {
468+
window.removeEventListener('resize', updateDimensions)
469+
})
470+
445471
return {
446472
state,
447473
classesInner,

0 commit comments

Comments
 (0)