|
...
|
...
|
@@ -2,24 +2,33 @@ |
|
|
|
<template>
|
|
|
|
<div class="page-container">
|
|
|
|
<!-- 搜索与新增区域 -->
|
|
|
|
<ContentWrap>
|
|
|
|
<ContentWrap class="plan-search-bar">
|
|
|
|
<div class="search-bar">
|
|
|
|
<el-input v-model="searchForm.name" placeholder="肌肉名称" clearable @keyup.enter="handleSearch" />
|
|
|
|
<el-button @click="handleSearch">
|
|
|
|
<el-icon>
|
|
|
|
<Search />
|
|
|
|
</el-icon>搜索
|
|
|
|
</el-button>
|
|
|
|
<el-button @click="handleReset">
|
|
|
|
<el-icon>
|
|
|
|
<Refresh />
|
|
|
|
</el-icon>重置
|
|
|
|
</el-button>
|
|
|
|
<el-button @click="handleAdd">
|
|
|
|
<el-icon>
|
|
|
|
<Plus />
|
|
|
|
</el-icon>新增
|
|
|
|
</el-button>
|
|
|
|
<div class="search-item">
|
|
|
|
<label class="search-label">肌肉名称</label>
|
|
|
|
<el-input v-model="searchForm.name" placeholder="肌肉名称" clearable @keyup.enter="handleSearch"
|
|
|
|
class="search-input" />
|
|
|
|
<div class="search-buttons">
|
|
|
|
<el-button type="primary" @click="handleSearch">
|
|
|
|
<el-icon>
|
|
|
|
<Search />
|
|
|
|
</el-icon>
|
|
|
|
搜索
|
|
|
|
</el-button>
|
|
|
|
<el-button @click="handleReset">
|
|
|
|
<el-icon>
|
|
|
|
<Refresh />
|
|
|
|
</el-icon>
|
|
|
|
重置
|
|
|
|
</el-button>
|
|
|
|
<el-button type="primary" @click="handleAdd">
|
|
|
|
<el-icon>
|
|
|
|
<Plus />
|
|
|
|
</el-icon>
|
|
|
|
新增
|
|
|
|
</el-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ContentWrap>
|
|
|
|
|
|
...
|
...
|
@@ -30,8 +39,6 @@ |
|
|
|
<el-table-column prop="id" label="ID" sortable align="center" />
|
|
|
|
<!-- 肌肉名称列(对应接口的name字段) -->
|
|
|
|
<el-table-column prop="name" label="肌肉名称" align="center" />
|
|
|
|
<!-- 关联大类ID列 -->
|
|
|
|
<!-- <el-table-column prop="categoryId" label="关联大类ID" align="center" /> -->
|
|
|
|
<el-table-column prop="createTime" label="创建时间" align="center" :formatter="dateFormatter" />
|
|
|
|
<el-table-column prop="updateTime" label="更新时间" align="center" min-width="100" :formatter="dateFormatter" />
|
|
|
|
<!-- 操作列 -->
|
|
...
|
...
|
@@ -59,39 +66,33 @@ |
|
|
|
</div>
|
|
|
|
</ContentWrap>
|
|
|
|
|
|
|
|
<ContentWrap>
|
|
|
|
<!-- 编辑弹窗 -->
|
|
|
|
<el-dialog v-model="editDialogVisible" title="编辑肌肉信息" @close="resetEditForm">
|
|
|
|
<el-form ref="editFormRef" :rules="editRules" :model="editForm" label-width="100px">
|
|
|
|
<el-form-item label="肌肉名称" prop="name">
|
|
|
|
<el-input v-model="editForm.name" placeholder="请输入肌肉名称" />
|
|
|
|
</el-form-item>
|
|
|
|
<!-- <el-form-item label="关联大类ID" prop="categoryId">
|
|
|
|
<el-input v-model.number="editForm.categoryId" type="number" placeholder="请输入关联大类ID" />
|
|
|
|
</el-form-item> -->
|
|
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
|
|
<el-button @click="editDialogVisible = false">取消</el-button>
|
|
|
|
<el-button type="primary" @click="submitEditForm">确定</el-button>
|
|
|
|
</template>
|
|
|
|
</el-dialog>
|
|
|
|
<!-- <ContentWrap> -->
|
|
|
|
<!-- 编辑弹窗 -->
|
|
|
|
<el-dialog v-model="editDialogVisible" title="编辑肌肉信息" @close="resetEditForm">
|
|
|
|
<el-form ref="editFormRef" :rules="editRules" :model="editForm" label-width="100px">
|
|
|
|
<el-form-item label="肌肉名称" prop="name">
|
|
|
|
<el-input v-model="editForm.name" placeholder="请输入肌肉名称" />
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
|
|
<el-button @click="editDialogVisible = false">取消</el-button>
|
|
|
|
<el-button type="primary" @click="submitEditForm">确定</el-button>
|
|
|
|
</template>
|
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
<!-- 新增弹窗 -->
|
|
|
|
<el-dialog v-model="addDialogVisible" title="新增肌肉信息" @close="resetAddForm">
|
|
|
|
<el-form :model="addForm" :rules="addRules" ref="addFormRef" label-width="100px">
|
|
|
|
<el-form-item label="肌肉名称" prop="name">
|
|
|
|
<el-input v-model="addForm.name" placeholder="请输入肌肉名称" />
|
|
|
|
</el-form-item>
|
|
|
|
<!-- <el-form-item label="关联大类ID" prop="categoryId">
|
|
|
|
<el-input v-model.number="addForm.categoryId" type="number" placeholder="请输入关联大类ID" />
|
|
|
|
</el-form-item> -->
|
|
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
|
|
<el-button @click="addDialogVisible = false">取消</el-button>
|
|
|
|
<el-button type="primary" @click="submitAddForm">确定</el-button>
|
|
|
|
</template>
|
|
|
|
</el-dialog>
|
|
|
|
</ContentWrap>
|
|
|
|
<!-- 新增弹窗 -->
|
|
|
|
<el-dialog v-model="addDialogVisible" title="新增肌肉信息" @close="resetAddForm">
|
|
|
|
<el-form :model="addForm" :rules="addRules" ref="addFormRef" label-width="100px">
|
|
|
|
<el-form-item label="肌肉名称" prop="name">
|
|
|
|
<el-input v-model="addForm.name" placeholder="请输入肌肉名称" />
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
|
|
<el-button @click="addDialogVisible = false">取消</el-button>
|
|
|
|
<el-button type="primary" @click="submitAddForm">确定</el-button>
|
|
|
|
</template>
|
|
|
|
</el-dialog>
|
|
|
|
<!-- </ContentWrap> -->
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
...
|
...
|
@@ -100,7 +101,7 @@ import { ref, reactive, onMounted, watch } from 'vue' |
|
|
|
import { ElMessage, ElMessageBox, ElEmpty, ElForm, ElFormItem, ElInput, ElDialog } from 'element-plus'
|
|
|
|
// 导入你提供的接口文件
|
|
|
|
import { MusclesApi, type MusclesVO } from '@/api/store/training/muscle'
|
|
|
|
|
|
|
|
import { Search, Refresh, Plus } from '@element-plus/icons-vue'
|
|
|
|
import { dateFormatter } from '@/utils/formatTime'
|
|
|
|
|
|
|
|
// 表格数据(对应接口返回的列表)
|
|
...
|
...
|
@@ -114,9 +115,9 @@ const searchForm = reactive({ |
|
|
|
|
|
|
|
// 分页参数
|
|
|
|
const pagination = reactive({
|
|
|
|
pageNo: 1, // 替换原currentPage
|
|
|
|
pageSize: 10, // 替换原pageSize
|
|
|
|
total: 0 // 替换原total
|
|
|
|
pageNo: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
total: 0
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------------- 编辑功能相关变量 ----------------------
|
|
...
|
...
|
@@ -135,10 +136,6 @@ const editRules = reactive({ |
|
|
|
name: [
|
|
|
|
{ required: true, message: '请输入肌肉名称', trigger: 'blur' },
|
|
|
|
{ min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }
|
|
|
|
],
|
|
|
|
categoryId: [
|
|
|
|
{ required: true, message: '请输入关联大类ID', trigger: 'blur' },
|
|
|
|
{ type: 'number', min: 1, message: '关联大类ID必须为正整数', trigger: 'blur' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
...
|
...
|
@@ -157,10 +154,6 @@ const addRules = reactive({ |
|
|
|
name: [
|
|
|
|
{ required: true, message: '请输入肌肉名称', trigger: 'blur' },
|
|
|
|
{ min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' }
|
|
|
|
],
|
|
|
|
categoryId: [
|
|
|
|
{ required: true, message: '请输入关联大类ID', trigger: 'blur' },
|
|
|
|
{ type: 'number', min: 1, message: '关联大类ID必须为正整数', trigger: 'blur' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
...
|
...
|
@@ -168,25 +161,23 @@ const addRules = reactive({ |
|
|
|
const getMusclesList = async () => {
|
|
|
|
try {
|
|
|
|
loading.value = true
|
|
|
|
// 构造请求参数:参数转字符串传递
|
|
|
|
// 构造请求参数
|
|
|
|
const params = {
|
|
|
|
pageNo: pagination.pageNo + '', // 转字符串
|
|
|
|
pageSize: pagination.pageSize + '', // 转字符串
|
|
|
|
name: searchForm.name // 搜索的肌肉名称
|
|
|
|
pageNo: pagination.pageNo + '',
|
|
|
|
pageSize: pagination.pageSize + '',
|
|
|
|
name: searchForm.name
|
|
|
|
}
|
|
|
|
// 调用接口获取数据
|
|
|
|
const res = await MusclesApi.getMusclesPage(params)
|
|
|
|
// 兼容不同的接口返回格式(优先取res.data,没有则取res本身)
|
|
|
|
const result = res.data || res
|
|
|
|
tableData.value = result.list || []
|
|
|
|
pagination.total = result.total || 0
|
|
|
|
console.log('肌肉分页接口返回数据:', res)
|
|
|
|
|
|
|
|
// 分页边界处理:如果当前页大于总页数,自动切到最后一页
|
|
|
|
// 分页边界处理
|
|
|
|
const totalPages = Math.ceil(pagination.total / pagination.pageSize)
|
|
|
|
if (pagination.pageNo > totalPages && totalPages > 0) {
|
|
|
|
pagination.pageNo = totalPages
|
|
|
|
getMusclesList() // 重新请求最后一页数据
|
|
|
|
getMusclesList()
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
ElMessage.error('获取肌肉列表失败,请重试')
|
|
...
|
...
|
@@ -212,13 +203,13 @@ watch([() => pagination.total, () => pagination.pageSize], () => { |
|
|
|
})
|
|
|
|
|
|
|
|
// 4. 事件处理函数
|
|
|
|
// 搜索:保持原有逻辑,仅调整分页参数名
|
|
|
|
// 搜索
|
|
|
|
const handleSearch = () => {
|
|
|
|
pagination.pageNo = 1 // 搜索时重置页码为1
|
|
|
|
pagination.pageNo = 1
|
|
|
|
getMusclesList()
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重置:保持原有逻辑,仅调整分页参数名
|
|
|
|
// 重置
|
|
|
|
const handleReset = () => {
|
|
|
|
searchForm.name = ''
|
|
|
|
pagination.pageNo = 1
|
|
...
|
...
|
@@ -237,7 +228,6 @@ const handleAdd = () => { |
|
|
|
const resetAddForm = () => {
|
|
|
|
addForm.name = ''
|
|
|
|
addForm.categoryId = 0
|
|
|
|
// 清空表单验证状态
|
|
|
|
if (addFormRef.value) {
|
|
|
|
addFormRef.value.clearValidate()
|
|
|
|
}
|
|
...
|
...
|
@@ -247,20 +237,16 @@ const resetAddForm = () => { |
|
|
|
const submitAddForm = async () => {
|
|
|
|
if (!addFormRef.value) return
|
|
|
|
try {
|
|
|
|
// 表单验证
|
|
|
|
await addFormRef.value.validate()
|
|
|
|
// 调用新增接口(无需传id,由后端生成)
|
|
|
|
await MusclesApi.createMuscles({
|
|
|
|
...addForm,
|
|
|
|
id: 0 // 占位,后端会自动生成
|
|
|
|
id: 0
|
|
|
|
})
|
|
|
|
ElMessage.success('新增成功!')
|
|
|
|
// 关闭弹窗
|
|
|
|
addDialogVisible.value = false
|
|
|
|
// 重新加载列表数据
|
|
|
|
getMusclesList()
|
|
|
|
} catch (error) {
|
|
|
|
if (error !== 'cancel') { // 排除表单验证取消的情况
|
|
|
|
if (error !== 'cancel') {
|
|
|
|
ElMessage.error('新增失败,请重试')
|
|
|
|
console.error('新增失败:', error)
|
|
|
|
}
|
|
...
|
...
|
@@ -271,14 +257,10 @@ const submitAddForm = async () => { |
|
|
|
// 打开编辑弹窗并回显数据
|
|
|
|
const handleEdit = async (row: MusclesVO) => {
|
|
|
|
try {
|
|
|
|
// 清空编辑表单
|
|
|
|
resetEditForm()
|
|
|
|
// 打开弹窗
|
|
|
|
editDialogVisible.value = true
|
|
|
|
// 调用接口获取详情
|
|
|
|
const res = await MusclesApi.getMuscles(row.id)
|
|
|
|
const detail = res.data || res
|
|
|
|
// 回显数据到编辑表单
|
|
|
|
editForm.id = detail.id
|
|
|
|
editForm.name = detail.name
|
|
|
|
editForm.categoryId = detail.categoryId
|
|
...
|
...
|
@@ -293,7 +275,6 @@ const resetEditForm = () => { |
|
|
|
editForm.id = 0
|
|
|
|
editForm.name = ''
|
|
|
|
editForm.categoryId = 0
|
|
|
|
// 清空表单验证状态
|
|
|
|
if (editFormRef.value) {
|
|
|
|
editFormRef.value.clearValidate()
|
|
|
|
}
|
|
...
|
...
|
@@ -303,17 +284,13 @@ const resetEditForm = () => { |
|
|
|
const submitEditForm = async () => {
|
|
|
|
if (!editFormRef.value) return
|
|
|
|
try {
|
|
|
|
// 表单验证
|
|
|
|
await editFormRef.value.validate()
|
|
|
|
// 调用更新接口
|
|
|
|
await MusclesApi.updateMuscles({ ...editForm })
|
|
|
|
ElMessage.success('编辑成功!')
|
|
|
|
// 关闭弹窗
|
|
|
|
editDialogVisible.value = false
|
|
|
|
// 重新加载列表数据
|
|
|
|
getMusclesList()
|
|
|
|
} catch (error) {
|
|
|
|
if (error !== 'cancel') { // 排除表单验证取消的情况
|
|
|
|
if (error !== 'cancel') {
|
|
|
|
ElMessage.error('编辑失败,请重试')
|
|
|
|
console.error('编辑失败:', error)
|
|
|
|
}
|
|
...
|
...
|
@@ -323,7 +300,6 @@ const submitEditForm = async () => { |
|
|
|
// 删除
|
|
|
|
const handleDelete = async (row: MusclesVO) => {
|
|
|
|
try {
|
|
|
|
// 确认删除
|
|
|
|
await ElMessageBox.confirm(
|
|
|
|
'此操作将永久删除该肌肉信息,是否继续?',
|
|
|
|
'温馨提示',
|
|
...
|
...
|
@@ -333,13 +309,11 @@ const handleDelete = async (row: MusclesVO) => { |
|
|
|
type: 'warning'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
// 调用删除接口
|
|
|
|
await MusclesApi.deleteMuscles(row.id)
|
|
|
|
ElMessage.success('删除成功!')
|
|
|
|
// 重新获取列表
|
|
|
|
getMusclesList()
|
|
|
|
} catch (error) {
|
|
|
|
if (error !== 'cancel') { // 排除用户取消的情况
|
|
|
|
if (error !== 'cancel') {
|
|
|
|
ElMessage.error('删除失败,请重试')
|
|
|
|
console.error('删除失败:', error)
|
|
|
|
}
|
|
...
|
...
|
@@ -361,12 +335,44 @@ const handleCurrentChange = (val: number) => { |
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.page-container {
|
|
|
|
/* min-height: 100vh;
|
|
|
|
background: #fff; */
|
|
|
|
.plan-search-bar {
|
|
|
|
margin-bottom: 20px;
|
|
|
|
box-shadow: 0 1px 2px rgb(0 0 0 / 5%);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 核心修复:自动换行 + 自适应布局 */
|
|
|
|
.search-item {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 10px;
|
|
|
|
padding: 15px 20px;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-label {
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 输入框自适应宽度 */
|
|
|
|
.search-input {
|
|
|
|
max-width: 300px;
|
|
|
|
min-width: 200px;
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 按钮组靠右,不挤压 */
|
|
|
|
.search-buttons {
|
|
|
|
display: flex;
|
|
|
|
gap: 10px;
|
|
|
|
|
|
|
|
/* margin-left: auto; */
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.plan-search-bar) {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 新增分页样式 */
|
|
|
|
.pagination-wrapper {
|
|
|
|
display: flex;
|
|
|
|
padding: 12px 16px 0;
|
...
|
...
|
|