Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

肖康 / H5_2.0

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • H5_2.0
  • components
  • drag-button-follow
  • drag-button-follow.vue
drag-button-follow.vue 5.78 KB
肖康's avatar
first init
ddbafbda
 
肖康 committed 2 years ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<template>
	<view <!-- #ifndef MP-WEIXIN -->
		:style="{
		transform: `translate(${offsetX}px, ${offsetY}px)`,
		MsTransform: `translate(${offsetX}px, ${offsetY}px)`,
		MozTransform: `translate(${offsetX}px, ${offsetY}px)`,
		WebkitTransform: `translate(${offsetX}px, ${offsetY}px)`,
		OTransform: `translate(${offsetX}px, ${offsetY}px)`,
		transition: move ? 'none' : 'transform 0.2s ease-in-out',
		MsTransition: move ? 'none' : 'transform 0.2s ease-in-out',
		MozTransition: move ? 'none' : 'transform 0.2s ease-in-out',
		WebkitTransition: move ? 'none' : 'transform 0.2s ease-in-out',
		OTransition: move ? 'none' : 'transform 0.2s ease-in-out'
		}"
		<!-- #endif -->
		@click.stop="click"
		@touchmove.stop.prevent="touchmove"
		@touchstart="touchstart"
		@touchend="touchend"
		>
肖康's avatar
首页 修改
e6f67aee
 
肖康 committed a year ago
21
		<a class="navxfbox25" :href="url" target="_balnk">
肖康's avatar
first init
ddbafbda
 
肖康 committed 2 years ago
22 23 24
			<text class="icon iconfont icon-qq icon-qqnavxf"></text>
			<view class="texttmavsk">QQ</view>
			<view class="texttmavsk">咨询</view>
肖康's avatar
首页 修改
e6f67aee
 
肖康 committed a year ago
25
		</a>
肖康's avatar
first init
ddbafbda
 
肖康 committed 2 years ago
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
		<slot>

		</slot>
	</view>
</template>

