Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
b8cc9b37
提交
b8cc9b37
authored
5月 28, 2020
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
拖到打印修改
上级
035a30b2
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
123 行增加
和
69 行删除
+123
-69
DragSetting.js
zyd_private/DragAndPrint/DragSetting.js
+115
-65
index.js
zyd_private/DragAndPrint/ViewPrint/index.js
+3
-0
index.js
zyd_private/DragAndPrint/index.js
+1
-1
index.less
zyd_private/DragAndPrint/index.less
+4
-3
没有找到文件。
zyd_private/DragAndPrint/DragSetting.js
浏览文件 @
b8cc9b37
...
...
@@ -4,73 +4,111 @@ import styles from './index.less';
export
default
class
Index
extends
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{};
this
.
time1
=
new
Date
().
getTime
();
this
.
state
=
{
isDownObj
:
{},
drag
:
{
objX
:
'0px'
,
objY
:
'0px'
,
mouseY
:
0
,
mouseX
:
0
,
},
};
}
componentDidMount
()
{
}
dragEventList
=
()
=>
{
const
{
updateConfig
}
=
this
.
props
;
let
draggedRef
=
null
;
document
.
addEventListener
(
'dragstart'
,
function
(
event
)
{
// 保存拖动元素的引用(ref.)
draggedRef
=
event
.
target
;
// 使其半透明
event
.
target
.
style
.
opacity
=
0.5
;
},
false
,
);
document
.
addEventListener
(
'dragend'
,
function
(
event
)
{
// 重置透明度
event
.
target
.
style
.
opacity
=
''
;
},
false
,
);
handleOnMouseDown
=
(
e
,
id
)
=>
{
const
div
=
document
.
getElementById
(
id
);
const
{
isDownObj
}
=
this
.
state
;
const
newDrag
=
{
objX
:
div
.
style
.
left
,
objY
:
div
.
style
.
top
,
mouseX
:
e
.
clientX
,
mouseY
:
e
.
clientY
,
};
for
(
let
item
in
isDownObj
)
{
isDownObj
[
item
]
=
false
;
}
isDownObj
[
id
]
=
true
;
/* 放下目标节点时触发事件 */
document
.
addEventListener
(
'dragover'
,
function
(
event
)
{
// 阻止默认动作
event
.
preventDefault
();
console
.
log
(
'drop-x = '
,
event
.
offsetX
);
console
.
log
(
'drop-y = '
,
event
.
offsety
);
},
false
,
);
document
.
addEventListener
(
'drop'
,
function
(
event
)
{
// 阻止默认动作(如打开一些元素的链接)
event
.
preventDefault
();
// 将拖动的元素到所选择的放置目标节点中
if
(
event
.
target
.
id
===
'dropZone'
)
{
const
left
=
event
.
offsetX
;
if
(
left
>
event
.
target
.
width
-
draggedRef
.
offsetWidth
-
10
)
{
console
.
error
(
'拖拽到了图片区域外部,不能进行拖拽'
);
return
false
;
}
const
top
=
event
.
offsetY
;
console
.
log
(
'drop-x = '
,
event
.
offsetX
);
console
.
log
(
'drop-y = '
,
event
.
offsety
);
updateConfig
({
id
:
draggedRef
.
id
.
replace
(
'dragKey-'
,
''
),
x
:
left
,
y
:
top
,
});
draggedRef
.
style
.
left
=
left
;
// `${left}px`;
draggedRef
.
style
.
top
=
top
;
// `${top}px`;
}
},
false
,
);
this
.
setState
({
drag
:
newDrag
,
isDownObj
,
});
};
componentDidMount
()
{
this
.
dragEventList
();
}
handleOnMouseMove
=
(
e
)
=>
{
const
{
drag
,
isDownObj
}
=
this
.
state
;
if
(
new
Date
().
getTime
()
-
this
.
time1
<
17
)
{
this
.
time1
=
new
Date
().
getTime
();
return
false
;
}
let
id
=
''
;
for
(
let
item
in
isDownObj
)
{
if
(
isDownObj
[
item
])
{
id
=
item
;
}
}
if
(
!
id
)
{
return
false
;
}
let
{
mouseX
,
mouseY
,
objX
,
objY
}
=
drag
;
const
div
=
document
.
getElementById
(
id
);
let
x
=
e
.
clientX
;
let
y
=
e
.
clientY
;
if
(
isDownObj
&&
isDownObj
[
id
])
{
const
styleLeft
=
parseInt
(
objX
,
10
)
+
parseInt
(
x
,
10
)
-
parseInt
(
mouseX
,
10
);
// 计算偏移量
const
styleTop
=
parseInt
(
objY
,
10
)
+
parseInt
(
y
,
10
)
-
parseInt
(
mouseY
,
10
);
// 计算偏移量
const
dropZone
=
document
.
getElementById
(
'dropZone'
);
if
(
// 阻止拖拽到图片外部
styleLeft
>
dropZone
.
width
-
15
||
(
styleLeft
<
15
)
||
(
styleTop
>
dropZone
.
height
-
15
)
||
styleTop
<
15
)
{
console
.
error
(
'拖拽到了图片区域外部,不能进行拖拽'
);
return
false
;
}
div
.
style
.
left
=
styleLeft
+
'px'
;
div
.
style
.
top
=
styleTop
+
'px'
;
}
};
handleOnMouseUp
=
(
e
,
id
)
=>
{
const
{
drag
,
isDownObj
}
=
this
.
state
;
let
{
mouseX
,
mouseY
,
objX
,
objY
}
=
drag
;
if
(
isDownObj
[
id
])
{
let
x
=
e
.
clientX
;
let
y
=
e
.
clientY
;
let
div
=
document
.
getElementById
(
id
);
const
styleLeft
=
parseInt
(
x
,
10
)
-
parseInt
(
mouseX
,
10
)
+
parseInt
(
objX
,
10
);
const
styleTop
=
parseInt
(
y
,
10
)
-
parseInt
(
mouseY
,
10
)
+
parseInt
(
objY
,
10
);
div
.
style
.
left
=
`
${
styleLeft
}
px`
;
div
.
style
.
top
=
`
${
styleTop
}
px`
;
mouseX
=
x
;
mouseY
=
y
;
const
{
updateConfig
}
=
this
.
props
;
updateConfig
({
id
:
id
.
replace
(
'dragKey-'
,
''
),
x
:
styleLeft
,
y
:
styleTop
,
});
this
.
setState
({
drag
:
{
mouseX
,
mouseY
,
objX
,
objY
,
},
isDownObj
:
{},
});
}
};
render
()
{
const
{
...
...
@@ -80,6 +118,9 @@ export default class Index extends Component {
return
(
<
div
className
=
{
styles
.
outSideDiv
}
>
<
div
onMouseMove
=
{(
e
)
=>
{
this
.
handleOnMouseMove
(
e
);
}}
style
=
{{
padding
:
'12px'
,
}}
>
...
...
@@ -91,17 +132,26 @@ export default class Index extends Component {
alt
=
{
'背景图'
}
/
>
{
config
.
map
((
item
,
index
)
=>
{
const
domId
=
`dragKey-
${
item
.
id
}
`
;
return
(
<
div
draggable
=
{
tru
e
}
draggable
=
{
fals
e
}
className
=
{
styles
.
inSideItem
}
key
=
{
item
.
id
}
id
=
{
`dragKey-
${
item
.
id
}
`
}
onMouseDown
=
{(
e
)
=>
{
this
.
handleOnMouseDown
(
e
,
domId
);
}}
onMouseUp
=
{(
e
)
=>
{
this
.
handleOnMouseUp
(
e
,
domId
);
}}
id
=
{
domId
}
style
=
{{
top
:
`
${
item
.
y
||
20
+
index
*
40
}
px`
,
left
:
`
${
item
.
x
||
20
}
px`
,
}}
>
{
item
.
title
}
<
span
style
=
{{
marginLeft
:
'10px'
,
marginRight
:
'10px'
}}
>
{
item
.
title
}
<
/span
>
<
/div
>
);
})}
...
...
zyd_private/DragAndPrint/ViewPrint/index.js
浏览文件 @
b8cc9b37
...
...
@@ -23,6 +23,9 @@ export default class ViewPrint extends Component {
}
countImageHeight
=
()
=>
{
if
(
!
this
.
state
.
configAll
){
return
false
;
}
const
{
configAll
:
{
backgroundUrl
},
}
=
this
.
state
;
...
...
zyd_private/DragAndPrint/index.js
浏览文件 @
b8cc9b37
...
...
@@ -60,7 +60,7 @@ export default class Index extends Component {
if
(
!
configAll
||
!
configAll
.
backgroundUrl
)
{
return
null
;
}
console
.
log
(
configAll
);
//
console.log(configAll);
return
(
<
Shell
styleShell
=
{{
marginTop
:
'0'
,
marginBottom
:
'20px'
}}
>
<
div
style
=
{{
height
:
'54px'
,
padding
:
'12px 0 24px 12px'
}}
>
...
...
zyd_private/DragAndPrint/index.less
浏览文件 @
b8cc9b37
...
...
@@ -12,10 +12,11 @@
cursor: move;
z-index: 10;
color: #000;
padding-left: 10px;
padding-right: 10px;
user-select: none;
// padding-left: 10px;
// padding-right: 10px;
font-size: 14px;
line-height: 28px;
//
line-height: 28px;
border: 1px solid gray;
background-color: #CCC;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论