1
李凌
9 days ago 349c48e168b9f2580334422228acde7d1b21bede
src/views/trade/index.vue
@@ -13,7 +13,6 @@
    <ContractHeader :symbol="symbol" :range="range" :selectIndex="selectIndex" :symbolName="symbolName"
      :balance="userInfo.balance" @tab="onTopTab" @update-coin="onUpdate">
    </ContractHeader>
    <!-- <Head :symbolObj="symbolObj"></Head> -->
    <div :key="symbol" class="pb-108 no_touch">
@@ -22,7 +21,7 @@
        <span class="time">{{ chartData.market.time_str }}</span>&nbsp;
        <span>{{ chartData.market.time_zone && $t(chartData.market.time_zone) }}</span>
      </p>
      <div :class="{ slide2: animated1 }" v-if="selectIndex === 1">
      <div :class="{ slide2: animated1 }" v-if="Number(selectIndex) === 1">
        <section class="value-container" v-if="showMore">
          <div class="flex-l">
            <p class="first-line red">{{ formatMoney(chartData?.close) }}</p>
@@ -216,16 +215,13 @@
      showLength = 7
    },
    initFutrue(val) {
      if (val) {
        if (this.$route.query.selectIndex == 2) {
          if (this.isUpdate) {
            setTimeout(() => {
              this.onTopTab(2)
            })
            this.isUpdate = false
          }
        }
      if (!val || !this.symbol) return
      if (Number(this.selectIndex) === 2 && this.curTab && typeof this[this.curTab] === 'function') {
        this.$nextTick(() => {
          this[this.curTab](this.symbol)
        })
      }
      this.isUpdate = false
    }
  },
  data() {
@@ -260,7 +256,7 @@
        deep: null /// 深度
      },
      curTab: '', // 当前委托还是持有仓位
      selectIndex: 1, // 当前tab
      selectIndex: 2, // 当前tab(仅AI量化)
      initFutrue: {}, /// 交割合约
      show: false, // popup
      animated1: false,
@@ -305,10 +301,10 @@
    }
  },
  async created() {
    if (this.$route.query.type) {
      this.type = this.$route.query.type
    }
   this.keyIndex += 1
    await this.SET_COIN_LIST(this.type)
    _getBalance().then(data => { // 获取用户余额
      this.$store.commit('user/SET_USERINFO', { balance: data.money })
@@ -317,8 +313,10 @@
    })
  },
  methods: {
    ...mapActions('home', [SET_COIN_LIST]),
    onUpdate(symbol) { // 更新
      this.keyIndex += 1
      this.currentType = 'long'
      this.symbol = symbol
      this.closeSocket()
@@ -372,36 +370,43 @@
    handleClickShowMore() {
      this.showMore = !this.showMore
    },
    onTopTab(evt) { // 当前tab 永续/交割
      this.keyIndex += 1
      this.selectIndex = evt
    onTopTab(evt) { // 仅AI量化
      const tab = Number(evt) === 1 ? 2 : Number(evt)
      this.syncContractTab(tab, true)
      if (String(this.$route.query.selectIndex) !== String(tab)) {
        this.$router.replace({
          path: this.$route.path,
          query: { ...this.$route.query, selectIndex: String(tab) }
        }).catch(() => {})
      }
    },
    syncContractTab(evt, bumpKey = true) {
      const idx = Number(evt)
      if (bumpKey) {
        this.keyIndex += 1
      }
      this.selectIndex = idx
      this.clearTimer()
      if (this.selectIndex / 1 === 1) {
        //this.curTab = 'fetchOrderListCur'
      if (idx === 1) {
        this.curTab = 'fetchOrderListHold'
        // this.animated1 = true
        // this.timer = setTimeout(() => {
        //     this.animated1 = false
        //     clearTimeout(this.timer)
        // }, 200)
        this.animated2 = true
        this.timer = setTimeout(() => {
          this.animated2 = false
          clearTimeout(this.timer)
        }, 200)
      } else {
        // this.animated2 = true
        // this.timer = setTimeout(() => {
        //     this.animated2 = false
        //     clearTimeout(this.timer)
        // }, 200)
        this.curTab = 'fetchFutrueHoldList'
        this.animated1 = true
        this.timer = setTimeout(() => {
          this.animated1 = false
          clearTimeout(this.timer)
        }, 200)
      }
      this[this.curTab](this.symbol)
      if (this.symbol && this.curTab && typeof this[this.curTab] === 'function') {
        this.$nextTick(() => {
          this[this.curTab](this.symbol)
        })
      }
    },
    onOrdered(evt) { // 下单过后的回调
      this.clearTimer()
@@ -492,6 +497,8 @@
      }
    },
    startDeepSocket() {
      this.asks = []
      this.bids = []
      this.sockets.deep = new WebSocket(`${WS_URL}/3/${this.symbol}`)
      this.sockets.deep.onmessage = (evt) => {
        const { data } = evt
@@ -676,28 +683,33 @@
    if (!symbol && catchSymbol) {
      symbol = catchSymbol
    } else if (!symbol && !catchSymbol) {
      return
      symbol = 'btcusdt'
      setStorage('symbol', symbol)
    }
    if (symbol) {
      next(vm => {
        if (selectIndex) {
          // vm.selectIndex = selectIndex
          if (vm.selectIndex / 1 === 2) {
            vm.curTab = 'fetchFutrueHoldList'
          } else {
            //vm.curTab = 'fetchOrderListCur'
            vm.curTab = 'fetchOrderListHold'
          }
        } else {
          //vm.curTab = 'fetchOrderListCur'
          vm.curTab = 'fetchOrderListHold'
        }
        vm.symbol = symbol
        vm.init(symbol)
      })
    } else {
      next()
    next(vm => {
      let idx = selectIndex !== undefined && selectIndex !== null && selectIndex !== ''
        ? Number(selectIndex)
        : 2
      if (idx === 1) idx = 2
      vm.selectIndex = idx
      vm.curTab = 'fetchFutrueHoldList'
      vm.symbol = symbol
      vm.init(symbol)
      if (idx === 2) {
        vm.$nextTick(() => vm.syncContractTab(2, false))
      }
    })
  },
  beforeRouteUpdate(to, from, next) {
    const selectIndex = to.query.selectIndex
    if (selectIndex !== undefined && selectIndex !== null && selectIndex !== '') {
      let idx = Number(selectIndex)
      if (idx === 1) idx = 2
      if (Number(this.selectIndex) !== idx) {
        this.syncContractTab(idx, true)
      }
    }
    next()
  },
  deactivated() {
    this.closeSocket()