From 80a09bd78eb94501754ce2b1fcc71befa35290f2 Mon Sep 17 00:00:00 2001 From: shike <1284707383@qq.com> Date: Wed, 22 Jul 2020 18:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=A1=8C=E6=83=85=E8=BD=AE?= =?UTF-8?q?=E6=92=AD/=E6=88=90=E4=BA=A4=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/js/api.js | 32 +++---- src/store/modules/trend.js | 61 +++++++++++-- src/views/coincoin/coincoin_trade.vue | 16 +++- src/views/coincoin/components/trade_deal.vue | 17 ++-- .../coincoin/components/trade_pair_list.vue | 1 + src/views/index/components/price.vue | 85 ++++++++++++++++--- src/views/index/components/trend.vue | 12 +-- 7 files changed, 167 insertions(+), 57 deletions(-) diff --git a/src/assets/js/api.js b/src/assets/js/api.js index ee1a686..60ba0ff 100644 --- a/src/assets/js/api.js +++ b/src/assets/js/api.js @@ -4,20 +4,20 @@ import common from './common' // common.js文件中统一存放一些公共常 import store from '@/store/index' //vuex import i18n from '@/assets/js/language' -import { Message, Loading } from 'element-ui' +import { Message } from 'element-ui' const baseURL = common.baseURL; // API接口 // loading对象 -let loadingObj; +// let loadingObj; let reqNum = 0; //用于判断多个axios请求是否都已经完成 function reqNumFunc() { reqNum--; //没完成一次接口请求 -1,当reqNum === 0 时,说明所有同时发起的请求已经完成 if (reqNum === 0) { - if (loadingObj) { - loadingObj.close() // 隐藏loading - } + // if (loadingObj) { + // loadingObj.close() // 隐藏loading + // } Message.close(); } } @@ -54,17 +54,17 @@ axios.interceptors.request.use(function(config) { config.headers['Accept-language'] = common.getItem('lan') == 'zh' ? 'cn':'en'; //判断是否需要Loading,如果不需要loading 接口请求时设置 loading为true this.common.setItem('loading',true); - let isLoadings = common.getItem('loading'); - - if (!isLoadings) { - // 创建loading - loadingObj = Loading.service({ - lock: true, - text: i18n.t('加载中'), - spinner: 'el-icon-loading', - //background: 'rgba(0, 0, 0, 0.7)' - }) - } + // let isLoadings = common.getItem('loading'); + + // if (!isLoadings) { + // // 创建loading + // loadingObj = Loading.service({ + // lock: true, + // text: i18n.t('加载中'), + // spinner: 'el-icon-loading', + // //background: 'rgba(0, 0, 0, 0.7)' + // }) + // } return config }, function(error) { // 请求错误时弹框提示,或做些其他事 diff --git a/src/store/modules/trend.js b/src/store/modules/trend.js index b2dbfb5..b85ab60 100644 --- a/src/store/modules/trend.js +++ b/src/store/modules/trend.js @@ -8,11 +8,15 @@ export default { allCoinList: [], //所有币种 对应后台币种管理 --资产模块使用 allPairList: [], //所有交易对 --行情模块使用 allTrendList: [], //所有交易对+价格 + newList: [],//新币 myCollectList: [] ,//我的收藏 - currentPair: null, //当前交易对 + currentPair: 'BTC-USDT', //当前交易对 buyList: [], //买盘 sellList: [], //卖盘 + + // 实时成交 + transactions:[], }, mutations: { setCoin(state, data) { //币种 --资产模块 @@ -21,11 +25,16 @@ export default { setPair(state, data) { //交易对 -- 行情、币币模块 //console.log(JSON.stringify(data)); state.allPairList = data; + console.log(JSON.stringify(data)+'12131313') }, setTrend(state, data) { //行情 //console.log(JSON.stringify(data)); state.allTrendList = data; }, + setNewCoin(state, data) { //行情 + //console.log(JSON.stringify(data)); + state.newList = data; + }, setDepth(state, data) { //深度 state.buyList = data.buyList; state.sellList = data.sellList; @@ -37,19 +46,43 @@ export default { resetPair(state, data) { //更新交易对 state.currentPair = data; - } + }, + // 切换 当前交易对 + setSub(state,data){ + state.sub={ + dealCoin: data.dealCoin, + convertType: data.convertType, + name: data.symbolId + } + }, + + // 设置 实时成交 + setTransactions(state, data) { + state.transactions = data + }, }, actions: { + async init(context) { let token = common.getItem(common.tokenKey); if (token) { // 如果token存在,才去获取用户数据 context.dispatch('getAllCoin'); context.dispatch('getCollect'); await context.dispatch('getTrend'); + await context.dispatch('getNewCoin'); context.dispatch('getAllPair'); + context.dispatch('getTransactions'); } }, - + + // 获取实时成交 + getTransactions(ctx) { + console.log(ctx.state.currentPair); + request.getAxios('/api/entrust/trade/list/'+`${ctx.state.currentPair.dealCoin}-${ctx.state.currentPair.convertType}`).then(res => { + ctx.commit('setTransactions', res) + }); + }, + getAllCoin(context) { //获取资产的所有币种信息 request.getAxios('/api/user/coin/list') .then(res => { @@ -57,7 +90,7 @@ export default { }) }, getAllPair(context) { //获取行情的交易对 - request.getAxios('/api/coin/case/all') + return request.getAxios('/api/coin/case/all') .then(res => { // let newData = [...this.allTrendList] res.data.push({ @@ -72,12 +105,23 @@ export default { status: 'C_C_S_NORMAL', childen: [{'prices': context.state.allTrendList}] }) + let list = [] + context.state.allTrendList.forEach(item=>{ + context.state.newList.forEach(item2=>{ + if(item.dealCoin == item2.coinId) { + list.push(item) + } + }) + + }) res.data.push({ caseName: '新币榜', caseCode: "6", status: 'C_C_S_NORMAL', - childen: [{'prices': context.state.allTrendList}] + childen: [{'prices': list}] }) + + if(!context.state.currentPair) context.commit('resetPair', res.data[0].childen[0].prices[0].dealCoin); context.commit('setPair', res.data); }) }, @@ -88,6 +132,13 @@ export default { context.commit('setTrend', res.data); }) }, + getNewCoin(context) { //获取行情 + common.setItem("loading", true); //不显示loading + return request.getAxios('/api/new/coin/list', {}) + .then(res => { + context.commit('setNewCoin', res.data); + }) + }, getDepth(context, params) { //获取深度 common.setItem('loading', true); //不显示loading request.postAxios('/api/entrust/depth/list', params) diff --git a/src/views/coincoin/coincoin_trade.vue b/src/views/coincoin/coincoin_trade.vue index 022ef51..90f36cc 100644 --- a/src/views/coincoin/coincoin_trade.vue +++ b/src/views/coincoin/coincoin_trade.vue @@ -98,6 +98,11 @@ computed: { ...mapState('trend', ['allPairList', 'currentPair']), }, + watch:{ + currentPair(val,old){ + if(val.symbolId!==old.symbolId) this.restart() + } + }, methods: { /* ---------------- 以下是K线图配置 --------------------*/ @@ -111,7 +116,7 @@ //重启K线图 restart() { - this.$store.state.tv_setting.symbol = 'BTC-USDT'; //K线版块(交易对) + this.$store.state.tv_setting.symbol = this.currentPair.symbolId; //K线版块(交易对) this.$refs.tradingViewChart.symbolTab(); }, @@ -119,7 +124,7 @@ KlinFunc() { if (!this.getsetting().wsurl) { this.$store.state.tv_setting.skin = 'white'; //K线颜色 white \ black - this.$store.state.tv_setting.symbol = 'BTC-USDT'; //K线版块(交易对) + this.$store.state.tv_setting.symbol = this.currentPair.symbolId; //K线版块(交易对) this.load(); console.log(11111111) this.$store.state.tv_setting.wsurl = 'ws://119.23.49.169:10803/ws/coin/exchange'; @@ -210,6 +215,10 @@ this.$refs.order.getOrderList(1); this.getBalance(); }, + async getData(){ + await this.$store.dispatch('trend/getAllPair'); + this.getDepth(); + } }, beforeDestroy() { clearInterval(this.timers); @@ -218,8 +227,7 @@ this.initCoin(); this.KlinFunc() this.timers = setInterval(() => { - this.$store.dispatch('trend/getAllPair'); - this.getDepth(); + this.getData(); }, 1000); } } diff --git a/src/views/coincoin/components/trade_deal.vue b/src/views/coincoin/components/trade_deal.vue index 28be07f..eb3a906 100644 --- a/src/views/coincoin/components/trade_deal.vue +++ b/src/views/coincoin/components/trade_deal.vue @@ -15,18 +15,11 @@
-
+
    -
  • 10:52:08
  • -
  • 4784.10
  • -
  • 0.4528
  • -
