MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / move

Function move

public/iframe/lib/js/common.js:10–177  ·  view source on GitHub ↗
(e, that, nowTemplate)

Source from the content-addressed store, hash-verified

8}
9
10function move (e, that, nowTemplate) {
11 let outLayerProperty = {}
12 const { type, parentId } = nowTemplate.property
13
14 if (type === 'group' && !parentId) {
15 // 最外层的组
16 outLayerProperty.top = 0
17 outLayerProperty.left = 0
18 } else if (type === 'group') {
19 outLayerProperty = vm.getParentGroupProperty(nowTemplate, false)
20 } else {
21 outLayerProperty = vm.getParentGroupProperty(nowTemplate)
22 }
23
24 let top = 0
25 let left = 0
26 e.pageX = Math.round(e.pageX / vm.zoom);
27 e.pageY = Math.round(e.pageY / vm.zoom);
28 const posix = !document.move_target
29 ? {
30 x: 0,
31 y: 0,
32 }
33 : document.move_target.posix;
34
35
36 // 限制拖拽的位置不能超过边界
37 let elementWidth = 600;
38 let elementHeight = 400;
39 if (nowTemplate) {
40 elementWidth = nowTemplate.property.width;
41 elementHeight = nowTemplate.property.height;
42 }
43 if (elementWidth + e.pageX - posix.x > vm.basicConfig.width) {
44 left = vm.basicConfig.width - elementWidth;
45 } else if (e.pageX - posix.x < 0) {
46 left = 0;
47 } else {
48 left = e.pageX - posix.x;
49 }
50 if (elementHeight + e.pageY - posix.y > vm.basicConfig.height) {
51 top = vm.basicConfig.height - elementHeight;
52 } else if (e.pageY - posix.y < 0) {
53 top = 0;
54 } else {
55 top = e.pageY - posix.y;
56 }
57
58 left -= outLayerProperty.left
59 top -= outLayerProperty.top;
60 // top left 相差10像素的元素自动吸附对齐
61 if (type !== 'group') { // 不是组
62 (function autoAlign () {
63 // 自动对齐
64 vm.templateList.map(item => {
65 if (
66 top + 10 >= item.property.top &&
67 top - 10 <= item.property.top

Callers 1

common.jsFile · 0.85

Calls 1

$Function · 0.70

Tested by

no test coverage detected