Commit 57282f2b authored by 张伯涛's avatar 张伯涛

接口调用初步修改

parent d47bd55f
import httpTwo from '../httpTwo'
export const getWeatherMagData = () => { // 获取气象干预数据
return httpTwo.get(`/busMeterEquipment/list`)
}
import axios from 'axios'
import store from '../store/index'
// import qs from "qs";
//import { useRouter, useRoute } from 'vue-router'
import { useRouter } from "vue-router";
//import { ref } from 'vue'
//import { ExternalSERVEICE, WithinSERVEICE } from '../../public/config'
import { ElLoading as Loading, ElMessage as Message } from 'element-plus';
let loadingInstance;
let loadingStatus = false;
const router = useRouter();
axios.defaults.timeout = 50000;
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.baseURL = 'http://192.168.116.26:8099/';//ExternalSERVEICE;
axios.defaults.withCredentials = true;
if (!axios.defaults.baseURL.endsWith('/')) {
axios.defaults.baseURL+="/";
}
let ipAddress = 'http://192.168.116.26:8099/';
axios.interceptors.request.use((config) => {
config.baseURL = 'http://192.168.116.26:8099/';
console.log(config.baseURL);
// config.data = qs.stringify(config.data);
return config;
}, (error) => {
return Promise.reject(error);
});
axios.interceptors.response.use((res) => {
closeLoading();
checkResponse(res);
return Promise.resolve(res);
}, (error) => {
closeLoading();
let httpMessage = '';
if (error.response) {
if (error.response.status == '401') {
if (error.response.data && error.response.data.status == 401) {
if (!localStorage.getItem('user')) {
Message.error({
showClose: true,
message: '登陆已过期',
type: 'error'
});
}
toLogin();
return;
}
}
if (error.response.status == '404') {
httpMessage = "未找到请求地址";
}
else if (error.response.data && error.response.data.message) {
httpMessage = error.response.data.message;
}
}
if (error.request) {
httpMessage = "未连接到远程服务器!";
console.log(httpMessage + error.message);
if(error.config.url!='/api/User/getVierificationCode'){
toLogin();
}
}
else {
httpMessage = '服务器处理异常';
}
redirect(httpMessage);
return Promise.reject(error.response || {}, httpMessage);
});
function changeIP(IP){
axios.defaults.baseURL = IP;
}
function showLoading (loading) {
if (!loading || loadingStatus) {
return;
}
loadingInstance = Loading.service({
lock: true,
text: 'Loading',
customClass:"http-loading",
background: typeof loading == "string" ? loading : '正在处理.....',
background: 'rgba(58, 61, 63, 0.32)'
});
}
function closeLoading () {
if (loadingInstance) {
loadingInstance.close();
}
if (loadingStatus) {
loadingStatus = false;
if (loadingInstance) {
loadingInstance.close();
}
}
}
function checkResponse (res) {
//刷新token
if (!res.headers) {
if (res.getResponseHeader("ams_exp") == "1") {
replaceToken();
}
}
else if (res.headers.ams_exp == "1") {
replaceToken();
}
}
const _Authorization = 'Authorization';
function getToken () {
// const token = sessionStorage.getItem('token');
// if(token != null)
// {
// return token;
// }else{
// return "";
// }
//console.log("token:" + store.getters.getToken());
return store.getters.getToken();
}
/*
url
params请求后台的参数,如:{name:123,values:['a','b','c']}
loading是否显示遮罩层,可以传入true.false.及提示文本
config配置信息,如{timeout:3000,headers:{token:123}}
*/
function post (url, params, loading, config) {
showLoading(loading);
//console.log(ipAddress);
axios.defaults.headers[_Authorization] = getToken();
return new Promise((resolve, reject) => {
axios.post(url, params, config)
.then(response => {
resolve(response.data);
}, err => {
reject(err && err.data && err.data.message ? err.data.message : '服务器处理异常');
})
.catch((error) => {
reject(error)
})
})
}
//=true异步请求时会显示遮罩层,=字符串,异步请求时遮罩层显示当前字符串
function get (url, param, loading, config) {
showLoading(loading);
//console.log(ipAddress);
axios.defaults.headers[_Authorization] = getToken();
return new Promise((resolve, reject) => {
axios.get(url, config)
.then(response => {
resolve(response.data)
}, err => {
reject(err)
})
.catch((error) => {
reject(error)
})
})
}
//url:url地址
//params:请求参数
//fileName:下载的文件名
//loading:是否显示加载状态
function download (url, params, fileName, loading, callback) {
fileName = fileName.replace(">", ">").replace("<", "<");
post(url, params, loading, { responseType: 'blob' }).then(content => {
const blob = new Blob([content])
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(blob, fileName)
}
callback&&callback();
})
}
function createXHR () {
if (XMLHttpRequest) {
return new XMLHttpRequest();
}
if (ActiveXObject) {
if (typeof arguments.callee.activeXString != "string") {
var versions = [
"MSXML2.XMLHttp.6.0",
"MSXML2.XMLHttp",
"MSXML2.XMLHttp.3.0"
];
for (var i = 0; i < versions.length; i++) {
try {
new ActiveXObject(versions[i]);
arguments.callee.activeXString = versions[i];
break;
} catch (e) {
console.log(e);
}
}
}
return new ActiveXObject(arguments.callee.activeXString);
}
}
function redirect (responseText, message) {
try {
let responseData = typeof responseText == 'string' ? JSON.parse(responseText) : responseText;
if ((responseData.hasOwnProperty('status') && responseData.status == 401)
|| (responseData.data && responseData.data.status == 401)) {
closeLoading();
toLogin();
} else {
if (message) {
Message.error({
showClose: true,
message: message,
type: 'error'
});
}
}
} catch (error) {
//console.log(error);
Message.error({
showClose: true,
message: responseText,
type: 'error'
});
}
}
//退回到登录页
function toLogin () {
if (window.location.hash) {
window.location.href = window.location.origin + '/#/login'
return
}
window.location.href = window.location.origin + '/login'
}
//动态刷新token
function replaceToken () {
ajax({
url: "/api/User/replaceToken",
param: {},
json: true,
success: function (x) {
if (x.success) {
let userInfo = store.getters.getUserInfo();
userInfo.token = x.data;
store.commit('setUserInfo', userInfo);
} else {
console.log(x.message);
toLogin();
}
},
errror: function (ex) {
console.log(ex);
toLogin();
},
type: "post",
async: false
});
}
function ajax (param) {
let httpParam =
Object.assign({
url: '', headers: {},
param: {}, json: true,
success: function () { },
errror: function () { },
type: 'post', async: true
}, param);
httpParam.url = axios.defaults.baseURL + httpParam.url.replace(/\/?/, '');
httpParam.headers[_Authorization] = getToken();
var xhr = createXHR();
xhr.onreadystatechange = function () {
if (xhr.status == 403 || xhr.status == 401) {
redirect(xhr.responseText);
return;
}
checkResponse(xhr);
if (xhr.readyState == 4 && xhr.status == 200) {
httpParam.success(httpParam.json ? JSON.parse(xhr.responseText) : xhr.responseText);
return;
}
if (xhr.status != 0 && xhr.readyState != 1) {
httpParam.errror(xhr);
}
};
//初始化请求
xhr.open(
httpParam.type,
httpParam.url,
httpParam.async
);
xhr.setRequestHeader("Content-type", "application/json");
for (const key in httpParam.headers) {
xhr.setRequestHeader(key, httpParam.headers[key]);
}
try {
xhr.send(JSON.stringify(httpParam.param));
} catch (error) {
toLogin();
}
}
ajax.post = function (url, param, success, errror) {
ajax({ url: url, param: param, success: success, error: errror, type: 'post' })
}
ajax.get = function (url, param, success, errror) {
ajax({ url: url, param: param, success: success, error: errror, type: 'get' })
}
export default { post, get, download, ajax, ipAddress, changeIP }
...@@ -20,6 +20,7 @@ import Notifications from '@kyvg/vue3-notification' ...@@ -20,6 +20,7 @@ import Notifications from '@kyvg/vue3-notification'
import App from './App.vue' import App from './App.vue'
import http from './api/http' import http from './api/http'
import httpTwo from './api/httpTwo'
import store from './store' import store from './store'
import $ from 'jquery' import $ from 'jquery'
// import {WebControl} from '@/assets/script/video/web-control.esm.min.js' // import {WebControl} from '@/assets/script/video/web-control.esm.min.js'
...@@ -36,6 +37,7 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) { ...@@ -36,6 +37,7 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component('Notification', Notification) app.component('Notification', Notification)
app.config.globalProperties.http = http; app.config.globalProperties.http = http;
app.config.globalProperties.httpTwo = httpTwo;
// app.config.globalProperties.$api = api; // app.config.globalProperties.$api = api;
//将element-plus注册成全局可用组件库 //将element-plus注册成全局可用组件库
app.use(store) app.use(store)
......
...@@ -5,7 +5,8 @@ import ExtinguisherHistoryPage from './ExtinguisherHistoryPage.vue' // 导入组 ...@@ -5,7 +5,8 @@ import ExtinguisherHistoryPage from './ExtinguisherHistoryPage.vue' // 导入组
import ExtinguisherAlarmPage from './ExtinguisherAlarmPage.vue' // 导入组件 import ExtinguisherAlarmPage from './ExtinguisherAlarmPage.vue' // 导入组件
import zhCn from "element-plus/dist/locale/zh-cn.mjs" import zhCn from "element-plus/dist/locale/zh-cn.mjs"
import store from "../../../store/index.js"; import store from "../../../store/index.js";
import {getWeatherMagData} from "@/api/AIStation/Extinguisher.js";
import axios from 'axios'
const options = reactive([]); const options = reactive([]);
const enterpriseId = ref(); const enterpriseId = ref();
const props = { multiple: true, emitPath: false } const props = { multiple: true, emitPath: false }
...@@ -103,6 +104,12 @@ const search = () => { ...@@ -103,6 +104,12 @@ const search = () => {
startTime: queryParams.value.startTime, startTime: queryParams.value.startTime,
endTime: queryParams.value.endTime, endTime: queryParams.value.endTime,
} }
axios.get('http://192.168.116.26:8099/busMeterEquipment/list').then(res => {
})
// getWeatherMagData().then(res => {
//
// })
console.log('查询:', item); console.log('查询:', item);
searchData.value = data; searchData.value = data;
console.log('传值:', searchData.value); console.log('传值:', searchData.value);
...@@ -113,36 +120,36 @@ const search = () => { ...@@ -113,36 +120,36 @@ const search = () => {
// console.log('导出:', queryParams.value); // console.log('导出:', queryParams.value);
// }; // };
this.$axios.get(this.HTTPApi + '/contract/contract/detail/' + FROMID).then(res => { // this.$axios.get(this.HTTPApi + '/contract/contract/detail/' + FROMID).then(res => {
} // })
/** 导出按钮操作 */ /** 导出按钮操作 */
function handleExport() { // function handleExport() {
const item = { // const item = {
stationId: stationId.value, // stationId: stationId.value,
alarmStatus: queryParams.value.alarmStatus, // alarmStatus: queryParams.value.alarmStatus,
alarmType: queryParams.value.alarmType, // alarmType: queryParams.value.alarmType,
startTime: queryParams.value.startTime, // startTime: queryParams.value.startTime,
endTime: queryParams.value.endTime, // endTime: queryParams.value.endTime,
} // }
this.$confirm('是否确认操作?', '警告', { // this.$confirm('是否确认操作?', '警告', {
confirmButtonText: '确定', // confirmButtonText: '确定',
cancelButtonText: '取消', // cancelButtonText: '取消',
type: 'warning' // type: 'warning'
}).then(function() { // }).then(function() {
return exportExtinguisherPage(item).then(response => { // return exportExtinguisherPage(item).then(response => {
const blob = new Blob([response]) // const blob = new Blob([response])
const downloadElement = document.createElement('a') // const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接 // const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href // downloadElement.href = href
downloadElement.download = '灭火器信息' + '.xls' // 下载后文件名 // downloadElement.download = '灭火器信息' + '.xls' // 下载后文件名
document.body.appendChild(downloadElement) // document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载 // downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素 // document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象 // window.URL.revokeObjectURL(href)// 释放掉blob对象
}) // })
}) // })
} // }
// 重置 // 重置
const resetSearch = () => { const resetSearch = () => {
queryParams.value = { queryParams.value = {
......
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