index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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="">{{ $t('index.rg') }}</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" @click="navto('/pages/index/language')">
  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" @click="navto('/pages/transaction/transactionDetail?type=' + index)" v-for="(item, index) in listOBj">
  75. <view class="main-left">{{ item.name }}</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. that.listOBj[res.arg.instId] = res.data[0]; const item = that.listOBj[res.arg.instId]; item.dcf = (((item.last * 1 - item.sodUtc0 * 1) / (item.sodUtc0 * 1)) * 100).toFixed(2); item.name = item.instId.replace('-', '/')
  168. // res.res.data[0].name = res.arg.instId
  169. // that.listOBj[res.arg.instId] = res.data[0];
  170. // that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  171. that.listOBj = Object.assign({}, that.listOBj);
  172. }
  173. // console.log(that.listOBj, 'that.listOBj++++++');
  174. } catch (e) {
  175. console.log(res, res.data, '报错');
  176. }
  177. });
  178. });
  179. },
  180. closeScoket() {
  181. this.scoket.scoketClose();
  182. },
  183. // 获取查询列表
  184. geLevertade() {
  185. const that = this;
  186. geLevertade().then(e => {
  187. that.spList = e.list;
  188. // 开启长连接
  189. that.onScoket();
  190. });
  191. },
  192. // 轮播图跳转
  193. bannerNavToUrl(item) {
  194. // #ifdef H5
  195. console.log(item.wap_url.indexOf('http'), 'banner');
  196. if (item.wap_url.indexOf('http') >= 0) {
  197. window.location.href = item.wap_url;
  198. }
  199. // #endif
  200. //测试数据没有写id,用title代替
  201. uni.navigateTo({
  202. url: item.wap_url
  203. });
  204. },
  205. tradelist() {
  206. tradelist().then(res => {
  207. console.log(res);
  208. this.clist = res.data.clist;
  209. this.clist = Object.assign({}, this.clist);
  210. console.log(this.clist, 'this.clist');
  211. });
  212. }
  213. }
  214. };
  215. </script>
  216. <style lang="scss">
  217. // 顶部轮播图
  218. .top-swiper {
  219. margin: auto;
  220. width: 726rpx;
  221. height: 273rpx;
  222. .carousel-item {
  223. }
  224. // margin: 20rpx 0 0;
  225. image {
  226. // margin: auto;
  227. width: 726rpx;
  228. height: 273rpx;
  229. }
  230. }
  231. .gnh-wrap {
  232. margin: 20rpx 0;
  233. width: 750rpx;
  234. height: 315rpx;
  235. background-color: #fff;
  236. border-radius: 50rpx 50rpx 0 0;
  237. .gnh-top {
  238. justify-content: space-around;
  239. height: 156rpx;
  240. .top-item {
  241. flex-direction: column;
  242. justify-content: center;
  243. align-items: center;
  244. image {
  245. width: 66rpx;
  246. height: 75rpx;
  247. }
  248. view {
  249. font-weight: 500;
  250. color: #525c6e;
  251. }
  252. }
  253. }
  254. .gnh-btm {
  255. justify-content: space-around;
  256. .btm-item {
  257. width: 33%;
  258. text-align: center;
  259. padding-top: 20rpx;
  260. .btm-item-name {
  261. font-size: 24rpx;
  262. font-weight: 500;
  263. color: #525c6e;
  264. }
  265. .btm-item-val {
  266. font-size: 26rpx;
  267. font-weight: 500;
  268. color: #dd3745;
  269. padding: 20rpx 0;
  270. }
  271. .btm-item-bl {
  272. font-size: 24rpx;
  273. font-weight: 500;
  274. color: #dd3745;
  275. }
  276. }
  277. }
  278. }
  279. .list {
  280. background: #ffffff;
  281. border-top-left-radius: 26rpx;
  282. border-top-right-radius: 26rpx;
  283. padding: 40rpx 15rpx 0;
  284. .list-title {
  285. font-size: 28rpx;
  286. font-family: PingFang SC;
  287. font-weight: 500;
  288. color: #525c6e;
  289. padding-bottom: 32rpx;
  290. .title-left {
  291. text-align: left;
  292. width: 33%;
  293. }
  294. .title-center {
  295. text-align: center;
  296. width: 33%;
  297. }
  298. .title-right {
  299. text-align: right;
  300. width: 33%;
  301. }
  302. }
  303. .list-main {
  304. padding: 12rpx 0;
  305. .main-left {
  306. text-align: left;
  307. width: 33%;
  308. font-size: 28rpx;
  309. font-family: PingFang SC;
  310. font-weight: 500;
  311. color: #525c6e;
  312. }
  313. .main-center {
  314. text-align: center;
  315. width: 33%;
  316. font-size: 28rpx;
  317. font-family: PingFang SC;
  318. font-weight: 500;
  319. color: #e15560;
  320. &.down {
  321. color: #5ec886;
  322. }
  323. &.ping {
  324. color: #525c6e;
  325. }
  326. }
  327. .main-right {
  328. text-align: right;
  329. width: 33%;
  330. display: flex;
  331. justify-content: flex-end;
  332. .btn {
  333. width: 122rpx;
  334. height: 63rpx;
  335. background: #e15562;
  336. border-radius: 5rpx;
  337. text-align: center;
  338. line-height: 63rpx;
  339. font-size: 24rpx;
  340. font-family: PingFang SC;
  341. font-weight: 500;
  342. color: #ffffff;
  343. &.down {
  344. background: #5ec886;
  345. }
  346. &.ping {
  347. background: #f6f6f6;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. .vheight {
  354. height: var(--status-bar-height);
  355. }
  356. </style>