Blame view

pages/API/on-compass-change/on-compass-change.vue 1.64 KB
4b045f7c   刘淇   江阴初始化项目
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
  <template>
  	<view>
  		<page-head :title="title"></page-head>
  		<view class="uni-padding-wrap">
  			<view class="uni-hello-text uni-center" style="padding-bottom:50rpx;">
  				旋转手机即可获取方位信息
  			</view>
  			<view class="direction">
  				<view class="bg-compass-line"></view>
  				<image class="bg-compass" src="../../../static/compass.png" :style="'transform: rotate('+direction+'deg)'"></image>
  				<view class="direction-value">
  					<text>{{direction}}</text>
  					<text class="direction-degree">o</text>
  				</view>
  			</view>
  		</view>
  	</view>
  </template>
  <script>
  	export default {
  		data() {
  			return {
  				title: 'onCompassChange',
  				direction: 0
  			}
  		},
  		onReady: function () {
  			uni.onCompassChange((res) => {
  				this.direction = parseInt(res.direction)
  			})
  		},
  		onUnload() {
  			// #ifndef MP-ALIPAY
  			uni.stopCompass();
  			this.direction = 0;
  			// #endif
  
  			// #ifdef MP-ALIPAY
  			uni.offCompassChange();
  			// #endif
  		}
  	}
  </script>
  
  <style>
  	.direction {
  		position: relative;
  		margin-top: 70rpx;
  		display: flex;
  		width: 540rpx;
  		height: 540rpx;
  		align-items: center;
  		justify-content: center;
  		margin:0 auto;
  	}
  
  	.direction-value {
  		position: relative;
  		font-size: 200rpx;
  		color: #353535;
  		line-height: 1;
  		z-index: 1;
  	}
  
  	.direction-degree {
  		position: absolute;
  		top: 0;
  		right: -40rpx;
  		font-size: 60rpx;
  	}
  
  	.bg-compass {
  		position: absolute;
  		top: 0;
  		left: 0;
  		width: 540rpx;
  		height: 540rpx;
  		transition: .1s;
  	}
  
  	.bg-compass-line {
  		position: absolute;
  		left: 267rpx;
  		top: -10rpx;
  		width: 6rpx;
  		height: 56rpx;
  		background-color: #1AAD19;
  		border-radius: 999rpx;
  		z-index: 1;
  	}
  </style>