nuxt3网站文章分享微信 ,QQ功能

打印 上一主题 下一主题

主题 971|帖子 971|积分 2913

1.安装
npm install qrcode --save-dev
2.组件利用
  1.   
  2.           <div class="share">
  3.             <div style="line-height: 69px; color: #fff;width: 100px;">
  4.               <p style="text-align: center;">分享:</p>
  5.             </div>
  6.             <div @click="shareToMicroblog()" class="BJ_WB">
  7.               <a class="weibo" />
  8.               <a>微博</a>
  9.             </div>
  10.             <!-- <div @click="shareToQQ()" class="BJ_QQ">
  11.                 <a class="qq"></a>
  12.                 <a>QQ好友</a>
  13.               </div> -->
  14.             <div
  15.               class="BJ_WX"
  16.               @mouseover="showQR = true"
  17.               @mouseleave="showQR = false"
  18.             >
  19.               <div class="weixinall">
  20.                 <a class="weixin" />
  21.                 <a>微信</a>
  22.               </div>
  23.               <div
  24.                 class="weixincode"
  25.                 :class="{ 'qrcode-visible': showQR }"
  26.                 style="
  27.                   position: absolute;
  28.                   top: -220px;
  29.                   opacity: 0;
  30.                   transition: opacity 0.3s ease;
  31.                   width: 200px;
  32.                   height: 200px;
  33.                   background-color: #fff;
  34.                 "
  35.               >
  36.                 <canvas
  37.                   id="QRCode_header"
  38.                   style="width: 165px; height: 165px; margin: auto"
  39.                 />
  40.                 <p
  41.                   style="
  42.                     color: #818181;
  43.                     font-size: 12px;
  44.                     line-height: 16px;
  45.                     margin-left: 15px;
  46.                   "
  47.                 >
  48.                   打开微信扫一扫<br />将您喜欢的内容分享微信朋友圈
  49.                 </p>
  50.               </div>
  51.             </div>
  52.             <div class="BJ" @click="shareToQQRom()">
  53.               <a class="qqkj"></a>
  54.               <a>QQ</a>
  55.             </div>
  56.           </div>
复制代码
  1. <script setup lang="ts">
  2. import QRCode from "qrcode";
  3. const route = useRoute();
  4. const id = ref(route.params.id);
  5. const showQR = ref(false);
  6. const shareUrl = `https://XXXXXXX.COM/XXXXXXXXXX/${id.value}`;
  7. //分享到QQ
  8. // const shareToQQ= function() {
  9. //   window.open(
  10. //       `https://connect.qq.com/widget/shareqq/index.html?url=${shareUrl}&title=${sysInfo}&source=${shareUrl}&desc=${sysInfo}&pics=`)
  11. // }
  12. //分享到微信
  13. onMounted(() => {
  14.   const QR_OPTIONS = {
  15.     errorCorrectionLevel: "H",
  16.     width: 165,
  17.     height: 165,
  18.     margin: 3,
  19.     color: {
  20.       dark: "#000",
  21.       light: "#fff",
  22.     },
  23.    
  24.   };
  25.   QRCode.toCanvas(
  26.     document.querySelector("#QRCode_header"),
  27.     shareUrl,
  28.     QR_OPTIONS,
  29.     (error: any) => {
  30.       if (error) console.error("二维码生成失败:", error);
  31.     }
  32.   );
  33. });
  34. //分享到微博
  35. const shareToMicroblog = function () {
  36.   window.open(
  37.     `https://service.weibo.com/share/share.php?url=${shareUrl}&title=${details.value.productBackground}`
  38.   );
  39. };
  40. //分享到qq空间
  41. const shareToQQRom = function () {
  42.   const pics = encodeURIComponent(details.value.productBackgroundImage);
  43.   const desc = encodeURIComponent(details.value.productBackground);
  44.   window.open(
  45.     `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${shareUrl}&title=${details.value.productBackground}&summary=${details.value.productBackground}&desc=${desc}&pics=${pics}`
  46.   );
  47. };
  48. </script>
