提交 6e75e691 编写于 作者: Q qiang

feat: 支持 nodesRef.context

上级 517afa30
...@@ -59,8 +59,7 @@ const media = [ ...@@ -59,8 +59,7 @@ const media = [
'saveVideoToPhotosAlbum', 'saveVideoToPhotosAlbum',
'createVideoContext', 'createVideoContext',
'createCameraContext', 'createCameraContext',
'createLivePlayerContext', 'createLivePlayerContext'
'createEditorContext'
] ]
const device = [ const device = [
......
...@@ -66,8 +66,7 @@ ...@@ -66,8 +66,7 @@
"uni.saveVideoToPhotosAlbum": true, "uni.saveVideoToPhotosAlbum": true,
"uni.createVideoContext": true, "uni.createVideoContext": true,
"uni.createCameraContext": true, "uni.createCameraContext": true,
"uni.createLivePlayerContext": true, "uni.createLivePlayerContext": true
"uni.createEditorContext": true
} }
}, { }, {
"name": "device", "name": "device",
......
...@@ -258,7 +258,7 @@ var methods3 = ['setFillStyle', 'setTextAlign', 'setStrokeStyle', 'setGlobalAlph ...@@ -258,7 +258,7 @@ var methods3 = ['setFillStyle', 'setTextAlign', 'setStrokeStyle', 'setGlobalAlph
'setTextBaseline', 'setLineDash' 'setTextBaseline', 'setLineDash'
] ]
class CanvasContext { export class CanvasContext {
constructor (id, pageId) { constructor (id, pageId) {
this.id = id this.id = id
this.pageId = pageId this.pageId = pageId
......
...@@ -7,7 +7,7 @@ function operateMapPlayer (mapId, pageVm, type, data) { ...@@ -7,7 +7,7 @@ function operateMapPlayer (mapId, pageVm, type, data) {
invokeMethod('operateMapPlayer', mapId, pageVm, type, data) invokeMethod('operateMapPlayer', mapId, pageVm, type, data)
} }
class MapContext { export class MapContext {
constructor (id, pageVm) { constructor (id, pageVm) {
this.id = id this.id = id
this.pageVm = pageVm this.pageVm = pageVm
...@@ -43,4 +43,4 @@ export function createMapContext (id, context) { ...@@ -43,4 +43,4 @@ export function createMapContext (id, context) {
return new MapContext(id, context) return new MapContext(id, context)
} }
return new MapContext(id, getCurrentPageVm('createMapContext')) return new MapContext(id, getCurrentPageVm('createMapContext'))
} }
...@@ -9,7 +9,7 @@ function operateVideoPlayer (videoId, pageVm, type, data) { ...@@ -9,7 +9,7 @@ function operateVideoPlayer (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data) invokeMethod('operateVideoPlayer', videoId, pageVm, type, data)
} }
class VideoContext { export class VideoContext {
constructor (id, pageVm) { constructor (id, pageVm) {
this.id = id this.id = id
this.pageVm = pageVm this.pageVm = pageVm
...@@ -25,8 +25,8 @@ class VideoContext { ...@@ -25,8 +25,8 @@ class VideoContext {
operateVideoPlayer(this.id, this.pageVm, 'stop') operateVideoPlayer(this.id, this.pageVm, 'stop')
} }
seek (position) { seek (position) {
operateVideoPlayer(this.id, this.pageVm, 'seek', { operateVideoPlayer(this.id, this.pageVm, 'seek', {
position position
}) })
} }
sendDanmu (args) { sendDanmu (args) {
...@@ -36,8 +36,8 @@ class VideoContext { ...@@ -36,8 +36,8 @@ class VideoContext {
if (!~RATES.indexOf(rate)) { if (!~RATES.indexOf(rate)) {
rate = 1.0 rate = 1.0
} }
operateVideoPlayer(this.id, this.pageVm, 'playbackRate', { operateVideoPlayer(this.id, this.pageVm, 'playbackRate', {
rate rate
}) })
} }
requestFullScreen (args = {}) { requestFullScreen (args = {}) {
...@@ -59,4 +59,4 @@ export function createVideoContext (id, context) { ...@@ -59,4 +59,4 @@ export function createVideoContext (id, context) {
return new VideoContext(id, context) return new VideoContext(id, context)
} }
return new VideoContext(id, getCurrentPageVm('createVideoContext')) return new VideoContext(id, getCurrentPageVm('createVideoContext'))
} }
import {
getCurrentPageId
} from '../../platform'
import { import {
callback callback
} from 'uni-shared' } from 'uni-shared'
...@@ -22,7 +19,7 @@ UniServiceJSBridge.subscribe('onEditorMethodCallback', ({ ...@@ -22,7 +19,7 @@ UniServiceJSBridge.subscribe('onEditorMethodCallback', ({
const methods = ['insertDivider', 'insertImage', 'insertText', 'setContents', 'getContents', 'clear', 'removeFormat', 'undo', 'redo'] const methods = ['insertDivider', 'insertImage', 'insertText', 'setContents', 'getContents', 'clear', 'removeFormat', 'undo', 'redo']
class EditorContext { export class EditorContext {
constructor (id, pageId) { constructor (id, pageId) {
this.id = id this.id = id
this.pageId = pageId this.pageId = pageId
...@@ -45,15 +42,3 @@ methods.forEach(function (method) { ...@@ -45,15 +42,3 @@ methods.forEach(function (method) {
}) })
}) })
}) })
export function createEditorContext (id, context) {
if (context) {
return new EditorContext(id, context.$page.id)
}
const pageId = getCurrentPageId()
if (pageId) {
return new EditorContext(id, pageId)
} else {
UniServiceJSBridge.emit('onError', 'createEditorContext:fail')
}
}
...@@ -7,6 +7,26 @@ import { ...@@ -7,6 +7,26 @@ import {
getCurrentPageVm getCurrentPageVm
} from '../../platform' } from '../../platform'
import { CanvasContext } from '../context/canvas'
import { MapContext } from '../context/create-map-context'
import { VideoContext } from '../context/create-video-context'
import { EditorContext } from '../context/editor'
const ContextClasss = {
canvas: CanvasContext,
map: MapContext,
video: VideoContext,
editor: EditorContext
}
function convertContext (result) {
if (result.context) {
const { id, name, page } = result.context
const ContextClass = ContextClasss[name]
result.context = ContextClass && new ContextClass(id, page)
}
}
class NodesRef { class NodesRef {
constructor (selectorQuery, component, selector, single) { constructor (selectorQuery, component, selector, single) {
this._selectorQuery = selectorQuery this._selectorQuery = selectorQuery
...@@ -53,6 +73,18 @@ class NodesRef { ...@@ -53,6 +73,18 @@ class NodesRef {
) )
return this._selectorQuery return this._selectorQuery
} }
context (callback) {
this._selectorQuery._push(
this._selector,
this._component,
this._single, {
context: true
},
callback
)
return this._selectorQuery
}
} }
class SelectorQuery { class SelectorQuery {
...@@ -66,6 +98,11 @@ class SelectorQuery { ...@@ -66,6 +98,11 @@ class SelectorQuery {
invokeMethod('requestComponentInfo', this._page, this._queue, res => { invokeMethod('requestComponentInfo', this._page, this._queue, res => {
const queueCbs = this._queueCb const queueCbs = this._queueCb
res.forEach((result, index) => { res.forEach((result, index) => {
if (Array.isArray(result)) {
result.forEach(convertContext)
} else {
convertContext(result)
}
const queueCb = queueCbs[index] const queueCb = queueCbs[index]
if (isFn(queueCb)) { if (isFn(queueCb)) {
queueCb.call(this, result) queueCb.call(this, result)
...@@ -109,4 +146,4 @@ export function createSelectorQuery (context) { ...@@ -109,4 +146,4 @@ export function createSelectorQuery (context) {
return new SelectorQuery(context) return new SelectorQuery(context)
} }
return new SelectorQuery(getCurrentPageVm('createSelectorQuery')) return new SelectorQuery(getCurrentPageVm('createSelectorQuery'))
} }
...@@ -74,6 +74,11 @@ function getNodeInfo (el, fields) { ...@@ -74,6 +74,11 @@ function getNodeInfo (el, fields) {
info.scrollTop = 0 info.scrollTop = 0
} }
} }
if (fields.context) {
if (el.__vue__ && el.__vue__._getContextInfo) {
info.context = el.__vue__._getContextInfo()
}
}
return info return info
} }
...@@ -134,4 +139,4 @@ export function requestComponentInfo ({ ...@@ -134,4 +139,4 @@ export function requestComponentInfo ({
reqId, reqId,
res: result res: result
}, pageVm.$page.id) }, pageVm.$page.id)
} }
...@@ -19,6 +19,9 @@ export default { ...@@ -19,6 +19,9 @@ export default {
}, },
beforeDestroy () { // 销毁时移除 beforeDestroy () { // 销毁时移除
this._toggleListeners('unsubscribe', this.id) this._toggleListeners('unsubscribe', this.id)
if (this._contextId) {
this._toggleListeners('unsubscribe', this._contextId)
}
}, },
methods: { methods: {
_toggleListeners (type, id, watch) { _toggleListeners (type, id, watch) {
...@@ -31,6 +34,18 @@ export default { ...@@ -31,6 +34,18 @@ export default {
} }
// 纠正VUniVideo等组件命名为Video // 纠正VUniVideo等组件命名为Video
UniViewJSBridge[type](this.$page.id + '-' + this.$options.name.replace(/VUni([A-Z])/, '$1').toLowerCase() + '-' + id, this._handleSubscribe) UniViewJSBridge[type](this.$page.id + '-' + this.$options.name.replace(/VUni([A-Z])/, '$1').toLowerCase() + '-' + id, this._handleSubscribe)
},
_getContextInfo () {
const id = `context-${this._uid}`
if (!this._contextId) {
this._toggleListeners('subscribe', id)
this._contextId = id
}
return {
name: this.$options.name.replace(/VUni([A-Z])/, '$1').toLowerCase(),
id,
page: this.$page.id
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册