index.vue 22 KB

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