09-12
This commit is contained in:
@@ -2,12 +2,57 @@ import html2canvas from "html2canvas";
|
||||
const getJpeg = dom =>{
|
||||
return new Promise(resolve =>{
|
||||
html2canvas(dom,{useCORS: true,}).then(canvas =>{
|
||||
const jpeg = canvas.toDataURL('image/jpeg',1.0);
|
||||
resolve(base64ToFile(jpeg))
|
||||
console.log(jpeg,'=========');
|
||||
let base64 = canvas.toDataURL('image/jpeg',.9);
|
||||
let quality = 0.9 // 压缩系数0-1之间
|
||||
let newImage = new Image()
|
||||
newImage.src = base64
|
||||
newImage.setAttribute('crossOrigin', 'Anonymous') // url为外域时需要
|
||||
let imgWidth,
|
||||
imgHeight
|
||||
let w = undefined
|
||||
newImage.onload = function () {
|
||||
w = this.width * .8
|
||||
imgWidth = this.width
|
||||
imgHeight = this.height
|
||||
let canvas = document.createElement('canvas')
|
||||
let ctx = canvas.getContext('2d')
|
||||
if (Math.max(imgWidth, imgHeight) > w) {
|
||||
if (imgWidth > imgHeight) {
|
||||
canvas.width = w
|
||||
canvas.height = w * (imgHeight / imgWidth)
|
||||
} else {
|
||||
canvas.height = w
|
||||
canvas.width = w * (imgWidth / imgHeight)
|
||||
}
|
||||
} else {
|
||||
canvas.width = imgWidth
|
||||
canvas.height = imgHeight
|
||||
quality = 0.6
|
||||
}
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
||||
ctx.drawImage(this, 0, 0, canvas.width, canvas.height) // // 这里面的 this 指向 newImage
|
||||
let smallBase64 = canvas.toDataURL('image/jpeg', quality) // 压缩语句
|
||||
let fileData = dataURLtoFile(smallBase64);
|
||||
let fileOfBlob = new File([fileData], new Date() + ".jpg"); // 命名图片名
|
||||
// console.log(smallBase64);
|
||||
// resolve(base64ToFile(fileOfBlob))
|
||||
resolve(fileOfBlob)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
//base64转成blob
|
||||
function dataURLtoFile(dataURI, type) {
|
||||
let binary = atob(dataURI.split(",")[1]);
|
||||
let array = [];
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
array.push(binary.charCodeAt(i));
|
||||
}
|
||||
return new Blob([new Uint8Array(array)], { type: "image/jpeg" });
|
||||
}
|
||||
|
||||
//转换
|
||||
|
||||
const base64ToFile = urlData =>{
|
||||
const arr = urlData.split(',');
|
||||
const mime = arr[0].match(/:(.*?);/)[1]
|
||||
@@ -17,7 +62,6 @@ const base64ToFile = urlData =>{
|
||||
while (n--){
|
||||
ia[n] = bytes.charCodeAt(n);
|
||||
}
|
||||
console.log(new File([ia],'jpeg',{type:mime}));
|
||||
return new File([ia],'jpeg',{type:mime})
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,15 @@ import { message } from 'ant-design-vue';
|
||||
// }else{
|
||||
// axios.defaults.baseURL = process.env.VUE_APP_BASE_URL; //配置接口地址
|
||||
// }
|
||||
let httpIp
|
||||
if(process.env.NODE_ENV == 'development'){
|
||||
httpIp = 'http://192.168.1.6:10086'
|
||||
}else{
|
||||
httpIp = ''
|
||||
}
|
||||
console.log(httpIp);
|
||||
axios.defaults.baseURL = process.env.VUE_APP_BASE_URL; //配置接口地址
|
||||
console.log(process.env.VUE_APP_BASE_URL);
|
||||
// console.log(process.env.VUE_APP_BASE_URL);
|
||||
//POST传参序列化(添加请求拦截器)
|
||||
axios.interceptors.request.use((config) => {
|
||||
//在发送请求之前做某件事
|
||||
@@ -75,10 +82,10 @@ export const Https = {
|
||||
elementSavePrint:'/api/element/savePrint',//保存印花
|
||||
getRgbByTcx:'/api/element/getRgbByTcx', // 通过hsv值获取潘通信息
|
||||
getRgbByHsv:'/api/element/getRgbByHsv', //通过hsv值获取潘通信息
|
||||
designCollection:'/api/design/designCollection', //设计 Conllection
|
||||
designCollection:`${httpIp}/api/design/designCollection`, //设计 Conllection
|
||||
reDesignCollection:'/api/design/reDesignCollection',//重新设计 Conllection
|
||||
countDesignProcess:'/api/design/countDesignProcess', //统计design进度
|
||||
getRgbByHsvBatch:'http://192.168.1.6:10086/api/element/getRgbByHsvBatch', //通过hsv值数组批量获取潘通信息
|
||||
getRgbByHsvBatch:`${httpIp}/api/element/getRgbByHsvBatch`, //通过hsv值数组批量获取潘通信息
|
||||
designLike:'/api/design/like', //Design Like
|
||||
designDislike: '/api/design/dislike', //Design Dislike
|
||||
queryUserGroup:'/api/history/queryUserGroup', //History用户分页分组列表
|
||||
@@ -99,9 +106,12 @@ export const Https = {
|
||||
saveOrEditTemplatePoint:'/api/library/saveOrEditTemplatePoint',//保存或者编辑template打点
|
||||
libraryModelsDot:'/api/library/modelsDot',//Models打点预览
|
||||
pythonChatStream:'/api/python/chatStream',//机器人助力
|
||||
workspaceDetail:'http://192.168.1.6:10086/api/workspace/detail',//用户习惯详情
|
||||
workspaceDetail:`${httpIp}/api/workspace/detail`,//用户习惯详情
|
||||
workspaceList:`${httpIp}/api/workspace/list`,
|
||||
sketchAndPrintGenerate:'/api/generate/sketchAndPrint',//sketchGenerate生成图片
|
||||
|
||||
generateLike:'/api/generate/like',//喜欢ganerate图片
|
||||
elementUpload:'/api/element/upload',//上传图片
|
||||
|
||||
},
|
||||
|
||||
axiosGet(url,config) {
|
||||
|
||||
@@ -59,23 +59,25 @@ function rgbToHsv([R, G, B]) {
|
||||
B /= 255
|
||||
const max = Math.max(R, G, B)
|
||||
const min = Math.min(R, G, B)
|
||||
const range = max - min
|
||||
let V = max
|
||||
let S = V === 0 ? 0 : range / V
|
||||
let H = 0
|
||||
if (R === V) H = (60 * (G - B)) / range
|
||||
if (G === V) H = 120 + (60 * (B - R)) / range
|
||||
if (B === V) H = 240 + (60 * (R - G)) / range
|
||||
|
||||
if (range === 0) H = 0
|
||||
if (H < 0) H += 360
|
||||
H = (H / 2) * (256 / 180)
|
||||
S *= 255
|
||||
V *= 255
|
||||
|
||||
H = parseInt(H)
|
||||
S = parseInt(S)
|
||||
V = parseInt(V)
|
||||
const delta = max - min
|
||||
var H,S,V
|
||||
if (delta === 0) {
|
||||
H = 0;
|
||||
} else if (max === R) {
|
||||
H = ((G - B) / delta) % 6;
|
||||
} else if (max === G) {
|
||||
H = (B - R) / delta + 2;
|
||||
} else { // max === B
|
||||
H = (R - G) / delta + 4;
|
||||
}
|
||||
H = Math.round(H * 60); // 范围为 0-360
|
||||
if (max === 0) {
|
||||
S = 0;
|
||||
} else {
|
||||
S = delta / max;
|
||||
}
|
||||
S = Math.round(S*100); // 范围为 0-100
|
||||
V = Math.round(max*100); // 范围为 0-100
|
||||
return [H, S, V]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user