index.vue 10 KB

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