提交 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) {
......
...@@ -27,6 +27,11 @@ ...@@ -27,6 +27,11 @@
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"
......
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
v-if="visible"
class="uni-system-preview-image" class="uni-system-preview-image"
@click="_click" @click="_click"
> >
<v-uni-swiper <v-uni-swiper
navigation="auto"
:current.sync="index" :current.sync="index"
:indicator-dots="false" :indicator-dots="false"
:autoplay="false" :autoplay="false"
class="uni-system-preview-image-swiper" class="uni-system-preview-image-swiper"
> >
<v-uni-swiper-item <v-uni-swiper-item
v-for="(src,key) in urls" v-for="(src, key) in urls"
:key="key" :key="key"
> >
<image-view :src="src" /> <image-view :src="src" />
</v-uni-swiper-item> </v-uni-swiper-item>
</v-uni-swiper> </v-uni-swiper>
<div class="nav-btn-back">
<i class="uni-btn-icon">&#xe650;</i>
</div>
</div> </div>
</template> </template>
...@@ -23,36 +29,54 @@ ...@@ -23,36 +29,54 @@
import imageView from './image-view' import imageView from './image-view'
export default { export default {
name: 'SystemPreviewImage', name: 'PreviewImage',
components: { components: {
imageView imageView
}, },
props: {
visible: {
type: Boolean,
default: false
},
urls: {
type: Array,
default: () => []
},
current: {
type: [String, Number],
default: 0
}
},
data () { data () {
const {
urls,
current
} = this.$route.params
return { return {
urls: urls || [],
current,
index: 0 index: 0
} }
}, },
created () { watch: {
const index = typeof this.current === 'number' ? this.current : this.urls.indexOf(this.current) visible (val) {
if (val) {
const index =
typeof this.current === 'number'
? this.current
: this.urls.indexOf(this.current)
this.index = index < 0 ? 0 : index this.index = index < 0 ? 0 : index
}
}
}, },
mounted () { mounted () {
const MAX_MOVE = 20 const MAX_MOVE = 20
let x = 0 let x = 0
let y = 0 let y = 0
this.$el.addEventListener('mousedown', (event) => { this.$el.addEventListener('mousedown', event => {
this.preventDefault = false this.preventDefault = false
x = event.clientX x = event.clientX
y = event.clientY y = event.clientY
}) })
this.$el.addEventListener('mouseup', (event) => { this.$el.addEventListener('mouseup', event => {
if (Math.abs(event.clientX - x) > MAX_MOVE || Math.abs(event.clientY - y) > MAX_MOVE) { if (
Math.abs(event.clientX - x) > MAX_MOVE ||
Math.abs(event.clientY - y) > MAX_MOVE
) {
this.preventDefault = true this.preventDefault = true
} }
}) })
...@@ -60,7 +84,7 @@ export default { ...@@ -60,7 +84,7 @@ export default {
methods: { methods: {
_click () { _click () {
if (!this.preventDefault) { if (!this.preventDefault) {
getApp().$router.back() this.$emit('close')
} }
} }
} }
...@@ -75,7 +99,7 @@ export default { ...@@ -75,7 +99,7 @@ export default {
width: 100%; 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;
...@@ -84,4 +108,18 @@ export default { ...@@ -84,4 +108,18 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.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> </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.
先完成此消息的编辑!
想要评论请 注册