Browse Source

首页代码优化

RaoMeng 6 years ago
parent
commit
5957e76143
1 changed files with 51 additions and 53 deletions
  1. 51 53
      frontend/wechat-web/src/modules/home/HomePage.jsx

+ 51 - 53
frontend/wechat-web/src/modules/home/HomePage.jsx

@@ -90,38 +90,22 @@ class HomePage extends Component {
         const {userInfo} = this.props
         let {studentIndex} = this.state
 
-        const teacherMenu = this.getTeacherMenu()
-        const parentMenu = this.getParentMenu()
-        const videoLayout = this.getVideoLayout()
-        const topMenus = this.getTopMenus()
-
         const studentList = []
-
         if (!isObjEmpty(userInfo.parent) && !isObjEmpty(userInfo.parent.students) && userInfo.userRole === 1) {
             userInfo.parent.students.forEach((item, index) => {
                 studentList.push(<StuItem isSelect={studentIndex === index} stuObj={item}
                                           stuIndex={index} onStuSwitch={this.onStuSwitch}/>)
             })
         }
-        const albumItems = []
 
-        let schoolName = '', userAvatar = '', userName = '', albums = ''
+        const albumItems = []
+        let albums = ''
         if (userInfo.userRole === 1) {
-            if (userInfo.parent) {
-                schoolName = userInfo.parent.schoolName
-                userAvatar = userInfo.parent.parentsPhoto
-                userName = userInfo.parent.parentsName
-
-                if (!isObjEmpty(userInfo.parent.student)) {
-                    albums = userInfo.parent.student.picAlbum
-                }
+            if (!isObjEmpty(userInfo.parent, userInfo.parent.student)) {
+                albums = userInfo.parent.student.picAlbum
             }
         } else if (userInfo.userRole === 2) {
             if (userInfo.teacher) {
-                schoolName = userInfo.teacher.schoolName
-                userAvatar = userInfo.teacher.teacherPhoto
-                userName = userInfo.teacher.teacherName
-
                 albums = userInfo.teacher.albums
             }
         }
@@ -137,31 +121,16 @@ class HomePage extends Component {
         return (
             <div className='home-page-root'>
                 <div className='home-top-layout-root'>
-                    <div className='home-top-school-text'>{schoolName}</div>
-                    <div className='home-top-msg-root'>
-                        {isObjEmpty(userAvatar) ?
-                            <Avatar size={50} icon='user'/> :
-                            <img
-                                src={userAvatar}
-                                width={50} height={50} className="img-circle"
-                                style={{border: '3px solid #ffffff'}}/>
-                        }
-                        <span
-                            className='home-top-msg-text'>尊敬的{userName + (userInfo.userRole === 1 ? '家长' : '老师')}</span>
-                        {(userInfo.teacher && userInfo.parent) ?
-                            <img style={{marginLeft: "5px"}} src={icon_home_change} width={16}
-                                 height={16} onClick={this.onIdentitySwitch}/> : ''}
-
-                    </div>
+                    {this.userInfoLayout()}
                     <div className='home-student-layout-root'>
                         {studentList}
                     </div>
                     <div className='home-top-menu-root'>
-                        {topMenus}
+                        {this.getTopMenus()}
                     </div>
                 </div>
                 {/*功能菜单*/}
-                {userInfo.userRole == 1 ? parentMenu : teacherMenu}
+                {userInfo.userRole == 1 ? this.getParentMenu() : this.getTeacherMenu()}
                 {/*班级相册*/}
                 {<div className={isObjEmpty(albumItems) ? 'displayNone' : ''}>
                     <div className='gray-line'></div>
@@ -172,11 +141,9 @@ class HomePage extends Component {
                         </div>
                     </div>
                 </div>}
-
+                {/*{this.getAlbumLayout()}*/}
                 {/*精彩瞬间*/}
-                {/*{videoLayout}*/}
-
-
+                {/*{this.getVideoLayout()}*/}
                 {/*底线标识*/}
                 {this.getBottomLayout()}
             </div>
@@ -269,10 +236,7 @@ class HomePage extends Component {
                 } else if (!isObjEmpty(response.data.parents)) {
                     userRole = 1
                 }
-
-                /*switchUser({
-                    userRole: userRole,
-                })()*/
+                //切换当前user信息
                 switchCurrentUser(userRole)()
 
                 if (!isObjEmpty(userInfo.parent, userInfo.parent.students)) {
@@ -306,7 +270,6 @@ class HomePage extends Component {
                         setTimeout(() => {
                             Toast.success('切换成功!', 1)
                             switchCurrentUser(1)()
-                            // switchUser({userRole: 1})()
                         }, 500)
                     }
                 }
@@ -318,7 +281,6 @@ class HomePage extends Component {
                         setTimeout(() => {
                             Toast.success('切换成功!', 1)
                             switchCurrentUser(2)()
-                            // switchUser({userRole: 2})();
                         }, 500)
                     }
                 }
@@ -326,6 +288,44 @@ class HomePage extends Component {
         ])
     }
 
+    userInfoLayout = () => {
+        const {userInfo} = this.props
+        let schoolName = '', userAvatar = '', userName = '', albums = ''
+        if (userInfo.userRole === 1) {
+            if (userInfo.parent) {
+                schoolName = userInfo.parent.schoolName
+                userAvatar = userInfo.parent.parentsPhoto
+                userName = userInfo.parent.parentsName
+            }
+        } else if (userInfo.userRole === 2) {
+            if (userInfo.teacher) {
+                schoolName = userInfo.teacher.schoolName
+                userAvatar = userInfo.teacher.teacherPhoto
+                userName = userInfo.teacher.teacherName
+            }
+        }
+        return (
+            <div>
+                <div className='home-top-school-text'>{schoolName}</div>
+                <div className='home-top-msg-root'>
+                    {isObjEmpty(userAvatar) ?
+                        <Avatar size={50} icon='user'/> :
+                        <img
+                            src={userAvatar}
+                            width={50} height={50} className="img-circle"
+                            style={{border: '3px solid #ffffff'}}/>
+                    }
+                    <span
+                        className='home-top-msg-text'>尊敬的{userName + (userInfo.userRole === 1 ? '家长' : '老师')}</span>
+                    {(userInfo.teacher && userInfo.parent) ?
+                        <img style={{marginLeft: "5px"}} src={icon_home_change} width={16}
+                             height={16} onClick={this.onIdentitySwitch}/> : ''}
+
+                </div>
+            </div>
+        )
+    }
+
     getBottomLayout = () => {
         return (
             <div className='common-flex-row-x-y-center' style={{padding: 28}}>
@@ -362,11 +362,9 @@ class HomePage extends Component {
             return <div>
                 <div className='gray-line'></div>
                 <MenuGroup groupIcon={require('imgs/ic_group_album.png')} groupText='班级相册'/>
-                <div className='home-albums-layout'>
-                    <div className="home-swiper-container">
-                        <div className="swiper-wrapper">
-                            {albumItems}
-                        </div>
+                <div className="home-swiper-container">
+                    <div className="swiper-wrapper">
+                        {albumItems}
                     </div>
                 </div>
             </div>