获取音色数据的接口实现,优化AudioPlayer警告

This commit is contained in:
Ran_Chen
2025-04-09 11:00:10 +08:00
parent fe0fb9a884
commit a42ed5c388
5 changed files with 106 additions and 38 deletions
+4 -1
View File
@@ -4,13 +4,15 @@ import agent from './module/agent.js'
import device from './module/device.js' import device from './module/device.js'
import model from './module/model.js' import model from './module/model.js'
import user from './module/user.js' import user from './module/user.js'
import timbre from "./module/timbre.js";
/** /**
* 接口地址 * 接口地址
* 开发时自动读取使用.env.development文件 * 开发时自动读取使用.env.development文件
* 编译时自动读取使用.env.production文件 * 编译时自动读取使用.env.production文件
*/ */
const DEV_API_SERVICE = process.env.VUE_APP_API_BASE_URL // const DEV_API_SERVICE = process.env.VUE_APP_API_BASE_URL
const DEV_API_SERVICE = 'https://2662r3426b.vicp.fun/xiaozhi'
/** /**
* 根据开发环境返回接口url * 根据开发环境返回接口url
@@ -29,4 +31,5 @@ export default {
agent, agent,
device, device,
model, model,
timbre,
} }
@@ -0,0 +1,28 @@
// timbre.js
import { getServiceUrl } from '../api';
import RequestService from '../httpRequest';
export default {
getVoiceList(params, callback) {
const queryParams = new URLSearchParams({
ttsModelId: params.ttsModelId,
page: params.page || 1,
limit: params.limit || 10,
name: params.name || ''
}).toString();
RequestService.sendRequest()
.url(`${getServiceUrl()}/ttsVoice?${queryParams}`)
.method('GET')
.success((res) => {
RequestService.clearRequestTime();
callback(res.data || []);
})
.fail((err) => {
console.error('获取音色列表失败:', err);
RequestService.reAjaxFun(() => {
this.getVoiceList(params, callback);
});
}).send();
},
}
@@ -360,8 +360,8 @@ onUnmounted(() => {
left: -14px; left: -14px;
width: 30px; width: 30px;
height: 60px; height: 60px;
-webkit-appearance: slider-vertical; writing-mode: vertical-lr;
writing-mode: bt-lr; direction: rtl;
opacity: 0; opacity: 0;
cursor: pointer; cursor: pointer;
z-index: 2; z-index: 2;
+61 -33
View File
@@ -4,7 +4,8 @@
width="75%" width="75%"
@close="handleClose" @close="handleClose"
:show-close="false" :show-close="false"
:append-to-body="true"> :append-to-body="true"
:close-on-click-modal="true">
<button class="custom-close-btn" @click="handleClose"> <button class="custom-close-btn" @click="handleClose">
× ×
</button> </button>
@@ -15,6 +16,7 @@
@scroll="handleScroll" @scroll="handleScroll"
> >
<el-table <el-table
v-loading="loading"
:data="filteredTtsModels" :data="filteredTtsModels"
style="width: 100%;" style="width: 100%;"
class="data-table" class="data-table"
@@ -46,7 +48,8 @@
<el-table-column label="试听" align="center" min-width="225" class-name="audio-column"> <el-table-column label="试听" align="center" min-width="225" class-name="audio-column">
<template slot-scope="scope"> <template slot-scope="scope">
<div class="custom-audio-container"> <div class="custom-audio-container">
<AudioPlayer :audioUrl="getAudioUrl(scope.row.voiceCode)"/> <AudioPlayer :audioUrl="scope.row.voiceDemo"/>
<!-- <AudioPlayer :audioUrl="'https://music.163.com/song/media/outer/url?id=5257138.mp3'"/>-->
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
@@ -104,6 +107,7 @@
<script> <script>
import AudioPlayer from './AudioPlayer.vue' import AudioPlayer from './AudioPlayer.vue'
import Api from "@/apis/api";
export default { export default {
components: {AudioPlayer}, components: {AudioPlayer},
@@ -111,49 +115,36 @@ export default {
visible: { visible: {
type: Boolean, type: Boolean,
default: false default: false
},
ttsModelId: {
type: String,
required: true
} }
}, },
data() { data() {
return { return {
localVisible: this.visible, localVisible: this.visible,
activeModel: 'EdgeTTS',
searchQuery: '', searchQuery: '',
editDialogVisible: false, editDialogVisible: false,
editVoiceData: {}, editVoiceData: {},
ttsModels: [ ttsModels: [],
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: 'AAAA国少', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
{voiceCode: 'wawaxiaohe', voiceName: '湾湾小何', languageType: '中文', remark: '', selected: false},
],
currentPage: 1, currentPage: 1,
pageSize: 4, pageSize: 100,
total: 20, total: 0,
isDragging: false, isDragging: false,
startY: 0, startY: 0,
scrollTop: 0, scrollTop: 0,
selectAll: false, selectAll: false,
selectedRows: [] selectedRows: [],
loading: false,
}; };
}, },
watch: { watch: {
visible(newVal) { visible(newVal) {
this.localVisible = newVal; this.localVisible = newVal;
if (newVal) { if (newVal) {
this.currentPage = 1;
this.loadData(); // 对话框显示时加载数据
this.$nextTick(() => { this.$nextTick(() => {
this.updateScrollbar(); this.updateScrollbar();
}); });
@@ -184,15 +175,45 @@ export default {
window.removeEventListener('mousemove', this.handleDrag); window.removeEventListener('mousemove', this.handleDrag);
}, },
methods: { methods: {
handleClose() { loadData() {
this.localVisible = false; const params = {
this.$emit('update:visible', false); ttsModelId: this.ttsModelId,
this.ttsModels.forEach(model => { page: this.currentPage,
model.remark = ''; limit: this.pageSize,
name: this.searchQuery
};
Api.timbre.getVoiceList(params, (data) => {
console.log(data.data.list);
if (data.code === 0) {
this.ttsModels = data.data.list.map(item => ({
id: item.id || '',
voiceCode: item.ttsVoice || '',
voiceName: item.name || '未命名音色',
languageType: item.languages || '',
remark: item.remark || '',
voiceDemo: item.voiceDemo || '',
selected: false,
editing: false
}));
this.total = data.total;
} else {
this.$message.error(data.msg || '获取音色列表失败');
}
}, (err) => {
console.error('加载失败:', err);
this.$message.error('加载音色数据失败');
}); });
}, },
getAudioUrl(voiceCode) { handleClose() {
return `https://music.163.com/song/media/outer/url?id=5257138.mp3`; // 重置状态
this.ttsModels = [];
this.currentPage = 1;
this.total = 0;
this.selectAll = false;
this.searchQuery = '';
this.localVisible = false;
this.$emit('update:visible', false);
}, },
updateScrollbar() { updateScrollbar() {
const container = this.$refs.tableContainer; const container = this.$refs.tableContainer;
@@ -224,6 +245,13 @@ export default {
scrollbarThumb.style.top = `${Math.min(thumbTop, maxTop)}px`; scrollbarThumb.style.top = `${Math.min(thumbTop, maxTop)}px`;
}, },
handleScroll() { handleScroll() {
const container = this.$refs.tableContainer;
if (container.scrollTop + container.clientHeight >= container.scrollHeight - 50) {
if (this.currentPage * this.pageSize < this.total) {
this.currentPage++;
this.loadData();
}
}
this.updateThumbPosition(); this.updateThumbPosition();
}, },
startDrag(e) { startDrag(e) {
+11 -2
View File
@@ -80,7 +80,11 @@
</el-table-column> </el-table-column>
<el-table-column v-if="activeTab === 'tts'" label="音色管理" align="center"> <el-table-column v-if="activeTab === 'tts'" label="音色管理" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" size="mini" @click="ttsDialogVisible = true" class="voice-management-btn"> <el-button
type="text"
size="mini"
@click="openTtsDialog(scope.row)"
class="voice-management-btn">
音色管理 音色管理
</el-button> </el-button>
</template> </template>
@@ -124,7 +128,7 @@
<ModelEditDialog :modelType="activeTab" :visible.sync="editDialogVisible" :modelData="editModelData" <ModelEditDialog :modelType="activeTab" :visible.sync="editDialogVisible" :modelData="editModelData"
@save="handleModelSave" /> @save="handleModelSave" />
<TtsModel :visible.sync="ttsDialogVisible" /> <TtsModel :visible.sync="ttsDialogVisible" :ttsModelId="selectedTtsModelId"/>
<AddModelDialog :modelType="activeTab" :visible.sync="addDialogVisible" @confirm="handleAddConfirm" /> <AddModelDialog :modelType="activeTab" :visible.sync="addDialogVisible" @confirm="handleAddConfirm" />
</div> </div>
@@ -151,6 +155,7 @@ export default {
editDialogVisible: false, editDialogVisible: false,
editModelData: {}, editModelData: {},
ttsDialogVisible: false, ttsDialogVisible: false,
selectedTtsModelId: '',
modelList: [], modelList: [],
currentPage: 1, currentPage: 1,
pageSize: 5, pageSize: 5,
@@ -200,6 +205,10 @@ export default {
}, },
methods: { methods: {
openTtsDialog(row) {
this.selectedTtsModelId = row.id;
this.ttsDialogVisible = true;
},
headerCellClassName({ column, columnIndex }) { headerCellClassName({ column, columnIndex }) {
if (columnIndex === 0) { if (columnIndex === 0) {
return 'custom-selection-header'; return 'custom-selection-header';