5 changed files with 143 additions and 8 deletions
@ -1,8 +1,8 @@ |
|||||
{ |
{ |
||||
"name": "vueDatav", |
"name": "parkBigScreen2", |
||||
"version": "0.1.0", |
"version": "0.1.0", |
||||
"private": true, |
"private": true, |
||||
"author": "JackChen <[email protected]>", |
"author": "weirui", |
||||
"scripts": { |
"scripts": { |
||||
"serve": "vue-cli-service serve", |
"serve": "vue-cli-service serve", |
||||
"build": "vue-cli-service build", |
"build": "vue-cli-service build", |
||||
|
@ -0,0 +1,49 @@ |
|||||
|
import request from '@/api/request' |
||||
|
|
||||
|
/** |
||||
|
* 大数据api接口 |
||||
|
*/ |
||||
|
export const BiApi = { |
||||
|
// 车场排行
|
||||
|
getParkingRanking: (query) => { |
||||
|
return request({ |
||||
|
url: '/pk/openup/OpenStatisticsController/parkingRanking', |
||||
|
method: 'get', |
||||
|
params: query |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 广告位-id查询
|
||||
|
getInfo: (id) => { |
||||
|
return request({ |
||||
|
url: '/pk/ad/PkAdPosition/getInfo/' + id, |
||||
|
method: 'get' |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 新增广告位
|
||||
|
addInfo: (data) => { |
||||
|
return request({ |
||||
|
url: '/pk/ad/PkAdPosition/add', |
||||
|
method: 'post', |
||||
|
data: data |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 编辑广告位
|
||||
|
updateInfo: (data) => { |
||||
|
return request({ |
||||
|
url: '/pk/ad/PkAdPosition/edit', |
||||
|
method: 'put', |
||||
|
data: data |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
// 删除广告位
|
||||
|
delInfo: (id) => { |
||||
|
return request({ |
||||
|
url: '/pk/ad/PkAdPosition/remove/' + id, |
||||
|
method: 'delete' |
||||
|
}) |
||||
|
} |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
|
||||
|
|
||||
|
import axios from 'axios' |
||||
|
|
||||
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
||||
|
|
||||
|
// 创建axios实例
|
||||
|
const service = axios.create({ |
||||
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||
|
baseURL: 'http://192.168.31.128:8866', |
||||
|
// 超时
|
||||
|
timeout: 30000 |
||||
|
}) |
||||
|
// request拦截器
|
||||
|
service.interceptors.request.use(config => { |
||||
|
// get请求映射params参数
|
||||
|
if (config.method === 'get' && config.params) { |
||||
|
let url = config.url + '?'; |
||||
|
for (const propName of Object.keys(config.params)) { |
||||
|
const value = config.params[propName]; |
||||
|
var part = encodeURIComponent(propName) + "="; |
||||
|
if (value !== null && typeof (value) !== "undefined") { |
||||
|
if (typeof value === 'object') { |
||||
|
for (const key of Object.keys(value)) { |
||||
|
let params = propName + '[' + key + ']'; |
||||
|
var subPart = encodeURIComponent(params) + "="; |
||||
|
url += subPart + encodeURIComponent(value[key]) + "&"; |
||||
|
} |
||||
|
} else { |
||||
|
url += part + encodeURIComponent(value) + "&"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
url = url.slice(0, -1); |
||||
|
config.params = {}; |
||||
|
config.url = url; |
||||
|
} |
||||
|
return config |
||||
|
}, error => { |
||||
|
console.log(error) |
||||
|
Promise.reject(error) |
||||
|
}) |
||||
|
|
||||
|
// 响应拦截器
|
||||
|
service.interceptors.response.use(res => { |
||||
|
// console.log(res);
|
||||
|
// 未设置状态码则默认成功状态
|
||||
|
const code = res.data.code || 200; |
||||
|
// 获取错误信息
|
||||
|
const msg = res.data.msg |
||||
|
if (code === 401) { |
||||
|
console.log(msg); |
||||
|
} else if (code === 500) { |
||||
|
console.log(msg); |
||||
|
} else if (code !== 200) { |
||||
|
console.log(msg); |
||||
|
} else { |
||||
|
return res.data |
||||
|
} |
||||
|
}, |
||||
|
error => { |
||||
|
console.log('err' + error) |
||||
|
let { message } = error; |
||||
|
if (message == "Network Error") { |
||||
|
message = "后端接口连接异常"; |
||||
|
} |
||||
|
else if (message.includes("timeout")) { |
||||
|
message = "系统接口请求超时"; |
||||
|
} |
||||
|
else if (message.includes("Request failed with status code")) { |
||||
|
message = "系统接口" + message.substr(message.length - 3) + "异常"; |
||||
|
} |
||||
|
alert(message) |
||||
|
return Promise.reject(error) |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
export default service |
Loading…
Reference in new issue