index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="denet-message" v-show="state.list.length > 0">
  3. <template v-for="item in state.list">
  4. <div class="denet-message-area" @click="clickItem(item)" v-if="item.bizType == 2">
  5. <img :src="require('@/assets/img/icon-message-fail.png')" alt />
  6. <span>You were not selected from the giveaway events... Click to see more giveaways!</span>
  7. <div class="denet-message-close" @click.stop="clickClose(item)">
  8. <img :src="require('@/assets/img/icon-message-close.png')" alt />
  9. </div>
  10. </div>
  11. <div class="denet-message-area" @click="clickItem(item)" v-if="item.bizType == 1">
  12. <img :src="require('@/assets/img/icon-message-win.png')" alt />
  13. <span>Congratulations! You won <b class="denet-message-money">{{ item.bizData.lotteryMoney }}
  14. {{ item.bizData.lotteryTokenSymbol }}</b> from the giveaway!🎉</span>
  15. <div class="denet-message-close" @click.stop="clickClose(item)">
  16. <img :src="require('@/assets/img/icon-message-close.png')" alt />
  17. </div>
  18. </div>
  19. </template>
  20. </div>
  21. </template>
  22. <script setup>
  23. import { onMounted, reactive } from "vue";
  24. let state = reactive({
  25. list: [],
  26. })
  27. // 过5秒消失逻辑
  28. const overTimeClose = () => {
  29. setTimeout(() => {
  30. let now_time = new Date().getTime()
  31. for (let i in state.list) {
  32. if ((now_time - state.list[i].read_time) > 4500) {
  33. state.list.splice(i, 1)
  34. }
  35. }
  36. }, 5000)
  37. }
  38. const clickClose = (item) => {
  39. // 通知已读
  40. for (let i in state.list) {
  41. if (item.id == state.list[i].id) {
  42. state.list.splice(i, 1)
  43. }
  44. }
  45. }
  46. const clickItem = (item) => {
  47. if (item.bizType == 1) {
  48. // 跳转详情页
  49. window.open(`https://twitter.com/${item.bizData.twitterAccount}/status/${item.bizData.twitterId}`)
  50. } else {
  51. window.open('https://twitter.com/search?q=%23DeNet&src=typed_query')
  52. }
  53. }
  54. // 读取消息
  55. const readMessage = (id = 0) => {
  56. chrome.runtime.sendMessage({
  57. actionType: "CONTENT_HTTP_NET_WORK",
  58. funcName: '通知已读',
  59. data: {
  60. url: '/notice/read',
  61. params: {
  62. noticeId: id
  63. }
  64. }
  65. });
  66. }
  67. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  68. if (req.actionType == 'BACK_UNREAD_MESSAGE') {
  69. let data = req.data.data || []
  70. console.log('BACK_UNREAD_MESSAGE', data)
  71. if (req.data.code == 0 && data.length > 0) {
  72. data.forEach((item) => {
  73. if (state.list.filter((filter_item) => { return filter_item.id == item.id }).length == 0) {
  74. item.bizData = JSON.parse(item.bizData)
  75. item.read_time = new Date().getTime()
  76. state.list.push(item)
  77. }
  78. readMessage(item.id)
  79. })
  80. overTimeClose()
  81. }
  82. }
  83. })
  84. </script>
  85. <style lang="scss" scoped>
  86. .denet-message {
  87. position: fixed;
  88. max-height: 100%;
  89. overflow: hidden;
  90. top: 0;
  91. right: 0;
  92. width: 500px;
  93. z-index: 9999;
  94. &-area {
  95. width: 344px;
  96. background: #FFFFFF;
  97. border-radius: 15px;
  98. min-height: 72px;
  99. position: relative;
  100. margin-top: 22px;
  101. display: flex;
  102. cursor: pointer;
  103. filter: drop-shadow(0px 5px 20px rgba(0, 0, 0, 0.22));
  104. margin-left: 129px;
  105. img:first-child {
  106. width: 40px;
  107. height: 40px;
  108. margin: 16px 14px 0 16px;
  109. }
  110. span {
  111. padding: 14px 26px 14px 0;
  112. font-style: normal;
  113. font-weight: 500;
  114. font-size: 14px;
  115. line-height: 20px;
  116. }
  117. .denet-message-money {
  118. color: #3D7CB4;
  119. }
  120. }
  121. &-area:last-child {
  122. margin-bottom: 50px;
  123. }
  124. &-close {
  125. border-radius: 100px;
  126. width: 24px;
  127. height: 24px;
  128. display: flex;
  129. justify-content: center;
  130. align-items: center;
  131. background: #F2F2F2;
  132. position: absolute;
  133. right: -10px;
  134. top: -10px;
  135. filter: drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.12));
  136. cursor: pointer;
  137. img:first-child {
  138. height: 10px;
  139. width: 10px;
  140. margin: 0;
  141. }
  142. }
  143. }
  144. </style>