投屏pc端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.2 KiB

import request from '@/assets/js/api'
import common from '@/assets/js/common'
//import {Toast} from 'mand-mobile'
export default {
namespaced: true, //模块与文件同名
state: {
allCoinList: [], //所有币种 对应后台币种管理 --资产模块使用
allPairList: [], //所有交易对 --行情模块使用
allTrendList: [], //所有交易对+价格
myCollectList: [] ,//我的收藏
currentPair: null, //当前交易对
},
mutations: {
setCoin(state, data) { //币种 --资产模块
state.allCoinList = data;
},
setPair(state, data) { //交易对 -- 行情、币币模块
//console.log(JSON.stringify(data));
state.allPairList = data;
state.currentPair = data[0].childen[0].prices[0];
},
setTrend(state, data) { //行情
//console.log(JSON.stringify(data));
state.allTrendList = data;
},
setCollect(state, data) { //收藏 -- 自选模块
state.myCollectList = JSON.parse(data);
},
resetPair(state, data) { //更新交易对
state.currentPair = data;
}
},
actions: {
init(context) {
let token = common.getItem(common.tokenKey);
if (token) { // 如果token存在,才去获取用户数据
context.dispatch('getAllCoin');
context.dispatch('getAllPair');
context.dispatch('getTrend');
context.dispatch('getCollect');
}
},
getAllCoin(context) { //获取资产的所有币种信息
request.getAxios('/api/user/coin/list')
.then(res => {
context.commit('setCoin', res.data);
})
},
getAllPair(context) { //获取行情的交易对
request.getAxios('/api/coin/case/all')
.then(res => {
context.commit('setPair', res.data);
})
},
getTrend(context) { //获取行情
common.setItem("loading", true); //不显示loading
request.getAxios('/api/coin/price/all', {})
.then(res => {
context.commit('setTrend', res.data);
})
},
getCollect(context) { //获取收藏列表
request.getAxios('/api/user/config/list')
.then(res => {
console.log(JSON.stringify(res.data))
res.data.forEach(item => {
if (item.configKey == 'U_COLLECTION') {
context.commit('setCollect', item.configValue);
}
})
})
},
getNewPair(context, item) { //更新交易对
context.commit('resetPair', item)
}
}
}