diff --git a/src/api/dataAnalysis/projectSafety.js b/src/api/dataAnalysis/projectSafety.js index f4d96f2..6e5b84c 100644 --- a/src/api/dataAnalysis/projectSafety.js +++ b/src/api/dataAnalysis/projectSafety.js @@ -1,36 +1,73 @@ import request from '@/utils/request' +import requestFormData from '@/utils/request_formdata' -// 获取工程安全列表 -export function getProjectSafetyListAPI(data) { +// 获取工程安全分析一本账列表 +export function getProjectSafetyAnalysisListAPI(data) { return request({ - url: '/background/***', + url: '/background/sj/safety/list', method: 'get', params: data, }) } -// 新增工程安全 -export function addProjectSafetyAPI(data) { +// 新增工程安全分析一本账列表 +export function addProjectSafetyAnalysisAPI(data) { return request({ - url: '/background/***', + url: '/background/sj/safety/addData', method: 'post', data, }) } -// 编辑工程安全 -export function editProjectSafetyAPI(data) { +// 编辑工工程安全分析一本账列表 +export function editProjectSafetyAnalysisAPI(data) { return request({ - url: '/background/***', + url: '/background/sj/safety/updateData', method: 'post', data, }) } -// 删除工程安全 -export function deleteProjectSafetyAPI(data) { +// 删除工工程安全分析一本账列表 +export function deleteProjectSafetyAnalysisAPI(data) { return request({ - url: '/background/***', + url: '/background/sj/safety/delete', + method: 'post', + data, + }) +} + +// 获取视频风险分析列表 +export function getVideoSafetyAnalysisListAPI(data) { + return request({ + url: '/background/sj/safety/getVideoList', + method: 'get', + params: data, + }) +} + +// 新增视频风险分析列表 +export function addVideoSafetyAnalysisAPI(data) { + return requestFormData({ + url: '/background/sj/safety/addVideoFile', + method: 'post', + data, + }) +} + +// 编辑工视频风险分析列表 +export function editVideoSafetyAnalysisAPI(data) { + return requestFormData({ + url: '/background/sj/safety/updateVideoFile', + method: 'post', + data, + }) +} + +// 删除工视频风险分析列表 +export function deleteVideoSafetyAnalysisAPI(data) { + return request({ + url: '/background/sj/safety/deleteVideo', method: 'post', data, }) diff --git a/src/components/UploadImgFormData/index.vue b/src/components/UploadImgFormData/index.vue new file mode 100644 index 0000000..1f530cf --- /dev/null +++ b/src/components/UploadImgFormData/index.vue @@ -0,0 +1,268 @@ + + + + + diff --git a/src/utils/request_formdata.js b/src/utils/request_formdata.js new file mode 100644 index 0000000..4210d9a --- /dev/null +++ b/src/utils/request_formdata.js @@ -0,0 +1,267 @@ +import axios from 'axios' +import { MessageBox, Message } from 'element-ui' +import store from '@/store' +import { getIscId, getToken, removeToken, tansParams } from '@/utils/auth' +import router from '@/router' // @表示src目录 +import cache from '@/utils/cache' +import { encryptCBC, decryptCBC } from '@/utils/aescbc' +import { SM4Util } from '@/utils/sm4' +// create an axios instance +const service = axios.create({ + baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url + // withCredentials: true, // send cookies when cross-domain requests + timeout: 20000, // request timeout +}) + +// request interceptor +// service.interceptors.request.use( +// config => { +// // do something before request is sent +// if (!config?.custom && store.getters.token) { +// // let each request carry token +// // ['X-Token'] is a custom headers key +// // please modify it according to the actual situation +// config.headers['Authorization'] = getToken() +// } +// return config +// }, +// error => { +// // do something with request error +// console.log(error) // for debug +// return Promise.reject(error) +// } +// ) + +// request拦截器 +service.interceptors.request.use( + (config) => { + let iscUserId = getIscId() + console.log('iscUserId===' + iscUserId) + // 是否需要加密 + let aqEnnable = false + // 是否需要设置 token + const isToken = (config.headers || {}).isToken === false + // 是否需要防止数据重复提交 + const isRepeatSubmit = (config.headers || {}).repeatSubmit === false + if (getToken() && !isToken) { + config.headers['Authorization'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 + } + + //参数加密 + if (config.method === 'post' && config.data) { + if (config.headers['decrypt'] != 'decrypt') { + // if (aqEnnable) { + // config.data = encryptCBC(JSON.stringify(config.data)) + // } + + if (config.data instanceof FormData) { + // 对于FormData,我们创建一个对象来保存数据以便验证 + const formDataObj = new FormData() + config.data.forEach((value, key) => { + const isFile = value instanceof File + if (aqEnnable && !isFile) { + formDataObj.append(key, encryptCBC(value)) + } else { + formDataObj.append(key, value) + } + }) + config.data = formDataObj + // dataStr = JSON.stringify(formDataObj) + // 保持Content-Type为multipart/form-data(由浏览器自动设置) + delete config.headers['Content-Type'] + } else { + if (aqEnnable) { + config.data = encryptCBC(JSON.stringify(config.data)) + } + } + } + } + config.headers['Content-Type'] = 'application/json' + // get请求映射params参数 + if (config.method === 'get' && config.params) { + let url = '' + //加密 + if (aqEnnable) { + let urlStr = tansParams(config.params) + urlStr = urlStr.slice(0, -1) + console.log(urlStr) + url = config.url + '?params=' + encryptCBC(urlStr) + } + //未加密 + if (!aqEnnable) { + url = config.url + '?' + tansParams(config.params) + url = url.slice(0, -1) + } + config.params = {} + config.url = url + } + if ( + !isRepeatSubmit && + (config.method === 'post' || config.method === 'get') + ) { + const requestObj = { + url: config.url, + data: + typeof config.data === 'object' + ? JSON.stringify(config.data) + : config.data, + time: new Date().getTime(), + } + const requestSize = Object.keys(JSON.stringify(requestObj)).length // 请求数据大小 + const limitSize = 5 * 1024 * 1024 // 限制存放数据5M + if (requestSize >= limitSize) { + console.warn( + `[${config.url}]: ` + + '请求数据大小超出允许的5M限制,无法进行防重复提交验证。', + ) + return config + } + 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) + }, +) + +// response interceptor +service.interceptors.response.use( + /** + * If you want to get http information such as headers or status + * Please return response => response + */ + + /** + * Determine the request status by custom code + * Here is just an example + * You can also judge the status by HTTP Status Code + */ + (response) => { + let sm4 = new SM4Util() + if ( + typeof response.data.decrypt != 'undefined' && + response.data.decrypt + ) { + let resultData = sm4.decryptDefault_CBC(response.data.data) + resultData = removePadding(resultData) + + // replaceAll(/\/g, '').replaceAll(/\s+/g, ' ').replaceAll("","").replaceAll("","") + // .replaceAll("","") + // .replaceAll("", "").replaceAll("","").replaceAll("","").trim(); + // console.log(removePadding(resultData)) + try { + response.data = JSON.parse(resultData.trim()) + // 成功解析后的操作 + } catch (e) { + console.log(resultData.trim()) + console.error('解析JSON数据出错:', e) + // 解析失败后的操作,比如提示用户或进行错误处理 + } + } + if ( + response.request.responseType === 'blob' || + response.request.responseType === 'arraybuffer' + ) { + return response.data + } + if (typeof response.data.code == 'undefined') { + response.data = response.data.data + } + const res = response.data + console.log(res) + if (res.code === 401) { + removeToken() + MessageBox.confirm('登录已过期', '退出登录', { + confirmButtonText: '重新登录', + cancelButtonText: '取消', + type: 'warning', + }).then(() => { + let iscId = getIscId() + window.location.href = 'http://sgwpdm.ah.sgcc.com.cn/' + // router.push({ path: '/login' }) + }) + return + } + if (response.request?.responseType === 'blob') { + // 文件流 + return response.data + } else if (res.code !== 200) { + Message({ + message: res.msg || 'Error', + type: 'error', + duration: 5 * 1000, + }) + + if ( + res.code === 50008 || + res.code === 50012 || + res.code === 50014 + ) { + // to re-login + MessageBox.confirm( + 'You have been logged out, you can cancel to stay on this page, or log in again', + 'Confirm logout', + { + confirmButtonText: 'Re-Login', + cancelButtonText: 'Cancel', + type: 'warning', + }, + ).then(() => { + store.dispatch('user/resetToken').then(() => { + location.reload() + }) + }) + } + return Promise.reject(new Error(res.message || 'Error')) + } else { + return res + } + }, + (error) => { + console.log('err' + error) // for debug + Message({ + message: error.message, + type: 'error', + duration: 5 * 1000, + }) + return Promise.reject(error) + }, +) +function removePadding(decrypted) { + const lastByte = decrypted.charCodeAt(decrypted.length - 1) + if (lastByte <= 16) { + for (let i = decrypted.length - lastByte; i < decrypted.length; i++) { + if (decrypted.charCodeAt(i) !== lastByte) { + return decrypted // 如果填充不正确,返回原始字符串 + } + } + return decrypted.slice(0, -lastByte) + } + return decrypted +} +export default service diff --git a/src/views/dataAnalysis/projectQuality/components/addAndEditForm.vue b/src/views/dataAnalysis/projectQuality/components/addAndEditForm.vue index 93e4959..b393dd2 100644 --- a/src/views/dataAnalysis/projectQuality/components/addAndEditForm.vue +++ b/src/views/dataAnalysis/projectQuality/components/addAndEditForm.vue @@ -223,7 +223,6 @@ import { addProjectQualityAPI, editProjectQualityAPI, - getProjectQualityDetailsAPI, } from '@/api/dataAnalysis/projectQuality' export default { name: 'AddAndEditForm', @@ -472,26 +471,9 @@ export default { ).toFixed(2) } }, - - // 获取详情 - async getDetails() { - const res = await getProjectQualityDetailsAPI({ - id: this.detailsId, - }) - // this.addAndEditForm = res.data - }, }, watch: { - detailsId: { - handler(newVal) { - if (newVal) { - this.getDetails() - } - }, - immediate: true, - }, - editRow: { handler(newVal) { if (Object.keys(newVal).length > 0) { diff --git a/src/views/dataAnalysis/projectSafety/components/addAndEditForm.vue b/src/views/dataAnalysis/projectSafety/components/addAndEditForm.vue deleted file mode 100644 index 0370110..0000000 --- a/src/views/dataAnalysis/projectSafety/components/addAndEditForm.vue +++ /dev/null @@ -1,122 +0,0 @@ - - - - - diff --git a/src/views/dataAnalysis/projectSafety/components/addAndEditFormOne.vue b/src/views/dataAnalysis/projectSafety/components/addAndEditFormOne.vue new file mode 100644 index 0000000..f3b8fec --- /dev/null +++ b/src/views/dataAnalysis/projectSafety/components/addAndEditFormOne.vue @@ -0,0 +1,236 @@ + + + + + diff --git a/src/views/dataAnalysis/projectSafety/components/addAndEditFormTwo.vue b/src/views/dataAnalysis/projectSafety/components/addAndEditFormTwo.vue new file mode 100644 index 0000000..c2d85ab --- /dev/null +++ b/src/views/dataAnalysis/projectSafety/components/addAndEditFormTwo.vue @@ -0,0 +1,238 @@ + + + + + diff --git a/src/views/dataAnalysis/projectSafety/index.vue b/src/views/dataAnalysis/projectSafety/index.vue index 9c3fcc5..304a1f0 100644 --- a/src/views/dataAnalysis/projectSafety/index.vue +++ b/src/views/dataAnalysis/projectSafety/index.vue @@ -7,17 +7,26 @@