提交 a3243aa0 编写于 作者: Q qiang

fix: v3-app cover-image 组件支持事件:load、error

上级 daf93aca
import {
plusReady
} from 'uni-shared'
function hideKeyboard () { function hideKeyboard () {
document.activeElement.blur() document.activeElement.blur()
} }
...@@ -34,15 +38,6 @@ export default { ...@@ -34,15 +38,6 @@ export default {
this.onKeyboardHide() this.onKeyboardHide()
}, },
methods: { methods: {
plusReady (callback) {
if (!callback) {
return
}
if (window.plus) {
return callback()
}
document.addEventListener('plusready', callback)
},
initKeyboard (el) { initKeyboard (el) {
el.addEventListener('focus', () => { el.addEventListener('focus', () => {
UniViewJSBridge.subscribe('hideKeyboard', hideKeyboard) UniViewJSBridge.subscribe('hideKeyboard', hideKeyboard)
...@@ -52,12 +47,12 @@ export default { ...@@ -52,12 +47,12 @@ export default {
el.addEventListener('blur', this.onKeyboardHide) el.addEventListener('blur', this.onKeyboardHide)
}, },
showSoftKeybord () { showSoftKeybord () {
this.plusReady(() => { plusReady(() => {
plus.key.showSoftKeybord() plus.key.showSoftKeybord()
}) })
}, },
setSoftinputTemporary () { setSoftinputTemporary () {
this.plusReady(() => { plusReady(() => {
var currentWebview = plus.webview.currentWebview() var currentWebview = plus.webview.currentWebview()
var style = currentWebview.getStyle() || {} var style = currentWebview.getStyle() || {}
if (style.softinputMode === 'adjustResize') { if (style.softinputMode === 'adjustResize') {
......
<template> <template>
<uni-cover-image <uni-cover-image
:src="src" :src="src"
:style="imageInfo"
v-on="$listeners"> v-on="$listeners">
<div <div
ref="container" ref="container"
...@@ -10,6 +11,12 @@ ...@@ -10,6 +11,12 @@
<script> <script>
import native from '../../mixins/native' import native from '../../mixins/native'
import cover from '../../mixins/cover' import cover from '../../mixins/cover'
import {
plusReady
} from 'uni-shared'
import {
TEMP_PATH
} from '../../../service/api/constants'
export default { export default {
name: 'CoverImage', name: 'CoverImage',
...@@ -18,16 +25,80 @@ export default { ...@@ -18,16 +25,80 @@ export default {
src: { src: {
type: String, type: String,
default: '' default: ''
},
autoSize: {
type: [Boolean, String],
default: false
} }
}, },
data () { data () {
return { return {
coverType: 'image' coverType: 'image',
coverContent: '',
imageInfo: {}
} }
}, },
computed: { watch: {
coverContent () { src () {
return this.$getRealPath(this.src) this.loadImage()
}
},
created () {
this.loadImage()
},
beforeDestroy () {
const downloaTask = this.downloaTask
if (downloaTask && downloaTask.state < 4) {
downloaTask.abort()
}
},
methods: {
loadImage () {
this.coverContent = ''
this.imageInfo = this.autoSize ? { width: 0, height: 0 } : {}
const realPath = this.src ? this.$getRealPath(this.src) : ''
if (realPath.indexOf('http://') === 0 || realPath.indexOf('https://') === 0) {
plusReady(() => {
this.downloaTask = plus.downloader.createDownload(realPath, {
filename: TEMP_PATH + '/download/'
}, (task, status) => {
if (status === 200) {
this.getImageInfo(task.filename)
} else {
this.$trigger('error', {}, {
errMsg: 'error'
})
}
}).start()
})
} else if (realPath) {
this.getImageInfo(realPath)
}
},
getImageInfo (src) {
this.coverContent = src
plusReady(() => {
plus.io.getImageInfo({
src,
success: ({ width, height }) => {
if (this.autoSize) {
this.imageInfo = {
width: `${width}px`,
height: `${height}px`
}
if (this._isMounted) {
this._requestPositionUpdate()
}
}
this.$trigger('load', {}, { width, height })
},
fail: () => {
this.$trigger('error', {}, {
errMsg: 'error'
})
}
})
})
} }
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
:key="index" :key="index"
:src="control.iconPath" :src="control.iconPath"
:style="control.position" :style="control.position"
auto-size
@click="controlclick(control)"/> @click="controlclick(control)"/>
<div class="uni-map-slot"> <div class="uni-map-slot">
<slot /> <slot />
......
export * from './env' export * from './env'
export * from './util' export * from './util'
export * from './color' export * from './color'
export * from './query' export * from './query'
export * from './scroll' export * from './scroll'
export * from './platform'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册