index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="container">
  3. <view class="flex" style="justify-content: space-between;padding: 20rpx 30rpx;">
  4. <image src="../../static/icon/user.png" mode="" style="width: 53rpx;height: 53rpx;" @click="navto('/pages/user/menu')"></image>
  5. <!-- <image src="../../static/icon/tz.png" mode="" style="width: 53rpx;height: 53rpx;"></image> -->
  6. </view>
  7. <!-- 轮播图 start -->
  8. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  9. <swiper-item v-for="item in clist" class="carousel-item" @click="bannerNavToUrl(item)"><image :src="item" /></swiper-item>
  10. </swiper>
  11. <!-- 轮播图 end -->
  12. <!-- 通告欄 start -->
  13. <u-notice-bar type="none" :more-icon="true" mode="vertical" :list="list" @click="navto()" @getMore="navto('/pages/index/gglist')"></u-notice-bar>
  14. <!-- 通告欄 end -->
  15. <!-- 功能盒 start -->
  16. <view class="gnh-wrap">
  17. <view class="gnh-top flex">
  18. <view class="top-item flex">
  19. <image src="../../static/icon/gn-1.png" mode="" class=""></image>
  20. <view class="">認購</view>
  21. </view>
  22. <view class="top-item flex" @click="navto('/pages/transaction/cblist')">
  23. <image src="../../static/icon/gn-2.png" mode="" class=""></image>
  24. <view class="">充幣</view>
  25. </view>
  26. <view class="top-item flex" @click="navto('/pages/transaction/tblist')">
  27. <image src="../../static/icon/gn-3.png" mode="" class=""></image>
  28. <view class="">提幣</view>
  29. </view>
  30. <!-- <view class="top-item flex">
  31. <image src="../../static/icon/gn-4.png" mode="" class=""></image>
  32. <view class="">語言</view>
  33. </view> -->
  34. <view class="top-item flex" @click="navto('/pages/index/kf')">
  35. <image src="../../static/icon/gn-5.png" mode="" class=""></image>
  36. <view class="">客服</view>
  37. </view>
  38. </view>
  39. <view class="gnh-btm flex">
  40. <view class="btm-item">
  41. <view class="btm-item-name">BTC/USDT</view>
  42. <template v-if="listOBj['BTC-USDT']">
  43. <view class="btm-item-val" :style="{ color: listOBj['BTC-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['BTC-USDT'].last || '--,--' }}</view>
  44. <view class="btm-item-bl" :style="{ color: listOBj['BTC-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['BTC-USDT'].dcf || '--,--' }}%</view>
  45. </template>
  46. </view>
  47. <view class="btm-item">
  48. <view class="btm-item-name">BCH/USDT</view>
  49. <template v-if="listOBj['BCH-USDT']">
  50. <view class="btm-item-val" :style="{ color: listOBj['BCH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['BCH-USDT'].last || '--,--' }}</view>
  51. <view class="btm-item-bl" :style="{ color: listOBj['BCH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['BCH-USDT'].dcf || '--,--' }}%</view>
  52. </template>
  53. </view>
  54. <view class="btm-item">
  55. <view class="btm-item-name">ETH/USDT</view>
  56. <template v-if="listOBj['ETH-USDT']">
  57. <view class="btm-item-val" :style="{ color: listOBj['ETH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['ETH-USDT'].last || '--,--' }}</view>
  58. <view class="btm-item-bl" :style="{ color: listOBj['ETH-USDT'].dcf > 0 ? '#5ec886' : '#DD3745' }">{{ listOBj['ETH-USDT'].dcf || '--,--' }}%</view>
  59. </template>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 功能盒 end -->
  64. <!-- -->
  65. <view class="list">
  66. <view class="list-title flex">
  67. <view class="title-left">交易對</view>
  68. <view class="title-center">最新價格</view>
  69. <view class="title-right">24h漲跌</view>
  70. </view>
  71. <view class="list-main flex" v-for="(item, index) in listOBj">
  72. <view class="main-left">{{ index }}</view>
  73. <view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.last == 0 ? '--.--' : item.last }}</view>
  74. <view class="main-right">
  75. <view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import { tradelist } from '@/api/login.js';
  83. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  84. import { mapState, mapMutations } from 'vuex';
  85. import { scoketNew, scoketOpen } from '@/utils/socket.js';
  86. import { geLevertade, gglist } from '@/api/index.js';
  87. export default {
  88. data() {
  89. return {
  90. clist: {},
  91. scoket: '',
  92. instId: 'IOTA-USDT', //请求的产品id
  93. spList: [], //需要查询的列表
  94. list: [],
  95. listInfo: [],
  96. listOBj: {} //保存实际列表对象
  97. };
  98. },
  99. computed: {
  100. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  101. },
  102. onLoad: function(option) {},
  103. onShow: function() {
  104. this.geLevertade();
  105. this.tradelist();
  106. this.getgg();
  107. },
  108. onHide() {
  109. this.closeScoket();
  110. },
  111. //下拉刷新
  112. onPullDownRefresh() {},
  113. methods: {
  114. navto(url) {
  115. console.log(url);
  116. if (!this.hasLogin) {
  117. // 保存地址
  118. saveUrl();
  119. // 登录拦截
  120. interceptor();
  121. } else {
  122. uni.navigateTo({
  123. url
  124. });
  125. }
  126. },
  127. getgg() {
  128. const obj = this;
  129. gglist({ page: 1, limit: 1000 }).then(e => {
  130. obj.listInfo = e.data;
  131. e.data.forEach(e => {
  132. obj.list.push(e.title);
  133. });
  134. });
  135. },
  136. swiperChange() {},
  137. // 开始请求长连接
  138. onScoket() {
  139. const that = this;
  140. that.scoket = scoketNew('wss://wsaws.okx.com:8443/ws/v5/public');
  141. that.scoket.scoketOpen().then(res => {
  142. const requestList = that.spList.map(e => {
  143. return {
  144. channel: 'tickers',
  145. instId: e.coinname.toUpperCase() + '-USDT'
  146. };
  147. });
  148. that.scoket
  149. .scoketSend({
  150. op: 'subscribe',
  151. args: requestList
  152. })
  153. .then(res => {
  154. console.log(res, '发送成功');
  155. });
  156. that.scoket.scoketMessage(res => {
  157. try {
  158. if (res.data) {
  159. // res.res.data[0].name = res.arg.instId
  160. that.listOBj[res.arg.instId] = res.data[0];
  161. that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  162. that.listOBj = Object.assign({}, that.listOBj);
  163. }
  164. console.log(that.listOBj, 'that.listOBj++++++');
  165. } catch (e) {
  166. console.log(res, res.data, '报错');
  167. }
  168. });
  169. });
  170. },
  171. closeScoket() {
  172. this.scoket.scoketClose();
  173. },
  174. // 获取查询列表
  175. geLevertade() {
  176. const that = this;
  177. geLevertade().then(e => {
  178. that.spList = e.list;
  179. // 开启长连接
  180. that.onScoket();
  181. });
  182. },
  183. // 轮播图跳转
  184. bannerNavToUrl(item) {
  185. // #ifdef H5
  186. console.log(item.wap_url.indexOf('http'), 'banner');
  187. if (item.wap_url.indexOf('http') >= 0) {
  188. window.location.href = item.wap_url;
  189. }
  190. // #endif
  191. //测试数据没有写id,用title代替
  192. uni.navigateTo({
  193. url: item.wap_url
  194. });
  195. },
  196. tradelist() {
  197. tradelist().then(res => {
  198. console.log(res);
  199. this.clist = res.data.clist;
  200. this.clist = Object.assign({}, this.clist);
  201. console.log(this.clist, 'this.clist');
  202. });
  203. }
  204. }
  205. };
  206. </script>
  207. <style lang="scss">
  208. // 顶部轮播图
  209. .top-swiper {
  210. margin: auto;
  211. width: 726rpx;
  212. height: 273rpx;
  213. .carousel-item {
  214. }
  215. // margin: 20rpx 0 0;
  216. image {
  217. // margin: auto;
  218. width: 726rpx;
  219. height: 273rpx;
  220. }
  221. }
  222. .gnh-wrap {
  223. margin: 20rpx 0;
  224. width: 750rpx;
  225. height: 315rpx;
  226. background-color: #fff;
  227. border-radius: 50rpx 50rpx 0 0;
  228. .gnh-top {
  229. justify-content: space-around;
  230. height: 156rpx;
  231. .top-item {
  232. flex-direction: column;
  233. justify-content: center;
  234. align-items: center;
  235. image {
  236. width: 66rpx;
  237. height: 75rpx;
  238. }
  239. view {
  240. font-weight: 500;
  241. color: #525c6e;
  242. }
  243. }
  244. }
  245. .gnh-btm {
  246. justify-content: space-around;
  247. .btm-item {
  248. width: 33%;
  249. text-align: center;
  250. padding-top: 20rpx;
  251. .btm-item-name {
  252. font-size: 24rpx;
  253. font-weight: 500;
  254. color: #525c6e;
  255. }
  256. .btm-item-val {
  257. font-size: 26rpx;
  258. font-weight: 500;
  259. color: #dd3745;
  260. padding: 20rpx 0;
  261. }
  262. .btm-item-bl {
  263. font-size: 24rpx;
  264. font-weight: 500;
  265. color: #dd3745;
  266. }
  267. }
  268. }
  269. }
  270. .list {
  271. background: #ffffff;
  272. border-top-left-radius: 26rpx;
  273. border-top-right-radius: 26rpx;
  274. padding: 40rpx 15rpx 0;
  275. .list-title {
  276. font-size: 28rpx;
  277. font-family: PingFang SC;
  278. font-weight: 500;
  279. color: #525c6e;
  280. padding-bottom: 32rpx;
  281. .title-left {
  282. text-align: left;
  283. width: 33%;
  284. }
  285. .title-center {
  286. text-align: center;
  287. width: 33%;
  288. }
  289. .title-right {
  290. text-align: right;
  291. width: 33%;
  292. }
  293. }
  294. .list-main {
  295. padding: 12rpx 0;
  296. .main-left {
  297. text-align: left;
  298. width: 33%;
  299. font-size: 28rpx;
  300. font-family: PingFang SC;
  301. font-weight: 500;
  302. color: #525c6e;
  303. }
  304. .main-center {
  305. text-align: center;
  306. width: 33%;
  307. font-size: 28rpx;
  308. font-family: PingFang SC;
  309. font-weight: 500;
  310. color: #e15560;
  311. &.down {
  312. color: #5ec886;
  313. }
  314. &.ping {
  315. color: #525c6e;
  316. }
  317. }
  318. .main-right {
  319. text-align: right;
  320. width: 33%;
  321. display: flex;
  322. justify-content: flex-end;
  323. .btn {
  324. width: 122rpx;
  325. height: 63rpx;
  326. background: #e15562;
  327. border-radius: 5rpx;
  328. text-align: center;
  329. line-height: 63rpx;
  330. font-size: 24rpx;
  331. font-family: PingFang SC;
  332. font-weight: 500;
  333. color: #ffffff;
  334. &.down {
  335. background: #5ec886;
  336. }
  337. &.ping {
  338. background: #f6f6f6;
  339. }
  340. }
  341. }
  342. }
  343. }
  344. </style>