123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <template>
- <view class="content">
- <scroll-view scroll-x="true" :scroll-with-animation="true" class="navbar">
- <view class="navbar-item" :class="{ current: tabCurrentIndex === index }" v-for="(item, index) in typelist" @click="tabClick(index)">{{ $t('jy.' + item.name) }}</view>
- </scroll-view>
- <view class="list">
- <view class="list-title flex">
- <view class="title-left">{{ $t('index.jyd') }}</view>
- <view class="title-center">{{ $t('index.zxjg') }}</view>
- <view class="title-right">{{ $t('index.zd') }}</view>
- </view>
- <scroll-view class="swiper-box" scroll-y="true" :style="{ height: maxheight }">
- <view class="list-main flex" @click="navTo('/pages/transaction/transactionDetail?type=' + index)" v-for="(item, index) in listOBj">
- <view class="main-left">{{ item.name }}</view>
- <view class="main-center" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.last == 0 ? '--.--' : item.last }}</view>
- <view class="main-right">
- <view class="btn" :class="{ down: item.dcf > 0, ping: item.dcf == 0 }">{{ item.dcf }}%</view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- import { mapMutations, mapState } from 'vuex';
- import { scoketNew, scoketOpen } from '@/utils/socket.js';
- import { geLevertade } from '@/api/index.js';
- import { gcb } from '@/api/login.js'
- export default {
- onReady(res) {
- var _this = this;
- uni.getSystemInfo({
- success: resu => {
- const query = uni.createSelectorQuery();
- query.select('.swiper-box').boundingClientRect();
- query.exec(function(res) {
- _this.maxheight = resu.windowHeight - res[0].top + 'px';
- console.log('打印页面的剩余高度', _this.maxheight);
- });
- },
- fail: res => {
- console.log('打印页面的剩余高度', res);
- }
- });
- },
- computed: {
- ...mapState('user', ['hasLogin'])
- },
- data() {
- return {
- timer: '',
- typelist: [{ name: 'usdtsc' }],
- tabCurrentIndex: 0,
- maxheight: '',
- scoket: '',
- instId: 'IOTA-USDT', //请求的产品id
- spList: [], //需要查询的列表
- listOBj: {
- 'BTC-USDT': {},
- 'ETH-USDT': {}
- } //保存实际列表对象
- };
- },
- onLoad() {},
- onShow() {
- uni.setNavigationBarTitle({ title: this.$t('jy.bbjysc') });
- if (this.hasLogin) {
- this.geLevertade();
- this.gcb()
- } else {
- uni.showModal({
- title: this.$t('popup.ts'),
- content: this.$t('popup.nwdl'),
- confirmText: this.$t('popup.qr'),
- cancelText: this.$t('popup.qx'),
- complete(res) {
- console.log(res);
- if (res.confirm) {
- uni.navigateTo({
- url: '/pages/public/login'
- });
- }
- }
- });
- }
- },
- onHide() {
- this.closeScoket();
- clearTimeout(this.timer);
- },
- onUnload() {
- clearTimeout(this.timer);
- },
- methods: {
- navTo(url) {
- uni.navigateTo({
- url
- });
- },
- tabClick(opt) {
- this.tabCurrentIndex = opt;
- },
- // 开始请求长连接
- onScoket() {
- const that = this;
- that.scoket = scoketNew('wss://wsaws.okx.com:8443/ws/v5/public');
- that.scoket.scoketOpen().then(res => {
- const requestList = that.spList.map(e => {
- return {
- channel: 'tickers',
- instId: e.coinname.toUpperCase() + '-USDT'
- };
- });
- that.scoket
- .scoketSend({
- op: 'subscribe',
- args: requestList
- })
- .then(res => {
- console.log(res, '发送成功');
- });
- that.scoket.scoketMessage(res => {
- try {
- if (res.data) {
- 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('-', '/');
- // that.listOBj[res.arg.instId] = res.data[0];
- // that.listOBj[res.arg.instId].dcf = (((res.data[0].last * 1 - res.data[0].sodUtc0 * 1) / (res.data[0].sodUtc0 * 1)) * 100).toFixed(2);
- that.listOBj = Object.assign({}, that.listOBj);
- }
- // console.log(that.listOBj, 'that.listOBj++++++');
- } catch (e) {
- console.log(res, res.data, '报错');
- }
- });
- });
- },
- closeScoket() {
- this.scoket.scoketClose();
- },
- // 获取查询列表
- geLevertade() {
- const that = this;
- geLevertade().then(e => {
- that.spList = e.list;
- // 开启长连接
- that.onScoket();
- });
- },
- gcb() {
- let that = this
- gcb().then(res => {
- console.log(res)
- let data = res.data
- that.listOBj[data.name] = data
- that.listOBj[data.name].dcf = (((data.last * 1 - data.sodUtc0 * 1) / (data.sodUtc0 * 1)) * 100)
- .toFixed(2);
- that.listOBj[data.name].name = data.name.replace('-', '/')
- console.log(that.listOBj, 'that.listOBj')
- if (that.timer) {
- clearTimeout(that.timer)
- that.timer = null
- }
- that.timer = setTimeout(() => {
- that.gcb()
- },5000)
- })
- },
- }
- };
- </script>
- <style lang="scss">
- page,
- .content {
- height: auto;
- min-height: 100%;
- background: #f6f6f6;
- }
- .navbar {
- padding-top: 34rpx;
- display: flex;
- align-items: center;
- white-space: nowrap;
- height: 100rpx;
- .navbar-item {
- text-align: center;
- display: inline-block;
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: 800;
- color: #777988;
- margin-left: 115rpx;
- padding-bottom: 14rpx;
- line-height: 1;
- &.current {
- border-bottom: 3px solid #f7d359;
- }
- }
- }
- .list {
- background: #ffffff;
- border-top-left-radius: 26rpx;
- border-top-right-radius: 26rpx;
- padding: 40rpx 15rpx 0;
- .list-title {
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #525c6e;
- padding-bottom: 32rpx;
- .title-left {
- text-align: left;
- width: 33%;
- }
- .title-center {
- text-align: center;
- width: 33%;
- }
- .title-right {
- text-align: right;
- width: 33%;
- }
- }
- .list-main {
- padding: 12rpx 0;
- .main-left {
- text-align: left;
- width: 33%;
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #525c6e;
- }
- .main-center {
- text-align: center;
- width: 33%;
- font-size: 28rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #e15560;
- &.down {
- color: #5ec886;
- }
- &.ping {
- color: #525c6e;
- }
- }
- .main-right {
- text-align: right;
- width: 33%;
- display: flex;
- justify-content: flex-end;
- .btn {
- width: 122rpx;
- height: 63rpx;
- background: #e15562;
- border-radius: 5rpx;
- text-align: center;
- line-height: 63rpx;
- font-size: 24rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #ffffff;
- &.down {
- background: #5ec886;
- }
- &.ping {
- background: #f6f6f6;
- }
- }
- }
- }
- }
- </style>
|