transaction.vue 5.9 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" @click="navTo('/pages/transaction/transactionDetail?type='+index)" v-for="(item,index) in listOBj">
  14. <view class="main-left">{{ item.name }}</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. that.listOBj[res.arg.instId] = res.data[0];
  114. const item = that.listOBj[res.arg.instId];
  115. item.dcf = (((item.last * 1 - item.sodUtc0 * 1) / (item.sodUtc0 * 1)) * 100).toFixed(2);
  116. item.name = item.instId.replace('-', '/')
  117. // that.listOBj[res.arg.instId] = res.data[0];
  118. // that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  119. that.listOBj = Object.assign({}, that.listOBj);
  120. }
  121. // console.log(that.listOBj, 'that.listOBj++++++');
  122. } catch (e) {
  123. console.log(res, res.data, '报错');
  124. }
  125. });
  126. });
  127. },
  128. closeScoket() {
  129. this.scoket.scoketClose();
  130. },
  131. // 获取查询列表
  132. geLevertade() {
  133. const that = this;
  134. geLevertade().then(e => {
  135. that.spList = e.list;
  136. // 开启长连接
  137. that.onScoket();
  138. });
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss">
  144. page,
  145. .content {
  146. height: auto;
  147. min-height: 100%;
  148. background: #f6f6f6;
  149. }
  150. .navbar {
  151. padding-top: 34rpx;
  152. display: flex;
  153. align-items: center;
  154. white-space: nowrap;
  155. height: 100rpx;
  156. .navbar-item {
  157. text-align: center;
  158. display: inline-block;
  159. font-size: 32rpx;
  160. font-family: PingFang SC;
  161. font-weight: 800;
  162. color: #777988;
  163. margin-left: 115rpx;
  164. padding-bottom: 14rpx;
  165. line-height: 1;
  166. &.current {
  167. border-bottom: 3px solid #f7d359;
  168. }
  169. }
  170. }
  171. .list {
  172. background: #ffffff;
  173. border-top-left-radius: 26rpx;
  174. border-top-right-radius: 26rpx;
  175. padding: 40rpx 15rpx 0;
  176. .list-title {
  177. font-size: 28rpx;
  178. font-family: PingFang SC;
  179. font-weight: 500;
  180. color: #525c6e;
  181. padding-bottom: 32rpx;
  182. .title-left {
  183. text-align: left;
  184. width: 33%;
  185. }
  186. .title-center {
  187. text-align: center;
  188. width: 33%;
  189. }
  190. .title-right {
  191. text-align: right;
  192. width: 33%;
  193. }
  194. }
  195. .list-main {
  196. padding: 12rpx 0;
  197. .main-left {
  198. text-align: left;
  199. width: 33%;
  200. font-size: 28rpx;
  201. font-family: PingFang SC;
  202. font-weight: 500;
  203. color: #525c6e;
  204. }
  205. .main-center {
  206. text-align: center;
  207. width: 33%;
  208. font-size: 28rpx;
  209. font-family: PingFang SC;
  210. font-weight: 500;
  211. color: #e15560;
  212. &.down {
  213. color: #5ec886;
  214. }
  215. &.ping {
  216. color: #525c6e;
  217. }
  218. }
  219. .main-right {
  220. text-align: right;
  221. width: 33%;
  222. display: flex;
  223. justify-content: flex-end;
  224. .btn {
  225. width: 122rpx;
  226. height: 63rpx;
  227. background: #e15562;
  228. border-radius: 5rpx;
  229. text-align: center;
  230. line-height: 63rpx;
  231. font-size: 24rpx;
  232. font-family: PingFang SC;
  233. font-weight: 500;
  234. color: #ffffff;
  235. &.down {
  236. background: #5ec886;
  237. }
  238. &.ping {
  239. background: #f6f6f6;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. </style>