Merge pull request 'baigl' (#52) from baigl into main

Reviewed-on: #52
This commit is contained in:
baigl 2024-11-21 16:22:50 +08:00
commit 39a5e6b60c
2 changed files with 18 additions and 51 deletions

View File

@ -8,7 +8,7 @@
http-equiv="Content-Security-Policy" http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
/> --> /> -->
<meta http-equiv="Content-Security-Policy" content="connect-src *; default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src * blob:;img-src * 'self' data: blob:" /> <meta http-equiv="Content-Security-Policy" content="connect-src * blob:; default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src * blob:;img-src * 'self' data: blob:" />
</head> </head>

View File

@ -174,22 +174,22 @@ const initHomeWork = async()=> {
// taskList.value = res; // taskList.value = res;
// tasklist_loading.value = false; // tasklist_loading.value = false;
} }
const getBase64 = (file) =>{ // const getBase64 = (file) =>{
return new Promise(function (resolve, reject) { // return new Promise(function (resolve, reject) {
let reader = new FileReader(); // let reader = new FileReader();
let imgResult = ""; // let imgResult = "";
reader.readAsDataURL(file); // reader.readAsDataURL(file);
reader.onload = function () { // reader.onload = function () {
imgResult = reader.result; // imgResult = reader.result;
}; // };
reader.onerror = function (error) { // reader.onerror = function (error) {
reject(error); // reject(error);
}; // };
reader.onloadend = function () { // reader.onloadend = function () {
resolve(imgResult); // resolve(imgResult);
}; // };
}); // });
} // }
/** /**
* @desc: 上传本地图片 * @desc: 上传本地图片
* @return: {*} * @return: {*}
@ -203,37 +203,7 @@ const handleImportImg = (uploadFile) => {
}); });
return; return;
} }
console.log('uploadFile', uploadFile); cropOption.img = window.URL.createObjectURL(uploadFile.raw);
//
getBase64(uploadFile.raw).then(res => {
// console.log('res-------', res);
// Electron 使 URL.createObjectURL
// const base64Data = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/...'; // Base64
// const base64Data = res; // Base64
// const buffer = Buffer.from(base64Data.split(',')[1], 'base64');
// const filePath = path.join(Remote.app.getPath('userData'), 'image.jpg');
// console.log(filePath,'???????????????????');
// fs.writeFileSync(filePath, buffer);
// const buf = fs.readFileSync(filePath)
// console.log(buf);
// const uint8Buffer = Uint8Array.from(buf)
// cropOption.img = window.URL.createObjectURL(new Blob([uint8Buffer]));
// cropOption.img = URL.createObjectURL(new Blob([fs.readFileSync(filePath)]));
// cropOption.img = URL.createObjectURL(new Blob([buffer]));
cropOption.img = res;
// console.log(cropOption.img);
// cropOption.img = window.URL.createObjectURL(new Blob([res]));
// console.log(cropOption.img);
})
// cropOption.img = window.URL.createObjectURL(uploadFile.raw);
// cropOption.img = window.URL.createObjectURL(new Blob([uploadFile.raw]));
// cropOption.img = window.URL.createObjectURL(new Blob([uploadFile.raw]));
// console.log(cropOption.img);
ElMessage.success('上传成功'); ElMessage.success('上传成功');
}; };
/** /**
@ -246,9 +216,6 @@ const getClipboardImg = async() => {
for (const item of clipboardItems) { for (const item of clipboardItems) {
for (const type of item.types) { for (const type of item.types) {
if (type.includes('image/')) { if (type.includes('image/')) {
console.log('剪贴板图片type', type);
console.log('剪贴板图片item', item);
console.log('剪贴板图片clipboardItems', clipboardItems);
const blob = await item.getType(type); const blob = await item.getType(type);
// blob Blob // blob Blob
cropOption.img = URL.createObjectURL(blob); cropOption.img = URL.createObjectURL(blob);