|
@@ -10,19 +10,28 @@
|
|
|
<view class="title-right">24h漲跌</view>
|
|
|
</view>
|
|
|
<scroll-view class="swiper-box" scroll-y="true" :style="{ height: maxheight }">
|
|
|
- <view class="list-main flex" v-for="(item, index) in list">
|
|
|
- <view class="main-left">{{ item.jyd }}</view>
|
|
|
- <view class="main-center" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.price == 0 ? '--.--' : item.price }}</view>
|
|
|
- <view class="main-right">
|
|
|
- <view class="btn" :class="{ down: item.zd < 0, ping: item.zd == 0 }">{{ item.zd }}%</view>
|
|
|
- </view>
|
|
|
+ <view class="list-main flex" v-for="(item,index ) in listOBj">
|
|
|
+ <view class="main-left">{{index}}</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>
|
|
|
+<script>
|
|
|
+ import { mapMutations,mapState } from 'vuex';
|
|
|
+ import {
|
|
|
+ scoketNew,
|
|
|
+ scoketOpen
|
|
|
+ } from '@/utils/socket.js';
|
|
|
+ import {
|
|
|
+ geLevertade
|
|
|
+ } from '@/api/index.js';
|
|
|
export default {
|
|
|
onReady(res) {
|
|
|
var _this = this;
|
|
@@ -39,40 +48,96 @@ export default {
|
|
|
console.log('打印页面的剩余高度', res);
|
|
|
}
|
|
|
});
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState('user',['hasLogin'])
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- typelist: [{ name: 'USDT市场' }, { name: 'LP市场' }, { name: 'BNB市场' }, { name: 'TP市场' }],
|
|
|
+ typelist: [{ name: 'USDT市场' }],
|
|
|
tabCurrentIndex: 0,
|
|
|
- maxheight: '',
|
|
|
- list: [
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'ETH/USDT', price: '0.8431', zd: -1.2 },
|
|
|
- { jyd: 'EOS/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'DOGE/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BCH/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0', zd: 0 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: -1.2 },
|
|
|
- { jyd: 'BTC/USDT', price: '0.8431', zd: 1.2 }
|
|
|
- ]
|
|
|
+ maxheight: '',
|
|
|
+ scoket: '',
|
|
|
+ instId: 'IOTA-USDT', //请求的产品id
|
|
|
+ spList: [], //需要查询的列表
|
|
|
+ listOBj: {} //保存实际列表对象
|
|
|
};
|
|
|
},
|
|
|
- onLoad() {},
|
|
|
- onShow() {},
|
|
|
+ onLoad() {
|
|
|
+
|
|
|
+ },
|
|
|
+ onShow() {
|
|
|
+ if(this.hasLogin) {
|
|
|
+ this.geLevertade()
|
|
|
+ }else {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '您未登錄,是否馬上登錄?',
|
|
|
+ complete(res) {
|
|
|
+ console.log(res)
|
|
|
+ if(res.confirm) {
|
|
|
+ uni.navigateTo({
|
|
|
+ url:'/pages/public/login'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ onHide() {
|
|
|
+ this.closeScoket()
|
|
|
+ },
|
|
|
methods: {
|
|
|
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) {
|
|
|
+ // res.res.data[0].name = res.arg.instId
|
|
|
+ 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() {
|
|
|
+ that.scoket.scoketClose();
|
|
|
+ },
|
|
|
+ // 获取查询列表
|
|
|
+ geLevertade() {
|
|
|
+ const that = this;
|
|
|
+ geLevertade().then((e) => {
|
|
|
+ that.spList = e.list;
|
|
|
+ // 开启长连接
|
|
|
+ that.onScoket()
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
};
|
|
|
</script>
|