This commit is contained in:
menxipeng
2025-09-13 13:48:40 +08:00
parent 549706f808
commit a14edb27c1
4 changed files with 170 additions and 14 deletions

View File

@@ -81,10 +81,14 @@ export default {
set(val) { set(val) {
this.$emit('update:limit', val) this.$emit('update:limit', val)
} }
},
maxPage() {
return Math.ceil(this.total / this.pageSize) || 1
} }
}, },
methods: { methods: {
handleSizeChange(val) { handleSizeChange(val) {
// 当页面大小改变时,检查当前页是否还有效
if (this.currentPage * val > this.total) { if (this.currentPage * val > this.total) {
this.currentPage = 1 this.currentPage = 1
} }
@@ -94,6 +98,16 @@ export default {
} }
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
// 计算最大页数,进行边界检查
const maxPage = Math.ceil(this.total / this.pageSize) || 1;
// 如果请求的页码超出范围,限制在有效范围内
if (val > maxPage) {
val = maxPage;
} else if (val < 1) {
val = 1;
}
this.$emit('pagination', { page: val, limit: this.pageSize }) this.$emit('pagination', { page: val, limit: this.pageSize })
if (this.autoScroll) { if (this.autoScroll) {
scrollTo(0, 800) scrollTo(0, 800)

View File

@@ -89,7 +89,7 @@
:total="total" :total="total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@pagination="getList" @pagination="handlePagination"
/> />
<!-- 添加或修改活动对话框 --> <!-- 添加或修改活动对话框 -->
@@ -247,10 +247,38 @@ export default {
/** 查询活动列表 */ /** 查询活动列表 */
getList() { getList() {
this.loading = true; this.loading = true;
listActivity(this.queryParams).then(response => {
this.activityList = response.rows; // 清理查询参数,移除空值
this.total = response.total; const cleanParams = {};
Object.keys(this.queryParams).forEach(key => {
const value = this.queryParams[key];
if (value !== null && value !== undefined && value !== '') {
cleanParams[key] = value;
}
});
// 确保分页参数存在
cleanParams.pageNum = this.queryParams.pageNum || 1;
cleanParams.pageSize = this.queryParams.pageSize || 10;
console.log('活动搜索参数:', cleanParams);
listActivity(cleanParams).then(response => {
this.activityList = response.rows || [];
this.total = response.total || 0;
this.loading = false; this.loading = false;
console.log('活动搜索结果:', {
total: this.total,
count: this.activityList.length,
params: cleanParams
});
}).catch(error => {
console.error('获取活动列表失败:', error);
this.activityList = [];
this.total = 0;
this.loading = false;
this.$modal.msgError("获取活动列表失败");
}); });
}, },
// 取消按钮 // 取消按钮
@@ -276,13 +304,30 @@ export default {
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
console.log('执行搜索,当前查询参数:', this.queryParams);
this.getList(); this.getList();
}, },
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm("queryForm"); this.resetForm("queryForm");
// 手动重置查询参数,确保所有条件都被清空
this.queryParams = {
pageNum: 1,
pageSize: 10,
name: null,
status: null,
shelf: null
};
console.log('重置查询参数:', this.queryParams);
this.handleQuery(); this.handleQuery();
}, },
/** 分页事件处理 */
handlePagination(pagination) {
this.queryParams.pageNum = pagination.page;
this.queryParams.pageSize = pagination.limit;
console.log('分页参数变更:', pagination);
this.getList();
},
// 多选框选中数据 // 多选框选中数据
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.id) this.ids = selection.map(item => item.id)

View File

@@ -141,7 +141,7 @@
:total="total" :total="total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@pagination="getList" @pagination="handlePagination"
/> />
<!-- 添加或修改普通歌曲对话框 --> <!-- 添加或修改普通歌曲对话框 -->
@@ -290,6 +290,20 @@ export default {
} }
}; };
}, },
computed: {
// 计算最大页数
maxPage() {
return Math.ceil(this.total / this.queryParams.pageSize) || 1;
},
// 检查是否为第一页
isFirstPage() {
return this.queryParams.pageNum <= 1;
},
// 检查是否为最后一页
isLastPage() {
return this.queryParams.pageNum >= this.maxPage;
}
},
created() { created() {
this.getList(); this.getList();
this.getTagOptions(); this.getTagOptions();
@@ -303,9 +317,25 @@ export default {
getList() { getList() {
this.loading = true; this.loading = true;
listNormalSong(this.queryParams).then(response => { listNormalSong(this.queryParams).then(response => {
this.playlistList = response.rows; this.playlistList = response.rows || [];
this.total = response.total; this.total = response.total || 0;
// 简单的边界检查:如果当前页码超出了实际页数,重置到最后一页
const maxPage = Math.ceil(this.total / this.queryParams.pageSize) || 1;
if (this.queryParams.pageNum > maxPage && this.total > 0) {
this.queryParams.pageNum = maxPage;
// 重新请求数据
this.getList();
return;
}
this.loading = false; this.loading = false;
}).catch(error => {
console.error('获取歌曲列表失败:', error);
this.playlistList = [];
this.total = 0;
this.loading = false;
this.$modal.msgError("获取歌曲列表失败");
}); });
}, },
// 获取标签选项 // 获取标签选项
@@ -358,6 +388,12 @@ export default {
this.queryParams.musicType = 'ordinary'; this.queryParams.musicType = 'ordinary';
this.handleQuery(); this.handleQuery();
}, },
/** 分页事件处理 */
handlePagination(pagination) {
this.queryParams.pageNum = pagination.page;
this.queryParams.pageSize = pagination.limit;
this.getList();
},
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset();

View File

@@ -48,8 +48,16 @@
<span v-else>-</span> <span v-else>-</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="120" /> <el-table-column label="创建时间" align="center" prop="createTime" width="160" :show-overflow-tooltip="true">
<el-table-column label="更新时间" align="center" prop="updateTime" width="120" /> <template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
</template>
</el-table-column>
<el-table-column label="更新时间" align="center" prop="updateTime" width="160" :show-overflow-tooltip="true">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
@@ -73,7 +81,7 @@
:total="total" :total="total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@pagination="getList" @pagination="handlePagination"
/> />
<!-- 添加或修改场景音乐对话框 --> <!-- 添加或修改场景音乐对话框 -->
@@ -110,6 +118,7 @@
<script> <script>
import { listScene, getScene, delScene, addScene, updateScene } from "@/api/playlist/scene"; import { listScene, getScene, delScene, addScene, updateScene } from "@/api/playlist/scene";
import { getImageUrl } from "@/utils/image"; import { getImageUrl } from "@/utils/image";
import { parseTime } from "@/utils/ruoyi";
import request from '@/utils/request'; import request from '@/utils/request';
export default { export default {
@@ -145,7 +154,19 @@ export default {
// 表单校验 // 表单校验
rules: { rules: {
scene: [ scene: [
{ required: true, message: "场景名称不能为空", trigger: "blur" } { required: true, message: "场景名称不能为空", trigger: "blur" },
{
validator: (rule, value, callback) => {
if (value && (value.trim() === '' || value !== value.trim())) {
callback(new Error('场景名称不能为纯空格或包含首尾空格'));
} else if (value && /\s/.test(value)) {
callback(new Error('场景名称不能包含空格'));
} else {
callback();
}
},
trigger: "blur"
}
] ]
} }
}; };
@@ -162,11 +183,33 @@ export default {
getList() { getList() {
this.loading = true; this.loading = true;
listScene(this.queryParams).then(response => { listScene(this.queryParams).then(response => {
this.sceneList = response.rows; this.sceneList = response.rows || [];
this.total = response.total; this.total = response.total || 0;
// 简单的边界检查:如果当前页码超出了实际页数,重置到最后一页
const maxPage = Math.ceil(this.total / this.queryParams.pageSize) || 1;
if (this.queryParams.pageNum > maxPage && this.total > 0) {
this.queryParams.pageNum = maxPage;
// 重新请求数据
this.getList();
return;
}
this.loading = false; this.loading = false;
}).catch(error => {
console.error('获取场景音乐列表失败:', error);
this.sceneList = [];
this.total = 0;
this.loading = false;
this.$modal.msgError("获取场景音乐列表失败");
}); });
}, },
/** 分页事件处理 */
handlePagination(pagination) {
this.queryParams.pageNum = pagination.page;
this.queryParams.pageSize = pagination.limit;
this.getList();
},
// 取消按钮 // 取消按钮
cancel() { cancel() {
this.open = false; this.open = false;
@@ -218,6 +261,23 @@ export default {
submitForm() { submitForm() {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
// 提交前清理数据,去除首尾空格
if (this.form.scene) {
this.form.scene = this.form.scene.trim();
}
// 再次验证清理后的数据
if (!this.form.scene || this.form.scene === '') {
this.$modal.msgError("场景名称不能为空或纯空格");
return;
}
// 检查是否包含空格
if (/\s/.test(this.form.scene)) {
this.$modal.msgError("场景名称不能包含空格");
return;
}
if (this.form.id != null) { if (this.form.id != null) {
updateScene(this.form).then(response => { updateScene(this.form).then(response => {
this.$modal.msgSuccess("修改成功"); this.$modal.msgSuccess("修改成功");
@@ -237,7 +297,8 @@ export default {
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const ids = row.id || this.ids; const ids = row.id || this.ids;
this.$modal.confirm('是否确认删除场景音乐编号为"' + ids + '"的数据项?').then(function() { const sceneName = row.scene || '未知场景';
this.$modal.confirm('是否确认删除场景音乐"' + sceneName + '"').then(function() {
return delScene(ids); return delScene(ids);
}).then(() => { }).then(() => {
this.getList(); this.getList();