top.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="center">
  3. <view class="box-top">
  4. <view class="bg3" @click="test()"><image src="../../static/index/img14.png" mode=""></image></view>
  5. <view class="bg3 two" @click="foxlogin"><image src="../../static/index/img08.png" mode=""></image></view>
  6. </view>
  7. <u-popup v-model="show" mode="left" width="565rpx" border-radius="14">
  8. <view class="popup">
  9. <view class="title">
  10. <view class="title-img"><image src="../../static/img/logo.png" mode=""></image></view>
  11. <view class="text">恒星币</view>
  12. </view>
  13. <view class="hx"></view>
  14. <view class="box-left" v-for="(item, index) in cdList" @click="navTo(item.url)">
  15. <view class="box-box">
  16. <view class="box-img"><image :src="item.image" mode=""></image></view>
  17. <view class="box-title">{{ item.title }}</view>
  18. <view class="box-right"><image :src="item.right" mode=""></image></view>
  19. </view>
  20. <view class="hx1"></view>
  21. </view>
  22. </view>
  23. </u-popup>
  24. </view>
  25. </template>
  26. <script>
  27. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  28. import MetaMaskOnboarding from '@metamask/onboarding';
  29. import { mapState, mapMutations } from 'vuex';
  30. import { logins, userinfo, logout } from '@/api/login.js';
  31. export default {
  32. computed: {
  33. ...mapState('user', ['address', 'hasLogin', 'userInfo'])
  34. },
  35. data() {
  36. return {
  37. show: false,
  38. cdList: [
  39. {
  40. image: '../../static/img/cd1.png',
  41. title: '首页 ',
  42. right: '../../static/img/right.png',
  43. url: '/pages/index/index'
  44. },
  45. {
  46. image: '../../static/img/cd2.png',
  47. title: '恒星私募',
  48. right: '../../static/img/right.png',
  49. url: '/pages/private/private'
  50. },
  51. {
  52. image: '../../static/img/cd5.png',
  53. title: 'DIFI挖矿',
  54. right: '../../static/img/right.png',
  55. url: '/pages/index/Expect'
  56. },
  57. {
  58. image: '../../static/img/cd4.png',
  59. title: '我的推荐',
  60. right: '../../static/img/right.png',
  61. url: '/pages/index/share'
  62. },
  63. {
  64. image: '../../static/img/cd3.png',
  65. title: '超级节点',
  66. right: '../../static/img/right.png',
  67. url: '/pages/index/Expect'
  68. },
  69. {
  70. image: '../../static/img/cd6.png',
  71. title: '游戏版块',
  72. right: '../../static/img/right.png',
  73. url: '/pages/index/Expect'
  74. },
  75. {
  76. image: '../../static/img/cd7.png',
  77. title: '好友加速明细',
  78. right: '../../static/img/right.png',
  79. url: '/pages/index/Expect'
  80. },
  81. {
  82. image: '../../static/img/cd8.png',
  83. title: '算力奖励明细',
  84. right: '../../static/img/right.png',
  85. url: '/pages/index/Expect'
  86. },
  87. {
  88. image: '../../static/img/cd9.png',
  89. title: '社群奖励明细',
  90. right: '../../static/img/right.png',
  91. url: '/pages/index/Expect'
  92. },
  93. {
  94. image: '../../static/img/cd10.png',
  95. title: '公会奖励明细',
  96. right: '../../static/img/right.png',
  97. url: '/pages/index/Expect'
  98. }
  99. ]
  100. };
  101. },
  102. methods: {
  103. ...mapMutations('user', ['setAddress', 'setUserInfo', 'login']),
  104. navTo(url) {
  105. uni.navigateTo({
  106. url
  107. });
  108. },
  109. test() {
  110. this.show = true;
  111. console.log(this.show);
  112. },
  113. foxlogin() {
  114. const isMetaMaskInstalled = this.isMetaMaskInstalled();
  115. if (!isMetaMaskInstalled) {
  116. const forwarderOrigin = 'http://flow.frp.liuniu946.com/index/#/';
  117. const onboarding = new MetaMaskOnboarding({ forwarderOrigin });
  118. onboarding.startOnboarding();
  119. } else {
  120. try {
  121. ethereum.request({ method: 'eth_requestAccounts' });
  122. this.getaccount();
  123. } catch (error) {
  124. console.log(error, '1234556');
  125. }
  126. }
  127. },
  128. async getaccount() {
  129. const obj = this;
  130. const accounts = await ethereum.request({ method: 'eth_accounts' });
  131. if (accounts[0] == undefined) {
  132. this.foxlogin();
  133. } else {
  134. console.log(accounts[0],"123456");
  135. this.setAddress(accounts[0]);
  136. this.changeAddress();
  137. logins({ address: obj.address }).then(({ data }) => {
  138. obj.login();
  139. uni.setStorageSync('token', data.userinfo.token);
  140. userinfo().then(({ data }) => {
  141. console.log(data);
  142. obj.setUserInfo(data.data);
  143. });
  144. });
  145. }
  146. },
  147. async changeAddress() {
  148. try {
  149. await ethereum.request({
  150. method: 'wallet_switchEthereumChain',
  151. params: [{ chainId: '0x38' }]
  152. });
  153. } catch (switchError) {
  154. console.log(switchError, 'erro');
  155. // This error code indicates that the chain has not been added to MetaMask.
  156. if (switchError.code === 4902) {
  157. try {
  158. await ethereum.request({
  159. method: 'wallet_addEthereumChain',
  160. params: [
  161. {
  162. chainId: '0x38',
  163. chainName: 'BSC主网络',
  164. rpcUrls: ['https://bsc-dataseed1.binance.org/'] /* ... */,
  165. blockExplorerUrls: ['https://bscscan.com/'],
  166. nativeCurrency: {
  167. name: 'BNB',
  168. symbol: 'BNB',
  169. decimals: 18
  170. }
  171. }
  172. ]
  173. });
  174. } catch (addError) {}
  175. }
  176. }
  177. },
  178. isMetaMaskInstalled() {
  179. const { ethereum } = window;
  180. return Boolean(ethereum && ethereum.isMetaMask);
  181. },
  182. }
  183. };
  184. </script>
  185. <style lang="less">
  186. .box-top {
  187. display: flex;
  188. padding: 36rpx 41rpx 72rpx 41rpx;
  189. }
  190. image {
  191. width: 100%;
  192. height: 100%;
  193. }
  194. .bg3 {
  195. width: 56rpx;
  196. height: 62rpx;
  197. }
  198. .two {
  199. margin-left: 36rpx;
  200. }
  201. .popup {
  202. display: flex;
  203. flex-direction: column;
  204. background: linear-gradient(180deg, #00143b 0%, #000309 100%);
  205. height: 100%;
  206. .box-left {
  207. width: 530rpx;
  208. display: flex;
  209. flex-direction: column;
  210. .box-box {
  211. position: relative;
  212. display: flex;
  213. align-items: center;
  214. justify-content: flex-start;
  215. margin-left: 30rpx;
  216. }
  217. .box-img {
  218. z-index: 999;
  219. width: 35rpx;
  220. height: 35rpx;
  221. }
  222. .box-title {
  223. margin-left: 20rpx;
  224. font-size: 30rpx;
  225. font-family: PingFang SC;
  226. // font-weight: bold;
  227. color: #ffffff;
  228. line-height: 78rpx;
  229. }
  230. .box-right {
  231. position: absolute;
  232. right: 0;
  233. z-index: 999;
  234. width: 17rpx;
  235. height: 32rpx;
  236. }
  237. }
  238. .title {
  239. margin: 40rpx 190rpx;
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. .title-img {
  244. width: 186rpx;
  245. height: 193rpx;
  246. }
  247. .text {
  248. display: flex;
  249. font-size: 41rpx;
  250. font-family: zihun100hao-fangfangxianfengti;
  251. font-weight: 400;
  252. color: #ffffff;
  253. line-height: 38rpx;
  254. }
  255. }
  256. .hx {
  257. width: 565rpx;
  258. height: 12rpx;
  259. background: #ffffff;
  260. opacity: 0.23;
  261. }
  262. .hx1 {
  263. width: 565rpx;
  264. height: 2rpx;
  265. background: #ffffff;
  266. opacity: 0.1;
  267. }
  268. }
  269. </style>