index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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="goDetail" @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" @click="navto('/pages/index/rg')">
  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. goDetail(e) {
  128. uni.navigateTo({
  129. url: '/pages/index/ggDetail?id=' + this.listInfo[e].id
  130. });
  131. },
  132. getgg() {
  133. const obj = this;
  134. gglist({ page: 1, limit: 1000 }).then(e => {
  135. obj.listInfo = e.data;
  136. e.data.forEach(e => {
  137. obj.list.push(e.title);
  138. });
  139. });
  140. },
  141. swiperChange() {},
  142. // 开始请求长连接
  143. onScoket() {
  144. const that = this;
  145. that.scoket = scoketNew('wss://wsaws.okx.com:8443/ws/v5/public');
  146. that.scoket.scoketOpen().then(res => {
  147. const requestList = that.spList.map(e => {
  148. return {
  149. channel: 'tickers',
  150. instId: e.coinname.toUpperCase() + '-USDT'
  151. };
  152. });
  153. that.scoket
  154. .scoketSend({
  155. op: 'subscribe',
  156. args: requestList
  157. })
  158. .then(res => {
  159. console.log(res, '发送成功');
  160. });
  161. that.scoket.scoketMessage(res => {
  162. try {
  163. if (res.data) {
  164. // res.res.data[0].name = res.arg.instId
  165. that.listOBj[res.arg.instId] = res.data[0];
  166. that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
  167. that.listOBj = Object.assign({}, that.listOBj);
  168. }
  169. console.log(that.listOBj, 'that.listOBj++++++');
  170. } catch (e) {
  171. console.log(res, res.data, '报错');
  172. }
  173. });
  174. });
  175. },
  176. closeScoket() {
  177. this.scoket.scoketClose();
  178. },
  179. // 获取查询列表
  180. geLevertade() {
  181. const that = this;
  182. geLevertade().then(e => {
  183. that.spList = e.list;
  184. // 开启长连接
  185. that.onScoket();
  186. });
  187. },
  188. // 轮播图跳转
  189. bannerNavToUrl(item) {
  190. // #ifdef H5
  191. console.log(item.wap_url.indexOf('http'), 'banner');
  192. if (item.wap_url.indexOf('http') >= 0) {
  193. window.location.href = item.wap_url;
  194. }
  195. // #endif
  196. //测试数据没有写id,用title代替
  197. uni.navigateTo({
  198. url: item.wap_url
  199. });
  200. },
  201. tradelist() {
  202. tradelist().then(res => {
  203. console.log(res);
  204. this.clist = res.data.clist;
  205. this.clist = Object.assign({}, this.clist);
  206. console.log(this.clist, 'this.clist');
  207. });
  208. }
  209. }
  210. };
  211. </script>
  212. <style lang="scss">
  213. // 顶部轮播图
  214. .top-swiper {
  215. margin: auto;
  216. width: 726rpx;
  217. height: 273rpx;
  218. .carousel-item {
  219. }
  220. // margin: 20rpx 0 0;
  221. image {
  222. // margin: auto;
  223. width: 726rpx;
  224. height: 273rpx;
  225. }
  226. }
  227. .gnh-wrap {
  228. margin: 20rpx 0;
  229. width: 750rpx;
  230. height: 315rpx;
  231. background-color: #fff;
  232. border-radius: 50rpx 50rpx 0 0;
  233. .gnh-top {
  234. justify-content: space-around;
  235. height: 156rpx;
  236. .top-item {
  237. flex-direction: column;
  238. justify-content: center;
  239. align-items: center;
  240. image {
  241. width: 66rpx;
  242. height: 75rpx;
  243. }
  244. view {
  245. font-weight: 500;
  246. color: #525c6e;
  247. }
  248. }
  249. }
  250. .gnh-btm {
  251. justify-content: space-around;
  252. .btm-item {
  253. width: 33%;
  254. text-align: center;
  255. padding-top: 20rpx;
  256. .btm-item-name {
  257. font-size: 24rpx;
  258. font-weight: 500;
  259. color: #525c6e;
  260. }
  261. .btm-item-val {
  262. font-size: 26rpx;
  263. font-weight: 500;
  264. color: #dd3745;
  265. padding: 20rpx 0;
  266. }
  267. .btm-item-bl {
  268. font-size: 24rpx;
  269. font-weight: 500;
  270. color: #dd3745;
  271. }
  272. }
  273. }
  274. }
  275. .list {
  276. background: #ffffff;
  277. border-top-left-radius: 26rpx;
  278. border-top-right-radius: 26rpx;
  279. padding: 40rpx 15rpx 0;
  280. .list-title {
  281. font-size: 28rpx;
  282. font-family: PingFang SC;
  283. font-weight: 500;
  284. color: #525c6e;
  285. padding-bottom: 32rpx;
  286. .title-left {
  287. text-align: left;
  288. width: 33%;
  289. }
  290. .title-center {
  291. text-align: center;
  292. width: 33%;
  293. }
  294. .title-right {
  295. text-align: right;
  296. width: 33%;
  297. }
  298. }
  299. .list-main {
  300. padding: 12rpx 0;
  301. .main-left {
  302. text-align: left;
  303. width: 33%;
  304. font-size: 28rpx;
  305. font-family: PingFang SC;
  306. font-weight: 500;
  307. color: #525c6e;
  308. }
  309. .main-center {
  310. text-align: center;
  311. width: 33%;
  312. font-size: 28rpx;
  313. font-family: PingFang SC;
  314. font-weight: 500;
  315. color: #e15560;
  316. &.down {
  317. color: #5ec886;
  318. }
  319. &.ping {
  320. color: #525c6e;
  321. }
  322. }
  323. .main-right {
  324. text-align: right;
  325. width: 33%;
  326. display: flex;
  327. justify-content: flex-end;
  328. .btn {
  329. width: 122rpx;
  330. height: 63rpx;
  331. background: #e15562;
  332. border-radius: 5rpx;
  333. text-align: center;
  334. line-height: 63rpx;
  335. font-size: 24rpx;
  336. font-family: PingFang SC;
  337. font-weight: 500;
  338. color: #ffffff;
  339. &.down {
  340. background: #5ec886;
  341. }
  342. &.ping {
  343. background: #f6f6f6;
  344. }
  345. }
  346. }
  347. }
  348. }
  349. </style>