popup.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <div class="page-wrapper" ref="pageWrapperDom">
  3. <div class="content">
  4. <div class="balance">
  5. <div class="wallet">
  6. <font>Balance Valuation</font>
  7. </div>
  8. </div>
  9. <div class="amount-wrapper">
  10. <div class="amount">
  11. <a-tooltip :title="'$' + canWithdrawBalance">
  12. ${{ getBit(canWithdrawBalance) }}
  13. </a-tooltip>
  14. </div>
  15. <div class="right">
  16. <div class="bill" @click="showTransactions">
  17. <red-dot class="red-dot" v-if="unReadCountWallet > 0"></red-dot>
  18. <img :src="require('@/assets/svg/icon-home-list.svg')" />
  19. </div>
  20. <img :src="require('@/assets/svg/icon-home-refresh.svg')" class="icon"
  21. :class="{ transform_rotate: iconRotate }" @click="refreshList" />
  22. </div>
  23. </div>
  24. </div>
  25. <currency-list
  26. v-if="userInfo.accessToken"
  27. style="height: calc(100% - 103px);"
  28. ref="currencyListDom"
  29. :showRefresh="false"
  30. @selectCurrency="selectCurrency"></currency-list>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, onMounted, onBeforeUnmount, inject } from "vue";
  35. import redDot from "@/view/components/red-dot.vue";
  36. import CurrencyList from "@/view/components/currency-list.vue";
  37. import {
  38. getChromeStorage,
  39. } from "@/uilts/chromeExtension";
  40. import { getBalance } from "@/http/account";
  41. import { getAllMessageInfo } from "@/http/messageApi"
  42. import { setBadgeInfo, hideBadge } from "@/logic/background/twitter";
  43. import Report from "@/log-center/log";
  44. import router from "@/router/popup.js";
  45. import { getBit } from "@/uilts/help";
  46. let withdraw_info = inject('withdraw_info')
  47. withdraw_info.paypal = {}
  48. var moment = require("moment");
  49. let userInfo = ref({});
  50. let canWithdrawBalance = ref(0);
  51. withdraw_info.paypal.amount_value = 0;
  52. withdraw_info.balance = 0
  53. let isRequestWithdrawBalance = ref(false);
  54. let currencyListDom = ref('');
  55. let iconRotate = ref(false)
  56. // 钱包未读数
  57. let unReadCountWallet = ref(0);
  58. let walletWithdrawConfig = ref({
  59. withdrawUSDPaypalFee: 0,
  60. withdrawUSDPreMinAmount: 100,
  61. withdrawUSDSwitch: "",
  62. withdrawUSDPaypalFeeDesc: ''
  63. });
  64. withdraw_info.paypal.wallet_withdraw_config = walletWithdrawConfig
  65. function selectCurrency(_params) {
  66. router.push({
  67. path: 'currencyDetail',
  68. query: {
  69. params: JSON.stringify(_params)
  70. }
  71. });
  72. }
  73. const init = () => {
  74. checkLoginState((res) => {
  75. if (res) {
  76. getAccountBalance();
  77. Report.reportLog({
  78. pageSource: Report.pageSource.denetHomePage,
  79. businessType: Report.businessType.pageView,
  80. }, {
  81. type: window.location.href.indexOf('home.html') > -1 ? 'web' : 'extensions'
  82. });
  83. setMessageCount();
  84. } else {
  85. Report.reportLog({
  86. pageSource: Report.pageSource.denetLogin,
  87. businessType: Report.businessType.pageView,
  88. });
  89. }
  90. });
  91. }
  92. const setMessageCount = () => {
  93. getAllMessageInfo({
  94. params: {
  95. }
  96. }).then(res => {
  97. if (res.code == 0) {
  98. let { unReadCountTotal = 0, unReadCountWalletDetail = 0, unReadCountTaskLuckdrop = 0 } = res.data;
  99. unReadCountWallet.value = unReadCountWalletDetail;
  100. if (unReadCountTotal > 0) {
  101. let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal + '';
  102. setBadgeInfo({ data: { text } });
  103. } else {
  104. hideBadge();
  105. }
  106. }
  107. });
  108. }
  109. /**
  110. * 获取账户余额
  111. */
  112. const getAccountBalance = () => {
  113. isRequestWithdrawBalance.value = false;
  114. getBalance({}).then((res) => {
  115. isRequestWithdrawBalance.value = true;
  116. if (res.code == 0) {
  117. if (res.data) {
  118. canWithdrawBalance.value = res.data.allAssetValuationUSD;
  119. withdraw_info.balance = res.data.allAssetValuationUSD || 0
  120. }
  121. }
  122. });
  123. };
  124. const getUserInfo = (cb) => {
  125. getChromeStorage("userInfo", (res) => {
  126. cb && cb(res);
  127. });
  128. };
  129. /**
  130. * 检查登录状态
  131. */
  132. const checkLoginState = (cb) => {
  133. getUserInfo((res) => {
  134. if (res && res.accessToken) {
  135. userInfo.value = res;
  136. } else {
  137. userInfo.value = {};
  138. }
  139. cb && cb(res);
  140. });
  141. };
  142. const showTransactions = () => {
  143. router.push('/transactions')
  144. };
  145. // 点击提现
  146. const clickWithdraw = () => {
  147. Report.reportLog({
  148. pageSource: Report.pageSource.denetHomePage,
  149. businessType: Report.businessType.buttonClick,
  150. objectType: Report.objectType.withdrawButton
  151. });
  152. router.push('/withdraw/home');
  153. }
  154. const clickTopUp = () => {
  155. Report.reportLog({
  156. pageSource: Report.pageSource.denetHomePage,
  157. businessType: Report.businessType.buttonClick,
  158. objectType: Report.objectType.topupButton
  159. });
  160. router.push('/top-up/home');
  161. }
  162. const refreshList = () => {
  163. if (iconRotate.value) {
  164. return
  165. }
  166. iconRotate.value = true
  167. setTimeout(() => {
  168. iconRotate.value = false
  169. }, 1000)
  170. getAccountBalance();
  171. if(currencyListDom.value) {
  172. currencyListDom.value.refresh && currencyListDom.value.refresh();
  173. }
  174. }
  175. const onMessage = () => {
  176. chrome.runtime.onMessage.addListener(msgListener)
  177. }
  178. const msgListener = (req, sender, sendResponse) => {
  179. ;
  180. switch (req.actionType) {
  181. case 'CONTENT_POPUP_PAGE_SHOW':
  182. init();
  183. if (currencyListDom.value) {
  184. currencyListDom.value.getCurrencyInfoList && currencyListDom.value.getCurrencyInfoList();
  185. }
  186. break;
  187. }
  188. }
  189. onMounted(() => {
  190. onMessage();
  191. init();
  192. });
  193. onBeforeUnmount(() => {
  194. chrome.runtime.onMessage.removeListener(msgListener);
  195. })
  196. </script>
  197. <style lang="scss" scoped>
  198. html,
  199. body {
  200. padding: 0 !important;
  201. margin: 0 !important;
  202. }
  203. .page-wrapper {
  204. width: 375px;
  205. height: 100%;
  206. box-sizing: border-box;
  207. overflow-y: auto;
  208. .nav-bar {
  209. padding: 14px;
  210. box-sizing: border-box;
  211. display: flex;
  212. align-items: center;
  213. justify-content: space-between;
  214. .item {
  215. display: flex;
  216. align-items: center;
  217. font-size: 13px;
  218. cursor: pointer;
  219. img {
  220. width: 16px;
  221. height: 16px;
  222. margin-right: 4px;
  223. }
  224. }
  225. .left {
  226. font-weight: 500;
  227. }
  228. .right {
  229. color: #b6b6b6;
  230. }
  231. }
  232. .content {
  233. padding: 12px 16px 10px 16px;
  234. background: #1D9BF0;
  235. box-sizing: border-box;
  236. .icon-money {
  237. width: 70px;
  238. height: 70px;
  239. }
  240. .balance {
  241. display: flex;
  242. justify-content: space-between;
  243. .wallet {
  244. font {
  245. font-size: 13px;
  246. color: #fff;
  247. opacity: 0.7;
  248. }
  249. }
  250. }
  251. .amount-wrapper {
  252. margin-top: 2px;
  253. font-weight: 700;
  254. font-size: 36px;
  255. color: #fff;
  256. display: flex;
  257. align-items: center;
  258. justify-content: space-between;
  259. .amount {
  260. display: inline-block;
  261. }
  262. .right {
  263. display: flex;
  264. align-items: center;
  265. .bill {
  266. height: 24px;
  267. width: 24px;
  268. position: relative;
  269. img {
  270. width: 24px;
  271. height: 24px;
  272. cursor: pointer;
  273. position: absolute;
  274. left: 0;
  275. top: 0;
  276. }
  277. .red-dot {
  278. position: absolute;
  279. right: 0px;
  280. top: -1px;
  281. z-index: 100;
  282. }
  283. }
  284. .icon {
  285. margin-left: 22px;
  286. cursor: pointer;
  287. }
  288. .transform_rotate {
  289. transform: rotate(360deg);
  290. transition-duration: 1s;
  291. }
  292. }
  293. }
  294. .msg {
  295. margin-top: 10px;
  296. font-size: 13px;
  297. color: #b6b6b6;
  298. }
  299. }
  300. }
  301. .page-wrapper::-webkit-scrollbar {
  302. display: none;
  303. }
  304. </style>