index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 in clist" class="carousel-item" @click="bannerNavToUrl(item)">
  10. <image :src="item" />
  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 { tradelist} from '@/api/login.js'
  101. import {
  102. saveUrl,
  103. interceptor,
  104. } from '@/utils/loginUtils.js';
  105. import {
  106. mapState,
  107. mapMutations
  108. } from 'vuex';
  109. import {
  110. scoketNew,
  111. scoketOpen
  112. } from '@/utils/socket.js';
  113. import {
  114. geLevertade
  115. } from '@/api/index.js';
  116. export default {
  117. data() {
  118. return {
  119. clist: {},
  120. scoket: '',
  121. instId: 'IOTA-USDT', //请求的产品id
  122. spList: [], //需要查询的列表
  123. listOBj: {} //保存实际列表对象
  124. };
  125. },
  126. computed: {
  127. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  128. },
  129. onLoad: function(option) {
  130. },
  131. onShow: function() {
  132. this.geLevertade()
  133. this.tradelist()
  134. },
  135. onHide() {
  136. this.closeScoket()
  137. },
  138. //下拉刷新
  139. onPullDownRefresh() {
  140. },
  141. methods: {
  142. navto(url) {
  143. console.log(url);
  144. if (!this.hasLogin) {
  145. // 保存地址
  146. saveUrl();
  147. // 登录拦截
  148. interceptor();
  149. } else {
  150. uni.navigateTo({
  151. url
  152. });
  153. }
  154. },
  155. swiperChange() {
  156. },
  157. // 开始请求长连接
  158. onScoket() {
  159. const that = this;
  160. that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
  161. that.scoket.scoketOpen().then((res) => {
  162. const requestList = that.spList.map((e) => {
  163. return {
  164. "channel": "tickers",
  165. "instId": e.coinname.toUpperCase() + "-USDT"
  166. }
  167. })
  168. that.scoket.scoketSend({
  169. "op": "subscribe",
  170. "args": requestList
  171. }).then((res) => {
  172. console.log(res, '发送成功');
  173. })
  174. that.scoket.scoketMessage((res) => {
  175. try {
  176. if (res.data) {
  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. // margin: 20rpx 0 0;
  233. image {
  234. // margin: auto;
  235. width: 726rpx;
  236. height: 273rpx;
  237. }
  238. }
  239. .gnh-wrap {
  240. margin: 20rpx 0;
  241. width: 750rpx;
  242. height: 315rpx;
  243. background-color: #fff;
  244. border-radius: 50rpx 50rpx 0 0;
  245. .gnh-top {
  246. justify-content: space-around;
  247. height: 156rpx;
  248. .top-item {
  249. flex-direction: column;
  250. justify-content: center;
  251. align-items: center;
  252. image {
  253. width: 66rpx;
  254. height: 75rpx;
  255. }
  256. view {
  257. font-weight: 500;
  258. color: #525C6E;
  259. }
  260. }
  261. }
  262. .gnh-btm {
  263. justify-content: space-around;
  264. .btm-item {
  265. width: 33%;
  266. text-align: center;
  267. padding-top: 20rpx;
  268. .btm-item-name {
  269. font-size: 24rpx;
  270. font-weight: 500;
  271. color: #525C6E;
  272. }
  273. .btm-item-val {
  274. font-size: 26rpx;
  275. font-weight: 500;
  276. color: #DD3745;
  277. padding: 20rpx 0;
  278. }
  279. .btm-item-bl {
  280. font-size: 24rpx;
  281. font-weight: 500;
  282. color: #DD3745;
  283. }
  284. }
  285. }
  286. }
  287. .list {
  288. background: #ffffff;
  289. border-top-left-radius: 26rpx;
  290. border-top-right-radius: 26rpx;
  291. padding: 40rpx 15rpx 0;
  292. .list-title {
  293. font-size: 28rpx;
  294. font-family: PingFang SC;
  295. font-weight: 500;
  296. color: #525c6e;
  297. padding-bottom: 32rpx;
  298. .title-left {
  299. text-align: left;
  300. width: 33%;
  301. }
  302. .title-center {
  303. text-align: center;
  304. width: 33%;
  305. }
  306. .title-right {
  307. text-align: right;
  308. width: 33%;
  309. }
  310. }
  311. .list-main {
  312. padding: 12rpx 0;
  313. .main-left {
  314. text-align: left;
  315. width: 33%;
  316. font-size: 28rpx;
  317. font-family: PingFang SC;
  318. font-weight: 500;
  319. color: #525c6e;
  320. }
  321. .main-center {
  322. text-align: center;
  323. width: 33%;
  324. font-size: 28rpx;
  325. font-family: PingFang SC;
  326. font-weight: 500;
  327. color: #e15560;
  328. &.down {
  329. color: #5ec886;
  330. }
  331. &.ping {
  332. color: #525c6e;
  333. }
  334. }
  335. .main-right {
  336. text-align: right;
  337. width: 33%;
  338. display: flex;
  339. justify-content: flex-end;
  340. .btn {
  341. width: 122rpx;
  342. height: 63rpx;
  343. background: #e15562;
  344. border-radius: 5rpx;
  345. text-align: center;
  346. line-height: 63rpx;
  347. font-size: 24rpx;
  348. font-family: PingFang SC;
  349. font-weight: 500;
  350. color: #ffffff;
  351. &.down {
  352. background: #5ec886;
  353. }
  354. &.ping {
  355. background: #f6f6f6;
  356. }
  357. }
  358. }
  359. }
  360. }
  361. </style>