-
-
-
    -
  • 10:52:08
  • -
  • 4786.55
  • -
  • 0.51865
  • +
  • {{item.date | dateFormat('HH:mm:ss')}}
  • +
  • {{item.price}}
  • +
  • {{item.amount}}
@@ -40,7 +33,7 @@ export default { name: 'tradeDeal', computed: { - ...mapState('trend', ['currentPair']), + ...mapState('trend', ['currentPair','transactions']), }, } diff --git a/src/views/coincoin/components/trade_pair_list.vue b/src/views/coincoin/components/trade_pair_list.vue index e780320..666fbc5 100644 --- a/src/views/coincoin/components/trade_pair_list.vue +++ b/src/views/coincoin/components/trade_pair_list.vue @@ -223,6 +223,7 @@ }, choosePair(item) { //选择交易对 this.$store.dispatch('trend/getNewPair', item); + this.$store.dispatch('trend/getTransactions'); this.$emit('updateOrder'); }, diff --git a/src/views/index/components/price.vue b/src/views/index/components/price.vue index 9de2389..b18f71f 100644 --- a/src/views/index/components/price.vue +++ b/src/views/index/components/price.vue @@ -1,6 +1,38 @@ diff --git a/src/views/index/components/trend.vue b/src/views/index/components/trend.vue index 648bbec..89d30e1 100644 --- a/src/views/index/components/trend.vue +++ b/src/views/index/components/trend.vue @@ -168,16 +168,6 @@ }) } }); - - // newData.sort((a, b) => a.changes - b.changes) - - // list.push({ - // caseName: '涨跌榜', - // caseCode: "4", - // status: 'C_C_S_NORMAL', - // childen: newData || [] - // }) - // console.log(list) return list; }, tradePairList() { //交易对列表 @@ -289,8 +279,10 @@ this.caseIndex = item.caseCode; if(this.caseIndex == 4) { this.toRange = 2 + this.toVolumn = 0 }else if(this.caseIndex == 5) { this.toVolumn = 2 + this.toRange = 2 }else { this.toVolumn = 0 this.toRange = 0