Commit c949337896406827a1267687260415a7914a754f

Authored by liuqimichale
1 parent 9aa901e6

api 接口封装

src/api/api.js 0 → 100644
  1 +import { get, post} from './httpRequest'
  2 +
  3 +//....用户数
  4 +export const memberAddress = p => post('urban/intelligence/appuser/queryUserPersonStatistic',p)
  5 +
  6 +//....收费员
  7 +export const tollmanAddress = p => post('urban/intelligence/employee/queryEmployeeStaByOrgIds',p)
  8 +
  9 +//....设备
  10 +export const deviceAddress = p => post('urban/intelligence/device/queryDeviceStatistic',p)
... ...
src/api/httpRequest.js
1 1 //引入axios
2 2 import axios from 'axios'
3 3 //import qs from 'qs'
4   -let cancel ,promiseArr = {}
  4 +let cancel
5 5 const CancelToken = axios.CancelToken;
6 6 //请求拦截器 // 在发送请求之前做些什么
7 7 axios.interceptors.request.use(config => {
8 8 //发起请求时,取消掉当前正在进行的相同请求
9 9 config.headers['x-auth-token'] = '18de1300-c3f2-4365-9f51-62f77614f8c5'
10   - // if(config.method === 'post') {
11   - // let data = qs.parse(config.data)
12   - //
13   - // config.data = qs.stringify({
14   - // sysCode: '1001'
15   - // })
16   - // } else if(config.method === 'get') {
17   - // config.params = {
18   - // sysCode: '1001'
19   - // }
20   - // }
21 10 config.data = {
22 11 ...config.data,
23 12 sysCode: '1001'
... ... @@ -91,35 +80,22 @@ axios.defaults.baseURL = 'http://bcp.service.renniting.cn/';
91 80 // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
92 81 axios.defaults.timeout = 10000
93 82  
94   -export default {
95   - //get请求
96   - get (url,param) {
97   - return new Promise((resolve,reject) => {
98   - axios({
99   - method: 'get',
100   - url,
101   - params: param,
102   - cancelToken: new CancelToken(c => {
103   - cancel = c
104   - })
105   - }).then(res => {
106   - resolve(res)
107   - })
108   - })
109   - },
110   - //post请求
111   - post (url,param) {
112   - return new Promise((resolve,reject) => {
113   - axios({
114   - method: 'post',
115   - url,
116   - data: param,
117   - cancelToken: new CancelToken(c => {
118   - cancel = c
119   - })
120   - }).then(res => {
121   - resolve(res)
  83 +
  84 +function post(url, params) {
  85 + return new Promise((resolve,reject) => {
  86 + axios({
  87 + method: 'post',
  88 + url,
  89 + data: params,
  90 + cancelToken: new CancelToken(c => {
  91 + cancel = c
122 92 })
  93 + }).then(res => {
  94 + resolve(res)
123 95 })
124   - }
  96 + })
125 97 }
  98 +
  99 +
  100 +export {post}
  101 +
... ...
src/components/device/index.vue
... ... @@ -79,41 +79,41 @@
79 79 </template>
80 80  
81 81 <script>
82   - import echarts from 'echarts'
  82 +import { deviceAddress } from '../../api/api'
83 83 export default {
84 84 name: "device",
85 85 data() {
86 86 return {
87   - PDANum:1235,//PDA数
  87 + PDANum:'',//PDA数
88 88 PDAName:'',
89   - diCiNum:1456,//地磁数
  89 + diCiNum:'',//地磁数
90 90 diCiName:'',
91   - daoZhaNum:1245,//道闸数
  91 + daoZhaNum:'',//道闸数
92 92 daoZhaName:'',
93   - youDaoNum:1235,//诱导屏
  93 + youDaoNum:'',//诱导屏
94 94 youDaoName:'',
95 95 name: '设备'
96 96 }
97 97 },
98 98 mounted() {
99   - this.axios.post('urban/intelligence/device/queryDeviceStatistic',{
100   - orgIds: this.GLOBAL.paramsvariables
101   - }).then((response)=>{
102   - let data = response.data.data
103   - this.PDANum = data[0].num
104   - this.PDAName = data[0].deviceName
105   - this.diCiNum = data[1].num
106   - this.diCiName = data[1].deviceName
107   - this.daoZhaNum = data[2].num
108   - this.daoZhaName = data[2].deviceName
109   - this.youDaoNum = data[3].num
110   - this.youDaoName = data[3].deviceName
111   - }).catch((response)=>{
112   - console.log(response);
113   - })
  99 + this.onLoad()
114 100 },
115 101 methods: {
116   -
  102 + onLoad() {
  103 + deviceAddress({orgIds: this.GLOBAL.paramsvariables}).then((response)=>{
  104 + let data = response.data.data
  105 + this.PDANum = data[0].num
  106 + this.PDAName = data[0].deviceName
  107 + this.diCiNum = data[1].num
  108 + this.diCiName = data[1].deviceName
  109 + this.daoZhaNum = data[2].num
  110 + this.daoZhaName = data[2].deviceName
  111 + this.youDaoNum = data[3].num
  112 + this.youDaoName = data[3].deviceName
  113 + }).catch((response)=>{
  114 + console.log(response);
  115 + })
  116 + }
117 117 },
118 118 }
119 119 </script>
... ...
src/components/memberNum/index.vue
... ... @@ -24,38 +24,41 @@
24 24 <script>
25 25 import { mapActions } from 'vuex'
26 26 import common from '../../api/common';
27   - import echarts from 'echarts'
  27 + import { memberAddress } from '../../api/api'
28 28 export default {
29 29 name: "memberNum",
30 30 data() {
31 31 return {
32 32 demo:'',//示例 总数
33 33 memberNumTotal:"",//会员总数html
34   - activeUserNum:23454,//日活跃
35   - newUerNum:521,//新增用户
  34 + activeUserNum:'',//日活跃
  35 + newUerNum:'',//新增用户
36 36 name: '会员数'
37 37 }
38 38 },
39 39 mounted() {
40 40 //会员总数
41   - this.axios.post('urban/intelligence/appuser/queryUserPersonStatistic').then((response)=>{
42   - let data = response.data.data
43   - this.registerNum = data.registerNum
44   - this.memberNumTotal = common.formatNumToStr(this.registerNum);
45   - this.activeUserNum = data.todayActiveNum
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)
51   - }).catch((response)=>{
52   - console.log(response);
53   - })
  41 + this.onLoad()
54 42 },
55 43 methods: {
56 44 ...mapActions([
57 45 'transferParkingTotal'
58   - ])
  46 + ]),
  47 + onLoad() {
  48 + memberAddress().then((response)=>{
  49 + let data = response.data.data
  50 + this.registerNum = data.registerNum
  51 + this.memberNumTotal = common.formatNumToStr(this.registerNum);
  52 + this.activeUserNum = data.todayActiveNum
  53 + this.newUerNum = data.todayRegisterNum
  54 + this.$store.dispatch('transferParkingTotal', data.registerNum)
  55 + //this.$store.dispatch('transferParkingTotal',10000);
  56 + //this.transferParkingTotal( data.registerNum);
  57 + console.log(this.$store.state.ParkingTotal)
  58 + }).catch((response)=>{
  59 + console.log(response);
  60 + })
  61 + }
59 62 /*
60 63 * 格式化会员总数
61 64 // * */
... ...
src/components/tollman/index.vue
... ... @@ -27,41 +27,40 @@
27 27  
28 28 <script>
29 29 import common from '../../api/common';
30   - import echarts from 'echarts'
  30 + import { tollmanAddress } from '../../api/api'
31 31 export default {
32 32 name: "tollman",
33 33 data() {
34 34 return {
35 35 demo:'',//示例 总数
36 36 tollmanTotal:"",//收费员总数html
37   - onDutyNum:254,//值班
38   - noDutyNum:154,//未值班
  37 + onDutyNum:'',//值班
  38 + noDutyNum:'',//未值班
39 39 name: '折线图'
40 40 }
41 41 },
42 42 mounted() {
43 43 //this.createLine();
44 44 //收费员总数
45   -
46   - this.axios.post('urban/intelligence/employee/queryEmployeeStaByOrgIds',{
47   - orgIds: this.GLOBAL.paramsvariables
48   - }).then((response)=>{
49   - let data = response.data.data
50   - this.tollmanTotal = data.allTollCollector
51   - this.tollmanTotal = common.formatNumToStr(this.tollmanTotal);
52   - this.onDutyNum = data.signInTollCollector
53   - this.noDutyNum = data.unSignInTollCollector
54   - }).catch((response)=>{
55   - console.log(response);
56   - })
  45 + this.onLoad()
57 46 },
58 47 methods: {
59 48 /*
60 49 * 格式化会员总数
61 50 * */
62   - formatNumToStr:function(){
63   - return common.formatNumToStr(this.$options.data().demo);
64   - },
  51 + onLoad() {
  52 + tollmanAddress({
  53 + orgIds: this.GLOBAL.paramsvariables
  54 + }).then((response)=>{
  55 + let data = response.data.data
  56 + this.tollmanTotal = data.allTollCollector
  57 + this.tollmanTotal = common.formatNumToStr(this.tollmanTotal);
  58 + this.onDutyNum = data.signInTollCollector
  59 + this.noDutyNum = data.unSignInTollCollector
  60 + }).catch((response)=>{
  61 + console.log(response);
  62 + })
  63 + }
65 64 },
66 65  
67 66 }
... ...