From 0b8a427f070c1127e5dc5b55c169cf4700dee9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E8=83=9C=E5=BC=BA?= Date: Mon, 17 Dec 2018 12:39:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0API=EF=BC=9Auni.creat?= =?UTF-8?q?eContext=E3=80=81uni.drawCanvas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/helpers/protocol/canvas.js | 15 +++++++++++++ src/core/service/api/context/canvas.js | 30 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/core/helpers/protocol/canvas.js b/src/core/helpers/protocol/canvas.js index 800157974..fb9b55611 100644 --- a/src/core/helpers/protocol/canvas.js +++ b/src/core/helpers/protocol/canvas.js @@ -92,3 +92,18 @@ export const canvasToTempFilePath = { } } } + +export const drawCanvas = { + canvasId: { + type: String, + require: true + }, + actions: { + type: Array, + require: true + }, + reserve: { + type: Boolean, + default: false + } +} diff --git a/src/core/service/api/context/canvas.js b/src/core/service/api/context/canvas.js index 5469cf8fc..1c8872e15 100644 --- a/src/core/service/api/context/canvas.js +++ b/src/core/service/api/context/canvas.js @@ -422,6 +422,16 @@ class CanvasContext { this.subpath = [this.subpath.shift()] } } + clearActions () { + this.actions = [] + this.path = [] + this.subpath = [] + } + getActions () { + var actions = [...this.actions] + this.clearActions() + return actions + } } [...methods1, ...methods2].forEach(function (method) { @@ -700,3 +710,23 @@ export function canvasToTempFilePath ({ callbackId: cId }) } + +export function createContext () { + return new CanvasContext() +} + +export function drawCanvas ({ + canvasId, + actions, + reserve +}) { + const app = getApp() + if (app.$route && app.$route.params.__id__) { + operateCanvas(canvasId, app.$route.params.__id__, 'actionsChanged', { + actions, + reserve + }) + } else { + UniServiceJSBridge.emit('onError', 'drawCanvas:fail') + } +} -- GitLab