share.uvue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('分享文本')">
  5. <cl-button @tap="shareText">{{ t("分享文本") }}</cl-button>
  6. </demo-item>
  7. <demo-item :label="t('分享图片')">
  8. <cl-button @tap="shareImage">{{ t("分享图片") }}</cl-button>
  9. </demo-item>
  10. <demo-item :label="t('分享文件')">
  11. <cl-button @tap="shareFile">{{ t("分享文件") }}</cl-button>
  12. </demo-item>
  13. <demo-item :label="t('分享链接')">
  14. <cl-button @tap="shareLink">{{ t("分享链接") }}</cl-button>
  15. </demo-item>
  16. </view>
  17. </cl-page>
  18. </template>
  19. <script lang="ts" setup>
  20. // #ifdef APP
  21. import { shareWithSystem } from "@/uni_modules/cool-share";
  22. // #endif
  23. import DemoItem from "../components/item.uvue";
  24. import { t } from "@/locale";
  25. function shareText() {
  26. // #ifdef APP
  27. shareWithSystem({
  28. type: "text",
  29. title: "Cool Unix",
  30. summary: "Cool Unix 是一个高效的项目脚手架",
  31. success: () => {
  32. console.log("success");
  33. },
  34. fail: (error) => {
  35. console.log("fail", error);
  36. }
  37. });
  38. // #endif
  39. }
  40. function shareImage() {
  41. // #ifdef APP
  42. shareWithSystem({
  43. type: "image",
  44. url: "https://cool-js.com/logo.png",
  45. success: () => {
  46. console.log("success");
  47. }
  48. });
  49. // #endif
  50. }
  51. function shareFile() {
  52. // #ifdef APP
  53. shareWithSystem({
  54. type: "file",
  55. url: "https://show.cool-admin.com/用户导入模版.xlsx",
  56. success: () => {
  57. console.log("success");
  58. }
  59. });
  60. // #endif
  61. }
  62. function shareLink() {
  63. // #ifdef APP
  64. shareWithSystem({
  65. type: "link",
  66. url: "https://cool-js.com/",
  67. success: () => {
  68. console.log("success");
  69. }
  70. });
  71. // #endif
  72. }
  73. </script>
  74. <style lang="scss" scoped></style>