invite-friends.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="invite-friends">
  3. <div class="txt">To open the treasure chest you need to share the URL to your friends. Make sure they finish
  4. the
  5. tasks.</div>
  6. <div class="area-url">
  7. <div class="url">{{ state.detail.inviteUrl }}</div>
  8. <div class="btn copy-btn" @click="clickCopy" v-click-log="state.log_invite_copy_btn_click"
  9. :data-clipboard-text="state.detail.inviteCopyUrl">
  10. Copy
  11. </div>
  12. </div>
  13. <div class="share-list">
  14. <img :src="item.iconPath" alt="" v-for="item in state.share_list" :data-clipboard-text="item.inviteContent"
  15. @click="clickShare(item)" class="share-item" />
  16. </div>
  17. <v-btn :txt="state.open_btn.txt" :font-size="'17px'" class="btn" :icon="false"
  18. :disabled="state.open_btn.disabled" v-show-log="state.log_invite_btn_show" :loading="state.btn_loading"
  19. v-click-log="state.log_invite_btn_click" @onClick="clickBtn" font-weight="600"></v-btn>
  20. </div>
  21. </template>
  22. <script setup>
  23. import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
  24. import { inviteChannel } from '@/http/treasure'
  25. import { inject, onMounted } from 'vue'
  26. import Report from "@/log-center/log"
  27. import { getFrontConfig } from "@/http/account";
  28. import { faceShareRedirectUrl } from '@/http/configAPI'
  29. import { setChromeStorage } from '@/uilts/chromeExtension.js'
  30. let ClipboardJS = require('clipboard');
  31. let state = inject('state')
  32. state.log_invite_btn_show = {
  33. businessType: Report.businessType.buttonView,
  34. pageSource: Report.pageSource.inviteFriendsPage,
  35. objectType: Report.objectType.openChestButton,
  36. redPacketType: Report.redPacketType.treasure,
  37. shareLinkId: state.invite_code,
  38. myShareLinkId: state.detail.inviteCopyUrl,
  39. currentInvitedNum: state.inviteCount,
  40. postId: state.postId
  41. }
  42. state.log_invite_btn_click = {
  43. businessType: Report.businessType.buttonClick,
  44. pageSource: Report.pageSource.inviteFriendsPage,
  45. objectType: Report.objectType.openChestButton,
  46. redPacketType: Report.redPacketType.treasure,
  47. shareLinkId: state.invite_code,
  48. myShareLinkId: state.detail.inviteCopyUrl,
  49. currentInvitedNum: state.inviteCount,
  50. postId: state.postId
  51. }
  52. state.log_invite_copy_btn_click = {
  53. businessType: Report.businessType.buttonClick,
  54. pageSource: Report.pageSource.inviteFriendsPage,
  55. objectType: Report.objectType.copyButton,
  56. redPacketType: Report.redPacketType.treasure,
  57. shareLinkId: state.invite_code,
  58. myShareLinkId: state.detail.inviteCopyUrl,
  59. currentInvitedNum: state.inviteCount,
  60. postId: state.postId
  61. }
  62. let facebookAppConfig = {
  63. facebookAppId: "",
  64. faceShareRedirectUrl
  65. };
  66. onMounted(() => {
  67. state.btn_loading = false
  68. setFrontConfig();
  69. initInviteChannel()
  70. })
  71. chrome.management.onDisabled.addListener(() => {
  72. initInviteChannel()
  73. })
  74. chrome.management.onEnabled.addListener(() => {
  75. initInviteChannel()
  76. })
  77. chrome.management.onInstalled.addListener(() => {
  78. initInviteChannel()
  79. })
  80. chrome.management.onUninstalled.addListener(() => {
  81. initInviteChannel()
  82. })
  83. let linePluginInstalled
  84. const initInviteChannel = () => {
  85. try {
  86. chrome.management.get('ophjlpahpchlmihnnnihgmmeilfjmjjc', (res) => {
  87. if ((res && linePluginInstalled == 1) || (!res && linePluginInstalled == 0)) {
  88. return
  89. }
  90. if (res) {
  91. linePluginInstalled = 1
  92. } else {
  93. linePluginInstalled = 0
  94. }
  95. inviteChannel({
  96. params: {
  97. linePluginInstalled,
  98. postId: state.postId
  99. }
  100. }).then((res) => {
  101. if (res.code == 0) {
  102. state.share_list = res.data
  103. }
  104. })
  105. })
  106. } catch (error) {
  107. console.error(error)
  108. }
  109. }
  110. async function clickBtn() {
  111. let _userInfo = await state.checkIsLogin()
  112. if (!_userInfo) {
  113. return
  114. }
  115. state.btn_loading = true
  116. state.treasureOpen()
  117. }
  118. const clickShare = (item) => {
  119. var clipboard = new ClipboardJS('.share-item');
  120. clipboard.on('success', function (e) {
  121. state.toast.txt = 'Copy Successfully'
  122. state.toast.has_icon = true
  123. state.toast.show = true
  124. setTimeout(() => {
  125. state.toast.show = false
  126. }, 2000)
  127. e.clearSelection();
  128. })
  129. if (item.name == 'facebook') {
  130. setChromeStorage({
  131. shareFacebookData: JSON.stringify({
  132. contentStr: item.inviteContent
  133. })
  134. })
  135. let cbParams = {
  136. bizType: 'TEASURE_INVITE'
  137. }
  138. let url = `https://www.facebook.com/dialog/share?app_id=${facebookAppConfig.facebookAppId}&display=popup&href=${item.treasureInviteUrl}&redirect_uri=${facebookAppConfig.faceShareRedirectUrl}?params=${JSON.stringify(cbParams)}`;
  139. chrome.windows.create({
  140. width: 800,
  141. type: 'normal',
  142. url
  143. }, function (window) {
  144. })
  145. } else {
  146. chrome.tabs.create({
  147. url: item.redirectPath
  148. });
  149. }
  150. Report.reportLog({
  151. businessType: Report.businessType.buttonClick,
  152. pageSource: Report.pageSource.inviteFriendsPage,
  153. objectType: Report.objectType.channelButton,
  154. shareLinkId: state.invite_code,
  155. myShareLinkId: state.detail.inviteCopyUrl,
  156. currentInvitedNum: state.inviteCount,
  157. postId: state.postId
  158. }, {
  159. 'channel-name': item.name
  160. });
  161. }
  162. const setFrontConfig = () => {
  163. getFrontConfig({
  164. params: {},
  165. }).then((res) => {
  166. if (res.code == 0) {
  167. facebookAppConfig.facebookAppId = res.data.fbClientId;
  168. }
  169. });
  170. };
  171. const clickCopy = () => {
  172. var clipboard = new ClipboardJS('.copy-btn');
  173. clipboard.on('success', function (e) {
  174. state.toast.txt = 'Copy Successfully'
  175. state.toast.has_icon = true
  176. state.toast.show = true
  177. setTimeout(() => {
  178. state.toast.show = false
  179. }, 2000)
  180. e.clearSelection();
  181. })
  182. clipboard.on('error', function (e) {
  183. state.toast.txt = 'Copy Error'
  184. state.toast.has_icon = false
  185. state.toast.show = true
  186. setTimeout(() => {
  187. state.toast.show = false
  188. }, 2000)
  189. })
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .invite-friends {
  194. padding: 18px 16px 25px 16px;
  195. background: #fff;
  196. .txt {
  197. font-style: normal;
  198. font-weight: 500;
  199. font-size: 13px;
  200. line-height: 18px;
  201. /* or 129% */
  202. margin-bottom: 18.5px;
  203. letter-spacing: 0.3px;
  204. color: #000000;
  205. }
  206. .area-url {
  207. height: 70px;
  208. background: rgba(29, 155, 240, 0.01);
  209. border: 1px solid #1D9BF0;
  210. border-radius: 5px;
  211. display: flex;
  212. align-items: center;
  213. padding-left: 15px;
  214. padding-right: 11px;
  215. justify-content: space-between;
  216. .url {
  217. display: -webkit-box;
  218. -webkit-box-orient: vertical;
  219. -webkit-line-clamp: 3;
  220. overflow: hidden;
  221. width: 194px;
  222. color: #737373;
  223. font-weight: 400;
  224. font-size: 13px;
  225. white-space: normal;
  226. word-wrap: break-word;
  227. word-break: break-all;
  228. }
  229. .btn {
  230. user-select: none;
  231. background: #1D9BF0;
  232. border-radius: 35px;
  233. width: 100px;
  234. text-align: center;
  235. line-height: 37px;
  236. height: 37px;
  237. font-weight: 700;
  238. font-size: 15px;
  239. color: #fff;
  240. cursor: pointer;
  241. }
  242. }
  243. .share-list {
  244. margin-top: 20px;
  245. text-align: center;
  246. margin-bottom: 14px;
  247. img {
  248. user-select: none;
  249. cursor: pointer;
  250. width: 33px;
  251. height: 33px;
  252. margin-right: 14px;
  253. border-radius: 100px;
  254. }
  255. }
  256. }
  257. </style>