Skip to content

Commit 5a20442

Browse files
author
xinfei1
committed
logic
1 parent 7cb6a73 commit 5a20442

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed
File renamed without changes.

src/components/cardListDragPreview.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { Component } from 'react';
2+
import background_card from '@/logo.svg'
23
//拖拽预览组件类
34
export default class CardListDragPreview extends Component {
45
render() {
56
const { cardListLength, cardId } = this.props;
67
let divDom = [];
78
for (let index = 0; index < cardListLength; index++) {
8-
//第一个显示layer的dom,需要显示图片和数量红色气泡
9+
//第一个显示layer的dom,需要显示图片
910
if (index === cardListLength - 1) {
1011
const myIndex = index >= 3 ? 3 : index;
1112
divDom.push(
@@ -15,6 +16,12 @@ export default class CardListDragPreview extends Component {
1516
style={{ left: `${myIndex * 5}px`, top: `${myIndex * 5}px` }}
1617
>
1718
<span className='layer-card-span'>{cardId}</span>
19+
<img
20+
src={background_card}
21+
alt='logo'
22+
width='107'
23+
height='113'
24+
/>
1825
</div>
1926
);
2027
} else if (index < 3) {//layer的dom最多显示四个

src/utils/collision.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export const layoutCheck = (function () {
6666
widthOrHeight = item.height;
6767
}
6868
//判断当前卡片的坐标和目标卡片加上宽度/高度是否有重叠,防止重叠产生
69+
//在vertical情况下,是判断类似拖拽(0,1)宽1高1的方块与(0,0)宽1高2的纵向长方形,此时的交叠,纵向长方形保持不动,
70+
//在horizontal情况下,是判断类似拖拽(1,0)宽1高1的方块与(0,0)宽2高1的横向长方形,此时的交叠,横向长方形保持不动,
6971
if (
7072
layoutItem[axis] > item[axis] &&
7173
layoutItem[axis] < item[axis] + widthOrHeight

src/views/content.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MyContent extends Component {
1616
constructor(props) {
1717
super(props);
1818
this.state = {
19-
compactType: 'horizontal',//('vertical' | 'horizontal') = 'vertical'
19+
compactType: 'vertical',//('vertical' | 'horizontal') = 'vertical'
2020
defaultLayout: {
2121
containerWidth: 1200,
2222
containerHeight: 300,
@@ -42,7 +42,6 @@ class MyContent extends Component {
4242
};
4343
}
4444
/*
45-
* 工作桌面 用户桌面设置 页面
4645
* 关于卡片在组内的操作
4746
*/
4847
/**

test/case-collision.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* (0,0) 宽2 高1
3+
* (1,0) 宽1 高1
4+
*/
15
const testData1 = {
26
test: {
37
a: {
@@ -15,6 +19,10 @@ const testData1 = {
1519
},
1620
expect: true,
1721
};
22+
/**
23+
* (0,0) 宽1 高1
24+
* (1,0) 宽1 高1
25+
*/
1826
const testData2 = {
1927
test: {
2028
a: {
@@ -32,8 +40,31 @@ const testData2 = {
3240
},
3341
expect: false,
3442
};
43+
/**
44+
* (0,0) 宽1 高2
45+
* (0,1) 宽1 高1
46+
* 碰撞 解决issue:when 2x2 or 1x2 collosion bug for horizontal
47+
*/
48+
const testData3 = {
49+
test: {
50+
a: {
51+
gridx: 0,
52+
gridy: 0,
53+
width: 1,
54+
height: 2
55+
},
56+
b: {
57+
gridx: 0,
58+
gridy: 1,
59+
width: 1,
60+
height: 1
61+
}
62+
},
63+
expect: true,
64+
};
3565

3666
export default [
3767
testData1,
38-
testData2
68+
testData2,
69+
testData3
3970
];

0 commit comments

Comments
 (0)