index.vue 9.1 KB

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