transaction.vue 5.5 KB

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