index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/logo.png"></image>
  4. <view class="text-area">
  5. <text class="title">{{title}}</text>
  6. </view>
  7. <view class="pages-bt" @click.stop="onMuLocation">
  8. 获取定位
  9. </view>
  10. <view class="">{{Position}}</view>
  11. <view class="pages-bt" style="margin-top: 50px;" @click.stop="showRecorder ? recStop():recReq()">
  12. {{showRecorder ? '停止录音':'开始录音'}}
  13. </view>
  14. {{audioUrl}}
  15. <audio :src="audioUrl" controls></audio>
  16. <mumu-getlocation ref='muLocation'></mumu-getlocation>
  17. </view>
  18. </template>
  19. <script>
  20. import mumuGetlocation from '@/uni_modules/mumu-getlocation/components/mumu-getlocation/mumu-getlocation.vue'
  21. import H5Recorder from "@/pages/task/components/H5Recorder.js"
  22. export default {
  23. mixins: [H5Recorder],
  24. components: { mumuGetlocation },
  25. data() {
  26. return {
  27. title: 'Hello',
  28. Position: "",
  29. showRecorder: false,
  30. audioUrl: "",
  31. }
  32. },
  33. onLoad() {
  34. },
  35. methods: {
  36. onMuLocation() {
  37. uni.showLoading({
  38. title: '获取定位中...',
  39. mask: true
  40. })
  41. // 初始化组件,并且检测是否开启与授权定位
  42. this.$refs.muLocation.__init().then(location => {
  43. // 用户授权了和开启了定位,把定位对象保存到 data 中
  44. // this.locationRef = location
  45. // 调用 getLocation 方法获取精准定位
  46. location.getLocation().then(res => {
  47. console.log('location', res);
  48. try {
  49. const { province, city, district, addr } = res || {}
  50. this.Position = `${province}${city}${district}${addr}`;
  51. } catch (e) {
  52. //TODO handle the exception
  53. }
  54. // res 就是返回的数据
  55. // uni.showModal({
  56. // content: JSON.stringify(res, null, 4)
  57. // })
  58. })
  59. uni.hideLoading()
  60. }, err => {
  61. // 用户拒绝了定位请求,获取系统没有开启定位功能
  62. uni.hideLoading()
  63. if (err.code === 1) {
  64. uni.showModal({
  65. title: '获取定位权限失败',
  66. content: '你拒绝了位置授权服务。请允许当前页面获取定位授权,后刷新页面。'
  67. })
  68. } else {
  69. uni.showModal({
  70. title: '获取定位权限失败',
  71. content: '请确定手机定位已打开,并且当前浏览器允许获取定位,都开启后请刷新页面。'
  72. })
  73. }
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style>
  80. .content {
  81. display: flex;
  82. flex-direction: column;
  83. align-items: center;
  84. justify-content: center;
  85. }
  86. .logo {
  87. height: 200rpx;
  88. width: 200rpx;
  89. margin-top: 200rpx;
  90. margin-left: auto;
  91. margin-right: auto;
  92. margin-bottom: 50rpx;
  93. }
  94. .text-area {
  95. display: flex;
  96. justify-content: center;
  97. }
  98. .title {
  99. font-size: 36rpx;
  100. color: #8f8f94;
  101. }
  102. .pages-bt {
  103. background-color: #ccc;
  104. }
  105. </style>