hookehuyr

fix 完善浮动窗口显示逻辑

1 <!-- 1 <!--
2 * @Date: 2024-09-15 22:08:49 2 * @Date: 2024-09-15 22:08:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-09-18 14:17:43 4 + * @LastEditTime: 2024-09-18 16:39:55
5 * @FilePath: /map-demo/src/views/bieyuan/info.vue 5 * @FilePath: /map-demo/src/views/bieyuan/info.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -47,9 +47,11 @@ ...@@ -47,9 +47,11 @@
47 <div style="color: #47525F; margin-top: 1rem;">静心咖啡绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍</div> 47 <div style="color: #47525F; margin-top: 1rem;">静心咖啡绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍介绍</div>
48 </div> 48 </div>
49 <div class="audio-wrapper"> 49 <div class="audio-wrapper">
50 - <div @click="playAudio(item, index)" :class="['audio-item', play_audio_index === index ? 'click' : '']" v-for="(item, index) in audioList" :key="index"> 50 + <div :class="['audio-item', play_audio_index === index ? 'click' : '']" v-for="(item, index) in audioList" :key="index">
51 <div>{{ item.text }}</div> 51 <div>{{ item.text }}</div>
52 - <div :class="['audio-icon', play_audio_index === index ? 'click' : '']"></div> 52 + <!-- <div :class="['audio-icon', play_audio_index === index ? 'click' : '']"></div> -->
53 + <van-icon @click="stopAudio(item, index)" v-if="item.play" size="2rem" name="stop-circle-o" color="#DD7850" />
54 + <van-icon v-else @click="playAudio(item, index)" size="2rem" name="https://cdn.ipadbiz.cn/bieyuan/map/icon/audio_icon.png" />
53 </div> 55 </div>
54 </div> 56 </div>
55 <div style="width: 100%;"> 57 <div style="width: 100%;">
...@@ -105,14 +107,16 @@ const audioList = ref([{ ...@@ -105,14 +107,16 @@ const audioList = ref([{
105 play: false, 107 play: false,
106 }]) 108 }])
107 109
108 -const playAudio = ({src}, index) => { 110 +const playAudio = (item, index) => {
109 - audio.value.src = src; 111 + audioList.value.forEach(item => item.play = false);
112 + audio.value.src = item.src;
110 play_audio_index.value = index; 113 play_audio_index.value = index;
111 let play_status = audio.value.play() // 播放 114 let play_status = audio.value.play() // 播放
112 if (play_status) { 115 if (play_status) {
113 console.warn('start'); 116 console.warn('start');
114 play_status.then(() => { 117 play_status.then(() => {
115 console.warn('success'); 118 console.warn('success');
119 + item.play = true;
116 }).catch((e) => { 120 }).catch((e) => {
117 // 失败 121 // 失败
118 console.log('Operation is too fast, audio play fails') 122 console.log('Operation is too fast, audio play fails')
...@@ -120,11 +124,24 @@ const playAudio = ({src}, index) => { ...@@ -120,11 +124,24 @@ const playAudio = ({src}, index) => {
120 } 124 }
121 } 125 }
122 126
127 +const stopAudio = (item, index) => {
128 + item.play = false;
129 + audio.value.pause();
130 +}
131 +
123 const audio = ref(new Audio()); 132 const audio = ref(new Audio());
124 133
125 const audio_play = (src, index) => { 134 const audio_play = (src, index) => {
126 audio.value.src = src; 135 audio.value.src = src;
127 } 136 }
137 +
138 +const outerStopAudio = () => {
139 + audio.value.pause();
140 +}
141 +
142 +defineExpose({
143 + outerStopAudio
144 +})
128 </script> 145 </script>
129 146
130 <style lang="less"> 147 <style lang="less">
......
1 <!-- 1 <!--
2 * @Date: 2023-05-19 14:54:27 2 * @Date: 2023-05-19 14:54:27
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-09-18 09:49:17 4 + * @LastEditTime: 2024-09-18 16:43:00
5 * @FilePath: /map-demo/src/views/bieyuan/map.vue 5 * @FilePath: /map-demo/src/views/bieyuan/map.vue
6 * @Description: 公众地图主体页面 6 * @Description: 公众地图主体页面
7 --> 7 -->
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
19 19
20 <van-config-provider :theme-vars="themeVars"> 20 <van-config-provider :theme-vars="themeVars">
21 <van-floating-panel v-model:height="info_height" :anchors="anchors" @height-change="onHeightChange"> 21 <van-floating-panel v-model:height="info_height" :anchors="anchors" @height-change="onHeightChange">
22 - <page-info></page-info> 22 + <page-info ref="pageInfo"></page-info>
23 + <div v-if="showClose" @click="closeFloatPanel" class="close-float-panel">
24 + <van-icon name="cross" color="#FFF" size="1.5rem" />
25 + </div>
23 </van-floating-panel> 26 </van-floating-panel>
24 </van-config-provider> 27 </van-config-provider>
25 </div> 28 </div>
...@@ -116,10 +119,11 @@ export default { ...@@ -116,10 +119,11 @@ export default {
116 data_paths: {}, // 接口获取-地图导航路径 119 data_paths: {}, // 接口获取-地图导航路径
117 data_path_list: [], // 接口获取-地图导航路径 120 data_path_list: [], // 接口获取-地图导航路径
118 info_height: 0, 121 info_height: 0,
119 - anchors: [0, Math.round(0.4 * window.innerHeight), Math.round(1 * window.innerHeight)], 122 + anchors: [0, (0.5 * window.innerHeight), (1 * window.innerHeight)],
120 themeVars: { 123 themeVars: {
121 floatingPanelHeaderHeight: 0, 124 floatingPanelHeaderHeight: 0,
122 - } 125 + },
126 + showClose: false,
123 } 127 }
124 }, 128 },
125 async mounted() { 129 async mounted() {
...@@ -162,9 +166,11 @@ export default { ...@@ -162,9 +166,11 @@ export default {
162 // 设置贴片地图 166 // 设置贴片地图
163 this.setTitleLayer(); 167 this.setTitleLayer();
164 // 168 //
165 - setTimeout(() => { 169 + // setTimeout(() => {
166 - this.info_height = Math.round(0.4 * window.innerHeight); 170 + // this.info_height = (0.5 * window.innerHeight);
167 - }, 2000); 171 + // // 浮动面板样式
172 + // $('.van-floating-panel__content').css('borderRadius', '1rem');
173 + // }, 2000);
168 }, 174 },
169 watch: { 175 watch: {
170 }, 176 },
...@@ -211,7 +217,7 @@ export default { ...@@ -211,7 +217,7 @@ export default {
211 marker_icon = entity_info[i].icon; 217 marker_icon = entity_info[i].icon;
212 } 218 }
213 if (entity_info[i]?.writing_mode === 'vertical') { // 标题文字垂直 219 if (entity_info[i]?.writing_mode === 'vertical') { // 标题文字垂直
214 - var textMarker = new AMap.Text({ 220 + let textMarker = new AMap.Text({
215 zooms: [18, 20], // 点标记显示的层级范围,超过范围不显示。 221 zooms: [18, 20], // 点标记显示的层级范围,超过范围不显示。
216 text: entity_info[i].name, //标记显示的文本内容 222 text: entity_info[i].name, //标记显示的文本内容
217 anchor: "center", //设置文本标记锚点位置 223 anchor: "center", //设置文本标记锚点位置
...@@ -222,8 +228,8 @@ export default { ...@@ -222,8 +228,8 @@ export default {
222 //设置文本样式,Object 同 css 样式表 228 //设置文本样式,Object 同 css 样式表
223 "padding": ".5rem .2rem .5rem .2rem", 229 "padding": ".5rem .2rem .5rem .2rem",
224 // "margin-bottom": "1rem", 230 // "margin-bottom": "1rem",
225 - // "border-radius": ".25rem", 231 + "border-radius": ".25rem",
226 - "background-color": "#965f13", 232 + "background-color": "#DD7850",
227 // "width": "1rem", 233 // "width": "1rem",
228 // "border-width": 0, 234 // "border-width": 0,
229 // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)", 235 // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)",
...@@ -238,38 +244,72 @@ export default { ...@@ -238,38 +244,72 @@ export default {
238 }, 244 },
239 position: entity_info[i].position, //点标记在地图上显示的位置 245 position: entity_info[i].position, //点标记在地图上显示的位置
240 }); 246 });
247 + textMarker.setMap(this.map); //将文本标记设置到地图上
248 + this.markerSum.push(textMarker);
241 if (clickListener1) { 249 if (clickListener1) {
242 textMarker.off('click', clickListener) 250 textMarker.off('click', clickListener)
243 } 251 }
244 // 绑定景点的点击事件 - 文字出现才能触发 252 // 绑定景点的点击事件 - 文字出现才能触发
245 var clickListener1 = textMarker.on('click', (e) => { 253 var clickListener1 = textMarker.on('click', (e) => {
246 - // console.warn(e); 254 + // 还原样式
247 - this.itemInfo = entity_info[i]; 255 + this.markerSum.forEach(item => {
248 - // 不同弹框类型 256 + if (e.target.hS !== item.hS) {
249 - // if (entity_info[i].window_type === 'normal') { 257 + // 修改文本的样式
250 - // this.showInfoPopup = true; 258 + item.setStyle({
251 - // } else if (entity_info[i].window_type === 'lite') { 259 + //设置文本样式,Object 同 css 样式表
252 - // this.showInfoLitePopup = true; 260 + "padding": ".5rem .2rem .5rem .2rem",
253 - // } else if (entity_info[i].window_type === 'warn') { 261 + // "margin-bottom": "1rem",
254 - // this.showInfoWarnPopup = true; 262 + "border-radius": ".25rem",
255 - // } 263 + "background-color": "#DD7850",
264 + // "width": "1rem",
265 + // "border-width": 0,
266 + // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)",
267 + // "text-align": "center",
268 + "font-size": "0.8rem",
269 + "color": "white",
270 + "writing-mode": "vertical-rl",
271 + "text-orientation": "mixed",
272 + "display": "flex",
273 + "justify-content": "center",
274 + "align-items": "center",
275 + });
276 + }
277 + })
256 // 修改文本的样式 278 // 修改文本的样式
257 - textMarker.setStyle({ 279 + e.target.setStyle({
258 - 'font-size': '20px', // 修改字体大小 280 + //设置文本样式,Object 同 css 样式表
259 - 'color': '#ff0000', // 修改字体颜色 281 + "padding": ".5rem .2rem .5rem .2rem",
260 - 'background-color': '#0000ff', // 修改背景颜色 282 + // "margin-bottom": "1rem",
261 - 'border': '1px solid #fff', // 增加边框 283 + "border-color": "#DD7850",
262 - 'padding': '10px', // 调整内边距 284 + "border-radius": ".25rem",
263 - 'border-radius': '10px' // 调整圆角 285 + "background-color": "#FFF",
286 + // "width": "1rem",
287 + // "border-width": 0,
288 + // "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)",
289 + // "text-align": "center",
290 + "font-size": "0.8rem",
291 + "color": "#DD7850",
292 + "writing-mode": "vertical-rl",
293 + "text-orientation": "mixed",
294 + "display": "flex",
295 + "justify-content": "center",
296 + "align-items": "center",
264 }); 297 });
265 298
266 // 修改文本内容 299 // 修改文本内容
267 - textMarker.setText('样式已修改'); 300 + // textMarker.setText('样式已修改');
301 + //
302 +
303 + // console.warn(e);
304 + this.itemInfo = entity_info[i];
305 +
306 + // 打开浮动面板
307 + this.info_height = (0.5 * window.innerHeight);
308 + // 浮动面板样式
309 + $('.van-floating-panel__content').css('borderRadius', '1rem');
268 }) 310 })
269 - textMarker.setMap(this.map); //将文本标记设置到地图上
270 - this.markerSum.push(textMarker);
271 } 311 }
272 - }) 312 + });
273 this.map.add(this.markerSum); 313 this.map.add(this.markerSum);
274 }, 314 },
275 isPointInRing() { // 是否在景区范围 315 isPointInRing() { // 是否在景区范围
...@@ -533,8 +573,22 @@ export default { ...@@ -533,8 +573,22 @@ export default {
533 // path: '/bieyuan/scan' 573 // path: '/bieyuan/scan'
534 // }) 574 // })
535 }, 575 },
536 - onHeightChange ({ height }) { 576 + onHeightChange ({ height }) { // 监听浮动面板高度变化
537 - console.warn('拖动完成', height); 577 + if (height === window.innerHeight) {
578 + // 浮动面板样式
579 + $('.van-floating-panel__content').css('borderRadius', '0');
580 + this.showClose = true;
581 + } else {
582 + $('.van-floating-panel__content').css('borderRadius', '1rem');
583 + this.showClose = false;
584 + }
585 + },
586 + closeFloatPanel () {
587 + this.info_height = (0.5 * window.innerHeight);
588 + $('.van-floating-panel__content').css('borderRadius', '1rem');
589 + this.showClose = false;
590 + // 关闭音频
591 + this.$refs.pageInfo.outerStopAudio();
538 } 592 }
539 } 593 }
540 } 594 }
...@@ -716,4 +770,10 @@ export default { ...@@ -716,4 +770,10 @@ export default {
716 padding: 5px 12px; 770 padding: 5px 12px;
717 font-size: 0.8rem; 771 font-size: 0.8rem;
718 } 772 }
773 +
774 +.close-float-panel {
775 + position: absolute;
776 + top: 1rem;
777 + left: 1rem;
778 +}
719 </style> 779 </style>
......