index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef APP-PLUS -->
  4. <view class="vheight"></view>
  5. <!-- #endif -->
  6. <view class="flex" style="justify-content: space-between;padding: 20rpx 30rpx;">
  7. <image src="../../static/icon/user.png" mode="" style="width: 53rpx;height: 53rpx;"
  8. @click="navto('/pages/user/menu')"></image>
  9. <!-- <image src="../../static/icon/tz.png" mode="" style="width: 53rpx;height: 53rpx;"></image> -->
  10. </view>
  11. <!-- 轮播图 start -->
  12. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  13. <swiper-item v-for="item in clist" class="carousel-item" @click="bannerNavToUrl(item)">
  14. <image :src="item" />
  15. </swiper-item>
  16. </swiper>
  17. <!-- 轮播图 end -->
  18. <!-- 通告欄 start -->
  19. <u-notice-bar type="none" :more-icon="true" mode="vertical" :list="list" @click="goDetail"
  20. @getMore="navto('/pages/index/gglist')"></u-notice-bar>
  21. <!-- 通告欄 end -->
  22. <!-- 功能盒 start -->
  23. <view class="gnh-wrap">
  24. <view class="gnh-top flex">
  25. <!-- <view class="top-item flex" @click="navto('/pages/index/rg')"> -->
  26. <view class="top-item flex" @click="jqqd()">
  27. <image src="../../static/icon/gn-1.png" mode="" class=""></image>
  28. <view class="">{{ $t('index.rg') }}</view>
  29. </view>
  30. <view class="top-item flex" @click="navto('/pages/transaction/cblist')">
  31. <image src="../../static/icon/gn-2.png" mode="" class=""></image>
  32. <view class="">{{ $t('index.cb') }}</view>
  33. </view>
  34. <view class="top-item flex" @click="navto('/pages/transaction/tblist')">
  35. <image src="../../static/icon/gn-3.png" mode="" class=""></image>
  36. <view class="">{{ $t('index.tb') }}</view>
  37. </view>
  38. <view class="top-item flex" @click="navTo('/pages/index/language')">
  39. <image src="../../static/icon/gn-4.png" mode="" class=""></image>
  40. <view class="">{{ $t('index.yy') }}</view>
  41. </view>
  42. <view class="top-item flex" @click="navto('/pages/index/kf')">
  43. <image src="../../static/icon/gn-5.png" mode="" class=""></image>
  44. <view class="">{{ $t('index.kf') }}</view>
  45. </view>
  46. </view>
  47. <view class="gnh-btm flex">
  48. <view class="btm-item" @click="navto('/pages/transaction/transactionDetail?type=BTC-USDT')">
  49. <view class="btm-item-name">BTC/USDT</view>
  50. <template v-if="listOBj['BTC-USDT']">
  51. <view class="btm-item-val"
  52. :style="{ color: listOBj['BTC-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  53. {{ listOBj['BTC-USDT'].last || '--,--' }}
  54. </view>
  55. <view class="btm-item-bl"
  56. :style="{ color: listOBj['BTC-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  57. {{ listOBj['BTC-USDT'].dcf || '--,--' }}%
  58. </view>
  59. </template>
  60. </view>
  61. <view class="btm-item" @click="navto('/pages/transaction/transactionDetail?type=BCH-USDT')">
  62. <view class="btm-item-name">BCH/USDT</view>
  63. <template v-if="listOBj['BCH-USDT']">
  64. <view class="btm-item-val"
  65. :style="{ color: listOBj['BCH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  66. {{ listOBj['BCH-USDT'].last || '--,--' }}
  67. </view>
  68. <view class="btm-item-bl"
  69. :style="{ color: listOBj['BCH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  70. {{ listOBj['BCH-USDT'].dcf || '--,--' }}%
  71. </view>
  72. </template>
  73. </view>
  74. <view class="btm-item" @click="navto('/pages/transaction/transactionDetail?type=AZB-USDT')" v-if="listOBj['AZB-USDT']">
  75. <view class="btm-item-name">AZB/USDT</view>
  76. <template >
  77. <view class="btm-item-val"
  78. :style="{ color: listOBj['AZB-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  79. {{ listOBj['AZB-USDT'].last || '--,--' }}
  80. </view>
  81. <view class="btm-item-bl"
  82. :style="{ color: listOBj['AZB-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  83. {{ listOBj['AZB-USDT'].dcf || '--,--' }}%
  84. </view>
  85. </template>
  86. </view>
  87. <view class="btm-item" @click="navto('/pages/transaction/transactionDetail?type=AZB-USDT')" v-if="!listOBj['AZB-USDT']">
  88. <view class="btm-item-name">AZB/USDT</view>
  89. <template >
  90. <view class="btm-item-val"
  91. :style="{ color: listOBj['AZB-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  92. {{ listOBj['AZB-USDT'].last || '--,--' }}
  93. </view>
  94. <view class="btm-item-bl"
  95. :style="{ color: listOBj['AZB-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  96. {{ listOBj['AZB-USDT'].dcf || '--,--' }}%
  97. </view>
  98. </template>
  99. </view>
  100. <view class="btm-item" @click="navto('/pages/transaction/transactionDetail?type=ETH-USDT')">
  101. <view class="btm-item-name">ETH/USDT</view>
  102. <template v-if="listOBj['ETH-USDT']">
  103. <view class="btm-item-val"
  104. :style="{ color: listOBj['ETH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  105. {{ listOBj['ETH-USDT'].last || '--,--' }}
  106. </view>
  107. <view class="btm-item-bl"
  108. :style="{ color: listOBj['ETH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">
  109. {{ listOBj['ETH-USDT'].dcf || '--,--' }}%
  110. </view>
  111. </template>
  112. </view>
  113. </view>
  114. </view>
  115. <view class="list">
  116. <view class="list-title flex">
  117. <view class="title-left">{{ $t('index.jyd') }}</view>
  118. <view class="title-center">{{ $t('index.zxjg') }}</view>
  119. <view class="title-right">{{ $t('index.zd') }}</view>
  120. </view>
  121. <view class="list-main flex" @click="navto('/pages/transaction/transactionDetail?type=' + index)"
  122. v-for="(item, index) in listOBj">
  123. <view class="main-left">{{ item.name }}</view>
  124. <view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">
  125. {{ item.last == 0 ? '--.--' : item.last }}
  126. </view>
  127. <view class="main-right">
  128. <view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
  129. </view>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. <script>
  135. import {
  136. tradelist,
  137. gcb,
  138. version
  139. } from '@/api/login.js';
  140. import {
  141. saveUrl,
  142. interceptor
  143. } from '@/utils/loginUtils.js';
  144. import {
  145. mapState,
  146. mapMutations
  147. } from 'vuex';
  148. import {
  149. scoketNew,
  150. scoketOpen
  151. } from '@/utils/socket.js';
  152. import {
  153. geLevertade,
  154. gglist
  155. } from '@/api/index.js';
  156. export default {
  157. data() {
  158. return {
  159. timer: '',
  160. clist: {},
  161. scoket: '',
  162. instId: 'IOTA-USDT', //请求的产品id
  163. spList: [], //需要查询的列表
  164. list: [],
  165. listInfo: [],
  166. listOBj: {
  167. 'BTC-USDT': {},
  168. 'ETH-USDT': {}
  169. } //保存实际列表对象
  170. };
  171. },
  172. computed: {
  173. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  174. },
  175. onLoad: function(option) {
  176. if (this.timer) {
  177. clearTimeout(this.timer);
  178. this.timer = null;
  179. }
  180. uni.setNavigationBarTitle({
  181. title: this.$t('index.sy')
  182. });
  183. },
  184. onShow: function() {
  185. this.geLevertade();
  186. this.tradelist();
  187. this.getgg();
  188. this.gcb()
  189. this.ww()
  190. },
  191. onHide() {
  192. this.closeScoket();
  193. clearTimeout(this.timer);
  194. },
  195. onUnload() {
  196. clearTimeout(this.timer);
  197. },
  198. //下拉刷新
  199. onPullDownRefresh() {},
  200. methods: {
  201. navto(url) {
  202. console.log(url);
  203. if (!this.hasLogin) {
  204. // 保存地址
  205. saveUrl();
  206. // 登录拦截
  207. interceptor();
  208. } else {
  209. uni.navigateTo({
  210. url
  211. });
  212. }
  213. },
  214. navTo(url) {
  215. uni.navigateTo({
  216. url,
  217. fail() {
  218. uni.switchTab({
  219. url
  220. })
  221. }
  222. });
  223. },
  224. gcb() {
  225. let that = this
  226. gcb().then(res => {
  227. console.log(res,'1')
  228. let data = res.data
  229. that.listOBj[data.name] = data
  230. that.listOBj[data.name].dcf = (((data.last * 1 - data.sodUtc0 * 1) / (data.sodUtc0 * 1)) * 100)
  231. .toFixed(2);
  232. clog
  233. that.listOBj[data.name].name = data.name.replace('-', '/')
  234. console.log(that.listOBj, 'that.listOBj')
  235. if (that.timer) {
  236. clearTimeout(that.timer)
  237. that.timer = null
  238. }
  239. that.timer = setTimeout(() => {
  240. that.gcb()
  241. },5000)
  242. })
  243. },
  244. jqqd() {
  245. this.$api.msg(this.$t('zxt.jqqd'));
  246. },
  247. goDetail(e) {
  248. uni.navigateTo({
  249. url: '/pages/index/ggDetail?id=' + this.listInfo[e].id
  250. });
  251. },
  252. getgg() {
  253. const obj = this;
  254. gglist({
  255. page: 1,
  256. limit: 1000
  257. }).then(e => {
  258. obj.listInfo = e.data;
  259. e.data.forEach(e => {
  260. obj.list.push(e.title);
  261. });
  262. });
  263. },
  264. swiperChange() {},
  265. // 开始请求长连接
  266. onScoket() {
  267. const that = this;
  268. that.scoket = scoketNew('wss://wsaws.okx.com:8443/ws/v5/public');
  269. that.scoket.scoketOpen().then(res => {
  270. const requestList = that.spList.map(e => {
  271. return {
  272. channel: 'tickers',
  273. instId: e.coinname.toUpperCase() + '-USDT'
  274. };
  275. });
  276. that.scoket
  277. .scoketSend({
  278. op: 'subscribe',
  279. args: requestList
  280. })
  281. .then(res => {
  282. console.log(res, '发送成功');
  283. });
  284. that.scoket.scoketMessage(res => {
  285. try {
  286. if (res.data) {
  287. // console.log(res.data, '123456');
  288. that.listOBj[res.arg.instId] = res.data[0];
  289. const item = that.listOBj[res.arg.instId];
  290. item.dcf = (((item.last * 1 - item.sodUtc0 * 1) / (item.sodUtc0 * 1)) *
  291. 100).toFixed(2);
  292. item.name = item.instId.replace('-', '/');
  293. // res.res.data[0].name = res.arg.instId
  294. // that.listOBj[res.arg.instId] = res.data[0];
  295. // that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  296. that.listOBj = Object.assign({}, that.listOBj);
  297. }
  298. // console.log(that.listOBj, 'that.listOBj++++++');
  299. } catch (e) {
  300. console.log(res, res.data, '报错');
  301. }
  302. });
  303. });
  304. },
  305. closeScoket() {
  306. this.scoket.scoketClose();
  307. },
  308. // 获取查询列表
  309. geLevertade() {
  310. const that = this;
  311. geLevertade().then(e => {
  312. that.spList = e.list;
  313. // 开启长连接
  314. that.onScoket();
  315. });
  316. },
  317. // 轮播图跳转
  318. bannerNavToUrl(item) {
  319. // #ifdef H5
  320. console.log(item.wap_url.indexOf('http'), 'banner');
  321. if (item.wap_url.indexOf('http') >= 0) {
  322. window.location.href = item.wap_url;
  323. }
  324. // #endif
  325. //测试数据没有写id,用title代替
  326. uni.navigateTo({
  327. url: item.wap_url
  328. });
  329. },
  330. tradelist() {
  331. tradelist().then(res => {
  332. console.log(res);
  333. this.clist = res.data.clist;
  334. this.clist = Object.assign({}, this.clist);
  335. console.log(this.clist, 'this.clist');
  336. });
  337. },
  338. down() {
  339. version().then(res => {
  340. console.log(res)
  341. window.open(res.data.app)
  342. })
  343. },
  344. ww() {
  345. }
  346. }
  347. };
  348. </script>
  349. <style lang="scss">
  350. // 顶部轮播图
  351. .top-swiper {
  352. margin: auto;
  353. width: 726rpx;
  354. height: 273rpx;
  355. .carousel-item {}
  356. // margin: 20rpx 0 0;
  357. image {
  358. // margin: auto;
  359. width: 726rpx;
  360. height: 273rpx;
  361. }
  362. }
  363. .gnh-wrap {
  364. margin: 20rpx 0;
  365. width: 750rpx;
  366. min-height: 315rpx;
  367. padding-bottom: 20rpx;
  368. background-color: #fff;
  369. border-radius: 50rpx 50rpx 0 0;
  370. .gnh-top {
  371. justify-content: space-around;
  372. height: 156rpx;
  373. .top-item {
  374. flex-direction: column;
  375. justify-content: center;
  376. align-items: center;
  377. image {
  378. width: 66rpx;
  379. height: 75rpx;
  380. }
  381. view {
  382. font-weight: 500;
  383. color: #525c6e;
  384. }
  385. }
  386. }
  387. .gnh-btm {
  388. justify-content: space-around;
  389. .btm-item {
  390. width: 33%;
  391. text-align: center;
  392. padding-top: 20rpx;
  393. .btm-item-name {
  394. font-size: 24rpx;
  395. font-weight: 500;
  396. color: #525c6e;
  397. }
  398. .btm-item-val {
  399. font-size: 26rpx;
  400. font-weight: 500;
  401. color: #dd3745;
  402. padding: 20rpx 0;
  403. }
  404. .btm-item-bl {
  405. font-size: 24rpx;
  406. font-weight: 500;
  407. color: #dd3745;
  408. }
  409. }
  410. }
  411. }
  412. .list {
  413. background: #ffffff;
  414. border-top-left-radius: 26rpx;
  415. border-top-right-radius: 26rpx;
  416. padding: 40rpx 15rpx 0;
  417. .list-title {
  418. font-size: 28rpx;
  419. font-family: PingFang SC;
  420. font-weight: 500;
  421. color: #525c6e;
  422. padding-bottom: 32rpx;
  423. .title-left {
  424. text-align: left;
  425. width: 33%;
  426. }
  427. .title-center {
  428. text-align: center;
  429. width: 33%;
  430. }
  431. .title-right {
  432. text-align: right;
  433. width: 33%;
  434. }
  435. }
  436. .list-main {
  437. padding: 12rpx 0;
  438. .main-left {
  439. text-align: left;
  440. width: 33%;
  441. font-size: 28rpx;
  442. font-family: PingFang SC;
  443. font-weight: 500;
  444. color: #525c6e;
  445. }
  446. .main-center {
  447. text-align: center;
  448. width: 33%;
  449. font-size: 28rpx;
  450. font-family: PingFang SC;
  451. font-weight: 500;
  452. color: #e15560;
  453. &.down {
  454. color: #5ec886;
  455. }
  456. &.ping {
  457. color: #525c6e;
  458. }
  459. }
  460. .main-right {
  461. text-align: right;
  462. width: 33%;
  463. display: flex;
  464. justify-content: flex-end;
  465. .btn {
  466. width: 122rpx;
  467. height: 63rpx;
  468. background: #e15562;
  469. border-radius: 5rpx;
  470. text-align: center;
  471. line-height: 63rpx;
  472. font-size: 24rpx;
  473. font-family: PingFang SC;
  474. font-weight: 500;
  475. color: #ffffff;
  476. &.down {
  477. background: #5ec886;
  478. }
  479. &.ping {
  480. background: #f6f6f6;
  481. }
  482. }
  483. }
  484. }
  485. }
  486. .vheight {
  487. height: var(--status-bar-height);
  488. }
  489. .wwdown {
  490. // padding: 20rpx;
  491. image {
  492. width: 750rpx;
  493. }
  494. margin-bottom: 20rpx;
  495. font-size: 24rpx;
  496. text-align: right;
  497. color: #525c6e;
  498. }
  499. </style>