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

feat: 支持 nodesRef.context

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