合并代码

This commit is contained in:
X1627315083
2024-08-19 10:36:46 +08:00
parent a8ab30f30c
commit e4b3ebe88b
30 changed files with 857 additions and 472 deletions

View File

@@ -1,50 +1,37 @@
import html2canvas from "html2canvas";
const getJpeg = dom =>{
return new Promise(resolve =>{
setTimeout(() => {
html2canvas(dom,{useCORS: true,}).then(canvas =>{
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 * 1
// 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(base64);
let fileOfBlob = new File([fileData], new Date() + ".jpg"); // 命名图片名
// console.log(smallBase64);
// resolve(base64ToFile(fileOfBlob))
resolve(fileOfBlob)
newImage.remove()
}
})
}, 100);
})
return new Promise(resolve =>{
setTimeout(() => {
html2canvas(dom,{useCORS: true,}).then(canvas =>{
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为外域时需要
const filename = new Date().toISOString() + '.jpg';
resolve(base64ToFile(base64,filename))
newImage.remove()
// }
})
}, 100);
})
}
function base64ToFile(base64,filename) {
// 从 Base64 编码中去掉数据类型描述部分
const base64Str = base64.replace(/^data:image\/[a-z]+;base64,/, '');
// 解码 Base64 字符串
const byteCharacters = atob(base64Str);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
// 创建 File 对象
const file = new File([byteArray], filename, { type: 'image/jpeg' }); // 根据需要的类型进行修改
console.log(file);
return file;
}
//base64转成blob
function dataURLtoFile(dataURI, type) {
@@ -58,16 +45,15 @@ function dataURLtoFile(dataURI, type) {
//转换
const base64ToFile = urlData =>{
const arr = urlData.split(',');
const mime = arr[0].match(/:(.*?);/)[1]
const bytes = atob(arr[1])
let n = bytes.length;
const ia = new Uint8Array(n)
while (n--){
ia[n] = bytes.charCodeAt(n);
}
return new File([ia],'jpeg',{type:mime})
}
// const base64ToFile = urlData =>{
// const arr = urlData.split(',');
// const mime = arr[0].match(/:(.*?);/)[1]
// const bytes = atob(arr[1])
// let n = bytes.length;
// const ia = new Uint8Array(n)
// while (n--){
// ia[n] = bytes.charCodeAt(n);
// }
// return new File([ia],'jpeg',{type:mime})
// }
export default getJpeg

View File

@@ -119,7 +119,7 @@ function createDriver(){
showButtons:false,
stagePadding:10,//切口到元素的距离
stageRadius:5,//切口圆弧度
allowKeyboardControl:false,//控制是否可以键盘控制下一步
allowKeyboardControl:true,//控制是否可以键盘控制下一步
disableActiveInteraction:false,//是否禁用显示元素的交互
overlayOpacity:.4,
overlay: true,
@@ -228,7 +228,6 @@ function removeDiv(element){
}
const openGuide = () =>{
return//暂时关闭
let isTest = JSON.parse(getCookie('isTest'))
let isBeginner = JSON.parse(getCookie('isBeginner'))
// console.log(isBeginner);

View File

@@ -27,7 +27,6 @@ import store from '@/store';
// }
let httpIp = process.env.NODE_ENV == 'development' ? "" : "";
// let httpIp = process.env.NODE_ENV == 'development' ? "https://192.168.1.8:10086" : "";
// console.log(httpIp,process.env.VUE_APP_BASE_URL,process.env.NODE_ENV);
axios.defaults.baseURL = httpIp; //配置接口地址
// console.log(axios.defaults.baseURL);
@@ -250,7 +249,8 @@ export const Https = {
getAllUserId:`/api/inquiry/getAllUserId`,//获取所有用户id和Name
adminAddUser:`/api/inquiry/addUser`,//添加用户
modifyUser:`/api/inquiry/modifyUser`,//修改用户
publishSysMessage:`/api/message/publishSysMessage`,//发布系统任务
getTasksList:`/api/tasks/getList`,//获取w为执行完的所有任务
getTasksHistory:`/api/tasks/getAllTask`,//获取所有任务列表
@@ -268,6 +268,11 @@ export const Https = {
portfolioCommentPage:`/api/portfolio/commentPage`,//作品广场评论列表
commentDelete:`/api/portfolio/commentDelete`,//删除评论
porfolioDelete:`/api/portfolio/delete`,//删除作品
porfolioFollow:`/api/portfolio/follow`,//删除作品
porfolioFollow:`/api/portfolio/follow`,//关注
porfolioCancelFollow:`/api/portfolio/cancelFollow`,//取消关注
porfolioGetFolloweeList:`/api/portfolio/getFolloweeList`,//获取关注列表
porfolioGetFollowerList:`/api/portfolio/getFollowerList`,//获取粉丝列表
//product生成
toProduct:`/api/history/toProduct`,//开始生成
@@ -292,6 +297,14 @@ export const Https = {
//调查问卷
questionnaire:`/api/account/questionnaire`,//保存画布
//消息系统
getUnreadCount:`/api/message/getUnreadCount`,//获取未读消息
setReadStatus:`/api/message/setReadStatus`,//设置消息已读
getHistoryNotification:`/api/message/getHistoryNotification`,//获取历史消息
oneClickRead:`/api/message/oneClickRead`,//全部设为已读
},
axiosGet(url,config) {

16
src/tool/myEvents.js Normal file
View File

@@ -0,0 +1,16 @@
class MyEvent{
static list = []
add(name,call){
MyEvent.list.push({name,call})
}
remove(name,call){
MyEvent.list.filter(item=>item.name!=name&&item.call!=call)
}
emit(name,data){
MyEvent.list.forEach(item => {
if(item.name == name)item.call(data)
});
}
}
export default new MyEvent()

View File

@@ -1,11 +1,27 @@
import MyEvent from "@/tool/myEvents";
class MyWs {
constructor() {
this.ws = null;
// this.ws = new WebSocket();
let http = process.env.VUE_APP_BASE_URL.replace(/^https?:\/\//, '')
this.messageUrl = http+'/notification'
}
linkWs(url) {
console.log(this.ws && this.ws.readyState == 1);
if (this.ws && this.ws.readyState == 1) return
this.ws = new WebSocket(url)
this.ws.onmessage = (e)=>{
try {
MyWs.receiveText(JSON.parse(e.data))
} catch (error) {
console.error('websocket',error)
}
}
console.log(this.ws);
}
static receiveText(data,call){
console.log('receive',data);
MyEvent.emit('getMessage',data)
}
sendMessage(data) {
console.log(this);
@@ -43,4 +59,5 @@ class MyWs {
}
}
}
export default new MyWs();
export default new MyWs()