card.vue 8.0 KB

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