74 changed files with 5051 additions and 4372 deletions
@ -0,0 +1,60 @@ |
|||||
|
import request from '@/utils/request' |
||||
|
|
||||
|
|
||||
|
|
||||
|
// USER_CODE_BEGIN -- student
|
||||
|
/** |
||||
|
* 获取学员列表 |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function getStudentList(params: Record<string, any>) { |
||||
|
return request.get(`student/student`, {params}) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取学员详情 |
||||
|
* @param id 学员id |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function getStudentInfo(id: number) { |
||||
|
return request.get(`student/student/${id}`); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加学员 |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function addStudent(params: Record<string, any>) { |
||||
|
return request.post('student/student', params, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑学员 |
||||
|
* @param id |
||||
|
* @param params |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function editStudent(params: Record<string, any>) { |
||||
|
return request.put(`student/student/${params.id}`, params, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除学员 |
||||
|
* @param id |
||||
|
* @returns |
||||
|
*/ |
||||
|
export function deleteStudent(id: number) { |
||||
|
return request.delete(`student/student/${id}`, { showErrorMessage: true, showSuccessMessage: true }) |
||||
|
} |
||||
|
|
||||
|
export function getWithCampusList(params: Record<string,any>){ |
||||
|
return request.get('student/campus_all', {params}) |
||||
|
}export function getWithClassGradeList(params: Record<string,any>){ |
||||
|
return request.get('student/class_grade_all', {params}) |
||||
|
}export function getWithMemberList(params: Record<string,any>){ |
||||
|
return request.get('student/member_all', {params}) |
||||
|
} |
||||
|
|
||||
|
// USER_CODE_END -- student
|
||||
@ -0,0 +1,31 @@ |
|||||
|
{ |
||||
|
"campusId":"校区", |
||||
|
"campusIdPlaceholder":"全部", |
||||
|
"classId":"班级", |
||||
|
"classIdPlaceholder":"请输入班级", |
||||
|
"userId":"用户", |
||||
|
"userIdPlaceholder":"请输入用户", |
||||
|
"name":"学员姓名", |
||||
|
"namePlaceholder":"请输入学员姓名", |
||||
|
"gender":"性别", |
||||
|
"genderPlaceholder":"请输入性别", |
||||
|
"age":"年龄", |
||||
|
"agePlaceholder":"请输入年龄", |
||||
|
"birthday":"生日", |
||||
|
"birthdayPlaceholder":"请输入生日", |
||||
|
"emergencyContact":"紧急联系人", |
||||
|
"emergencyContactPlaceholder":"请输入紧急联系人", |
||||
|
"contactPhone":"联系人电话", |
||||
|
"contactPhonePlaceholder":"请输入联系人电话", |
||||
|
"note":"备注信息", |
||||
|
"notePlaceholder":"请输入备注信息", |
||||
|
"status":"学员状态", |
||||
|
"statusPlaceholder":"请输入学员状态", |
||||
|
"createdAt":"创建时间", |
||||
|
"createdAtPlaceholder":"请输入创建时间", |
||||
|
"addStudent":"添加学员", |
||||
|
"updateStudent":"编辑学员", |
||||
|
"studentDeleteTips":"确定要删除该数据吗?", |
||||
|
"startDate":"请选择开始时间", |
||||
|
"endDate":"请选择结束时间" |
||||
|
} |
||||
@ -0,0 +1,287 @@ |
|||||
|
<template> |
||||
|
<el-dialog v-model="showDialog" :title="formData.id ? t('updateExamQuestions') : t('addExamQuestions')" width="50%" |
||||
|
class="diy-dialog-wrap" :destroy-on-close="true"> |
||||
|
<el-form :model="formData" label-width="120px" ref="formRef" :rules="formRules" class="page-form" |
||||
|
v-loading="loading"> |
||||
|
<el-form-item :label="t('title')" prop="title"> |
||||
|
<el-input v-model="formData.title" clearable :placeholder="t('titlePlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('questionType')" prop="question_type"> |
||||
|
<el-select class="input-width" v-model="formData.question_type" clearable |
||||
|
:placeholder="t('questionTypePlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option v-for="(item, index) in question_typeList" :key="index" :label="item.name" |
||||
|
:value="item.value" /> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('questionContentType')" prop="question_content_type"> |
||||
|
<el-select class="input-width" v-model="formData.question_content_type" clearable |
||||
|
:placeholder="t('questionContentTypePlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option v-for="(item, index) in question_content_typeList" :key="index" :label="item.name" |
||||
|
:value="item.value" /> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('questionContent')" v-if="formData.question_content_type == 'text'"> |
||||
|
<el-input v-model="formData.question_content" clearable class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
|
||||
|
<el-form-item :label="t('questionContent')" v-if="formData.question_content_type == 'image'"> |
||||
|
<upload-image v-model="formData.question_content" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<!-- <el-form-item :label="t('optionJson')" prop="option_json"> |
||||
|
<el-input v-model="formData.option_json" clearable :placeholder="t('optionJsonPlaceholder')" class="input-width" /> |
||||
|
</el-form-item> --> |
||||
|
|
||||
|
<el-form-item :label="t('optionJson')"> |
||||
|
<div v-for="(option, index) in formData.option_json" :key="index" class="option-item"> |
||||
|
<el-card class="box-card" shadow="never"> |
||||
|
|
||||
|
<el-form-item label="类型" label-width="60"> |
||||
|
<el-select v-model="option.option_content_type" placeholder="请选择类型"> |
||||
|
<el-option label="文本" value="text" /> |
||||
|
<el-option label="图片" value="image" /> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item label="内容" label-width="60" style="margin-top:5px;"> |
||||
|
<template v-if="option.option_content_type === 'text'"> |
||||
|
<el-input v-model="option.option_content" placeholder="请输入选项文本" /> |
||||
|
</template> |
||||
|
<template v-else> |
||||
|
<upload-file v-model="option.option_content" /> |
||||
|
</template> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item label="答案" label-width="60"> |
||||
|
<el-switch v-model="option.correct_answer" |
||||
|
:disabled="formData.question_type === 'single_choice' && option.correct_answer" |
||||
|
@change="handleCorrectAnswerChange(index)" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item label="操作" label-width="60"> |
||||
|
<el-button @click="removeOption(index)" type="danger" size="small" plain>删除</el-button> |
||||
|
</el-form-item> |
||||
|
|
||||
|
|
||||
|
|
||||
|
</el-card> |
||||
|
</div> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item> |
||||
|
<el-button type="primary" @click="addOption">添加选项</el-button> |
||||
|
</el-form-item> |
||||
|
|
||||
|
|
||||
|
</el-form> |
||||
|
|
||||
|
<template #footer> |
||||
|
<span class="dialog-footer"> |
||||
|
<el-button @click="showDialog = false">{{ t('cancel') }}</el-button> |
||||
|
<el-button type="primary" :loading="loading" @click="confirm(formRef)">{{ |
||||
|
t('confirm') |
||||
|
}}</el-button> |
||||
|
</span> |
||||
|
</template> |
||||
|
</el-dialog> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts" setup> |
||||
|
import { ref, reactive, computed, watch } from 'vue' |
||||
|
import { useDictionary } from '@/app/api/dict' |
||||
|
import { t } from '@/lang' |
||||
|
import type { FormInstance } from 'element-plus' |
||||
|
import { addExamQuestions, editExamQuestions, getExamQuestionsInfo } from '@/app/api/exam_questions' |
||||
|
|
||||
|
let showDialog = ref(false) |
||||
|
const loading = ref(false) |
||||
|
|
||||
|
/** |
||||
|
* 表单数据 |
||||
|
*/ |
||||
|
const initialFormData = { |
||||
|
id: '', |
||||
|
title: '', |
||||
|
question_type: '', |
||||
|
question_content_type: '', |
||||
|
question_content: '', |
||||
|
option_json: [] |
||||
|
} |
||||
|
|
||||
|
const addOption = () => { |
||||
|
formData.option_json.push({ |
||||
|
option_content_type: 'text', |
||||
|
option_content: '', |
||||
|
correct_answer: false |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
const removeOption = (index) => { |
||||
|
formData.option_json.splice(index, 1) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const handleCorrectAnswerChange = (changedIndex) => { |
||||
|
if (formData.question_type === 'single_choice') { |
||||
|
formData.options.forEach((opt, i) => { |
||||
|
if (i !== changedIndex) opt.correct_answer = false |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const formData : Record<string, any> = reactive({ ...initialFormData }) |
||||
|
|
||||
|
const formRef = ref<FormInstance>() |
||||
|
|
||||
|
// 表单验证规则 |
||||
|
const formRules = computed(() => { |
||||
|
return { |
||||
|
title: [ |
||||
|
{ required: true, message: t('titlePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
question_type: [ |
||||
|
{ required: true, message: t('questionTypePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
question_content_type: [ |
||||
|
{ required: true, message: t('questionContentTypePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
question_content: [ |
||||
|
{ required: true, message: t('questionContentPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
option_json: [ |
||||
|
{ required: true, message: t('optionJsonPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
correct_answer: [ |
||||
|
{ required: true, message: t('correctAnswerPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
const emit = defineEmits(['complete']) |
||||
|
|
||||
|
/** |
||||
|
* 确认 |
||||
|
* @param formEl |
||||
|
*/ |
||||
|
const confirm = async (formEl : FormInstance | undefined) => { |
||||
|
if (loading.value || !formEl) return |
||||
|
let save = formData.id ? editExamQuestions : addExamQuestions |
||||
|
|
||||
|
await formEl.validate(async (valid) => { |
||||
|
if (valid) { |
||||
|
loading.value = true |
||||
|
|
||||
|
let data = formData |
||||
|
|
||||
|
save(data).then(res => { |
||||
|
loading.value = false |
||||
|
showDialog.value = false |
||||
|
emit('complete') |
||||
|
}).catch(err => { |
||||
|
loading.value = false |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 获取字典数据 |
||||
|
let question_typeList = ref([]) |
||||
|
const question_typeDictList = async () => { |
||||
|
question_typeList.value = await (await useDictionary('question_type')).data.dictionary |
||||
|
} |
||||
|
question_typeDictList(); |
||||
|
watch(() => question_typeList.value, () => { formData.question_type = question_typeList.value[0].value }) |
||||
|
let question_content_typeList = ref([]) |
||||
|
const question_content_typeDictList = async () => { |
||||
|
question_content_typeList.value = await (await useDictionary('question_content_type')).data.dictionary |
||||
|
} |
||||
|
question_content_typeDictList(); |
||||
|
watch(() => question_content_typeList.value, () => { formData.question_content_type = question_content_typeList.value[0].value }) |
||||
|
|
||||
|
|
||||
|
|
||||
|
const setFormData = async (row : any = null) => { |
||||
|
Object.assign(formData, initialFormData) |
||||
|
loading.value = true |
||||
|
if (row) { |
||||
|
const data = await (await getExamQuestionsInfo(row.id)).data |
||||
|
if (data) Object.keys(formData).forEach((key : string) => { |
||||
|
if (data[key] != undefined) formData[key] = data[key] |
||||
|
}) |
||||
|
} |
||||
|
loading.value = false |
||||
|
} |
||||
|
|
||||
|
// 验证手机号格式 |
||||
|
const mobileVerify = (rule : any, value : any, callback : any) => { |
||||
|
if (value && !/^1[3-9]\d{9}$/.test(value)) { |
||||
|
callback(new Error(t('generateMobile'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证身份证号 |
||||
|
const idCardVerify = (rule : any, value : any, callback : any) => { |
||||
|
if (value && !/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value)) { |
||||
|
callback(new Error(t('generateIdCard'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证邮箱号 |
||||
|
const emailVerify = (rule : any, value : any, callback : any) => { |
||||
|
if (value && !/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(value)) { |
||||
|
callback(new Error(t('generateEmail'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证请输入整数 |
||||
|
const numberVerify = (rule : any, value : any, callback : any) => { |
||||
|
if (!Number.isInteger(value)) { |
||||
|
callback(new Error(t('generateNumber'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
defineExpose({ |
||||
|
showDialog, |
||||
|
setFormData |
||||
|
}) |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped></style> |
||||
|
<style lang="scss"> |
||||
|
.diy-dialog-wrap .el-form-item__label { |
||||
|
height: auto !important; |
||||
|
} |
||||
|
|
||||
|
.option-item { |
||||
|
margin-bottom: 20px; |
||||
|
margin-right: 10px; |
||||
|
|
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,315 @@ |
|||||
|
<template> |
||||
|
<el-dialog v-model="showDialog" :title="formData.id ? t('updateStudent') : t('addStudent')" width="50%" class="diy-dialog-wrap" :destroy-on-close="true"> |
||||
|
<el-form :model="formData" label-width="120px" ref="formRef" :rules="formRules" class="page-form" v-loading="loading"> |
||||
|
<el-form-item :label="t('campusId')" > |
||||
|
<el-select class="input-width" v-model="formData.campus_id" clearable :placeholder="t('campusIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in campusIdList" |
||||
|
:key="index" |
||||
|
:label="item['campus_name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('classId')" prop="class_id"> |
||||
|
<el-select class="input-width" v-model="formData.class_id" clearable :placeholder="t('classIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in classIdList" |
||||
|
:key="index" |
||||
|
:label="item['class_name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('userId')" prop="user_id"> |
||||
|
<el-select class="input-width" v-model="formData.user_id" clearable :placeholder="t('userIdPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in userIdList" |
||||
|
:key="index" |
||||
|
:label="item['nickname']" |
||||
|
:value="item['member_id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('name')" prop="name"> |
||||
|
<el-input v-model="formData.name" clearable :placeholder="t('namePlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('gender')" prop="gender"> |
||||
|
<el-select class="input-width" v-model="formData.gender" clearable :placeholder="t('genderPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in genderList" |
||||
|
:key="index" |
||||
|
:label="item.name" |
||||
|
:value="item.value" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('age')" > |
||||
|
<el-input v-model="formData.age" clearable :placeholder="t('agePlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('birthday')" class="input-width"> |
||||
|
<el-date-picker |
||||
|
class="flex-1 !flex" |
||||
|
v-model="formData.birthday" |
||||
|
clearable |
||||
|
type="datetime" |
||||
|
value-format="YYYY-MM-DD HH:mm:ss" |
||||
|
:placeholder="t('birthdayPlaceholder')"> |
||||
|
</el-date-picker> |
||||
|
</el-form-item> |
||||
|
<el-form-item :label="t('emergencyContact')" > |
||||
|
<el-input v-model="formData.emergency_contact" clearable :placeholder="t('emergencyContactPlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('contactPhone')" > |
||||
|
<el-input v-model="formData.contact_phone" clearable :placeholder="t('contactPhonePlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('note')" > |
||||
|
<el-input v-model="formData.note" clearable :placeholder="t('notePlaceholder')" class="input-width" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('status')" prop="status"> |
||||
|
<el-select class="input-width" v-model="formData.status" clearable :placeholder="t('statusPlaceholder')"> |
||||
|
<el-option label="请选择" value=""></el-option> |
||||
|
<el-option |
||||
|
v-for="(item, index) in statusList" |
||||
|
:key="index" |
||||
|
:label="item.name" |
||||
|
:value="Number(item.value)" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
</el-form> |
||||
|
|
||||
|
<template #footer> |
||||
|
<span class="dialog-footer"> |
||||
|
<el-button @click="showDialog = false">{{ t('cancel') }}</el-button> |
||||
|
<el-button type="primary" :loading="loading" @click="confirm(formRef)">{{ |
||||
|
t('confirm') |
||||
|
}}</el-button> |
||||
|
</span> |
||||
|
</template> |
||||
|
</el-dialog> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts" setup> |
||||
|
import { ref, reactive, computed, watch } from 'vue' |
||||
|
import { useDictionary } from '@/app/api/dict' |
||||
|
import { t } from '@/lang' |
||||
|
import type { FormInstance } from 'element-plus' |
||||
|
import { addStudent, editStudent, getStudentInfo, getWithCampusList, getWithClassGradeList, getWithMemberList } from '@/app/api/student' |
||||
|
|
||||
|
let showDialog = ref(false) |
||||
|
const loading = ref(false) |
||||
|
|
||||
|
/** |
||||
|
* 表单数据 |
||||
|
*/ |
||||
|
const initialFormData = { |
||||
|
id: '', |
||||
|
campus_id: '', |
||||
|
class_id: '', |
||||
|
user_id: '', |
||||
|
name: '', |
||||
|
gender: '', |
||||
|
age: '', |
||||
|
birthday: '', |
||||
|
emergency_contact: '', |
||||
|
contact_phone: '', |
||||
|
note: '', |
||||
|
status: '', |
||||
|
} |
||||
|
const formData: Record<string, any> = reactive({ ...initialFormData }) |
||||
|
|
||||
|
const formRef = ref<FormInstance>() |
||||
|
|
||||
|
// 表单验证规则 |
||||
|
const formRules = computed(() => { |
||||
|
return { |
||||
|
campus_id: [ |
||||
|
{ required: true, message: t('campusIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
class_id: [ |
||||
|
{ required: true, message: t('classIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
user_id: [ |
||||
|
{ required: true, message: t('userIdPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
name: [ |
||||
|
{ required: true, message: t('namePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
gender: [ |
||||
|
{ required: true, message: t('genderPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
age: [ |
||||
|
{ required: true, message: t('agePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
birthday: [ |
||||
|
{ required: true, message: t('birthdayPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
emergency_contact: [ |
||||
|
{ required: true, message: t('emergencyContactPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
contact_phone: [ |
||||
|
{ required: true, message: t('contactPhonePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
note: [ |
||||
|
{ required: true, message: t('notePlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
status: [ |
||||
|
{ required: true, message: t('statusPlaceholder'), trigger: 'blur' }, |
||||
|
|
||||
|
] |
||||
|
, |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
const emit = defineEmits(['complete']) |
||||
|
|
||||
|
/** |
||||
|
* 确认 |
||||
|
* @param formEl |
||||
|
*/ |
||||
|
const confirm = async (formEl: FormInstance | undefined) => { |
||||
|
if (loading.value || !formEl) return |
||||
|
let save = formData.id ? editStudent : addStudent |
||||
|
|
||||
|
await formEl.validate(async (valid) => { |
||||
|
if (valid) { |
||||
|
loading.value = true |
||||
|
|
||||
|
let data = formData |
||||
|
|
||||
|
save(data).then(res => { |
||||
|
loading.value = false |
||||
|
showDialog.value = false |
||||
|
emit('complete') |
||||
|
}).catch(err => { |
||||
|
loading.value = false |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// 获取字典数据 |
||||
|
let genderList = ref([]) |
||||
|
const genderDictList = async () => { |
||||
|
genderList.value = await (await useDictionary('gender')).data.dictionary |
||||
|
} |
||||
|
genderDictList(); |
||||
|
watch(() => genderList.value, () => { formData.gender = genderList.value[0].value }) |
||||
|
let statusList = ref([]) |
||||
|
const statusDictList = async () => { |
||||
|
statusList.value = await (await useDictionary('xy_status')).data.dictionary |
||||
|
} |
||||
|
statusDictList(); |
||||
|
watch(() => statusList.value, () => { formData.status = statusList.value[0].value }) |
||||
|
|
||||
|
|
||||
|
const campusIdList = ref([] as any[]) |
||||
|
const setCampusIdList = async () => { |
||||
|
campusIdList.value = await (await getWithCampusList({})).data |
||||
|
} |
||||
|
setCampusIdList() |
||||
|
const classIdList = ref([] as any[]) |
||||
|
const setClassIdList = async () => { |
||||
|
classIdList.value = await (await getWithClassGradeList({})).data |
||||
|
} |
||||
|
setClassIdList() |
||||
|
const userIdList = ref([] as any[]) |
||||
|
const setUserIdList = async () => { |
||||
|
userIdList.value = await (await getWithMemberList({})).data |
||||
|
} |
||||
|
setUserIdList() |
||||
|
const setFormData = async (row: any = null) => { |
||||
|
Object.assign(formData, initialFormData) |
||||
|
loading.value = true |
||||
|
if(row){ |
||||
|
const data = await (await getStudentInfo(row.id)).data |
||||
|
if (data) Object.keys(formData).forEach((key: string) => { |
||||
|
if (data[key] != undefined) formData[key] = data[key] |
||||
|
}) |
||||
|
} |
||||
|
loading.value = false |
||||
|
} |
||||
|
|
||||
|
// 验证手机号格式 |
||||
|
const mobileVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/^1[3-9]\d{9}$/.test(value)) { |
||||
|
callback(new Error(t('generateMobile'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证身份证号 |
||||
|
const idCardVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value)) { |
||||
|
callback(new Error(t('generateIdCard'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证邮箱号 |
||||
|
const emailVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (value && !/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(value)) { |
||||
|
callback(new Error(t('generateEmail'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 验证请输入整数 |
||||
|
const numberVerify = (rule: any, value: any, callback: any) => { |
||||
|
if (!Number.isInteger(value)) { |
||||
|
callback(new Error(t('generateNumber'))) |
||||
|
} else { |
||||
|
callback() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
defineExpose({ |
||||
|
showDialog, |
||||
|
setFormData |
||||
|
}) |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped></style> |
||||
|
<style lang="scss"> |
||||
|
.diy-dialog-wrap .el-form-item__label{ |
||||
|
height: auto !important; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,240 @@ |
|||||
|
<template> |
||||
|
<div class="main-container"> |
||||
|
<el-card class="box-card !border-none" shadow="never"> |
||||
|
|
||||
|
<div class="flex justify-between items-center"> |
||||
|
<span class="text-lg">{{pageName}}</span> |
||||
|
<el-button type="primary" @click="addEvent"> |
||||
|
{{ t('addStudent') }} |
||||
|
</el-button> |
||||
|
</div> |
||||
|
|
||||
|
<el-card class="box-card !border-none my-[10px] table-search-wrap" shadow="never"> |
||||
|
<el-form :inline="true" :model="studentTable.searchParam" ref="searchFormRef"> |
||||
|
|
||||
|
<el-form-item :label="t('campusId')" prop="campus_id"> |
||||
|
<el-select class="w-[280px]" v-model="studentTable.searchParam.campus_id" clearable :placeholder="t('campusIdPlaceholder')"> |
||||
|
<el-option |
||||
|
v-for="(item, index) in campusIdList" |
||||
|
:key="index" |
||||
|
:label="item['campus_name']" |
||||
|
:value="item['id']" |
||||
|
/> |
||||
|
</el-select> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item :label="t('name')" prop="name"> |
||||
|
<el-input v-model="studentTable.searchParam.name" :placeholder="t('namePlaceholder')" /> |
||||
|
</el-form-item> |
||||
|
<el-form-item :label="t('emergencyContact')" prop="emergency_contact"> |
||||
|
<el-input v-model="studentTable.searchParam.emergency_contact" :placeholder="t('emergencyContactPlaceholder')" /> |
||||
|
</el-form-item> |
||||
|
<el-form-item :label="t('contactPhone')" prop="contact_phone"> |
||||
|
<el-input v-model="studentTable.searchParam.contact_phone" :placeholder="t('contactPhonePlaceholder')" /> |
||||
|
</el-form-item> |
||||
|
<el-form-item :label="t('createdAt')" prop="created_at"> |
||||
|
<el-date-picker v-model="studentTable.searchParam.created_at" type="datetimerange" format="YYYY-MM-DD hh:mm:ss" |
||||
|
:start-placeholder="t('startDate')" :end-placeholder="t('endDate')" /> |
||||
|
</el-form-item> |
||||
|
|
||||
|
<el-form-item> |
||||
|
<el-button type="primary" @click="loadStudentList()">{{ t('search') }}</el-button> |
||||
|
<el-button @click="resetForm(searchFormRef)">{{ t('reset') }}</el-button> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
</el-card> |
||||
|
|
||||
|
<div class="mt-[10px]"> |
||||
|
<el-table :data="studentTable.data" size="large" v-loading="studentTable.loading"> |
||||
|
<template #empty> |
||||
|
<span>{{ !studentTable.loading ? t('emptyData') : '' }}</span> |
||||
|
</template> |
||||
|
<el-table-column prop="campus_id_name" :label="t('campusId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="class_id_name" :label="t('classId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="user_id_name" :label="t('userId')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="name" :label="t('name')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column :label="t('gender')" min-width="180" align="center" :show-overflow-tooltip="true"> |
||||
|
<template #default="{ row }"> |
||||
|
<div v-for="(item, index) in genderList"> |
||||
|
<div v-if="item.value == row.gender">{{ item.name }}</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
<el-table-column prop="age" :label="t('age')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="emergency_contact" :label="t('emergencyContact')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="contact_phone" :label="t('contactPhone')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column prop="note" :label="t('note')" min-width="120" :show-overflow-tooltip="true"/> |
||||
|
|
||||
|
<el-table-column :label="t('status')" min-width="180" align="center" :show-overflow-tooltip="true"> |
||||
|
<template #default="{ row }"> |
||||
|
<div v-for="(item, index) in statusList"> |
||||
|
<div v-if="item.value == row.status">{{ item.name }}</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
<el-table-column :label="t('operation')" fixed="right" min-width="120"> |
||||
|
<template #default="{ row }"> |
||||
|
<el-button type="primary" link @click="editEvent(row)">{{ t('edit') }}</el-button> |
||||
|
<el-button type="primary" link @click="deleteEvent(row.id)">{{ t('delete') }}</el-button> |
||||
|
</template> |
||||
|
</el-table-column> |
||||
|
|
||||
|
</el-table> |
||||
|
<div class="mt-[16px] flex justify-end"> |
||||
|
<el-pagination v-model:current-page="studentTable.page" v-model:page-size="studentTable.limit" |
||||
|
layout="total, sizes, prev, pager, next, jumper" :total="studentTable.total" |
||||
|
@size-change="loadStudentList()" @current-change="loadStudentList" /> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<edit ref="editStudentDialog" @complete="loadStudentList" /> |
||||
|
</el-card> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script lang="ts" setup> |
||||
|
import { reactive, ref, watch } from 'vue' |
||||
|
import { t } from '@/lang' |
||||
|
import { useDictionary } from '@/app/api/dict' |
||||
|
import { getStudentList, deleteStudent, getWithCampusList, getWithClassGradeList, getWithMemberList } from '@/app/api/student' |
||||
|
import { img } from '@/utils/common' |
||||
|
import { ElMessageBox,FormInstance } from 'element-plus' |
||||
|
import Edit from '@/app/views/student/components/student-edit.vue' |
||||
|
import { useRoute } from 'vue-router' |
||||
|
const route = useRoute() |
||||
|
const pageName = route.meta.title; |
||||
|
|
||||
|
let studentTable = reactive({ |
||||
|
page: 1, |
||||
|
limit: 10, |
||||
|
total: 0, |
||||
|
loading: true, |
||||
|
data: [], |
||||
|
searchParam:{ |
||||
|
"campus_id":"", |
||||
|
"name":"", |
||||
|
"emergency_contact":"", |
||||
|
"contact_phone":"", |
||||
|
"created_at":[] |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
const searchFormRef = ref<FormInstance>() |
||||
|
|
||||
|
// 选中数据 |
||||
|
const selectData = ref<any[]>([]) |
||||
|
|
||||
|
// 字典数据 |
||||
|
const genderList = ref([] as any[]) |
||||
|
const genderDictList = async () => { |
||||
|
genderList.value = await (await useDictionary('gender')).data.dictionary |
||||
|
} |
||||
|
genderDictList(); |
||||
|
const statusList = ref([] as any[]) |
||||
|
const statusDictList = async () => { |
||||
|
statusList.value = await (await useDictionary('xy_status')).data.dictionary |
||||
|
} |
||||
|
statusDictList(); |
||||
|
|
||||
|
/** |
||||
|
* 获取学员列表 |
||||
|
*/ |
||||
|
const loadStudentList = (page: number = 1) => { |
||||
|
studentTable.loading = true |
||||
|
studentTable.page = page |
||||
|
|
||||
|
getStudentList({ |
||||
|
page: studentTable.page, |
||||
|
limit: studentTable.limit, |
||||
|
...studentTable.searchParam |
||||
|
}).then(res => { |
||||
|
studentTable.loading = false |
||||
|
studentTable.data = res.data.data |
||||
|
studentTable.total = res.data.total |
||||
|
}).catch(() => { |
||||
|
studentTable.loading = false |
||||
|
}) |
||||
|
} |
||||
|
loadStudentList() |
||||
|
|
||||
|
const editStudentDialog: Record<string, any> | null = ref(null) |
||||
|
|
||||
|
/** |
||||
|
* 添加学员 |
||||
|
*/ |
||||
|
const addEvent = () => { |
||||
|
editStudentDialog.value.setFormData() |
||||
|
editStudentDialog.value.showDialog = true |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 编辑学员 |
||||
|
* @param data |
||||
|
*/ |
||||
|
const editEvent = (data: any) => { |
||||
|
editStudentDialog.value.setFormData(data) |
||||
|
editStudentDialog.value.showDialog = true |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除学员 |
||||
|
*/ |
||||
|
const deleteEvent = (id: number) => { |
||||
|
ElMessageBox.confirm(t('studentDeleteTips'), t('warning'), |
||||
|
{ |
||||
|
confirmButtonText: t('confirm'), |
||||
|
cancelButtonText: t('cancel'), |
||||
|
type: 'warning', |
||||
|
} |
||||
|
).then(() => { |
||||
|
deleteStudent(id).then(() => { |
||||
|
loadStudentList() |
||||
|
}).catch(() => { |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const campusIdList = ref([]) |
||||
|
const setCampusIdList = async () => { |
||||
|
campusIdList.value = await (await getWithCampusList({})).data |
||||
|
} |
||||
|
setCampusIdList() |
||||
|
const classIdList = ref([]) |
||||
|
const setClassIdList = async () => { |
||||
|
classIdList.value = await (await getWithClassGradeList({})).data |
||||
|
} |
||||
|
setClassIdList() |
||||
|
const userIdList = ref([]) |
||||
|
const setUserIdList = async () => { |
||||
|
userIdList.value = await (await getWithMemberList({})).data |
||||
|
} |
||||
|
setUserIdList() |
||||
|
|
||||
|
const resetForm = (formEl: FormInstance | undefined) => { |
||||
|
if (!formEl) return |
||||
|
formEl.resetFields() |
||||
|
loadStudentList() |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
/* 多行超出隐藏 */ |
||||
|
.multi-hidden { |
||||
|
word-break: break-all; |
||||
|
text-overflow: ellipsis; |
||||
|
overflow: hidden; |
||||
|
display: -webkit-box; |
||||
|
-webkit-line-clamp: 2; |
||||
|
-webkit-box-orient: vertical; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,121 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\adminapi\controller\student; |
||||
|
|
||||
|
use core\base\BaseAdminController; |
||||
|
use app\service\admin\student\StudentService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 学员控制器 |
||||
|
* Class Student |
||||
|
* @package app\adminapi\controller\student |
||||
|
*/ |
||||
|
class Student extends BaseAdminController |
||||
|
{ |
||||
|
/** |
||||
|
* 获取学员列表 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function lists(){ |
||||
|
$data = $this->request->params([ |
||||
|
["campus_id",""], |
||||
|
["name",""], |
||||
|
["emergency_contact",""], |
||||
|
["contact_phone",""], |
||||
|
["created_at",["",""]] |
||||
|
]); |
||||
|
return success((new StudentService())->getPage($data)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 学员详情 |
||||
|
* @param int $id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function info(int $id){ |
||||
|
return success((new StudentService())->getInfo($id)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加学员 |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function add(){ |
||||
|
$data = $this->request->params([ |
||||
|
["campus_id",0], |
||||
|
["class_id",0], |
||||
|
["user_id",0], |
||||
|
["name",""], |
||||
|
["gender",0], |
||||
|
["age",0.00], |
||||
|
["birthday","2025-05-23 17:31:39"], |
||||
|
["emergency_contact",""], |
||||
|
["contact_phone",""], |
||||
|
["note",""], |
||||
|
["status",0], |
||||
|
|
||||
|
]); |
||||
|
$this->validate($data, 'app\validate\student\Student.add'); |
||||
|
$id = (new StudentService())->add($data); |
||||
|
return success('ADD_SUCCESS', ['id' => $id]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 学员编辑 |
||||
|
* @param $id 学员id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function edit(int $id){ |
||||
|
$data = $this->request->params([ |
||||
|
["campus_id",0], |
||||
|
["class_id",0], |
||||
|
["user_id",0], |
||||
|
["name",""], |
||||
|
["gender",0], |
||||
|
["age",0.00], |
||||
|
["birthday","2025-05-23 17:31:39"], |
||||
|
["emergency_contact",""], |
||||
|
["contact_phone",""], |
||||
|
["note",""], |
||||
|
["status",0], |
||||
|
|
||||
|
]); |
||||
|
$this->validate($data, 'app\validate\student\Student.edit'); |
||||
|
(new StudentService())->edit($id, $data); |
||||
|
return success('EDIT_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 学员删除 |
||||
|
* @param $id 学员id |
||||
|
* @return \think\Response |
||||
|
*/ |
||||
|
public function del(int $id){ |
||||
|
(new StudentService())->del($id); |
||||
|
return success('DELETE_SUCCESS'); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function getCampusAll(){ |
||||
|
return success(( new StudentService())->getCampusAll()); |
||||
|
} |
||||
|
|
||||
|
public function getClassGradeAll(){ |
||||
|
return success(( new StudentService())->getClassGradeAll()); |
||||
|
} |
||||
|
|
||||
|
public function getMemberAll(){ |
||||
|
return success(( new StudentService())->getMemberAll()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
use think\facade\Route; |
||||
|
|
||||
|
use app\adminapi\middleware\AdminCheckRole; |
||||
|
use app\adminapi\middleware\AdminCheckToken; |
||||
|
use app\adminapi\middleware\AdminLog; |
||||
|
|
||||
|
// USER_CODE_BEGIN -- student |
||||
|
|
||||
|
Route::group('student', function () { |
||||
|
|
||||
|
//学员列表 |
||||
|
Route::get('student', 'student.Student/lists'); |
||||
|
//学员详情 |
||||
|
Route::get('student/:id', 'student.Student/info'); |
||||
|
//添加学员 |
||||
|
Route::post('student', 'student.Student/add'); |
||||
|
//编辑学员 |
||||
|
Route::put('student/:id', 'student.Student/edit'); |
||||
|
//删除学员 |
||||
|
Route::delete('student/:id', 'student.Student/del'); |
||||
|
|
||||
|
Route::get('campus_all','student.Student/getCampusAll'); |
||||
|
|
||||
|
Route::get('class_grade_all','student.Student/getClassGradeAll'); |
||||
|
|
||||
|
Route::get('member_all','student.Student/getMemberAll'); |
||||
|
|
||||
|
})->middleware([ |
||||
|
AdminCheckToken::class, |
||||
|
AdminCheckRole::class, |
||||
|
AdminLog::class |
||||
|
]); |
||||
|
// USER_CODE_END -- student |
||||
@ -0,0 +1,117 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\service\admin\student; |
||||
|
|
||||
|
use app\model\student\Student; |
||||
|
use app\model\campus\Campus; |
||||
|
use app\model\class_grade\ClassGrade; |
||||
|
use app\model\member\Member; |
||||
|
|
||||
|
use core\base\BaseAdminService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 学员服务层 |
||||
|
* Class StudentService |
||||
|
* @package app\service\admin\student |
||||
|
*/ |
||||
|
class StudentService extends BaseAdminService |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
$this->model = new Student(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取学员列表 |
||||
|
* @param array $where |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getPage(array $where = []) |
||||
|
{ |
||||
|
$field = 'id,campus_id,class_id,user_id,name,gender,age,birthday,emergency_contact,contact_phone,note,status,created_at,updated_at,deleted_at'; |
||||
|
$order = 'id asc'; |
||||
|
|
||||
|
$search_model = $this->model->withSearch(["campus_id","name","emergency_contact","contact_phone","created_at"], $where)->with(['campus','classGrade','member'])->field($field)->order($order); |
||||
|
$list = $this->pageQuery($search_model); |
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取学员信息 |
||||
|
* @param int $id |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function getInfo(int $id) |
||||
|
{ |
||||
|
$field = 'id,campus_id,class_id,user_id,name,gender,age,birthday,emergency_contact,contact_phone,note,status,created_at,updated_at,deleted_at'; |
||||
|
|
||||
|
$info = $this->model->field($field)->where([['id', "=", $id]])->with(['campus','classGrade','member'])->findOrEmpty()->toArray(); |
||||
|
return $info; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加学员 |
||||
|
* @param array $data |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function add(array $data) |
||||
|
{ |
||||
|
$res = $this->model->create($data); |
||||
|
return $res->id; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 学员编辑 |
||||
|
* @param int $id |
||||
|
* @param array $data |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function edit(int $id, array $data) |
||||
|
{ |
||||
|
|
||||
|
$this->model->where([['id', '=', $id]])->update($data); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 删除学员 |
||||
|
* @param int $id |
||||
|
* @return bool |
||||
|
*/ |
||||
|
public function del(int $id) |
||||
|
{ |
||||
|
$model = $this->model->where([['id', '=', $id]])->find(); |
||||
|
$res = $model->delete(); |
||||
|
return $res; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public function getCampusAll(){ |
||||
|
$campusModel = new Campus(); |
||||
|
return $campusModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
public function getClassGradeAll(){ |
||||
|
$classGradeModel = new ClassGrade(); |
||||
|
return $classGradeModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
public function getMemberAll(){ |
||||
|
$memberModel = new Member(); |
||||
|
return $memberModel->select()->toArray(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
<?php |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Niucloud-admin 企业快速开发的多应用管理平台 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | 官方网址:https://www.niucloud.com |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | niucloud团队 版权所有 开源版本可自由商用 |
||||
|
// +---------------------------------------------------------------------- |
||||
|
// | Author: Niucloud Team |
||||
|
// +---------------------------------------------------------------------- |
||||
|
|
||||
|
namespace app\validate\student; |
||||
|
use core\base\BaseValidate; |
||||
|
/** |
||||
|
* 学员验证器 |
||||
|
* Class Student |
||||
|
* @package addon\app\validate\student |
||||
|
*/ |
||||
|
class Student extends BaseValidate |
||||
|
{ |
||||
|
|
||||
|
protected $rule = [ |
||||
|
'class_id' => 'require', |
||||
|
'user_id' => 'require', |
||||
|
'name' => 'require', |
||||
|
'gender' => 'require', |
||||
|
'status' => 'require', |
||||
|
]; |
||||
|
|
||||
|
protected $message = [ |
||||
|
'class_id.require' => ['common_validate.require', ['class_id']], |
||||
|
'user_id.require' => ['common_validate.require', ['user_id']], |
||||
|
'name.require' => ['common_validate.require', ['name']], |
||||
|
'gender.require' => ['common_validate.require', ['gender']], |
||||
|
'status.require' => ['common_validate.require', ['status']], |
||||
|
]; |
||||
|
|
||||
|
protected $scene = [ |
||||
|
"add" => ['campus_id', 'class_id', 'user_id', 'name', 'gender', 'age', 'birthday', 'emergency_contact', 'contact_phone', 'note', 'status'], |
||||
|
"edit" => ['campus_id', 'class_id', 'user_id', 'name', 'gender', 'age', 'birthday', 'emergency_contact', 'contact_phone', 'note', 'status'] |
||||
|
]; |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue