import axios from "axios"; import vuex from "@/store/index.js"; import errorCode from "@/utils/errorCode"; import { tansParams, blobValidate } from "@/utils/ruoyi"; import cache from "@/plugins/cache"; import { Notification, MessageBox, Message, Loading } from "element-ui"; import { saveAs } from "file-saver"; import { getToken } from "@/utils/auth"; axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8"; // 是否显示重新登录 export let isReloginShow = false; // 创建axios实例 const request = axios.create({ // axios中请求配置有baseURL选项,表示请求URL公共部分 baseURL: window.axiosURI, //baseURL: "http://192.168.100.252:8080", // 超时 timeout: 100000, }); // request拦截器 request.interceptors.request.use( (config) => { //代码防止重复提交会导致浏览器内存溢出,因此没在这添加判断 config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 // 是否需要防止数据重复提交 const isRepeatSubmit = (config.headers || {}).repeatSubmit === false; // get请求映射params参数 if (config.method === "get" && config.params) { let url = config.url + "?" + tansParams(config.params); url = url.slice(0, -1); config.params = {}; config.url = url; } if ( !isRepeatSubmit && (config.method === "post" || config.method === "put") ) { const requestObj = { url: config.url, data: typeof config.data === "object" ? JSON.stringify(config.data) : config.data, time: new Date().getTime(), }; if (requestObj.data.length > 2048) { requestObj.data = requestObj.data.substring(0, 2048); } const sessionObj = cache.session.getJSON("sessionObj"); if ( sessionObj === undefined || sessionObj === null || sessionObj === "" ) { cache.session.setJSON("sessionObj", requestObj); } else { const s_url = sessionObj.url; // 请求地址 const s_data = sessionObj.data; // 请求数据 const s_time = sessionObj.time; // 请求时间 const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交 if ( s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url ) { const message = "数据正在处理,请勿重复提交"; console.warn(`[${s_url}]: ` + message); return Promise.reject(new Error(message)); } else { cache.session.setJSON("sessionObj", requestObj); } } } return config; }, (error) => { console.log(error); Promise.reject(error); } ); // 响应拦截器 request.interceptors.response.use( (res) => { // 未设置状态码则默认成功状态 const code = res.data.code || 200; // 获取错误信息 const msg = errorCode[code] || res.data.msg || errorCode["default"]; // 二进制数据则直接返回 if ( res.request.responseType === "blob" || res.request.responseType === "arraybuffer" ) { return res; } if (code === 401) { if (!isReloginShow) { isReloginShow = !isReloginShow; MessageBox.confirm( "登录状态已过期,您可以继续留在该页面,或者重新登录", "系统提示", { confirmButtonText: "重新登录", cancelButtonText: "取消", type: "warning", } ) .then(() => { isReloginShow = !isReloginShow; vuex.dispatch("LogOut").then(() => { location.href = "/login"; }); }) .catch(() => { isReloginShow = !isReloginShow; }); } return Promise.reject("无效的会话,或者会话已过期,请重新登录。"); } else if (code === 500) { Message({ message: msg, type: "error", }); return Promise.reject(new Error(msg)); } else if (code === 601) { Message({ message: msg, type: "warning", }); return Promise.reject("error"); } else if (code !== 200) { Notification.error({ title: msg, }); return Promise.reject("error"); } 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) + "异常"; } Message({ message: message, type: "error", duration: 5 * 1000, }); return Promise.reject(error); } ); /** * 基准地价报告 * @param {*} data * @returns */ export async function getJZDJWord(data) { let response = await request({ url: "/model/exportWord/exportWord4", method: "post", responseType: "blob", data: data, }); debugger; var fileName = "分析报告"; debugger; const contentDisposition = response.headers["content-disposition"]; if (contentDisposition) { fileName = window.decodeURI( response.headers["content-disposition"].split("=")[1], "UTF-8" ); } const isBlob = blobValidate(response.data); debugger; if (isBlob) { const blob = new Blob([response.data]); saveAs(blob, fileName); } else { const resText = await response.text(); const rspObj = JSON.parse(resText); const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"]; Message.error(errMsg); } return; } /** * 征收补偿报告 * @param {*} data * @returns */ export async function getZDBCWord(data) { let response = await request({ url: "/model/exportWord/exportWord3", method: "post", responseType: "blob", data: data, }); debugger; var fileName = data.projectName; debugger; const contentDisposition = response.headers["content-disposition"]; if (contentDisposition) { fileName = window.decodeURI( response.headers["content-disposition"].split("=")[1], "UTF-8" ); } const isBlob = blobValidate(response.data); debugger; if (isBlob) { const blob = new Blob([response.data]); saveAs(blob, fileName); } else { const resText = await response.text(); const rspObj = JSON.parse(resText); const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"]; Message.error(errMsg); } return; } /*************************报建项目******************** start */ // 查询项目信息列表 export async function listProjectinformation(query) { return await request({ url: "/model/projectinformation/list", method: "get", params: query, }); } // 查询项目信息详细 export async function getProjectinformation(id) { return await request({ url: "/model/projectinformation/" + id, method: "get", }); } // 新增项目信息 export async function addProjectinformation(data) { return await request({ url: "/model/projectinformation", method: "post", data: data, }); } // 修改项目信息 export async function updateProjectinformation(data) { return await request({ url: "/model/projectinformation", method: "put", data: data, }); } // 删除项目信息 export async function delProjectinformation(id) { return await request({ url: "/model/projectinformation/" + id, method: "delete", }); } // 查询报建模型列表 export async function listConstructionmodel(query) { return await request({ url: "/model/constructionmodel/list", method: "get", params: query, }); } // 查询报建模型详细 export async function getConstructionmodel(id) { return await request({ url: "/model/constructionmodel/" + id, method: "get", }); } // 新增报建模型 export async function addConstructionmodel(data) { return await request({ url: "/model/constructionmodel", method: "post", data: data, }); } // 修改报建模型 export async function updateConstructionmodel(data) { return await request({ url: "/model/constructionmodel", method: "put", data: data, }); } // 删除报建模型 export async function delConstructionmodel(id) { return await request({ url: "/model/constructionmodel/" + id, method: "delete", }); } // 查询项目模型指标人工核算值详细 export async function getZtProjectModelZb(id) { return await request({ url: "/model/ZtProjectModelZb/" + id, method: "get", }); } // 新增项目模型指标人工核算值 export async function addZtProjectModelZb(data) { return await request({ url: "/model/ZtProjectModelZb", method: "post", data: data, }); } // 修改项目模型指标人工核算值 export async function updateZtProjectModelZb(data) { return await request({ url: "/model/ZtProjectModelZb", method: "put", data: data, }); } /*************************报建项目******************** end */ /*************************基准地价******************** start */ // 基准地价分析 export async function getAnalyseResult(data) { return request({ url: "/model/jzdjanalyse/getAnalyseResult", method: "post", data: data, }); } // 查询基准地价信息列表 export async function listBenchmarkLandPrices(query) { return request({ url: "/model/BenchmarkLandPrices/list", method: "get", params: query, }); } // 查询基准地价信息详细 export async function getBenchmarkLandPrices(id) { return request({ url: "/model/BenchmarkLandPrices/" + id, method: "get", }); } // 新增基准地价信息 export async function addBenchmarkLandPrices(data) { return request({ url: "/model/BenchmarkLandPrices", method: "post", data: data, }); } // 修改基准地价信息 export async function updateBenchmarkLandPrices(data) { return request({ url: "/model/BenchmarkLandPrices", method: "put", data: data, }); } // 删除基准地价信息 export async function delBenchmarkLandPrices(id) { return request({ url: "/model/BenchmarkLandPrices/" + id, method: "delete", }); } // 查询基准地价分析结果列表 export function listZtBenchmarkLandPriceResults(query) { return request({ url: "/model/ZtBenchmarkLandPriceResults/list", method: "get", params: query, }); } // 查询基准地价分析结果详细 export function getZtBenchmarkLandPriceResults(id) { return request({ url: "/model/ZtBenchmarkLandPriceResults/" + id, method: "get", }); } // 新增基准地价分析结果 export function addZtBenchmarkLandPriceResults(data) { return request({ url: "/model/ZtBenchmarkLandPriceResults", method: "post", data: data, }); } // 修改基准地价分析结果 export function updateZtBenchmarkLandPriceResults(data) { return request({ url: "/model/ZtBenchmarkLandPriceResults", method: "put", data: data, }); } // 删除基准地价分析结果 export function delZtBenchmarkLandPriceResults(id) { return request({ url: "/model/ZtBenchmarkLandPriceResults/" + id, method: "delete", }); } /*************************基准地价******************** end */ /*************************征收补偿******************** start */ // 01 征地补偿标准列表 list export function getZdBcbzList(query) { return request({ url: "/model/zdbcbz/list", method: "get", params: query, }); } // 征地 补偿标准 getbyid export function getZdBcbzById(id) { return request({ url: "/model/zdbcbz/getInfo/" + id, method: "get", }); } //添加 征地 补偿标准 add export function addZdBcbz(data) { return request({ url: "/model/zdbcbz/", method: "post", data: data, }); } // 更新 征地 补偿标准 update export function updateZdBcbz(data) { return request({ url: "/model/zdbcbz/", method: "put", data: data, }); } // 删除 征地 补偿标准 delbyid export function delZdBcbz(id) { return request({ url: "/model/zdbcbz/" + id, method: "delete", }); } // 02 青苗 补偿标准列表 list export function getQmbcbzList(query) { return request({ url: "/model/qmbcbz/list", method: "get", params: query, }); } // 青苗 补偿标准 getbyid export function getQmbcbzById(id) { return request({ url: "/model/qmbcbz/" + id, method: "get", }); } //添加 青苗 补偿标准 add export function addQmbcbz(data) { return request({ url: "/model/qmbcbz", method: "post", data: data, }); } // 更新 青苗 补偿标准 update export function updateQmbcbz(data) { return request({ url: "/model/qmbcbz", method: "put", data: data, }); } // 删除 青苗 补偿标准 delbyid export function delQmbcbz(id) { return request({ url: "/model/qmbcbz/" + id, method: "delete", }); } // 03 拆迁 补偿标准列表 list export function getCqBcbzList(query) { return request({ url: "/model/cqbczd/list", method: "get", params: query, }); } // 拆迁 补偿标准 getbyid export function getCqBcbzById(id) { return request({ url: "/model/cqbcbz/" + id, method: "get", }); } //添加 拆迁 补偿标准 add export function addCqBcbz(data) { return request({ url: "/model/cqbcbz", method: "post", data: data, }); } // 更新 拆迁 补偿标准 update export function updateCqBcbz(data) { return request({ url: "/model/cqbcbz", method: "post", data: data, }); } // 删除 拆迁 补偿标准 delbyid export function delCqBcbz(id) { return request({ url: "/model/cqbcbz/" + id, method: "delete", }); } // 03-1 拆迁 补偿标准项 list export function getCqBcbzItemList(query) { return request({ url: "/model/cqbcbzitem/list", method: "get", params: query, }); } // 拆迁 补偿标准项 getbyid export function getCqBcbzItemById(id) { return request({ url: "/model/cqbcbzitem/" + id, method: "get", }); } //添加 拆迁 补偿标准项 add export function addCqBcbzItem(data) { return request({ url: "/model/cqbcbzitem", method: "post", data: data, }); } // 更新 拆迁 补偿标准项 update export function updateCqBcbzItem(data) { return request({ url: "/model/cqbcbzitem", method: "put", data: data, }); } // 删除 拆迁 补偿标准项 delbyid export function delCqBcbzItem(id) { return request({ url: "/model/cqbcbzitem/" + id, method: "delete", }); } // 04 拆迁 分析结果 列表 list export function getCqResultList(query) { return request({ url: "/model/cqresult/list", method: "get", params: query, }); } // 拆迁 分析结果 getbyid export function getCqResultById(id) { return request({ url: "/model/cqresult/" + id, method: "get", }); } //添加 拆迁 分析结果 add export function addCqResult(data) { return request({ url: "/model/cqresult", method: "post", data: data, }); } // 更新 拆迁 分析结果 update export function updateCqResult(data) { return request({ url: "/model/cqresult", method: "post", data: data, }); } // 删除 拆迁 分析结果 delbyid export function delCqResult(id) { return request({ url: "/model/cqresult/" + id, method: "delete", }); } // 05 征地 分析结果 列表 list export function getZdResultList(query) { return request({ url: "/model/zdresult/list", method: "get", params: query, }); } // 征地 分析结果 getbyid export function getZdResultById(id) { return request({ url: "/model/zdresult/" + id, method: "get", }); } //添加 征地 分析结果 add export function addZdResult(data) { return request({ url: "/model/zdresult", method: "post", data: data, }); } // 更新 征地 分析结果 update export function updateZdResult(data) { return request({ url: "/model/zdresult", method: "post", data: data, }); } // 删除 征地 分析结果 delbyid export function delZdResult(id) { return request({ url: "/model/zdresult/" + id, method: "delete", }); } // 06 青苗 分析结果 列表 list export function getQmResultList(query) { return request({ url: "/model/qmresult/list", method: "get", params: query, }); } // 青苗 分析结果 getbyid export function getQmResultById(id) { return request({ url: "/model/qmresult/" + id, method: "get", }); } //添加 青苗 分析结果 add export function addQmResult(data) { return request({ url: "/model/qmresult", method: "post", data: data, }); } // 更新 青苗 分析结果 update export function updateQmResult(data) { return request({ url: "/model/qmresult", method: "post", data: data, }); } // 删除 青苗 分析结果 delbyid export function delQmResult(id) { return request({ url: "/model/qmresult/" + id, method: "delete", }); } // 07 征收补偿项目 列表 list export function getZdProjectList(query) { return request({ url: "/model/zdproject/list", method: "get", params: query, }); } // 征收补偿项目 getbyid export function getZdProjectById(id) { return request({ url: "/model/zdproject/" + id, method: "get", }); } //添加 征收补偿项目 add export function addZdProject(data) { return request({ url: "/model/zdproject", method: "post", data: data, }); } // 更新 征收补偿项目 update export function updateZdProject(data) { return request({ url: "/model/zdproject", method: "post", data: data, }); } // 删除 征收补偿项目 delbyid export function delZdProject(id) { return request({ url: "/model/zdproject/" + id, method: "delete", }); } export async function expotZDBCWord(data) { let response = await request({ url: "/model/zdproject/exportWord", method: "post", responseType: "blob", data: data, }); debugger; var fileName = "分析报告"; if (data.projectName) fileName = data.projectName; debugger; const contentDisposition = response.headers["content-disposition"]; if (contentDisposition) { fileName = window.decodeURI( response.headers["content-disposition"].split("=")[1], "UTF-8" ); } const isBlob = blobValidate(response.data); debugger; if (isBlob) { const blob = new Blob([response.data]); saveAs(blob, fileName); } else { const resText = await response.text(); const rspObj = JSON.parse(resText); const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode["default"]; Message.error(errMsg); } return; } // 08 权属 分析结果 列表 list export function getQsResultList(query) { return request({ url: "/model/qsresult/list", method: "get", params: query, }); } // 权属 分析结果 getbyid export function getQsResultById(id) { return request({ url: "/model/qsresult/" + id, method: "get", }); } //添加 权属 分析结果 add export function addQsResult(data) { return request({ url: "/model/qsresult", method: "post", data: data, }); } // 更新 权属 分析结果 update export function updateQsResult(data) { return request({ url: "/model/qsresult", method: "post", data: data, }); } // 删除 权属 分析结果 delbyid export function delQsResult(id) { return request({ url: "/model/qsresult/" + id, method: "delete", }); } /*************************征收补偿******************** end */ /*************************夜景灯光******************** start */ // 查询夜景灯光列列表 export function listZtLightList(query) { return request({ url: "/model/ZtLightList/list", method: "get", params: query, }); } // 查询夜景灯光列详细 export function getZtLightList(id) { return request({ url: "/model/ZtLightList/" + id, method: "get", }); } // 新增夜景灯光列 export function addZtLightList(data) { return request({ url: "/model/ZtLightList", method: "post", data: data, }); } // 修改夜景灯光列 export function updateZtLightList(data) { return request({ url: "/model/ZtLightList", method: "put", data: data, }); } // 删除夜景灯光列 export function delZtLightList(id) { return request({ url: "/model/ZtLightList/" + id, method: "delete", }); } /*************************夜景灯光******************** end */ /*************************广告信息******************** start */ // 查询广告项目信息列表 export function listZtBillboardInfoList(query) { return request({ url: "/model/ZtBillboardInfoList/list", method: "get", params: query, }); } // 查询广告项目信息详细 export function getZtBillboardInfoList(id) { return request({ url: "/model/ZtBillboardInfoList/" + id, method: "get", }); } // 新增广告项目信息 export function addZtBillboardInfoList(data) { return request({ url: "/model/ZtBillboardInfoList", method: "post", data: data, }); } // 修改广告项目信息 export function updateZtBillboardInfoList(data) { return request({ url: "/model/ZtBillboardInfoList", method: "put", data: data, }); } // 删除广告项目信息 export function delZtBillboardInfoList(id) { return request({ url: "/model/ZtBillboardInfoList/" + id, method: "delete", }); } // 查询广告模型信息列表 export function listBillboardModelList(query) { return request({ url: "/model/billboardModelList/list", method: "get", params: query, }); } // 查询广告模型信息详细 export function getBillboardModelList(id) { return request({ url: "/model/billboardModelList/" + id, method: "get", }); } // 新增广告模型信息 export function addBillboardModelList(data) { return request({ url: "/model/billboardModelList", method: "post", data: data, }); } // 修改广告模型信息 export function updateBillboardModelList(data) { return request({ url: "/model/billboardModelList", method: "put", data: data, }); } // 删除广告模型信息 export function delBillboardModelList(id) { return request({ url: "/model/billboardModelList/" + id, method: "delete", }); } /*************************广告信息******************** end */