提交 8be18dd8 编写于 作者: Q qq_41923622

Fri Feb 14 13:04:00 CST 2025 inscode

上级 7ac2f57f
import React, { useRef } from 'react';
import { Editor } from 'tiny-image-editor';
import image from './basic.jpg';
//
const Demo = () => {
const EditorRefID =useRef<HTMLCanvasElement>(null);
setTimeout(()=>{
console.log(`dddd`,EditorRefID);
const handleUpload = EditorRefID?.current?.uploadRef?.current?.handleUpload;
handleUpload('https://erp-new.cdn.yingtaoyun.com/flw/1784/Q2406170015/jx/1241858/TY990010.jpg!w320')
},1000)
setTimeout(()=>{
const handleUpload = EditorRefID?.current?.uploadRef?.current?.handleUpload;
const xhr = new XMLHttpRequest();
// 要请求的 URL
const url = 'https://vercel-api.fivecc.cn/api/annotation';
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const responseData = JSON.parse(xhr.responseText);
console.log(`asd`,responseData)
Object.keys(responseData.data).forEach((k)=>{
let itemObj = responseData.data[k]
handleUpload(itemObj.imgUrl,itemObj)
})
} else {
resultDiv.textContent = `Error: ${xhr.status}`;
}
}
};
xhr.send();
},6000)
return (
<div style={{width:"100%",height:"100%"}}>
<Editor ref={EditorRefID} url={image} />
</div>
);
};
export default Demo;
此差异已折叠。
此差异已折叠。
...@@ -3,7 +3,7 @@ import { IMAGE_NAME, LANG, MENU_TYPE_TEXT } from '../constants'; ...@@ -3,7 +3,7 @@ import { IMAGE_NAME, LANG, MENU_TYPE_TEXT } from '../constants';
import { EditorContext, base64ToBlob, isSupportFileApi } from '../util'; import { EditorContext, base64ToBlob, isSupportFileApi } from '../util';
import Popover from './setting/Popover'; import Popover from './setting/Popover';
function extractImageNames(str) { function extractImageNames(str:any) {
// 定义更通用的正则表达式 // 定义更通用的正则表达式
const regex = /([^\/!]+?)\.(?:jpeg|jpg|png|gif|bmp)(?![^!]*\.)/gi; const regex = /([^\/!]+?)\.(?:jpeg|jpg|png|gif|bmp)(?![^!]*\.)/gi;
const matches = []; const matches = [];
...@@ -25,7 +25,7 @@ const useDownload = () => { ...@@ -25,7 +25,7 @@ const useDownload = () => {
// 获取画布上的所有元素 // 获取画布上的所有元素
const allObjects = canvas.getObjects(); const allObjects = canvas.getObjects();
// 存储标注信息的数组 // 存储标注信息的数组
const annotations = []; const annotations:[] = [];
function getDeviceId() { function getDeviceId() {
let deviceId = localStorage.getItem('deviceId'); let deviceId = localStorage.getItem('deviceId');
......
...@@ -14,7 +14,6 @@ function annotationsInit(imgData, canvas, historyRef, positionInfo) { ...@@ -14,7 +14,6 @@ function annotationsInit(imgData, canvas, historyRef, positionInfo) {
// 遍历标注信息,重新创建元素并添加到画布上 // 遍历标注信息,重新创建元素并添加到画布上
imgData.annotations.forEach((annotation) => { imgData.annotations.forEach((annotation) => {
let newObject; let newObject;
switch (annotation.type) { switch (annotation.type) {
case 'rect': case 'rect':
newObject = new fabric.Rect({ newObject = new fabric.Rect({
...@@ -157,7 +156,7 @@ export const useUpload = () => { ...@@ -157,7 +156,7 @@ export const useUpload = () => {
}); });
return; return;
}, { },{
newLeft, newLeft,
newTop, newTop,
newScaleFactor, newScaleFactor,
......
...@@ -23,6 +23,7 @@ export interface IEditorContextProps extends IEditorProps { ...@@ -23,6 +23,7 @@ export interface IEditorContextProps extends IEditorProps {
imageUrl: string, imageUrl: string,
justBackground: boolean, justBackground: boolean,
callback?: () => void, callback?: () => void,
annotationsData?:any
) => void; ) => void;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册