transaction.vue 6.7 KB

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