<script>
	export default {
		name: 'DragButtonFollow',
		props: {
			className: {
				type: String,
				default: ''
			},
			// #ifdef MP-WEIXIN
			style: {
				type: String,
				default: ''
			},
			// #endif
			drag: {
				type: Boolean,
				default: true
			},
肖康's avatar
首页 修改
e6f67aee
 
肖康 committed a year ago
50 51 52 53 54
			url: {
				type: String,
				default: ''
			},
			
肖康's avatar
first init
ddbafbda
 
肖康 committed 2 years ago
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
			follow: {
				type: String | Boolean,
				default: 'all'
			},
			followNum: {
				type: Number,
				default: 0
			}
		},
		safeArea: {},
		data() {
			return {
				offsetX: 0,
				offsetY: 0,
				width: 0,
				height: 0,
				left: 0,
				top: 0,
				move: false,
				foll: {

				}
			}
		},
		mounted() {
			const systemInfo = uni.getSystemInfoSync() || {}
			this.$options.safeArea = {
				left: 0,
				top: 0,
				right: systemInfo.windowWidth,
				bottom: systemInfo.windowHeight
			}
			const query = this.$parent.createSelectorQuery()
			query.select(`.${this.className}`).boundingClientRect(data => {
				if (data) {
					this.width = data.width
					this.height = data.height
					this.left = data.left
					this.top = data.top
				}
			}).exec()
			if (this.follow) {
				const type = this.follow.split(",")
				let isLeft, isRight, isTop, isBottom, isAll, num
				type.forEach(_ => {
					if (_ === 'all') isAll = true
					if (_ === 'left') isLeft = true
					if (_ === 'right') isRight = true
					if (_ === 'top') isTop = true
					if (_ === 'bottom') isBottom = true
				})
				if (isAll) isLeft = isRight = isTop = isBottom = true
				num = Math.round(this.width * this.followNum / 100)
				this.foll = {
					isLeft,
					isRight,
					isTop,
					isBottom,
					num
				}
			}
		},
		methods: {
			click() {
				this.$emit('btnClick');
			},
			touchstart(e) {
				if (!this.drag) return
				this.move = true
			},
			touchmove(e) {
				if (!this.drag) return
				if (!this.move) return
				const {
					left,
					right,
					top,
					bottom
				} = this.$options.safeArea
				const dot = e.changedTouches[0]
				if (dot.clientX < left + this.width / 2) dot.clientX = left + this.width / 2
				if (dot.clientX > right - this.width / 2) dot.clientX = right - this.width / 2
				if (dot.clientY < top + this.height / 2) dot.clientY = top + this.height / 2
				if (dot.clientY > bottom - this.height / 2) dot.clientY = bottom - this.height / 2
				this.offsetX = dot.clientX - this.left - this.width / 2
				this.offsetY = dot.clientY - this.top - this.height / 2
				// #ifdef MP-WEIXIN
				this.$emit("update:style", `
					transform: translate(${this.offsetX}px, ${this.offsetY}px);
					WebkitTransform: translate(${this.offsetX}px, ${this.offsetY}px);
					transition: ${this.move ? 'none' : 'transform 0.2s ease-in-out'};
					WebkitTransition: ${this.move ? 'none' : 'transform 0.2s ease-in-out'};
				`)
				// #endif
			},
			touchend(e) {
				if (!this.drag) return
				this.move = false
				if (!this.follow) return
				const dot = e.changedTouches[0]
				const {
					left,
					right,
					top,
					bottom
				} = this.$options.safeArea
				if (this.foll.isLeft && this.foll.isRight) {
					if (dot.clientX <= (left + right) / 2) this.offsetX = this.foll.num - this.left
					if (dot.clientX > (left + right) / 2) this.offsetX = right - this.width - this.foll.num - this.left
				} else if (this.foll.isLeft) {
					this.offsetX = this.foll.num - this.left
				} else if (this.foll.isRight) {
					this.offsetX = right - this.width - this.foll.num - this.left
				}
				if (this.foll.isTop && this.foll.isBottom) {
					if (dot.clientY <= (top + bottom) / 2) this.offsetY = this.foll.num - this.top
					if (dot.clientY > (top + bottom) / 2) this.offsetY = bottom - this.height - this.foll.num - this.top
				} else if (this.foll.isTop) {
					this.offsetY = this.foll.num - this.top
				} else if (this.foll.isBottom) {
					this.offsetY = bottom - this.height - this.foll.num - this.top
				}
				// #ifdef MP-WEIXIN
				this.$emit("update:style", `
					transform: translate(${this.offsetX}px, ${this.offsetY}px);
					WebkitTransform: translate(${this.offsetX}px, ${this.offsetY}px);
					transition: ${this.move ? 'none' : 'transform 0.2s ease-in-out'};
					WebkitTransition: ${this.move ? 'none' : 'transform 0.2s ease-in-out'};
				`)
				// #endif
			},
		}
	}
</script>
<style scoped>
	/* #ifdef MP-WEIXIN */
	view {
		height: 100%;
		width: 100%;
		display: inherit;
		justify-content: inherit;
		align-items: inherit;
	}

	/* #endif */
	.drag-button {
		width: 68rpx;
		height: 130rpx;
		background: #1969F9;
		border-radius: 10rpx;
		position: fixed;
		left: 0px;
		top: 50%;
		z-index: 777;

	}

	.navxfbox25 {
		width: 68rpx;
		height: 130rpx;
		text-align: center;
		padding-top: 16rpx;
		box-sizing: border-box;
		display: block;
		text-decoration: none;

	}

	.icon-qqnavxf {
		font-size: 48rpx;
		color: #fff;
	}

	.texttmavsk {
		font-size: 20rpx;
		color: #fff;
		height: 24rpx;
		line-height: 24rpx;
	}
</style>