popup.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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" v-show="walletWithdrawConfig.withdrawUSDPaypalFeeDesc">({{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.postTaskLuckdrop.reSendAvailable">
  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.reSendAvailable"
  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.reSendAvailable
  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 isRequestWithdrawBalance = ref(false);
  246. let currentTabIndex = ref(0);
  247. let giveList = ref([]);
  248. let giveReqParams = {
  249. params: {
  250. pageNum: 1,
  251. pageSize: 10,
  252. },
  253. loadMore: false,
  254. };
  255. let walletWithdrawConfig = ref({
  256. withdrawUSDPaypalFee: 0,
  257. withdrawUSDPreMinAmount: 100,
  258. withdrawUSDSwitch: "",
  259. withdrawUSDPaypalFeeDesc: ''
  260. });
  261. let moreTabList = ref([
  262. {
  263. icon: require("../assets/svg/icon-twitter.svg"),
  264. label: "Twitter contact",
  265. },
  266. {
  267. icon: require("../assets/svg/icon-about.svg"),
  268. label: "About",
  269. },
  270. ]);
  271. let tabList = ref([
  272. {
  273. icon: require("../assets/svg/icon-giveaways.svg"),
  274. label: "Giveaways",
  275. },
  276. {
  277. icon: require("../assets/svg/icon-more.svg"),
  278. label: "More",
  279. },
  280. ]);
  281. onMounted(() => {
  282. checkLoginState(() => {
  283. if (isLogin.value) {
  284. getAccountBalance();
  285. getLuckdropRecordsList();
  286. queryWithdrawConfig();
  287. }
  288. });
  289. });
  290. /**
  291. * 获取提现配置
  292. */
  293. const queryWithdrawConfig = () => {
  294. getWithdrawConfig({
  295. params: {},
  296. }).then((res) => {
  297. console.log(res);
  298. if (res.code == 0) {
  299. walletWithdrawConfig.value = res.data;
  300. }
  301. });
  302. };
  303. /**
  304. * 获取账户余额
  305. */
  306. const getAccountBalance = () => {
  307. isRequestWithdrawBalance.value = false;
  308. getBalance({
  309. params: {
  310. currencyCode: "USD",
  311. },
  312. }).then((res) => {
  313. isRequestWithdrawBalance.value = true;
  314. if (res.code == 0) {
  315. if (res.data) {
  316. canWithdrawBalance.value = res.data.canWithdrawBalance;
  317. }
  318. }
  319. });
  320. };
  321. const getUserInfo = (cb) => {
  322. getChromeStorage("userInfo", (res) => {
  323. cb && cb(res);
  324. });
  325. };
  326. /**
  327. * 检查登录状态
  328. */
  329. const checkLoginState = (cb) => {
  330. getUserInfo((res) => {
  331. if (res && res.accessToken) {
  332. userInfo.value = res;
  333. setStorage("de-userInfo", res);
  334. isLogin.value = true;
  335. homeVisibility.value = true;
  336. } else {
  337. userInfo.value = {};
  338. isLogin.value = false;
  339. }
  340. cb && cb();
  341. });
  342. };
  343. const pageScroll = (e) => {
  344. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  345. let pageGiveListHeight = pageGiveListDom.value.offsetHeight;
  346. let scrollTop = e.target.scrollTop || 0;
  347. if (currentTabIndex.value != 0) {
  348. return;
  349. }
  350. if (
  351. giveReqParams.loadMore === false &&
  352. wrapperHeight + scrollTop >= pageGiveListHeight
  353. ) {
  354. giveReqParams.loadMore = true;
  355. giveReqParams.params.pageNum++;
  356. getLuckdropRecordsList();
  357. }
  358. };
  359. /**
  360. * 获取红包列表
  361. */
  362. const getLuckdropRecordsList = () => {
  363. getMineLuckdropRecords({
  364. params: giveReqParams.params,
  365. }).then((res) => {
  366. if (res.data && res.data.length) {
  367. if (giveReqParams.params.pageNum < 2) {
  368. giveList.value = res.data;
  369. } else {
  370. let data = giveList.value;
  371. data = data.concat(res.data);
  372. giveList.value = data;
  373. }
  374. giveReqParams.loadMore = false;
  375. }
  376. });
  377. };
  378. const clickTab = (params, index) => {
  379. currentTabIndex.value = index;
  380. console.log(params, index);
  381. };
  382. /**
  383. * 点击列表跳转到推文
  384. */
  385. const clickListItem = (params, index) => {
  386. if(!params.srcContentId) {
  387. return;
  388. }
  389. let url = "";
  390. let twitterUrl = "https://twitter.com/";
  391. let nickName = "";
  392. if (params.type == 1) {
  393. nickName = params.userInfo.nickName;
  394. } else if (params.type == 2) {
  395. nickName = userInfo.value.nickName;
  396. }
  397. url = twitterUrl + nickName + "/status/" + params.srcContentId;
  398. chrome.tabs.create({
  399. url,
  400. });
  401. };
  402. /**
  403. * 交易列表返回
  404. */
  405. const transactionsBack = () => {
  406. if (!homeVisibility.value) {
  407. if (transactionsVisibility.value) {
  408. transactionsVisibility.value = false;
  409. }
  410. homeVisibility.value = true;
  411. }
  412. };
  413. /**
  414. * 提现返回
  415. */
  416. const withdrawBack = () => {
  417. if (!homeVisibility.value) {
  418. if (withdrawVisibility.value) {
  419. withdrawVisibility.value = false;
  420. }
  421. homeVisibility.value = true;
  422. getAccountBalance();
  423. giveReqParams.params.pageNum = 1;
  424. getLuckdropRecordsList();
  425. }
  426. };
  427. const showTransactions = () => {
  428. homeVisibility.value = false;
  429. transactionsVisibility.value = true;
  430. };
  431. const clickWithdraw = () => {
  432. if(isRequestWithdrawBalance.value) {
  433. homeVisibility.value = false;
  434. withdrawVisibility.value = true;
  435. }
  436. };
  437. const loginAction = () => {
  438. login();
  439. };
  440. const login = () => {
  441. callEventPageMethod("POPUP_LOGIN", "", function (response) {
  442. console.log("res", response);
  443. });
  444. };
  445. /**
  446. * sendMessage
  447. */
  448. const callEventPageMethod = (method, data, callback) => {
  449. chrome.runtime.sendMessage(
  450. { method: method, data: data },
  451. function (response) {
  452. if (typeof callback === "function") callback(response);
  453. }
  454. );
  455. };
  456. /**
  457. * 点击发送,去发推
  458. */
  459. const sendTwitter = (params) => {
  460. console.log(params)
  461. callEventPageMethod(
  462. "POPUP_PUBLISH_TWITTER_RED_PACK",
  463. { srcContent: params.postTaskLuckdrop.srcContent, postId: params.postTaskLuckdrop.postId },
  464. function (response) {
  465. console.log("res", response);
  466. }
  467. );
  468. };
  469. </script>
  470. <style lang="scss">
  471. html,body {
  472. padding: 0 !important;
  473. margin: 0 !important;
  474. }
  475. .page-wrapper {
  476. width: 375px;
  477. height: 600px;
  478. box-sizing: border-box;
  479. overflow-y: scroll;
  480. .nav-bar {
  481. padding: 14px;
  482. box-sizing: border-box;
  483. display: flex;
  484. align-items: center;
  485. justify-content: space-between;
  486. .item {
  487. display: flex;
  488. align-items: center;
  489. font-size: 13px;
  490. cursor: pointer;
  491. img {
  492. width: 16px;
  493. height: 16px;
  494. margin-right: 4px;
  495. }
  496. }
  497. .left {
  498. font-weight: 500;
  499. }
  500. .right {
  501. color: #b6b6b6;
  502. }
  503. }
  504. .content {
  505. margin-top: 30px;
  506. text-align: center;
  507. .icon-money {
  508. width: 70px;
  509. height: 70px;
  510. }
  511. .amount {
  512. margin-top: 16px;
  513. margin-bottom: 20px;
  514. font-weight: 700;
  515. font-size: 42px;
  516. }
  517. .withdraw-btn {
  518. background: rgba(56, 154, 255, 0.01);
  519. border: 1px solid #ffb443;
  520. box-sizing: border-box;
  521. width: 120px;
  522. height: 38px;
  523. text-align: center;
  524. line-height: 38px;
  525. border-radius: 100px;
  526. color: #ffb443;
  527. display: inline-block;
  528. cursor: pointer;
  529. }
  530. .msg {
  531. margin-top: 10px;
  532. font-size: 13px;
  533. color: #b6b6b6;
  534. }
  535. }
  536. .tab-bar {
  537. display: flex;
  538. align-items: center;
  539. margin-top: 25px;
  540. position: sticky;
  541. position: -webkit-sticky;
  542. top: 0px;
  543. z-index: 1000;
  544. background-color: #fff;
  545. .tab-item {
  546. flex: 1;
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. padding: 17px 0;
  551. box-sizing: border-box;
  552. border-bottom: 1px solid #d1d1d1;
  553. cursor: pointer;
  554. .icon {
  555. width: 16px;
  556. height: 16px;
  557. margin-right: 5px;
  558. font-weight: 500;
  559. font-size: 16px;
  560. }
  561. }
  562. .active {
  563. border-bottom: 2px solid #000;
  564. }
  565. }
  566. .list-wrapper {
  567. min-height: 202px;
  568. .give-list {
  569. min-height: 202px;
  570. position: relative;
  571. .cell {
  572. display: flex;
  573. justify-content: space-between;
  574. align-items: center;
  575. height: 66px;
  576. box-sizing: border-box;
  577. padding-left: 20px;
  578. cursor: pointer;
  579. .img-wrapper {
  580. position: relative;
  581. margin-right: 16px;
  582. box-sizing: border-box;
  583. .icon-avatar {
  584. width: 34px;
  585. height: 34px;
  586. border-radius: 50%;
  587. }
  588. .icon-give {
  589. position: absolute;
  590. right: -4px;
  591. bottom: 2px;
  592. }
  593. }
  594. .info-wrapper {
  595. flex: 1;
  596. height: 100%;
  597. display: flex;
  598. justify-content: space-between;
  599. align-items: center;
  600. border-bottom: 1px solid #d1d1d1;
  601. box-sizing: border-box;
  602. padding-right: 16px;
  603. .left {
  604. .nickname {
  605. font-weight: 500;
  606. font-size: 14px;
  607. margin-bottom: 5px;
  608. }
  609. .time {
  610. font-size: 12px;
  611. color: #b6b6b6;
  612. }
  613. }
  614. .right {
  615. display: flex;
  616. align-items: center;
  617. cursor: pointer;
  618. .msg {
  619. .bold {
  620. font-weight: 500;
  621. font-size: 14px;
  622. text-align: right;
  623. }
  624. .desc {
  625. font-size: 12px;
  626. color: #b6b6b6;
  627. display: flex;
  628. align-items: center;
  629. justify-content: end;
  630. margin-top: 5px;
  631. .send-btn {
  632. height: 24px;
  633. width: 54px;
  634. line-height: 24px;
  635. text-align: center;
  636. border-radius: 100px;
  637. border: 1px solid #389aff;
  638. color: #389aff;
  639. font-weight: 500;
  640. font-size: 14px;
  641. cursor: pointer;
  642. margin-left: 8px;
  643. }
  644. }
  645. }
  646. .icon {
  647. width: 18px;
  648. height: 24px;
  649. margin-left: 4px;
  650. }
  651. }
  652. }
  653. }
  654. .icon-empty {
  655. position: absolute;
  656. left: 50%;
  657. top: 50%;
  658. transform: translate(-50%, -50%);
  659. }
  660. }
  661. .more-list {
  662. .cell {
  663. display: flex;
  664. justify-content: space-between;
  665. align-items: center;
  666. height: 66px;
  667. box-sizing: border-box;
  668. padding-left: 20px;
  669. .icon {
  670. width: 42px;
  671. height: 42px;
  672. border-radius: 50%;
  673. }
  674. .info-wrapper {
  675. flex: 1;
  676. height: 100%;
  677. display: flex;
  678. justify-content: space-between;
  679. align-items: center;
  680. border-bottom: 1px solid #d1d1d1;
  681. box-sizing: border-box;
  682. padding-right: 16px;
  683. .left {
  684. font-weight: 500;
  685. font-size: 16px;
  686. }
  687. .right {
  688. display: flex;
  689. align-items: center;
  690. cursor: pointer;
  691. .icon {
  692. width: 18px;
  693. height: 24px;
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. }
  701. .page-wrapper::-webkit-scrollbar {
  702. display: none;
  703. }
  704. </style>