Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Five-菜鸟级
NodeJS_668036
提交
df8c2f01
N
NodeJS_668036
项目概览
Five-菜鸟级
/
NodeJS_668036
与 Fork 源项目一致
Fork自
inscode / NodeJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NodeJS_668036
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
df8c2f01
编写于
2月 06, 2025
作者:
Q
qq_41923622
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Feb 6 11:54:00 CST 2025 inscode
上级
7c2d9c59
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
168 addition
and
168 deletion
+168
-168
src/tiny-image-editor/src/components/Upload.tsx
src/tiny-image-editor/src/components/Upload.tsx
+168
-168
未找到文件。
src/tiny-image-editor/src/components/Upload.tsx
浏览文件 @
df8c2f01
// import { Popover } from '@casstime/bricks';
// import { Popover } from '@casstime/bricks';
import
React
,
{
forwardRef
,
useContext
,
useImperativeHandle
}
from
'
react
'
;
import
React
,
{
forwardRef
,
useContext
,
useImperativeHandle
}
from
'
react
'
;
import
{
ACTION
,
LANG
,
MENU_TYPE_ENUM
,
MENU_TYPE_TEXT
}
from
'
../constants
'
;
import
{
ACTION
,
LANG
,
MENU_TYPE_ENUM
,
MENU_TYPE_TEXT
}
from
'
../constants
'
;
import
{
EditorContext
}
from
'
../util
'
;
import
{
EditorContext
}
from
'
../util
'
;
import
Popover
from
'
./setting/Popover
'
;
import
Popover
from
'
./setting/Popover
'
;
import
{
fabric
}
from
'
fabric
'
;
import
{
fabric
}
from
'
fabric
'
;
function
annotationsInit
(
annotations
,
canvas
,
historyRef
){
function
annotationsInit
(
annotations
,
canvas
,
historyRef
){
// 遍历标注信息,重新创建元素并添加到画布上
// 遍历标注信息,重新创建元素并添加到画布上
annotations
.
forEach
((
annotation
)
=>
{
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
({
left
:
annotation
.
left
,
left
:
annotation
.
left
,
top
:
annotation
.
top
,
top
:
annotation
.
top
,
originX
:
'
left
'
,
originX
:
'
left
'
,
originY
:
'
top
'
,
originY
:
'
top
'
,
width
:
annotation
.
width
,
width
:
annotation
.
width
,
height
:
annotation
.
height
,
height
:
annotation
.
height
,
angle
:
annotation
.
angle
,
angle
:
annotation
.
angle
,
fill
:
annotation
.
fill
,
fill
:
annotation
.
fill
,
stroke
:
annotation
.
stroke
,
stroke
:
annotation
.
stroke
,
scaleX
:
annotation
.
scaleX
,
scaleX
:
annotation
.
scaleX
,
scaleY
:
annotation
.
scaleY
,
scaleY
:
annotation
.
scaleY
,
strokeWidth
:
annotation
.
size
,
strokeWidth
:
annotation
.
size
,
transparentCorners
:
false
,
transparentCorners
:
false
,
opacity
:
annotation
.
opacity
||
1
opacity
:
annotation
.
opacity
||
1
});
});
break
;
break
;
case
'
textbox
'
:
case
'
textbox
'
:
case
'
text
'
:
case
'
text
'
:
newObject
=
new
fabric
.
Textbox
(
annotation
.
text
,
{
newObject
=
new
fabric
.
Textbox
(
annotation
.
text
,
{
left
:
annotation
.
left
,
left
:
annotation
.
left
,
top
:
annotation
.
top
,
top
:
annotation
.
top
,
width
:
annotation
.
width
,
width
:
annotation
.
width
,
angle
:
annotation
.
angle
,
angle
:
annotation
.
angle
,
fill
:
annotation
.
fill
,
fill
:
annotation
.
fill
,
stroke
:
annotation
.
stroke
,
stroke
:
annotation
.
stroke
,
scaleX
:
annotation
.
scaleX
,
scaleX
:
annotation
.
scaleX
,
scaleY
:
annotation
.
scaleY
,
scaleY
:
annotation
.
scaleY
,
opacity
:
annotation
.
opacity
||
1
opacity
:
annotation
.
opacity
||
1
});
});
break
;
break
;
case
'
circle
'
:
case
'
circle
'
:
newObject
=
new
fabric
.
Circle
({
newObject
=
new
fabric
.
Circle
({
left
:
annotation
.
left
,
left
:
annotation
.
left
,
top
:
annotation
.
top
,
top
:
annotation
.
top
,
radius
:
annotation
.
width
/
2
,
radius
:
annotation
.
width
/
2
,
angle
:
annotation
.
angle
||
0
,
angle
:
annotation
.
angle
||
0
,
fill
:
annotation
.
fill
||
''
,
fill
:
annotation
.
fill
||
''
,
originX
:
'
left
'
,
originX
:
'
left
'
,
originY
:
'
top
'
,
originY
:
'
top
'
,
stroke
:
annotation
.
stroke
,
stroke
:
annotation
.
stroke
,
scaleX
:
annotation
.
scaleX
,
scaleX
:
annotation
.
scaleX
,
scaleY
:
annotation
.
scaleY
,
scaleY
:
annotation
.
scaleY
,
strokeWidth
:
annotation
.
size
,
strokeWidth
:
annotation
.
size
,
opacity
:
annotation
.
opacity
||
1
opacity
:
annotation
.
opacity
||
1
});
});
break
;
break
;
// 可以根据需要添加更多元素类型的处理
// 可以根据需要添加更多元素类型的处理
}
}
if
(
newObject
)
{
if
(
newObject
)
{
console
.
log
(
`annotation`
,
newObject
,
annotation
,
canvas
)
console
.
log
(
`annotation`
,
newObject
,
annotation
,
canvas
)
canvas
.
add
(
newObject
)
canvas
.
add
(
newObject
)
canvas
.
setActiveObject
(
newObject
);
canvas
.
setActiveObject
(
newObject
);
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
,
true
,
true
);
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
,
true
,
true
);
// canvas.setActiveObject(newObject);
// canvas.setActiveObject(newObject);
}
}
});
});
}
}
export
const
useUpload
=
()
=>
{
export
const
useUpload
=
()
=>
{
const
{
const
{
canvasInstanceRef
,
canvasInstanceRef
,
canvasEl
,
canvasEl
,
currentMenuRef
,
currentMenuRef
,
historyRef
,
historyRef
,
setCurrentMenu
,
setCurrentMenu
,
initBackGroundImage
,
initBackGroundImage
,
}
=
useContext
(
EditorContext
);
}
=
useContext
(
EditorContext
);
const
handleUpload
=
(
e
:
any
,
imgData
?:
any
)
=>
{
const
handleUpload
=
(
e
:
any
,
imgData
?:
any
)
=>
{
console
.
log
(
`e`
,
e
,
imgData
)
console
.
log
(
`e`
,
e
,
imgData
)
const
canvas
=
canvasInstanceRef
.
current
;
const
canvas
=
canvasInstanceRef
.
current
;
if
(
canvasEl
?.
current
&&
typeof
e
===
'
string
'
){
if
(
canvasEl
?.
current
&&
typeof
e
===
'
string
'
){
let
imgObj
=
new
Image
();
let
imgObj
=
new
Image
();
imgObj
.
src
=
e
as
string
;
imgObj
.
src
=
e
as
string
;
initBackGroundImage
(
e
as
string
,
true
,
()
=>
{
initBackGroundImage
(
e
as
string
,
true
,
()
=>
{
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
);
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
);
setTimeout
(()
=>
{
setTimeout
(()
=>
{
if
(
imgData
){
if
(
imgData
){
annotationsInit
(
imgData
.
annotations
,
canvas
,
historyRef
);
annotationsInit
(
imgData
.
annotations
,
canvas
,
historyRef
);
}
}
})
})
},
5000
);
},
5000
);
return
;
return
;
}
}
if
(
if
(
!
canvas
||
!
canvas
||
!
canvasEl
.
current
||
!
canvasEl
.
current
||
!
e
.
target
.
files
.
length
||
!
e
.
target
.
files
.
length
||
!
e
.
target
.
files
[
0
]?.
type
?.
includes
(
'
image
'
)
!
e
.
target
.
files
[
0
]?.
type
?.
includes
(
'
image
'
)
)
{
)
{
return
;
return
;
}
}
if
(
currentMenuRef
.
current
!==
MENU_TYPE_ENUM
.
upload
)
{
if
(
currentMenuRef
.
current
!==
MENU_TYPE_ENUM
.
upload
)
{
setCurrentMenu
(
MENU_TYPE_ENUM
.
upload
);
setCurrentMenu
(
MENU_TYPE_ENUM
.
upload
);
}
}
const
reader
=
new
FileReader
();
const
reader
=
new
FileReader
();
reader
.
onload
=
function
(
event
)
{
reader
.
onload
=
function
(
event
)
{
if
(
!
event
||
!
event
.
target
)
{
if
(
!
event
||
!
event
.
target
)
{
return
;
return
;
}
}
let
imgObj
=
new
Image
();
let
imgObj
=
new
Image
();
imgObj
.
src
=
event
.
target
.
result
as
string
;
imgObj
.
src
=
event
.
target
.
result
as
string
;
initBackGroundImage
(
event
.
target
.
result
as
string
,
true
,
()
=>
{
initBackGroundImage
(
event
.
target
.
result
as
string
,
true
,
()
=>
{
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
);
historyRef
.
current
.
updateCanvasState
(
ACTION
.
add
);
});
});
};
};
reader
.
readAsDataURL
(
e
.
target
.
files
[
0
]);
reader
.
readAsDataURL
(
e
.
target
.
files
[
0
]);
};
};
return
{
handleUpload
};
return
{
handleUpload
};
};
};
/** 上传 */
/** 上传 */
export
const
Upload
=
forwardRef
((
props
,
ref
)
=>
{
export
const
Upload
=
forwardRef
((
props
,
ref
)
=>
{
const
{
const
{
lang
=
LANG
.
en
lang
=
LANG
.
en
}
=
useContext
(
EditorContext
);
}
=
useContext
(
EditorContext
);
const
{
handleUpload
}
=
useUpload
();
const
{
handleUpload
}
=
useUpload
();
useImperativeHandle
(
useImperativeHandle
(
ref
,
ref
,
()
=>
({
()
=>
({
handleUpload
:
handleUpload
,
handleUpload
:
handleUpload
,
}),
}),
[
handleUpload
],
[
handleUpload
],
);
);
return
(
return
(
<>
<>
{
/* <div className="tie-image-editor_tool-item tie-image-editor_tool-upload"> */
}
{
/* <div className="tie-image-editor_tool-item tie-image-editor_tool-upload"> */
}
{
/* <Popover content={MENU_TYPE_TEXT.upload[lang]} placement="top"> */
}
{
/* <Popover content={MENU_TYPE_TEXT.upload[lang]} placement="top"> */
}
{
/* <i className="tie-image-editor_icon"> */
}
{
/* <i className="tie-image-editor_icon"> */
}
{
/* <input
{
/* <input
onChange={handleUpload}
onChange={handleUpload}
type="file"
type="file"
className="tie-image-editor_tool-upload-input"
className="tie-image-editor_tool-upload-input"
accept="image/*"
accept="image/*"
/> */
}
/> */
}
{
/* </i> */
}
{
/* </i> */
}
{
/* </Popover> */
}
{
/* </Popover> */
}
{
/* </div> */
}
{
/* </div> */
}
</>
</>
);
);
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录