Blame view
src/platforms/app-plus/orientation/orientation.vue
1.52 KB
289f85d9e 提交 |
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 |
<template> <view> <page-head :title="title"></page-head> <view class="uni-padding-wrap uni-common-mt"> <view class="uni-btn-v"> <button type="primary" @tap="getOrient">获取设备的方向信息</button> <button type="primary" @tap="watchOrient">监听设备的方向变化</button> <button type="primary" @tap="watchStop">停止监听</button> </view> <view class="uni-textarea"> <textarea :value="value" /> </view> </view> </view> </template> <script> var id = null export default { data() { return { title: 'orientation', value: '' } }, methods: { getOrient: function () { var that = this; plus.orientation.getCurrentOrientation(function (o) { that.value = "alpha:" + o.alpha + " beta:" + o.beta + " gamma:" + o.gamma; }, function (e) { console.log("获取失败:" + e.message); }); }, watchOrient: function () { var that = this; if (id) { return; } id = plus.orientation.watchOrientation(function (o) { that.value = "监听设备方向变化信息 " + "alpha:" + o.alpha + " beta:" + o.beta + " gamma:" + o.gamma; }, function (e) { plus.orientation.clearWatch(id); id = null; console.log("监听失败:" + e.message); }); }, watchStop: function () { if (id) { plus.orientation.clearWatch(id); id = null; } else { console.log("没有监听设备方向变化"); } } } } </script> <style> </style> |