@@ -69,6 +69,16 @@ const props = defineProps({
6969 }
7070})
7171
72+ const {
73+ canvasComponentData,
74+ baseWidth,
75+ baseHeight,
76+ baseMarginLeft,
77+ baseMarginTop,
78+ draggable,
79+ resizable
80+ } = toRefs (props )
81+
7282type Coord = {
7383 x1: number
7484 y1: number
@@ -94,17 +104,6 @@ type Item = {
94104 sizeY: number
95105 [key : string ]: any
96106}
97-
98- const {
99- canvasComponentData,
100- baseWidth,
101- baseHeight,
102- baseMarginLeft,
103- baseMarginTop,
104- draggable,
105- resizable
106- } = toRefs (props )
107-
108107// DOM ref
109108const containerRef = ref <HTMLElement | null >(null )
110109const renderOk = ref (false )
@@ -115,6 +114,17 @@ const maxCell = ref(0)
115114const positionBox = ref <Array <Array <{ el: boolean }>>>([])
116115const coordinates = ref <Coord []>([])
117116const infoBox = ref ()
117+ const pointList = [' lt' , ' t' , ' rt' , ' r' , ' rb' , ' b' , ' lb' , ' l' ]
118+ const cursors = {
119+ lt: ' nw' ,
120+ t: ' n' ,
121+ rt: ' ne' ,
122+ r: ' e' ,
123+ rb: ' se' ,
124+ b: ' s' ,
125+ lb: ' sw' ,
126+ l: ' w'
127+ }
118128
119129// Position data (non-reactive)
120130
@@ -452,9 +462,9 @@ function findClosetCoords(item: { _dragId: string | number }, tCoord: Coord) {
452462}
453463/**
454464 * Generate coordinates
455- * @param {Item } item : The item object to generate coordinates for
465+ * @param {any } item : The item object to generate coordinates for
456466 */
457- function makeCoordinate(item : Item ) {
467+ function makeCoordinate(item : any ) {
458468 let width = cellWidth .value * item .sizeX - baseMarginLeft .value
459469 let height = cellHeight .value * item .sizeY - baseMarginTop .value
460470 let left = cellWidth .value * (item .x - 1 ) + baseMarginLeft .value
@@ -645,8 +655,8 @@ function findBelowItems(item: Item) {
645655
646656 return _ .sortBy (Object .values (belowItems ), ' y' )
647657}
648-
649- function startResize(e : MouseEvent , item : Item , index : number ) {
658+ // @ts-ignore
659+ function startResize(e : MouseEvent , point : string , item : Item , index : number ) {
650660 if (! resizable .value ) return
651661 props .resizeStart (e , item , index )
652662
@@ -707,7 +717,6 @@ function startMove(e: MouseEvent, item: Item, index: number) {
707717 infoBox .value .nowItemNode = target .closest (' .item' )
708718 infoBox .value .cloneItem = infoBox .value .nowItemNode .cloneNode (true )
709719 }
710-
711720 infoBox .value .cloneItem .classList .add (' cloneNode' )
712721 if ( containerRef .value ){
713722 containerRef .value .append (infoBox .value .cloneItem )
@@ -882,6 +891,46 @@ function moving() {
882891 // do moving
883892}
884893
894+ function getPointStyle(point : string , item : Item ) {
895+ const { sizeX, sizeY } = item
896+ const width = sizeX * (baseWidth .value + baseMarginLeft .value ) - baseMarginLeft .value
897+ const height = sizeY * (baseHeight .value + baseMarginTop .value ) - baseMarginTop .value
898+
899+ const hasT = / t/ .test (point )
900+ const hasB = / b/ .test (point )
901+ const hasL = / l/ .test (point )
902+ const hasR = / r/ .test (point )
903+ let newLeft = 0
904+ let newTop = 0
905+
906+ // 四个角的点
907+ if (point .length === 2 ) {
908+ newLeft = hasL ? 0 : width
909+ newTop = hasT ? 0 : height
910+ } else {
911+ // 上下两点的点,宽度居中
912+ if (hasT || hasB ) {
913+ newLeft = width / 2
914+ newTop = hasT ? 0 : height
915+ }
916+
917+ // 左右两边的点,高度居中
918+ if (hasL || hasR ) {
919+ newLeft = hasL ? 0 : width
920+ newTop = Math .floor (height / 2 )
921+ }
922+ }
923+
924+ return {
925+ marginLeft: ' -4px' ,
926+ marginTop: ' -4px' ,
927+ left: ` ${newLeft }px ` ,
928+ top: ` ${newTop }px ` ,
929+ // @ts-ignore
930+ cursor: ` ${cursors [point ]}-resize `
931+ }
932+ }
933+
885934defineExpose ({
886935 getRenderState ,
887936 init ,
@@ -922,12 +971,15 @@ defineExpose({
922971 :key =" 'item' + index"
923972 :style =" nowItemStyle(item)"
924973 >
925- <slot :name =" 'slot' + index" >{{ item }}</slot >
926- <span
974+ <slot :name =" 'slot' + index" >{{ item }} -- {{ baseWidth }}</slot >
975+
976+ <div
977+ v-for =" point in pointList"
978+ :key =" point"
927979 class =" resizeHandle"
928- v-show = " resizable "
929- @mousedown =" startResize($event, item, index)"
930- ></span >
980+ :style = " getPointStyle(point, item) "
981+ @mousedown =" startResize($event, point, item, index)"
982+ ></div >
931983 </div >
932984 </div >
933985 </div >
0 commit comments