index.vue 13 KB

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