modal 声音试听弹窗

demo 记录:
html
<ng-container> <div class="audition-modal"> <p class="item" *ngFor="let item of list; let sub = index"> <span>{{ sub + 1 }}. {{ item.name | translate }}</span> <span><b class="alar-voice" (click)="onAuditionClick(item)"></b></span> </p> <div class="audition-alert"> <span class="audition-attention">{{ 'Explorer.Alarm.Attention' | translate }}:</span> <p>1. {{ 'Explorer.Alarm.AttentionConfirm' | translate }}</p> <p>2. {{ 'Explorer.Alarm.AlertContent' | translate }}</p> </div> </div> </ng-container>
scss
.audition-modal {
line-height: 35px;
text-align: center;
padding: 10px;
.item {
display: flex;
.alar-voice {
position: unset;
}
& > span {
flex: 1;
}
}
.audition-alert {
text-align: left;
line-height: 18px;
margin-top: 10px;
color: #f00;
font-size: 12px;
position: relative;
padding-left: 60px;
.audition-attention {
position: absolute;
left: 15px;
top: 0;
}
}
}
父级scss 相关
@mixin alar-voice {
cursor: pointer;
display: inline-block;
position: relative;
top: 5px;
left: 2px;
height: 24px;
width: 24px;
background-size: 24px 24px;
background-image: url('../../../../../assets/icon/Audition.svg');
}
::ng-deep {
.alar-voice {
@include alar-voice;
left: unset;
top: unset;
right: 0;
position: absolute;
}
}
component
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-audition-sound', templateUrl: './audition-sound.component.html', styleUrls: [ './audition-sound.component.scss' ] }) export class AuditionSoundComponent implements OnInit { // 记录 audio 元素 auditionEle: any = null; list: any[] = [ { name: 'Explorer.Alarm.AlarmLevel.Low', key: 0 }, { name: 'Explorer.Alarm.AlarmLevel.High', key: 1 }, { name: 'Explorer.Alarm.AlarmLevel.Urgent', key: 2 }, ]; constructor() { } ngOnInit() { setTimeout(() => { this.auditionEle = document.getElementById('audition-audio'); }); } /** * 根据点击类型,播放对应音频 * @param item Object */ onAuditionClick(item: any) { const type = item.key; let url = ''; switch (type) { case 0: url = './assets/audio/AlarmSoundLow.mp3'; break; case 1: url = './assets/audio/AlarmSoundHigh.mp3'; break; case 2: url = './assets/audio/AlarmSoundUrgent.mp3'; break; } console.log(type); this.auditionEle.src = url; this.auditionEle.play(); } }
外部调用
/** * 点击试听按钮,打开对话框 */ openAuditionModal() { const translate = getTranslateAsync(); translate('Explorer.Alarm.AuditionSound').then(title => { const instance = this.modalService.create({ nzTitle: title, nzBodyStyle: { padding: '0px', }, nzWidth: 400, nzContent: AuditionSoundComponent, nzCancelText: null, nzOkType: 'default', nzOnOk: () => { let ele: any = document.getElementById('audition-audio'); ele.src = ''; instance.destroy(); }, nzOnCancel: () => { let ele: any = document.getElementById('audition-audio'); ele.src = ''; instance.destroy(); }, }); }); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2020-06-29 No provider for TreeDraggedElement 报错问题