forked from wangziqi/gongxue-base
feat: establish production SaaS foundation
This commit is contained in:
21
apps/taro/src/capabilities/share.ts
Normal file
21
apps/taro/src/capabilities/share.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import Taro from '@tarojs/taro';
|
||||
import { isH5Runtime } from '@/env';
|
||||
|
||||
export async function copyText(content: string) {
|
||||
await Taro.setClipboardData({ data: content });
|
||||
}
|
||||
|
||||
export async function shareText(input: { title: string; text?: string; url?: string }) {
|
||||
if (isH5Runtime() && typeof navigator !== 'undefined' && typeof navigator.share === 'function') {
|
||||
await navigator.share({ title: input.title, text: input.text, url: input.url });
|
||||
return 'shared' as const;
|
||||
}
|
||||
await copyText([input.title, input.text, input.url].filter(Boolean).join('\n'));
|
||||
return 'copied' as const;
|
||||
}
|
||||
|
||||
export async function enableNativeShareMenu() {
|
||||
if (typeof Taro.showShareMenu !== 'function') return false;
|
||||
await Taro.showShareMenu({ withShareTicket: true });
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user