Commit acc12d13 by zhanghui1

dashboard相关修改未完

parent cdd10fb4
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
Vue.filter('date422', function(value) { Vue.filter('date422', function (value) {
if (!value) { return '' } if (!value) { return '' }
value = value.toString() value = value.toString()
return value.slice(0, 4) + '-' + value.slice(4, 6) + '-' + value.slice(6, 8); return value.slice(0, 4) + '-' + value.slice(4, 6) + '-' + value.slice(6, 8);
}) })
Vue.filter('uppercase', function(value) { Vue.filter('uppercase', function (value) {
if (!value) { return '' } if (!value) { return '' }
value = value.toString() value = value.toString()
return value.toUpperCase(); return value.toUpperCase();
}) })
Vue.filter('lowercase', function(value) { Vue.filter('lowercase', function (value) {
if (!value) { return '' } if (!value) { return '' }
value = value.toString() value = value.toString()
return value.toLowerCase(); return value.toLowerCase();
}) })
Vue.filter('formatPercent', function(value) { Vue.filter('formatPercent', function (value) {
if (value == 0) { if (value == 0) {
return '--' return '--'
}; };
return (value * 100).toFixed(2) + "%" return (value * 100).toFixed(2) + "%"
}) })
Vue.filter('formatPercent2', function(value) { Vue.filter('formatPercent2', function (value) {
return (value * 100).toFixed(2) + "%" return (value * 100).toFixed(2) + "%"
}) })
Vue.filter('formatStar', function(str) { Vue.filter('formatStar', function (str) {
return str.slice(0, 3) + "******" + str.slice(str.length - 3, str.length); return str.slice(0, 3) + "******" + str.slice(str.length - 3, str.length);
}) })
Vue.filter('formatDate', function(time) { Vue.filter('formatDate', function (time) {
var date = new Date(time * 1000); var date = new Date(time * 1000);
return formatDate(date, "yyyy-MM-dd hh:mm"); return formatDate(date, "yyyy-MM-dd hh:mm");
}) })
Vue.filter('formatDate2', function(time) { Vue.filter('formatDate2', function (time) {
if (!time) return ''; if (!time) return '';
var date = parseInt((new Date().getTime()) / 1000 - time); var date = parseInt((new Date().getTime()) / 1000 - time);
if (localStorage.getItem('language') == 'zh-cn') { if (localStorage.getItem('language') == 'zh-cn') {
...@@ -77,6 +77,11 @@ Vue.filter('formatDate2', function(time) { ...@@ -77,6 +77,11 @@ Vue.filter('formatDate2', function(time) {
} }
}) })
Vue.filter('formatDate3', function (time) {
var date = new Date(time * 1000);
return formatDate(date, "yyyy-MM-dd hh:mm:ss");
})
function formatDate(date, fmt) { function formatDate(date, fmt) {
if (/(y+)/.test(fmt)) { if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
...@@ -181,12 +186,12 @@ export default { ...@@ -181,12 +186,12 @@ export default {
* @return {[type]} [description] * @return {[type]} [description]
*/ */
getSubAccountById(puid) { getSubAccountById(puid) {
return new Promise(function(relsove, reject) { return new Promise(function (relsove, reject) {
if (!$store.state.SubAccount) $store.state.SubAccount = {}; if (!$store.state.SubAccount) $store.state.SubAccount = {};
if ($store.state.SubAccount['SubAccount' + puid]) { if ($store.state.SubAccount['SubAccount' + puid]) {
relsove($store.state.SubAccount['SubAccount' + puid]) relsove($store.state.SubAccount['SubAccount' + puid])
} else { } else {
$axios($store.state.common_url + "/subaccount/" + puid).then(function(res) { $axios($store.state.common_url + "/subaccount/" + puid).then(function (res) {
$store.state.SubAccount['SubAccount' + puid] = res; $store.state.SubAccount['SubAccount' + puid] = res;
relsove($store.state.SubAccount['SubAccount' + puid]) relsove($store.state.SubAccount['SubAccount' + puid])
}) })
...@@ -238,8 +243,22 @@ export default { ...@@ -238,8 +243,22 @@ export default {
*/ */
getAllRegions() { getAllRegions() {
//console.log("getAllRegions") //console.log("getAllRegions")
// return new Promise((resolve, reject) => {
// resolve($store.state.init_url.regions)
// })
let coin_type = localStorage.getItem('coin_type');
let regions = [];
let obj = {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve($store.state.init_url.regions) _.each($store.state.init_url.regions, function (v, k) {
_.each(v.supported_coin_types, function (v1, k1) {
if (v1.coin_type == coin_type) {
obj = { region_id: v.region_id, text_en: v.text_en, 'text_zh-cn': v['text_zh-cn'] }
regions.push(obj)
}
})
});
resolve(regions);
}) })
}, },
/** /**
...@@ -253,7 +272,7 @@ export default { ...@@ -253,7 +272,7 @@ export default {
//console.log("getRegionInfo") //console.log("getRegionInfo")
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let cur_region; let cur_region;
_.each($store.state.init_url.regions, function(v, k) { _.each($store.state.init_url.regions, function (v, k) {
if (v.region_id == region_id) { if (v.region_id == region_id) {
cur_region = v; cur_region = v;
} }
...@@ -295,8 +314,8 @@ export default { ...@@ -295,8 +314,8 @@ export default {
getZonglanList(url, cointype) { getZonglanList(url, cointype) {
//console.log("getZonglanList") //console.log("getZonglanList")
let list = []; let list = [];
_.each(url.regions, function(v, i) { _.each(url.regions, function (v, i) {
_.each(v.supported_coin_types, function(v1, i1) { _.each(v.supported_coin_types, function (v1, i1) {
if (v1.coin_type == cointype) { if (v1.coin_type == cointype) {
list.push({ 'region_id': v.region_id, 'text_en': v.text_en, 'text_zh-cn': v['text_zh-cn'], 'coin_type': cointype, 'api_base_url': v1.api_base_url, 'coins': url.coins[cointype] }) list.push({ 'region_id': v.region_id, 'text_en': v.text_en, 'text_zh-cn': v['text_zh-cn'], 'coin_type': cointype, 'api_base_url': v1.api_base_url, 'coins': url.coins[cointype] })
} }
...@@ -317,9 +336,9 @@ export default { ...@@ -317,9 +336,9 @@ export default {
// console.log("getApiBaseUrl") // console.log("getApiBaseUrl")
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let api_base_url = ''; let api_base_url = '';
_.each($store.state.init_url.regions, function(v, k) { _.each($store.state.init_url.regions, function (v, k) {
if (v.region_id == region_id) { if (v.region_id == region_id) {
_.each(v.supported_coin_types, function(v1, k1) { _.each(v.supported_coin_types, function (v1, k1) {
if (v1.coin_type == cointype) { if (v1.coin_type == cointype) {
api_base_url = v1.api_base_url; api_base_url = v1.api_base_url;
} }
...@@ -399,7 +418,7 @@ export default { ...@@ -399,7 +418,7 @@ export default {
getPaymentHistoryReason(tableData) { getPaymentHistoryReason(tableData) {
//console.log("getPaymentHistoryReason") //console.log("getPaymentHistoryReason")
let reason = []; let reason = [];
_.each(tableData, function(v, i) { _.each(tableData, function (v, i) {
if (v.payment_status == 'DELAYED') { if (v.payment_status == 'DELAYED') {
if (v.unpaid_reason.code == 'ERR_EMPTY_ADDRESS') { if (v.unpaid_reason.code == 'ERR_EMPTY_ADDRESS') {
if (localStorage.getItem("language") == "zh-cn") reason.push('未设定收款地址') if (localStorage.getItem("language") == "zh-cn") reason.push('未设定收款地址')
...@@ -554,9 +573,9 @@ export default { ...@@ -554,9 +573,9 @@ export default {
*/ */
getRegionCoins(region_id) { getRegionCoins(region_id) {
let arr_coins = []; let arr_coins = [];
_.map($store.state.init_url.regions, function(v, i, o) { _.map($store.state.init_url.regions, function (v, i, o) {
if (v.region_id == region_id) { if (v.region_id == region_id) {
_.map(v.supported_coin_types, function(v1, i1, o1) { _.map(v.supported_coin_types, function (v1, i1, o1) {
arr_coins.push(v1.coin_type) arr_coins.push(v1.coin_type)
}) })
} }
...@@ -586,9 +605,9 @@ export default { ...@@ -586,9 +605,9 @@ export default {
getStratumUrl(region_id, coin_type) { getStratumUrl(region_id, coin_type) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let stratum_url = ''; let stratum_url = '';
_.each($store.state.init_url.regions, function(v, k) { _.each($store.state.init_url.regions, function (v, k) {
if (v.region_id == region_id) { if (v.region_id == region_id) {
_.each(v.supported_coin_types, function(v1, k1) { _.each(v.supported_coin_types, function (v1, k1) {
if (v1.coin_type == coin_type) { if (v1.coin_type == coin_type) {
stratum_url = v1.stratum_url; stratum_url = v1.stratum_url;
} }
...@@ -611,8 +630,8 @@ export default { ...@@ -611,8 +630,8 @@ export default {
let data = []; let data = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let stratum_url = ''; let stratum_url = '';
_.each($store.state.init_url.regions, function(v, k) { _.each($store.state.init_url.regions, function (v, k) {
_.each(v.supported_coin_types, function(v1, k1) { _.each(v.supported_coin_types, function (v1, k1) {
if (v1.coin_type == coin_type) { if (v1.coin_type == coin_type) {
data.push({ region_id: v.region_id, text_en: v.text_en, 'text_zh-cn': v['text_zh-cn'], coin_info: v1 }) data.push({ region_id: v.region_id, text_en: v.text_en, 'text_zh-cn': v['text_zh-cn'], coin_info: v1 })
} }
...@@ -633,23 +652,62 @@ export default { ...@@ -633,23 +652,62 @@ export default {
return $axios($store.state.common_url + "/subaccount/summary?puid=" + puid + "&coin_type=" + coin_type) return $axios($store.state.common_url + "/subaccount/summary?puid=" + puid + "&coin_type=" + coin_type)
}, },
/** /**
* [getApiBaseUrls 根据币种获取到所有节点的api_base_url] * [getAllRegionByCoin 根据币种获取到所有节点所支持的所有节点]
* @Author Zhanghui * @Author Zhanghui
* @DateTime 2017-12-27 * @DateTime 2017-12-27
* @param {[type]} coin_type [description] * @param {[type]} coin_type [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
getApiBaseUrls(coin_type) { getAllRegionByCoin(coin_type) {
let apiBaseUrls = []; let regions = [];
let obj = {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_.each($store.state.init_url.regions, function(v, k) { _.each($store.state.init_url.regions, function (v, k) {
_.each(v.supported_coin_types, function(v1, k1) { _.each(v.supported_coin_types, function (v1, k1) {
if (v1.coin_type == coin_type) { if (v1.coin_type == coin_type) {
apiBaseUrls.push(v1.api_base_url) obj = { region_id: v.region_id, text_en: v.text_en, 'text_zh-cn': v['text_zh-cn'] }
regions.push(obj)
} }
}) })
}); });
resolve(apiBaseUrls); resolve(regions);
}) })
}, },
/**
* 创建 token
*/
createToken(puid, params) {
return $axios.post($store.state.common_url + '/watcher/token/create?puid=' + puid, params)
},
/**
* 列出 token
*/
listToken(puid, coin) {
return $axios($store.state.common_url + '/watcher/token?puid=' + puid + '&coin_type=' + coin)
},
/**
* 获取 token 详情
*/
getTokenInfo(token) {
return $axios($store.state.common_url + '/watcher/token/info?token=' + token)
},
/**
* 移除 token
*/
delToken(puid, params) {
return $axios.post($store.state.common_url + '/watcher/token/delete?puid=' + puid, params)
},
/**
* 获取所支持币种
*/
getCoinsOnly(obj) {
let arr_coins = [];
_.map(obj.regions, function (v, i, o) {
_.map(v.supported_coin_types, function (v1, i1, o1) {
arr_coins.push(v1.coin_type)
})
});
return _.uniq(arr_coins)
}
} }
<template> <template>
<div class="my-popup"> <div class="my-popup">
<ul> <ul>
<li class="list-coin" v-for="(cur_coin,index) in $store.state['cur_coins']" :key="cur_coin" @click="coinAcitve(cur_coin,index)" :class="{active:coin==cur_coin}"> <li class="list-coin" v-for="cur_coin in $store.state['cur_coins']" :key="cur_coin" @click="coinAcitve(cur_coin)" :class="cur_coin==coin_type?'active':''">
<b :class="cur_coin">{{cur_coin|uppercase}}</b> <b :class="cur_coin">{{cur_coin|uppercase}}{{$store.state.init_url.coins[cur_coin]['text_zh-cn']}}</b>
<i class="iconfont icon-dui"></i> <i class="iconfont icon-dui"></i>
</li> </li>
</ul> </ul>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name:'coin', name: 'coin',
props: ['coin'], data() {
data(){ return {
return { puid: this.$route.params.puid,
} coin_type: this.$route.params.coin_type,
}, region_id: this.$route.params.region_id,
methods: { language: localStorage.getItem('language'),
coinAcitve(info,index){
this.$emit('childCoin',info)
},
}
} }
},
methods: {
coinAcitve(cur_coin) {
this.$emit('childCoin', cur_coin)
this.$store.commit('setCoinType', cur_coin)
this.coin_type=cur_coin
}
}
}
</script> </script>
...@@ -2,21 +2,21 @@ ...@@ -2,21 +2,21 @@
<div class="page dashboard"> <div class="page dashboard">
<div class="page-header" :class="hasZIndex==true?'zIndexAuto':''" flex="main:justify cross:center"> <div class="page-header" :class="hasZIndex==true?'zIndexAuto':''" flex="main:justify cross:center">
<div class="side" @click="getSide"><i class="iconfont icon-mulu"></i></div> <div class="side" @click="getSide"><i class="iconfont icon-mulu"></i></div>
<div class="title" @click="getRegion">YZCF - {{messageRegion}}<i class="iconfont icon-down"></i></div> <div class="title" @click="getRegion">{{account_name}} - {{cur_region['text_zh-cn']}}<i class="iconfont icon-down"></i></div>
<div class="btn-choose-coin" @click="getCoin"><span :class="messageCoin"></span><i class="iconfont icon-down"></i></div> <div class="btn-choose-coin" @click="getCoin"><span :class="coin_type"></span><i class="iconfont icon-down"></i></div>
</div> </div>
<div class="page-content"> <div class="page-content">
<!-- 切换币种 --> <!-- 切换币种 -->
<mt-popup v-model="showCoin" position="top" class='top show-top'> <mt-popup v-model="showCoin" position="top" class='top show-top'>
<coin :coin="messageCoin" v-on:childCoin="fromCoin"></coin> <coin v-on:childCoin="fromCoin"></coin>
</mt-popup> </mt-popup>
<!-- 切换区域 --> <!-- 切换区域 -->
<mt-popup v-model="showRegion" position="top" class='top show-top'> <mt-popup v-model="showRegion" position="top" class='top show-top'>
<region :region="messageRegion" v-on:childRegion="fromRegion"></region> <region v-on:childRegion="fromRegion"></region>
</mt-popup> </mt-popup>
<!-- 切换子账户 --> <!-- 切换子账户 -->
<mt-popup v-model="showSide" position="left" class="left show-left"> <mt-popup v-model="showSide" position="left" class="left show-left">
<subaccount></subaccount> <subaccount v-on:childSubAccount="fromSubAccount"></subaccount>
</mt-popup> </mt-popup>
<div class="block-list"> <div class="block-list">
<div class="cell" flex="box:mean"> <div class="cell" flex="box:mean">
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</div> </div>
<div flex="main:center dir:top box:center cross:center"> <div flex="main:center dir:top box:center cross:center">
<p> <p>
<span class="v" v-if="$store.state.coin_type=='xmr'"><animated-num :value="(payment_stats.yesterday_amount)/Math.pow(10,12)" :fixed=12></animated-num></span> <span class="v" v-if="$store.state.coin_type=='xmr'" style="font-size:0.28rem;"><animated-num :value="(payment_stats.yesterday_amount)/Math.pow(10,12)" :fixed=12></animated-num></span>
<span class="v" v-else><animated-num :value="(payment_stats.yesterday_amount)/Math.pow(10,8)" :fixed=8></animated-num></span> <span class="v" v-else><animated-num :value="(payment_stats.yesterday_amount)/Math.pow(10,8)" :fixed=8></animated-num></span>
<span class="k">{{$route.params.coin_type|uppercase}}</span> <span class="k">{{$route.params.coin_type|uppercase}}</span>
</p> </p>
...@@ -82,159 +82,178 @@ ...@@ -82,159 +82,178 @@
</div> </div>
</template> </template>
<script> <script>
import fn from "@/assets/js/function.js"; import fn from "@/assets/js/function.js";
import coin from "@/components/Dashboard/coin"; import coin from "@/components/Dashboard/coin";
import region from "@/components/Dashboard/region"; import region from "@/components/Dashboard/region";
import subaccount from "@/components/Dashboard/subaccount"; import subaccount from "@/components/Dashboard/subaccount";
import animatedNum from "@/components/Common/AnimatedNum"; import animatedNum from "@/components/Common/AnimatedNum";
import dashboardChart from "@/components/Dashboard/dashboardChart.vue"; import dashboardChart from "@/components/Dashboard/dashboardChart.vue";
import tabbar from "@/components/Common/Tabbar.vue"; import tabbar from "@/components/Common/Tabbar.vue";
export default { export default {
name: "dashboard", name: "dashboard",
components: { components: {
coin, coin,
region, region,
subaccount, subaccount,
animatedNum, animatedNum,
dashboardChart, dashboardChart,
tabbar tabbar
}, },
data() { data() {
return { return {
hasZIndex: false, puid: '',
showCoin: false, coin_type: '',
showRegion: false, region_id: '',
showSide: false, language: '',
regions: [],
cur_region: { hasZIndex: false, //侧栏滑出的zindex调整
"region_id": "", showCoin: false,
"text_en": "", showRegion: false,
"text_zh-cn": "", showSide: false,
},
cur_account: { regions: [], //当前币种对应的支持节点(子组件下拉区域)
data: { cur_region: {
name: '' "region_id": "",
} "text_en": "",
}, "text_zh-cn": "",
suanli: {},
payment_stats: {
yesterday_amount: 0,
today_estimate: 0
},
messageRegion: '北方联通',
messageCoin:'dash'
};
},
mounted() {
this.pageInitInterval();
},
methods: {
pageInitInterval() {
let self = this;
clearInterval(window.dingshiqi)
self.pageInit();
window.dingshiqi = setInterval(function() {
self.pageInit();
}, $store.state.refresh_time)
}, },
pageInit() {
let self = this; region_name: '', //中英文切换对应的text_en/text_zh-cn
let puid = this.$route.params.puid; account_name: '', //当前帐户对应的名字
let coin_type = this.$route.params.coin_type;
let region_id = this.$route.params.region_id; suanli: {},
this.language = localStorage.getItem('language'); payment_stats: {
//获取stratum_url yesterday_amount: 0,
fn.getStratumUrl(region_id, coin_type) today_estimate: 0,
.then(res => { balance: 0,
self.stratum_url = res; total_paid_amount: 0
}) }
//获取userName };
fn.getSubAccountById(puid) },
.then(res => { mounted() {
this.pageInitInterval();
},
methods: {
pageInitInterval() {
let self = this;
clearInterval(window.dingshiqi)
self.pageInit();
window.dingshiqi = setInterval(function() {
self.pageInit();
}, $store.state.refresh_time)
},
pageInit() {
let self = this;
this.puid = this.$route.params.puid || localStorage.getItem('puid'); //相关路由参数
this.coin_type = this.$route.params.coin_type || localStorage.getItem('coin_type');
this.region_id = this.$route.params.region_id || localStorage.getItem('region_id');
this.language = localStorage.getItem('language');
this.language = localStorage.getItem('language');
fn.getApiBaseUrl(this.region_id, this.coin_type).then(api => {
if (api == '') {
//自动到无节点页面
} else {
//请求实时算力
fn.getWorkerStats(api, this.puid).then(res => {
if (res.data.err_no == 0) { if (res.data.err_no == 0) {
this.cur_account = res.data; this.suanli = res.data.data;
} else { } else {
this.$message.error("当前子账户错误,请重新选择!") this.$message.error("请求实时算力错误!")
$router.replace({
path: '/my'
})
} }
}); });
//获取所有节点 //获取收益
fn.getAllRegions().then(res => { fn.getPaymentStats(api, this.puid).then(res => {
this.regions = res; if (res.data.err_no == 0) {
}); this.payment_stats = res.data.data
//获取当前节点信息
fn.getRegionInfo(region_id).then(res => {
if (self.language == 'zh-cn') {
this.region_name = res['text_zh-cn'];
}
if (self.language == 'en') {
this.region_name = res['text_en'];
}
})
//请求实时算力
fn.getApiBaseUrl(region_id, coin_type)
.then(api => {
if (api == "") {
this.$message.error("当前币种所在的节点不支持!");
$router.replace("/my/" + puid + "/" + localStorage.getItem('coin_type'))
return false;
} else {
fn.getWorkerStats(api, puid)
.then(res => {
if (res.data.err_no == 0) {
self.suanli = res.data.data;
} else {
this.$message.error("请求实时算力错误!")
}
});
}
})
//获取收益
fn.getApiBaseUrl(region_id, coin_type)
.then(api => {
if (api == "") {
return false;
} else { } else {
fn.getPaymentStats(api, puid) this.$message.error("请求支付状态错误!")
.then(res => {
if (res.data.err_no == 0) {
self.payment_stats = res.data.data
} else {
this.$message.error("请求支付状态错误!")
}
self.loading = false;
});
} }
}) this.loading = false;
}, });
getSide() { }
this.hasZIndex = true; })
this.showSide = !this.showSide;
this.showRegion = false; //获取userName
this.showCoin = false; fn.getSubAccountById(this.puid)
}, .then(res => {
getCoin() { if (res.data.err_no == 0) {
this.hasZIndex = false; this.account_name = res.data.data.name;
this.showCoin = !this.showCoin; }
this.showRegion = false; });
this.showSide = false;
}, //获取当前节点信息
getRegion() { this.getRegionInfo();
this.hasZIndex = false;
this.showRegion = !this.showRegion;
this.showCoin = false; },
this.showSide = false; getRegionInfo() {
}, fn.getRegionInfo(this.region_id).then(res => {
fromRegion(msg){ this.cur_region = res;
this.messageRegion = msg; if (this.language == 'zh-cn') {
this.showRegion = false; this.region_name = this.cur_region['text_zh-cn'];
}, }
fromCoin(msg){ if (this.language == 'en') {
this.messageCoin = msg; this.region_name = this.cur_region['text_en'];
this.showCoin = false; }
} })
} },
}; getSide() {
this.hasZIndex = true;
this.showSide = !this.showSide;
this.showRegion = false;
this.showCoin = false;
},
getRegion() {
this.hasZIndex = false;
this.showRegion = !this.showRegion;
this.showCoin = false;
this.showSide = false;
},
getCoin() {
this.hasZIndex = false;
this.showCoin = !this.showCoin;
this.showRegion = false;
this.showSide = false;
},
fromSubAccount(obj) {
this.$store.commit('setPuid', obj.puid)
this.$store.commit('setCoinType', obj.default_coin_type)
this.showSide = false;
this.$route.params.puid = obj.puid;
this.$route.params.coin_type = obj.default_coin_type;
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
fromRegion(msg) {
this.$store.commit('setRegionId', msg)
this.showRegion = false;
this.$route.params.region_id = msg;
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
fromCoin(msg) {
this.$store.commit('setCoinType', msg)
this.showCoin = false;
this.$route.params.coin_type = msg;
this.getRegionInfo();
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
},
watch: {
'$route' (to, from) {
console.log("index.vue watch")
this.pageInitInterval();
},
}
};
</script> </script>
<template>
<div class="page dashboard">
<div class="page-header" :class="hasZIndex==true?'zIndexAuto':''" flex="main:justify cross:center">
<div class="side" @click="getSide"><i class="iconfont icon-mulu"></i></div>
<div class="title" @click="getRegion">{{account_name}} - {{region_name}}<i class="iconfont icon-down"></i></div>
<div class="btn-choose-coin" @click="getCoin"><span :class="coin_type"></span><i class="iconfont icon-down"></i></div>
</div>
<div class="page-content">
<!-- 切换币种 -->
<mt-popup v-model="showCoin" position="top" class='top show-top'>
<coin v-on:childCoin="fromCoin"></coin>
</mt-popup>
<!-- 切换区域 -->
<mt-popup v-model="showRegion" position="top" class='top show-top'>
<region v-on:childRegion="fromRegion"></region>
</mt-popup>
<!-- 切换子账户 -->
<mt-popup v-model="showSide" position="left" class="left show-left">
<subaccount v-on:childSubAccount="fromSubAccount"></subaccount>
</mt-popup>
<div>
无节点,无算力页
</div>
</div>
<tabbar></tabbar>
</div>
</template>
<script>
import fn from "@/assets/js/function.js";
import coin from "@/components/Dashboard/coin";
import region from "@/components/Dashboard/region";
import subaccount from "@/components/Dashboard/subaccount";
import animatedNum from "@/components/Common/AnimatedNum";
import dashboardChart from "@/components/Dashboard/dashboardChart.vue";
import tabbar from "@/components/Common/Tabbar.vue";
export default {
name: "no",
components: {
coin,
region,
subaccount,
animatedNum,
dashboardChart,
tabbar
},
data() {
return {
puid: '',
coin_type: '',
region_id: '',
language: '',
hasZIndex: false, //侧栏滑出的zindex调整
showCoin: false,
showRegion: false,
showSide: false,
regions: [], //当前币种对应的支持节点(子组件下拉区域)
cur_region: {
"region_id": "",
"text_en": "",
"text_zh-cn": "",
},
region_name: '', //中英文切换对应的text_en/text_zh-cn
account_name: '', //当前帐户对应的名字
demoData: [{
region_id: '',
text_en: "",
"text_zh-cn": "",
coin_info: {
"coin_type": "",
"stratum_url": [],
"api_base_url": "",
"merge_mining_coins": [{
"coin_type": ""
}]
}
}],
};
},
mounted() {
this.pageInit();
},
methods: {
pageInitInterval() {
let self = this;
clearInterval(window.dingshiqi)
self.pageInit();
window.dingshiqi = setInterval(function() {
self.pageInit();
}, $store.state.refresh_time)
},
pageInit() {
let self = this;
this.puid = this.$route.params.puid || localStorage.getItem('puid'); //相关路由参数
this.coin_type = this.$route.params.coin_type || localStorage.getItem('coin_type');
this.region_id = this.$route.params.region_id || localStorage.getItem('region_id');
this.language = localStorage.getItem('language');
//获取userName
fn.getSubAccountById(this.puid).then(res => {
if (res.data.err_no == 0) {
this.account_name = res.data.data.name;
}
});
//获取当前节点信息
fn.getRegionInfo(this.region_id).then(res => {
if (this.language == 'zh-cn') {
this.region_name = res['text_zh-cn'];
}
if (this.language == 'en') {
this.region_name = res['text_en'];
}
});
//获取支持当前币种的节点信息和当前币种信息
fn.getStratumUrls(this.coin_type).then(res => {
self.demoData = res;
});
},
getSide() {
this.hasZIndex = true;
this.showSide = !this.showSide;
this.showRegion = false;
this.showCoin = false;
},
getRegion() {
this.hasZIndex = false;
this.showRegion = !this.showRegion;
this.showCoin = false;
this.showSide = false;
},
getCoin() {
this.hasZIndex = false;
this.showCoin = !this.showCoin;
this.showRegion = false;
this.showSide = false;
},
fromSubAccount(obj) {
this.$store.commit('setPuid', obj.puid)
this.$store.commit('setCoinType', obj.default_coin_type)
this.showSide = false;
this.$route.params.puid = obj.puid;
this.$route.params.coin_type = obj.default_coin_type;
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
fromRegion(msg) {
this.$store.commit('setRegionId', msg)
this.showRegion = false;
this.$route.params.region_id = msg;
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
fromCoin(msg) {
this.$store.commit('setCoinType', msg)
this.showCoin = false;
this.$route.params.coin_type = msg;
this.$router.replace({
name: 'dashboard',
params: this.$route.params
})
},
},
watch: {
'$route' (to, from) {
this.pageInit();
},
}
};
</script>
<template> <template>
<div class="my-popup"> <div class="my-popup">
<ul> <ul>
<li v-for="(items, index) in regionDate" :key="items.text" :class="{active:region==items.text}" v-on:click="regionAcitve(items, index)" > <li v-for="(region, index) in regions" :key="region.region_id" :class="region_id==region.region_id?'active':''" v-on:click="regionAcitve(region, index)">
<span>{{items.text}}</span> <span>{{region['text_zh-cn']}}</span>
<i class="iconfont icon-dui"></i> <i class="iconfont icon-dui"></i>
</li> </li>
</ul> </ul>
</div> </div>
</template> </template>
<script> <script>
import fn from '@/assets/js/function.js'
export default { export default {
name: 'region', name: 'region',
props: ['region'],
data() { data() {
return { return {
regionDate: [{ puid: this.$route.params.puid,
text: '南方电信' coin_type: this.$route.params.coin_type,
}, { region_id: this.$route.params.region_id,
text: '北方联通' language: localStorage.getItem('language'),
}, {
text: '美国旧金山' regions: []
}, {
text: '德国法兰克福'
}],
} }
}, },
mounted() {
this.getAllRegionByCoin()
},
methods: { methods: {
regionAcitve(items, index) { getAllRegionByCoin() {
this.$emit('childRegion', items.text) let coin_type=this.$route.params.coin_type;
fn.getAllRegionByCoin(coin_type).then(res => {
this.regions = res;
})
},
regionAcitve(regionObj, index) {
this.$emit('childRegion', regionObj.region_id);
this.region_id=regionObj.region_id;
}
},
watch: {
'$route' (to, from) {
console.log("region.vue watch")
this.getAllRegionByCoin()
} }
} }
} }
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
<h2>选择子账户</h2> <h2>选择子账户</h2>
</div> </div>
<div class="list-item"> <div class="list-item">
<div class="list" v-for="(items, index) in subaccountDate" :key="items" @click="subaccountActive(items, index)" :class="index==i?'active':''"> <div class="list" v-for="subaccount in subaccountList" :key="subaccount.puid" @click="subaccountActive(subaccount)" :class="subaccount.puid==puid?'active':''">
<span>{{items}}</span> <span>{{subaccount.name}}</span>
<i v-show="index == i" class="iconfont icon-dui"></i> <i v-show="puid == subaccount.puid" class="iconfont icon-dui"></i>
</div> </div>
<div class="subAdd" @click="goCreate"> <div class="subAdd" @click="goCreate">
<b class="iconfont icon-jiantou"></b>创建子账户 <b class="iconfont icon-jiantou"></b>创建子账户
...@@ -17,56 +17,158 @@ ...@@ -17,56 +17,158 @@
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import fn from '@/assets/js/function.js'
export default { export default {
name: 'subaccount', name: 'subaccount',
data() { data() {
return { return {
infoUser: 'xuzhiyuan@163.com', infoUser: 'xuzhiyuan@163.com',
subaccountDate: ['wakuang1', 'wakuang2', 'wakuang3', 'wakuang4'],
i: 0 puid: this.$route.params.puid,
coin_type: this.$route.params.coin_type,
region_id: this.$route.params.region_id,
language: localStorage.getItem('language'),
subaccountList: [],
cur_account_info:{},
} }
}, },
mounted() {
this.getSubAccount();
this.getSubAccountById();
},
methods: { methods: {
subaccountActive(items, index) { subaccountActive(obj) {
this.i = index this.puid = obj.puid
console.log(items) this.$emit('childSubAccount', obj)
}, },
goCreate(){ goCreate() {
this.$router.replace('/create') this.$router.replace('/create')
},
getSubAccount() {
fn.getSubAccount().then(res => {
if (res.data.err_no == 0) {
this.subaccountList = res.data.data
} else {
alert("接口错误!")
}
})
},
getSubAccountById(){
fn.getSubAccountById(this.puid).then(res=>{
if(res.data.err_no==0){
this.cur_account_info=res.data.data
}else{
alert("错误")
}
})
} }
} }
} }
</script> </script>
<style lang="less"> <style lang="less">
//仿原生线 //仿原生线
.line(){ .line() {
&.xb{left: 0; right: 0;height: 1px;width: 100%; background: #ccc;content: '';position: absolute;bottom:0;transform: scaleY(0.33) translateY(1px);} &.xb {
left: 0;
right: 0;
height: 1px;
width: 100%;
background: #ccc;
content: '';
position: absolute;
bottom: 0;
transform: scaleY(0.33) translateY(1px);
}
}
.show-left,
.subaccount {
width: 5.9rem;
background-color: #fff;
}
.show-left {
height: 100%;
} }
.show-left,.subaccount{width:5.9rem;background-color: #fff;}
.show-left{height: 100%;} .subaccount {
.subaccount{height: 100%; height: 100%;
.subtop{position: fixed;margin:auto;top: 0;left: 0;right: 0;height: .88rem;z-index: 999;} .subtop {
.logo{height: 2rem;padding:1.1rem .30rem 0;line-height: .9rem;background-color: #103f73;color: #Fff;box-sizing: border-box;font-size: .32rem; position: fixed;
i{font-size: .50rem;color: #Fff;float: right;} margin: auto;
top: 0;
left: 0;
right: 0;
height: .88rem;
z-index: 999;
}
.logo {
height: 2rem;
padding: 1.1rem .30rem 0;
line-height: .9rem;
background-color: #103f73;
color: #Fff;
box-sizing: border-box;
font-size: .32rem;
i {
font-size: .50rem;
color: #Fff;
float: right;
}
}
h2 {
padding: .20rem .30rem 0;
font-size: .28rem;
color: #727272;
line-height: .68rem;
background: #ededf2;
} }
h2{padding:.20rem .30rem 0;font-size: .28rem;color: #727272;line-height: .68rem;background: #ededf2;} .list-item {
.list-item{padding-top:2.88rem;box-sizing: border-box;height: 100%;overflow: auto; padding-top: 2.88rem;
.list{line-height: .90rem;height: .90rem;position: relative;padding: 0 .30rem; box-sizing: border-box;
&:after{.line.xb;} height: 100%;
i{font-size: .50rem;color: #1c5fa9;float: right;} overflow: auto;
&.active{color: #1c5fa9;} .list {
&:active{background-color: #e6e6e6;} line-height: .90rem;
height: .90rem;
position: relative;
padding: 0 .30rem;
&:after {
.line.xb;
}
i {
font-size: .50rem;
color: #1c5fa9;
float: right;
}
&.active {
color: #1c5fa9;
}
&:active {
background-color: #e6e6e6;
}
} }
} }
.subAdd{text-align: center;font-size: .32rem;color:#1c5fa9;line-height: .90rem;height: .90rem;position: relative; .subAdd {
b{font-size: .40rem;font-weight: 400;} text-align: center;
&:after{.line.xb;} font-size: .32rem;
&:active{background-color: #e6e6e6;} color: #1c5fa9;
line-height: .90rem;
height: .90rem;
position: relative;
b {
font-size: .40rem;
font-weight: 400;
}
&:after {
.line.xb;
}
&:active {
background-color: #e6e6e6;
}
} }
} }
</style>
</style>
...@@ -7,36 +7,36 @@ ...@@ -7,36 +7,36 @@
<router-link to="/create">1.跳转到新建子账户页</router-link> <router-link to="/create">1.跳转到新建子账户页</router-link>
</li> </li>
<!-- <li> <!-- <li>
<router-link to="/subaccount">2.跳转到账户列表</router-link> <router-link to="/subaccount">2.跳转到账户列表</router-link>
</li> --> </li> -->
<li> <li>
<router-link to="/welcome">2.跳转到欢迎页,即列表页精简版</router-link> <router-link to="/welcome">2.跳转到欢迎页,即列表页精简版</router-link>
</li> </li>
<li @click="goDashboard" style="cursor:pointer">3.跳转到子账户面板</li> <li @click="goDashboard" style="cursor:pointer">3.跳转到子账户面板</li>
<li> <li>
<router-link to="/my/7/ltc/shenzhen/dashboard">4.跳入用户面板页面</router-link> <router-link to="/my/7/ltc/shenzhen/dashboard">4.跳入用户面板页面</router-link>
</li> </li>
</ul> </ul>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'jump', name: 'jump',
data() { data() {
return { return {
msg: '判断跳转中...' msg: '判断跳转中...',
} }
}, },
mounted() {}, mounted() {},
methods: { methods: {
goDashboard() { goDashboard() {
this.$router.replace("/my/puid/coin_type/region_id/dashboard") this.$router.replace("/my/78/" + localStorage.getItem('coin_type') + "/" + localStorage.getItem('region_id') + "/dashboard")
}
} }
} }
}
</script> </script>
<style> <style scoped>
li {
margin-top: 20px;
}
</style> </style>
...@@ -37,7 +37,7 @@ axios.interceptors.request.use(config => { ...@@ -37,7 +37,7 @@ axios.interceptors.request.use(config => {
function checkToken() { function checkToken() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlEwTTBNRUl4UVRVME5qazJNa0ZFT0RCRk56WkJNVGc0TmtFd09UWkNOakZGTlRFMFEwVTJOdyJ9.eyJpc3MiOiJodHRwczovL2Jsb2NraW4uYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDU5ZjE3OTc5ZDljMGM1MzZiZjRhMzVjMSIsImF1ZCI6WyJodHRwczovL3d3dy5wb29saW4uY29tL2FwaSIsImh0dHBzOi8vYmxvY2tpbi5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNTE2NzYzNTQ4LCJleHAiOjE1MTY3NzA3NDgsImF6cCI6IkZhczI5dWJNNW52NElFMlZUQ3ZEWU5iaWtIeTF0bDBkIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSByZWFkIHdyaXRlIn0.szk9htUCmgk43W5kPVcIQiMZxmVSCdKsoPwYjGp63elPdfu7DrUxWY8xLFbSZ-4ynTlH9z8jEEH_mGgtVDP-00TDqO3aXQRjqr2PSfl6wYp3YWXTK1eBIb3khJbPT0MCgFidm3KJJrZXbvs5JdEEWK1uATrro0F7c_DKHG19KluIkJpYobEYcCanCvHbxAIISQKAIBJ9Fjj0FmAABSoe0N_U1qaXVS6HDMQKVVWHymAmVDE0agO2SvW7f6_mYYX17Nyt0zhxJ41tl5GRZANpr4agXYS27QnjwHkRgLWeWZ0ZHBDJHy_GA2ZapuKVltm5EHszlrYLWzYILSsSNfpFoA"); resolve("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlEwTTBNRUl4UVRVME5qazJNa0ZFT0RCRk56WkJNVGc0TmtFd09UWkNOakZGTlRFMFEwVTJOdyJ9.eyJpc3MiOiJodHRwczovL2Jsb2NraW4uYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDVhMzM4MWE2ZjczMzNjNjdkMzMxOWZiYyIsImF1ZCI6WyJodHRwczovL3d3dy5wb29saW4uY29tL2FwaSIsImh0dHBzOi8vYmxvY2tpbi5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNTE2OTU3ODMwLCJleHAiOjE1MTY5NjUwMzAsImF6cCI6IkZhczI5dWJNNW52NElFMlZUQ3ZEWU5iaWtIeTF0bDBkIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSByZWFkIHdyaXRlIn0.tl_zchdcoQe1k6CqgJPR_vRinzig1n5mvKJHfzz0iNLxwv47OGLUGvo5-1tTphzO7Y5DAI4saeu6oGpb4QHXCDCj_HiSQSAqVLNauBlmJJdoacbYJUFik7hJ9SSzkVVDY8Y1wHjU9-0QEg2Z7kLz9lER3zTRf2nipHRLpJPet0ysE8C-aQyF0bmiVMM_0LW4ujQAmNSyemjo_GXULZno8_kpTOge0PMFykMc2grt7YG_Ol87M2XMCJgtiZxtnQS2eaovGmNKSTTZQKWOKEUtK3tq2TgH0hc-mUQUKuWsHNgNhcvjIk-uIkJlk49dRP__C6FiUwO_8V9ESUeWmg9-JQ");
}) })
} }
window.$axios = Vue.prototype.$axios = axios; window.$axios = Vue.prototype.$axios = axios;
......
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import fn from '@/assets/js/function.js'
Vue.use(Router) Vue.use(Router)
import Home from '@/components/Home' import Home from '@/components/Home'
...@@ -8,6 +9,8 @@ import Jump from '@/components/Jump' ...@@ -8,6 +9,8 @@ import Jump from '@/components/Jump'
import Login from '@/components/Login/' import Login from '@/components/Login/'
import Reg from '@/components/Reg/' import Reg from '@/components/Reg/'
import no from '@/components/Dashboard/no'
import Dashboard from '@/components/Dashboard/' import Dashboard from '@/components/Dashboard/'
import Miners from '@/components/Miners/' import Miners from '@/components/Miners/'
...@@ -30,177 +33,193 @@ import NoticeShow from '@/components/Notice/detail' ...@@ -30,177 +33,193 @@ import NoticeShow from '@/components/Notice/detail'
const router = new Router({ const router = new Router({
routes: [{ routes: [{
path: '/', path: '/',
name: 'home', name: 'home',
component: Home, component: Home,
meta: { meta: {
title: 'Home.vue' title: 'Home.vue'
} }
}, { }, {
path: '/login', path: '/login',
name: 'login', name: 'login',
component: Login, component: Login,
meta: { meta: {
title: 'Login.vue' title: 'Login.vue'
} }
}, { }, {
path: '/reg', path: '/reg',
name: 'reg', name: 'reg',
component: Reg, component: Reg,
meta: { meta: {
title: 'Reg.vue' title: 'Reg.vue'
} }
}, { }, {
path: '/jump', path: '/jump',
name: 'jump', name: 'jump',
component: Jump, component: Jump,
meta: { meta: {
title: 'Jump.vue' title: 'Jump.vue'
} }
}, { }, {
path: '/create', path: '/create',
name: 'create', name: 'create',
component: Create, component: Create,
meta: { meta: {
title: 'Create.vue' title: 'Create.vue'
} }
}, { }, {
path: '/welcome', path: '/welcome',
name: 'welcome', name: 'welcome',
component: Welcome, component: Welcome,
meta: { meta: {
title: 'Welcome.vue' title: 'Welcome.vue'
} }
}, { }, {
path: '/subaccount', path: '/subaccount',
name: 'subaccount', name: 'subaccount',
component: Subaccount, component: Subaccount,
meta: { meta: {
title: 'Subaccount.vue' title: 'Subaccount.vue'
} }
}, { }, {
path: '/my/:puid/:coin_type/:region_id/dashboard', path: '/my/:puid/:coin_type',
name: 'dashboard', name: 'no',
component: Dashboard, component: no,
meta: { meta: {
title: 'Dashboard.vue' title: 'no.vue'
} }
}, { }, {
path: '/my/:puid/:coin_type/:region_id/miners', path: '/my/:puid/:coin_type/:region_id/dashboard',
name: 'miners', name: 'dashboard',
component: Miners, component: Dashboard,
meta: { meta: {
title: 'Miners.vue' title: 'Dashboard.vue'
} }
}, { }, {
path: '/my/:puid/:coin_type/:region_id/miners/:worker_id', path: '/my/:puid/:coin_type/:region_id/miners',
name: 'minershow', name: 'miners',
component: MinerShow, component: Miners,
meta: { meta: {
title: 'MinerShow.vue' title: 'Miners.vue'
} }
}, { }, {
path: '/my/:puid/:coin_type/:region_id/payments', path: '/my/:puid/:coin_type/:region_id/miners/:worker_id',
name: 'payments', name: 'minershow',
component: Payments, component: MinerShow,
meta: { meta: {
title: 'Payments.vue' title: 'MinerShow.vue'
} }
}, { }, {
path: '/settings', path: '/my/:puid/:coin_type/:region_id/payments',
name: 'settings', name: 'payments',
component: Settings, component: Payments,
meta: { meta: {
title: 'Settings.vue' title: 'Payments.vue'
} }
}, { }, {
path: '/defaultCoin', path: '/settings',
name: 'defaultCoin', name: 'settings',
component: DefaultCoin, component: Settings,
meta: { meta: {
title: 'DefaultCoin.vue' title: 'Settings.vue'
} }
}, { }, {
path: '/language', path: '/defaultCoin',
name: 'language', name: 'defaultCoin',
component: Language, component: DefaultCoin,
meta: { meta: {
title: 'Language.vue' title: 'DefaultCoin.vue'
} }
},{ }, {
path: '/account', path: '/language',
name: 'account', name: 'language',
component: Account, component: Language,
meta: { meta: {
title: 'Account.vue' title: 'Language.vue'
} }
},{ }, {
path: '/notice', path: '/account',
name: 'notice', name: 'account',
component: Notice, component: Account,
meta: { meta: {
title: 'Notice.vue' title: 'Account.vue'
} }
}, { }, {
path: '/noticeList', path: '/notice',
name: 'noticeList', name: 'notice',
component: NoticeList, component: Notice,
meta: { meta: {
title: 'NoticeList.vue' title: 'Notice.vue'
} }
}, { }, {
path: '/noticeShow', path: '/noticeList',
name: 'noticeShow', name: 'noticeList',
component: NoticeShow, component: NoticeList,
meta: { meta: {
title: 'NoticeShow.vue' title: 'NoticeList.vue'
} }
}, }, {
path: '/noticeShow',
name: 'noticeShow',
component: NoticeShow,
meta: {
title: 'NoticeShow.vue'
}
},
] ]
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// if (localStorage.getItem('enter_panel') == "true") { //console.log(to)
// $store.commit('setEnterPannel', true); var arr = ['home', 'jump'];
// }
function getCoins(obj) { if (localStorage.getItem('enter_panel') == null) {
let arr_coins = []; $store.commit('setEnterPannel', $store.state.enter_panel);
_.map(obj.regions, function (v, i, o) { }
_.map(v.supported_coin_types, function (v1, i1, o1) { if (localStorage.getItem('puid') == null) {
arr_coins.push(v1.coin_type) $store.commit('setPuid', '');
}) } else {
}); if (to.params.puid) {
return _.uniq(arr_coins) $store.commit('setPuid', to.params.puid)
}
}
if (localStorage.getItem('enter_panel') == "true") {
$store.commit('setEnterPannel', true);
} }
var arr = ['home', 'jump']; if (localStorage.getItem('language') == null) {
$store.commit('setLanguage', $store.state.language)
}
//最先执行的初始数据
if ($store.state.cur_coins.length == 0) { if ($store.state.cur_coins.length == 0) {
$axios($store.state.base_url) $axios($store.state.base_url).then(res => {
.then(res => { $store.commit('setInitUrl', res.data);
$store.commit('setInitUrl', res.data); $store.commit('setCurCoins', fn.getCoinsOnly(res.data));
$store.commit('setCurCoins', getCoins(res.data));
if (localStorage.coin_type) { if (localStorage.getItem('coin_type') == null) {
$store.commit('setCoinType', localStorage.coin_type); $store.commit('setCoinType', $store.state.cur_coins[0]);
} else {
if (to.params.coin_type) {
$store.commit('setCoinType', to.params.coin_type);
} else { } else {
$store.commit('setCoinType', $store.state.cur_coins[0]); $store.commit('setCoinType', localStorage.getItem('coin_type'));
} }
if (localStorage.region_id) { }
$store.commit('setRegionId', localStorage.region_id)
if (localStorage.getItem("region_id") == null) {
$store.commit('setRegionId', res.data.regions[0].region_id);
} else {
if (to.params.region_id) {
$store.commit('setRegionId', to.params.region_id);
} else { } else {
$store.commit('setRegionId', res.data.regions[0].region_id); $store.commit('setRegionId', localStorage.getItem('region_id'));
} }
if (!localStorage.puid) { }
$store.commit('setPuid', '') modeSwitch(to, from, next)
} })
if (!localStorage.language) {
$store.commit('setLanguage', $store.state.language)
}
next();
})
} else { } else {
next(); modeSwitch(to, from, next)
} }
}) })
...@@ -211,3 +230,44 @@ router.afterEach((to, from) => { ...@@ -211,3 +230,44 @@ router.afterEach((to, from) => {
}) })
export default router export default router
function modeSwitch(to, from, next) {
if (to.query.read_token != undefined || to.query.read_token != null) {
// alert("进入观察者模式")
let token = to.query.read_token;
localStorage.setItem('read_token', token);
$store.state.is_login = false;
fn.getTokenInfo(token).then(res => {
if (res.data.err_no == 0) {
if (res.data.data != null) {
let data = res.data.data;
localStorage.setItem('read_expires_at', data.expired_at * 1000)
localStorage.setItem('read_name', data.name);
localStorage.setItem('read_subaccount_name', data.subaccount_name);
localStorage.setItem('puid', data.puid);
$store.state.read_token = token;
next();
} else {
alert("参数错误!")
$router.replace('/index')
}
} else {
alert("字段类型错误或为空");
}
})
} else {
// alert("进入正常模式")
localStorage.removeItem('read_token');
$store.state.read_token = '';
next();
// var arr = ['index', 'stats', 'callback', 'jump'];
// if ($auth.isAuthenticated() || arr.indexOf(to.name) > -1) {
// next()
// } else {
// localStorage.removeItem('access_token')
// localStorage.removeItem('id_token')
// localStorage.removeItem('expires_at')
// $auth.login();
// }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment