💥 feat(模块): 添加了个很棒的功能
This commit is contained in:
parent
c3d24d6c03
commit
f5b7cfb87a
@ -5,7 +5,7 @@ import { Button, Col, message, Modal, Popconfirm, Row, Space, Image, Drawer } fr
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { connect } from "umi";
|
import { connect } from "umi";
|
||||||
import { handleAddTemplates, handleBatchService, handleDeleteTemplates, handleGetQuestionList, handleGetTemplatesList, handleSearchModalTree, handleUpdateTemplates, handleUploadFile } from "./service";
|
import { handleAddTemplates, handleBatchService, handleDeleteTemplates, handleGetQuestionList, handleGetTemplatesList, handleSearchModalTree, handleUpdateTemplates, handleUploadFile, uploadAHYDPicture } from "./service";
|
||||||
import { handleGetExamineTypeTreeList } from "../index/service";
|
import { handleGetExamineTypeTreeList } from "../index/service";
|
||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import { base64ToFile } from "@/utils/publicMethods";
|
import { base64ToFile } from "@/utils/publicMethods";
|
||||||
@ -518,6 +518,27 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
}
|
}
|
||||||
console.log('reqadd', req);
|
console.log('reqadd', req);
|
||||||
data = await handleUpdateTemplates(req)
|
data = await handleUpdateTemplates(req)
|
||||||
|
console.log('data1231232131', data);
|
||||||
|
|
||||||
|
// const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.Result_Data.id}`);
|
||||||
|
// const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.Result_Data.id}.png`);
|
||||||
|
// console.log('file', file);
|
||||||
|
// const formData = new FormData();
|
||||||
|
// // formData.append("file", file, `wenjuan${data.Result_Data.id}.png`); // 确保文件名也传递
|
||||||
|
// formData.append("file[]", file); // 确保文件名也传递
|
||||||
|
// formData.append('ImageType', '1133');
|
||||||
|
// formData.append('ImageName', `wenjuan${data.Result_Data.id}.png`);
|
||||||
|
|
||||||
|
// // const fileData = await handleUploadFile(formData)
|
||||||
|
// const fileData = await uploadAHYDPicture(formData)
|
||||||
|
// console.log('fileData', fileData);
|
||||||
|
// let url = fileData.Result_Data.ImageUrl
|
||||||
|
|
||||||
|
// await handleUpdateTemplates({
|
||||||
|
// ...req,
|
||||||
|
// qrUrl: url
|
||||||
|
// })
|
||||||
|
// setQrCodeUrl(url || '')
|
||||||
} else {
|
} else {
|
||||||
let questions: any = []
|
let questions: any = []
|
||||||
if (res.questions && res.questions.length > 0) {
|
if (res.questions && res.questions.length > 0) {
|
||||||
@ -555,7 +576,28 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
}
|
}
|
||||||
console.log('reqreqreqreqreq', req);
|
console.log('reqreqreqreqreq', req);
|
||||||
data = await handleAddTemplates(req)
|
data = await handleAddTemplates(req)
|
||||||
// console.log('datadsadsa1', data);
|
console.log('datadsadsa1321312', data);
|
||||||
|
|
||||||
|
|
||||||
|
const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.Result_Data.id}`);
|
||||||
|
const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.Result_Data.id}.png`);
|
||||||
|
console.log('file', file);
|
||||||
|
const formData = new FormData();
|
||||||
|
// formData.append("file", file, `wenjuan${data.Result_Data.id}.png`); // 确保文件名也传递
|
||||||
|
formData.append("file[]", file); // 确保文件名也传递
|
||||||
|
formData.append('ImageType', '1133');
|
||||||
|
formData.append('ImageName', `wenjuan${data.Result_Data.id}.png`);
|
||||||
|
|
||||||
|
// const fileData = await handleUploadFile(formData)
|
||||||
|
const fileData = await uploadAHYDPicture(formData)
|
||||||
|
console.log('fileData', fileData);
|
||||||
|
let url = fileData.Result_Data.ImageUrl
|
||||||
|
|
||||||
|
await handleUpdateTemplates({
|
||||||
|
...data.Result_Data,
|
||||||
|
qrUrl: url
|
||||||
|
})
|
||||||
|
setQrCodeUrl(url || '')
|
||||||
|
|
||||||
// const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.Result_Data.id}`);
|
// const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.Result_Data.id}`);
|
||||||
// const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.Result_Data.id}.png`);
|
// const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.Result_Data.id}.png`);
|
||||||
@ -563,17 +605,18 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
// const formData = new FormData();
|
// const formData = new FormData();
|
||||||
// formData.append("file", file, `wenjuan${data.Result_Data.id}.png`); // 确保文件名也传递
|
// formData.append("file", file, `wenjuan${data.Result_Data.id}.png`); // 确保文件名也传递
|
||||||
|
|
||||||
// const fileData = await handleUploadFile(formData)
|
// // const fileData = await handleUploadFile(formData)
|
||||||
|
// const fileData = await uploadAHYDPicture(formData)
|
||||||
// console.log('fileData', fileData);
|
// console.log('fileData', fileData);
|
||||||
// let imgUrl: string = `https://es.eshangtech.com/${fileData.data.path}`
|
// // let imgUrl: string = `https://es.eshangtech.com/${fileData.data.path}`
|
||||||
// await handleUpdateTemplates({
|
// // await handleUpdateTemplates({
|
||||||
// ...data.Result_Data,
|
// // ...data.Result_Data,
|
||||||
// qrUrl: imgUrl
|
// // qrUrl: imgUrl
|
||||||
// })
|
// // })
|
||||||
|
|
||||||
setQrCodeUrl(data.Result_Data.qrUrl || '')
|
// setQrCodeUrl(data.Result_Data.qrUrl || '')
|
||||||
|
|
||||||
// setQrCodeUrl(myQRCodeDataUrl)
|
// // setQrCodeUrl(myQRCodeDataUrl)
|
||||||
}
|
}
|
||||||
console.log('datadsadsa', data);
|
console.log('datadsadsa', data);
|
||||||
setModalLoading(true)
|
setModalLoading(true)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import requestOld from "@/utils/requestOld"
|
|||||||
// import request from "@/utils/request"
|
// import request from "@/utils/request"
|
||||||
import requestNode from "@/utils/request"
|
import requestNode from "@/utils/request"
|
||||||
import request from "@/utils/requestJava"
|
import request from "@/utils/requestJava"
|
||||||
|
import requestUpload from '@/utils/requestUpload'
|
||||||
|
|
||||||
// 拿到模版id列表 去绑定服务区的多个站点信息 的列表接口
|
// 拿到模版id列表 去绑定服务区的多个站点信息 的列表接口
|
||||||
export async function handleGetTemplatesList(params?: any) {
|
export async function handleGetTemplatesList(params?: any) {
|
||||||
@ -45,6 +46,14 @@ export async function handleUploadFile(params?: any) {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//原先的上传文件
|
||||||
|
export async function uploadAHYDPicture(uploadFilds?: any) {
|
||||||
|
return await requestUpload(`/Picture/UploadPicture`, {
|
||||||
|
method: 'POST',
|
||||||
|
data: uploadFilds
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 模版树的查询
|
// 模版树的查询
|
||||||
export async function handleSearchModalTree(params?: any) {
|
export async function handleSearchModalTree(params?: any) {
|
||||||
const data = await request.post(`/questionnaire-templates/search/tree`, params)
|
const data = await request.post(`/questionnaire-templates/search/tree`, params)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import qs from 'qs';
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import CryptoJS from "crypto-js";
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
// const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
||||||
@ -16,8 +16,8 @@ const { UMI_APP_BASEURL } = process.env;
|
|||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'https://admin.es.eshangtech.com/platform' });
|
// const instance = axios.create({ baseURL: 'https://admin.es.eshangtech.com/platform' });
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://111.229.213.193:18071/' });
|
const instance = axios.create({ baseURL: 'http://111.229.213.193:18071/' });
|
||||||
const instance = axios.create({ baseURL: 'https://java.es.eshangtech.com:443/' });
|
// const instance = axios.create({ baseURL: 'https://java.es.eshangtech.com:443/' });
|
||||||
|
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://10.104.1.175:8070/platform' });
|
// const instance = axios.create({ baseURL: 'http://10.104.1.175:8070/platform' });
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import CryptoJS from "crypto-js";
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
// const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import CryptoJS from "crypto-js";
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
// const instance = axios.create({ baseURL: '/auth' });
|
// const instance = axios.create({ baseURL: '/auth' });
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import CryptoJS from "crypto-js";
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
// const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
||||||
|
|||||||
164
src/utils/requestUpload.ts
Normal file
164
src/utils/requestUpload.ts
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { getDvaApp } from 'umi';
|
||||||
|
import { notification } from 'antd';
|
||||||
|
import type { AxiosRequestHeaders } from 'axios/index';
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
import qs from 'qs';
|
||||||
|
|
||||||
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
|
const instance = axios.create({ baseURL: 'https://eshangtech.com:18900/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: 'http://home.robot-z.cn:7001/' });
|
||||||
|
// 修改baseURL为完整的API地址,确保在生产环境中正确访问
|
||||||
|
// const instance = axios.create({ baseURL: 'https://es.robot-z.cn' });
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: 'https://es.eshangtech.com' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: 'https://admin.es.eshangtech.com/platform' });
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: 'http://10.104.1.175:8070/platform' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
instance.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
// 对data数据进行加密
|
||||||
|
// if (config.data) {
|
||||||
|
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
|
||||||
|
// }
|
||||||
|
|
||||||
|
// config.headers = {
|
||||||
|
// ...config.headers,
|
||||||
|
// Authorization: token ? `Bearer ${localStorage.getItem('Authorization') || ''}` : "",
|
||||||
|
// "Content-Type": isUpload ? "multipart/form-data" : "application/json;charset=utf-8",
|
||||||
|
// } as AxiosRequestHeaders;
|
||||||
|
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error),
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.interceptors.response.use(
|
||||||
|
//状态码为2xx的时候执行
|
||||||
|
(response) => {
|
||||||
|
const { data } = response;
|
||||||
|
|
||||||
|
if (data.Result_Code !== 100) {
|
||||||
|
// notification.error({
|
||||||
|
// message: data.message,
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamp = getFormattedDate()
|
||||||
|
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
//状态码不是2xx的时候执行
|
||||||
|
(error) => {
|
||||||
|
const { response } = error;
|
||||||
|
|
||||||
|
if (response && response.status === 401) {
|
||||||
|
// // 清除本地存储的token
|
||||||
|
// localStorage.removeItem('Authorization');
|
||||||
|
// // 重定向到登录页
|
||||||
|
// window.location.href = '/user/login';
|
||||||
|
// notification.error({
|
||||||
|
// message: response?.data?.message || '请求失败',
|
||||||
|
// description: error.message
|
||||||
|
// });
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: response?.data?.message || '请求失败',
|
||||||
|
description: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject({
|
||||||
|
code: response?.status || 500,
|
||||||
|
message: response?.data?.message || '请求失败'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
const encryptAESECB = (data: string, key: string) => {
|
||||||
|
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
|
||||||
|
const cipher = CryptoJS.AES.encrypt(data, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
|
||||||
|
// let encrypted = cipher.update(data, 'utf8', 'hex');
|
||||||
|
// encrypted += cipher.final('hex');
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
const decryptAESECB = (data: string, key: string) => {
|
||||||
|
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
|
||||||
|
// let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||||
|
// decrypted += decipher.final('utf8');
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
|
||||||
|
const encryptedData = CryptoJS.enc.Hex.parse(data);
|
||||||
|
|
||||||
|
// 解密操作
|
||||||
|
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB, // ECB 模式
|
||||||
|
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
|
||||||
|
});
|
||||||
|
// 将解密后的结果转为 UTF-8 字符串
|
||||||
|
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
|
||||||
|
return decryptedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// md5 签名
|
||||||
|
const md5 = (key: string, data: string, timestamp: string) => {
|
||||||
|
const text = "s" + key + data + timestamp;
|
||||||
|
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名戳
|
||||||
|
const getFormattedDate = () => {
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear(); // 获取年份 (yyyy)
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
|
||||||
|
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
|
||||||
|
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密方法
|
||||||
|
const preprocessData = (data: string) => {
|
||||||
|
console.log('data', data);
|
||||||
|
// YYYYMMDD
|
||||||
|
let timestamp = getFormattedDate()
|
||||||
|
console.log('timestamp', timestamp);
|
||||||
|
// 秒为单位的时间戳
|
||||||
|
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
|
||||||
|
console.log('timeSecond', timeSecond);
|
||||||
|
// 数据的加密
|
||||||
|
let encryptionData = encryptAESECB(data, timestamp)
|
||||||
|
console.log('encryptionData', encryptionData);
|
||||||
|
// md5签名方法
|
||||||
|
let md5Data = md5(timestamp, encryptionData, timestamp)
|
||||||
|
console.log('md5Data', md5Data);
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
data: encryptionData,
|
||||||
|
timestamp: timeSecond,
|
||||||
|
sign: md5Data
|
||||||
|
}
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
export default instance;
|
||||||
Loading…
x
Reference in New Issue
Block a user