提交代码,在sys_user表中新增了account_type字段来区分学生和老师
This commit is contained in:
1 parent
b215f7b9b3
commit
0c6d70cc4c
26 files changed
+5917
-3
No files matched your search
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<el-dialog :title="getScopeDialogTitle(type)" v-model="visible" width="600px" append-to-body destroy-on-close>
|
||||
<el-form :model="form" label-width="100px">
|
||||
<el-form-item :label="getScopeName(type)">
|
||||
<div v-if="type === 'custom'">
|
||||
<el-checkbox-group v-model="form.selectedScopes">
|
||||
<el-checkbox v-for="item in scopeOptions.custom" :key="item.id" :label="item.id">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
<div v-else-if="type === 'teacher'">
|
||||
<el-checkbox-group v-model="form.selectedScopes">
|
||||
<el-checkbox v-for="item in scopeOptions.teacher" :key="item.id" :label="item.id">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
admin: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'custom'
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'submit']);
|
||||
|
||||
// 计算属性:对话框可见性
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
});
|
||||
|
||||
// 范围选项(模拟数据)
|
||||
const scopeOptions = {
|
||||
custom: [
|
||||
{ id: 1, name: '高一年级' },
|
||||
{ id: 2, name: '高二年级' },
|
||||
{ id: 3, name: '高三年级' },
|
||||
{ id: 4, name: '初一年级' },
|
||||
{ id: 5, name: '初二年级' },
|
||||
{ id: 6, name: '初三年级' }
|
||||
],
|
||||
teacher: [
|
||||
{ id: 101, name: '高一(1)班' },
|
||||
{ id: 102, name: '高一(2)班' },
|
||||
{ id: 103, name: '高一(3)班' },
|
||||
{ id: 104, name: '高二(1)班' },
|
||||
{ id: 105, name: '高二(2)班' },
|
||||
{ id: 106, name: '高三(1)班' },
|
||||
{ id: 107, name: '高三(2)班' }
|
||||
]
|
||||
};
|
||||
|
||||
// 表单数据
|
||||
const form = reactive({
|
||||
selectedScopes: [] as number[]
|
||||
});
|
||||
|
||||
// 获取范围对话框标题
|
||||
function getScopeDialogTitle(type: string) {
|
||||
const name = props.admin?.name || '';
|
||||
switch (type) {
|
||||
case 'custom':
|
||||
return `为【${name}】分配管理范围`;
|
||||
case 'teacher':
|
||||
return `为【${name}】分配班级`;
|
||||
default:
|
||||
return `为【${name}】分配范围`;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取范围名称
|
||||
function getScopeName(type: string) {
|
||||
switch (type) {
|
||||
case 'custom':
|
||||
return '管理范围';
|
||||
case 'teacher':
|
||||
return '所管理班级';
|
||||
default:
|
||||
return '管理范围';
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
// 组装要提交的数据
|
||||
const selectedIds = form.selectedScopes;
|
||||
let scopeName = '';
|
||||
|
||||
// 根据类型获取选中的名称
|
||||
if (type.value === 'custom') {
|
||||
scopeName = scopeOptions.custom
|
||||
.filter((item) => selectedIds.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
.join(', ');
|
||||
} else if (type.value === 'teacher') {
|
||||
scopeName = scopeOptions.teacher
|
||||
.filter((item) => selectedIds.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
// 提交
|
||||
emit('submit', {
|
||||
sourceIds: selectedIds,
|
||||
scopeName: scopeName
|
||||
});
|
||||
|
||||
ElMessage.success('分配成功');
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 取消
|
||||
function cancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 从props获取类型的响应式引用
|
||||
const type = computed(() => props.type);
|
||||
|
||||
// 暴露组件以修复导出问题
|
||||
defineExpose({
|
||||
submitForm,
|
||||
cancel
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.el-checkbox-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.el-checkbox {
|
||||
margin-right: 15px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user