card.vue 8.7 KB

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