|
@@ -1,6 +1,5 @@
|
|
|
import axios from 'axios'
|
|
|
import { ElNotification, ElMessageBox, ElMessage, ElLoading } from 'element-plus'
|
|
|
-// import { getToken } from '@/utils/auth'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
import { tansParams, blobValidate } from '@/utils/ruoyi'
|
|
|
import cache from '@/plugins/cache'
|
|
@@ -21,49 +20,32 @@ const service = axios.create({
|
|
|
})
|
|
|
// request拦截器
|
|
|
service.interceptors.request.use(config => {
|
|
|
-
|
|
|
-
|
|
|
-// 获取请求头参数
|
|
|
- const {signature, timestamp, secret} = signatureGenerate(config)
|
|
|
-
|
|
|
- config.headers['key'] = 'c65ba95718be44a88d69962b66094075'
|
|
|
- config.headers['sign'] = signature
|
|
|
- config.headers['timestamp'] = timestamp
|
|
|
-
|
|
|
-
|
|
|
- console.log('post请求参数')
|
|
|
- console.log(config.data)
|
|
|
-
|
|
|
-
|
|
|
- // 如果存在data,并且我们想替换body
|
|
|
- if (config.data && config.method.toLowerCase() === 'post') {
|
|
|
+ //获取请求头参数
|
|
|
+ const {signature, timestamp, secret} = signatureGenerate(config)
|
|
|
+ config.headers['key'] = 'c65ba95718be44a88d69962b66094075' //富士接口key
|
|
|
+ config.headers['sign'] = signature //富士接口签名
|
|
|
+ config.headers['timestamp'] = timestamp
|
|
|
+ // console.log('post请求参数')
|
|
|
+ // console.log(config.data)
|
|
|
+ // 如果存在data,并且我们想替换body
|
|
|
+ if (config.data && config.method.toLowerCase() === 'post') {
|
|
|
// 将数据转换为JSON字符串
|
|
|
const data = JSON.stringify(config.data);
|
|
|
// 对数据进行Base64编码
|
|
|
const base64EncodedData = base64Encode(data);
|
|
|
// 替换请求体
|
|
|
config.data = base64EncodedData;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- function base64Encode(str) {
|
|
|
- // 先将字符串转换为Latin1编码
|
|
|
- var latin1Str = unescape(encodeURIComponent(str));
|
|
|
- // 然后使用btoa进行Base64编码
|
|
|
- return btoa(latin1Str);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+ function base64Encode(str) {
|
|
|
+ // 先将字符串转换为Latin1编码
|
|
|
+ var latin1Str = unescape(encodeURIComponent(str));
|
|
|
+ // 然后使用btoa进行Base64编码
|
|
|
+ return btoa(latin1Str);
|
|
|
+ }
|
|
|
// 是否需要设置 token
|
|
|
const isToken = (config.headers || {}).isToken === false
|
|
|
// 是否需要防止数据重复提交
|
|
|
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
|
|
- if (localStorage.getItem("token725") && !isToken) {
|
|
|
- config.headers['Authorization'] = localStorage.getItem("token725") // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
- }
|
|
|
// get请求映射params参数
|
|
|
if (config.method === 'get' && config.params) {
|
|
|
let url = config.url + '?' + tansParams(config.params);
|
|
@@ -97,17 +79,8 @@ service.interceptors.request.use(config => {
|
|
|
cache.session.setJSON('sessionObj', requestObj)
|
|
|
}
|
|
|
}
|
|
|
- if (config.url == "/YtIoT/iot/alarm/view/updateHj" ||
|
|
|
- config.url == "/YtIoT/iot/alarm/view/updateEf" ||
|
|
|
- config.url == "/YtIoT/iot/alarm/view/updateSj" ||
|
|
|
- config.url == "/YtIoT/iot/alarm/view/updateRtu" ||
|
|
|
- config.url == "/YtIoT/iot/alarm/view/updateAlarm" ||
|
|
|
- config.url == "/YtIoT/iot/frontpage/getCurrentObjectListByCompanyId" ||
|
|
|
- config.url == "/YtIoT/iot/frontpage/getCurrentStatus") { //消防互联网大屏
|
|
|
- config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
|
- } else {
|
|
|
- config.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
- }
|
|
|
+ config.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
+
|
|
|
return config
|
|
|
}, error => {
|
|
|
Promise.reject(error)
|
|
@@ -115,52 +88,39 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(res => {
|
|
|
- if (res.data.chk) { //安博展撒点 c++ 还
|
|
|
+ // 未设置状态码则默认成功状态
|
|
|
+ const code = res.data.status;
|
|
|
+ // 获取错误信息
|
|
|
+ const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
+ // 二进制数据则直接返回
|
|
|
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
return res.data
|
|
|
- } else if (res.data.action == "updateHj" ||
|
|
|
- res.data.action == "updateEf" ||
|
|
|
- res.data.action == "updateSj" ||
|
|
|
- res.data.action == "updateRtu" ||
|
|
|
- res.data.action == "updateAlarm" ||
|
|
|
- res.data.action == "getCurrentObjectListByCompanyId" ||
|
|
|
- res.data.action == "getCurrentStatus"
|
|
|
- ) { //告警处理
|
|
|
+ }
|
|
|
+ if (code == "SUCCESS" || res.data.msg == "操作成功") {
|
|
|
+ return res.headers['content-type'].indexOf("application/vnd.ms-excel") != -1 ? res : res.data
|
|
|
+ } else if (res.data.code == 0) { //系统监控=>定时任务
|
|
|
return res.data
|
|
|
} else {
|
|
|
- // 未设置状态码则默认成功状态
|
|
|
- const code = res.data.status;
|
|
|
- // 获取错误信息
|
|
|
- const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
- // 二进制数据则直接返回
|
|
|
- if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
- return res.data
|
|
|
- }
|
|
|
- if (code == "SUCCESS" || res.data.msg == "操作成功") {
|
|
|
- return res.headers['content-type'].indexOf("application/vnd.ms-excel") != -1 ? res : res.data
|
|
|
- } else if (res.data.code == 0) { //系统监控=>定时任务
|
|
|
- return res.data
|
|
|
+ if (res.data.code == "401") {
|
|
|
+ return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
+ } else if (res.data.code === 500) {
|
|
|
+ ElMessage({
|
|
|
+ message: msg,
|
|
|
+ type: 'error'
|
|
|
+ })
|
|
|
+ return msg && Promise.reject(new Error(msg)) || ""
|
|
|
+ } else if (res.data.code !== 0) {
|
|
|
+ ElNotification.error({
|
|
|
+ title: msg
|
|
|
+ })
|
|
|
+ return Promise.reject('error')
|
|
|
} else {
|
|
|
- if (res.data.code == "401") {
|
|
|
- return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
- } else if (res.data.code === 500) {
|
|
|
- ElMessage({
|
|
|
- message: msg,
|
|
|
- type: 'error'
|
|
|
- })
|
|
|
- return msg && Promise.reject(new Error(msg)) || ""
|
|
|
- } else if (res.data.code !== 0) {
|
|
|
- ElNotification.error({
|
|
|
- title: msg
|
|
|
- })
|
|
|
- return Promise.reject('error')
|
|
|
- } else {
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
error => {
|
|
|
- let message = error.response.data.msg;
|
|
|
+ let message = error?.response?.data?.msg || "";
|
|
|
if (message == "Network Error") {
|
|
|
message = "后端接口连接异常";
|
|
|
} else if (message.includes("timeout")) {
|