提交 55c2e4de 编写于 作者: Q qiang

Merge branch 'v3' of github.com:dcloudio/uni-app into v3

......@@ -12,5 +12,5 @@
"message": "chore(release): publish %s"
}
},
"version": "3.0.0-alpha-24020191018006"
"version": "3.0.0-alpha-24020191018012"
}
{
"name": "@dcloudio/uni-app-plus-nvue",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app app-plus-nvue",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-app-plus",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app app-plus",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-cli-shared",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-cli-shared",
"main": "lib/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-h5-ui",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app h5 ui",
"main": "dist/index.umd.min.js",
"repository": {
......
......@@ -261,8 +261,12 @@
]
],
"createMapContext": [
"/platforms/h5/service/api/context/map.js",
"/core/service/api/context/create-map-context.js",
[
[
"/platforms/h5/service/api/context/operate-map-player.js",
"operateMapPlayer"
],
[
"/core/helpers/protocol/context/context.js",
"createMapContext"
......@@ -314,8 +318,12 @@
]
],
"createVideoContext": [
"/platforms/h5/service/api/context/video.js",
"/core/service/api/context/create-video-context.js",
[
[
"/platforms/h5/service/api/context/operate-video-player.js",
"operateVideoPlayer"
],
[
"/core/helpers/protocol/context/context.js",
"createVideoContext"
......@@ -661,8 +669,12 @@
[]
],
"createSelectorQuery": [
"/platforms/h5/service/api/ui/create-selector-query.js",
"/core/service/api/ui/create-selector-query.js",
[
[
"/platforms/h5/service/api/ui/request-component-info.js",
"requestComponentInfo"
],
[
"/core/view/bridge/subscribe/api/request-component-info.js",
"requestComponentInfo"
......@@ -670,7 +682,7 @@
]
],
"createIntersectionObserver": [
"/platforms/h5/service/api/ui/create-intersection-observer.js",
"/core/service/api/ui/create-intersection-observer.js",
[
[
"/core/view/bridge/subscribe/api/request-component-observer.js",
......
{
"name": "@dcloudio/uni-h5",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"repository": {
......
{
"name": "@dcloudio/uni-mp-alipay",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"repository": {
......
......@@ -1499,6 +1499,8 @@ function parseBaseComponent (vueComponentOptions, {
return [componentOptions, VueComponent]
}
const newLifecycle = swan.canIUse('lifecycle-2-0');
function parseComponent (vueOptions) {
const componentOptions = parseBaseComponent(vueOptions, {
isPage,
......@@ -1513,16 +1515,27 @@ function parseComponent (vueOptions) {
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
this.pageinstance.$vm = this.$vm;
if (hasOwn(this.pageinstance, '_$args')) {
if (hasOwn(this.pageinstance, '_$args')) {
this.$vm.$mp.query = this.pageinstance._$args;
this.$vm.__call_hook('onLoad', this.pageinstance._$args);
this.$vm.__call_hook('onLoad', this.pageinstance._$args);
delete this.pageinstance._$args;
}
// TODO 目前版本 百度 Component 作为页面时,methods 中的 onShow 不触发
this.$vm.__call_hook('onShow');
// TODO 3.105.17以下基础库内百度 Component 作为页面时,methods 中的 onShow 不触发
!newLifecycle && this.$vm.__call_hook('onShow');
}
};
if (newLifecycle) {
delete componentOptions.lifetimes.ready;
componentOptions.methods.onReady = function () {
if (this.$vm) {
this.$vm._isMounted = true;
this.$vm.__call_hook('mounted');
this.$vm.__call_hook('onReady');
}
};
}
componentOptions.messages = {
'__l': componentOptions.methods['__l']
};
......
{
"name": "@dcloudio/uni-mp-baidu",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-mp-qq",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app mp-qq",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-mp-weixin",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-stat",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "",
"main": "dist/index.js",
"repository": {
......
{
"name": "@dcloudio/uni-template-compiler",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-template-compiler",
"main": "lib/index.js",
"repository": {
......
{
"name": "@dcloudio/vue-cli-plugin-hbuilderx",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "HBuilderX plugin for vue-cli 3",
"main": "index.js",
"repository": {
......
{
"name": "@dcloudio/vue-cli-plugin-uni-optimize",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app optimize plugin for vue-cli 3",
"main": "index.js",
"repository": {
......
{
"name": "@dcloudio/vue-cli-plugin-uni",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app plugin for vue-cli 3",
"main": "index.js",
"repository": {
......@@ -17,7 +17,7 @@
"author": "fxy060608",
"license": "Apache-2.0",
"dependencies": {
"@dcloudio/uni-stat": "^3.0.0-alpha-24020191018006",
"@dcloudio/uni-stat": "^3.0.0-alpha-24020191018012",
"copy-webpack-plugin": "^4.6.0",
"cross-env": "^5.2.0",
"envinfo": "^6.0.1",
......
{
"name": "@dcloudio/webpack-uni-mp-loader",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "webpack-uni-mp-loader",
"main": "index.js",
"repository": {
......
{
"name": "@dcloudio/webpack-uni-pages-loader",
"version": "3.0.0-alpha-24020191018006",
"version": "3.0.0-alpha-24020191018012",
"description": "uni-app pages.json loader",
"main": "lib/index.js",
"repository": {
......@@ -21,7 +21,7 @@
"strip-json-comments": "^2.0.1"
},
"uni-app": {
"compilerVersion": "2.3.3"
"compilerVersion": "2.3.4"
},
"gitHead": "10184426b19cb76e01c93fb25c982c72887557e8"
}
import {
invokeMethod,
getCurrentPageVm
} from '../../platform'
function operateMapPlayer (mapId, pageVm, type, data) {
invokeMethod('operateMapPlayer', mapId, pageVm, type, data)
}
class MapContext {
constructor (id, pageVm) {
this.id = id
this.pageVm = pageVm
}
getCenterLocation (args) {
operateMapPlayer(this.id, this.pageVm, 'getCenterLocation', args)
}
moveToLocation () {
operateMapPlayer(this.id, this.pageVm, 'moveToLocation')
}
translateMarker (args) {
operateMapPlayer(this.id, this.pageVm, 'translateMarker', args)
}
includePoints (args) {
operateMapPlayer(this.id, this.pageVm, 'includePoints', args)
}
getRegion (args) {
operateMapPlayer(this.id, this.pageVm, 'getRegion', args)
}
getScale (args) {
operateMapPlayer(this.id, this.pageVm, 'getScale', args)
}
}
export function createMapContext (id, context) {
if (context) {
return new MapContext(id, context)
}
return new MapContext(id, getCurrentPageVm('createMapContext'))
}
import {
invokeMethod,
getCurrentPageVm
} from '../../platform'
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5]
function operateVideoPlayer (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data)
}
class VideoContext {
constructor (id, pageVm) {
this.id = id
this.pageVm = pageVm
}
play () {
operateVideoPlayer(this.id, this.pageVm, 'play')
}
pause () {
operateVideoPlayer(this.id, this.pageVm, 'pause')
}
stop () {
operateVideoPlayer(this.id, this.pageVm, 'stop')
}
seek (position) {
operateVideoPlayer(this.id, this.pageVm, 'seek', {
position
})
}
sendDanmu (args) {
operateVideoPlayer(this.id, this.pageVm, 'sendDanmu', args)
}
playbackRate (rate) {
if (!~RATES.indexOf(rate)) {
rate = 1.0
}
operateVideoPlayer(this.id, this.pageVm, 'playbackRate', {
rate
})
}
requestFullScreen () {
operateVideoPlayer(this.id, this.pageVm, 'requestFullScreen')
}
exitFullScreen () {
operateVideoPlayer(this.id, this.pageVm, 'exitFullScreen')
}
showStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'showStatusBar')
}
hideStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'hideStatusBar')
}
}
export function createVideoContext (id, context) {
if (context) {
return new VideoContext(id, context)
}
return new VideoContext(id, getCurrentPageVm('createVideoContext'))
}
import Vue from 'vue'
import createCallbacks from 'uni-helpers/callbacks'
const createIntersectionObserverCallbacks = createCallbacks('requestComponentObserver')
const defaultOptions = {
thresholds: [0],
initialRatio: 0,
observeAll: false
}
class MPIntersectionObserver {
constructor (pageId, options) {
this.pageId = pageId
this.options = Object.assign({}, defaultOptions, options)
}
_makeRootMargin (margins = {}) {
this.options.rootMargin = ['top', 'right', 'bottom', 'left'].map(name => `${Number(margins[name]) || 0}px`).join(' ')
}
relativeTo (selector, margins) {
this.options.relativeToSelector = selector
this._makeRootMargin(margins)
return this
}
relativeToViewport (margins) {
this.options.relativeToSelector = null
this._makeRootMargin(margins)
return this
}
observe (selector, callback) {
if (typeof callback !== 'function') {
return
}
this.options.selector = selector
this.reqId = createIntersectionObserverCallbacks.push(callback)
UniServiceJSBridge.publishHandler('requestComponentObserver', {
reqId: this.reqId,
options: this.options
}, this.pageId)
}
disconnect () {
UniServiceJSBridge.publishHandler('destroyComponentObserver', {
reqId: this.reqId
}, this.pageId)
}
}
export function createIntersectionObserver (context, options) {
if (!(context instanceof Vue)) {
options = context
context = null
}
if (context) {
return new MPIntersectionObserver(context.$page.id, options)
}
const app = getApp()
if (app.$route && app.$route.params.__id__) {
return new MPIntersectionObserver(app.$route.params.__id__, options)
} else {
UniServiceJSBridge.emit('onError', 'createIntersectionObserver:fail')
}
import createCallbacks from 'uni-helpers/callbacks'
import {
getCurrentPageVm
} from '../../platform'
const createIntersectionObserverCallbacks = createCallbacks('requestComponentObserver')
const defaultOptions = {
thresholds: [0],
initialRatio: 0,
observeAll: false
}
class ServiceIntersectionObserver {
constructor (component, options) {
this.pageId = component.$page.id
this.component = component._$id || component // app-plus 平台传输_$id
this.options = Object.assign({}, defaultOptions, options)
}
_makeRootMargin (margins = {}) {
this.options.rootMargin = ['top', 'right', 'bottom', 'left'].map(name => `${Number(margins[name]) || 0}px`).join(
' ')
}
relativeTo (selector, margins) {
this.options.relativeToSelector = selector
this._makeRootMargin(margins)
return this
}
relativeToViewport (margins) {
this.options.relativeToSelector = null
this._makeRootMargin(margins)
return this
}
observe (selector, callback) {
if (typeof callback !== 'function') {
return
}
this.options.selector = selector
this.reqId = createIntersectionObserverCallbacks.push(callback)
UniServiceJSBridge.publishHandler('requestComponentObserver', {
reqId: this.reqId,
component: this.component,
options: this.options
}, this.pageId)
}
disconnect () {
UniServiceJSBridge.publishHandler('destroyComponentObserver', {
reqId: this.reqId
}, this.pageId)
}
}
export function createIntersectionObserver (context, options) {
if (!context._isVue) {
options = context
context = null
}
if (context) {
return new ServiceIntersectionObserver(context, options)
}
return new ServiceIntersectionObserver(getCurrentPageVm('createIntersectionObserver'), options)
}
......@@ -2,9 +2,10 @@ import {
isFn
} from 'uni-shared'
import createCallbacks from 'uni-helpers/callbacks'
const requestComponentInfoCallbacks = createCallbacks('requestComponentInfo')
import {
invokeMethod,
getCurrentPageVm
} from '../../platform'
class NodesRef {
constructor (selectorQuery, component, selector, single) {
......@@ -54,24 +55,15 @@ class NodesRef {
}
}
function requestComponentInfo (pageId, queue, callback) {
const reqId = requestComponentInfoCallbacks.push(callback)
UniServiceJSBridge.publishHandler('requestComponentInfo', {
reqId,
reqs: queue
}, pageId)
}
class SelectorQuery {
constructor (pageId) {
this.pageId = pageId
constructor (page) {
this._page = page
this._queue = []
this._queueCb = []
}
exec (callback) {
requestComponentInfo(this.pageId, this._queue, res => {
invokeMethod('requestComponentInfo', this._page, this._queue, res => {
const queueCbs = this._queueCb
res.forEach((result, index) => {
const queueCb = queueCbs[index]
......@@ -83,9 +75,9 @@ class SelectorQuery {
})
}
['in'] (component) {
// TODO 跨平台,非 h5 平台传递 component._$id
this._component = component
['in'] (component) {
// app-plus 平台传递 id
this._component = component._$id || component
return this
}
......@@ -114,12 +106,7 @@ class SelectorQuery {
export function createSelectorQuery (context) {
if (context) {
return new SelectorQuery(context.$page.id)
}
const app = getApp()
if (app.$route && app.$route.params.__id__) {
return new SelectorQuery(app.$route.params.__id__)
} else {
UniServiceJSBridge.emit('onError', 'createSelectorQuery:fail')
return new SelectorQuery(context)
}
return new SelectorQuery(getCurrentPageVm('createSelectorQuery'))
}
......@@ -13,4 +13,14 @@ export function invokeMethod (name, ...args) {
*/
export function onMethod (name, callback) {
return UniServiceJSBridge.on('api.' + name, callback)
}
export function getCurrentPageVm (method) {
const pages = getCurrentPages()
const len = pages.length
if (!len) {
UniServiceJSBridge.emit('onError', `${method}:fail`)
}
const page = pages[len - 1]
return page.$vm
}
......@@ -4,6 +4,10 @@ import {
import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import {
findElm
} from './util'
function getRootInfo (fields) {
const info = {}
if (fields.id) {
......@@ -74,9 +78,7 @@ function getNodeInfo (el, fields) {
}
function getNodesInfo (pageVm, component, selector, single, fields) {
/* eslint-disable no-mixed-operators */
// TODO 判断 component 是否是 _$id,如果是,从 pageVm 中递归查找该组件实例
const $el = component && component.$el || pageVm.$el
const $el = findElm(component, pageVm)
if (single) {
const node = $el && ($el.matches(selector) ? $el : $el.querySelector(selector))
if (node) {
......@@ -106,13 +108,14 @@ export function requestComponentInfo ({
}, pageId) {
const pages = getCurrentPages() // 跨平台时,View 层也应该实现该方法,举例 App 上,View 层的 getCurrentPages 返回长度为1的当前页面数组
const pageVm = pages.find(page => page.$page.id === pageId)
const page = pages.find(page => page.$page.id === pageId)
if (!pageVm) {
// TODO 是否需要 defer
if (!page) {
throw new Error(`Not Found:Page[${pageId}]`)
}
const pageVm = page.$vm
const result = []
reqs.forEach(function ({
component,
......
import 'intersection-observer'
import {
normalizeDataset
} from 'uni-helpers/index'
function getRect (rect) {
return {
bottom: rect.bottom,
height: rect.height,
left: rect.left,
right: rect.right,
top: rect.top,
width: rect.width
}
}
const intersectionObservers = {}
export function requestComponentObserver ({
reqId,
options
}, pageId) {
const pages = getCurrentPages()
const pageVm = pages.find(page => page.$page.id === pageId)
if (!pageVm) {
throw new Error(`Not Found:Page[${pageId}]`)
import 'intersection-observer'
import {
normalizeDataset
} from 'uni-helpers/index'
import {
findElm
} from './util'
function getRect (rect) {
return {
bottom: rect.bottom,
height: rect.height,
left: rect.left,
right: rect.right,
top: rect.top,
width: rect.width
}
}
const intersectionObservers = {}
export function requestComponentObserver ({
reqId,
component,
options
}, pageId) {
const pages = getCurrentPages()
const page = pages.find(page => page.$page.id === pageId)
if (!page) {
throw new Error(`Not Found:Page[${pageId}]`)
}
const $el = pageVm.$el
const root = options.relativeToSelector ? $el.querySelector(options.relativeToSelector) : null
let intersectionObserver = intersectionObservers[reqId] = new IntersectionObserver((entries, observer) => {
entries.forEach(entrie => {
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
res: {
intersectionRatio: entrie.intersectionRatio,
intersectionRect: getRect(entrie.intersectionRect),
boundingClientRect: getRect(entrie.boundingClientRect),
relativeRect: getRect(entrie.rootBounds),
time: Date.now(),
dataset: normalizeDataset(entrie.target.dataset || {}),
id: entrie.target.id
}
}, pageVm.$page.id)
})
}, {
root,
rootMargin: options.rootMargin,
threshold: options.thresholds
})
if (options.observeAll) {
intersectionObserver.USE_MUTATION_OBSERVER = true
Array.prototype.map.call($el.querySelectorAll(options.selector), el => {
intersectionObserver.observe(el)
})
} else {
intersectionObserver.USE_MUTATION_OBSERVER = false
intersectionObserver.observe($el.querySelector(options.selector))
}
}
export function destroyComponentObserver ({ reqId }) {
const intersectionObserver = intersectionObservers[reqId]
if (intersectionObserver) {
intersectionObserver.disconnect()
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
reqEnd: true
})
}
const pageVm = page.$vm
const $el = findElm(component, pageVm)
const root = options.relativeToSelector ? $el.querySelector(options.relativeToSelector) : null
let intersectionObserver = intersectionObservers[reqId] = new IntersectionObserver((entries, observer) => {
entries.forEach(entrie => {
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
res: {
intersectionRatio: entrie.intersectionRatio,
intersectionRect: getRect(entrie.intersectionRect),
boundingClientRect: getRect(entrie.boundingClientRect),
relativeRect: getRect(entrie.rootBounds),
time: Date.now(),
dataset: normalizeDataset(entrie.target.dataset || {}),
id: entrie.target.id
}
}, pageVm.$page.id)
})
}, {
root,
rootMargin: options.rootMargin,
threshold: options.thresholds
})
if (options.observeAll) {
intersectionObserver.USE_MUTATION_OBSERVER = true
Array.prototype.map.call($el.querySelectorAll(options.selector), el => {
intersectionObserver.observe(el)
})
} else {
intersectionObserver.USE_MUTATION_OBSERVER = false
intersectionObserver.observe($el.querySelector(options.selector))
}
}
export function destroyComponentObserver ({
reqId
}) {
const intersectionObserver = intersectionObservers[reqId]
if (intersectionObserver) {
intersectionObserver.disconnect()
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
reqEnd: true
})
}
}
function findVmById (id, vm) {
if (id === vm._$id) {
return vm
}
const childVms = vm.$children
const len = childVms.length
for (let i = 0; i < len; i++) {
const childVm = findVmById(id, childVms[i])
if (childVm) {
return childVm
}
}
}
export function findElm (component, pageVm) {
if (!component) {
return pageVm.$el
}
if (__PLATFORM__ === 'app-plus') {
if (typeof component === 'string') {
const componentVm = findVmById(component, pageVm)
if (!componentVm) {
throw new Error(`Not Found:Page[${pageVm.$page.id}][${component}]`)
}
return componentVm.$el
}
}
return component.$el
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
class MapContext {
constructor (id, ctx) {
this.id = id
this.ctx = ctx
}
getCenterLocation (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'getCenterLocation', cbs)
}
moveToLocation () {
return invokeVmMethodWithoutArgs(this.ctx, 'moveToLocation')
}
translateMarker (args) {
return invokeVmMethod(this.ctx, 'translateMarker', args, ['animationEnd'])
}
includePoints (args) {
return invokeVmMethod(this.ctx, 'includePoints', args)
}
getRegion (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'getRegion', cbs)
}
getScale (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'getScale', cbs)
}
}
export function createMapContext (id, vm) {
if (!vm) {
return console.warn('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)')
}
const elm = findElmById(id, vm)
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new MapContext(id, elm)
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
const METHODS = {
getCenterLocation (ctx, cbs) {
return invokeVmMethodWithoutArgs(ctx, 'getCenterLocation', cbs)
},
moveToLocation (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'moveToLocation')
},
translateMarker (ctx, args) {
return invokeVmMethod(ctx, 'translateMarker', args, ['animationEnd'])
},
includePoints (ctx, args) {
return invokeVmMethod(ctx, 'includePoints', args)
},
getRegion (ctx, cbs) {
return invokeVmMethodWithoutArgs(ctx, 'getRegion', cbs)
},
getScale (ctx, cbs) {
return invokeVmMethodWithoutArgs(ctx, 'getScale', cbs)
}
}
export function operateMapPlayer (mapId, pageVm, type, data) {
return METHODS[type](findElmById(mapId, pageVm), data)
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
const METHODS = {
play (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'play')
},
pause (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'pause')
},
seek (ctx, args) {
return invokeVmMethod(ctx, 'seek', args)
},
stop (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'stop')
},
sendDanmu (ctx, args) {
return invokeVmMethod(ctx, 'sendDanmu', args)
},
playbackRate (ctx, args) {
return invokeVmMethod(ctx, 'playbackRate', args)
},
requestFullScreen (ctx, args) {
return invokeVmMethod(ctx, 'requestFullScreen', args)
},
exitFullScreen (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'exitFullScreen')
},
showStatusBar (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'showStatusBar')
},
hideStatusBar (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'hideStatusBar')
}
}
export function operateVideoPlayer (videoId, pageVm, type, data) {
return METHODS[type](findElmById(videoId, pageVm), data)
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
class VideoContext {
constructor (id, ctx) {
this.id = id
this.ctx = ctx
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
}
export function createVideoContext (id, vm) {
if (!vm) {
return console.warn('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)')
}
const elm = findElmById(id, vm)
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new VideoContext(id, elm)
}
export * from './context/live-pusher'
export * from './context/map'
export * from './context/video'
export * from './context/operate-map-player'
export * from './context/operate-video-player'
export * from './ui/create-selector-query'
export * from './ui/request-component-info'
import {
isFn
} from 'uni-shared'
class NodesRef {
constructor (selectorQuery, component, selector, single) {
this._selectorQuery = selectorQuery
this._component = component
this._selector = selector
this._single = single
}
boundingClientRect (callback) {
this._selectorQuery._push(
this._selector,
this._component,
this._single, {
id: true,
dataset: true,
rect: true,
size: true
},
callback)
return this._selectorQuery
}
fields (fields, callback) {
this._selectorQuery._push(
this._selector,
this._component,
this._single,
fields,
callback
)
return this._selectorQuery
}
scrollOffset (callback) {
this._selectorQuery._push(
this._selector,
this._component,
this._single, {
id: true,
dataset: true,
scrollOffset: true
},
callback
)
return this._selectorQuery
}
}
function processDataset (attr) {
const dataset = {}
Object.keys(attr || {}).forEach(key => {
if (key.indexOf('data') === 0) {
let str = key.replace('data', '')
str = str.charAt(0).toLowerCase() + str.slice(1)
dataset[str] = attr[key]
}
})
return dataset
}
function findAttrs (ids, elm, result) {
let nodes = elm.children
if (!Array.isArray(nodes)) {
return false
}
for (let i = 0; i < nodes.length; i++) {
let node = nodes[i]
if (node.attr) {
let index = ids.indexOf(node.attr.id)
if (index >= 0) {
result[index] = {
id: ids[index],
ref: node.ref,
dataset: processDataset(node.attr)
}
if (ids.length === 1) {
break
}
}
}
if (node.children) {
findAttrs(ids, node, result)
}
}
}
function getSelectors (queue) {
let ids = []
for (let i = 0; i < queue.length; i++) {
const selector = queue[i].selector
if (selector.indexOf('#') === 0) {
ids.push(selector.substring(1))
}
}
return ids
}
function getComponentRectAll (dom, attrs, index, result, callback) {
const attr = attrs[index]
dom.getComponentRect(attr.ref, option => {
option.size.id = attr.id
option.size.dataset = attr.dataset
result.push(option.size)
index += 1
if (index < attrs.length) {
getComponentRectAll(dom, attrs, index, result, callback)
} else {
callback(result)
}
})
}
function requestComponentInfo (dom, component, queue, callback) {
const selectors = getSelectors(queue)
let outAttrs = new Array(selectors.length)
findAttrs(selectors, component.$el, outAttrs)
getComponentRectAll(dom, outAttrs, 0, [], (result) => {
callback(result)
})
}
class SelectorQuery {
constructor (pageId) {
this.pageId = pageId
this._queue = []
this._queueCb = []
}
exec (callback) {
if (!this._component) {
return
}
this._dom = this._component._$weex.requireModule('dom')
requestComponentInfo(this._dom, this._component, this._queue, res => {
const queueCbs = this._queueCb
res.forEach((result, index) => {
const queueCb = queueCbs[index]
if (isFn(queueCb)) {
queueCb.call(this, result)
}
})
isFn(callback) && callback.call(this, res)
})
}
['in'] (component) {
if (!component) {
return console.warn('uni.createSelectorQuery 必须传入当前 vm 对象(this)')
}
this._component = component
return this
}
select (selector) {
return new NodesRef(this, this._component, selector, true)
}
selectAll (selector) {
return new NodesRef(this, this._component, selector, false)
}
selectViewport () {
return new NodesRef(this, 0, '', true)
}
_push (selector, component, single, fields, callback) {
this._queue.push({
component,
selector,
single,
fields
})
this._queueCb.push(callback)
}
}
export function createSelectorQuery () {
return new SelectorQuery()
function parseDataset (attr) {
const dataset = {}
Object.keys(attr || {}).forEach(key => {
if (key.indexOf('data') === 0) {
let str = key.replace('data', '')
str = str.charAt(0).toLowerCase() + str.slice(1)
dataset[str] = attr[key]
}
})
return dataset
}
function findAttrs (ids, elm, result) {
let nodes = elm.children
if (!Array.isArray(nodes)) {
return false
}
for (let i = 0; i < nodes.length; i++) {
let node = nodes[i]
if (node.attr) {
let index = ids.indexOf(node.attr.id)
if (index >= 0) {
result[index] = {
id: ids[index],
ref: node.ref,
dataset: parseDataset(node.attr)
}
if (ids.length === 1) {
break
}
}
}
if (node.children) {
findAttrs(ids, node, result)
}
}
}
function getSelectors (queue) {
let ids = []
for (let i = 0; i < queue.length; i++) {
const selector = queue[i].selector
if (selector.indexOf('#') === 0) {
ids.push(selector.substring(1))
}
}
return ids
}
function getComponentRectAll (dom, attrs, index, result, callback) {
const attr = attrs[index]
dom.getComponentRect(attr.ref, option => {
option.size.id = attr.id
option.size.dataset = attr.dataset
result.push(option.size)
index += 1
if (index < attrs.length) {
getComponentRectAll(dom, attrs, index, result, callback)
} else {
callback(result)
}
})
}
export function requestComponentInfo (pageVm, queue, callback) {
// TODO 重构,逻辑不对,queue 里的每一项可能有单独的作用域查找(即 component)
const dom = pageVm._$weex.requireModule('dom')
const selectors = getSelectors(queue)
let outAttrs = new Array(selectors.length)
findAttrs(selectors, pageVm.$el, outAttrs)
getComponentRectAll(dom, outAttrs, 0, [], (result) => {
callback(result)
})
}
......@@ -46,7 +46,11 @@ export function invokeVmMethod (vm, method, args, extras) {
}
export function findElmById (id, vm) {
return findRefByElm(id, vm.$el)
const elm = findRefByElm(id, vm.$el)
if (!elm) {
return console.error('Can not find `' + id + '`')
}
return elm
}
function findRefByElm (id, elm) {
......@@ -108,4 +112,4 @@ function normalizeCallback (method, callbacks) {
isFn(complete) && complete(ret)
}
}
}
}
import {
operateMapPlayer as operateVueMapPlayer
} from 'uni-platforms/h5/service/api/context/operate-map-player'
import {
operateMapPlayer as operateNVueMapPlayer
} from 'uni-platforms/app-plus-nvue/service/api/context/operate-map-player'
export function operateMapPlayer (mapId, pageVm, type, data) {
pageVm.$page.meta.isNVue
? operateNVueMapPlayer(mapId, pageVm, type, data)
: operateVueMapPlayer(mapId, pageVm, type, data)
}
import {
operateVideoPlayer as operateVueVideoPlayer
} from 'uni-platforms/h5/service/api/context/operate-video-player'
import {
operateVideoPlayer as operateNVueVideoPlayer
} from 'uni-platforms/app-plus-nvue/service/api/context/operate-video-player'
export function operateVideoPlayer (videoId, pageVm, type, data) {
pageVm.$page.meta.isNVue
? operateNVueVideoPlayer(videoId, pageVm, type, data)
: operateVueVideoPlayer(videoId, pageVm, type, data)
}
export * from './context/audio'
export * from './context/background-audio'
export * from './context/background-audio'
export * from './context/operate-map-player'
export * from './context/operate-video-player'
export * from './device/accelerometer'
export * from './device/add-phone-contact'
......@@ -61,3 +63,5 @@ export {
from './ui/pull-down-refresh'
export * from './ui/tab-bar'
export * from './ui/request-component-info'
import {
requestComponentInfo as requestVueComponentInfo
} from 'uni-platforms/h5/service/api/ui/request-component-info'
import {
requestComponentInfo as requestNVueComponentInfo
} from 'uni-platforms/app-plus-nvue/service/api/ui/request-component-info'
export function requestComponentInfo (pageVm, queue, callback) {
pageVm.$page.meta.isNVue
? requestNVueComponentInfo(pageVm, queue, callback)
: requestVueComponentInfo(pageVm, queue, callback)
}
......@@ -19,6 +19,12 @@ export default {
initData(Vue)
initLifecycle(Vue)
Object.defineProperty(Vue.prototype, '$page', {
get () {
return this.$root.$scope.$page
}
})
const oldMount = Vue.prototype.$mount
Vue.prototype.$mount = function mount (el, hydrating) {
if (this.mpType === 'app') {
......
......@@ -7,9 +7,9 @@ export function publishHandler (eventType, args, pageIds) {
pageIds = [pageIds]
}
const evalJSCode =
`typeof UniViewJSBridge !== 'undefined' && UniViewJSBridge.subscribeHandler("${eventType}",${args})`
`typeof UniViewJSBridge !== 'undefined' && UniViewJSBridge.subscribeHandler("${eventType}",${args},__PAGE_ID__)`
pageIds.forEach(id => {
const webview = plus.webview.getWebviewById(String(id))
webview && webview.evalJS(evalJSCode)
webview && webview.evalJS(evalJSCode.replace('__PAGE_ID__', id))
})
}
......@@ -50,7 +50,8 @@ const handleData = {
},
[PAGE_CREATED]: function onPageCreated (data) {
const [pageId, pagePath] = data
new PageVueComponent({
const page = getCurrentPages()[0]
page.$vm = new PageVueComponent({
mpType: 'page',
pageId,
pagePath
......
function operateMapPlayer (mapId, pageId, type, data) {
UniServiceJSBridge.publishHandler(pageId + '-map-' + mapId, {
mapId,
type,
data
}, pageId)
}
class MapContext {
constructor (id, pageId) {
this.id = id
this.pageId = pageId
}
getCenterLocation ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageId, 'getCenterLocation', {
success,
fail,
complete
})
}
moveToLocation () {
operateMapPlayer(this.id, this.pageId, 'moveToLocation')
}
translateMarker ({
markerId,
destination,
autoRotate,
rotate,
duration,
animationEnd,
fail
}) {
operateMapPlayer(this.id, this.pageId, 'translateMarker', {
markerId,
destination,
autoRotate,
rotate,
duration,
animationEnd,
fail
})
}
includePoints ({
points,
padding
}) {
operateMapPlayer(this.id, this.pageId, 'includePoints', {
points,
padding
})
}
getRegion ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageId, 'getRegion', {
success,
fail,
complete
})
}
getScale ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageId, 'getScale', {
success,
fail,
complete
})
}
}
export function createMapContext (id, context) {
if (context) {
return new MapContext(id, context.$page.id)
}
const app = getApp()
if (app.$route && app.$route.params.__id__) {
return new MapContext(id, app.$route.params.__id__)
} else {
UniServiceJSBridge.emit('onError', 'createMapContext:fail')
}
}
export function operateMapPlayer (mapId, pageVm, type, data) {
const pageId = pageVm.$page.id
UniServiceJSBridge.publishHandler(pageId + '-map-' + mapId, {
mapId,
type,
data
}, pageId)
}
export function operateVideoPlayer (videoId, pageVm, type, data) {
const pageId = pageVm.$page.id
UniServiceJSBridge.publishHandler(pageId + '-video-' + videoId, {
videoId,
type,
data
}, pageId)
}
function operateVideoPlayer (videoId, pageId, type, data) {
UniServiceJSBridge.publishHandler(pageId + '-video-' + videoId, {
videoId,
type,
data
}, pageId)
}
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5]
class VideoContext {
constructor (id, pageId) {
this.id = id
this.pageId = pageId
}
play () {
operateVideoPlayer(this.id, this.pageId, 'play')
}
pause () {
operateVideoPlayer(this.id, this.pageId, 'pause')
}
stop () {
operateVideoPlayer(this.id, this.pageId, 'stop')
}
seek (position) {
operateVideoPlayer(this.id, this.pageId, 'seek', {
position
})
}
sendDanmu ({
text,
color
} = {}) {
operateVideoPlayer(this.id, this.pageId, 'sendDanmu', {
text,
color
})
}
playbackRate (rate) {
if (!~RATES.indexOf(rate)) {
rate = 1.0
}
operateVideoPlayer(this.id, this.pageId, 'playbackRate', {
rate
})
}
requestFullScreen () {
operateVideoPlayer(this.id, this.pageId, 'requestFullScreen')
}
exitFullScreen () {
operateVideoPlayer(this.id, this.pageId, 'exitFullScreen')
}
showStatusBar () {
operateVideoPlayer(this.id, this.pageId, 'showStatusBar')
}
hideStatusBar () {
operateVideoPlayer(this.id, this.pageId, 'hideStatusBar')
}
}
export function createVideoContext (id, context) {
if (context) {
return new VideoContext(id, context.$page.id)
}
const app = getApp()
if (app.$route && app.$route.params.__id__) {
return new VideoContext(id, app.$route.params.__id__)
} else {
UniServiceJSBridge.emit('onError', 'createVideoContext:fail')
}
}
import createCallbacks from 'uni-helpers/callbacks'
const requestComponentInfoCallbacks = createCallbacks('requestComponentInfo')
export function requestComponentInfo (pageVm, queue, callback) {
UniServiceJSBridge.publishHandler('requestComponentInfo', {
reqId: requestComponentInfoCallbacks.push(callback),
reqs: queue
}, pageVm.$page.id)
}
import {
hasOwn
} from 'uni-shared'
import {
isPage,
hasOwn
} from 'uni-shared'
import {
isPage,
initRelation
} from './util'
import parseBaseComponent from '../../../mp-weixin/runtime/wrapper/component-base-parser'
const newLifecycle = swan.canIUse('lifecycle-2-0')
export default function parseComponent (vueOptions) {
const componentOptions = parseBaseComponent(vueOptions, {
isPage,
......@@ -23,13 +25,26 @@ export default function parseComponent (vueOptions) {
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
this.pageinstance.$vm = this.$vm
if (hasOwn(this.pageinstance, '_$args')) {
if (hasOwn(this.pageinstance, '_$args')) {
this.$vm.$mp.query = this.pageinstance._$args
this.$vm.__call_hook('onLoad', this.pageinstance._$args)
this.$vm.__call_hook('onLoad', this.pageinstance._$args)
delete this.pageinstance._$args
}
// TODO 目前版本 百度 Component 作为页面时,methods 中的 onShow 不触发
this.$vm.__call_hook('onShow')
// TODO 3.105.17以下基础库内百度 Component 作为页面时,methods 中的 onShow 不触发
!newLifecycle && this.$vm.__call_hook('onShow')
}
}
if (newLifecycle) {
delete componentOptions.lifetimes.ready
componentOptions.methods.onReady = function () {
if (this.$vm) {
this.$vm._isMounted = true
this.$vm.__call_hook('mounted')
this.$vm.__call_hook('onReady')
} else {
// this.is && console.warn(this.is + ' is not attached')
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册