index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="main">
  3. <map class="map" :latitude="config.latitude" :longitude="config.longitude" :scale="config.scale"
  4. :markers="markers" @callouttap="toTap"></map>
  5. </view>
  6. </template>
  7. <script>
  8. let innerAudioContext = uni.createInnerAudioContext();
  9. export default {
  10. data() {
  11. return {
  12. config: {},
  13. markers: []
  14. }
  15. },
  16. onShow: async function() {
  17. const that = this;
  18. that.searchConfig();
  19. that.search();
  20. },
  21. onHide: function(e) {
  22. innerAudioContext.destroy(); //销毁这个实例
  23. },
  24. methods: {
  25. async searchConfig() {
  26. const that = this;
  27. const res = await that.$api(`/config`, 'GET', {})
  28. if (res.errcode == '0') {
  29. that.$set(that, `config`, res.data)
  30. } else {
  31. uni.showToast({
  32. title: res.errmsg,
  33. });
  34. }
  35. },
  36. // 查询
  37. async search() {
  38. const that = this;
  39. let info = {
  40. is_use: '0',
  41. }
  42. let res;
  43. res = await that.$api(`/map`, 'GET', {
  44. ...info,
  45. });
  46. if (res.errcode == '0') {
  47. that.$set(that, `markers`, res.data);
  48. } else {
  49. uni.showToast({
  50. title: res.errmsg,
  51. icon: 'none'
  52. })
  53. }
  54. },
  55. // 点击标记点对应的气泡 播放多种语音类型的讲解
  56. toTap(e) {
  57. const that = this;
  58. const markerId = e.detail.markerId.toString()
  59. const index = markerId.substr(markerId.length - 1)
  60. const marker = that.markers[index]
  61. let src;
  62. if (marker.audio.length > 0) src = marker.audio[0].url
  63. innerAudioContext.destroy(); //销毁这个实例
  64. innerAudioContext = uni.createInnerAudioContext();
  65. innerAudioContext.autoplay = true;
  66. innerAudioContext.sessionCategory = "soloAmbient"
  67. innerAudioContext.src = src
  68. innerAudioContext.onPlay(() => {
  69. console.log('开始播放');
  70. });
  71. innerAudioContext.onError((res) => {
  72. uni.showToast({
  73. title: res.errMsg,
  74. icon: 'error',
  75. duration: 2000
  76. });
  77. });
  78. },
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .main {
  84. display: flex;
  85. flex-direction: column;
  86. width: 100vw;
  87. height: 100vh;
  88. .map {
  89. width: 100%;
  90. height: 100vh;
  91. .button {
  92. background-color: var(--f3CColor);
  93. }
  94. }
  95. }
  96. </style>