index.vue 9.6 KB

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