t-comm
Version:
专业、稳定、纯粹的工具库
142 lines (139 loc) • 6.13 kB
JavaScript
import { loadJS } from '../../loader/loader.mjs';
import { WX_JS_SDK } from '../../wx/config.mjs';
import { configWx } from '../../wx/wx-config.mjs';
import { QQ_JS_SDK, ShareConfig, DEFAULT_API_LIST, DEFAULT_OPEN_TAG_LIST } from '../config.mjs';
import { initCommShareTip } from '../helper.mjs';
import '../../loader/little-loader.mjs';
import '../../tslib.es6-096fffdd.js';
import '../../dialog/custom-dialog.mjs';
import '../../dom/dom.mjs';
function initQQShare(_a) {
var shareObject = _a.shareObject;
initCommShareTip();
// https://open.mobile.qq.com/api/common/index
loadJS(QQ_JS_SDK).then(function () {
var _a, _b;
(_b = (_a = window === null || window === void 0 ? void 0 : window.mqq) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.setOnShareHandler(function (type) {
var _a, _b;
if ([0, 1, 2, 3, 11].indexOf(+type) > -1) {
var param = {
title: shareObject.title,
desc: shareObject.desc,
share_type: type,
share_url: shareObject.link,
image_url: shareObject.icon,
back: true,
uinType: 0
};
var callback = function callback() {
var _a;
(_a = shareObject === null || shareObject === void 0 ? void 0 : shareObject.callback) === null || _a === void 0 ? void 0 : _a.call(shareObject); // alert(result.retCode);
};
(_b = (_a = window === null || window === void 0 ? void 0 : window.mqq) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.shareMessage(param, callback);
}
});
});
}
function hideQQShareBtn() {
loadJS('QQ_JS_SDK').then(function () {
var _a, _b, _c;
(_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.mqq) === null || _a === void 0 ? void 0 : _a.ui) === null || _b === void 0 ? void 0 : _b.setWebViewBehavior) === null || _c === void 0 ? void 0 : _c.call(_b, {
actionButton: 0 // 隐藏 webview右上角按钮
});
});
}
function initWeixinShare(_a) {
var shareObject = _a.shareObject,
getWxSignaturePromise = _a.getWxSignaturePromise,
_b = _a.apiList,
apiList = _b === void 0 ? DEFAULT_API_LIST : _b,
_c = _a.openTagList,
openTagList = _c === void 0 ? DEFAULT_OPEN_TAG_LIST : _c;
initCommShareTip();
configWx({
apiList: apiList,
openTagList: openTagList,
getWxSignaturePromise: getWxSignaturePromise
}).then(function () {
var _a, _b, _c, _d;
var wx = window.wx;
// 处理分享参数
var tmp = {
title: shareObject.title,
desc: shareObject.desc,
link: shareObject.link,
imgUrl: shareObject.icon,
type: '',
dataUrl: '',
success: function success(info) {
var _a;
(_a = shareObject.callback) === null || _a === void 0 ? void 0 : _a.call(shareObject);
console.warn('success', info);
},
cancel: function cancel() {},
fail: function fail(info) {
console.warn('fail', info);
}
};
if (tmp.link.indexOf('?') === -1) {
tmp.link = "".concat(tmp.link, "?sharect=").concat(new Date().getTime());
} else if (tmp.link.indexOf('sharect') === -1) {
tmp.link = "".concat(tmp.link, "&sharect=").concat(new Date().getTime());
}
(_a = wx === null || wx === void 0 ? void 0 : wx.onMenuShareTimeline) === null || _a === void 0 ? void 0 : _a.call(wx, tmp);
(_b = wx === null || wx === void 0 ? void 0 : wx.onMenuShareAppMessage) === null || _b === void 0 ? void 0 : _b.call(wx, tmp);
(_c = wx === null || wx === void 0 ? void 0 : wx.onMenuShareQQ) === null || _c === void 0 ? void 0 : _c.call(wx, tmp);
(_d = wx === null || wx === void 0 ? void 0 : wx.onMenuShareQZone) === null || _d === void 0 ? void 0 : _d.call(wx, tmp);
// 请注意,原有的 wx.onMenuShareTimeline、wx.onMenuShareAppMessage、wx.onMenuShareQQ、wx.onMenuShareQZone 接口,
// 即将废弃。请尽快迁移使用客户端6.7.2及JSSDK 1.4.0以上版本支持的 wx.updateAppMessageShareData、wx.updateTimelineShareData接口。
// 2019.11.14 npm weixin-sdk-js还未更新到1.4.0,更新后需要改下
// wx.updateAppMessageShareData(tmp)
// wx.updateTimelineShareData(tmp)
// 文档地址 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
wx === null || wx === void 0 ? void 0 : wx.ready(function () {
var _a, _b;
(_a = wx === null || wx === void 0 ? void 0 : wx.updateAppMessageShareData) === null || _a === void 0 ? void 0 : _a.call(wx, tmp);
console.warn(tmp);
(_b = wx === null || wx === void 0 ? void 0 : wx.updateTimelineShareData) === null || _b === void 0 ? void 0 : _b.call(wx, tmp);
});
})["catch"](function (error) {
console.log('initWeixinShare error : ', error);
});
}
function hideWeixinShareBtn() {
var getWxSignaturePromise = ShareConfig.shareObject.getWxSignaturePromise;
if (!getWxSignaturePromise) return;
configWx({
apiList: ['checkJsApi', 'hideMenuItems'],
getWxSignaturePromise: getWxSignaturePromise
}).then(function () {
var _a;
var wx = window.wx;
(_a = wx === null || wx === void 0 ? void 0 : wx.ready) === null || _a === void 0 ? void 0 : _a.call(wx, function () {
wx.hideMenuItems({
menuList: ['menuItem:share:qq', 'menuItem:share:QZone', 'menuItem:share:appMessage', 'menuItem:share:timeline', 'menuItem:share:wework' // 隐藏分享企业微信
]
});
});
})["catch"](function (error) {
console.log('[hideShareBtn] error : ', error);
});
}
/**
* 设置小程序分享
* @description 设置小程序分享信息,用户需要手动点击右上角转发功能进行分享
*/
function initMiniProgramShare(_a) {
var shareObject = _a.shareObject;
initCommShareTip();
// 设置小程序分享图片和文案
loadJS(WX_JS_SDK).then(function () {
window.wx.miniProgram.postMessage({
data: {
cmd: 'share',
shareParams: shareObject
}
});
});
}
export { hideQQShareBtn, hideWeixinShareBtn, initMiniProgramShare, initQQShare, initWeixinShare };