index.vue 9.8 KB

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