mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
修复了”删除“和”批量删除“的bug
This commit is contained in:
@@ -115,7 +115,6 @@ export default {
|
|||||||
},
|
},
|
||||||
// 删除
|
// 删除
|
||||||
deleteParam(ids, callback) {
|
deleteParam(ids, callback) {
|
||||||
console.log(4444,ids )
|
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/admin/params/delete`)
|
.url(`${getServiceUrl()}/admin/params/delete`)
|
||||||
.method('POST')
|
.method('POST')
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
// timbre.js
|
|
||||||
import {getServiceUrl} from '../api';
|
import {getServiceUrl} from '../api';
|
||||||
import RequestService from '../httpRequest';
|
import RequestService from '../httpRequest';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
// 获取音色
|
||||||
* 获取音色数据
|
|
||||||
*/
|
|
||||||
getVoiceList(params, callback) {
|
getVoiceList(params, callback) {
|
||||||
const queryParams = new URLSearchParams({
|
const queryParams = new URLSearchParams({
|
||||||
ttsModelId: params.ttsModelId,
|
ttsModelId: params.ttsModelId,
|
||||||
@@ -28,9 +25,7 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
/**
|
// 音色保存
|
||||||
* 音色保存
|
|
||||||
*/
|
|
||||||
saveVoice(params, callback) {
|
saveVoice(params, callback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/ttsVoice`)
|
.url(`${getServiceUrl()}/ttsVoice`)
|
||||||
@@ -54,15 +49,12 @@ export default {
|
|||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
/**
|
// 音色删除
|
||||||
* 音色删除
|
deleteVoice(ids, callback) {
|
||||||
*/
|
|
||||||
deleteVoice(id, callback) {
|
|
||||||
console.log('尝试删除音色,ID:', id);
|
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/ttsVoice`)
|
.url(`${getServiceUrl()}/ttsVoice/delete`)
|
||||||
.method('DELETE')
|
.method('POST')
|
||||||
.data({ ids: [id] })
|
.data(ids)
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
RequestService.clearRequestTime()
|
RequestService.clearRequestTime()
|
||||||
callback(res);
|
callback(res);
|
||||||
@@ -70,13 +62,11 @@ export default {
|
|||||||
.fail((err) => {
|
.fail((err) => {
|
||||||
console.error('删除音色失败:', err);
|
console.error('删除音色失败:', err);
|
||||||
RequestService.reAjaxFun(() => {
|
RequestService.reAjaxFun(() => {
|
||||||
this.deleteVoice(id, callback);
|
this.deleteVoice(ids, callback);
|
||||||
});
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
/**
|
// 音色修改
|
||||||
* 音色修改
|
|
||||||
*/
|
|
||||||
updateVoice(params, callback) {
|
updateVoice(params, callback) {
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/ttsVoice/${params.id}`)
|
.url(`${getServiceUrl()}/ttsVoice/${params.id}`)
|
||||||
|
|||||||
@@ -108,7 +108,11 @@
|
|||||||
<el-button type="primary" size="mini" @click="addNew" style="background: #f6cf79;border: None; color: #000012">
|
<el-button type="primary" size="mini" @click="addNew" style="background: #f6cf79;border: None; color: #000012">
|
||||||
新增
|
新增
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button type="primary" size="mini" @click="batchDelete" style="background: red;border:None">删除</el-button>
|
<el-button type="primary"
|
||||||
|
size="mini"
|
||||||
|
@click="deleteRow(filteredTtsModels.filter(row => row.selected))"
|
||||||
|
style="background: red;border:None">删除
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -419,105 +423,57 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteRow(row) {
|
deleteRow(row) {
|
||||||
this.$confirm("确定要删除该音色吗?", "警告", {
|
// 处理单个音色或音色数组
|
||||||
confirmButtonText: "确定",
|
const voices = Array.isArray(row) ? row : [row];
|
||||||
cancelButtonText: "取消",
|
|
||||||
type: "warning",
|
if (Array.isArray(row) && row.length === 0) {
|
||||||
})
|
this.$message.warning("请先选择需要删除的音色");
|
||||||
.then(() => {
|
return;
|
||||||
Api.timbre.deleteVoice(row.id, (response) => {
|
}
|
||||||
if (response.code === 0) {
|
|
||||||
this.$message.success({
|
|
||||||
message: "删除成功",
|
const voiceCount = voices.length;
|
||||||
showClose: true
|
this.$confirm(`确定要删除选中的${voiceCount}个音色吗?`, "警告", {
|
||||||
});
|
confirmButtonText: "确定",
|
||||||
this.loadData(); // 刷新数据
|
cancelButtonText: "取消",
|
||||||
} else {
|
type: "warning",
|
||||||
this.$message.error({
|
distinguishCancelAndClose: true
|
||||||
message: response.msg || "删除失败",
|
}).then(() => {
|
||||||
showClose: true
|
const ids = voices.map(voice => voice.id);
|
||||||
});
|
if (ids.some(id => !id)) {
|
||||||
|
this.$message.error("存在无效的音色ID");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.$message.info("已取消删除");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
batchDelete() {
|
Api.timbre.deleteVoice(ids, ({data}) => {
|
||||||
const selectedRows = this.filteredTtsModels.filter(row => row.selected);
|
if (data.code === 0) {
|
||||||
if (selectedRows.length === 0) {
|
this.$message.success({
|
||||||
this.$message.warning("请先选择需要删除的音色");
|
message: `成功删除${voiceCount}个参数`,
|
||||||
return;
|
showClose: true
|
||||||
}
|
|
||||||
|
|
||||||
this.$confirm(`确定要删除选中的${selectedRows.length}个音色吗?`, "警告", {
|
|
||||||
confirmButtonText: "确定",
|
|
||||||
cancelButtonText: "取消",
|
|
||||||
type: "warning",
|
|
||||||
})
|
|
||||||
.then(async () => {
|
|
||||||
const loading = this.$loading({
|
|
||||||
lock: true,
|
|
||||||
text: "正在删除中...",
|
|
||||||
spinner: "el-icon-loading",
|
|
||||||
background: "rgba(0, 0, 0, 0.7)",
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const results = await Promise.all(
|
|
||||||
selectedRows.map((row) => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
Api.timbre.deleteVoice(row.id, (response) => {
|
|
||||||
if (response.code === 0) {
|
|
||||||
resolve({ success: true, id: row.id });
|
|
||||||
} else {
|
|
||||||
resolve({
|
|
||||||
success: false,
|
|
||||||
id: row.id,
|
|
||||||
msg: response.msg || '删除失败'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
this.loadData(); // 刷新参数列表
|
||||||
);
|
|
||||||
|
|
||||||
const successCount = results.filter(r => r.success).length;
|
|
||||||
const failCount = results.length - successCount;
|
|
||||||
|
|
||||||
if (failCount === 0) {
|
|
||||||
this.$message.success({
|
|
||||||
message: `成功删除${successCount}个音色`,
|
|
||||||
showClose: true
|
|
||||||
});
|
|
||||||
} else if (successCount === 0) {
|
|
||||||
this.$message.error({
|
|
||||||
message: '删除失败,请重试',
|
|
||||||
showClose: true
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.$message.warning({
|
this.$message.error({
|
||||||
message: `成功删除${successCount}个音色,${failCount}个删除失败`,
|
message: data.msg || '删除失败,请重试',
|
||||||
showClose: true
|
showClose: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadData(); // 刷新数据
|
|
||||||
} catch (error) {
|
|
||||||
console.error('批量删除出错:', error);
|
|
||||||
this.$message.error({
|
|
||||||
message: '删除过程中发生错误',
|
|
||||||
showClose: true
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
loading.close();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.$message.info("已取消删除");
|
|
||||||
});
|
});
|
||||||
|
}).catch(action => {
|
||||||
|
if (action === 'cancel') {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: '已取消删除操作',
|
||||||
|
duration: 1000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$message({
|
||||||
|
type: 'info',
|
||||||
|
message: '操作已关闭',
|
||||||
|
duration: 1000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
isValidAudioUrl(url) {
|
isValidAudioUrl(url) {
|
||||||
|
|||||||
Reference in New Issue
Block a user