Commit a1bafdec26a3e7ac0d99e1c9197d416526bb6e08

Authored by liuqimichale
1 parent e7b075f9

vuex

src/components/chinaMap/index.vue
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 <table class="parkTotalTb"> 13 <table class="parkTotalTb">
14 <tr> 14 <tr>
15 <td><div class="memberTotalImg"></div></td> 15 <td><div class="memberTotalImg"></div></td>
16 - <td><div class="infoBox"><div><countTo :startVal='memberParams.startVal' :endVal='memberParams.endVal' :duration='animationTime'></countTo></div><div>会员总数</div></div> </td> 16 + <td><div class="infoBox"><div><countTo :startVal='memberParams.startVal' :endVal='$store.state.ParkingTotal' :duration='animationTime'></countTo></div><div>会员总数</div></div> </td>
17 </tr> 17 </tr>
18 </table> 18 </table>
19 </div> 19 </div>
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 <script> 32 <script>
33 import echarts from 'echarts' 33 import echarts from 'echarts'
34 import countTo from 'vue-count-to';//通过设置:endVall 和 :startVall 会自动判断计数和倒数,:duration='3000'是指完成动画的时间。 34 import countTo from 'vue-count-to';//通过设置:endVall 和 :startVall 会自动判断计数和倒数,:duration='3000'是指完成动画的时间。
  35 + import {mapGetters} from 'vuex' //use commit
35 export default { 36 export default {
36 name: "chinaMap", 37 name: "chinaMap",
37 components: { countTo }, 38 components: { countTo },
@@ -53,7 +54,13 @@ @@ -53,7 +54,13 @@
53 mapChart: {}, 54 mapChart: {},
54 } 55 }
55 }, 56 },
  57 + computed: {
  58 + ...mapGetters(['getParkingTotal'])
  59 + },
56 mounted() { 60 mounted() {
  61 + this.parkParams.endVal = this.$store.state.ParkingTotal
  62 +
  63 + console.log(this.getParkingTotal)
57 this.mapChart= this.createPie(); 64 this.mapChart= this.createPie();
58 const _self=this; 65 const _self=this;
59 //var tmpCount=0; 66 //var tmpCount=0;
@@ -61,7 +68,7 @@ @@ -61,7 +68,7 @@
61 let tmpCount =Math.floor(Math.random()*3+1);;//1-3随机数 68 let tmpCount =Math.floor(Math.random()*3+1);;//1-3随机数
62 // _self.parkParams.startVal= _self.parkParams.endVal; 69 // _self.parkParams.startVal= _self.parkParams.endVal;
63 // _self.parkParams.endVal +=tmpCount; 70 // _self.parkParams.endVal +=tmpCount;
64 - console.log(tmpCount); 71 + //console.log(tmpCount);
65 _self.dayParams.startVal=_self.dayParams.endVal; 72 _self.dayParams.startVal=_self.dayParams.endVal;
66 _self.dayParams.endVal +=tmpCount; 73 _self.dayParams.endVal +=tmpCount;
67 },10000); 74 },10000);
src/components/memberNum/index.vue
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 </template> 22 </template>
23 23
24 <script> 24 <script>
  25 + import { mapActions } from 'vuex'
25 import common from '../../api/common'; 26 import common from '../../api/common';
26 import echarts from 'echarts' 27 import echarts from 'echarts'
27 export default { 28 export default {
@@ -37,18 +38,24 @@ @@ -37,18 +38,24 @@
37 }, 38 },
38 mounted() { 39 mounted() {
39 //会员总数 40 //会员总数
40 -  
41 this.axios.post('urban/intelligence/appuser/queryUserPersonStatistic').then((response)=>{ 41 this.axios.post('urban/intelligence/appuser/queryUserPersonStatistic').then((response)=>{
42 let data = response.data.data 42 let data = response.data.data
43 this.registerNum = data.registerNum 43 this.registerNum = data.registerNum
44 this.memberNumTotal = common.formatNumToStr(this.registerNum); 44 this.memberNumTotal = common.formatNumToStr(this.registerNum);
45 this.activeUserNum = data.todayActiveNum 45 this.activeUserNum = data.todayActiveNum
46 this.newUerNum = data.todayRegisterNum 46 this.newUerNum = data.todayRegisterNum
  47 + this.$store.dispatch('transferParkingTotal', data.registerNum)
  48 + //this.$store.dispatch('transferParkingTotal',10000);
  49 + //this.transferParkingTotal( data.registerNum);
  50 + console.log(this.$store.state.ParkingTotal)
47 }).catch((response)=>{ 51 }).catch((response)=>{
48 console.log(response); 52 console.log(response);
49 }) 53 })
50 }, 54 },
51 methods: { 55 methods: {
  56 + ...mapActions([
  57 + 'transferParkingTotal'
  58 + ])
52 /* 59 /*
53 * 格式化会员总数 60 * 格式化会员总数
54 // * */ 61 // * */
src/store/index.js
1 import Vue from 'vue' 1 import Vue from 'vue'
2 import Vuex from 'vuex' 2 import Vuex from 'vuex'
3 -import weather from './modules/weather'  
4 -import weatherForecast from './modules/weatherForecast'  
5 -//import createLogger from '../../../src/plugins/logger' 3 +
  4 +import createLogger from 'vuex/dist/logger'
6 5
7 Vue.use(Vuex) 6 Vue.use(Vuex)
8 7
9 -//const debug = process.env.NODE_ENV !== 'production' 8 +const state = {
  9 + ParkingTotal: 10000
  10 +
  11 +}
  12 +
  13 +const getters = {
  14 + getParkingTotal: function (state) {
  15 + return state.ParkingTotal
  16 + }
  17 +}
  18 +
  19 +const mutations = {
  20 + changeParkingTotal(state,str){
  21 + state.ParkingTotal = str
  22 + }
  23 +
  24 +}
  25 +
  26 +const actions = {
  27 + transferParkingTotal(context,obj){
  28 + context.commit('changeParkingTotal',obj)
  29 + }
  30 +}
  31 +
  32 +
  33 +const debug = process.env.NODE_ENV !== 'production'
10 34
11 -export default new Vuex.Store({  
12 - modules: {  
13 - weatherModule:weather,  
14 - weatherForecastModule:weatherForecast  
15 - },  
16 - // strict: debug,  
17 - // plugins: debug ? [createLogger()] : [] 35 +const store = new Vuex.Store({
  36 + state,
  37 + getters,
  38 + mutations,
  39 + actions,
  40 + plugins: debug ? [createLogger()] : []
18 }) 41 })
  42 +export default store;