diff --git a/src/api/high-formwork/index.js b/src/api/high-formwork/index.js new file mode 100644 index 00000000..bdf21b66 --- /dev/null +++ b/src/api/high-formwork/index.js @@ -0,0 +1,22 @@ +import request from '@/utils/request' + +/* 高支模分组管理接口 */ + +// 列表接口 +export const getHighFormworkListAPI = (data) => { + return request.get('/smart-site/devModel/getPageList', { + params: data, + }) +} +// 新增接口 +export const addHighFormworkDataAPI = (data) => { + return request.post('/smart-site/devModel/insertData', data) +} +// 修改接口 +export const editHighFormworkDataAPI = (data) => { + return request.post('/smart-site/devModel/updateData', data) +} +// 删除接口 +export const deleteHighFormworkDataAPI = (data) => { + return request.post('/smart-site/devModel/deleteData', data) +} diff --git a/src/components/TableModel/index.vue b/src/components/TableModel/index.vue index fd52bfd4..b6977fe1 100644 --- a/src/components/TableModel/index.vue +++ b/src/components/TableModel/index.vue @@ -81,12 +81,9 @@ > - 查询 - 填充 + + 查询 + 重置 @@ -324,25 +321,10 @@ export default { } else { this.$set(this.queryParams, e.f_model, '') } - // 设置表单必填 - if (e.f_rule) { - this.$set(this.formRules, e.f_rule, [ - { - required: true, - message: `请填写${e.f_label}`, - trigger: 'blur', - }, - ]) - } }) - if (this.sendParams !== null) { - Object.assign(this.queryParams, this.sendParams) - /* for(let key in this.sendParams) { - console.log(key, this.sendParams[key]) - this.$set(this.queryParams, key, this.sendParams[key]) - } */ - } - if (this.sendId !== null) this.queryParams.id = this.sendId + // if (this.sendParams !== null) { + // Object.assign(this.queryParams, this.sendParams) + // } this.getTableList() }, updated() { @@ -355,53 +337,26 @@ export default { if (this.queryParams.time && this.queryParams.time.length !== 0) { this.queryParams.startTime = this.queryParams.time[0] this.queryParams.endTime = this.queryParams.time[1] - // delete this.queryParams.time; } - console.log(this.queryParams) - if (Object.keys(this.formRules).length !== 0) { - this.$refs.queryFormRef.validate(async (valid) => { - if (valid) { - this.loading = true - const res = await this.requestApi(this.queryParams) - this.loading = false - console.log(res, '列表数据') - if (res.code === 200) { - if (res.data) { - this.tableList = res.data.rows || res.data - this.total = res.data.total || res.data.length - } else { - this.tableList = res.rows || res.data - this.total = res.data.total || res.rows.length - } - } - } - }) - } else { - this.loading = true - const res = await this.requestApi(this.queryParams) - this.loading = false - console.log(res, '列表数据2') - if (res.code === 200) { - if (res.data) { - this.tableList = res.data.rows || res.data - this.total = res.data.total || res.data.length - } else { - this.tableList = res.rows || res.data - this.total = res.total || res.rows.length - } - } + console.log( + `%c🔍 列表查询入参 %c`, + 'background: linear-gradient(90deg, #FF6B6B, #4ECDC4); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold;', + '', + this.queryParams, + ) + this.loading = true + const res = await this.requestApi(this.queryParams) + if (res.code === 200) { + this.tableList = res.rows + this.total = res.total } + this.loading = false }, /** 查询按钮 */ handleQuery() { this.getTableList() }, - /** 填充按钮 */ - handleFill() { - /* this.tableList.forEach(obj => { - Object.assign(obj, this.formLabel) - }) */ - }, + /** 重置按钮 */ resetQuery() { this.$refs.queryFormRef.resetFields() diff --git a/src/utils/request-new.js b/src/utils/request-new.js new file mode 100644 index 00000000..fbba7796 --- /dev/null +++ b/src/utils/request-new.js @@ -0,0 +1,274 @@ +import axios from 'axios' +import { Notification, MessageBox, Message, Loading } from 'element-ui' +import store from '@/store' +import { getToken } from '@/utils/auth' +import errorCode from '@/utils/errorCode' +import { tansParams, blobValidate } from '@/utils/bonus' +import cache from '@/plugins/cache' +import { saveAs } from 'file-saver' +import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' +const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || { + requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false }, +} + +let downloadLoadingInstance +// 是否显示重新登录 +export let isRelogin = { show: false } + +axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' + +// 创建axios实例 +const service = axios.create({ + // axios中请求配置有baseURL选项,表示请求URL公共部分 + baseURL: process.env.VUE_APP_BASE_API, + // 超时 + timeout: 10000, +}) + +// request 拦截器 +service.interceptors.request.use( + (config) => { + // 提取 headers 和方法 + const headers = config.headers || {} + const { + isToken = true, + encryptRequest = true, + checkIntegrity = true, + encryptResponse = true, + repeatSubmit = false, + } = headers + + // 设置请求头 + //入参加密 + config.headers['encryptRequest'] = + systemConfig.requestConfig.encryptRequest && encryptRequest ? 'true' : 'false' + // 数据完整性校验 + config.headers['checkIntegrity'] = + systemConfig.requestConfig.checkIntegrity && checkIntegrity ? 'true' : 'false' + //回参是否加密 + config.headers['encryptResponse'] = + systemConfig.requestConfig.encryptResponse && encryptResponse ? 'true' : 'false' + + const isRepeatSubmit = repeatSubmit + // 处理 Token + if (getToken() && isToken) { + config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义 token + } + + // 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')) { + // 修改为 FormData 格式 + if (config.headers['Content-Type'] === 'application/json') { + config.headers['Content-Type'] = 'multipart/form-data' + + // const formData = new FormData() + + // // 1. 处理普通表单数据 + // if (typeof config.data === 'object') { + // // 检查是否是包含文件的特殊格式(约定格式:{ formData: {...}, files: [...] }) + // if (config.data.file) { + // // 处理文件附件 + // // config.data.files.forEach((file, index) => { + // // formData.append('file' + (index > 0 ? index + 1 : ''), file) + // // }) + + // formData.append('file', config.data.file) + + // // 处理其他表单数据 + // if (config.data.params) { + // Object.keys(config.data.params).forEach((key) => { + // formData.append(key, config.data.formData[key]) + // }) + // } + // } else { + // // 普通对象数据直接转换 + // Object.keys(config.data).forEach((key) => { + // // 跳过 files 字段(如果存在但不是数组) + // if (key !== 'files' || Array.isArray(config.data[key])) { + // formData.append(key, config.data[key]) + // } + // }) + // } + // } else { + // formData.append('data', config.data) + // } + + config.data = data + } + + // 其他逻辑保持不变(如加密、防重复提交等) + if (systemConfig.requestConfig.encryptRequest && encryptRequest) { + console.log(config.data) + console.log(hashWithSM3AndSalt(config.data)) + // 注意:FormData 对象不能直接加密,需要特殊处理 + // 这里假设你仍然需要对数据进行加密 + const encryptedData = encryptWithSM4( + JSON.stringify(config.data) + '|' + hashWithSM3AndSalt(JSON.stringify(config.data)), + ) + config.data = { encryptedData } // 将加密后的数据作为 FormData 的一个字段 + } + + // 防止重复提交的逻辑保持不变 + const sessionObj = cache.session.getJSON('sessionObj') || {} + const requestObj = { url: config.url, data: config.data, time: Date.now() } + + if ( + sessionObj.data === requestObj.data && + requestObj.time - sessionObj.time < 0 && + sessionObj.url === requestObj.url + ) { + console.warn(`[${sessionObj.url}]: 数据正在处理,请勿重复提交`) + return Promise.reject(new Error('数据正在处理,请勿重复提交')) + } + cache.session.setJSON('sessionObj', requestObj) + } + return config + }, + (error) => { + console.error(error) + return Promise.reject(error) + }, +) + +// 响应拦截器 +service.interceptors.response.use( + (res) => { + if (res.headers.encryptresponse && !res.data.hasOwnProperty('code')) { + res.data = JSON.parse(decryptWithSM4(res.data)) + } + // 未设置状态码则默认成功状态 + 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.data + } + if (code === 401) { + if (!isRelogin.show) { + isRelogin.show = true + MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { + confirmButtonText: '重新登录', + cancelButtonText: '取消', + type: 'warning', + }) + .then(() => { + isRelogin.show = false + store.dispatch('LogOut').then(() => { + location.href = '/index' + }) + }) + .catch(() => { + isRelogin.show = false + }) + } + 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) => { + 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) + }, +) + +// 通用下载方法 +export function download(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ + text: '正在下载数据,请稍候', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)', + }) + return service + .post(url, params, { + transformRequest: [ + (params) => { + return tansParams(params) + }, + ], + headers: { 'Content-Type': 'application/x-www-form-urlencoded', encryptResponse: false }, + responseType: 'blob', + ...config, + }) + .then(async (data) => { + const isBlob = blobValidate(data) + if (isBlob) { + const blob = new Blob([data]) + saveAs(blob, filename) + } else { + const resText = await data.text() + const rspObj = JSON.parse(resText) + const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] + Message.error(errMsg) + } + downloadLoadingInstance.close() + }) + .catch((r) => { + console.error(r) + Message.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close() + }) +} + +// 通用导出方法 +export function derive(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ + text: '正在下载数据,请稍候', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)', + }) + return service + .post(url, JSON.stringify(params), { + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + encryption: 'encryption', + }, + responseType: 'blob', + ...config, + }) + .then(async (data) => { + const isBlob = blobValidate(data) + if (isBlob) { + const blob = new Blob([data]) + saveAs(blob, filename) + } else { + const resText = await data.text() + const rspObj = JSON.parse(resText) + const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] + Message.error(errMsg) + } + downloadLoadingInstance.close() + }) + .catch((r) => { + console.error(r) + Message.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close() + }) +} + +export default service diff --git a/src/views/high-formwork/components/add-edit-form.vue b/src/views/high-formwork/components/add-edit-form.vue index 7a5f14ac..c1d56be9 100644 --- a/src/views/high-formwork/components/add-edit-form.vue +++ b/src/views/high-formwork/components/add-edit-form.vue @@ -1,30 +1,30 @@ diff --git a/src/views/high-formwork/config.js b/src/views/high-formwork/config.js index 058523a4..08544faf 100644 --- a/src/views/high-formwork/config.js +++ b/src/views/high-formwork/config.js @@ -1,10 +1,10 @@ -export const formLabel = [{ f_label: '搜索关键词', f_model: 'proName', f_type: 'ipt', isShow: false }] +export const formLabel = [{ f_label: '搜索关键词', f_model: 'keyWord', f_type: 'ipt', isShow: false }] export const columnsList = [ - { t_props: 'projectName', t_label: '分组名称' }, - { t_props: 'address', t_label: '支护状态' }, - { t_props: 'planStartTime', t_label: '支护安全等级' }, - { t_props: 'planEndTime', t_label: '施工开始时间' }, - { t_props: 'ownerUnit', t_label: '描述' }, + { t_props: 'modelName', t_label: '分组名称' }, + { t_props: 'modelState', t_label: '支护状态', t_slot: 'status' }, + { t_props: 'modeLevel', t_label: '支护安全等级', t_slot: 'level' }, + { t_props: 'startTime', t_label: '施工开始时间' }, + { t_props: 'remark', t_label: '描述' }, ] export const dialogConfig = { diff --git a/src/views/high-formwork/index.vue b/src/views/high-formwork/index.vue index b0d3d6ab..ee8e17a3 100644 --- a/src/views/high-formwork/index.vue +++ b/src/views/high-formwork/index.vue @@ -1,7 +1,12 @@