You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
6.9 KiB

  1. <template>
  2. <view class="all">
  3. <!-- 背景图部分 -->
  4. <image class="img-share" src="/static/my/shareBackground.png"/>
  5. <image class="img-greenBack" src="/static/my/greenBackground.png"/>
  6. <!-- todo 这里给我个码-->
  7. <image class="img-QRcode" src="/static/my/QRcode.png"/>
  8. <image class="img-award" src="/static/my/award.png"/>
  9. <image class="img-myFriends" src="/static/my/myFriends.png"/>
  10. <image class="img-friends" src="/static/my/shareFriends.png"/>
  11. <!-- dccode -->
  12. <text class="jwcode">{{ dccode }}</text>
  13. <!-- 邀请按钮 -->
  14. <button class="invite" @click="openShare">立即邀请</button>
  15. <!-- 分享弹窗 -->
  16. <uni-popup ref="shareRef" type="share" safeArea>
  17. <SharePopup @select="onShareSelect" @close="closeShare" title=" "/>
  18. </uni-popup>
  19. <!-- 二次弹窗 -->
  20. <uni-popup ref="secondPopup" type="share">
  21. <view class="second-popup">
  22. <view style=" display: flex;justify-content: center;align-items: center; font-size: 17px">
  23. <image style="width: 16px; height: 16px; margin-right: 8rpx" src="/static/my/share/success.png"/>
  24. <text>已复制</text>
  25. </view>
  26. <view class="popup-msg-box">
  27. <text>{{ popupMsg }}</text>
  28. </view>
  29. <view style="justify-content: center; align-items: center;">
  30. <!-- 二次弹窗中的按钮图标 -->
  31. <button
  32. style="border-radius: 40rpx; background-color: black; color: white; display: flex; align-items: center; justify-content: center; padding: 12rpx 24rpx;"
  33. @click="closeSecondPopup">
  34. <image style="width: 25px; height: 25px; margin-right: 8rpx;"
  35. :src="platformIconMap[selectedPlatform]"/>
  36. 去粘贴给好友
  37. </button>
  38. </view>
  39. </view>
  40. </uni-popup>
  41. </view>
  42. </template>
  43. <script setup>
  44. import {ref} from 'vue'
  45. import SharePopup from '@/components/SharePopup.vue'
  46. import {getUserInfo} from "@/api/member";
  47. import {Share} from "@/api/setting/share";
  48. /* =============== 数据与引用 =============== */
  49. const shareRef = ref(null)
  50. const secondPopup = ref(null)
  51. const popupMsg = ref('')
  52. // const jwcode = ref('90047681')
  53. // 选中的平台
  54. const selectedPlatform = ref('')
  55. // dccode
  56. const dccode = ref('')
  57. // token
  58. const token = ref('1ab8f83f391ca866191385d0e5048938')
  59. // 设备码
  60. const deviceId = ref(100)
  61. // 版本
  62. const version = ref(100)
  63. // 获取设备类型
  64. const client = ref('android')
  65. // 平台图标
  66. const platformIconMap = ref({
  67. 'WeChat': '/static/my/share/WeChat.png',
  68. 'WhatsApp': '/static/my/share/WhatsApp.png',
  69. 'Line': '/static/my/share/Line.png',
  70. 'KakaoTalk': '/static/my/share/KakaoTalk.png',
  71. '复制链接': '/static/my/share/share.png'
  72. })
  73. // 用户信息
  74. const userInfoRes = ref()
  75. // 分享人的dccode
  76. const shareLink = ref('')
  77. /* =============== 方法 =============== */
  78. userInfoRes.value = getUserInfo()
  79. userInfoRes.value.then(res => {
  80. dccode.value = res.data.dccode
  81. console.log('用户信息', res.data)
  82. })
  83. const ShareRes = ref()
  84. ShareRes.value = Share()
  85. ShareRes.value.then(res => {
  86. if (res.code === 200){
  87. shareLink.value = res.message
  88. console.log('分享接口返回', res.data)
  89. }else {
  90. console.log('分享接口返回失败', res.data)
  91. }
  92. })
  93. // 打开分享弹窗
  94. function openShare() {
  95. Share()
  96. shareRef.value.open()
  97. }
  98. // 关闭分享弹窗
  99. function closeShare() {
  100. shareRef.value.close()
  101. }
  102. //
  103. // 点击分享选项
  104. function onShareSelect({item}) {
  105. console.log('选择了:', item.name)
  106. selectedPlatform.value = item.name // 记录选中的平台
  107. // // 生成动态助力链接
  108. // const baseUrl = 'https:'
  109. // // const shareLink = `${baseUrl}?token=${encodeURIComponent(token.value)}&deviceId=${encodeURIComponent(deviceId.value)}&version=${encodeURIComponent(version.value)}&client=${encodeURIComponent(client.value)}`
  110. // const shareLink = `$ `
  111. // 关闭第一个弹窗
  112. shareRef.value.close()
  113. popupMsg.value = `【DeepChart】邀请你加入,点击链接帮我助力: ${shareLink.value}`
  114. uni.setClipboardData({
  115. data: popupMsg.value,
  116. showToast: false
  117. });
  118. /* // 根据分享选项显示不同提示
  119. if (item.name === '复制链接') {
  120. popupMsg.value = '链接已复制,快去分享给好友吧~'
  121. } else if (item.name === 'WeChat') {
  122. popupMsg.value = '请在微信中分享~'
  123. } else {
  124. popupMsg.value = `你选择了 ${item.name}`
  125. }*/
  126. // 打开第二个弹窗
  127. secondPopup.value.open()
  128. }
  129. // 关闭第二个弹窗
  130. function closeSecondPopup() {
  131. if (selectedPlatform.value === 'WeChat') {
  132. uni.share({
  133. provider: "weixin",
  134. scene: "WXSceneSession",
  135. type: 1,
  136. summary: popupMsg.value,
  137. success: function (res) {
  138. console.log("success:" + JSON.stringify(res));
  139. },
  140. fail: function (err) {
  141. console.log("fail:" + JSON.stringify(err));
  142. }
  143. });
  144. secondPopup.value.close()
  145. }
  146. // 其他的几种情况 需要适配
  147. else if (selectedPlatform.value === 'WhatsApp' || selectedPlatform.value === 'Line' || selectedPlatform.value === 'KakaoTalk') {
  148. secondPopup.value.close()
  149. uni.showToast({title: '开发中……', icon: 'none'})
  150. } else if (selectedPlatform.value === '复制链接') {
  151. uni.showToast({title: '已复制', icon: 'success'})
  152. secondPopup.value.close()
  153. }
  154. }
  155. </script>
  156. <style scoped>
  157. .all {
  158. position: relative;
  159. width: 750rpx;
  160. height: auto;
  161. }
  162. /* 背景图片部分 */
  163. .img-share {
  164. width: 750rpx;
  165. height: 2118rpx;
  166. position: absolute;
  167. top: 0;
  168. left: 0;
  169. z-index: 1;
  170. }
  171. .img-greenBack {
  172. width: 670rpx;
  173. height: 1740rpx;
  174. position: absolute;
  175. top: 16vh;
  176. left: 40rpx;
  177. z-index: 2;
  178. }
  179. .img-QRcode {
  180. width: 320rpx;
  181. height: 320rpx;
  182. position: absolute;
  183. top: 26vh;
  184. left: 215rpx;
  185. z-index: 3;
  186. }
  187. .img-award {
  188. width: 300rpx;
  189. height: 120rpx;
  190. position: absolute;
  191. top: 61vh;
  192. left: 75rpx;
  193. z-index: 3;
  194. }
  195. .img-myFriends {
  196. width: 300rpx;
  197. height: 88rpx;
  198. position: absolute;
  199. top: 61vh;
  200. right: 75rpx;
  201. z-index: 3;
  202. }
  203. .img-friends {
  204. width: 602rpx;
  205. height: 840rpx;
  206. position: absolute;
  207. top: 68vh;
  208. left: 74rpx;
  209. z-index: 3;
  210. }
  211. /* 邀请码与按钮 */
  212. .jwcode {
  213. width: 320rpx;
  214. height: 38rpx;
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. position: absolute;
  219. top: 19vh;
  220. left: 212rpx;
  221. z-index: 999;
  222. }
  223. .invite {
  224. width: 320rpx;
  225. height: 80rpx;
  226. border-radius: 40rpx;
  227. background-color: black;
  228. color: white;
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. position: absolute;
  233. top: 50.7vh;
  234. left: 212rpx;
  235. z-index: 999;
  236. }
  237. /* 第二个弹窗样式 */
  238. .second-popup {
  239. background-color: #fff;
  240. border-radius: 12px;
  241. padding: 30rpx;
  242. text-align: center;
  243. }
  244. .popup-msg-box {
  245. background-color: #F3F3F3;
  246. border-radius: 8px;
  247. padding: 12px 16px;
  248. margin: 10px;
  249. align-items: center;
  250. justify-content: center;
  251. overflow: hidden; /* 隐藏溢出内容 */
  252. text-overflow: ellipsis; /* 溢出部分显示... */
  253. }
  254. </style>