popup.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <template>
  2. <div class="page-wrapper" ref="pageWrapperDom" @scroll="pageScroll">
  3. <template v-if="isLogin && homeVisibility">
  4. <div class="nav-bar">
  5. <div class="item left">
  6. <img :src="require('../assets/svg/icon-denet-logo.svg')" />
  7. DeNet
  8. </div>
  9. <div class="item right" @click="showTransactions">
  10. <img :src="require('../assets/svg/icon-option-list.svg')" />
  11. Transactions
  12. </div>
  13. </div>
  14. <div class="content">
  15. <img
  16. :src="require('../assets/svg/icon-money.svg')"
  17. class="icon-money"
  18. />
  19. <div class="amount">${{ canWithdrawBalance / 100 }}</div>
  20. <div class="withdraw-btn" @click="clickWithdraw">Withdraw</div>
  21. <div class="msg">({{walletWithdrawConfig.withdrawUSDPaypalFeeDesc}})</div>
  22. </div>
  23. <div class="tab-bar">
  24. <div
  25. class="tab-item"
  26. :class="{ active: currentTabIndex == index }"
  27. v-for="(item, index) in tabList"
  28. :key="index"
  29. @click="clickTab(item, index)"
  30. >
  31. <img :src="item.icon" class="icon" />
  32. {{ item.label }}
  33. </div>
  34. </div>
  35. <div class="list-wrapper" ref="pageGiveListDom">
  36. <div class="give-list" v-if="currentTabIndex == 0">
  37. <template v-if="giveList.length">
  38. <div
  39. class="cell"
  40. v-for="(item, index) in giveList"
  41. :key="index"
  42. @click="clickListItem(item, index)"
  43. >
  44. <div class="img-wrapper">
  45. <!-- 收到红包 -->
  46. <template v-if="item.type == 1">
  47. <img
  48. class="icon-avatar"
  49. :src="item.userInfo.avatarUrl"
  50. />
  51. <img
  52. class="icon-give"
  53. :src="
  54. require('../assets/svg/icon-giveaways.svg')
  55. "
  56. />
  57. </template>
  58. <!-- 发出去红包 -->
  59. <template v-else-if="2">
  60. <img
  61. :src="
  62. require('../assets/svg/icon-list-big-give.svg')
  63. "
  64. />
  65. </template>
  66. </div>
  67. <div class="info-wrapper">
  68. <div class="left">
  69. <div class="nickname">
  70. {{
  71. item.type == 1
  72. ? item.userInfo.nickName
  73. : "Giveaways"
  74. }}
  75. </div>
  76. <div class="time">
  77. {{
  78. moment(item.timestamp).format(
  79. "MM-DD hh:mm:ss"
  80. )
  81. }}
  82. </div>
  83. </div>
  84. <div class="right">
  85. <div class="msg">
  86. <div class="bold">
  87. <!-- 收到的 -->
  88. <template v-if="item.type == 1">
  89. <!-- 进行中-->
  90. <template
  91. v-if="item.status == 0"
  92. >
  93. in progress
  94. </template>
  95. <!-- 已完成 -->
  96. <template
  97. v-else-if="item.status == 1"
  98. >
  99. ${{ item.amount / 100 }}
  100. </template>
  101. <!-- 已过期 -->
  102. <template
  103. v-else-if="item.status == 2"
  104. >
  105. Timeout
  106. </template>
  107. </template>
  108. <!-- 发出去的 -->
  109. <template
  110. v-else-if="item.type == 2"
  111. >
  112. -${{ item.amount / 100 }}
  113. </template>
  114. </div>
  115. <!-- 发出的红包显示 -->
  116. <div class="desc" v-if="item.type == 2">
  117. <!-- 未发送-->
  118. <template v-if="item.status == 0">
  119. Unpublished
  120. </template>
  121. <!-- 进行中 -->
  122. <template
  123. v-else-if="item.status == 1"
  124. >
  125. {{
  126. item.postTaskLuckdrop
  127. .receivedCount
  128. }}/{{
  129. item.postTaskLuckdrop
  130. .totalCount
  131. }}
  132. </template>
  133. <!-- 已结束 -->
  134. <template
  135. v-else-if="item.status == 2"
  136. >
  137. (Time expired)
  138. {{
  139. item.postTaskLuckdrop
  140. .receivedCount
  141. }}/{{
  142. item.postTaskLuckdrop
  143. .totalCount
  144. }}
  145. </template>
  146. <!-- 红包未发出显示 -->
  147. <div
  148. v-if="!item.postTaskLuckdrop.srcPublishStatus"
  149. class="send-btn"
  150. @click.stop="sendTwitter(item)"
  151. >
  152. Send
  153. </div>
  154. </div>
  155. </div>
  156. <!-- 发红包,红包未发出隐藏-->
  157. <img
  158. v-if="
  159. !(
  160. item.type == 2 &&
  161. !item.postTaskLuckdrop.srcPublishStatus
  162. )
  163. "
  164. class="icon"
  165. :src="
  166. require('../assets/svg/icon-cell-arrow-right.svg')
  167. "
  168. />
  169. </div>
  170. </div>
  171. </div>
  172. </template>
  173. <template v-else>
  174. <img
  175. class="icon-empty"
  176. :src="require('../assets/svg/icon-empty-list.svg')"
  177. />
  178. </template>
  179. </div>
  180. <div class="more-list" v-else>
  181. <div
  182. class="cell"
  183. v-for="(item, index) in moreTabList"
  184. :key="index"
  185. >
  186. <img class="icon" :src="item.icon" />
  187. <div class="info-wrapper">
  188. <div class="left">
  189. {{ item.label }}
  190. </div>
  191. <div class="right">
  192. <img
  193. class="icon"
  194. :src="
  195. require('../assets/svg/icon-cell-arrow-right.svg')
  196. "
  197. />
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </div>
  203. </template>
  204. <!-- login -->
  205. <option-login v-if="!isLogin" @loginAction="loginAction" />
  206. <template v-if="isLogin && !homeVisibility">
  207. <!-- 交易列表 -->
  208. <option-transactions
  209. v-if="transactionsVisibility"
  210. @back="transactionsBack"
  211. />
  212. <!-- 提现页 -->
  213. <option-withdraw
  214. :amountValue="canWithdrawBalance"
  215. :walletWithdrawConfig="walletWithdrawConfig"
  216. v-if="withdrawVisibility"
  217. @back="withdrawBack"
  218. />
  219. </template>
  220. </div>
  221. </template>
  222. <script setup>
  223. /* eslint-disable */
  224. import { ref, reactive, onMounted, watch } from "vue";
  225. import optionTransactions from "./components/options-transactions";
  226. import optionLogin from "./components/option-login.vue";
  227. import optionWithdraw from "./components/option-withdraw.vue";
  228. import {
  229. getChromeStorage,
  230. } from "../uilts/chromeExtension";
  231. import {
  232. setStorage,
  233. getStorage,
  234. } from "../uilts/help";
  235. import { getBalance, getMineLuckdropRecords, getWithdrawConfig } from "../http/account";
  236. var moment = require("moment");
  237. let pageWrapperDom = ref(null);
  238. let pageGiveListDom = ref(null);
  239. let isLogin = ref(false);
  240. let homeVisibility = ref(false);
  241. let transactionsVisibility = ref(false);
  242. let withdrawVisibility = ref(false);
  243. let userInfo = ref({});
  244. let canWithdrawBalance = ref(0);
  245. let currentTabIndex = ref(0);
  246. let giveList = ref([]);
  247. let giveReqParams = {
  248. params: {
  249. pageNum: 1,
  250. pageSize: 10,
  251. },
  252. loadMore: false,
  253. };
  254. let walletWithdrawConfig = ref({
  255. withdrawUSDPaypalFee: 0,
  256. withdrawUSDPreMinAmount: 100,
  257. withdrawUSDSwitch: "",
  258. withdrawUSDPaypalFeeDesc: ''
  259. });
  260. let moreTabList = ref([
  261. {
  262. icon: require("../assets/svg/icon-twitter.svg"),
  263. label: "Twitter contact",
  264. },
  265. {
  266. icon: require("../assets/svg/icon-about.svg"),
  267. label: "About",
  268. },
  269. ]);
  270. let tabList = ref([
  271. {
  272. icon: require("../assets/svg/icon-giveaways.svg"),
  273. label: "Giveaways",
  274. },
  275. {
  276. icon: require("../assets/svg/icon-more.svg"),
  277. label: "More",
  278. },
  279. ]);
  280. onMounted(() => {
  281. checkLoginState(() => {
  282. if (isLogin.value) {
  283. getAccountBalance();
  284. getLuckdropRecordsList();
  285. queryWithdrawConfig();
  286. }
  287. });
  288. });
  289. /**
  290. * 获取提现配置
  291. */
  292. const queryWithdrawConfig = () => {
  293. getWithdrawConfig({
  294. params: {},
  295. }).then((res) => {
  296. console.log(res);
  297. if (res.code == 0) {
  298. walletWithdrawConfig.value = res.data;
  299. }
  300. });
  301. };
  302. /**
  303. * 获取账户余额
  304. */
  305. const getAccountBalance = () => {
  306. getBalance({
  307. params: {
  308. currencyCode: "USD",
  309. },
  310. }).then((res) => {
  311. if (res.code == 0) {
  312. if (res.data) {
  313. canWithdrawBalance.value = res.data.canWithdrawBalance;
  314. }
  315. }
  316. });
  317. };
  318. const getUserInfo = (cb) => {
  319. getChromeStorage("userInfo", (res) => {
  320. cb && cb(res);
  321. });
  322. };
  323. /**
  324. * 检查登录状态
  325. */
  326. const checkLoginState = (cb) => {
  327. getUserInfo((res) => {
  328. if (res && res.accessToken) {
  329. userInfo.value = res;
  330. setStorage("de-userInfo", res);
  331. isLogin.value = true;
  332. homeVisibility.value = true;
  333. } else {
  334. userInfo.value = {};
  335. isLogin.value = false;
  336. }
  337. cb && cb();
  338. });
  339. };
  340. const pageScroll = (e) => {
  341. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  342. let pageGiveListHeight = pageGiveListDom.value.offsetHeight;
  343. let scrollTop = e.target.scrollTop || 0;
  344. if (currentTabIndex.value != 0) {
  345. return;
  346. }
  347. if (
  348. giveReqParams.loadMore === false &&
  349. wrapperHeight + scrollTop >= pageGiveListHeight
  350. ) {
  351. giveReqParams.loadMore = true;
  352. giveReqParams.params.pageNum++;
  353. getLuckdropRecordsList();
  354. }
  355. };
  356. /**
  357. * 获取红包列表
  358. */
  359. const getLuckdropRecordsList = () => {
  360. getMineLuckdropRecords({
  361. params: giveReqParams.params,
  362. }).then((res) => {
  363. if (res.data && res.data.length) {
  364. if (giveReqParams.params.pageNum < 2) {
  365. giveList.value = res.data;
  366. } else {
  367. let data = giveList.value;
  368. data = data.concat(res.data);
  369. giveList.value = data;
  370. }
  371. giveReqParams.loadMore = false;
  372. }
  373. });
  374. };
  375. const clickTab = (params, index) => {
  376. currentTabIndex.value = index;
  377. console.log(params, index);
  378. };
  379. /**
  380. * 点击列表跳转到推文
  381. */
  382. const clickListItem = (params, index) => {
  383. if(!params.srcContentId) {
  384. return;
  385. }
  386. let url = "";
  387. let twitterUrl = "https://twitter.com/";
  388. let nickName = "";
  389. if (params.type == 1) {
  390. nickName = params.userInfo.nickName;
  391. } else if (params.type == 2) {
  392. nickName = userInfo.value.nickName;
  393. }
  394. url = twitterUrl + nickName + "/status/" + params.srcContentId;
  395. chrome.tabs.create({
  396. url,
  397. });
  398. };
  399. /**
  400. * 交易列表返回
  401. */
  402. const transactionsBack = () => {
  403. if (!homeVisibility.value) {
  404. if (transactionsVisibility.value) {
  405. transactionsVisibility.value = false;
  406. }
  407. homeVisibility.value = true;
  408. }
  409. };
  410. /**
  411. * 提现返回
  412. */
  413. const withdrawBack = () => {
  414. if (!homeVisibility.value) {
  415. if (withdrawVisibility.value) {
  416. withdrawVisibility.value = false;
  417. }
  418. homeVisibility.value = true;
  419. getAccountBalance();
  420. getLuckdropRecordsList();
  421. }
  422. };
  423. const showTransactions = () => {
  424. homeVisibility.value = false;
  425. transactionsVisibility.value = true;
  426. };
  427. const clickWithdraw = () => {
  428. homeVisibility.value = false;
  429. withdrawVisibility.value = true;
  430. };
  431. const loginAction = () => {
  432. login();
  433. };
  434. const login = () => {
  435. callEventPageMethod("POPUP_LOGIN", "", function (response) {
  436. console.log("res", response);
  437. });
  438. };
  439. /**
  440. * sendMessage
  441. */
  442. const callEventPageMethod = (method, data, callback) => {
  443. chrome.runtime.sendMessage(
  444. { method: method, data: data },
  445. function (response) {
  446. if (typeof callback === "function") callback(response);
  447. }
  448. );
  449. };
  450. /**
  451. * 点击发送,去发推
  452. */
  453. const sendTwitter = (params) => {
  454. callEventPageMethod(
  455. "POPUP_PUBLISH_TWITTER_RED_PACK",
  456. { srcContent: params.postTaskLuckdrop.srcContent },
  457. function (response) {
  458. console.log("res", response);
  459. }
  460. );
  461. };
  462. </script>
  463. <style lang="scss" scoped>
  464. .page-wrapper {
  465. width: 375px;
  466. height: 600px;
  467. box-sizing: border-box;
  468. overflow-y: scroll;
  469. .nav-bar {
  470. padding: 14px;
  471. box-sizing: border-box;
  472. display: flex;
  473. align-items: center;
  474. justify-content: space-between;
  475. .item {
  476. display: flex;
  477. align-items: center;
  478. font-size: 13px;
  479. cursor: pointer;
  480. img {
  481. width: 16px;
  482. height: 16px;
  483. margin-right: 4px;
  484. }
  485. }
  486. .left {
  487. font-weight: 500;
  488. }
  489. .right {
  490. color: #b6b6b6;
  491. }
  492. }
  493. .content {
  494. margin-top: 30px;
  495. text-align: center;
  496. .icon-money {
  497. width: 70px;
  498. height: 70px;
  499. }
  500. .amount {
  501. margin-top: 16px;
  502. margin-bottom: 20px;
  503. font-weight: 700;
  504. font-size: 42px;
  505. }
  506. .withdraw-btn {
  507. background: rgba(56, 154, 255, 0.01);
  508. border: 1px solid #ffb443;
  509. box-sizing: border-box;
  510. width: 120px;
  511. height: 38px;
  512. text-align: center;
  513. line-height: 38px;
  514. border-radius: 100px;
  515. color: #ffb443;
  516. display: inline-block;
  517. cursor: pointer;
  518. }
  519. .msg {
  520. margin-top: 10px;
  521. font-size: 13px;
  522. color: #b6b6b6;
  523. }
  524. }
  525. .tab-bar {
  526. display: flex;
  527. align-items: center;
  528. margin-top: 25px;
  529. position: sticky;
  530. position: -webkit-sticky;
  531. top: 0px;
  532. z-index: 1000;
  533. background-color: #fff;
  534. .tab-item {
  535. flex: 1;
  536. display: flex;
  537. align-items: center;
  538. justify-content: center;
  539. padding: 17px 0;
  540. box-sizing: border-box;
  541. border-bottom: 1px solid #d1d1d1;
  542. cursor: pointer;
  543. .icon {
  544. width: 16px;
  545. height: 16px;
  546. margin-right: 5px;
  547. font-weight: 500;
  548. font-size: 16px;
  549. }
  550. }
  551. .active {
  552. border-bottom: 2px solid #000;
  553. }
  554. }
  555. .list-wrapper {
  556. min-height: 202px;
  557. .give-list {
  558. min-height: 202px;
  559. position: relative;
  560. .cell {
  561. display: flex;
  562. justify-content: space-between;
  563. align-items: center;
  564. height: 66px;
  565. box-sizing: border-box;
  566. padding-left: 20px;
  567. cursor: pointer;
  568. .img-wrapper {
  569. position: relative;
  570. margin-right: 16px;
  571. box-sizing: border-box;
  572. .icon-avatar {
  573. width: 34px;
  574. height: 34px;
  575. border-radius: 50%;
  576. }
  577. .icon-give {
  578. position: absolute;
  579. right: -4px;
  580. bottom: 2px;
  581. }
  582. }
  583. .info-wrapper {
  584. flex: 1;
  585. height: 100%;
  586. display: flex;
  587. justify-content: space-between;
  588. align-items: center;
  589. border-bottom: 1px solid #d1d1d1;
  590. box-sizing: border-box;
  591. padding-right: 16px;
  592. .left {
  593. .nickname {
  594. font-weight: 500;
  595. font-size: 14px;
  596. margin-bottom: 5px;
  597. }
  598. .time {
  599. font-size: 12px;
  600. color: #b6b6b6;
  601. }
  602. }
  603. .right {
  604. display: flex;
  605. align-items: center;
  606. cursor: pointer;
  607. .msg {
  608. .bold {
  609. font-weight: 500;
  610. font-size: 14px;
  611. text-align: right;
  612. }
  613. .desc {
  614. font-size: 12px;
  615. color: #b6b6b6;
  616. display: flex;
  617. align-items: center;
  618. justify-content: end;
  619. margin-top: 5px;
  620. .send-btn {
  621. height: 24px;
  622. width: 54px;
  623. line-height: 24px;
  624. text-align: center;
  625. border-radius: 100px;
  626. border: 1px solid #389aff;
  627. color: #389aff;
  628. font-weight: 500;
  629. font-size: 14px;
  630. cursor: pointer;
  631. margin-left: 8px;
  632. }
  633. }
  634. }
  635. .icon {
  636. width: 18px;
  637. height: 24px;
  638. margin-left: 4px;
  639. }
  640. }
  641. }
  642. }
  643. .icon-empty {
  644. position: absolute;
  645. left: 50%;
  646. top: 50%;
  647. transform: translate(-50%, -50%);
  648. }
  649. }
  650. .more-list {
  651. .cell {
  652. display: flex;
  653. justify-content: space-between;
  654. align-items: center;
  655. height: 66px;
  656. box-sizing: border-box;
  657. padding-left: 20px;
  658. .icon {
  659. width: 42px;
  660. height: 42px;
  661. border-radius: 50%;
  662. }
  663. .info-wrapper {
  664. flex: 1;
  665. height: 100%;
  666. display: flex;
  667. justify-content: space-between;
  668. align-items: center;
  669. border-bottom: 1px solid #d1d1d1;
  670. box-sizing: border-box;
  671. padding-right: 16px;
  672. .left {
  673. font-weight: 500;
  674. font-size: 16px;
  675. }
  676. .right {
  677. display: flex;
  678. align-items: center;
  679. cursor: pointer;
  680. .icon {
  681. width: 18px;
  682. height: 24px;
  683. }
  684. }
  685. }
  686. }
  687. }
  688. }
  689. }
  690. .page-wrapper::-webkit-scrollbar {
  691. display: none;
  692. }
  693. </style>