card.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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/svg/icon-user.svg')"
  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/svg/icon-messgae.svg')"
  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/svg/icon-messgae.svg')" 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, onBeforeMount } 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: 'join',
  54. data: {},
  55. twitterAccount: ''
  56. })
  57. // 显示加入小组弹框
  58. async function clickJoin() {
  59. sendChromeTabMessage({ actionType: "SWITCH_GROUP_STATUS" }, () => { })
  60. let _userInfo = await checkIsLogin()
  61. if (!_userInfo) {
  62. return
  63. }
  64. // 如果没购买过 弹出购买
  65. if (state.data.buyNftStatus == 0) {
  66. sendChromeTabMessage({
  67. actionType: "IFRAME_SHOW_JOIN_DIALOG",
  68. data: {
  69. type: 'buy',
  70. buy_nft_status: state.data.buyNftStatus,
  71. nft_group_Id: state.data.nftGroupId,
  72. buyNftProjectId: state.data.buyNftProjectId,
  73. nftGroupIcon: state.data.nftGroupIcon,
  74. nftGroupName: state.data.nftGroupName
  75. }
  76. })
  77. // 如果购买过 没加入 显示加入按钮
  78. } else if (state.data.buyNftStatus == 1 && state.data.joinStatus == 0) {
  79. sendChromeTabMessage({
  80. actionType: "IFRAME_SHOW_JOIN_DIALOG",
  81. data: {
  82. type: 'join',
  83. buy_nft_status: state.data.buyNftStatus,
  84. nft_group_Id: state.data.nftGroupId,
  85. nftGroupIcon: state.data.nftGroupIcon,
  86. nftGroupName: state.data.nftGroupName
  87. }
  88. })
  89. } else if (state.data.buyNftStatus == null || state.data.joinStatus == null) {
  90. init()
  91. }
  92. }
  93. const init = (callback) => {
  94. getTwitterNftGroupInfo({
  95. params: {
  96. twitterAccount: state.twitterAccount
  97. }
  98. }).then((res) => {
  99. if (res.code == 0) {
  100. state.data = res.data
  101. if (state.data) {
  102. res.data.joinStatus == 0
  103. // 未加入
  104. if (res.data.joinStatus == 0) {
  105. state.show2 = 'join'
  106. // 已加入
  107. } else if (res.data.joinStatus == 1) {
  108. state.show2 = 'post'
  109. }
  110. if (state.show != 'arrow') {
  111. state.show = state.show2
  112. }
  113. // state.show2 = 'join'
  114. callback && callback()
  115. }
  116. sendMessageToContent({
  117. actionType: 'IFRAME_GROUP_BANNER_GROUP_INFO',
  118. data: res.data || {}
  119. })
  120. }
  121. })
  122. }
  123. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  124. sendResponse('')
  125. switch (req.actionType) {
  126. case 'FINISH_GROUP_BANNNER':
  127. init()
  128. break
  129. case 'SWITCH_GROUP_BANNER_STATUS':
  130. if (req.data.type == 'arrow') {
  131. state.show = 'arrow'
  132. } else {
  133. state.show = state.show2
  134. // console.log(11)
  135. // sendChromeTabMessage({ actionType: "SWITCH_GROUP_STATUS", data: { type: 'btn' } }, () => { })
  136. }
  137. break
  138. }
  139. })
  140. chrome.storage.onChanged.addListener(changes => {
  141. if (changes.userInfo) {
  142. let item = JSON.parse(changes.userInfo.newValue)
  143. if (item) {
  144. init()
  145. }
  146. }
  147. })
  148. window.addEventListener("message", function (event) {
  149. if (event.data) {
  150. switch (event.data.actionType) {
  151. case 'SHOW_BANNER':
  152. state.twitterAccount = event.data.twitterAccount
  153. init()
  154. }
  155. }
  156. });
  157. const sendMessageToContent = (params) => {
  158. let { actionType, data } = params || {};
  159. chrome.tabs.getCurrent((tab) => {
  160. chrome.tabs.sendMessage(tab.id, {
  161. actionType,
  162. data,
  163. }, (res) => { console.log(res) });
  164. })
  165. }
  166. const clickArrow = () => {
  167. sendChromeTabMessage({ actionType: "SWITCH_GROUP_STATUS" }, () => { })
  168. }
  169. async function clickPost() {
  170. sendChromeTabMessage({ actionType: "SWITCH_GROUP_STATUS" }, () => { })
  171. let _userInfo = await checkIsLogin()
  172. if (!_userInfo) {
  173. return
  174. }
  175. // 没有购买过
  176. if (state.data.buyNftStatus == 0) {
  177. sendChromeTabMessage({
  178. actionType: "IFRAME_SHOW_JOIN_DIALOG",
  179. data: {
  180. type: 'buy',
  181. buy_nft_status: state.data.buyNftStatus,
  182. nft_group_Id: state.data.nftGroupId,
  183. buyNftProjectId: state.data.buyNftProjectId,
  184. nftGroupIcon: state.data.nftGroupIcon,
  185. nftGroupName: state.data.nftGroupName
  186. }
  187. })
  188. // 购买过 && 加入过
  189. } else if (state.data.buyNftStatus == 1 && state.data.joinStatus == 1) {
  190. sendChromeTabMessage({
  191. actionType: "IFRAME_SHOW_POST_DIALOG",
  192. data: {
  193. groupId: state.data.nftGroupId
  194. }
  195. })
  196. } else if (state.data.buyNftStatus == null || state.data.joinStatus == null) {
  197. init()
  198. }
  199. }
  200. onBeforeMount(() => {
  201. state.twitterAccount = getQueryString('twitterAccount') || ''
  202. init(() => {
  203. sendChromeTabMessage({ actionType: "IFRAME_SHOW_GROUP_TIP" })
  204. })
  205. })
  206. </script>
  207. <style lang='scss'>
  208. html,
  209. body,
  210. #app {
  211. margin: 0;
  212. padding: 0;
  213. width: 100%;
  214. height: 100px;
  215. }
  216. #denet_group_tip {
  217. width: 100%;
  218. height: 100%;
  219. }
  220. </style>