header.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="header">
  3. <img class="logo" src="../static/img/logo.svg" alt="DeNet" />
  4. <div class="operation">
  5. <!-- <div class="login" @click="twitterAuth">
  6. <img class="add" src="../static/img/header-add.svg" alt="">
  7. <span>Create NFTs</span>
  8. </div> -->
  9. <div class="down" @click="install">
  10. <div class="text">Install DeNet</div>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="header-place"></div>
  15. </template>
  16. <script lang="ts" setup>
  17. import Api from '../static/http/api'
  18. import { postRequest } from '../static/http'
  19. import { getMid, appVersionCode, getOauthUrl, createWindow, callBackUrl } from '../static/utils'
  20. import { getStorage, removeStorage, setStorage, storageKey } from '../static/utils/storage'
  21. import { ref } from 'vue'
  22. import { useRouter } from 'vue-router'
  23. import { ElMessage } from 'element-plus'
  24. const timer = ref(0)
  25. const router = useRouter()
  26. const install = () => {
  27. window.open(`https://chrome.google.com/webstore/detail/denet/inlfbeejfdgkknpiodhemfcokbdgofja`);
  28. }
  29. const twitterAuth = () => {
  30. postRequest(Api.twitterRequestToken, {
  31. baseInfo: {
  32. mid: getMid(),
  33. appVersionCode,
  34. },
  35. params: {
  36. oauthCallback: callBackUrl
  37. }
  38. }).then(res => {
  39. let { code, data, msg } = res;
  40. if ( code === 0 ) {
  41. let url = getOauthUrl(data.authToken);
  42. let win = createWindow(url);
  43. timer.value = setInterval(() => {
  44. if (win && win.closed) {
  45. clearInterval(timer.value);
  46. twitterLogin(data);
  47. }
  48. }, 500)
  49. } else {
  50. ElMessage({
  51. offset: 100,
  52. type: 'error',
  53. message: msg,
  54. })
  55. }
  56. })
  57. }
  58. const twitterLogin = (data: { authToken: string, consumerKey: string }) => {
  59. let verifier = getStorage(storageKey.verifier)
  60. if (verifier) {
  61. postRequest(Api.twitterLogin, {
  62. baseInfo: {
  63. mid: getMid(),
  64. appVersionCode,
  65. },
  66. params: {
  67. consumerKey: data.consumerKey,
  68. oauthToken: data.authToken,
  69. oauthVerifier: verifier
  70. }
  71. }).then(res => {
  72. let { code, data } = res;
  73. if ( code === 0 ) {
  74. setStorage(storageKey.userInfo, data);
  75. removeStorage(storageKey.verifier);
  76. router.push(`/nft/list`)
  77. }
  78. })
  79. }
  80. }
  81. </script>
  82. <style lang="less" scoped>
  83. .header {
  84. position: fixed;
  85. z-index: 3;
  86. display: flex;
  87. justify-content: space-between;
  88. align-items: center;
  89. top: 0;
  90. left: 0;
  91. width: 100%;
  92. height: 60px;
  93. background-color: #ffffff;
  94. box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.1);
  95. .logo {
  96. height: 38px;
  97. margin-left: 26px;
  98. }
  99. .operation {
  100. display: flex;
  101. flex-direction: row;
  102. }
  103. .login {
  104. display: flex;
  105. align-items: center;
  106. justify-content: center;
  107. box-sizing: border-box;
  108. height: 38px;
  109. cursor: pointer;
  110. padding: 0 18px;
  111. font-size: 15px;
  112. color: #1D9BF0;
  113. margin-right: 19px;
  114. border-radius: 20px;
  115. border: solid 1px #1D9BF0;
  116. .add {
  117. width: 20px;
  118. margin-right: 4px;
  119. }
  120. }
  121. .down {
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. height: 38px;
  126. cursor: pointer;
  127. padding: 0 24px;
  128. margin-right: 26px;
  129. border-radius: 20px;
  130. background: #1D9BF0;
  131. .text {
  132. color: #fff;
  133. font-size: 15px;
  134. margin-top: -2px;
  135. }
  136. }
  137. &-place {
  138. height: 60px;
  139. }
  140. }
  141. </style>