transaction.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="content">
  3. <scroll-view scroll-x="true" :scroll-with-animation="true" class="navbar">
  4. <view class="navbar-item" :class="{ current: tabCurrentIndex === index }" v-for="(item, index) in typelist" @click="tabClick(index)">{{ item.name }}</view>
  5. </scroll-view>
  6. <view class="list">
  7. <view class="list-title flex">
  8. <view class="title-left">交易對</view>
  9. <view class="title-center">最新價格</view>
  10. <view class="title-right">24h漲跌</view>
  11. </view>
  12. <scroll-view class="swiper-box" scroll-y="true" :style="{ height: maxheight }">
  13. <view class="list-main flex" v-for="(item,index ) in listOBj">
  14. <view class="main-left">{{index}}</view>
  15. <view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">
  16. {{ item.last == 0 ? '--.--' : item.last }}</view>
  17. <view class="main-right">
  18. <view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
  19. </view>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import { mapMutations,mapState } from 'vuex';
  27. import {
  28. scoketNew,
  29. scoketOpen
  30. } from '@/utils/socket.js';
  31. import {
  32. geLevertade
  33. } from '@/api/index.js';
  34. export default {
  35. onReady(res) {
  36. var _this = this;
  37. uni.getSystemInfo({
  38. success: resu => {
  39. const query = uni.createSelectorQuery();
  40. query.select('.swiper-box').boundingClientRect();
  41. query.exec(function(res) {
  42. _this.maxheight = resu.windowHeight - res[0].top + 'px';
  43. console.log('打印页面的剩余高度', _this.maxheight);
  44. });
  45. },
  46. fail: res => {
  47. console.log('打印页面的剩余高度', res);
  48. }
  49. });
  50. },
  51. computed: {
  52. ...mapState('user',['hasLogin'])
  53. },
  54. data() {
  55. return {
  56. typelist: [{ name: 'USDT市场' }],
  57. tabCurrentIndex: 0,
  58. maxheight: '',
  59. scoket: '',
  60. instId: 'IOTA-USDT', //请求的产品id
  61. spList: [], //需要查询的列表
  62. listOBj: {} //保存实际列表对象
  63. };
  64. },
  65. onLoad() {
  66. },
  67. onShow() {
  68. if(this.hasLogin) {
  69. this.geLevertade()
  70. }else {
  71. uni.showModal({
  72. title: '提示',
  73. content: '您未登錄,是否馬上登錄?',
  74. complete(res) {
  75. console.log(res)
  76. if(res.confirm) {
  77. uni.navigateTo({
  78. url:'/pages/public/login'
  79. })
  80. }
  81. }
  82. })
  83. }
  84. },
  85. onHide() {
  86. this.closeScoket()
  87. },
  88. methods: {
  89. tabClick(opt) {
  90. this.tabCurrentIndex = opt;
  91. },
  92. // 开始请求长连接
  93. onScoket() {
  94. const that = this;
  95. that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
  96. that.scoket.scoketOpen().then((res) => {
  97. const requestList = that.spList.map((e) => {
  98. return {
  99. "channel": "tickers",
  100. "instId": e.coinname.toUpperCase() + "-USDT"
  101. }
  102. })
  103. that.scoket.scoketSend({
  104. "op": "subscribe",
  105. "args": requestList
  106. }).then((res) => {
  107. console.log(res, '发送成功');
  108. })
  109. that.scoket.scoketMessage((res) => {
  110. try {
  111. if (res.data) {
  112. // res.res.data[0].name = res.arg.instId
  113. that.listOBj[res.arg.instId] = res.data[0];
  114. that.listOBj[res.arg.instId].dcf = ((res.data[0].last*1 - res.data[0].sodUtc0*1)/(res.data[0].sodUtc0*1) * 100 ).toFixed(2)
  115. that.listOBj = Object.assign( {},that.listOBj);
  116. }
  117. console.log(that.listOBj, 'that.listOBj++++++')
  118. } catch (e) {
  119. console.log(res, res.data, '报错');
  120. }
  121. })
  122. })
  123. },
  124. closeScoket() {
  125. this.scoket.scoketClose();
  126. },
  127. // 获取查询列表
  128. geLevertade() {
  129. const that = this;
  130. geLevertade().then((e) => {
  131. that.spList = e.list;
  132. // 开启长连接
  133. that.onScoket()
  134. })
  135. },
  136. }
  137. };
  138. </script>
  139. <style lang="scss">
  140. page,
  141. .content {
  142. height: auto;
  143. min-height: 100%;
  144. background: #f6f6f6;
  145. }
  146. .navbar {
  147. padding-top: 34rpx;
  148. display: flex;
  149. align-items: center;
  150. white-space: nowrap;
  151. height: 100rpx;
  152. .navbar-item {
  153. text-align: center;
  154. display: inline-block;
  155. font-size: 32rpx;
  156. font-family: PingFang SC;
  157. font-weight: 800;
  158. color: #777988;
  159. margin-left: 115rpx;
  160. padding-bottom: 14rpx;
  161. line-height: 1;
  162. &.current {
  163. border-bottom: 3px solid #f7d359;
  164. }
  165. }
  166. }
  167. .list {
  168. background: #ffffff;
  169. border-top-left-radius: 26rpx;
  170. border-top-right-radius: 26rpx;
  171. padding: 40rpx 15rpx 0;
  172. .list-title {
  173. font-size: 28rpx;
  174. font-family: PingFang SC;
  175. font-weight: 500;
  176. color: #525c6e;
  177. padding-bottom: 32rpx;
  178. .title-left {
  179. text-align: left;
  180. width: 33%;
  181. }
  182. .title-center {
  183. text-align: center;
  184. width: 33%;
  185. }
  186. .title-right {
  187. text-align: right;
  188. width: 33%;
  189. }
  190. }
  191. .list-main {
  192. padding: 12rpx 0;
  193. .main-left {
  194. text-align: left;
  195. width: 33%;
  196. font-size: 28rpx;
  197. font-family: PingFang SC;
  198. font-weight: 500;
  199. color: #525c6e;
  200. }
  201. .main-center {
  202. text-align: center;
  203. width: 33%;
  204. font-size: 28rpx;
  205. font-family: PingFang SC;
  206. font-weight: 500;
  207. color: #e15560;
  208. &.down {
  209. color: #5ec886;
  210. }
  211. &.ping {
  212. color: #525c6e;
  213. }
  214. }
  215. .main-right {
  216. text-align: right;
  217. width: 33%;
  218. display: flex;
  219. justify-content: flex-end;
  220. .btn {
  221. width: 122rpx;
  222. height: 63rpx;
  223. background: #e15562;
  224. border-radius: 5rpx;
  225. text-align: center;
  226. line-height: 63rpx;
  227. font-size: 24rpx;
  228. font-family: PingFang SC;
  229. font-weight: 500;
  230. color: #ffffff;
  231. &.down {
  232. background: #5ec886;
  233. }
  234. &.ping {
  235. background: #f6f6f6;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. </style>