let socket = [] import { Api_getQuotationNew } from "@/api/index.js" import { setStorageSync, getStorageSync } from "@/utils/common.js" const getCurrencyVal = () => { return getStorageSync('currency_val') || {}; } const state = { restrictOrder: '', bids: [], asks: [], daymarket: {}, // getQuotationStatus: false, usdtList: [], optional: [], // 首页 市场 - 自选 marketAll: [], // 首页 市场 currencyVal: getCurrencyVal(), contract_optional: [], // 合约 市场 - 自选 contract_marketAll: [], // 合约 市场 - 自选 currencySuspend: false, orderList: [], // 合约页面 , 持仓 leverTrade: {}, // 合约页面, 杠杆 持仓 } const mutations = { set_restrictOrder: (state, order) => { console.log('order = ', order) state.restrictOrder = order; }, set_currencySuspend: (state, status) => { state.currencySuspend = status; }, set_currency_val: (state, val) => { // 币种列表 setStorageSync('currency_val', val) state.currencyVal = val; }, set_usdt_ist: (state, val) => { // 推荐列表 - 首页 state.usdtList = val; }, set_optional: (state, val) => { // 自选 state.optional = val; }, set_marketAll: (state, val) => { // 市场 state.marketAll = val; }, set_contract_optional: (state, val) => { // 合约 - 自选 state.contract_optional = val; }, set_contract_marketAll: (state, val) => { // 合约 - 市场 state.contract_marketAll = val; }, set_bids: (state, val) => { state.bids = val; }, set_asks: (state, val) => { state.asks = val; }, set_daymarket: (state, val) => { state.daymarket = val; }, set_orderList: (state, list) => { state.orderList = list; }, set_lever_trade: (state, list) => { // console.log('list = ', list.tradesList) if (state.restrictOrder && list.tradesList.length > 0) { try { list.tradesList.forEach(el => { if (el.id === state.restrictOrder.id) { state.restrictOrder = el // new throw Error('') // new throw Error() } }) } catch {} } state.leverTrade = list; }, // 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) { return false 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 }