消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
3.1 KiB

import { MiniGameKind, MiniGamePlatform } from '../platform/MiniGamePlatform';
/**
* 分享。抖音侧主动分享走 canIUse + invokeAsync,避免鸿蒙裸调阻塞。
* @see https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/api/retweet/tt-share-app-message
* @see https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/tutorial/open-capabilities/general-capabilities/miniapp-harmony-adapter
*/
export class Share {
init(shareDataList = []) {
MiniGamePlatform.init();
const pf = MiniGamePlatform.pf;
if (!pf) return;
if (MiniGamePlatform.canIUse('onShareAppMessage') && typeof pf.onShareAppMessage === 'function') {
let title = ``;
let imageUrl = ``;
pf.onShareAppMessage(() => {
const index = Math.floor(Math.random() * shareDataList.length);
const data = shareDataList[index] ?? {};
if (data.desc) title = data.desc;
if (data.res) imageUrl = data.res;
return { title, imageUrl };
});
}
if (MiniGamePlatform.canIUse('showShareMenu')) {
MiniGamePlatform.invokeAsync('showShareMenu', {
success() {
console.log('[Share] showShareMenu ok');
},
fail(err: { errMsg?: string; errNo?: number }) {
console.log('[Share] showShareMenu fail', err?.errMsg, err?.errNo);
},
});
}
}
share(title = '', imageUrl = '', cb?, query = ``, id = null) {
MiniGamePlatform.init();
const kind = MiniGamePlatform.kind;
if (!MiniGamePlatform.canIUse('shareAppMessage')) {
console.warn('[Share] shareAppMessage unavailable');
if (MiniGamePlatform.isHarmonyOS) {
MiniGamePlatform.pf?.showToast?.({ title: '当前系统暂不支持分享', icon: 'none' });
}
cb?.(false);
return;
}
if (kind === MiniGameKind.WeChat) {
MiniGamePlatform.invokeAsync('shareAppMessage', { title, imageUrl, query });
return;
}
if (kind === MiniGameKind.Douyin) {
MiniGamePlatform.invokeAsync('shareAppMessage', {
title,
templateId: id,
imageUrl,
query,
success: () => { cb?.(true); },
fail: (e: { errNo?: number }) => {
if (e?.errNo === 10302) {
MiniGamePlatform.pf?.showToast?.({ title: '当前系统暂不支持分享', icon: 'none' });
}
cb?.(false);
},
});
return;
}
if (kind === MiniGameKind.Kuaishou || kind === MiniGameKind.Bilibili) {
MiniGamePlatform.invokeAsync('shareAppMessage', {
title,
imageUrl,
query,
success: () => { cb?.(true); },
fail: () => { cb?.(false); },
});
}
}
}