提交 d436f272 编写于 作者: Q qiang

fix: context PageVm

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