12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // import * as clipboard from 'clipboard-polyfill/text';
- import copy from 'copy-to-clipboard';
- console.log("🚀 ~ file: native.js ~ line 3 ~ copy", copy)
- 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 copy(text, {
- format: 'text/plain',
- });
- // return await clipboard.writeText(text);
- },
- },
- });
- }
|