LAPTOP-D7TKRI82\邓 5 years ago
parent
commit
0e70bc0760
  1. 7
      projectionscreenPc/src/store/index.js
  2. 151
      projectionscreenPc/src/store/modules/trend.js
  3. 56
      projectionscreenPc/src/store/modules/user.js

7
projectionscreenPc/src/store/index.js

@ -6,12 +6,7 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
symbol: ' ',
renew: '0',
pair: '',
id: '1',
priceScale: 1000,
tv_option: {}
},
modules: {
user,

151
projectionscreenPc/src/store/modules/trend.js

@ -1,163 +1,12 @@
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: [], //所有交易对+价格
newList: [],//新币
myCollectList: [] ,//我的收藏
currentPair: 'BTC-USDT', //当前交易对
buyList: [], //买盘
sellList: [], //卖盘
// 实时成交
transactions:[],
},
mutations: {
setCoin(state, data) { //币种 --资产模块
state.allCoinList = data;
},
setPair(state, data) { //交易对 -- 行情、币币模块
//console.log(JSON.stringify(data));
state.allPairList = data;
},
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;
},
setCollect(state, data) { //收藏 -- 自选模块
state.myCollectList = JSON.parse(data);
},
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) {
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 => {
context.commit('setCoin', res.data);
})
},
getAllPair(context) { //获取行情的交易对
return request.getAxios('/api/coin/case/all')
.then(res => {
// let newData = [...this.allTrendList]
res.data.push({
caseName: '涨跌榜',
caseCode: "4",
status: 'C_C_S_NORMAL',
childen: [{'prices': context.state.allTrendList}]
})
res.data.push({
caseName: '成交榜',
caseCode: "5",
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': list}]
})
if(!context.state.currentPair) context.commit('resetPair', res.data[0].childen[0].prices[0].dealCoin);
context.commit('setPair', res.data);
})
},
getTrend(context) { //获取行情
common.setItem("loading", true); //不显示loading
return request.getAxios('/api/coin/price/all', {})
.then(res => {
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)
.then(res => {
context.commit('setDepth', res.data);
})
},
getCollect(context) { //获取收藏列表
request.getAxios('/api/user/config/list')
.then(res => {
res.data.forEach(item => {
if (item.configKey == 'U_COLLECTION') {
context.commit('setCollect', item.configValue);
}
})
})
},
getNewPair(context, item) { //更新交易对
context.commit('resetPair', item)
}
}
}

56
projectionscreenPc/src/store/modules/user.js

@ -1,66 +1,12 @@
import request from '@/assets/js/api'
import common from '@/assets/js/common'
import router from '../../router'
import { Message, MessageBox } from 'element-ui'
import i18n from '@/assets/js/language'
export default {
namespaced: true, //模块与文件同名
state: {
userConfig: [], //用户设置参数
userIsActive: '', //是否激活
isLogin: '',
},
mutations: {
setLoginStatus(state) {
if(common.getItem(common.tokenKey)) {
state.isLogin = true;
} else {
state.isLogin = false;
}
},
// 更新 个人设置
setUserConfig(state, data) {
state.userConfig = data;
},
clearData(state) {
state.userConfig = [];
state.isLogin = false;
state.userIsActive = '';
}
},
actions: {
init(context) { //初始化
let token = common.getItem(common.tokenKey);
if(token) { // 如果token存在,才去获取用户数据
context.dispatch('getUserConfig');
}
},
getUserConfig(context) { //获取用户配置
request.getAxios('/api/user/config/list')
.then(res => {
context.commit('setUserConfig', res.data);
})
},
logout(context) {
common.setItem(common.tokenKey, ""); //清除Token
context.commit('clearData');
MessageBox.confirm(i18n.t('是否退出登录?'), i18n.t('提示'), {
cancelButtonText: i18n.t('稍后再说'),
confirmButtonText: i18n.t('退出'),
type: 'warning'
})
.then(() => {
Message.success(i18n.t('退出登录成功!'));
})
setTimeout(() => {
router.push('/login');
}, 500)
}
}
}
Loading…
Cancel
Save