share.uvue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. import { shareWithSystem } from "@/uni_modules/cool-share";
  21. import DemoItem from "../components/item.uvue";
  22. import { t } from "@/locale";
  23. function shareText() {
  24. shareWithSystem({
  25. type: "text",
  26. title: "Cool Unix 是一个高效的项目脚手架",
  27. summary: "Cool Unix 是一个高效的项目脚手架",
  28. success: () => {
  29. console.log("success");
  30. },
  31. fail: (error) => {
  32. console.log("fail", error);
  33. }
  34. });
  35. }
  36. function shareImage() {
  37. shareWithSystem({
  38. type: "image",
  39. url: "https://cool-js.com/logo.png",
  40. success: () => {
  41. console.log("success");
  42. }
  43. });
  44. }
  45. function shareFile() {
  46. shareWithSystem({
  47. type: "file",
  48. url: "https://show.cool-admin.com/用户导入模版.xlsx",
  49. success: () => {
  50. console.log("success");
  51. }
  52. });
  53. }
  54. function shareLink() {
  55. shareWithSystem({
  56. type: "link",
  57. url: "https://cool-js.com/",
  58. success: () => {
  59. console.log("success");
  60. }
  61. });
  62. }
  63. </script>
  64. <style lang="scss" scoped></style>