index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <div class="message-wrapper">
  3. <!-- <div class="tab-bar">
  4. <div
  5. class="tab-item"
  6. :class="{ active: currentTabIndex == index }"
  7. v-for="(item, index) in tabList"
  8. :key="index"
  9. @click="clickTab(item, index)"
  10. >
  11. {{ item.label }}
  12. </div>
  13. </div> -->
  14. <div class="tab-content" ref="pageWrapperDom" @scroll="pageScroll">
  15. <div class="list-wrapper" ref="pageGiveListDom">
  16. <div class="give-list" v-if="currentTabIndex == 0">
  17. <template v-if="giveList.length">
  18. <div
  19. class="cell"
  20. :class="{ 'cell-center': item.type == 1 }"
  21. v-for="(item, index) in giveList"
  22. :key="index"
  23. @click="clickListItem(item, index)"
  24. >
  25. <red-dot
  26. class="red-dots"
  27. v-if="item.unReadMsgCount > 0 && isReadMsg"
  28. ></red-dot>
  29. <div class="img-wrapper">
  30. <!-- 收到红包 -->
  31. <template v-if="item.type == 1">
  32. <img class="icon-avatar" :src="item.userInfo.avatarUrl" />
  33. <img
  34. class="icon-give"
  35. :src="require('@/assets/svg/icon-get-giveaways-s.svg')"
  36. />
  37. </template>
  38. <!-- 发出去红包 -->
  39. <template v-else-if="2">
  40. <img
  41. class="icon-big-give"
  42. :src="require('@/assets/svg/icon-send-giveaways-s.svg')"
  43. />
  44. </template>
  45. </div>
  46. <div
  47. class="info-wrapper"
  48. :class="{ 'info-center': item.type == 1 }"
  49. >
  50. <div class="left">
  51. <div class="nickname">
  52. {{ item.type == 1 ? "Get Giveaway" : "Send Giveaway" }}
  53. </div>
  54. <div class="time">
  55. {{ moment(item.timestamp).format("MM-DD HH:mm:ss") }}
  56. </div>
  57. </div>
  58. <div class="right">
  59. <div class="msg">
  60. <div
  61. class="bold"
  62. :class="{
  63. 'align-content':
  64. (item.type == 2 ||
  65. (item.type == 1 && item.status == 1)) &&
  66. item.amount.length + item.currencySymbol.length > 12,
  67. }"
  68. >
  69. <!-- 收到的 -->
  70. <template v-if="item.type == 1">
  71. <!-- 进行中-->
  72. <template v-if="item.status == 0">
  73. in progress
  74. </template>
  75. <!-- 已完成 -->
  76. <template v-else-if="item.status == 1">
  77. <span class="blance">
  78. <a-tooltip :title="item.amount">
  79. {{ getBit(item.amount) }}</a-tooltip
  80. >
  81. </span>
  82. <div class="coin-type-wrapper">
  83. <span class="coin-type">{{
  84. item.currencySymbol || ""
  85. }}</span>
  86. <img :src="item.currencyIconPath" alt="" />
  87. </div>
  88. </template>
  89. <!-- 已过期 -->
  90. <template v-else-if="item.status == 2">
  91. Timeout
  92. </template>
  93. </template>
  94. <!-- 发出去的 -->
  95. <template v-else-if="item.type == 2">
  96. <span class="blance">
  97. <a-tooltip :title="'-' + item.amount">
  98. -{{ getBit(item.amount) }}
  99. </a-tooltip>
  100. </span>
  101. <div class="coin-type-wrapper">
  102. <span class="coin-type">{{
  103. item.currencySymbol || ""
  104. }}</span>
  105. <img :src="item.currencyIconPath" alt="" />
  106. </div>
  107. </template>
  108. </div>
  109. <!-- 发出的红包显示 -->
  110. <div class="desc" v-if="item.type == 2">
  111. <!-- 未发送-->
  112. <template v-if="item.postTaskLuckdrop.reSendAvailable">
  113. Unpublished
  114. </template>
  115. <!-- 进行中 -->
  116. <template v-else-if="item.status == 1">
  117. {{ item.postTaskLuckdrop.receivedCount }}/{{
  118. item.postTaskLuckdrop.totalCount
  119. }}
  120. </template>
  121. <!-- 2:已结束; 3:提前终止-->
  122. <template
  123. v-else-if="item.status == 2 || item.status == 3"
  124. >
  125. ({{
  126. item.status == 2 ? "Time expired" : "Termination"
  127. }}) {{ item.postTaskLuckdrop.receivedCount }}/{{
  128. item.postTaskLuckdrop.totalCount
  129. }}
  130. </template>
  131. <!-- 红包提前终止/退款(进行中)显示-->
  132. <template v-if="item.status == 4"> Terminating </template>
  133. <!-- 进行中或者未发送成功时显示
  134. v-if="item.status == 1 || item.postTaskLuckdrop.reSendAvailable"-->
  135. <div class="desc-bottom-bar">
  136. <!-- 没有终止红包时显示 -->
  137. <div
  138. v-if="item.postTaskLuckdrop.terminatedAvailable"
  139. class="btn"
  140. @click.stop="terminaHandler(item, index)"
  141. >
  142. Termination
  143. </div>
  144. <!-- 红包未发出显示 -->
  145. <div
  146. class="btn send-btn"
  147. v-if="item.postTaskLuckdrop.reSendAvailable"
  148. @click.stop="sendTwitter(item)"
  149. >
  150. Send
  151. </div>
  152. <div
  153. v-else-if="item.srcContentId"
  154. class="btn detail-btn"
  155. @click.stop="clickListItem(item, index)"
  156. >
  157. details
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <!-- 发红包—— 未发出、进行中 隐藏 -->
  163. <img
  164. v-if="item.type != 2"
  165. class="icon"
  166. :src="require('@/assets/svg/icon-cell-arrow-right.svg')"
  167. />
  168. </div>
  169. </div>
  170. </div>
  171. </template>
  172. <template v-else>
  173. <img
  174. class="icon-empty"
  175. :src="require('@/assets/svg/icon-empty-list.svg')"
  176. />
  177. </template>
  178. </div>
  179. </div>
  180. </div>
  181. <modal
  182. :visible="modalVisible"
  183. title="Early termination of Giveaway?"
  184. content="The remaining amount will be returned to your wallet within 1 day."
  185. cancelText="Termination"
  186. confirmText="Cancel"
  187. @cancel="modalCancel"
  188. @confirm="modalConfirm"
  189. />
  190. </div>
  191. </template>
  192. <script setup>
  193. import { ref, onMounted, inject, onBeforeUnmount } from "vue";
  194. import modal from "@/view/popup/components/modal.vue";
  195. import redDot from "@/view/components/red-dot.vue";
  196. import { getBit } from "@/uilts/help";
  197. import { getMineLuckdropRecords } from "@/http/account";
  198. import { terminatedLuckdrop } from "@/http/redPacket";
  199. import { readAllMsgByType, getAllMessageInfo } from "@/http/messageApi"
  200. import { setBadgeInfo, hideBadge } from "@/logic/background/twitter";
  201. import { getChromeStorage } from "@/uilts/chromeExtension";
  202. var moment = require("moment");
  203. let currentTabIndex = ref(0);
  204. let userInfo = ref({});
  205. let tabList = ref([
  206. {
  207. label: "ALL",
  208. },
  209. {
  210. label: "Giveaway",
  211. },
  212. {
  213. label: "NFT",
  214. },
  215. ]);
  216. let pageWrapperDom = ref(null);
  217. let pageGiveListDom = ref(null);
  218. let modalVisible = ref(false);
  219. let terminaTask = {};
  220. let giveList = ref([]);
  221. let giveReqParams = {
  222. params: {
  223. pageNum: 1,
  224. pageSize: 20,
  225. },
  226. loadMore: false,
  227. };
  228. let isReadMsg = ref(true);
  229. const clickTab = (params, index) => {
  230. currentTabIndex.value = index;
  231. };
  232. /**
  233. * 获取红包列表
  234. */
  235. const getLuckdropRecordsList = () => {
  236. getMineLuckdropRecords({
  237. params: giveReqParams.params,
  238. }).then((res) => {
  239. chrome.runtime.connect({ name: "popup" });
  240. if (res.data && res.data.length) {
  241. if (giveReqParams.params.pageNum < 2) {
  242. giveList.value = res.data;
  243. } else {
  244. let data = giveList.value;
  245. data = data.concat(res.data);
  246. giveList.value = data;
  247. }
  248. giveReqParams.loadMore = false;
  249. }
  250. });
  251. };
  252. /**
  253. * 点击列表跳转到推文
  254. */
  255. const clickListItem = (params) => {
  256. if (!params.srcContentId) {
  257. return;
  258. }
  259. let twitterUrl = "https://twitter.com/";
  260. let nickName = "";
  261. if (params.type == 1) {
  262. nickName = params.userInfo.nickName;
  263. } else if (params.type == 2) {
  264. nickName = userInfo.value.nickName;
  265. }
  266. let url = twitterUrl + nickName + "/status/" + params.srcContentId;
  267. chrome.tabs.create({
  268. url,
  269. });
  270. };
  271. const pageScroll = (e) => {
  272. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  273. let pageGiveListHeight = pageGiveListDom.value.offsetHeight;
  274. let scrollTop = e.target.scrollTop || 0;
  275. if (currentTabIndex.value != 0) {
  276. return;
  277. }
  278. if (
  279. giveReqParams.loadMore === false &&
  280. wrapperHeight + scrollTop >= pageGiveListHeight - 60
  281. ) {
  282. giveReqParams.loadMore = true;
  283. giveReqParams.params.pageNum++;
  284. getLuckdropRecordsList();
  285. }
  286. };
  287. /**
  288. * 点击发送,去发推
  289. */
  290. const sendTwitter = (params) => {
  291. console.log(params);
  292. callEventPageMethod(
  293. "POPUP_PUBLISH_TWITTER_RED_PACK",
  294. {
  295. srcContent: params.postTaskLuckdrop.srcContent,
  296. postId: params.postTaskLuckdrop.postId,
  297. },
  298. function (response) {
  299. console.log("res", response);
  300. }
  301. );
  302. };
  303. /**
  304. * sendMessage
  305. */
  306. const callEventPageMethod = (actionType, data, callback) => {
  307. chrome.runtime.sendMessage(
  308. {
  309. actionType: actionType,
  310. data: data,
  311. },
  312. function (response) {
  313. if (typeof callback === "function") callback(response);
  314. }
  315. );
  316. };
  317. const terminaHandler = (params, index) => {
  318. terminaTask = params;
  319. terminaTask.index = index;
  320. modalVisible.value = true;
  321. };
  322. const modalCancel = () => {
  323. //请求终止接口 id terminaTask.id 、 刷新当前列表、 关闭
  324. modalVisible.value = false;
  325. let index = terminaTask.index;
  326. terminatedLuckdrop({
  327. params: {
  328. luckdropId: terminaTask.id,
  329. },
  330. }).then((res) => {
  331. if (res.code == 0) {
  332. giveList.value[index]["status"] = res.data.status;
  333. giveList.value[index]["postTaskLuckdrop"]["reSendAvailable"] = false;
  334. giveList.value[index]["postTaskLuckdrop"]["terminatedAvailable"] = false;
  335. }
  336. });
  337. terminaTask = {};
  338. };
  339. const modalConfirm = () => {
  340. modalVisible.value = false;
  341. terminaTask = {};
  342. };
  343. const readAllMsg = ({msgType}, cb) => {
  344. readAllMsgByType({
  345. params: {
  346. msgType
  347. }
  348. }).then(res => {
  349. cb && cb();
  350. })
  351. };
  352. const setMessageCount = () => {
  353. getAllMessageInfo({params: {
  354. }}).then(res => {
  355. if(res.code == 0) {
  356. let {unReadCountTotal = 0, unReadCountWalletDetail = 0, unReadCountTaskLuckdrop = 0} = res.data;
  357. if(unReadCountTotal > 0) {
  358. let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal+'';
  359. setBadgeInfo({data: {text}});
  360. } else {
  361. hideBadge();
  362. }
  363. }
  364. });
  365. }
  366. const getUserInfo = (cb) => {
  367. getChromeStorage("userInfo", (res) => {
  368. if (res && res.accessToken) {
  369. userInfo.value = res;
  370. } else {
  371. userInfo.value = {};
  372. }
  373. cb && cb(res);
  374. });
  375. };
  376. const init = () => {
  377. getUserInfo();
  378. getLuckdropRecordsList();
  379. setMessageCount();
  380. setTimeout(() => {
  381. isReadMsg.value = false;
  382. readAllMsg({msgType: 1}, () => {
  383. setMessageCount();
  384. });
  385. }, 2000);
  386. }
  387. const onMessage = () => {
  388. chrome.runtime.onMessage.addListener(msgListener)
  389. }
  390. const msgListener = (req, sender, sendResponse) => {
  391. sendResponse('');
  392. switch (req.actionType) {
  393. case 'CONTENT_POPUP_PAGE_SHOW':
  394. init();
  395. break;
  396. }
  397. }
  398. onMounted(() => {
  399. onMessage();
  400. init();
  401. });
  402. onBeforeUnmount(() => {
  403. chrome.runtime.onMessage.removeListener(msgListener);
  404. })
  405. </script>
  406. <style scoped lang="scss">
  407. .message-wrapper {
  408. width: 100%;
  409. height: 100%;
  410. margin-top: 1px;
  411. .tab-bar {
  412. display: flex;
  413. align-items: center;
  414. background-color: #fff;
  415. box-shadow: 0px 0.5px 0px #d1d9dd;
  416. .tab-item {
  417. display: flex;
  418. align-items: center;
  419. justify-content: center;
  420. padding: 14px 0px;
  421. box-sizing: border-box;
  422. border-bottom: 2px solid #fff;
  423. margin: 0 12px;
  424. font-size: 14px;
  425. color: #949494;
  426. cursor: pointer;
  427. }
  428. .active {
  429. border-bottom: 2px solid #1d9bf0;
  430. font-weight: 500;
  431. color: #000;
  432. }
  433. }
  434. .tab-content {
  435. height: 100%;
  436. overflow-y: auto;
  437. .list-wrapper {
  438. min-height: 202px;
  439. .give-list {
  440. min-height: 202px;
  441. position: relative;
  442. .cell {
  443. display: flex;
  444. justify-content: space-between;
  445. min-height: 76px;
  446. box-sizing: border-box;
  447. padding-left: 14px;
  448. position: relative;
  449. cursor: pointer;
  450. .red-dots {
  451. position: absolute;
  452. right: 4px;
  453. top: 4px;
  454. }
  455. .img-wrapper {
  456. position: relative;
  457. margin-right: 16px;
  458. box-sizing: border-box;
  459. .icon-avatar {
  460. width: 34px;
  461. height: 34px;
  462. border-radius: 50%;
  463. margin-right: 8px;
  464. }
  465. .icon-give {
  466. position: absolute;
  467. right: 1px;
  468. bottom: -1px;
  469. width: 18px;
  470. height: 18px;
  471. }
  472. .icon-big-give {
  473. margin-top: 12px;
  474. }
  475. }
  476. .info-wrapper {
  477. flex: 1;
  478. height: 100%;
  479. display: flex;
  480. justify-content: space-between;
  481. box-sizing: border-box;
  482. padding: 10px 14px 10px 0;
  483. .left {
  484. .nickname {
  485. font-weight: 500;
  486. font-size: 13px;
  487. margin-bottom: 5px;
  488. max-width: 132px;
  489. word-break: break-all;
  490. }
  491. .time {
  492. font-size: 12px;
  493. color: #b0b0b0;
  494. }
  495. }
  496. .right {
  497. display: flex;
  498. align-items: center;
  499. cursor: pointer;
  500. .msg {
  501. display: flex;
  502. align-items: end;
  503. flex-direction: column;
  504. .bold {
  505. font-weight: 500;
  506. font-size: 13px;
  507. text-align: right;
  508. display: flex;
  509. justify-content: flex-end;
  510. align-items: center;
  511. max-width: 140px;
  512. .blance {
  513. margin-left: 3px;
  514. display: inline-block;
  515. max-width: 80px;
  516. word-break: break-all;
  517. line-height: 18px;
  518. color: #e86f00;
  519. }
  520. .coin-type-wrapper {
  521. display: flex;
  522. align-items: center;
  523. }
  524. .coin-type {
  525. margin-left: 3px;
  526. word-break: break-all;
  527. }
  528. img {
  529. margin-left: 4px;
  530. width: 14px;
  531. height: 14px;
  532. }
  533. }
  534. .align-content {
  535. flex-direction: column;
  536. align-items: flex-end;
  537. .blance {
  538. max-width: 130px;
  539. }
  540. }
  541. .desc {
  542. font-size: 12px;
  543. color: #b6b6b6;
  544. margin-top: 5px;
  545. text-align: right;
  546. .desc-bottom-bar {
  547. display: flex;
  548. align-items: center;
  549. justify-content: end;
  550. margin-top: 10px;
  551. .btn {
  552. min-width: 80px;
  553. height: 29px;
  554. padding: 0 8px;
  555. box-sizing: border-box;
  556. font-weight: 400;
  557. font-size: 14px;
  558. cursor: pointer;
  559. text-align: center;
  560. border-radius: 100px;
  561. color: #5e5e5e;
  562. border: 1px solid #dfdfdf;
  563. display: flex;
  564. align-items: center;
  565. justify-content: center;
  566. }
  567. .send-btn {
  568. border: 1px solid #1d9bf0;
  569. color: #1d9bf0;
  570. }
  571. .detail-btn,
  572. .send-btn {
  573. margin-left: 8px;
  574. }
  575. }
  576. }
  577. }
  578. .icon {
  579. width: 18px;
  580. height: 24px;
  581. margin-left: 4px;
  582. margin-right: -5px;
  583. }
  584. }
  585. }
  586. .info-center {
  587. align-items: center;
  588. }
  589. }
  590. .cell-center {
  591. align-items: center;
  592. }
  593. .icon-empty {
  594. position: absolute;
  595. left: 50%;
  596. top: 50%;
  597. transform: translate(-50%, -50%);
  598. }
  599. }
  600. }
  601. }
  602. }
  603. </style>