let socket = [] import { Api_getQuotationNew } from "@/api/index.js" const state = { bids: [], asks: [], daymarket: {}, // getQuotationStatus: false, usdtList: [], optional: [], marketAll: [], currencyVal: {}, currencySuspend: false } const mutations = { set_currencySuspend: (state, status) => { state.currencySuspend = status; }, set_currency_val: (state, val) => { state.currencyVal = val; }, set_bids: (state, val) => { state.bids = val; }, set_asks: (state, val) => { state.asks = val; }, set_daymarket: (state, val) => { state.daymarket = val; }, // SET_CONTRACT: (state, contract) => { // // 合约账户 // state.contractAccount = contract; // }, // SET_BIBI: (state, bibi) => { // // 币币账户 // state.bibiAccount = bibi; // }, // SET_LEGAL: (state, legal) => { // // 法币账户 // state.legalAccount = legal; // }, // SET_GIFTMONEY: (state, GiftMoney) => { // // 赠金账户 // state.GiftMoneyAccount = GiftMoney; // }, // SET_STOCKS_COLOR: (state, code) => { // state.stocksColor = code // }, // SET_TOKEN: (state, token) => { // setToken(token) // state.token = token // } } const nums = (arr) => { const att = arr.map(el => { return el[0] }) const num = Math.max.apply(null, att) arr.forEach(el => { let n = Math.round(el[0] / num * 10000) / 100 el[2] = n > 100 ? 100 : n; }) return arr } const actions = { openSocket({ commit, state }, data) { }, closeSocket({ commit, state }, data) { console.log('关闭socket', socket) try { socket.disconnect() // socket.forEach(el => { // el.disconnect() // }); // socket // socket.close() } catch {} socket = null; }, getQuotationNew({ commit, state }, data) { commit('set_currencySuspend', true) const rq = () => { Api_getQuotationNew().then(res => { if (res && res.length > 0) { let newArr = res.find((item) => item.name == 'USDT').quotation || []; if (!state.currencyVal || !state.currencyVal?.currency_id) { state.currencyVal = newArr[0]; } // 首页推荐 if (newArr && newArr.length > 0) { const nums = newArr.length > 3 ? 3 : newArr.length; state.usdtList = newArr.slice(0, nums); } else { state.usdtList = [] } // 自选 state.optional = newArr.slice(0, 6) // 全部 state.marketAll = newArr } }).catch(err => { if (state.currencySuspend && data?.noRefresh) { console.log(11111 , state.currencySuspend , data?.noRefresh) rq() } }).finally(() => { setTimeout(() => { // noRefresh : 是否不刷新,true 不会继续调用 if (state.currencySuspend && !data?.noRefresh) { console.log(22222 , state.currencySuspend , data?.noRefresh) rq() } }, 3000) }) } rq() }, } export default { namespaced: true, state, mutations, actions }