index.vue 9.9 KB

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