提交 a3243aa0 编写于 作者: Q qiang

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

上级 daf93aca
import {
plusReady
} from 'uni-shared'
function hideKeyboard () {
document.activeElement.blur()
}
......@@ -34,15 +38,6 @@ export default {
this.onKeyboardHide()
},
methods: {
plusReady (callback) {
if (!callback) {
return
}
if (window.plus) {
return callback()
}
document.addEventListener('plusready', callback)
},
initKeyboard (el) {
el.addEventListener('focus', () => {
UniViewJSBridge.subscribe('hideKeyboard', hideKeyboard)
......@@ -52,12 +47,12 @@ export default {
el.addEventListener('blur', this.onKeyboardHide)
},
showSoftKeybord () {
this.plusReady(() => {
plusReady(() => {
plus.key.showSoftKeybord()
})
},
setSoftinputTemporary () {
this.plusReady(() => {
plusReady(() => {
var currentWebview = plus.webview.currentWebview()
var style = currentWebview.getStyle() || {}
if (style.softinputMode === 'adjustResize') {
......
<template>
<uni-cover-image
:src="src"
:style="imageInfo"
v-on="$listeners">
<div
ref="container"
......@@ -10,6 +11,12 @@
<script>
import native from '../../mixins/native'
import cover from '../../mixins/cover'
import {
plusReady
} from 'uni-shared'
import {
TEMP_PATH
} from '../../../service/api/constants'
export default {
name: 'CoverImage',
......@@ -18,16 +25,80 @@ export default {
src: {
type: String,
default: ''
},
autoSize: {
type: [Boolean, String],
default: false
}
},
data () {
return {
coverType: 'image'
coverType: 'image',
coverContent: '',
imageInfo: {}
}
},
computed: {
coverContent () {
return this.$getRealPath(this.src)
watch: {
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 @@
:key="index"
:src="control.iconPath"
:style="control.position"
auto-size
@click="controlclick(control)"/>
<div class="uni-map-slot">
<slot />
......
export * from './env'
export * from './util'
export * from './env'
export * from './util'
export * from './color'
export * from './query'
export * from './scroll'
export * from './platform'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册