Commit ca49ee07 by zhangxw

接口调试,导出方法修改

1 parent 4ce8dade
...@@ -164,7 +164,7 @@ export const GET_AMAP_PROVINCE = params => { ...@@ -164,7 +164,7 @@ export const GET_AMAP_PROVINCE = params => {
// 历史停留列表 // 历史停留列表
export const GET_HISTORY_LOCATION = params => { export const GET_HISTORY_LOCATION = params => {
return request(params, '/trialdrive/monitor/stayPointList', 'get') return request(params, '/trialdrive/monitor/stayPointList', 'post')
} }
// 常驻地数据 // 常驻地数据
export const GET_RESIDENT_LOCATION = params => { export const GET_RESIDENT_LOCATION = params => {
......
...@@ -175,6 +175,7 @@ ...@@ -175,6 +175,7 @@
standno: this.$route.query.standno, standno: this.$route.query.standno,
sortByTimeIsPositive: true, sortByTimeIsPositive: true,
sortByStayIsPositive: true, sortByStayIsPositive: true,
sortType: '',
pickerOptions: { pickerOptions: {
disabledDate(time){ disabledDate(time){
return time.getTime() > ((new Date()).getTime()-24*60*60*1000) return time.getTime() > ((new Date()).getTime()-24*60*60*1000)
...@@ -236,8 +237,9 @@ ...@@ -236,8 +237,9 @@
params.minTime = this.form.stayMin; params.minTime = this.form.stayMin;
} }
this.params = params this.params = params
this.getSortParams()
EventBus.$emit('uiMap.historyLocation.destroy'); EventBus.$emit('uiMap.historyLocation.destroy');
let res = mock.getResidentByRealTime let res = mock.getResidentByRealTime
if (res.returnCode == 0) { if (res.returnCode == 0) {
const data = res.data const data = res.data
if (data.length) { if (data.length) {
...@@ -257,8 +259,8 @@ ...@@ -257,8 +259,8 @@
} }
this.isSearching = false this.isSearching = false
} }
GET_HISTORY_LOCATION(params).then((res)=>{ GET_HISTORY_LOCATION({...this.params}).then((res)=>{
if(res.returnCode == 0){ if(res.code == 200){
const data = res.data; const data = res.data;
if(data.length){ if(data.length){
data.forEach((item, idx)=>{ data.forEach((item, idx)=>{
...@@ -336,20 +338,33 @@ ...@@ -336,20 +338,33 @@
}) })
}, },
sortByTime(){ sortByTime(){
let sortArr = this.resultList.sort((a,b)=>{ // let sortArr = this.resultList.sort((a,b)=>{
return moment(a.begintime).isBefore(moment(b.begintime))?(this.sortByTimeIsPositive?-1:1):(this.sortByTimeIsPositive?1:-1); // return moment(a.begintime).isBefore(moment(b.begintime))?(this.sortByTimeIsPositive?-1:1):(this.sortByTimeIsPositive?1:-1);
}); // });
this.sortByTimeIsPositive = !this.sortByTimeIsPositive; this.sortByTimeIsPositive = !this.sortByTimeIsPositive;
this.resultList = [].concat(sortArr); // this.resultList = [].concat(sortArr);
this.sortType = 'beginTime'
this.getSortParams()
this.searchSubmit()
},
getSortParams() {
this.params.sort = this.sortType ? {
filed: this.sortType,
order: this.sortType === 'beginTime' ? (this.sortByTimeIsPositive ? 'ASC' : 'DESC') : (this.sortByStayIsPositive ? 'ASC' : 'DESC')
} : undefined
return this.params
}, },
sortByStay(){ sortByStay(){
let sortArr = this.resultList.sort((a,b)=>{ // let sortArr = this.resultList.sort((a,b)=>{
let aTime = (new Date(a.endtime)).getTime() - (new Date(a.begintime)).getTime(); // let aTime = (new Date(a.endtime)).getTime() - (new Date(a.begintime)).getTime();
let bTime = (new Date(b.endtime)).getTime() - (new Date(b.begintime)).getTime(); // let bTime = (new Date(b.endtime)).getTime() - (new Date(b.begintime)).getTime();
return aTime>bTime?(this.sortByStayIsPositive?-1:1):(this.sortByStayIsPositive?1:-1); // return aTime>bTime?(this.sortByStayIsPositive?-1:1):(this.sortByStayIsPositive?1:-1);
}); // });
this.sortByStayIsPositive = !this.sortByStayIsPositive; this.sortByStayIsPositive = !this.sortByStayIsPositive;
this.resultList = [].concat(sortArr); // this.resultList = [].concat(sortArr);
this.sortType = 'duration'
this.getSortParams()
this.searchSubmit()
}, },
exportExcel(){ exportExcel(){
// let arr = []; // let arr = [];
...@@ -362,8 +377,14 @@ ...@@ -362,8 +377,14 @@
// vmExportType: 6, // vmExportType: 6,
// jsonStr: encodeURI(JSON.stringify(arr)) // jsonStr: encodeURI(JSON.stringify(arr))
// }, 'post'); // }, 'post');
// let params = this.params
// params.sort = this.sortType ? {
// filed: this.sortType,
// order: this.sortType === 'beginTime' ? (this.sortByTimeIsPositive ? 'ASC' : 'DESC') : (this.sortByStayIsPositive ? 'ASC' : 'DESC')
// } : undefined
this.getSortParams()
if (this.resultList.length) { if (this.resultList.length) {
exportExcel('/trialdrive/monitor/exportStayPoint', {...this.params}, 'get'); exportExcel('/trialdrive/monitor/exportStayPoint', {...this.params}, 'post', '', true);
} else { } else {
this.$message({ this.$message({
type: 'error', type: 'error',
......
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
} }
this.params = params this.params = params
let res = mock.getResidentByRealTime let res = mock.getResidentByRealTime
if(res.returnCode == 0){ if(res.returnCode == 0){
const data = res.data; const data = res.data;
if(data.length){ if(data.length){
data.forEach((item, idx)=>{ data.forEach((item, idx)=>{
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
this.isSearching = false; this.isSearching = false;
} }
GET_RESIDENT_LOCATION(params).then((res)=>{ GET_RESIDENT_LOCATION(params).then((res)=>{
if(res.returnCode == 0){ if(res.code == 200){
const data = res.data; const data = res.data;
if(data.length){ if(data.length){
data.forEach((item, idx)=>{ data.forEach((item, idx)=>{
...@@ -280,7 +280,7 @@ ...@@ -280,7 +280,7 @@
// jsonStr: encodeURI(JSON.stringify(paramArr)), // jsonStr: encodeURI(JSON.stringify(paramArr)),
// vmExportType: 4 // vmExportType: 4
// }, 'post'); // }, 'post');
exportExcel('/trialdrive/monitor/exportResident', {...this.params}, 'get'); exportExcel('/trialdrive/monitor/exportResident', {...this.params}, 'get', '', true);
this.exporting = false; this.exporting = false;
}else{ }else{
this.$message({ this.$message({
......
...@@ -4,7 +4,7 @@ import qs from 'qs' ...@@ -4,7 +4,7 @@ import qs from 'qs'
import { Message } from "element-ui"; import { Message } from "element-ui";
import store from '../vuex/store' import store from '../vuex/store'
export default (url, oParam, datatype, cb) => { export default (url, oParam, datatype, cb, requestBody) => {
/*let exportForm = document.querySelector("#exportForm"); /*let exportForm = document.querySelector("#exportForm");
if(exportForm){ if(exportForm){
document.body.removeChild(exportForm) document.body.removeChild(exportForm)
...@@ -27,8 +27,26 @@ export default (url, oParam, datatype, cb) => { ...@@ -27,8 +27,26 @@ export default (url, oParam, datatype, cb) => {
exportForm.innerHTML = _input; exportForm.innerHTML = _input;
exportForm.submit();*/ exportForm.submit();*/
let BASE_URL = store.getters.baseURL; let BASE_URL = store.getters.baseURL;
url = BASE_URL+url url = BASE_URL + url
if (datatype == 'post') { if (datatype == 'post' && requestBody) {
axios.post(url, oParam, {
headers: {
'Content-Type': 'application/json',
Authorization: localStorage.getItem('token') || ''
}
})
.then(response => {
if (response) {
successCb(response, cb, requestBody)
}
})
.catch(err => {
console.log(`接口调用失败`);
console.log(err);
})
} else if (datatype == 'post') {
axios.post(url, typeof oParam == 'string'?oParam:qs.stringify(oParam), { axios.post(url, typeof oParam == 'string'?oParam:qs.stringify(oParam), {
responseType: 'blob', //指定返回数据的格式为blob responseType: 'blob', //指定返回数据的格式为blob
headers: { headers: {
...@@ -47,9 +65,8 @@ export default (url, oParam, datatype, cb) => { ...@@ -47,9 +65,8 @@ export default (url, oParam, datatype, cb) => {
console.log(err); console.log(err);
}); });
} else { } else if (datatype == 'get' && requestBody) {
axios.get(url, /*qs.stringify(oParam),*/ { axios.get(url, /*qs.stringify(oParam),*/ {
responseType: 'blob', //指定返回数据的格式为blob
params: oParam, params: oParam,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
...@@ -58,7 +75,7 @@ export default (url, oParam, datatype, cb) => { ...@@ -58,7 +75,7 @@ export default (url, oParam, datatype, cb) => {
}) })
.then(response => { .then(response => {
if (response) { if (response) {
successCb(response) successCb(response, cb, requestBody)
} }
}) })
...@@ -67,16 +84,51 @@ export default (url, oParam, datatype, cb) => { ...@@ -67,16 +84,51 @@ export default (url, oParam, datatype, cb) => {
console.log(err); console.log(err);
}); });
} else {
axios.get(url, /*qs.stringify(oParam),*/ {
responseType: 'blob', //指定返回数据的格式为blob
params: oParam,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
Authorization: localStorage.getItem('token') || ''
}
})
.then(response => {
if (response) {
successCb(response, cb, requestBody)
}
})
.catch(err => {
console.log(`接口调用失败`);
console.log(err);
});
} }
function successCb(response, cb) { function successCb(response, cb, requestBody) {
if (response.headers && response.headers.sessionstatus == 'timeout') { if (response.headers && response.headers.sessionstatus == 'timeout') {
window.location.href = '../ots/login'; window.location.href = '../ots/login';
return; return;
} }
if (requestBody) { //新导出处理
if (response.headers && response.headers['content-disposition']) { let url = response.data.data;
if (url && response.data.code === 200) {
let filename = response.data.data.split('/')[response.data.data.split('/').length - 1]
var a = document.createElement("a");
document.body.appendChild(a);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
} else {
Message({
message: response.data.message,
type: 'error'
})
}
} else if (response.headers && response.headers['content-disposition']) {
let filename = decodeURIComponent(response.headers['content-disposition'].replace('attachment;filename=', '')); let filename = decodeURIComponent(response.headers['content-disposition'].replace('attachment;filename=', ''));
if (window.navigator.appVersion.toString().indexOf('.NET') > 0) { if (window.navigator.appVersion.toString().indexOf('.NET') > 0) {
window.navigator.msSaveBlob(response.data, filename); window.navigator.msSaveBlob(response.data, filename);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!