transaction.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. confirmText: '確認',
  68. complete(res) {
  69. console.log(res);
  70. if (res.confirm) {
  71. uni.navigateTo({
  72. url: '/pages/public/login'
  73. });
  74. }
  75. }
  76. });
  77. }
  78. },
  79. onHide() {
  80. this.closeScoket();
  81. },
  82. methods: {
  83. tabClick(opt) {
  84. this.tabCurrentIndex = opt;
  85. },
  86. // 开始请求长连接
  87. onScoket() {
  88. const that = this;
  89. that.scoket = scoketNew('wss://wsaws.okx.com:8443/ws/v5/public');
  90. that.scoket.scoketOpen().then(res => {
  91. const requestList = that.spList.map(e => {
  92. return {
  93. channel: 'tickers',
  94. instId: e.coinname.toUpperCase() + '-USDT'
  95. };
  96. });
  97. that.scoket
  98. .scoketSend({
  99. op: 'subscribe',
  100. args: requestList
  101. })
  102. .then(res => {
  103. console.log(res, '发送成功');
  104. });
  105. that.scoket.scoketMessage(res => {
  106. try {
  107. if (res.data) {
  108. // res.res.data[0].name = res.arg.instId
  109. that.listOBj[res.arg.instId] = res.data[0];
  110. that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  111. that.listOBj = Object.assign({}, that.listOBj);
  112. }
  113. console.log(that.listOBj, 'that.listOBj++++++');
  114. } catch (e) {
  115. console.log(res, res.data, '报错');
  116. }
  117. });
  118. });
  119. },
  120. closeScoket() {
  121. this.scoket.scoketClose();
  122. },
  123. // 获取查询列表
  124. geLevertade() {
  125. const that = this;
  126. geLevertade().then(e => {
  127. that.spList = e.list;
  128. // 开启长连接
  129. that.onScoket();
  130. });
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="scss">
  136. page,
  137. .content {
  138. height: auto;
  139. min-height: 100%;
  140. background: #f6f6f6;
  141. }
  142. .navbar {
  143. padding-top: 34rpx;
  144. display: flex;
  145. align-items: center;
  146. white-space: nowrap;
  147. height: 100rpx;
  148. .navbar-item {
  149. text-align: center;
  150. display: inline-block;
  151. font-size: 32rpx;
  152. font-family: PingFang SC;
  153. font-weight: 800;
  154. color: #777988;
  155. margin-left: 115rpx;
  156. padding-bottom: 14rpx;
  157. line-height: 1;
  158. &.current {
  159. border-bottom: 3px solid #f7d359;
  160. }
  161. }
  162. }
  163. .list {
  164. background: #ffffff;
  165. border-top-left-radius: 26rpx;
  166. border-top-right-radius: 26rpx;
  167. padding: 40rpx 15rpx 0;
  168. .list-title {
  169. font-size: 28rpx;
  170. font-family: PingFang SC;
  171. font-weight: 500;
  172. color: #525c6e;
  173. padding-bottom: 32rpx;
  174. .title-left {
  175. text-align: left;
  176. width: 33%;
  177. }
  178. .title-center {
  179. text-align: center;
  180. width: 33%;
  181. }
  182. .title-right {
  183. text-align: right;
  184. width: 33%;
  185. }
  186. }
  187. .list-main {
  188. padding: 12rpx 0;
  189. .main-left {
  190. text-align: left;
  191. width: 33%;
  192. font-size: 28rpx;
  193. font-family: PingFang SC;
  194. font-weight: 500;
  195. color: #525c6e;
  196. }
  197. .main-center {
  198. text-align: center;
  199. width: 33%;
  200. font-size: 28rpx;
  201. font-family: PingFang SC;
  202. font-weight: 500;
  203. color: #e15560;
  204. &.down {
  205. color: #5ec886;
  206. }
  207. &.ping {
  208. color: #525c6e;
  209. }
  210. }
  211. .main-right {
  212. text-align: right;
  213. width: 33%;
  214. display: flex;
  215. justify-content: flex-end;
  216. .btn {
  217. width: 122rpx;
  218. height: 63rpx;
  219. background: #e15562;
  220. border-radius: 5rpx;
  221. text-align: center;
  222. line-height: 63rpx;
  223. font-size: 24rpx;
  224. font-family: PingFang SC;
  225. font-weight: 500;
  226. color: #ffffff;
  227. &.down {
  228. background: #5ec886;
  229. }
  230. &.ping {
  231. background: #f6f6f6;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. </style>