提交 c24cdefa 编写于 作者: D DCloud_LXH

feat(h5): previewImage add close btn and add navigation

上级 318c7a05
...@@ -46,7 +46,14 @@ const DEPS = { ...@@ -46,7 +46,14 @@ const DEPS = {
['/core/view/components/swiper-item/index.vue', 'SwiperItem'], ['/core/view/components/swiper-item/index.vue', 'SwiperItem'],
['/core/view/components/movable-area/index.vue', 'MovableArea'], ['/core/view/components/movable-area/index.vue', 'MovableArea'],
['/core/view/components/movable-view/index.vue', 'MovableView'], ['/core/view/components/movable-view/index.vue', 'MovableView'],
['/platforms/h5/components/system-routes/preview-image/index.vue', 'PreviewImage'] [
'/platforms/h5/components/app/popup/preview-image/index.vue',
'PreviewImage'
],
[
'/platforms/h5/components/app/popup/mixins/preview-image.js',
'PreviewImageMixin'
]
], ],
showToast: TOAST_DEPS, showToast: TOAST_DEPS,
hideToast: TOAST_DEPS, hideToast: TOAST_DEPS,
......
...@@ -383,8 +383,12 @@ ...@@ -383,8 +383,12 @@
"MovableView" "MovableView"
], ],
[ [
"/platforms/h5/components/system-routes/preview-image/index.vue", "/platforms/h5/components/app/popup/preview-image/index.vue",
"PreviewImage" "PreviewImage"
],
[
"/platforms/h5/components/app/popup/mixins/preview-image.js",
"PreviewImageMixin"
] ]
] ]
], ],
......
...@@ -257,32 +257,6 @@ const genSystemRoutes = function () { ...@@ -257,32 +257,6 @@ const genSystemRoutes = function () {
return [ return [
` `
{ {
path: '/preview-image',
component: {
render (createElement) {
return createElement(
'Page',
{
props:{
navigationStyle:'custom'
}
},
[
createElement('system-preview-image', {
slot: 'page'
})
]
)
}
},
meta:{
name:'preview-image',
pagePath:'/preview-image'
}
}
`,
`
{
path: '/choose-location', path: '/choose-location',
component: { component: {
render (createElement) { render (createElement) {
......
<template> <template>
<uni-app :class="{'uni-app--showtabbar':showTabBar,'uni-app--maxwidth':showMaxWidth}"> <uni-app :class="{'uni-app--showtabbar':showTabBar,'uni-app--maxwidth':showMaxWidth}">
<layout <layout
ref="layout" ref="layout"
:router-key="key" :router-key="key"
:keep-alive-include="keepAliveInclude" :keep-alive-include="keepAliveInclude"
@maxWidth="onMaxWidth" @maxWidth="onMaxWidth"
@layout="onLayout" @layout="onLayout"
/> />
<tab-bar <tab-bar
v-if="hasTabBar" v-if="hasTabBar"
v-show="showTabBar" v-show="showTabBar"
ref="tabBar" ref="tabBar"
v-bind="tabBarOptions" v-bind="tabBarOptions"
/> />
<toast <toast
v-if="$options.components.Toast" v-if="$options.components.Toast"
v-bind="showToast" v-bind="showToast"
/> />
<action-sheet <action-sheet
v-if="$options.components.ActionSheet" v-if="$options.components.ActionSheet"
v-bind="showActionSheet" v-bind="showActionSheet"
@close="_onActionSheetClose" @close="_onActionSheetClose"
/> />
<modal <modal
v-if="$options.components.Modal" v-if="$options.components.Modal"
v-bind="showModal" v-bind="showModal"
@close="_onModalClose" @close="_onModalClose"
/>
<preview-image
v-if="$options.components.PreviewImage"
v-bind="previewImage"
@close="_onPreviewClose"
/> />
<template v-if="sysComponents&&sysComponents.length"> <template v-if="sysComponents&&sysComponents.length">
<component <component
:is="item" :is="item"
v-for="(item, index) in sysComponents" v-for="(item, index) in sysComponents"
:key="index" :key="index"
/> />
</template> </template>
</uni-app> </uni-app>
...@@ -165,4 +170,4 @@ export default { ...@@ -165,4 +170,4 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>
import Toast from './toast' import Toast from './toast'
import Modal from './modal' import Modal from './modal'
import ActionSheet from './actionSheet' import ActionSheet from './actionSheet'
import PreviewImage from './preview-image'
export default { export default {
Toast, Toast,
Modal, Modal,
ActionSheet ActionSheet,
PreviewImage
} }
import {
isFn
} from 'uni-shared'
export default {
data () {
return {
previewImage: {
visible: false
}
}
},
created () {
UniServiceJSBridge.on('onShowPreviewImage', (args, callback) => {
this.previewImage = Object.assign({}, args, { visible: true })
isFn(callback) && this.$nextTick(callback)
})
UniServiceJSBridge.on('onClosePreviewImage', (callback) => {
this._onPreviewClose()
isFn(callback) && this.$nextTick(callback)
})
UniServiceJSBridge.on('onHidePopup', _ => {
this.previewImage.visible = false
})
},
methods: {
// 处理 preview-image close 回调
_onPreviewClose (res) {
this.previewImage.visible = false
}
}
}
<template> <template>
<div <div
class="uni-system-preview-image" v-if="visible"
@click="_click" class="uni-system-preview-image"
> @click="_click"
<v-uni-swiper >
:current.sync="index" <v-uni-swiper
:indicator-dots="false" navigation="auto"
:autoplay="false" :current.sync="index"
class="uni-system-preview-image-swiper" :indicator-dots="false"
> :autoplay="false"
<v-uni-swiper-item class="uni-system-preview-image-swiper"
v-for="(src,key) in urls" >
:key="key" <v-uni-swiper-item
> v-for="(src, key) in urls"
<image-view :src="src" /> :key="key"
</v-uni-swiper-item> >
</v-uni-swiper> <image-view :src="src" />
</div> </v-uni-swiper-item>
</template> </v-uni-swiper>
<script> <div class="nav-btn-back">
import imageView from './image-view' <i class="uni-btn-icon">&#xe650;</i>
</div>
export default { </div>
name: 'SystemPreviewImage', </template>
components: {
imageView <script>
}, import imageView from './image-view'
data () {
const { export default {
urls, name: 'PreviewImage',
current components: {
} = this.$route.params imageView
return { },
urls: urls || [], props: {
current, visible: {
index: 0 type: Boolean,
} default: false
}, },
created () { urls: {
const index = typeof this.current === 'number' ? this.current : this.urls.indexOf(this.current) type: Array,
this.index = index < 0 ? 0 : index default: () => []
}, },
mounted () { current: {
const MAX_MOVE = 20 type: [String, Number],
let x = 0 default: 0
let y = 0 }
this.$el.addEventListener('mousedown', (event) => { },
this.preventDefault = false data () {
x = event.clientX return {
y = event.clientY index: 0
}) }
this.$el.addEventListener('mouseup', (event) => { },
if (Math.abs(event.clientX - x) > MAX_MOVE || Math.abs(event.clientY - y) > MAX_MOVE) { watch: {
this.preventDefault = true visible (val) {
} if (val) {
}) const index =
}, typeof this.current === 'number'
methods: { ? this.current
_click () { : this.urls.indexOf(this.current)
if (!this.preventDefault) { this.index = index < 0 ? 0 : index
getApp().$router.back() }
} }
} },
} mounted () {
} const MAX_MOVE = 20
</script> let x = 0
<style> let y = 0
.uni-system-preview-image { this.$el.addEventListener('mousedown', event => {
display: block; this.preventDefault = false
position: fixed; x = event.clientX
left: 0; y = event.clientY
top: 0; })
width: 100%; this.$el.addEventListener('mouseup', event => {
if (
Math.abs(event.clientX - x) > MAX_MOVE ||
Math.abs(event.clientY - y) > MAX_MOVE
) {
this.preventDefault = true
}
})
},
methods: {
_click () {
if (!this.preventDefault) {
this.$emit('close')
}
}
}
}
</script>
<style>
.uni-system-preview-image {
display: block;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%; height: 100%;
z-index: 999; z-index: 999;
background: rgba(0,0,0,0.8); background: rgba(0, 0, 0, 0.8);
} }
.uni-system-preview-image-swiper { .uni-system-preview-image-swiper {
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> .uni-system-preview-image .nav-btn-back {
position: absolute;
box-sizing: border-box;
top: 0;
left: 0;
width: 44px;
height: 44px;
padding: 6px;
line-height: 32px;
font-size: 26px;
color: white;
text-align: center;
cursor: pointer;
}
</style>
import ChooseLocation from './choose-location' import ChooseLocation from './choose-location'
import OpenLocation from './open-location' import OpenLocation from './open-location'
import PreviewImage from './preview-image'
export default { export default {
ChooseLocation, ChooseLocation,
OpenLocation, OpenLocation
PreviewImage }
}
const { const {
emit,
invokeCallbackHandler: invoke invokeCallbackHandler: invoke
} = UniServiceJSBridge } = UniServiceJSBridge
export function previewImage ({ export function previewImage (args, callbackId) {
urls, emit('onShowPreviewImage', args, function (res) {
current
}, callbackId) {
getApp().$router.push({
type: 'navigateTo',
path: '/preview-image',
params: {
urls,
current
}
}, function () {
invoke(callbackId, { invoke(callbackId, {
errMsg: 'previewImage:ok' errMsg: 'previewImage:ok'
}) })
}, function () {
invoke(callbackId, {
errMsg: 'previewImage:fail'
})
}) })
} }
export function closePreviewImage (_, callbackId) { export function closePreviewImage (_, callbackId) {
const $router = getApp().$router emit('onClosePreviewImage', function () {
if ($router.history.current.path === '/preview-image') {
$router.back()
invoke(callbackId, { invoke(callbackId, {
errMsg: 'closePreviewImage:ok' errMsg: 'closePreviewImage:ok'
}) })
} else { })
invoke(callbackId, {
errMsg: 'closePreviewImage:fail'
})
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册