index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. for (let [index, item] of res.data.entries()) {
  48. item.id = index
  49. }
  50. that.$set(that, `markers`, res.data);
  51. } else {
  52. uni.showToast({
  53. title: res.errmsg,
  54. icon: 'none'
  55. })
  56. }
  57. },
  58. // 点击标记点对应的气泡 播放多种语音类型的讲解
  59. async toTap(e) {
  60. const that = this;
  61. const markerId = e.detail.markerId
  62. const marker = that.markers[markerId]
  63. let src;
  64. if (marker && marker.audio && marker.audio.length > 0) src = marker?.audio[0]?.url
  65. innerAudioContext.destroy(); //销毁这个实例
  66. innerAudioContext = uni.createInnerAudioContext();
  67. innerAudioContext.autoplay = true;
  68. innerAudioContext.sessionCategory = "soloAmbient"
  69. innerAudioContext.src = src
  70. innerAudioContext.onPlay(() => {
  71. console.log('开始播放');
  72. });
  73. innerAudioContext.onError((res) => {
  74. uni.showToast({
  75. title: res.errMsg,
  76. icon: 'error',
  77. duration: 2000
  78. });
  79. });
  80. },
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .main {
  86. display: flex;
  87. flex-direction: column;
  88. width: 100vw;
  89. height: 100vh;
  90. .map {
  91. width: 100%;
  92. height: 100vh;
  93. .button {
  94. background-color: var(--f3CColor);
  95. }
  96. }
  97. }
  98. </style>