drag.js 49.7 KB
Newer Older
huahua committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
const drag = {
	/**
	 * 部件缩放中事件四角缩放
	 */
	scaleMove(e,item,data) {
		var minwwidth = 50
		var minwheight = 50
		var shock = true
		if(item.type == 0 || item.type == 2){
			minwwidth = 50
			minwheight = 50
			shock = true
		}else if(item.type == 1){
			minwwidth = 50
			minwheight = 20
			shock = false
		}
		//记录移动后的位置
		item.touchMoveX = e.touches[0].clientX;
		item.touchMoveY = e.touches[0].clientY;
		//属性
		item.active = false //辅助线
		item.activeguide = false //辅助线
		item.activescale = false // 旋转状态
		item.activehorn = true // 角状态
		item.activeedge = false // 边状态
		// 记录移动的距离
		var ax = item.touchMoveX - item.touchX;
		var ay = item.touchMoveY - item.touchY;
		var x1 = item.left;
		var y1 = item.top;
		var x2 = item.left + item.width;
		var y2 = item.top + item.height;
		// 计算角度
		let roat = Math.abs(item.angle) % 360
		if(item.angle < 0){
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		if (item.typetext == "left-top") {
			// 2020-11-18
			// 获取图片宽度,处理图片拉伸自适应
			let initialScaleWidth = item.initialWidth * item.initialScale //获取图片宽度
			let initialscalingWidth = item.initialWidth * item.initialscaling //获取图片初始宽度
			let initialScaleHeight = item.initialHeight * item.initialScale //获取图片高度
			let initialscalingHeight = item.initialHeight * item.initialscaling //获取图片初始高度
			let Margin = initialScaleHeight - Math.abs(item.image_top) //视图可移动高度
			let Marginleft = initialScaleHeight - item.image_top //判断上边框移动是放大还是缩小
			let Margining = initialscalingHeight - Math.abs(item.image_top) //原来视图高度
			x1 += ax;
			y1 += ay;
			item.centerPos = {
				x: Math.floor((e.touches[0].clientX + item.rightBottomPoint.x) / 2),
				y: Math.floor((e.touches[0].clientY + item.rightMiddlePoint.y) / 2)
			}
			// 计算旋转为水平角度的两点坐标
			let newLeftTopPoint = this.getRotatedPoint({
				x: e.touches[0].clientX - item.mLeft,
				y: e.touches[0].clientY - item.mTop
			}, item.centerPos, -item.angle)
			let newRightBottomPoint = this.getRotatedPoint(item.rightBottomPoint, item.centerPos, -item.angle)
			let newWidth = newRightBottomPoint.x - newLeftTopPoint.x
			let newHeight = newRightBottomPoint.y - newLeftTopPoint.y
			// if (this.isScale) { 开启等比例缩放
				if (newWidth / newHeight > item.scaleone) {
					newLeftTopPoint.x = newLeftTopPoint.x + Math.abs(newWidth - newHeight * item.scaleone)
					newWidth = newHeight * item.scaleone
				} else {
					newLeftTopPoint.y = newLeftTopPoint.y + Math.abs(newHeight - newWidth / item.scaleone)
					newHeight = newWidth / item.scaleone
				}
				// 计算出左上角等比角度变换后水平坐标后,再计算旋转后的角度
				var rotateLeftTopPoint = this.getRotatedPoint(newLeftTopPoint, item.centerPos, item.angle)
				item.centerPos = {
					x: Math.floor((rotateLeftTopPoint.x + item.rightBottomPoint.x) / 2),
					y: Math.floor((rotateLeftTopPoint.y + item.rightBottomPoint.y) / 2)
				}
				item.x = item.centerPos.x // 方块圆心
				item.y = item.centerPos.y; // 方块圆心
				newLeftTopPoint = this.getRotatedPoint(rotateLeftTopPoint, item.centerPos, -item.angle)
				newRightBottomPoint = this.getRotatedPoint(item.rightBottomPoint, item.centerPos, -item.angle)
				newWidth = newRightBottomPoint.x - newLeftTopPoint.x
				newHeight = newRightBottomPoint.y - newLeftTopPoint.y
				let scaleWidth = newWidth / item.width
				let scaleHeight = newHeight / item.height
			// }
			if (newWidth <= minwwidth) {
				newWidth = minwwidth
				newHeight = Math.floor(newWidth / item.scaleone)
				newLeftTopPoint.x = newRightBottomPoint.x - newWidth
				newLeftTopPoint.y = newRightBottomPoint.y - newHeight
			}
			if (newHeight <= minwheight) {
				newHeight = minwheight
				newWidth = Math.floor(newHeight * item.scaleone)
				newLeftTopPoint.y = newRightBottomPoint.y - newHeight
				newLeftTopPoint.x = newRightBottomPoint.x - newWidth
			}
			if (newHeight > minwheight && newWidth > minwwidth) {
				item.left = newLeftTopPoint.x
				item.top = newLeftTopPoint.y
				item.width = newWidth
				item.height = newHeight
				
				if(item.left != 0 && item.top != 0){
					// console.log('top-left' + '-------' + item.top)
					// 修改初始化原始图片比率-坐标
					item.initialScale =  item.initialScale * scaleWidth
					item.initialscaling = item.initialscaling * scaleWidth
				}
				if(item.image_left < 0){
					if(item.left != 0){
						item.image_left = item.image_left * scaleWidth
					}
				}else{
					item.image_left = 0.001
				}
				
				if(item.image_top < 0){
					if(item.top != 0){
						item.image_top = item.image_top * scaleHeight
					}
				}else{
					item.image_top = 0.001
				}
				// 文本
				item.fontscale = item.fontscale * scaleHeight
				item.font_size = item.font_size * scaleHeight
				item.lineheight = item.lineheight * scaleHeight
				/* 2020-11-18 */
				// 计算左上角吸附效果
				if(item.type == 0 || item.type == 2){
					if (roat == 0 || roat == 180 || roat == 360) {
						if (item.left > -5 && item.left < 5) {  //左边框
							// console.log('left')
							// 修改初始化原始图片比率-坐标
							item.initialScale =  item.initialScale * (item.width + item.left) / item.width
							item.initialscaling = item.initialscaling * (item.width + item.left) / item.width
							// 裁剪区左边框磁性吸附
							item.width = newRightBottomPoint.x
							item.left = 0
							if(shock){
								wx.vibrateShort(); // 使手机振动15ms
							}
						}else if(item.top > -5 && item.top < 5) { //上边框
							console.log('top')
							if(item.top < 5 && item.top > 0){ //上边框偏下
								if(Marginleft < item.height){ //上边框放大
									item.initialScale =  item.initialScale * (item.height + item.top) / item.height
									item.initialscaling = item.initialscaling * (item.height + item.top) / item.height
								}else{	//上边框缩小
									// item.initialScale =  item.initialScale * (item.height + item.top) / item.height
									// item.initialscaling = item.initialscaling * (item.height + item.top) / item.height
								}
							}
							// 裁剪区上边框磁性吸附
							item.height = newRightBottomPoint.y
							item.top = 0
							if(shock){
								wx.vibrateShort(); // 使手机振动15ms
							}
						}
						this.getTransferPosition(item.left, item.top, item.width, item.height, item.angle, item.centerPos, item)
					}
				}
				
			}
		} else if (item.typetext == "left-bottom") {
			x1 += ax;
			y2 += ay;
			item.centerPos = {
			  x: Math.floor((e.touches[0].clientX + item.rightTopPoint.x) / 2),
			  y: Math.floor((e.touches[0].clientY + item.rightTopPoint.y) / 2)
			}
			// 计算旋转为水平角度的两点坐标
			let newLeftBottomPoint =  this.getRotatedPoint({
			  x: e.touches[0].clientX - item.mLeft,
			  y: e.touches[0].clientY - item.mTop
			}, item.centerPos, -item.angle)
			let newRightTopPoint = this.getRotatedPoint(item.rightTopPoint, item.centerPos, -item.angle)
			let newWidth = newRightTopPoint.x - newLeftBottomPoint.x
			let newHeight = newLeftBottomPoint.y - newRightTopPoint.y
			// if (item.isScale) {开启等比例缩放
			  if (newWidth / newHeight > item.scaleone) {
			    newLeftBottomPoint.x = newLeftBottomPoint.x + Math.abs(newWidth - newHeight * item.scaleone)
			    newWidth = newHeight * item.scaleone
			  } else {
			    newLeftBottomPoint.y = newLeftBottomPoint.y - Math.abs(newHeight - newWidth / item.scaleone)
			    newHeight = newWidth / item.scaleone
			  }
			  // 计算出左上角等比角度变换后水平坐标后,再计算旋转后的角度
			  var rotatedLeftBottomPoint = this.getRotatedPoint(newLeftBottomPoint, item.centerPos, item.angle)
			  item.centerPos = {
			    x: Math.floor((rotatedLeftBottomPoint.x + item.rightTopPoint.x) / 2),
			    y: Math.floor((rotatedLeftBottomPoint.y + item.rightTopPoint.y) / 2)
			  }
			  item.x = item.centerPos.x // 方块圆心
			  item.y = item.centerPos.y; // 方块圆心
			  newLeftBottomPoint = this.getRotatedPoint(rotatedLeftBottomPoint, item.centerPos, -item.angle)
			  newRightTopPoint = this.getRotatedPoint(item.rightTopPoint, item.centerPos, -item.angle)
			  newWidth = newRightTopPoint.x - newLeftBottomPoint.x
			  newHeight = newLeftBottomPoint.y - newRightTopPoint.y
			  let scaleWidth = newWidth / item.width
			  let scaleHeight = newHeight / item.height
			// }
			if (newHeight <= minwheight) {
			  newHeight = minwheight
			  newWidth = Math.floor(newHeight * item.scaleone)
			  newLeftBottomPoint = {
			    x: newRightTopPoint.x - newWidth,
			    y: newRightTopPoint.y + newHeight
			  }
			}
			if (newWidth <= minwwidth) {
			  newWidth = minwwidth
			  newHeight = Math.floor(newWidth / item.scaleone)
			  newLeftBottomPoint = {
			    x: newRightTopPoint.x - newWidth,
			    y: newRightTopPoint.y + newHeight
			  }
			}
			if (newHeight > minwheight && newWidth > minwwidth) {
			  item.left = newLeftBottomPoint.x
			  item.top = newRightTopPoint.y
			  item.width = newWidth
			  item.height = newHeight
			  // 修改初始化原始图片比率-坐标
			  item.initialScale =  item.initialScale * scaleWidth
			  item.initialscaling = item.initialscaling * scaleWidth
			  if(item.image_left < 0){
			  	item.image_left = item.image_left * scaleWidth
			  }else{
			  	item.image_left = 0.001
			  }
			  if(item.image_top < 0){
			  	item.image_top = item.image_top * scaleHeight
			  }else{
			  	item.image_top = 0.001
			  }
			  item.fontscale = item.fontscale * scaleHeight
			  item.font_size = item.font_size * scaleHeight
			  item.lineheight = item.lineheight * scaleHeight
			}
		} else if (item.typetext == "right-top") {
			x2 += ax;
			y1 += ay;
			
			item.centerPos = {
			  x: Math.floor(( e.touches[0].clientX + item.leftBottomPoint.x) / 2),
			  y: Math.floor(( e.touches[0].clientY + item.leftBottomPoint.y) / 2)
			}
			// 计算旋转为水平角度的两点坐标
			let newRightTopPoint = this.getRotatedPoint({
			  x: e.touches[0].clientX - item.mLeft,
			  y: e.touches[0].clientY - item.mTop
			}, item.centerPos, -item.angle)
			let newLeftBottomPoint = this.getRotatedPoint(item.leftBottomPoint, item.centerPos, -item.angle)
			let newWidth = newRightTopPoint.x - newLeftBottomPoint.x
			let newHeight = newLeftBottomPoint.y - newRightTopPoint.y
			// if (item.isScale) {开启等比例缩放
			  if (newWidth / newHeight > item.scaleone) {
			    newRightTopPoint.x = newRightTopPoint.x - Math.abs(newWidth - newHeight * item.scaleone)
			    newWidth = newHeight * item.scaleone
			  } else {
			    newRightTopPoint.y = newRightTopPoint.y + Math.abs(newHeight - newWidth / item.scaleone)
			    newHeight = newWidth / item.scaleone
			  }
			   // 计算出左上角等比角度变换后水平坐标后,再计算旋转后的角度
			  let rotatedRightTopPoint = this.getRotatedPoint(newRightTopPoint, item.centerPos, item.angle)
			  item.centerPos = {
			    x: Math.floor((rotatedRightTopPoint.x + item.leftBottomPoint.x) / 2),
			    y: Math.floor((rotatedRightTopPoint.y + item.leftBottomPoint.y) / 2)
			  }
			  item.x = item.centerPos.x // 方块圆心
			  item.y = item.centerPos.y; // 方块圆心
			  newLeftBottomPoint = this.getRotatedPoint(item.leftBottomPoint, item.centerPos, -item.angle)
			  newRightTopPoint = this.getRotatedPoint(rotatedRightTopPoint, item.centerPos, -item.angle)
			  newWidth = newRightTopPoint.x - newLeftBottomPoint.x
			  newHeight = newLeftBottomPoint.y - newRightTopPoint.y
			  let scaleWidth = newWidth / item.width
			  let scaleHeight = newHeight / item.height
			// }
			if (newWidth <= minwwidth) {
			  newWidth = minwwidth
			  newHeight = Math.floor(newWidth / item.scaleone)
			  newRightTopPoint = {
			    x: newLeftBottomPoint.x + newWidth,
			    y: newLeftBottomPoint.y - newHeight
			  }
			}
			if (newHeight <= minwheight) {
			  newHeight = minwheight
			  newWidth = Math.floor(newHeight * item.scaleone)
			  newRightTopPoint = {
			    x: newLeftBottomPoint.x + newWidth,
			    y: newLeftBottomPoint.y - newHeight
			  }
			}
			if (newWidth > minwwidth && newHeight > minwheight) {
			  item.left = newLeftBottomPoint.x
			  item.top = newRightTopPoint.y
			  item.width = newWidth
			  item.height = newHeight
			  // 修改初始化原始图片比率-坐标
			  item.initialScale =  item.initialScale * scaleWidth
			  item.initialscaling = item.initialscaling * scaleWidth
			  if(item.image_left < 0){
			  	item.image_left = item.image_left * scaleWidth
			  }else{
			  	item.image_left = 0.001
			  }
			  if(item.image_top < 0){
			  	item.image_top = item.image_top * scaleHeight
			  }else{
			  	item.image_top = 0.001
			  }
			  item.fontscale = item.fontscale * scaleHeight
			  item.font_size = item.font_size * scaleHeight
			  item.lineheight = item.lineheight * scaleHeight
			}
		} else if (item.typetext == "right-bottom") {
			x2 += ax;
			y2 += ay;
			
			item.centerPos = {
			  x: Math.floor((e.touches[0].clientX + item.leftTopPoint.x) / 2),
			  y: Math.floor((e.touches[0].clientY + item.leftTopPoint.y) / 2)
			}
			// 计算旋转为水平角度的两点坐标
			let newRightBottomPoint = this.getRotatedPoint({
			  x: e.touches[0].clientX - item.mLeft,
			  y: e.touches[0].clientY - item.mTop
			}, item.centerPos, -item.angle)
			let newLeftTopPoint = this.getRotatedPoint(item.leftTopPoint, item.centerPos, -item.angle)
			let newWidth = newRightBottomPoint.x - newLeftTopPoint.x
			let newHeight = newRightBottomPoint.y - newLeftTopPoint.y
			// if (item.isScale) {开启等比例缩放
			  if (newWidth / newHeight > item.scaleone) {
			    newRightBottomPoint.x = newRightBottomPoint.x - Math.abs(newWidth - newHeight * item.scaleone)
			    newWidth = newHeight * item.scaleone
			  } else {
			    newRightBottomPoint.y = newRightBottomPoint.y - Math.abs(newHeight - newWidth / item.scaleone)
			    newHeight = newWidth / item.scaleone
			  }
			  // 计算出左上角等比角度变换后水平坐标后,再计算旋转后的角度
			  let rotatedRightBottomPoint = this.getRotatedPoint(newRightBottomPoint, item.centerPos, item.angle)
			  item.centerPos = {
			    x: Math.floor((rotatedRightBottomPoint.x + item.leftTopPoint.x) / 2),
			    y: Math.floor((rotatedRightBottomPoint.y + item.leftTopPoint.y) / 2)
			  }
			  item.x = item.centerPos.x // 方块圆心
			  item.y = item.centerPos.y; // 方块圆心
			  newLeftTopPoint = this.getRotatedPoint(item.leftTopPoint, item.centerPos, -item.angle)
			  newRightBottomPoint = this.getRotatedPoint(rotatedRightBottomPoint, item.centerPos, -item.angle)
			  newWidth = newRightBottomPoint.x - newLeftTopPoint.x
			  newHeight = newRightBottomPoint.y - newLeftTopPoint.y
			  let scaleWidth = newWidth / item.width
			  let scaleHeight = newHeight / item.height
			// }
			if (newWidth <= minwwidth) {
			  newWidth = minwwidth
			  newHeight = Math.floor(newWidth / item.scaleone)
			  newRightBottomPoint = {
			    x: newLeftTopPoint.x + newWidth,
			    y: newLeftTopPoint.y + newHeight
			  }
			}
			if (newHeight <= minwheight) {
			  newHeight = minwheight
			  newWidth = Math.floor(newHeight * item.scaleone)
			  newRightBottomPoint = {
			    x: newLeftTopPoint.x + newWidth,
			    y: newLeftTopPoint.y + newHeight
			  }
			}
			if (newWidth > minwwidth && newHeight > minwheight) {
			  item.left = newLeftTopPoint.x
			  item.top = newLeftTopPoint.y
			  item.width = newWidth
			  item.height = newHeight
			  // 修改初始化原始图片比率-坐标
			  item.initialScale =  item.initialScale * scaleWidth
			  item.initialscaling = item.initialscaling * scaleWidth
			  if(item.image_left < 0){
			  	item.image_left = item.image_left * scaleWidth
			  }else{
			  	item.image_left = 0.001
			  }
			  if(item.image_top < 0){
			  	item.image_top = item.image_top * scaleHeight
			  }else{
			  	item.image_top = 0.001
			  }
			  item.fontscale = item.fontscale * scaleHeight
			  item.font_size = item.font_size * scaleHeight
			  item.lineheight = item.lineheight * scaleHeight
			}
		
		}
		//追加改动值
		// item.left = x1;
		// item.top = y1;
		// item.width = x2 - x1;
		// item.height = y2 - y1;
		//把新的值赋给老的值
		item.edgestartX = e.touches[0].clientX; // 获取鼠标按下时光标x的值
		item.edgestartY = e.touches[0].clientY; // 获取鼠标按下时光标Y的值
	},
	// 四边伸缩
	edgeMove(e,item,data){
		//记录移动后的位置
		item.edgemoveX = e.touches[0].clientX;
		item.edgemoveY = e.touches[0].clientY;
		//修改属性状态
		item.active = true //辅助线
		item.activeguide = false //辅助线
		item.activescale = false // 旋转状态
		item.activehorn = false // 角状态
		item.activeedge = true // 边状态
		//追加改动值
		let startX = item.edgestartX
		let moveX = item.edgemoveX
		let startY = item.edgestartY
		let moveY = item.edgemoveY
		item.x += item.edgemoveX - item.edgestartX; // 方块圆心
		item.y += item.edgemoveY - item.edgestartY; // 方块圆心
		// 获取图片宽度,处理图片拉伸自适应
		let initialScaleWidth = item.initialWidth * item.initialScale //获取图片宽度
		let initialscalingWidth = item.initialWidth * item.initialscaling //获取图片初始宽度
		let initialScaleHeight = item.initialHeight * item.initialScale //获取图片高度
		let initialscalingHeight = item.initialHeight * item.initialscaling //获取图片初始高度
		// 计算角度
		let roat = Math.abs(item.angle) % 360
		if(item.angle < 0){
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		if(item.typetext == "left"){
			let Margin = initialScaleWidth - Math.abs(item.image_left) //获取右边框移动宽度 = 图片宽度 - 移动的距离
			let Marginleft = initialScaleWidth - item.image_left  //判断左边框移动宽度 
			let Margining = initialscalingWidth - Math.abs(item.image_left) //原始视图宽度
			
			// 旋转角度拉伸算法核心代码
			let rotateCurrentPos = this.getRotatedPoint({
				x: e.touches[0].clientX - item.mLeft,
				y: e.touches[0].clientY - item.mTop
			}, item.rightMiddlePoint, -item.angle)
			let rotatedLeftMiddlePonit = {
				x: rotateCurrentPos.x,
				y: item.rightMiddlePoint.y
			}
			let newWidth = item.rightMiddlePoint.x - rotatedLeftMiddlePonit.x
			// 裁剪区最小值
			if (newWidth <= 50) {
				newWidth = 50
				rotatedLeftMiddlePonit.x = item.rightMiddlePoint.x - 50
			}
			item.leftMiddlePoint = this.getRotatedPoint(rotatedLeftMiddlePonit, item.rightMiddlePoint, item.angle)
			item.centerPos = {
				x: Math.floor((item.leftMiddlePoint.x + item.rightMiddlePoint.x) / 2),
				y: Math.floor((item.leftMiddlePoint.y + item.rightMiddlePoint.y) / 2)
			}
			item.differenceWidth = newWidth - item.width //宽度差值
			let scaleWidth = newWidth / item.width
			
			
			// 图片拉伸算法和背景图偏移数据
			if(item.image_left < 0){
				if(item.left != 0){
					item.image_left += newWidth - item.width;
				}
			}else{
				item.image_left = 0.001
			}
			item.left = item.centerPos.x - newWidth / 2
			item.top = item.centerPos.y - item.height / 2
			item.width = newWidth
			
			
			if (roat == 0 || roat == 180 || roat == 360) {
				if (item.left > -5 && item.left < 5) {
					// 图层吸附处理
					if(item.image_left != null && item.image_left != 0.001){
						// item.image_left = item.image_left + item.left;
						// let a_left = item.image_left
						// item.image_left = a_left - (item.width - item.rightTopPoint.x)
					}
					// 裁剪区左边框磁性吸附
					item.width = item.rightTopPoint.x
					item.left = 0
					wx.vibrateShort(); // 使手机振动15ms
					// 重新计算,计算背景图
					this.getTransferPosition(item.left, item.top, item.width, item.height, item.angle, item.centerPos, item)
					
				}
			}
			
			
			// 图片拉伸算法
			if(Marginleft < item.width){  //左边框移动过程中放大
				// console.log('移动放大')
				// x轴放大比率
				item.initialScalex = item.width / Margining
				// 计算图片放大比率=原始比率*x轴放大比率
				item.initialScale = item.initialscaling * item.initialScalex
				// 图片拉伸算法和背景图偏移数据
				item.image_top = item.image_top * scaleWidth
			}else{ //左边框移动过程中缩小
				// console.log('移动缩小')
				// 缩小到x轴放大比率 高度不能小于图片高度
				if(item.differenceWidth < 0 && item.initialScalex > 1 && initialScaleHeight > item.height){
					item.initialScalex = item.width / Margining
					item.initialScale = item.initialscaling * item.initialScalex
					// 图片拉伸算法和背景图偏移数据
					item.image_top = item.image_top * scaleWidth
				}
				// 左边框缩小到原始宽度时,x轴比率默认为=1,x轴不在缩放
				if(item.initialScale / item.initialScaley <= item.initialscaling){
					item.initialScalex = 1
					item.initialScale = item.initialscaling * item.initialScaley
				}
				// 左边框x轴缩小到最小值时,默认偏移数据
				if(item.differenceWidth < 0 && item.initialScalex <= 1){
					if(item.image_left > 0){
						item.image_left = -0.001;
					}	
				}
			}
		}else if(item.typetext == "right"){
			let Margin = initialScaleWidth - Math.abs(item.image_left) //视图宽度 原图-图片移动的距离
			let Marginleft = initialScaleWidth - item.image_left //判断左边框移动放大还是缩小
			let Margining = initialscalingWidth - Math.abs(item.image_left) //原来视图宽度
			// 旋转角度拉伸算法
			let rotateCurrentPos = this.getRotatedPoint({
				x: e.touches[0].clientX - item.mLeft,
				y: e.touches[0].clientY - item.mTop
			}, item.leftMiddlePoint, -item.angle)
			let rotatedRightMiddlePoint = {
				x: rotateCurrentPos.x,
				y: item.leftMiddlePoint.y
			}
			let newWidth = rotatedRightMiddlePoint.x - item.leftMiddlePoint.x
			// 裁剪区最小值
			if (newWidth <= 50) {
				newWidth = 50
				rotatedRightMiddlePoint.x = item.leftMiddlePoint.x + 50
			}
			item.rightMiddlePoint = this.getRotatedPoint(rotatedRightMiddlePoint, item.leftMiddlePoint, item.angle)
			item.centerPos = {
				x: Math.floor((item.leftMiddlePoint.x + item.rightMiddlePoint.x) / 2),
				y: Math.floor((item.leftMiddlePoint.y + item.rightMiddlePoint.y) / 2)
			}
			item.differenceWidth = newWidth - item.width  //宽度差值
			let scaleWidth = newWidth / item.width
			item.left = item.centerPos.x - newWidth / 2
			item.top = item.centerPos.y - item.height / 2
			item.width = newWidth
			if (roat == 0 || roat == 180 || roat == 360) {
				if (item.left > data.editorWidth - item.width - 5 && item.left < data.editorWidth - item.width + 5) {
					// 裁剪区右边框磁性吸附
					item.width = data.editorWidth - item.leftTopPoint.x
					wx.vibrateShort(); // 使手机振动15ms
				}
			}
			
			if(Margin < item.width){  //右边框放大
				// x轴放大比率
				item.initialScalex = item.width / Margining
				item.initialScale = item.initialscaling * item.initialScalex
				// 图片拉伸算法和背景图偏移数据
				item.image_top = item.image_top * scaleWidth
			}else{ //右边框缩小
				if(item.differenceWidth < 0 && item.initialScalex > 1 && initialScaleHeight > item.height){
					item.initialScalex = item.width / Margining
					item.initialScale = item.initialscaling * item.initialScalex
					// 图片拉伸算法和背景图偏移数据
					item.image_top = item.image_top * scaleWidth
				}
			}
		}else if(item.typetext == "top"){
			let Margin = initialScaleHeight - Math.abs(item.image_top) //视图可移动高度
			let Marginleft = initialScaleHeight - item.image_top //判断上边框移动是放大还是缩小
			let Margining = initialscalingHeight - Math.abs(item.image_top) //原来视图高度
			// 旋转角度拉伸算法
			let rotateCurrentPos = this.getRotatedPoint({
				x: e.touches[0].clientX - item.mLeft,
				y: e.touches[0].clientY - item.mTop
			}, item.bottomMiddlePoint, -item.angle)
			let rotatedTopMiddlePoint = {
				x: item.bottomMiddlePoint.x,
				y: rotateCurrentPos.y
			}
			let newHeight = item.bottomMiddlePoint.y - rotatedTopMiddlePoint.y
			// 裁剪区最小值
			if (newHeight <= 50) {
				newHeight = 50
				rotatedTopMiddlePoint.y = item.bottomMiddlePoint.y - 50
			}
			// 计算转回去的topmiddle点坐标
			item.topMiddlePoint = this.getRotatedPoint(rotatedTopMiddlePoint, item.bottomMiddlePoint, item.angle)
			item.centerPos = {
				x: (item.topMiddlePoint.x + item.bottomMiddlePoint.x) / 2,
				y: (item.topMiddlePoint.y + item.bottomMiddlePoint.y) / 2
			}
			item.differenceHeight = newHeight - item.height //高度差值,判断用户操作方向
			let scaleHeight = newHeight / item.height
			// 图片拉伸算法和背景图偏移数据
			if(item.image_top < 0){
				if(item.top != 0){
					item.image_top += newHeight - item.height;
				}
			}else{
				item.image_top = 0.001
			}
			item.left = item.centerPos.x - item.width / 2
			item.top = item.centerPos.y - newHeight / 2
			item.height = newHeight
			
			
			if (roat == 0 || roat == 180 || roat == 360) {
				if (item.top > -5 && item.top < 5) {
					// 裁剪区上边框磁性吸附
					item.height = item.leftBottomPoint.y
					item.top = 0
					wx.vibrateShort(); // 使手机振动15ms
					
					// 重新计算,计算背景图
					this.getTransferPosition(item.left, item.top, item.width, item.height, item.angle, item.centerPos, item)
				}
			}
			
			
			if(Marginleft < item.height){ //上边框放大
				item.initialScaley = item.height / Margining // y轴放大比率
				item.initialScale = item.initialscaling * item.initialScaley // 计算图片放大比率=原始比率*y轴放大比率
				// 图片拉伸算法和背景图偏移数据
				item.image_left = item.image_left * scaleHeight
			}else{  //上边框缩小
				if(item.differenceHeight < 0 && item.initialScaley > 1 && initialScaleWidth > item.width){
					item.initialScaley = item.height / Margining
					item.initialScale = item.initialscaling * item.initialScaley
					// 图片拉伸算法和背景图偏移数据
					item.image_left = item.image_left * scaleHeight
				}
				if(item.initialScale / item.initialScalex <= item.initialscaling){
					item.initialScaley = 1
					item.initialScale = item.initialscaling * item.initialScalex
				}
				// 恢复
				if(item.differenceHeight < 0 && item.initialScaley <= 1){
					if(item.image_top > 0){
						item.image_top = -0.001
					}
				}
			}
		}else if(item.typetext == "bottom"){
			let Margin = initialScaleHeight - Math.abs(item.image_top) //视图高度
			let Marginleft = initialScaleHeight - item.image_top //判断上边框移动放大还是缩小
			let Margining = initialscalingHeight - Math.abs(item.image_top) //原来视图高度
			// 旋转角度拉伸算法
			let rotateCurrentPos = this.getRotatedPoint({
				x: e.touches[0].clientX - item.mLeft,
				y: e.touches[0].clientY - item.mTop
			}, item.topMiddlePoint, -item.angle)
			let rotatedBottomMiddlePoint = {
				x: item.topMiddlePoint.x,
				y: rotateCurrentPos.y
			}
			let newHeight = rotatedBottomMiddlePoint.y - item.topMiddlePoint.y
			if (newHeight <= 50) {
				newHeight = 50
				rotatedBottomMiddlePoint.y = item.topMiddlePoint.y + 50
			}
			item.bottomMiddlePoint = this.getRotatedPoint(rotatedBottomMiddlePoint, item.topMiddlePoint, item.angle)
			item.centerPos = {
				x: Math.floor((item.bottomMiddlePoint.x + item.topMiddlePoint.x) / 2),
				y: Math.floor((item.bottomMiddlePoint.y + item.topMiddlePoint.y) / 2)
			}
			item.differenceHeight = newHeight - item.height //高度差值,判断用户操作方向
			let scaleHeight = newHeight / item.height
			item.left = item.centerPos.x - item.width / 2
			item.top = item.centerPos.y - newHeight / 2
			item.height = newHeight
			
			if (roat == 0 || roat == 180 || roat == 360) {
				if (item.top > data.editorHeight - item.height - 5 && item.top < data.editorHeight - item.height +5) {
					// 裁剪区下边框磁性吸附
					item.height = data.editorHeight - item.leftTopPoint.y
					wx.vibrateShort(); // 使手机振动15ms
				}
			}
			
			if(initialScaleHeight < item.height + Math.abs(item.image_top)){  //放大
				item.initialScaley = item.height / Margining
				item.initialScale = item.initialscaling * item.initialScaley
				// 图片拉伸算法和背景图偏移数据
				item.image_left = item.image_left * scaleHeight
			}else{ //缩小
				if(item.differenceHeight < 0 && item.initialScaley > 1 && initialScaleWidth > item.width){
					item.initialScaley = item.height / Margining
					item.initialScale = item.initialscaling * item.initialScaley
					// 图片拉伸算法和背景图偏移数据
					item.image_left = item.image_left * scaleHeight
				}
			}
		}
		//把新的值赋给老的值
		item.edgestartX = e.touches[0].clientX;// 获取鼠标按下时光标x的值
		item.edgestartY = e.touches[0].clientY;// 获取鼠标按下时光标Y的值
		//赋值就移动了
		// this.data.itemList = items
	},
	/**
	 * @description: 初始化targetObj的位置
	 */
	initPos(item) {
		// 记录初始盒子位置右下
		item.rightBottomPoint = {
			x: item.width + item.left,
			y: item.height + item.top
		}
		// 记录初始盒子右上角位置
		item.rightTopPoint = {
			x: item.width + item.left,
			y: item.top
		}
		// 记录左上角的位置
		item.leftTopPoint = {
			x: item.left,
			y: item.top
		}
		// 左下
		item.leftBottomPoint = {
			x: item.left,
			y: item.top + item.height
		}
		// 左中
		item.leftMiddlePoint = {
			x: item.left,
			y: item.top + item.height / 2
		}
		// 右中
		item.rightMiddlePoint = {
			x: item.left + item.width,
			y: item.top + item.height / 2
		}
		// 上中
		item.topMiddlePoint = {
			x: item.left + item.width / 2,
			y: item.top
		}
		// 下中
		item.bottomMiddlePoint = {
			x: item.left + item.width / 2,
			y: item.top + item.height
		}
		// 记录中心位置
		item.centerPos = {
			x: item.left + item.width / 2,
			y: item.top + item.height / 2
		}
		item.scaleone = item.width / item.height
		item.initRightBottomPoint = item.rightBottomPoint
		item.initRightTopPoint = item.rightTopPoint
		item.initLeftTopPoint = item.leftTopPoint
		item.initLeftBottomPoint = item.leftBottomPoint
		item.initLeftMiddlePoint = item.leftMiddlePoint
		item.initRightMiddlePoint = item.rightMiddlePoint
		item.initTopMiddlePoint = item.topMiddlePoint
		item.initBottomMiddlePoint = item.bottomMiddlePoint
		item.initCenterPos = item.centerPos
		// 计算角度
		let roat = Math.abs(item.angle) % 360
		if(item.angle < 0){
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		if(roat > 0){
			// 重新计算旋转后四个点的坐标变化
			let disAngle = roat
			item.rightBottomPoint = this.getRotatedPoint(item.initRightBottomPoint, item.centerPos, disAngle)
			item.rightTopPoint = this.getRotatedPoint(item.initRightTopPoint, item.centerPos, disAngle)
			item.leftTopPoint = this.getRotatedPoint(item.initLeftTopPoint, item.centerPos, disAngle)
			item.leftBottomPoint = this.getRotatedPoint(item.initLeftBottomPoint, item.centerPos, disAngle)
			item.leftMiddlePoint = this.getRotatedPoint(item.initLeftMiddlePoint, item.centerPos, disAngle)
			item.rightMiddlePoint = this.getRotatedPoint(item.initRightMiddlePoint, item.centerPos, disAngle)
			item.topMiddlePoint = this.getRotatedPoint(item.initTopMiddlePoint, item.centerPos, disAngle)
			item.bottomMiddlePoint = this.getRotatedPoint(item.initBottomMiddlePoint, item.centerPos, disAngle)
		}
		this.bg_initPos(item)
	},
	bg_initPos(item) {
		// 记录初始盒子位置右下
		item.bg_rightBottomPoint = {
			x: item.width + item.image_left,
			y: item.height + item.image_top
		}
		// 记录初始盒子右上角位置
		item.bg_rightTopPoint = {
			x: item.width + item.image_left,
			y: item.image_top
		}
		// 记录左上角的位置
		item.bg_leftTopPoint = {
			x: item.image_left,
			y: item.image_top
		}
		// 左下
		item.bg_leftBottomPoint = {
			x: item.image_left,
			y: item.image_top + item.height
		}
		// 左中
		item.bg_leftMiddlePoint = {
			x: item.image_left,
			y: item.image_top + item.height / 2
		}
		// 右中
		item.bg_rightMiddlePoint = {
			x: item.image_left + item.width,
			y: item.image_top + item.height / 2
		}
		// 上中
		item.bg_topMiddlePoint = {
			x: item.image_left + item.width / 2,
			y: item.image_top
		}
		// 下中
		item.bg_bottomMiddlePoint = {
			x: item.image_left + item.width / 2,
			y: item.image_top + item.height
		}
		// 记录中心位置
		item.bg_centerPos = {
			x: item.image_left + item.width / 2,
			y: item.top + item.height / 2
		}
		item.bg_scaleone = item.width / item.height
		item.bg_initRightBottomPoint = item.bg_rightBottomPoint
		item.bg_initRightTopPoint = item.bg_rightTopPoint
		item.bg_initLeftTopPoint = item.bg_leftTopPoint
		item.bg_initLeftBottomPoint = item.bg_leftBottomPoint
		item.bg_initLeftMiddlePoint = item.bg_leftMiddlePoint
		item.bg_initRightMiddlePoint = item.bg_rightMiddlePoint
		item.bg_initTopMiddlePoint = item.bg_topMiddlePoint
		item.bg_initBottomMiddlePoint = item.bg_bottomMiddlePoint
		item.bg_initCenterPos = item.bg_centerPos
		// 计算角度
		let roat = Math.abs(item.angle) % 360
		if(item.angle < 0){
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		if(roat > 0){
			// 重新计算旋转后四个点的坐标变化
			let disAngle = roat
			item.bg_rightBottomPoint = this.getRotatedPoint(item.bg_initRightBottomPoint, item.bg_centerPos, disAngle)
			item.bg_rightTopPoint = this.getRotatedPoint(item.bg_initRightTopPoint, item.bg_centerPos, disAngle)
			item.bg_leftTopPoint = this.getRotatedPoint(item.bg_initLeftTopPoint, item.bg_centerPos, disAngle)
			item.bg_leftBottomPoint = this.getRotatedPoint(item.bg_initLeftBottomPoint, item.bg_centerPos, disAngle)
			item.bg_leftMiddlePoint = this.getRotatedPoint(item.bg_initLeftMiddlePoint, item.bg_centerPos, disAngle)
			item.bg_rightMiddlePoint = this.getRotatedPoint(item.bg_initRightMiddlePoint, item.bg_centerPos, disAngle)
			item.bg_topMiddlePoint = this.getRotatedPoint(item.bg_initTopMiddlePoint, item.bg_centerPos, disAngle)
			item.bg_bottomMiddlePoint = this.getRotatedPoint(item.bg_initBottomMiddlePoint, item.bg_centerPos, disAngle)
		}
	},
	/**
	 * @description: 计算移动前坐标值
	 */
	getRotatedPoint(curPos, centerPos, angle) {
		return {
			x: Math.floor((curPos.x - centerPos.x) * Math.cos(Math.PI / 180 * angle) - (curPos.y - centerPos.y) * Math.sin(
				Math.PI / 180 * angle) + centerPos.x),
			y: Math.floor((curPos.x - centerPos.x) * Math.sin(Math.PI / 180 * angle) + (curPos.y - centerPos.y) * Math.cos(
				Math.PI / 180 * angle) + centerPos.y)
		}
	},
	/**
	 * @description: 计算变换后的方框四个角的位置
	 */
	getTransferPosition(left, top, width, height, angle, center,item) {
		// console.log('---------')
		// 计算变换后的方框四个角的位置
		var a1 = {
			x: left,
			y: top
		}
		var a2 = {
			x: left,
			y: top + height
		}
		var a3 = {
			x: left + width,
			y: top
		}
		var a4 = {
			x: left + width,
			y: top + height
		}
		var a5 = {
			x: left,
			y: top + height / 2
		}
		var a6 = {
			x: left + width,
			y: top + height / 2
		}
		var a7 = {
			x: left + width / 2,
			y: top
		}
		var a8 = {
			x: left + width / 2,
			y: top + height
		}
		item.leftTopPoint = this.getRotatedPoint(a1, center, angle)
		item.leftBottomPoint = this.getRotatedPoint(a2, center, angle)
		item.rightTopPoint = this.getRotatedPoint(a3, center, angle)
		item.rightBottomPoint = this.getRotatedPoint(a4, center, angle)
		item.leftMiddlePoint = this.getRotatedPoint(a5, center, angle)
		item.rightMiddlePoint = this.getRotatedPoint(a6, center, angle)
		item.topMiddlePoint = this.getRotatedPoint(a7, center, angle)
		item.bottomMiddlePoint = this.getRotatedPoint(a8, center, angle)
	},
	bg_getTransferPosition(left, top, width, height, angle, center,item) {
		// 计算变换后的方框四个角的位置
		var a1 = {
			x: left,
			y: top
		}
		var a2 = {
			x: left,
			y: top + height
		}
		var a3 = {
			x: left + width,
			y: top
		}
		var a4 = {
			x: left + width,
			y: top + height
		}
		var a5 = {
			x: left,
			y: top + height / 2
		}
		var a6 = {
			x: left + width,
			y: top + height / 2
		}
		var a7 = {
			x: left + width / 2,
			y: top
		}
		var a8 = {
			x: left + width / 2,
			y: top + height
		}
		item.bg_leftTopPoint = this.getRotatedPoint(a1, center, angle)
		item.bg_leftBottomPoint = this.getRotatedPoint(a2, center, angle)
		item.bg_rightTopPoint = this.getRotatedPoint(a3, center, angle)
		item.bg_rightBottomPoint = this.getRotatedPoint(a4, center, angle)
		item.bg_leftMiddlePoint = this.getRotatedPoint(a5, center, angle)
		item.bg_rightMiddlePoint = this.getRotatedPoint(a6, center, angle)
		item.bg_topMiddlePoint = this.getRotatedPoint(a7, center, angle)
		item.bg_bottomMiddlePoint = this.getRotatedPoint(a8, center, angle)
	},
	/**
	 * 计算触摸点到圆心的距离
	 *
	 * @param centerX   圆心的 x 坐标
	 * @param centerY   圆心的 y 坐标
	 * @param x         手点击的 x 坐标
	 * @param y         手点击的 y 坐标
	 * @returns {number}
	 */
	computeDistance: function(centerX, centerY, x, y) {
		var diffX = x - centerX;
		var diffY = y - centerY;
		return Math.sqrt(diffX * diffX + diffY * diffY);
	},
	/**
	 * @description: 初始化targetObj的位置
	 */
	initPosscale(item) {
		item.fontscale = item.fontscale * item.scale
		item.font_size = item.font_size * item.scale
		item.lineheight = item.lineheight * item.scale
		
		item.left = item.left - (item.width * item.scale - item.width) / 2
		item.top = item.top - (item.height * item.scale - item.height) / 2
		item.width = item.width * item.scale
		item.height = item.height * item.scale
		
		item.initialWidth = item.initialWidth * item.scale
		item.initialHeight = item.initialHeight * item.scale
		item.image_top = item.image_top * item.scale
		item.image_left = item.image_left * item.scale
		// 记录初始盒子位置右下
		item.rightBottomPoint = {
			x: item.width + item.left,
			y: item.height + item.top
		}
		// 记录初始盒子右上角位置
		item.rightTopPoint = {
			x: item.width + item.left,
			y: item.top
		}
		// 记录左上角的位置
		item.leftTopPoint = {
			x: item.left,
			y: item.top
		}
		// 左下
		item.leftBottomPoint = {
			x: item.left,
			y: item.top + item.height
		}
		// 左中
		item.leftMiddlePoint = {
			x: item.left,
			y: item.top + item.height / 2
		}
		// 右中
		item.rightMiddlePoint = {
			x: item.left + item.width,
			y: item.top + item.height / 2
		}
		// 上中
		item.topMiddlePoint = {
			x: item.left + item.width / 2,
			y: item.top
		}
		// 下中
		item.bottomMiddlePoint = {
			x: item.left + item.width / 2,
			y: item.top + item.height
		}
		// 记录中心位置
		item.centerPos = {
			x: item.left + item.width / 2,
			y: item.top + item.height / 2
		}
		item.scaleone = item.width / item.height
		item.initRightBottomPoint = item.rightBottomPoint
		item.initRightTopPoint = item.rightTopPoint
		item.initLeftTopPoint = item.leftTopPoint
		item.initLeftBottomPoint = item.leftBottomPoint
		item.initLeftMiddlePoint = item.leftMiddlePoint
		item.initRightMiddlePoint = item.rightMiddlePoint
		item.initTopMiddlePoint = item.topMiddlePoint
		item.initBottomMiddlePoint = item.bottomMiddlePoint
		item.initCenterPos = item.centerPos
		// 计算角度
		let roat = Math.abs(item.angle) % 360
		if(item.angle < 0){
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		if(roat > 0){
			// 重新计算旋转后四个点的坐标变化
			let disAngle = roat
			item.rightBottomPoint = this.getRotatedPoint(item.initRightBottomPoint, item.centerPos, disAngle)
			item.rightTopPoint = this.getRotatedPoint(item.initRightTopPoint, item.centerPos, disAngle)
			item.leftTopPoint = this.getRotatedPoint(item.initLeftTopPoint, item.centerPos, disAngle)
			item.leftBottomPoint = this.getRotatedPoint(item.initLeftBottomPoint, item.centerPos, disAngle)
			item.leftMiddlePoint = this.getRotatedPoint(item.initLeftMiddlePoint, item.centerPos, disAngle)
			item.rightMiddlePoint = this.getRotatedPoint(item.initRightMiddlePoint, item.centerPos, disAngle)
			item.topMiddlePoint = this.getRotatedPoint(item.initTopMiddlePoint, item.centerPos, disAngle)
			item.bottomMiddlePoint = this.getRotatedPoint(item.initBottomMiddlePoint, item.centerPos, disAngle)
		}
	},
	/**
	 * @description: 计算变换后的方框四个角的位置
	 */
	getTransferPositionangle(left, top, width, height, angle, center,item) {
		// 计算变换后的方框四个角的位置
		var a1 = {
			x: left,
			y: top
		}
		var a2 = {
			x: left,
			y: top + height
		}
		var a3 = {
			x: left + width,
			y: top
		}
		var a4 = {
			x: left + width,
			y: top + height
		}
		var a5 = {
			x: left,
			y: top + height / 2
		}
		var a6 = {
			x: left + width,
			y: top + height / 2
		}
		var a7 = {
			x: left + width / 2,
			y: top
		}
		var a8 = {
			x: left + width / 2,
			y: top + height
		}
		item.leftTopPoint = this.getRotatedPoint(a1, center, angle)
		item.leftBottomPoint = this.getRotatedPoint(a2, center, angle)
		item.rightTopPoint = this.getRotatedPoint(a3, center, angle)
		item.rightBottomPoint = this.getRotatedPoint(a4, center, angle)
		item.leftMiddlePoint = this.getRotatedPoint(a5, center, angle)
		item.rightMiddlePoint = this.getRotatedPoint(a6, center, angle)
		item.topMiddlePoint = this.getRotatedPoint(a7, center, angle)
		item.bottomMiddlePoint = this.getRotatedPoint(a8, center, angle)
	},
	/**
	 * 图片拖动中事件
	 */
	dragMove(e,item,data,editor_top){
		//移动时的坐标值也写图片的属性里
		item.moveX = e.touches[0].clientX;
		item.moveY = e.touches[0].clientY;
		//追加改动值
		item.left += item.moveX - item.startX; // x方向
		item.top += item.moveY - item.startY; // y方向
		item.x += item.moveX - item.startX; // 方块圆心
		item.y += item.moveY - item.startY; // 方块圆心
		// 磁性吸附部分
		item.xheart = item.left + (item.width) / 2 // 方块圆心
		item.yheart = item.top + (item.height) / 2 // 方块圆心
		item.heart_startX = e.touches[0].clientX; // 用于恢复startX数据
		item.heart_startY = e.touches[0].clientY; // 用于恢复startY数据
		//属性
		item.active = false //辅助线
		item.activeguide = true //辅助线
		item.activescale = false // 旋转状态
		item.activehorn = false // 角状态
		item.activeedge = false // 边状态
		let roat = Math.abs(item.angle) % 360
		if (item.angle < 0) {
			let multiple = Math.ceil(Math.abs(item.angle) / 360)
			roat = item.angle + multiple * 360
		}
		this.initPos(item)
		// if (item.scale < 1) { // 缩小
		// 	let left_upper = item.xheart + (item.width * item.scale) / 2 // 图层右边靠近辅助线
		// 	let left_lower = item.xheart - (item.width * item.scale) / 2 // 图层左边靠近辅助线
		// 	let top_upper = item.yheart + (item.height * item.scale) / 2 // 图层上边靠近辅助线
		// 	let top_lower = item.yheart - (item.height * item.scale) / 2 // 图层下边靠近辅助线
		// 	if (roat == 90 || roat == 270) {
		// 		item.startX = e.touches[0].clientX;
		// 		item.startY = e.touches[0].clientY;
		// 	} else if (roat == 0 || roat == 180 || roat == 360) {
		// 		/* 左中右磁性吸附 */
		// 		if (left_lower > (data.editorWidth / 2 - 5) && left_lower < (data.editorWidth / 2 + 5)) {
		// 			item.left = data.editorWidth / 2 - (item.width - item.width * item.scale) / 2
		// 		} else if (item.left > ((data.editorWidth - item.width) / 2 - 5) && item.left < ((data.editorWidth -
		// 				item.width) / 2 + 5)) {
		// 			item.left = (data.editorWidth - item.width) / 2
		// 		} else if (left_upper > (data.editorWidth / 2 - 5) && left_upper < (data.editorWidth / 2 + 5)) {
		// 			item.left = data.editorWidth / 2 - item.width + (item.width - item.width * item.scale) / 2
		// 		} else {
		// 			item.startX = e.touches[0].clientX;
		// 		}
		// 		/* 上中下磁性吸附 */
		// 		if (top_lower > editor_top - 5 && top_lower < editor_top + 5) {
		// 			item.top = editor_top - (item.height - item.height * item.scale) / 2
		// 		} else if (item.top > (editor_top - (item.height / 2) - 5) && item.top < (editor_top - (item.height /
		// 				2) + 5)) {
		// 			item.top = editor_top - (item.height / 2)
		// 		} else if (top_upper > (editor_top - 5) && top_upper < (editor_top + 5)) {
		// 			item.top = editor_top - item.height + (item.height - item.height * item.scale) / 2
		// 		} else {
		// 			item.startY = e.touches[0].clientY;
		// 		}
		// 	} else {
		// 		item.startX = e.touches[0].clientX;
		// 		item.startY = e.touches[0].clientY;
		// 	}
		// } else if (item.scale > 1) { // 放大
		// 	let left_upper = item.xheart + (item.width * item.scale) / 2
		// 	let left_lower = item.xheart - (item.width * item.scale) / 2
		// 	let top_upper = item.yheart + (item.height * item.scale) / 2
		// 	let top_lower = item.yheart - (item.height * item.scale) / 2
		// 	if (roat == 90 || roat == 270) {
		// 		item.startX = e.touches[0].clientX;
		// 		item.startY = e.touches[0].clientY;
		// 	} else if (roat == 0 || roat == 180 || roat == 360) {
		// 		//把新的值赋给老的值
		// 		if (left_lower > (data.editorWidth / 2 - 5) && left_lower < (data.editorWidth / 2 + 5)) {
		// 			item.left = data.editorWidth / 2 + (item.width * item.scale - item.width) / 2
		// 		} else if (item.left > ((data.editorWidth - item.width) / 2 - 5) && item.left < ((data.editorWidth -
		// 				item.width) / 2 + 5)) {
		// 			item.left = (data.editorWidth - item.width) / 2
		// 		} else if (left_upper > data.editorWidth / 2 - 5 && left_upper < data.editorWidth / 2 + 5) {
		// 			item.left = data.editorWidth / 2 - item.width * item.scale + (item.width * item.scale - item.width) / 2
		// 		} else {
		// 			item.startX = e.touches[0].clientX;
		// 		}
		// 		if (top_lower > editor_top - 5 && top_lower < editor_top + 5) {
		// 			item.top = editor_top + (item.height * item.scale - item.height) / 2
		// 		} else if (item.top > (editor_top - (item.height / 2) - 5) && item.top < (editor_top - (item.height /
		// 				2) + 5)) {
		// 			item.top = editor_top - (item.height / 2)
		// 		} else if (top_upper > (editor_top - 5) && top_upper < (editor_top + 5)) {
		// 			item.top = editor_top - item.height * item.scale + (item.height * item.scale - item.height) / 2
		// 		} else {
		// 			item.startY = e.touches[0].clientY;
		// 		}
		// 	} else {
		// 		item.startX = e.touches[0].clientX;
		// 		item.startY = e.touches[0].clientY;
		// 	}
		// } else {
			
			if (roat == 90 || roat == 270) {
				item.startX = e.touches[0].clientX;
				item.startY = e.touches[0].clientY;
				// if(item.xheart - item.height / 2 > (data.editorWidth / 2 - 5) && item.xheart - item.height / 2 < (data.editorWidth / 2 + 5)){
				// 	/* 左侧磁性吸附 */
				// 	item.left = data.editorWidth / 2 - (item.width - item.height)/2
				// }else if(item.left > ((data.editorWidth - item.width) / 2 - 5) && item.left < ((data.editorWidth - item.width) / 2 + 5)){
				// 	/* 居中磁性吸附 */
				// 	item.left = (data.editorWidth - item.width) / 2
				// }else if(item.xheart - item.height / 2 > (data.editorWidth / 2 - item.height - 5) && item.left < (data.editorWidth / 2 - item.height + 5)){
				// 	/* 右侧磁性吸附 */
				// 	// item.left = data.editorWidth / 2 - item.height -  (item.width - item.height)/2
				// }else{
				// 	item.startX = e.touches[0].clientX;
				// }
		
				// if(item.top > editor_top - 5 && item.top < editor_top + 5){
				// 	/* 左侧磁性吸附 */
				// 	item.top = editor_top
				// }else if(item.top > (editor_top - (item.height / 2) - 5) && item.top < (editor_top - (item.height / 2 )+ 5)){
				// 	/* 居中磁性吸附 */
				// 	item.top = editor_top - (item.height / 2)
				// }else if(item.top > (editor_top - item.height - 5) && item.top < (editor_top - item.height + 5)){
				// 	/* 右侧磁性吸附 */
				// 	item.top = editor_top - item.height
				// }else if(item.top > - 5 && item.top < 5){
				// 	// 上边框
				// 	item.top = 0
				// }else if(item.top > data.editorHeight - item.height - 5 && item.top <  data.editorHeight - item.height + 5){
				// 	// 下边框
				// 	item.top = data.editorHeight - item.height
				// }else{
				// 	item.startY = e.touches[0].clientY;
				// }
				
			} else if (roat == 0 || roat == 180 || roat == 360) {
				
				if (item.left > (data.editorWidth / 2 - 5) && item.left < (data.editorWidth / 2 + 5)) {
					/* 辅助线左侧磁性吸附 */
					item.left = data.editorWidth / 2
				} else if (item.left > ((data.editorWidth - item.width) / 2 - 5) && item.left < ((data.editorWidth -item.width) / 2 + 5)) {
					/* 辅助线居中磁性吸附 */
					item.left = (data.editorWidth - item.width) / 2
					wx.vibrateShort(); // 使手机振动15ms
				} else if (item.left > (data.editorWidth / 2 - item.width - 5) && item.left < (data.editorWidth / 2 -item.width + 5)) {
					/* 辅助线右侧磁性吸附 */
					item.left = data.editorWidth / 2 - item.width
				} else if (item.left > -5 && item.left < 5) {
					// 裁剪区左边框磁性吸附
					item.left = 0
				} else if (item.left > data.editorWidth - item.width - 5 && item.left < data.editorWidth - item.width +5) {
					// 裁剪区右边框磁性吸附
					item.left = data.editorWidth - item.width
				} else {
					item.startX = e.touches[0].clientX;
				}
				
				if (item.top > editor_top - 5 && item.top < editor_top + 5) {
					/* 辅助线上边框磁性吸附 */
					item.top = editor_top
				} else if (item.top > (editor_top - (item.height / 2) - 5) && item.top < (editor_top - (item.height /2) + 5)) {
					/* 辅助线居中磁性吸附 */
					item.top = editor_top - (item.height / 2)
					wx.vibrateShort(); // 使手机振动15ms
				} else if (item.top > (editor_top - item.height - 5) && item.top < (editor_top - item.height + 5)) {
					/* 辅助线下边框磁性吸附 */
					item.top = editor_top - item.height
				} else if (item.top > -5 && item.top < 5) {
					// 裁剪区上边框磁性吸附
					item.top = 0
				} else if (item.top > data.editorHeight - item.height - 5 && item.top < data.editorHeight - item.height +5) {
					// 裁剪区下边框磁性吸附
					item.top = data.editorHeight - item.height
				} else {
					item.startY = e.touches[0].clientY;
				}
			} else {
				item.startX = e.touches[0].clientX;
				item.startY = e.touches[0].clientY;
			}
		// }
	},
}

export default drag