transaction.vue 5.6 KB

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