提交 d436f272 编写于 作者: Q qiang

fix: context PageVm

上级 6809dbef
...@@ -28,7 +28,8 @@ import type { ...@@ -28,7 +28,8 @@ import type {
import { hasOwn } from '@vue/shared' import { hasOwn } from '@vue/shared'
import { import {
getCurrentPageId, getPageIdByVm,
getCurrentPageVm,
createCallbacks, createCallbacks,
ServiceJSBridge, ServiceJSBridge,
} from '@dcloudio/uni-core' } from '@dcloudio/uni-core'
...@@ -1005,9 +1006,9 @@ export const createCanvasContext = ...@@ -1005,9 +1006,9 @@ export const createCanvasContext =
API_CREATE_CANVAS_CONTEXT, API_CREATE_CANVAS_CONTEXT,
(canvasId, componentInstance): any => { (canvasId, componentInstance): any => {
if (componentInstance) { if (componentInstance) {
return new CanvasContext(canvasId, componentInstance.$page.id) return new CanvasContext(canvasId, getPageIdByVm(componentInstance)!)
} }
const pageId = getCurrentPageId() const pageId = getPageIdByVm(getCurrentPageVm()!)!
if (pageId) { if (pageId) {
return new CanvasContext(canvasId, pageId) return new CanvasContext(canvasId, pageId)
} else { } else {
...@@ -1021,7 +1022,7 @@ export const canvasGetImageData = ...@@ -1021,7 +1022,7 @@ export const canvasGetImageData =
defineAsyncApi<API_TYPE_CANVAS_GET_IMAGE_DATA>( defineAsyncApi<API_TYPE_CANVAS_GET_IMAGE_DATA>(
API_CANVAS_GET_IMAGE_DATA, API_CANVAS_GET_IMAGE_DATA,
({ canvasId, x, y, width, height }, { resolve, reject }) => { ({ canvasId, x, y, width, height }, { resolve, reject }) => {
const pageId = getCurrentPageId() const pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) { if (!pageId) {
reject() reject()
return return
...@@ -1056,7 +1057,7 @@ export const canvasPutImageData = ...@@ -1056,7 +1057,7 @@ export const canvasPutImageData =
defineAsyncApi<API_TYPE_CANVAS_PUT_IMAGE_DATA>( defineAsyncApi<API_TYPE_CANVAS_PUT_IMAGE_DATA>(
API_CANVAS_PUT_IMAGE_DATA, API_CANVAS_PUT_IMAGE_DATA,
async ({ canvasId, data, x, y, width, height }, { resolve, reject }) => { async ({ canvasId, data, x, y, width, height }, { resolve, reject }) => {
var pageId = getCurrentPageId() var pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) { if (!pageId) {
reject() reject()
return return
...@@ -1111,7 +1112,7 @@ export const canvasToTempFilePath = ...@@ -1111,7 +1112,7 @@ export const canvasToTempFilePath =
}, },
{ resolve, reject } { resolve, reject }
) => { ) => {
var pageId = getCurrentPageId() var pageId = getPageIdByVm(getCurrentPageVm()!)!
if (!pageId) { if (!pageId) {
reject() reject()
return return
......
import { ComponentPublicInstance } from 'vue' import { getPageIdByVm, getCurrentPageVm } from '@dcloudio/uni-core'
import { getCurrentPageVm } from '@dcloudio/uni-core'
import { operateMap } from '@dcloudio/uni-platform' import { operateMap } from '@dcloudio/uni-platform'
import { defineSyncApi } from '../../helpers/api' import { defineSyncApi } from '../../helpers/api'
import { import {
...@@ -8,30 +7,30 @@ import { ...@@ -8,30 +7,30 @@ import {
CreateMapContextProtocol, CreateMapContextProtocol,
} from '../../protocols/context/context' } from '../../protocols/context/context'
class MapContext implements UniApp.MapContext { export class MapContext implements UniApp.MapContext {
private id: string private id: string
private vm: ComponentPublicInstance private pageId: number
constructor(id: string, vm: ComponentPublicInstance) { constructor(id: string, pageId: number) {
this.id = id this.id = id
this.vm = vm this.pageId = pageId
} }
getCenterLocation(options: any) { getCenterLocation(options: any) {
operateMap(this.id, this.vm, 'getCenterLocation', options) operateMap(this.id, this.pageId, 'getCenterLocation', options)
} }
moveToLocation() { moveToLocation() {
operateMap(this.id, this.vm, 'moveToLocation') operateMap(this.id, this.pageId, 'moveToLocation')
} }
getScale(options: any) { getScale(options: any) {
operateMap(this.id, this.vm, 'getScale', options) operateMap(this.id, this.pageId, 'getScale', options)
} }
getRegion(options: any) { getRegion(options: any) {
operateMap(this.id, this.vm, 'getRegion', options) operateMap(this.id, this.pageId, 'getRegion', options)
} }
includePoints(options: any) { includePoints(options: any) {
operateMap(this.id, this.vm, 'includePoints', options) operateMap(this.id, this.pageId, 'includePoints', options)
} }
translateMarker(options: any) { translateMarker(options: any) {
operateMap(this.id, this.vm, 'translateMarker', options) operateMap(this.id, this.pageId, 'translateMarker', options)
} }
addCustomLayer() {} addCustomLayer() {}
removeCustomLayer() {} removeCustomLayer() {}
...@@ -50,9 +49,9 @@ export const createMapContext = <API_TYPE_CREATE_MAP_CONTEXT>defineSyncApi( ...@@ -50,9 +49,9 @@ export const createMapContext = <API_TYPE_CREATE_MAP_CONTEXT>defineSyncApi(
API_CREATE_MAP_CONTEXT, API_CREATE_MAP_CONTEXT,
(id, context) => { (id, context) => {
if (context) { if (context) {
return new MapContext(id, context) return new MapContext(id, getPageIdByVm(context)!)
} }
return new MapContext(id, getCurrentPageVm()!) return new MapContext(id, getPageIdByVm(getCurrentPageVm()!)!)
}, },
CreateMapContextProtocol CreateMapContextProtocol
) )
import { ComponentPublicInstance } from 'vue' import { getPageIdByVm, getCurrentPageVm } from '@dcloudio/uni-core'
import { getCurrentPageVm } from '@dcloudio/uni-core'
import { operateVideoPlayer } from '@dcloudio/uni-platform' import { operateVideoPlayer } from '@dcloudio/uni-platform'
import { defineSyncApi } from '../../helpers/api' import { defineSyncApi } from '../../helpers/api'
import { import {
...@@ -11,39 +10,39 @@ const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0] ...@@ -11,39 +10,39 @@ const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0]
export class VideoContext { export class VideoContext {
private id: string private id: string
private vm: ComponentPublicInstance private pageId: number
constructor(id: string, vm: ComponentPublicInstance) { constructor(id: string, pageId: number) {
this.id = id this.id = id
this.vm = vm this.pageId = pageId
} }
play() { play() {
operateVideoPlayer(this.id, this.vm, 'play') operateVideoPlayer(this.id, this.pageId, 'play')
} }
pause() { pause() {
operateVideoPlayer(this.id, this.vm, 'pause') operateVideoPlayer(this.id, this.pageId, 'pause')
} }
stop() { stop() {
operateVideoPlayer(this.id, this.vm, 'stop') operateVideoPlayer(this.id, this.pageId, 'stop')
} }
seek(position?: number) { seek(position?: number) {
operateVideoPlayer(this.id, this.vm, 'seek', { operateVideoPlayer(this.id, this.pageId, 'seek', {
position, position,
}) })
} }
sendDanmu(args: WechatMiniprogram.Danmu) { sendDanmu(args: WechatMiniprogram.Danmu) {
operateVideoPlayer(this.id, this.vm, 'sendDanmu', args) operateVideoPlayer(this.id, this.pageId, 'sendDanmu', args)
} }
playbackRate(rate: number) { playbackRate(rate: number) {
if (!~RATES.indexOf(rate)) { if (!~RATES.indexOf(rate)) {
rate = 1.0 rate = 1.0
} }
operateVideoPlayer(this.id, this.vm, 'playbackRate', { operateVideoPlayer(this.id, this.pageId, 'playbackRate', {
rate, rate,
}) })
} }
...@@ -51,19 +50,19 @@ export class VideoContext { ...@@ -51,19 +50,19 @@ export class VideoContext {
requestFullScreen( requestFullScreen(
args: WechatMiniprogram.VideoContextRequestFullScreenOption = {} args: WechatMiniprogram.VideoContextRequestFullScreenOption = {}
) { ) {
operateVideoPlayer(this.id, this.vm, 'requestFullScreen', args) operateVideoPlayer(this.id, this.pageId, 'requestFullScreen', args)
} }
exitFullScreen() { exitFullScreen() {
operateVideoPlayer(this.id, this.vm, 'exitFullScreen') operateVideoPlayer(this.id, this.pageId, 'exitFullScreen')
} }
showStatusBar() { showStatusBar() {
operateVideoPlayer(this.id, this.vm, 'showStatusBar') operateVideoPlayer(this.id, this.pageId, 'showStatusBar')
} }
hideStatusBar() { hideStatusBar() {
operateVideoPlayer(this.id, this.vm, 'hideStatusBar') operateVideoPlayer(this.id, this.pageId, 'hideStatusBar')
} }
} }
...@@ -71,8 +70,8 @@ export const createVideoContext = defineSyncApi<API_TYPE_CREATE_VIDEO_CONTEXT>( ...@@ -71,8 +70,8 @@ export const createVideoContext = defineSyncApi<API_TYPE_CREATE_VIDEO_CONTEXT>(
API_CREATE_VIDEO_CONTEXT, API_CREATE_VIDEO_CONTEXT,
(id, context) => { (id, context) => {
if (context) { if (context) {
return new VideoContext(id, context) return new VideoContext(id, getPageIdByVm(context)!)
} }
return new VideoContext(id, getCurrentPageVm()!) return new VideoContext(id, getPageIdByVm(getCurrentPageVm()!)!)
} }
) )
import { ComponentPublicInstance } from 'vue'
import { getPageIdByVm } from '@dcloudio/uni-core'
export function operateMap( export function operateMap(
id: string, id: string,
vm: ComponentPublicInstance, pageId: number,
type: string, type: string,
data?: unknown data?: unknown
) { ) {
const pageId = getPageIdByVm(vm)!
UniServiceJSBridge.publishHandler( UniServiceJSBridge.publishHandler(
'map.' + id, 'map.' + id,
{ {
......
import { ComponentPublicInstance } from 'vue'
import { getPageIdByVm } from '@dcloudio/uni-core'
export function operateVideoPlayer( export function operateVideoPlayer(
videoId: string, videoId: string,
vm: ComponentPublicInstance, pageId: number,
type: string, type: string,
data?: unknown data?: unknown
) { ) {
const pageId = getPageIdByVm(vm)!
UniServiceJSBridge.publishHandler( UniServiceJSBridge.publishHandler(
'video.' + videoId, 'video.' + videoId,
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册