提交 982b3853 编写于 作者: Q qiang

fix: ImagePreview, LocationView use preventScroll

上级 0f49ca95
import { onMounted, onUnmounted } from 'vue'
let index = 0
let overflow = ''
export function preventScroll(prevent: boolean) {
let before = index
index += prevent ? 1 : -1
index = Math.max(0, index)
if (index > 0) {
if (before === 0) {
overflow = document.body.style.overflow
document.body.style.overflow = 'hidden'
}
} else {
document.body.style.overflow = overflow
overflow = ''
}
}
export function usePreventScroll() {
onMounted(() => preventScroll(true))
onUnmounted(() => preventScroll(false))
}
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
computed, computed,
} from 'vue' } from 'vue'
import { createSvgIconVNode, ICON_PATH_BACK } from '@dcloudio/uni-core' import { createSvgIconVNode, ICON_PATH_BACK } from '@dcloudio/uni-core'
import { usePreventScroll } from '../../../../helpers/usePreventScroll'
const props = { const props = {
latitude: { latitude: {
...@@ -36,6 +37,7 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -36,6 +37,7 @@ export default /*#__PURE__*/ defineComponent({
props, props,
emits: ['close'], emits: ['close'],
setup(props, { emit }) { setup(props, { emit }) {
usePreventScroll()
const mapRef: Ref<HTMLIFrameElement | null> = ref(null) const mapRef: Ref<HTMLIFrameElement | null> = ref(null)
const key = __uniConfig.qqMapKey const key = __uniConfig.qqMapKey
const referer = 'uniapp' const referer = 'uniapp'
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
nextTick, nextTick,
} from 'vue' } from 'vue'
import { Swiper, SwiperItem } from '@dcloudio/uni-components' import { Swiper, SwiperItem } from '@dcloudio/uni-components'
import { usePreventScroll } from '../../../../helpers/usePreventScroll'
import ImageView from './ImageView' import ImageView from './ImageView'
const props = { const props = {
...@@ -40,6 +41,7 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -40,6 +41,7 @@ export default /*#__PURE__*/ defineComponent({
props, props,
emits: ['close'], emits: ['close'],
setup(props, { emit }) { setup(props, { emit }) {
usePreventScroll()
const rootRef: Ref<HTMLElement | null> = ref(null) const rootRef: Ref<HTMLElement | null> = ref(null)
const indexRef = ref(getIndex(props)) const indexRef = ref(getIndex(props))
watch( watch(
...@@ -98,6 +100,7 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -98,6 +100,7 @@ export default /*#__PURE__*/ defineComponent({
> >
<Swiper <Swiper
current={indexRef.value} current={indexRef.value}
// @ts-ignore
onChange={onChange} onChange={onChange}
indicator-dots={false} indicator-dots={false}
autoplay={false} autoplay={false}
......
...@@ -71,6 +71,7 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -71,6 +71,7 @@ export default /*#__PURE__*/ defineComponent({
return ( return (
<MovableArea <MovableArea
style={viewStyle} style={viewStyle}
// @ts-ignore
onTouchstart={withWebEvent(onTouchStart)} onTouchstart={withWebEvent(onTouchStart)}
onTouchmove={withWebEvent(checkDirection)} onTouchmove={withWebEvent(checkDirection)}
onTouchend={withWebEvent(onTouchEnd)} onTouchend={withWebEvent(onTouchEnd)}
...@@ -82,6 +83,7 @@ export default /*#__PURE__*/ defineComponent({ ...@@ -82,6 +83,7 @@ export default /*#__PURE__*/ defineComponent({
scale scale
scale-min="1" scale-min="1"
scale-max="4" scale-max="4"
// @ts-ignore
onScale={onScale} onScale={onScale}
> >
<img <img
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册