feat: 添加新增教练功能

This commit is contained in:
hyql 2026-07-09 12:25:39 +08:00
commit b07f961685
2 changed files with 47 additions and 15 deletions

View file

@ -56,3 +56,14 @@ export const rejoin = (id) => {
const target = list.find(item => item.id === id) const target = list.find(item => item.id === id)
target.quitDate = null target.quitDate = null
} }
// 新增教练
export const add = (coach) => {
const newCoach = {
id: list.length === 0 ? 1 : list[list.length -1].id + 1,
...coach,
quitDate: null
}
list.push(newCoach)
}

View file

@ -1,19 +1,35 @@
<script setup> <script setup>
import { reactive } from 'vue' import { ElMessage } from 'element-plus';
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router';
import { add } from '@/mock/coach';
import { Plus } from '@element-plus/icons-vue';
const router = useRouter()
const formRef = ref(null)
const coach = reactive({ const coach = reactive({
name: " ", name: " ",
sex: 1, sex: 1,
//avater:"" avatar: "",
remark: "" remark: ""
}) })
const rules = {
name: [
{ required: true, message: "教练名字不能为空", trigger: "blur" },
{ min: 2, max: 20, message: "教练名字长度 2-20", trigger: "blur" }
]
}
const addHandler = async () => {
await formRef.value.validate()
add(coach)
ElMessage({ type: "success", message: `教练"${coach.name}"添加成功` })
router.replace("/coach")
}
</script> </script>
<template> <template>
<el-form label-width="100px" label-position="left"> <el-form label-width="100px" label-position="left" ref="formRef" :model="coach" :rules="rules">
<h2 class="title">——新增教练——</h2> <h2 class="title">——新增教练——</h2>
<el-form-item label="教练名字"> <el-form-item label="教练名字" prop="name">
<el-input placeholder="请输入.." v-model.trim="coach.name"></el-input> <el-input placeholder="请输入.." v-model.trim="coach.name"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="性别:"> <el-form-item label="性别:">
@ -22,23 +38,28 @@ const coach = reactive({
<el-radio :value="2">女</el-radio> <el-radio :value="2">女</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="头像: ">
<el-upload class="avatar-uploader" action="" :auto-upload="false" list-type="picture-card">
<el-icon class="avatar-uploader-icon">
<Plus />
</el-icon>
<template #tip>
<div style="color:red;">提示:上传300*300的png/jpg图片</div>
</template>
</el-upload>
</el-form-item>
<el-form-item label="备注"> <el-form-item label="备注">
<el-input v-model.trim="coach.remark" type="textarea" :rows="5" placeholder="请输入教练备注..."></el-input> <el-input v-model.trim="coach.remark" type="textarea" :rows="5" placeholder="请输入教练备注..."></el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary">确定</el-button> <el-button type="primary" @click="addHandler">确定</el-button>
<el-button>取消</el-button> <el-button>取消</el-button>
</el-form-item> </el-form-item>
</el-form></template>
</el-form>
</template>
<style scoped> <style scoped>
.title { .title {
text-align: center; text-align: center;
margin-bottom: 30px; margin-bottom: 30px;
color: #333; color: rgb(196, 86, 86);
} }
</style> </style>