fix:个人中心修改;

This commit is contained in:
小杨 2024-10-30 10:50:30 +08:00
parent bc8b80e7d7
commit 7a18c1927a
5 changed files with 223 additions and 57 deletions

View File

@ -0,0 +1,157 @@
<template>
<div>
<el-dialog v-model="dialogVisible" title="加入班级" width="50%" append-to-body>
<el-form
style="width: 100%"
label-width="auto"
:model="classForm"
:rules="rules"
ref="myForm"
>
<el-form-item label="老师" style="margin-right: 10px; width: 50%">
<el-text>
{{ userStore.nickName }}
</el-text>
</el-form-item>
<el-form-item label="班级">
<el-tree-select
v-model="classids"
:data="gradeTree"
multiple
:render-after-expand="false"
style="width: 240px"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="btnSave"> </el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { ref, defineExpose,reactive } from 'vue'
import { listClassmain, addClasses } from '@/api/classManage/index'
import { ElMessage } from 'element-plus'
import useUserStore from '@/store/modules/user'
//
const dialogVisible = ref(false)
const userStore = useUserStore().user
const classids = ref([])
//
const classList = ref([])
//
const gradeTree = ref([])
//
const classesNotAMemberOf = ref([])
//
const currentIndex = ref(0)
const newGradeList = reactive([
[
{ label: '一年级', agekey: 1, checked: false, current: 1 },
{ label: '二年级', agekey: 2, checked: false, current: 1 },
{ label: '三年级', agekey: 3, checked: false, current: 1 },
{ label: '四年级', agekey: 4, checked: false, current: 1 },
{ label: '五年级', agekey: 5, checked: false, current: 1 },
{ label: '六年级', agekey: 6, checked: false, current: 1 },
],
[
{ label: '初一', agekey: 7, checked: false, current: 2 },
{ label: '初二', agekey: 8, checked: false, current: 2 },
{ label: '初三', agekey: 9, checked: false, current: 2 },
],
[
{ label: '高一', agekey: 10, checked: false, current: 3 },
{ label: '高二', agekey: 11, checked: false, current: 3 },
{ label: '高三', agekey: 12, checked: false, current: 3 },
],
])
//
const open = () => {
dialogVisible.value = true
getClassInfo()
}
//
const btnSave = () => {
addClasses({ classIds: classids.value.join(','), userId: userStore.userId }).then(res => {
if (res.code === 200) {
dialogVisible.value = false
ElMessage({
message: res.msg,
type: 'success',
})
//
classids.value = []
} else {
ElMessage({
message: res.msg,
type: 'warning',
})
}
})
}
//
const getClassInfo = () => {
classList.value = []
listClassmain({ classuserid: userStore.userId, pageSize: 100, status: 'open' }).then(response => {
classList.value = [...response.rows]
if(classList.value.length > 0){
currentIndex.value = 0
}
});
listClassmain({entpid: userStore.deptId, status: 'open', pageSize: 100}).then(response => {
//
classesNotAMemberOf.value = [...response.rows]
classList.value.forEach(item => {
const currentIndex = classesNotAMemberOf.value.findIndex(items => items.id === item.id)
if(currentIndex) classesNotAMemberOf.value.splice(currentIndex, 1)
})
//
gradeTree.value = groupByCondition(classesNotAMemberOf.value, item => item.agekey);
})
}
//
function groupByCondition(arr, condition) {
//
const groups = arr.reduce((groups, item) => {
const groupKey = condition(item);
item.label = item.caption
item.value = item.id
groups[groupKey] = groups[groupKey] || [];
groups[groupKey].push(item);
return groups;
}, {});
//
const formattedGroups = Object.keys(groups).map(key => ({
label: gradeName(key),
value:key,
children: groups[key]
}));
return formattedGroups;
}
//key
function gradeName(key){
//
const flatGradeDataList = newGradeList.flat();
const currentIndex = flatGradeDataList.findIndex(item => item.agekey === Number(key));
if(currentIndex !== -1){
return flatGradeDataList[currentIndex].label;
}else{
//
const defaultLabel = '社团';
flatGradeDataList[currentIndex] = { ...flatGradeDataList[currentIndex], label: defaultLabel };
return defaultLabel;
}
}
defineExpose({
open
})
</script>

View File

@ -1,12 +1,15 @@
<template> <template>
<div v-for="(item,index) in classList" :key="index"> <div style="display: flex;flex-wrap: wrap;align-items: center;">
<div>{{item.caption}}</div> <div v-for="(item,index) in classList" :key="index" style="margin-right: 10px;cursor: pointer;">
<el-tag type="primary">{{item.caption}}</el-tag>
</div> </div>
<el-button type="primary" link>加入班级</el-button> <el-button type="primary" link @click="addClass">加入班级</el-button>
</template> <AddClass ref="addClassRef" />
</div>
</template>
<script setup> <script setup>
import {onMounted, ref} from "vue"; import {onMounted, ref} from "vue";
import AddClass from './addClass.vue'
const props = defineProps({ const props = defineProps({
classList:{ classList:{
type:Array, type:Array,
@ -15,6 +18,10 @@
type:Array, type:Array,
} }
}) })
const addClassRef = ref()
const addClass = () => {
addClassRef.value.open()
}
onMounted(() => { onMounted(() => {
}) })

View File

@ -1,39 +1,41 @@
<template> <template>
<div style="margin-left: 15px"> <div style="display: flex;">
<el-dropdown @command="handleUserEduStage"> <div style="margin-left: 15px">
<span class="el-dropdown-link"> <el-dropdown @command="handleUserEduStage">
<el-button class="custom-button" type="default" round >{{ userStore.edustage }} <span class="el-dropdown-link">
<el-icon><ArrowDown /></el-icon> <el-button class="custom-button" type="default" round >{{ userStore.edustage }}
</el-button> <el-icon><ArrowDown /></el-icon>
</span> </el-button>
<template #dropdown> </span>
<el-dropdown-menu> <template #dropdown>
<el-dropdown-item command="幼儿园">幼儿园</el-dropdown-item> <el-dropdown-menu>
<el-dropdown-item command="小学">小学</el-dropdown-item> <el-dropdown-item command="幼儿园">幼儿园</el-dropdown-item>
<el-dropdown-item command="初中">初中</el-dropdown-item> <el-dropdown-item command="小学">小学</el-dropdown-item>
<el-dropdown-item command="高中">高中</el-dropdown-item> <el-dropdown-item command="初中">初中</el-dropdown-item>
</el-dropdown-menu> <el-dropdown-item command="高中">高中</el-dropdown-item>
</template> </el-dropdown-menu>
</el-dropdown>
</div>
<div style="margin-left: 15px">
<el-dropdown @command="handleUserEduSubject">
<span class="el-dropdown-link">
<el-button class="custom-button" type="default" round>{{ userStore.edusubject }}
<el-icon><ArrowDown /></el-icon>
</el-button>
</span>
<template #dropdown>
<el-dropdown-menu>
<template v-for="(item, index) in subjectList">
<el-dropdown-item v-if="item.edustage == userStore.edustage" :command="item.itemtitle">{{
item.itemtitle }}</el-dropdown-item>
</template> </template>
</el-dropdown-menu> </el-dropdown>
</template> </div>
</el-dropdown> <div style="margin-left: 15px">
<el-dropdown @command="handleUserEduSubject">
<span class="el-dropdown-link">
<el-button class="custom-button" type="default" round>{{ userStore.edusubject }}
<el-icon><ArrowDown /></el-icon>
</el-button>
</span>
<template #dropdown>
<el-dropdown-menu>
<template v-for="(item, index) in subjectList">
<el-dropdown-item :command="item.itemtitle">{{
item.itemtitle }}</el-dropdown-item>
</template>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div> </div>
</template> </template>
<script setup> <script setup>
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
@ -51,6 +53,13 @@ const getSubject = () => {
subjectList.value = res.rows.filter(item => arr.includes(String(item.id))).map(items => items) subjectList.value = res.rows.filter(item => arr.includes(String(item.id))).map(items => items)
}) })
} }
//
const handleUserEduStage = (item) => {
userStore.edustage = item
}
const handleUserEduSubject = (item) => {
userStore.edusubject = item
}
onMounted(() => { onMounted(() => {
getSubject() getSubject()
console.log(userStore,'123') console.log(userStore,'123')

View File

@ -80,9 +80,6 @@ onMounted(() => {
font-size: 28px; font-size: 28px;
font-weight: bold; font-weight: bold;
} }
.infomation{
display: flex;
}
} }
} }
.list-group-item { .list-group-item {

View File

@ -131,7 +131,7 @@ const getSubject = () => {
} }
setTimeout(() => { setTimeout(() => {
if (props.user.edudegree != '') { if (userStore.user.edudegree != '') {
var upcaseName = [ var upcaseName = [
'一年级', '一年级',
'二年级', '二年级',
@ -146,15 +146,15 @@ setTimeout(() => {
'高二', '高二',
'高三' '高三'
] ]
var d = parseInt(props.user.edudegree.replace('年级', '')) var d = parseInt(userStore.user.edudegree.replace('年级', ''))
if (d <= 6) { if (d <= 6) {
props.user.edustage = '小学' userStore.user.edustage = '小学'
} else if (d >= 7 && d <= 9) { } else if (d >= 7 && d <= 9) {
props.user.edustage = '初中' userStore.user.edustage = '初中'
} else if (d >= 9 && d <= 12) { } else if (d >= 9 && d <= 12) {
props.user.edustage = '高中' userStore.user.edustage = '高中'
} }
props.user.stagelabel = upcaseName[d - 1] userStore.user.stagelabel = upcaseName[d - 1]
} }
}, 1000) }, 1000)
@ -162,10 +162,10 @@ setTimeout(() => {
function submit() { function submit() {
proxy.$refs.userRef.validate((valid) => { proxy.$refs.userRef.validate((valid) => {
if (valid) { if (valid) {
props.user.avatar = userStore.user.avatar userStore.user.avatar = userStore.user.avatar
updateUserInfo(props.user).then((response) => { updateUserInfo(userStore.user).then((response) => {
if(response.code == 200){ if(response.code == 200){
userStore.login({username:props.user.userName,password:props.user.plainpwd}).then(() => { userStore.login({username:userStore.user.userName,password:userStore.user.plainpwd}).then(() => {
userStore.getInfo().then(res => { userStore.getInfo().then(res => {
if(res.code === 200){ if(res.code === 200){
let sessionSubject = { let sessionSubject = {
@ -191,21 +191,20 @@ function submit() {
} }
const semeterChange = (item) => { const semeterChange = (item) => {
if(item === '幼儿园'){ if(item === '幼儿园'){
props.user.edusubject = '' userStore.user.edusubject = ''
} }
} }
// //
const getClassInfo = () => { const getClassInfo = () => {
classList.value = [] classList.value = []
debugger listClassmain({ classuserid: userStore.user.userId, pageSize: 100, status: 'open' }).then(response => {
listClassmain({ classuserid: props.user.userId, pageSize: 100, status: 'open' }).then(response => {
classList.value = [...response.rows] classList.value = [...response.rows]
if(classList.value.length > 0){ if(classList.value.length > 0){
currentIndex.value = 0 currentIndex.value = 0
} }
}); });
listClassmain({entpid: props.user.deptId, status: 'open', pageSize: 100}).then(response => { listClassmain({entpid: userStore.user.deptId, status: 'open', pageSize: 100}).then(response => {
// //
classesNotAMemberOf.value = [...response.rows] classesNotAMemberOf.value = [...response.rows]
classList.value.forEach(item => { classList.value.forEach(item => {
@ -249,9 +248,6 @@ function groupByCondition(arr, condition) {
return defaultLabel; return defaultLabel;
} }
} }
const addClass = () => {
dialogVisible.value = true
}
onMounted(() => { onMounted(() => {
getSubject() getSubject()
getClassInfo() getClassInfo()