From 9c91f8d929d4e58cfb1db48a343e93abe6634ff8 Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Fri, 6 Mar 2020 13:17:24 +0800 Subject: [PATCH] add: shareWithSystem --- lib/apis.js | 1 + .../app-plus/service/api/plugin/share.js | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/apis.js b/lib/apis.js index 0d3ce943c..dfd43bb60 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -187,6 +187,7 @@ const third = [ 'checkSession', 'getUserInfo', 'share', + 'shareWithSystem', 'showShareMenu', 'hideShareMenu', 'requestPayment', diff --git a/src/platforms/app-plus/service/api/plugin/share.js b/src/platforms/app-plus/service/api/plugin/share.js index b40b6354b..2960ecad3 100644 --- a/src/platforms/app-plus/service/api/plugin/share.js +++ b/src/platforms/app-plus/service/api/plugin/share.js @@ -195,3 +195,36 @@ export function share (params, callbackId, method = 'share') { } ) } + +export function shareWithSystem (params, callbackId, method = 'shareWithSystem') { + let { + type, + imageUrl, + summary: content, + href + } = params + type = type || 'text' + const allowedTypes = ['text', 'image'] + if (allowedTypes.indexOf(type) < 0) { + invoke(callbackId, { + errMsg: method + ':fail:分享参数 type 不正确' + }) + } + if (typeof imageUrl === 'string' && imageUrl) { + imageUrl = getRealPath(imageUrl) + } + plus.share.sendWithSystem({ + type, + pictures: imageUrl ? [imageUrl] : [], + content, + href + }, function (res) { + invoke(callbackId, { + errMsg: method + ':ok' + }) + }, function (err) { + invoke(callbackId, { + errMsg: method + ':fail:' + err.message + }) + }) +} -- GitLab