提交 783c6325 编写于 作者: D DCloud_LXH

feat: cover 组件支持嵌套

上级 52b9e8c2
...@@ -73,53 +73,55 @@ export default { ...@@ -73,53 +73,55 @@ export default {
} }
}, },
mounted () { mounted () {
this._adId = 'AdView-' + this._newGUID() this._onParentReady(() => {
const adStyle = Object.assign({ this._adId = 'AdView-' + this._newGUID()
id: this._adId const adStyle = Object.assign({
}, this.position) id: this._adId
const adView = this.adView = plus.ad.createAdView(adStyle) }, this.position)
adView.interceptTouchEvent(false) const adView = this.adView = plus.ad.createAdView(adStyle)
plus.webview.currentWebview().append(adView) adView.interceptTouchEvent(false)
if (this.hidden) { plus.webview.currentWebview().append(adView)
adView.hide() if (this.hidden) {
} adView.hide()
this.$watch('attrs', () => { }
this._request() this.$watch('attrs', () => {
}, { this._request()
deep: true }, {
}) deep: true
this.$watch('position', () => { })
this.adView && this.adView.setStyle(this.position) this.$watch('position', () => {
}, { this.adView && this.adView.setStyle(this.position)
deep: true }, {
}) deep: true
// 模板渲染有效 })
adView.setDislikeListener && adView.setDislikeListener((data) => { // 模板渲染有效
this.adView && this.adView.close() adView.setDislikeListener && adView.setDislikeListener((data) => {
this.$refs.container.style.height = '0px' this.adView && this.adView.close()
this.$refs.container.style.height = '0px'
this._updateView()
this.$trigger('close', {}, data)
})
adView.setRenderingListener && adView.setRenderingListener((data) => {
if (data.result === 0) {
this.$refs.container.style.height = data.height + 'px'
this._updateView() this._updateView()
} else {
this.$trigger('error', {}, {
errCode: data.result
})
}
})
adView.setAdClickedListener((data) => {
this.$trigger('adclicked', {}, data)
})
this._callbackId = this.$page.id + this._adId this.$trigger('close', {}, data)
UniViewJSBridge.subscribe(this._callbackId, this._handleAdData.bind(this)) })
adView.setRenderingListener && adView.setRenderingListener((data) => {
if (data.result === 0) {
this.$refs.container.style.height = data.height + 'px'
this._updateView()
} else {
this.$trigger('error', {}, {
errCode: data.result
})
}
})
adView.setAdClickedListener((data) => {
this.$trigger('adclicked', {}, data)
})
this._callbackId = this.$page.id + this._adId
UniViewJSBridge.subscribe(this._callbackId, this._handleAdData.bind(this))
this._request() this._request()
})
}, },
beforeDestroy () { beforeDestroy () {
this.adView && this.adView.close() this.adView && this.adView.close()
......
...@@ -15,12 +15,17 @@ export default { ...@@ -15,12 +15,17 @@ export default {
render (createElement) { render (createElement) {
let coverContent = '' let coverContent = ''
const $slots = this.$slots.default || [] const $slots = this.$slots.default || []
$slots.forEach(node => { const _slots = $slots.filter(node => node.tag)
if (!node.tag) { if (!_slots.length) {
coverContent += node.text || '' $slots.forEach(node => {
} if (!node.tag) {
}) coverContent += node.text || ''
this.coverContent = coverContent }
})
this.coverContent = coverContent
} else {
coverContent = _slots
}
return createElement('uni-cover-view', { return createElement('uni-cover-view', {
on: { on: {
on: this.$listeners on: this.$listeners
...@@ -28,7 +33,7 @@ export default { ...@@ -28,7 +33,7 @@ export default {
}, [createElement('div', { }, [createElement('div', {
ref: 'container', ref: 'container',
staticClass: 'uni-cover-view' staticClass: 'uni-cover-view'
}, [coverContent])]) }, [].concat(coverContent))])
} }
} }
</script> </script>
...@@ -48,5 +53,6 @@ uni-cover-view[hidden] { ...@@ -48,5 +53,6 @@ uni-cover-view[hidden] {
uni-cover-view .uni-cover-view { uni-cover-view .uni-cover-view {
width: 100%; width: 100%;
height: 100%; height: 100%;
visibility: hidden;
} }
</style> </style>
...@@ -189,34 +189,36 @@ export default { ...@@ -189,34 +189,36 @@ export default {
} }
}, },
mounted () { mounted () {
const mapStyle = Object.assign({}, this.attrs, this.position) this._onParentReady(() => {
if (this.latitude && this.longitude) { const mapStyle = Object.assign({}, this.attrs, this.position)
mapStyle.center = new plus.maps.Point(this.longitude, this.latitude) if (this.latitude && this.longitude) {
} mapStyle.center = new plus.maps.Point(this.longitude, this.latitude)
const map = this.map = plus.maps.create(this.$page.id + '-map-' + (this.id || Date.now()), mapStyle) }
map.__markers__ = [] const map = this.map = plus.maps.create(this.$page.id + '-map-' + (this.id || Date.now()), mapStyle)
map.__markers_map__ = {} map.__markers__ = []
map.__lines__ = [] map.__markers_map__ = {}
map.__circles__ = [] map.__lines__ = []
map.setZoom(parseInt(this.scale)) map.__circles__ = []
plus.webview.currentWebview().append(map) map.setZoom(parseInt(this.scale))
if (this.hidden) { plus.webview.currentWebview().append(map)
map.hide() if (this.hidden) {
} map.hide()
this.$watch('position', () => { }
this.map && this.map.setStyles(this.position) this.$watch('position', () => {
}, { this.map && this.map.setStyles(this.position)
deep: true }, {
deep: true
})
map.onclick = (e) => {
this.$trigger('click', {}, e)
}
map.onstatuschanged = (e) => {
this.$trigger('regionchange', {}, {})
}
this._addMarkers(this.markers)
this._addMapLines(this.polyline)
this._addMapCircles(this.circles)
}) })
map.onclick = (e) => {
this.$trigger('click', {}, e)
}
map.onstatuschanged = (e) => {
this.$trigger('regionchange', {}, {})
}
this._addMarkers(this.markers)
this._addMapLines(this.polyline)
this._addMapCircles(this.circles)
}, },
beforeDestroy () { beforeDestroy () {
this.map && this.map.close() this.map && this.map.close()
......
...@@ -197,30 +197,32 @@ export default { ...@@ -197,30 +197,32 @@ export default {
} }
}, },
mounted () { mounted () {
const video = this.video = plus.video.createVideoPlayer('video' + Date.now(), Object.assign({}, this.attrs, this.position)) this._onParentReady(() => {
plus.webview.currentWebview().append(video) const video = this.video = plus.video.createVideoPlayer('video' + Date.now(), Object.assign({}, this.attrs, this.position))
if (this.hidden) { plus.webview.currentWebview().append(video)
video.hide() if (this.hidden) {
} video.hide()
this.$watch('attrs', () => {
this.video && this.video.setStyles(this.attrs)
}, { deep: true })
this.$watch('position', () => {
this.video && this.video.setStyles(this.position)
}, { deep: true })
this.$watch('hidden', (val) => {
const video = this.video
if (video) {
video[val ? 'hide' : 'show']()
// iOS 隐藏状态设置 setStyles 不生效
if (!val) {
video.setStyles(this.position)
}
} }
}) this.$watch('attrs', () => {
events.forEach(key => { this.video && this.video.setStyles(this.attrs)
video.addEventListener(key, (e) => { }, { deep: true })
this.$trigger(key, {}, { ...e.detail }) this.$watch('position', () => {
this.video && this.video.setStyles(this.position)
}, { deep: true })
this.$watch('hidden', (val) => {
const video = this.video
if (video) {
video[val ? 'hide' : 'show']()
// iOS 隐藏状态设置 setStyles 不生效
if (!val) {
video.setStyles(this.position)
}
}
})
events.forEach(key => {
video.addEventListener(key, (e) => {
this.$trigger(key, {}, { ...e.detail })
})
}) })
}) })
}, },
......
...@@ -93,15 +93,17 @@ export default { ...@@ -93,15 +93,17 @@ export default {
} }
}, },
mounted () { mounted () {
this.htmlId = WEBVIEW_ID_PREFIX + this.$page.id this._onParentReady(() => {
insertHTMLWebView({ this.htmlId = WEBVIEW_ID_PREFIX + this.$page.id
htmlId: this.htmlId insertHTMLWebView({
}) htmlId: this.htmlId
updateHTMLWebView({ })
src: this.$getRealPath(this.src), updateHTMLWebView({
webviewStyles: this.webviewStyles src: this.$getRealPath(this.src),
webviewStyles: this.webviewStyles
})
UniViewJSBridge.publishHandler(WEBVIEW_INSERTED, {}, this.$page.id)
}) })
UniViewJSBridge.publishHandler(WEBVIEW_INSERTED, {}, this.$page.id)
}, },
beforeDestroy () { beforeDestroy () {
removeHTMLWebView() removeHTMLWebView()
......
...@@ -8,7 +8,8 @@ export default { ...@@ -8,7 +8,8 @@ export default {
name: 'Cover', name: 'Cover',
data () { data () {
return { return {
style: {} style: {},
parentPosition: {}
} }
}, },
computed: { computed: {
...@@ -17,12 +18,12 @@ export default { ...@@ -17,12 +18,12 @@ export default {
for (const key in this.position) { for (const key in this.position) {
let val = this.position[key] let val = this.position[key]
const valNumber = parseFloat(val) const valNumber = parseFloat(val)
const parentValNumber = parseFloat(this._nativeParent.position[key]) const parentValNumber = parseFloat(this.parentPosition[key])
if (key === 'top' || key === 'left') { if (key === 'top' || key === 'left') {
val = Math.max(valNumber, parentValNumber) + 'px' val = Math.max(valNumber, parentValNumber) + 'px'
} else if (key === 'width' || key === 'height') { } else if (key === 'width' || key === 'height') {
const base = key === 'width' ? 'left' : 'top' const base = key === 'width' ? 'left' : 'top'
const parentStart = parseFloat(this._nativeParent.position[base]) const parentStart = parseFloat(this.parentPosition[base])
const viewStart = parseFloat(this.position[base]) const viewStart = parseFloat(this.position[base])
const diff1 = Math.max(parentStart - viewStart, 0) const diff1 = Math.max(parentStart - viewStart, 0)
const diff2 = Math.max((viewStart + valNumber) - (parentStart + parentValNumber), 0) const diff2 = Math.max((viewStart + valNumber) - (parentStart + parentValNumber), 0)
...@@ -91,16 +92,10 @@ export default { ...@@ -91,16 +92,10 @@ export default {
this._nativeParent = $parent this._nativeParent = $parent
}, },
mounted () { mounted () {
this._updateStyle() this._onParentReady((parentPosition) => {
const $nativeParent = this._nativeParent this.parentPosition = this._nativeParent.position || parentPosition
if ($nativeParent.isNative) { this._updateStyle()
if ($nativeParent._isMounted) { this._onCanInsert()
this._onCanInsert()
} else {
$nativeParent.onCanInsertCallbacks.push(() => {
this._onCanInsert()
})
}
this.$watch('hidden', (val) => { this.$watch('hidden', (val) => {
this.cover && this.cover[val ? 'hide' : 'show']() this.cover && this.cover[val ? 'hide' : 'show']()
}) })
...@@ -115,7 +110,7 @@ export default { ...@@ -115,7 +110,7 @@ export default {
} }
}, { deep: true }) }, { deep: true })
this.$on('uni-view-update', this._requestStyleUpdate) this.$on('uni-view-update', this._requestStyleUpdate)
} })
}, },
beforeDestroy () { beforeDestroy () {
if (this._nativeParent.isNative) { if (this._nativeParent.isNative) {
...@@ -139,7 +134,7 @@ export default { ...@@ -139,7 +134,7 @@ export default {
for (const key in this.position) { for (const key in this.position) {
let val = this.position[key] let val = this.position[key]
if (key === 'top' || key === 'left') { if (key === 'top' || key === 'left') {
val = Math.min((parseFloat(val) - parseFloat(this._nativeParent.position[key])), 0) + 'px' val = Math.min((parseFloat(val) - parseFloat(this.parentPosition[key])), 0) + 'px'
} }
position[key] = val position[key] = val
} }
......
...@@ -26,15 +26,23 @@ export default { ...@@ -26,15 +26,23 @@ export default {
hidden: false hidden: false
} }
}, },
provide () {
return {
parentOnDraw: this._onDraw
}
},
inject: {
parentOnDraw: { default: null }
},
created () { created () {
this.isNative = true this.isNative = true
this.onCanInsertCallbacks = [] this.onCanInsertCallbacks = []
this.onDrawCallbacks = []
}, },
mounted () { mounted () {
this._updatePosition() this._updatePosition()
this.$nextTick(() => { this.onCanInsertCallbacks.forEach(callback => callback())
this.onCanInsertCallbacks.forEach(callback => callback()) this.onCanInsertCallbacks = null
})
this.$on('uni-view-update', this._requestPositionUpdate) this.$on('uni-view-update', this._requestPositionUpdate)
}, },
methods: { methods: {
...@@ -60,6 +68,40 @@ export default { ...@@ -60,6 +68,40 @@ export default {
delete this._positionUpdateRequest delete this._positionUpdateRequest
this._updatePosition() this._updatePosition()
}) })
},
_onParentReady (parentReadyCallback) {
const callback = (parentPosition) => {
parentReadyCallback(parentPosition)
this.onDrawCallbacks.forEach(callback => callback(this.position))
this.onDrawCallbacks = null
}
this._onSelfReady(() => {
if (this.parentOnDraw) {
this.parentOnDraw(callback)
} else {
callback({
top: '0px',
left: '0px',
width: Number.MAX_SAFE_INTEGER + 'px',
height: Number.MAX_SAFE_INTEGER + 'px',
position: 'static'
})
}
})
},
_onSelfReady (callback) {
if (this.onCanInsertCallbacks) {
this.onCanInsertCallbacks.push(callback)
} else {
callback()
}
},
_onDraw (callback) {
if (this.onDrawCallbacks) {
this.onDrawCallbacks.push(callback)
} else {
callback(this.position)
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册