1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import * as clipboard from 'clipboard-polyfill/text';
- export default function ({ $userAgent, $wx }, i) {
- // const before = () => {
- // if ($userAgent.isApp) {
- // return;
- // }
- // // else if ($userAgent.isMiniProgram) {
- // // throw new Error('小程序环境不支持');
- // // }
- // throw new Error('非App环境');
- // };
- i('native', {
- async share({ title, desc, link, imgUrl }) {
- // before();
- if ($userAgent.isSzx) {
- if ($userAgent.isIos) {
- await window.webkit.messageHandlers.share.postMessage({
- title,
- content: desc,
- gotoUrl: link,
- shareImg: imgUrl,
- });
- return;
- }
- if ($userAgent.isAndroid) {
- await window.native.share(title, desc, link, imgUrl);
- return;
- }
- return;
- }
- if ($userAgent.isSzxBrowser) {
- await this.setShareInfo({ title, desc, link, imgUrl });
- await window.webkit.messageHandlers.openShare.postMessage({});
- }
- },
- async setShareInfo({ title, desc, link, imgUrl, path }) {
- if ($userAgent.isSzxBrowser) {
- // before();
- await window.webkit.messageHandlers.setShareInfo.postMessage({
- title,
- // content,
- gotoUrl: link,
- shareImg: imgUrl,
- });
- return;
- }
- if ($userAgent.isMiniProgram) {
- await $wx?.miniProgram?.postMessage({
- data: {
- action: 'updateAppMessageShareData',
- params: {
- title,
- path,
- imageUrl: imgUrl,
- },
- },
- });
- }
- // if ($userAgent.isIos) {
- // } else {
- // window.native.setShareUrl(url);
- // }
- },
- clipboard: {
- /**
- *
- * @param {string} text
- * @returns {Promise<any>}
- */
- async writeText(text) {
- if ($userAgent.isSzx && $userAgent.isAndroid) {
- return await window.native.copyToClipboard(text);
- }
- return await clipboard.writeText(text);
- },
- },
- });
- }
|