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){
					// 修改初始化原始图片比率-坐标
					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) {
		
		if(item == null){
			//this.bg_initPos(item)
			return
		}
		// 记录初始盒子位置右下
		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
