From d2fb3c12ee226b812e2e82c3d2390efff4ce9272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=AE=8F=E6=9D=B0?= <1943105267@qq.com> Date: Wed, 30 Aug 2023 15:23:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/wlSafe/index.js | 72 +++++++++---------- src/utils/request.js | 50 +++++++------ src/utils/ruoyi.js | 29 ++++++++ .../components/ReportingStatistics.vue | 1 - 4 files changed, 94 insertions(+), 58 deletions(-) create mode 100644 src/utils/ruoyi.js diff --git a/src/api/wlSafe/index.js b/src/api/wlSafe/index.js index 19d8384..7bf4210 100644 --- a/src/api/wlSafe/index.js +++ b/src/api/wlSafe/index.js @@ -1,59 +1,59 @@ -import request from '@/utils/request.js' +import request from "@/utils/request.js"; //数据来源 export function dataLY() { - return request({ - url: '/zongzhi/saftyscreen/source', - method: 'get', - }) + return request({ + url: "/zongzhi/saftyscreen/source", + method: "get", + }); } //地球受攻击 export function mapAttack(data) { - return request({ - url: '/zongzhi/attack/list', - method: 'get', - params: data - }) + return request({ + url: "/zongzhi/attack/list", + method: "get", + params: data, + }); } //安全隐患 export function safeRisks() { - return request({ - url: '/zongzhi/saftyscreen/safetyhazard', - method: 'get', - }) + return request({ + url: "/zongzhi/saftyscreen/safetyhazard", + method: "get", + }); } //部门专办情况 export function sectorZB() { - return request({ - url: '/zongzhi/opinionscreen/sentimentdept', - method: 'get', - }) + return request({ + url: "/zongzhi/opinionscreen/sentimentdept", + method: "get", + }); } //通报统计属地通报 export function territorialTB() { - return request({ - url: '/zongzhi/saftyscreen/tbarea', - method: 'get', - }) + return request({ + url: "/zongzhi/saftyscreen/tbarea", + method: "get", + }); } //通报统计部门通报 export function departmentTB() { - return request({ - url: '/zongzhi/saftyscreen/tbdept', - method: 'get', - }) + return request({ + url: "/zongzhi/saftyscreen/tbdept", + method: "get", + }); } //通报完成情况 export function tbFinish() { - return request({ - url: '/zongzhi/saftyscreen/tbcomplete', - method: 'get', - }) + return request({ + url: "/zongzhi/saftyscreen/tbcomplete", + method: "get", + }); } //获取部门通报列表 export function departmentList(data) { - return request({ - url: '/zongzhi/tb/list', - method: 'get', - params:data - }) -} \ No newline at end of file + return request({ + url: "/zongzhi/tb/list", + method: "get", + params: data, + }); +} diff --git a/src/utils/request.js b/src/utils/request.js index 1ad8b52..845a353 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -5,17 +5,18 @@ * @LastEditTime: 2022-03-04 11:30:33 * @Description: */ -import axios from 'axios' -import { Message } from 'element-ui' +import axios from "axios"; +import { Message } from "element-ui"; +import { tansParams } from "@/utils/ruoyi"; // MessageBox, -import store from '@/store' -import { getToken } from '@/utils/auth' +import store from "@/store"; +import { getToken } from "@/utils/auth"; // create an axios instance const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API2, // url = base url + request url // withCredentials: true, // send cookies when cross-domain requests - timeout: 120 * 1000 // request timeout -}) + timeout: 120 * 1000, // request timeout +}); // request interceptor service.interceptors.request.use( @@ -25,17 +26,24 @@ service.interceptors.request.use( // let each request carry token // ['X-Token'] is a custom headers key // please modify it according to the actual situation - config.headers['Authorization'] = getToken() + config.headers["Authorization"] = getToken(); } - config.headers['domain'] = encodeURI(sessionStorage.getItem('domain')) - return config + config.headers["domain"] = encodeURI(sessionStorage.getItem("domain")); + // 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; + } + return config; }, (error) => { // do something with request error - console.log(error) // for debug - return Promise.reject(error) + console.log(error); // for debug + return Promise.reject(error); } -) +); // response interceptor service.interceptors.response.use( @@ -50,18 +58,18 @@ service.interceptors.response.use( * You can also judge the status by HTTP Status Code */ (response) => { - const res = response.data - return res + const res = response.data; + return res; }, (error) => { - console.log('err' + error) // for debug + console.log("err" + error); // for debug Message({ message: error.message, - type: 'error', - duration: 5 * 1000 - }) - return Promise.reject(error) + type: "error", + duration: 5 * 1000, + }); + return Promise.reject(error); } -) +); -export default service +export default service; diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js new file mode 100644 index 0000000..633546e --- /dev/null +++ b/src/utils/ruoyi.js @@ -0,0 +1,29 @@ +/** + * 参数处理 + * @param {*} params 参数 + */ +export function tansParams(params) { + let result = ""; + for (const propName of Object.keys(params)) { + const value = params[propName]; + var part = encodeURIComponent(propName) + "="; + if (value !== null && value !== "" && typeof value !== "undefined") { + if (typeof value === "object") { + for (const key of Object.keys(value)) { + if ( + value[key] !== null && + value[key] !== "" && + typeof value[key] !== "undefined" + ) { + let params = propName + "[" + key + "]"; + var subPart = encodeURIComponent(params) + "="; + result += subPart + encodeURIComponent(value[key]) + "&"; + } + } + } else { + result += part + encodeURIComponent(value) + "&"; + } + } + } + return result; +} diff --git a/src/views/privateOrder/security/components/ReportingStatistics.vue b/src/views/privateOrder/security/components/ReportingStatistics.vue index 758f417..74f583e 100644 --- a/src/views/privateOrder/security/components/ReportingStatistics.vue +++ b/src/views/privateOrder/security/components/ReportingStatistics.vue @@ -251,7 +251,6 @@ export default { echartsJump(myChartPieFirst, optionFirst); }, clickFunc(val) { - console.log(val); this.queryData.areaId = val.area; console.log(this.queryData); //点击之后弹出框显示列表