card.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div id="denet_group_tip" v-if="state.data" style="display: flex;z-index: 100; background-color: #356789;">
  3. <div style="flex:1; display: flex; align-items: center;">
  4. <div>
  5. <img :src="state.data.nftGroupIcon" style="width:54px;height:54px; margin: 0 20px;" alt="" />
  6. </div>
  7. <div>
  8. <p style="font-weight: 700; font-size: 18px; color: #fff; margin: 0; padding: 0; margin-bottom: 11px;">
  9. {{ state.data.nftGroupName }}
  10. </p>
  11. <div style="display: flex; ">
  12. <div style="display: flex; align-items: center;">
  13. <img :src="require('@/assets/img/icon-user.png')"
  14. style="width:16px;height:16px; margin-right: 5px;" alt="" />
  15. <span style="color: #fff;">{{ state.data.memberCount }} Member</span>
  16. </div>
  17. <div style="display: flex; align-items: center; margin-left: 17px;">
  18. <img :src="require('@/assets/img/icon-messgae.png')"
  19. style="width:16px;height:16px; margin-right: 5px;" alt="" />
  20. <span style="color: #fff;">{{ state.data.postCount }} Posts</span>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div
  26. style="width: 180px;height: 100%; display: flex; align-items: center; justify-content: center; position: relative;">
  27. <div v-show="state.show == 'post'" style="width: 140px; height: 40px; display:flex; align-items: center; justify-content: center; background: #1D9BF0; border-radius: 50px;
  28. cursor: pointer;
  29. " @click="clickPost">
  30. <img :src="require('@/assets/img/icon-messgae.png')" style="width:16px;height:16px;" alt="">
  31. <span style="margin-left: 7px; font-size: 15px;font-weight: 700; color: #fff; ">Post</span>
  32. </div>
  33. <div v-show="state.show == 'join'"
  34. style="width: 140px; height: 40px; display:flex; align-items: center; justify-content: center; background: #1D9BF0; border-radius: 50px; cursor: pointer;"
  35. @click="clickJoin">
  36. <span style="margin-left: 7px; font-size: 15px;font-weight: 700; color: #fff; ">Join Now</span>
  37. </div>
  38. <svg @click="clickArrow" v-show="state.show == 'arrow'" id="denet_tip_group_arrow"
  39. style="position: absolute; right: 20px; cursor: pointer;" width="40" height="40" viewBox="0 0 40 40"
  40. fill="none" xmlns="http://www.w3.org/2000/svg">
  41. <path d="M15 10L26 19.6875L15 29.375" stroke="white" stroke-width="2" />
  42. </svg>
  43. </div>
  44. </div>
  45. </template>
  46. <script setup>
  47. import { reactive, onMounted } from 'vue'
  48. import { getTwitterNftGroupInfo } from "@/http/group";
  49. import { getQueryString } from '@/uilts/help.js';
  50. import { sendChromeTabMessage, checkIsLogin } from '@/uilts/chromeExtension.js';
  51. let state = reactive({
  52. show: 'arrow', //join
  53. show2: 'post',
  54. data: {},
  55. twitterAccount: ''
  56. })
  57. // 显示加入小组弹框
  58. async function clickJoin() {
  59. let _userInfo = await checkIsLogin()
  60. if (!_userInfo) {
  61. return
  62. }
  63. sendChromeTabMessage({
  64. actionType: "IFRAME_SHOW_JOIN_DIALOG",
  65. data: {
  66. type: 'join',
  67. buy_nft_status: state.data.buyNftStatus,
  68. nft_group_Id: state.data.nftGroupId,
  69. nftGroupIcon: state.data.nftGroupIcon,
  70. nftGroupName: state.data.nftGroupName
  71. }
  72. })
  73. }
  74. const init = (callback) => {
  75. getTwitterNftGroupInfo({
  76. params: {
  77. twitterAccount: state.twitterAccount
  78. }
  79. }).then((res) => {
  80. if (res.code == 0) {
  81. state.data = res.data
  82. if (state.data) {
  83. // 未加入
  84. if (res.data.joinStatus == 0) {
  85. state.show2 = 'join'
  86. // 已加入
  87. } else if (res.data.joinStatus == 1) {
  88. state.show2 = 'post'
  89. }
  90. if (state.show != 'arrow') {
  91. state.show = state.show2
  92. }
  93. // state.show2 = 'join'
  94. callback && callback()
  95. }
  96. }
  97. sendMessageToContent({
  98. actionType: 'IFRAME_GROUP_BANNER_GROUP_INFO',
  99. data: res.data || {}
  100. })
  101. })
  102. }
  103. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  104. sendResponse('')
  105. switch (req.actionType) {
  106. case 'FINISH_GROUP_BANNNER':
  107. init()
  108. break
  109. case 'SWITCH_GROUP_BANNER_STATUS':
  110. if (req.data.type == 'arrow') {
  111. state.show = 'arrow'
  112. } else {
  113. state.show = state.show2
  114. }
  115. break
  116. }
  117. })
  118. const sendMessageToContent = (params) => {
  119. let { actionType, data } = params || {};
  120. chrome.tabs.getCurrent((tab) => {
  121. chrome.tabs.sendMessage(tab.id, {
  122. actionType,
  123. data,
  124. }, (res) => { console.log(res) });
  125. })
  126. }
  127. const clickArrow = () => {
  128. sendChromeTabMessage({ actionType: "SWITCH_GROUP_STATUS" }, () => { })
  129. }
  130. async function clickPost() {
  131. let _userInfo = await checkIsLogin()
  132. if (!_userInfo) {
  133. return
  134. }
  135. // 没有购买过
  136. if (state.data.buyNftStatus == 0) {
  137. sendChromeTabMessage({
  138. actionType: "IFRAME_SHOW_JOIN_DIALOG",
  139. data: {
  140. type: 'buy',
  141. buy_nft_status: state.data.buyNftStatus,
  142. nft_group_Id: state.data.nftGroupId,
  143. buyNftProjectId: state.data.buyNftProjectId,
  144. nftGroupIcon: state.data.nftGroupIcon,
  145. nftGroupName: state.data.nftGroupName
  146. }
  147. })
  148. // 购买过
  149. } else if (state.data.buyNftStatus == 1) {
  150. sendChromeTabMessage({
  151. actionType: "IFRAME_SHOW_POST_DIALOG",
  152. data: {
  153. groupId: state.data.nftGroupId
  154. }
  155. })
  156. }
  157. }
  158. onMounted(() => {
  159. state.twitterAccount = getQueryString('twitterAccount') || ''
  160. init(() => {
  161. sendChromeTabMessage({ actionType: "IFRAME_SHOW_GROUP_TIP" })
  162. })
  163. })
  164. </script>
  165. <style lang='scss'>
  166. html,
  167. body,
  168. #app {
  169. margin: 0;
  170. padding: 0;
  171. width: 100%;
  172. height: 100%;
  173. }
  174. #denet_group_tip {
  175. width: 100%;
  176. height: 100%;
  177. }
  178. </style>