复制代码
  1. <style scoped lang="scss">
  2. .share {
  3.   display: flex;
  4.   flex-wrap: nowrap;
  5.   width: 100%;
  6.   justify-content: center;
  7.   .weibo {
  8.     display: block;
  9.     width: 24px;
  10.     height: 21px;
  11.     background-image: url("/assets/img/wb.png") !important;
  12.     background-size: cover;
  13.     background-repeat: no-repeat;
  14.     background-position: 50% 50%;
  15.   }
  16.   .BJ_WB {
  17.     background-color: #e6162d;
  18.     width: 110px;
  19.     height: 40px;
  20.     margin-top: 15px;
  21.     margin-right: 15px;
  22.     display: flex;
  23.     border-radius: 8px;
  24.     justify-content: center;
  25.     align-items: center;
  26.     color: #fff;
  27.     cursor: pointer;
  28.     &:hover {
  29.       background-color: #f75567;
  30.       transform: translateY(-2px);
  31.     }
  32.   }
  33.   .BJ_QQ {
  34.     background-color: #2384cc;
  35.     width: 110px;
  36.     height: 40px;
  37.     margin-top: 15px;
  38.     margin-right: 15px;
  39.     display: flex;
  40.     border-radius: 8px;
  41.     justify-content: center;
  42.     align-items: center;
  43.     color: #fff;
  44.     cursor: pointer;
  45.     &:hover {
  46.       background-color: #5faae2;
  47.       transform: translateY(-2px);
  48.     }
  49.   }
  50.   .BJ_WX {
  51.     background-color: #3cb034;
  52.     width: 110px;
  53.     height: 40px;
  54.     margin-top: 15px;
  55.     border-radius: 8px;
  56.     /* position: relative; */
  57.     display: flex;
  58.     justify-content: center;
  59.     align-items: center;
  60.     transition: transform 0.2s;
  61.     color: #fff;
  62.     cursor: pointer;
  63.     &:hover {
  64.       background-color: #7dd377;
  65.       transform: translateY(-2px);
  66.     }
  67.   }
  68.   .BJ {
  69.     background-color: rgb(255, 206, 0);
  70.     width: 110px;
  71.     height: 40px;
  72.     display: flex;
  73.     border-radius: 8px;
  74.     justify-content: center;
  75.     align-items: center;
  76.     color: #fff;
  77.     margin: 15px;
  78.     cursor: pointer;
  79.     &:hover {
  80.       background-color: #ffde52;
  81.       transform: translateY(-2px);
  82.     }
  83.   }
  84.   .qq {
  85.     display: block;
  86.     width: 28px;
  87.     height: 28px;
  88.     background-image: url("/assets/img/qq.png");
  89.     background-size: cover;
  90.     background-repeat: no-repeat;
  91.     background-position: 50% 50%;
  92.   }
  93.   .qqkj {
  94.     display: block;
  95.     width: 28px;
  96.     height: 28px;
  97.     background-image: url("/assets/img/qqkj.png");
  98.     background-size: cover;
  99.     background-repeat: no-repeat;
  100.     background-position: 50% 50%;
  101.   }
  102.   .weixinall {
  103.     position: relative;
  104.     display: flex;
  105.     justify-content: center;
  106.     .weixin {
  107.       display: block;
  108.       width: 28px;
  109.       height: 28px;
  110.       background-image: url("/assets/img/wx.png");
  111.       background-size: cover;
  112.       background-repeat: no-repeat;
  113.       background-position: 50% 50%;
  114.     }
  115.     .weixincode {
  116.       position: absolute;
  117.       left: -60px;
  118.       z-index: 1000 !important;
  119.     }
  120.   }
  121. }
  122. .qrcode-visible {
  123.   opacity: 1 !important;
  124.   pointer-events: auto;
  125. }
  126. </style>
复制代码
效果





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

老婆出轨

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表