Commit 490b471e authored by 郭铭瑶's avatar 郭铭瑶 🤘

网格相关请求添加自定义headers

parent 83cbb3d5
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
......
......@@ -32,7 +32,7 @@ Axios.interceptors.response.use(response => {
* @param {String} contentType [请求头,默认为'application/json;charset=UTF-8']
* @param {Boolean} showLoading [是否显示请求时的loading图,默认为false]
*/
const request = ({ method, url, params = {}, contentType = 'application/json;charset=UTF-8', showLoading = false }) => {
const request = ({ method, url, params = {}, contentType = 'application/json;charset=UTF-8', showLoading = false, headers = {} }) => {
if (!url || typeof(url) != 'string') {
throw new Error('接口URL不正确')
}
......@@ -42,6 +42,7 @@ const request = ({ method, url, params = {}, contentType = 'application/json;cha
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': contentType,
...headers
},
}
if (method === 'GET') {
......@@ -60,6 +61,9 @@ const request = ({ method, url, params = {}, contentType = 'application/json;cha
}
export default {
fetch(args) { // only for 网格相关请求需自定义headers(即api.DATA_URL开头的api)
return request({ method: 'GET', ...args, headers: api.GRID_OPTION})
},
get(args) {
return request({ method: 'GET', ...args })
},
......
......@@ -14,6 +14,10 @@ default:
// BASE_URL = 'http://yangpu.hm.omniview.pro/api' // 废弃
}
export default {
GRID_OPTION: { // 网格相关请求需要添加的headers内容
user: 'linkthings',
pwd: '2EBC694BBBA02355AA8B7FE0F03ECB52',
},
MAP_NET,
BASE_URL,
DATA_URL,
......
......@@ -29,9 +29,9 @@ export default {
},
async getGreenInfo({commit}) {
const result = [
{name: '环卫公厕', value: await ajax.get({url: api.DATA_URL + api.GET_TOILET_COUNT, params: {street: curStreet}}) || 0},
{name: '生活垃圾收集', value: await ajax.get({url: api.DATA_URL + api.GET_GARBAGE_COUNT, params: {street: curStreet}}) || 0},
{name: '小型压缩站', value: await ajax.get({url: api.DATA_URL + api.GET_COMPRESS_COUNT, params: {street: curStreet}}) || 0},
{name: '环卫公厕', value: await ajax.fetch({url: api.DATA_URL + api.GET_TOILET_COUNT, params: {street: curStreet}}) || 0},
{name: '生活垃圾收集', value: await ajax.fetch({url: api.DATA_URL + api.GET_GARBAGE_COUNT, params: {street: curStreet}}) || 0},
{name: '小型压缩站', value: await ajax.fetch({url: api.DATA_URL + api.GET_COMPRESS_COUNT, params: {street: curStreet}}) || 0},
]
commit('SET_GREEN_INFO', result)
},
......@@ -80,24 +80,24 @@ export default {
async getGridSum({commit}) {
const start = moment().format('YYYY-MM-DD')
const end = moment().add(1, 'days').format('YYYY-MM-DD')
const grid1 = await ajax.get({url: api.DATA_URL + api.GET_GRID1, params: {street: curStreet, start, end}})
const grid2 = await ajax.get({url: api.DATA_URL + api.GET_GRID2, params: {street: curStreet, start, end}})
const grid3 = await ajax.get({url: api.DATA_URL + api.GET_GRID3, params: {street: curStreet, start, end}})
const grid4 = await ajax.get({url: api.DATA_URL + api.GET_GRID4, params: {street: curStreet, start, end}})
const grid5 = await ajax.get({url: api.DATA_URL + api.GET_GRID5, params: {street: curStreet, start, end}})
const grid6 = await ajax.get({url: api.DATA_URL + api.GET_GRID6, params: {street: curStreet, start, end}})
const grid1 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID1, params: {street: curStreet, start, end}})
const grid2 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID2, params: {street: curStreet, start, end}})
const grid3 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID3, params: {street: curStreet, start, end}})
const grid4 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID4, params: {street: curStreet, start, end}})
const grid5 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID5, params: {street: curStreet, start, end}})
const grid6 = await ajax.fetch({url: api.DATA_URL + api.GET_GRID6, params: {street: curStreet, start, end}})
commit('SET_GRID_SUM', [+grid1 || 0, +grid2 || 0, +grid3 || 0, +grid4 || 0, +grid5 || 0, +grid6 || 0])
const alert1 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT1, params: {street: curStreet, start, end}})
const alert2 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT2, params: {street: curStreet, start, end}})
const alert3 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT3, params: {street: curStreet, start, end}})
const alert4 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT4, params: {street: curStreet, start, end}})
const alert5 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT5, params: {street: curStreet, start, end}})
const alert6 = await ajax.get({url: api.DATA_URL + api.GET_NOT_ALERT6, params: {street: curStreet, start, end}})
const alert1 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT1, params: {street: curStreet, start, end}})
const alert2 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT2, params: {street: curStreet, start, end}})
const alert3 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT3, params: {street: curStreet, start, end}})
const alert4 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT4, params: {street: curStreet, start, end}})
const alert5 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT5, params: {street: curStreet, start, end}})
const alert6 = await ajax.fetch({url: api.DATA_URL + api.GET_NOT_ALERT6, params: {street: curStreet, start, end}})
commit('SET_NOT_ALERT_SUM', [+alert1 || 0, +alert2 || 0, +alert3 || 0, +alert4 || 0, +alert5 || 0, +alert6 || 0])
},
async getPopulationInfo({commit}) {
const year1 = await ajax.get({url: api.DATA_URL + api.GET_POPULATION_INFO, params: {year: moment().add(-2, 'y').format('YYYY')}})
const year2 = await ajax.get({url: api.DATA_URL + api.GET_POPULATION_INFO, params: {year: moment().add(-1, 'y').format('YYYY')}})
const year1 = await ajax.fetch({url: api.DATA_URL + api.GET_POPULATION_INFO, params: {year: moment().add(-2, 'y').format('YYYY')}})
const year2 = await ajax.fetch({url: api.DATA_URL + api.GET_POPULATION_INFO, params: {year: moment().add(-1, 'y').format('YYYY')}})
if (year1 && year2) {
const result = [year1, year2].map(year => year.find(item => item.street == '总计'))
commit('SET_LAND_POPULATION_INFO', result)
......
......@@ -268,7 +268,7 @@ export default {
this.removeSelectedGridLayer()
const [paths] = geometry.rings
this.selectedGridArea = map.addPolygon({paths, fillColor: 'rgba(255,235,59,.15)'})
this.$ajax.get({
this.$ajax.fetch({
url: this.$api.DATA_URL + this.$api.GET_GRID_PERSON,
params: {street: this.currentStreetInfo.name, gridId: +attributes['网格编']},
showLoading: true,
......
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 to comment