This commit is contained in:
menxipeng
2025-11-05 22:11:20 +08:00
parent d367d40255
commit c5f94e2d2c
4 changed files with 177 additions and 59 deletions

View File

@@ -277,8 +277,52 @@ export default {
if (this.form.bannerAddr) {
this.form.previewUrl = this.getImageUrlMethod(this.form.bannerAddr);
}
this.open = true;
this.title = "修改Banner";
// 如果跳转类型为空,通过跳转链接进行判断
if (!this.form.jumpType && this.form.jumpUrl) {
if (this.form.jumpUrl.startsWith('music:')) {
// 音乐类型解析musicId
this.form.jumpType = 'music';
this.form.musicId = parseInt(this.form.jumpUrl.replace('music:', ''));
} else {
// URL类型
this.form.jumpType = 'url';
}
} else if (!this.form.jumpType) {
// 如果既没有jumpType也没有jumpUrl默认为url
this.form.jumpType = 'url';
}
// 如果jumpType是music但musicId未设置尝试从jumpUrl解析
if (this.form.jumpType === 'music' && !this.form.musicId && this.form.jumpUrl) {
if (this.form.jumpUrl.startsWith('music:')) {
this.form.musicId = parseInt(this.form.jumpUrl.replace('music:', ''));
}
}
// 如果是音乐类型,需要加载音乐列表以便回显
if (this.form.jumpType === 'music') {
this.loadMusicList().then(() => {
// 如果musicId存在但不在列表中尝试加载更多数据
if (this.form.musicId && !this.musicList.find(m => m.musicId === this.form.musicId)) {
// 尝试加载更多数据
return listMusic({
pageNum: 1,
pageSize: 100,
musicType: 'ordinary'
}).then(response => {
this.musicList = response.rows || [];
});
}
}).then(() => {
// 确保音乐列表加载完成后再显示对话框
this.open = true;
this.title = "修改Banner";
});
} else {
// 非音乐类型,直接显示对话框
this.open = true;
this.title = "修改Banner";
}
});
},
/** 提交按钮 */
@@ -412,13 +456,14 @@ export default {
// 加载音乐列表
loadMusicList() {
this.musicLoading = true;
listMusic({
return listMusic({
pageNum: 1,
pageSize: 50,
musicType: 'ordinary'
}).then(response => {
this.musicList = response.rows || [];
this.musicLoading = false;
return response;
}).catch(() => {
this.musicLoading = false;
});

View File

@@ -156,13 +156,13 @@
</el-table-column>
<el-table-column label="权限" align="center" prop="vip" width="80">
<template slot-scope="scope">
<span>{{ scope.row.vip === 1 ? 'VIP' : '免费' }}</span>
<span>{{ parseInt(scope.row.vip) === 1 ? 'VIP' : '免费' }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="shelf" width="80">
<template slot-scope="scope">
<el-tag :type="scope.row.shelf === 1 ? 'success' : 'danger'" size="mini">
{{ scope.row.shelf === 1 ? '上架' : '下架' }}
<el-tag :type="parseInt(scope.row.shelf) === 1 ? 'success' : 'danger'" size="mini">
{{ parseInt(scope.row.shelf) === 1 ? '上架' : '下架' }}
</el-tag>
</template>
</el-table-column>
@@ -253,7 +253,8 @@ export default {
name: null,
author: null
},
bindLoading: false
bindLoading: false,
isRestoringSelection: false // 标志位:是否正在恢复选择状态
};
},
created() {
@@ -438,6 +439,7 @@ export default {
};
this.selectedMusicIds = []; // 重置选中的音乐
this.boundMusicIds = []; // 重置已绑定的音乐ID
this.isRestoringSelection = false; // 重置标志位
this.getBoundMusic(row.categoryId); // 先获取已绑定的音乐
this.getMusicList();
this.bindMusicOpen = true;
@@ -451,13 +453,24 @@ export default {
} else if (response.rows && Array.isArray(response.rows)) {
this.boundMusicIds = response.rows.map(item => item.musicId || item.id);
}
// 初始化选中列表为已绑定的音乐ID
this.selectedMusicIds = [...this.boundMusicIds];
// 如果当前页已经加载,需要重新设置选择状态
if (this.musicList.length > 0) {
this.$nextTick(() => {
this.setDefaultSelection();
});
}
}).catch(() => {
this.boundMusicIds = [];
this.selectedMusicIds = [];
});
},
/** 查询音乐列表 */
getMusicList() {
this.musicLoading = true;
// 在数据更新前设置标志位,防止数据更新时触发选择变更事件
this.isRestoringSelection = true;
listMusic(this.musicQueryParams).then(response => {
this.musicList = response.rows;
this.musicTotal = response.total;
@@ -468,21 +481,47 @@ export default {
});
}).catch(() => {
this.musicLoading = false;
this.isRestoringSelection = false;
});
},
/** 设置默认勾选已绑定的音乐 */
/** 设置默认勾选已绑定的音乐和用户选择的音乐 */
setDefaultSelection() {
if (this.$refs.musicTable && this.boundMusicIds.length > 0) {
this.musicList.forEach((row, index) => {
if (this.boundMusicIds.includes(row.musicId)) {
this.$refs.musicTable.toggleRowSelection(row, true);
if (this.$refs.musicTable) {
// 标志位已经在 getMusicList 中设置,这里不需要再设置
// 清除所有选择,避免重复选择
this.$refs.musicTable.clearSelection();
// 恢复选择状态
this.$nextTick(() => {
if (this.selectedMusicIds.length > 0) {
this.musicList.forEach((row, index) => {
if (this.selectedMusicIds.includes(row.musicId)) {
this.$refs.musicTable.toggleRowSelection(row, true);
}
});
}
// 恢复完成后,重置标志位
this.isRestoringSelection = false;
});
} else {
// 如果表格引用不存在,也要重置标志位
this.isRestoringSelection = false;
}
},
// 音乐多选框选中数据
handleMusicSelectionChange(selection) {
this.selectedMusicIds = selection.map(item => item.musicId);
// 如果正在恢复选择状态,不处理选择变更
if (this.isRestoringSelection) {
return;
}
// 获取当前页面的音乐ID列表
const currentPageMusicIds = this.musicList.map(item => item.musicId);
// 获取当前页面选中的音乐ID列表
const currentPageSelectedIds = selection.map(item => item.musicId);
// 从完整选择列表中移除当前页面的音乐ID包括选中和未选中的
this.selectedMusicIds = this.selectedMusicIds.filter(id => !currentPageMusicIds.includes(id));
// 将当前页面选中的音乐ID添加到完整选择列表中
this.selectedMusicIds = [...this.selectedMusicIds, ...currentPageSelectedIds];
},
/** 提交绑定音乐 */
submitBindMusic() {

View File

@@ -152,13 +152,13 @@
</el-table-column>
<el-table-column label="权限" align="center" prop="vip" width="80">
<template slot-scope="scope">
<span>{{ scope.row.vip === 1 ? 'VIP' : '免费' }}</span>
<span>{{ parseInt(scope.row.vip) === 1 ? 'VIP' : '免费' }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="shelf" width="80">
<template slot-scope="scope">
<el-tag :type="scope.row.shelf === 1 ? 'success' : 'danger'" size="mini">
{{ scope.row.shelf === 1 ? '上架' : '下架' }}
<el-tag :type="parseInt(scope.row.shelf) === 1 ? 'success' : 'danger'" size="mini">
{{ parseInt(scope.row.shelf) === 1 ? '上架' : '下架' }}
</el-tag>
</template>
</el-table-column>
@@ -254,7 +254,8 @@ export default {
name: null,
musicType: 'ordinary' // 默认只获取普通音乐
},
bindLoading: false
bindLoading: false,
isRestoringSelection: false // 标志位:是否正在恢复选择状态
};
},
created() {
@@ -459,6 +460,7 @@ export default {
this.musicQueryParams.musicType = 'ordinary'; // 只获取普通音乐
this.selectedMusicIds = []; // 重置选中的音乐
this.boundMusicIds = []; // 重置已绑定的音乐ID
this.isRestoringSelection = false; // 重置标志位
this.getBoundMusic(row.id); // 先获取已绑定的音乐
this.getMusicList();
this.bindMusicOpen = true;
@@ -472,13 +474,24 @@ export default {
} else if (response.rows && Array.isArray(response.rows)) {
this.boundMusicIds = response.rows.map(item => item.musicId || item.id);
}
// 初始化选中列表为已绑定的音乐ID
this.selectedMusicIds = [...this.boundMusicIds];
// 如果当前页已经加载,需要重新设置选择状态
if (this.musicList.length > 0) {
this.$nextTick(() => {
this.setDefaultSelection();
});
}
}).catch(() => {
this.boundMusicIds = [];
this.selectedMusicIds = [];
});
},
/** 查询音乐列表 */
getMusicList() {
this.musicLoading = true;
// 在数据更新前设置标志位,防止数据更新时触发选择变更事件
this.isRestoringSelection = true;
listMusic(this.musicQueryParams).then(response => {
this.musicList = response.rows;
this.musicTotal = response.total;
@@ -489,21 +502,47 @@ export default {
});
}).catch(() => {
this.musicLoading = false;
this.isRestoringSelection = false;
});
},
/** 设置默认勾选已绑定的音乐 */
/** 设置默认勾选已绑定的音乐和用户选择的音乐 */
setDefaultSelection() {
if (this.$refs.musicTable && this.boundMusicIds.length > 0) {
this.musicList.forEach((row, index) => {
if (this.boundMusicIds.includes(row.musicId)) {
this.$refs.musicTable.toggleRowSelection(row, true);
if (this.$refs.musicTable) {
// 标志位已经在 getMusicList 中设置,这里不需要再设置
// 清除所有选择,避免重复选择
this.$refs.musicTable.clearSelection();
// 恢复选择状态
this.$nextTick(() => {
if (this.selectedMusicIds.length > 0) {
this.musicList.forEach((row, index) => {
if (this.selectedMusicIds.includes(row.musicId)) {
this.$refs.musicTable.toggleRowSelection(row, true);
}
});
}
// 恢复完成后,重置标志位
this.isRestoringSelection = false;
});
} else {
// 如果表格引用不存在,也要重置标志位
this.isRestoringSelection = false;
}
},
// 音乐多选框选中数据
handleMusicSelectionChange(selection) {
this.selectedMusicIds = selection.map(item => item.musicId);
// 如果正在恢复选择状态,不处理选择变更
if (this.isRestoringSelection) {
return;
}
// 获取当前页面的音乐ID列表
const currentPageMusicIds = this.musicList.map(item => item.musicId);
// 获取当前页面选中的音乐ID列表
const currentPageSelectedIds = selection.map(item => item.musicId);
// 从完整选择列表中移除当前页面的音乐ID包括选中和未选中的
this.selectedMusicIds = this.selectedMusicIds.filter(id => !currentPageMusicIds.includes(id));
// 将当前页面选中的音乐ID添加到完整选择列表中
this.selectedMusicIds = [...this.selectedMusicIds, ...currentPageSelectedIds];
},
/** 提交绑定音乐 */
submitBindMusic() {

View File

@@ -31,12 +31,6 @@
<el-option label="下架" :value="2" />
</el-select>
</el-form-item>
<el-form-item label="音乐类型" prop="musicType">
<el-select v-model="queryParams.musicType" placeholder="选择音乐类型" clearable style="width: 180px">
<el-option label="普通歌曲" value="ordinary" />
<el-option label="混音歌曲" value="mixing" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@@ -45,7 +39,11 @@
</el-form>
<el-table v-loading="loading" :data="playlistList">
<el-table-column label="序号" align="center" type="index" width="60" />
<el-table-column label="序号" align="center" width="60">
<template slot-scope="scope">
<span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
</template>
</el-table-column>
<el-table-column label="音乐名称" align="center" prop="name" :show-overflow-tooltip="true" />
<el-table-column label="作者" align="center" prop="author" :show-overflow-tooltip="true" />
<el-table-column label="音乐图片" align="center" prop="imgAddr">
@@ -91,13 +89,6 @@
</el-tag>
</template>
</el-table-column>
<el-table-column label="音乐类型" align="center" prop="musicType" width="100">
<template slot-scope="scope">
<el-tag :type="scope.row.musicType === 'ordinary' ? 'primary' : 'warning'" size="mini">
{{ scope.row.musicType === 'ordinary' ? '普通歌曲' : '混音歌曲' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="标签" align="center" prop="label" width="150">
<template slot-scope="scope">
<el-tag
@@ -165,12 +156,6 @@
<el-option label="下架" :value="2" />
</el-select>
</el-form-item>
<el-form-item label="音乐类型" prop="musicType">
<el-select v-model="form.musicType" placeholder="请选择音乐类型" style="width: 100%">
<el-option label="普通歌曲" value="ordinary" />
<el-option label="混音歌曲" value="mixing" />
</el-select>
</el-form-item>
<el-form-item label="标签" prop="label">
<el-select
v-model="selectedTags"
@@ -283,9 +268,6 @@ export default {
],
shelf: [
{ required: true, message: "上架状态不能为空", trigger: "change" }
],
musicType: [
{ required: true, message: "音乐类型不能为空", trigger: "change" }
]
}
};
@@ -361,20 +343,22 @@ export default {
},
// 表单重置
reset() {
this.form = {
id: null,
musicId: null,
name: null,
author: null,
vip: 2,
shelf: 1,
imgAddr: null,
musicAddr: null,
musicType: "ordinary",
label: null
};
this.selectedTags = [];
this.resetForm("form");
this.$nextTick(() => {
this.form = {
id: null,
musicId: null,
name: null,
author: null,
vip: 2,
shelf: 1,
imgAddr: null,
musicAddr: null,
musicType: "ordinary",
label: null
};
this.selectedTags = [];
});
},
/** 搜索按钮操作 */
handleQuery() {
@@ -413,6 +397,9 @@ export default {
if (this.form.shelf !== null && this.form.shelf !== undefined) {
this.form.shelf = parseInt(this.form.shelf);
}
// 确保音乐类型固定为普通歌曲
this.form.musicType = 'ordinary';
} else {
this.$modal.msgError("未找到歌曲信息");
return;
@@ -454,6 +441,14 @@ export default {
return;
}
// 确保音乐类型固定为普通歌曲
this.form.musicType = 'ordinary';
// 确保上架状态是数字类型
if (this.form.shelf !== null && this.form.shelf !== undefined) {
this.form.shelf = parseInt(this.form.shelf);
}
if (this.form.id != null) {
updateNormalSong(this.form).then(response => {
this.$modal.msgSuccess("修改成功");