Explorar o código

身份认证添加token功能添加

FANGLH %!s(int64=6) %!d(string=hai) anos
pai
achega
ebb0792f2a

+ 6 - 3
frontend/wechat-web/src/configs/api.config.js

@@ -7,10 +7,10 @@ import store from './../redux/store/store'
  * Created by RaoMeng on 2018/11/21
  * Desc: 项目接口
  */
-export const _host = 'https://school-api.ubtob.com'
+// export const _host = 'https://school-api.ubtob.com'
 // export const _host = 'http://10.1.80.47:9520' //顾群
 // export const _host = 'http://10.1.80.180:9520' //赵耀
-// export const _host = 'http://10.1.80.36:9520'  //陈伟
+export const _host = 'http://10.1.80.36:9520'  //陈伟
 
 export const _baseURL = _host + '/api/school'
 // export const _baseURL = _host
@@ -212,7 +212,10 @@ export const API = {
     HOMEWORK_REPLY: _baseURL + '/wxSchool/taskNotify/taskReply',
 
     //获取科目列表
-    SUBJECT_LIST: _baseURL + '/wxSchool/taskNotify/subjectDOList'
+    SUBJECT_LIST: _baseURL + '/wxSchool/taskNotify/subjectDOList',
+
+    //身份切换时获取token
+    SWITCH_IDENTITY :_baseURL + '/wxSchool/user/switchIdentity'
 }
 
 

+ 1 - 1
frontend/wechat-web/src/modules/accountBind/AccountBind.jsx

@@ -214,7 +214,7 @@ class AccountBind extends Component {
 
             if (response && response.data) {
                 switchUser({
-                    token:''
+                    token: response.data.token ? response.data.token.token : ''
                 })()
                 if (response.data.teacherDOS) {
                     const teacherDOS = response.data.teacherDOS[0]

+ 6 - 5
frontend/wechat-web/src/modules/accountBind/BindMenu.jsx

@@ -88,11 +88,12 @@ class BindMenu extends Component {
             schoolId: 1,//学校id暂时写死,后续需要添加选择学校的步骤
             headimgurl: decodeURIComponent(this.wxAvatar),
         }).then(response => {
-            switchUser({
-                userOpenid: this.openid,
-                token:''
-            })()
             if (response.data) {
+                switchUser({
+                    userOpenid: this.openid,
+                    token: response.data.token ? response.data.token.token : ''
+                })()
+
                 if (!isObjEmpty(response.data.teacherDOS)) {
                     const teacherDOS = response.data.teacherDOS[0]
 
@@ -195,7 +196,7 @@ class BindMenu extends Component {
                 <Button type="primary" block
                         style={{
                             marginTop: '20px', letterSpacing: '10px',
-                            borderRadius: '9px', fontSize: '14px',borderRadius: '30px',
+                            borderRadius: '9px', fontSize: '14px', borderRadius: '30px',
                         }}
                         onClick={this.parentBind}>我是家长</Button>
                 <Button type="primary" block

+ 2 - 2
frontend/wechat-web/src/modules/announce/AnnounceRelease.jsx

@@ -9,7 +9,7 @@ import 'css/announce.css'
 import {Toast} from 'antd-mobile'
 import TargetSelect from 'components/TargetSelect'
 import UploadEnclosure from 'components/UploadEnclosure'
-import {fetchGet, fetchPost,fetchPost2} from "../../utils/fetchRequest";
+import {fetchGet, fetchPost,fetchPostObj} from "../../utils/fetchRequest";
 import {_baseURL, API} from "../../configs/api.config";
 import {getIntValue, getStrValue, isObjEmpty} from "../../utils/common";
 import {connect} from 'react-redux'
@@ -240,7 +240,7 @@ class AnnounceRelease extends Component {
 
         this.isRequesting = true
         Toast.loading('正在发布...', 0)
-        fetchPost2(API.NOTIFY_CREATE,
+        fetchPostObj(API.NOTIFY_CREATE,
             JSON.stringify(paramObj),
             {"Content-Type": 'application/json;charset=UTF-8'}).then(response => {
             Toast.hide()

+ 36 - 29
frontend/wechat-web/src/modules/home/HomePage.jsx

@@ -17,7 +17,7 @@ import {connect} from "react-redux";
 import {CONFIG_TEACHER_MENU, CONFIG_PARENT_MENU, CONFIG_HOME_TOP_MENU} from "../../utils/homePage.constants";
 import {getIntValue, getSearchParams, getStrValue, isObjEmpty} from "../../utils/common";
 import 'css/home-page.css'
-import {fetchGet, fetchPost} from "../../utils/fetchRequest";
+import {fetchGet, fetchPost, fetchPostObj} from "../../utils/fetchRequest";
 import {_baseURL, API} from "../../configs/api.config";
 import icon_home_change from "../../style/imgs/icon_home_change.png";
 
@@ -180,7 +180,6 @@ class HomePage extends Component {
             if (response && response.data) {
                 if (!isObjEmpty(response.data.teacher)) {
                     const teacherDOS = response.data.teacher
-
                     switchUser({
                         teacher: {
                             teacherId: getIntValue(teacherDOS, 'teacherId'),
@@ -254,7 +253,7 @@ class HomePage extends Component {
                         studentIndex: studentIndex,
                     })
                 }
-
+                console.log('raomeng',userInfo)
                 this.mySwiper.init()
             }
         }).catch((error) => {
@@ -268,49 +267,57 @@ class HomePage extends Component {
     }
 
     onIdentitySwitch = () => {
+        console.log('onIdentitySwitch')
+        //this.props.userInfo.userRole
         operation([
             {
-                text: '家长', onPress: () => {
-                //TODO 拿token
-                fetchGet(API.leaveDetail, {}).then((response) => {
-                    if (response.success && !isObjEmpty(response.data)) {
+                text: '家长',
+                onPress: () => {
+                    if(this.props.userInfo.userRole == 1) //当前是家长端时,点击家长不进行任何操作
+                        return
+                    this.switchEvent(1)
+                }
+            },
+            {
+                text: '教师',
+                onPress: () => {
+                    if(this.props.userInfo.userRole == 2) //当前是教师端时,点击教师不进行任何操作
+                        return
+                    this.switchEvent(0)
+                }
+            },
+        ])
+    }
 
-                    }
-                }).catch((error) => {
-                    console.log("error:", JSON.stringify(error));
-                })
+    switchEvent = (type) => {
+        console.log('switchEvent,type',type)
 
-                if (this.props.userInfo.userRole === 2) {
+        fetchPost(API.SWITCH_IDENTITY, {
+            personId: this.props.userInfo.user.userFunId,
+            type: type
+        }).then((response) => {
+            if (response.success && !isObjEmpty(response.data)) {
+                if (type === 0) { //家长
                     Toast.loading('身份切换中...', 0)
                     setTimeout(() => {
                         Toast.success('切换成功!', 1)
-                        switchCurrentUser(1)()
+                        switchCurrentUser(2)()
                     }, 400)
-                } else if (this.props.userInfo.userRole === 1) {
+                } else if (type === 1) { //教师
                     Toast.loading('身份切换中...', 0)
                     setTimeout(() => {
                         Toast.success('切换成功!', 1)
-                        switchCurrentUser(2)()
+                        switchCurrentUser(1)()
                     }, 400)
                 }
                 switchUser({
-                    token: ''
+                    token: response.data.token ? response.data.token: ''
                 })()
             }
-            },
-            {
-                text: '教师', onPress: () => {
+        }).catch((error) => {
+            Toast.hide()
+        })
 
-                if (this.props.userInfo.userRole === 1) {
-                    Toast.loading('身份切换中...', 0)
-                    setTimeout(() => {
-                        Toast.success('切换成功!', 1)
-                        switchCurrentUser(2)()
-                    }, 400)
-                }
-            }
-            },
-        ])
     }
 
     userInfoLayout = () => {

+ 2 - 2
frontend/wechat-web/src/modules/homework/ReleaseAssignmentPage.js

@@ -9,7 +9,7 @@ import '../../style/css/app-gloal.css'
 import moment from 'moment'
 import {Input, Button, Icon, message} from 'antd';
 import TargetSelect from "../../components/TargetSelect";
-import {fetchPost, fetchGet,fetchPost2} from '../../utils/fetchRequest';
+import {fetchPost, fetchGet,fetchPostObj} from '../../utils/fetchRequest';
 import {_baseURL, API} from '../../configs/api.config';
 import {isObjEmpty, getIntValue, getStrValue} from '../../utils/common';
 import UploadEnclosure from 'components/UploadEnclosure'
@@ -173,7 +173,7 @@ class ReleaseAssignmentPage extends React.Component {
 
         }
         console.log(params)
-        fetchPost2(API.homeWorkAdd, JSON.stringify(params),{"Content-Type": 'application/json;charset=UTF-8'}).then((response) => {
+        fetchPostObj(API.homeWorkAdd, JSON.stringify(params),{"Content-Type": 'application/json;charset=UTF-8'}).then((response) => {
             Toast.hide();
             if (response.success) {
                 Toast.success("发布成功!", 1)

+ 13 - 13
frontend/wechat-web/src/modules/notificationCenter/NotifyBoardDetail.jsx

@@ -104,19 +104,19 @@ class NotifyBoardDetail extends Component {
                         <div className='notify-detail-modal-time'>{notifyDetail.noIssue}</div>
                         <div className='notify-detail-modal-time'>{notifyDetail.noTime}</div>
                         {/*<div className='notify-detail-modal-time'>{notifyDetail.noTime}</div>*/}
-                        <div className='gray-line'></div>
-                        <div className='common-flex-row-10 common-font-family'>
-                            <span style={{color: '#363636', fontSize: 14}}>接收人</span>
-                            {/*<span style={{fontSize: '12px', color: '#CD1D1D'}}>未读:{notifyDetail.unRead}</span>*/}
-                            <span style={{
-                                fontSize: '12px',
-                                color: '#666666',
-                                marginLeft: '10px'
-                            }}>{getIntValue(notifyDetail.readed, 'length')}/{notifyDetail.allCount}</span>
-                        </div>
-                        <div>
-                            {receiveItems}
-                        </div>
+                        {/*<div className='gray-line'></div>*/}
+                        {/*<div className='common-flex-row-10 common-font-family'>*/}
+                            {/*<span style={{color: '#363636', fontSize: 14}}>接收人</span>*/}
+                            {/*/!*<span style={{fontSize: '12px', color: '#CD1D1D'}}>未读:{notifyDetail.unRead}</span>*!/*/}
+                            {/*<span style={{*/}
+                                {/*fontSize: '12px',*/}
+                                {/*color: '#666666',*/}
+                                {/*marginLeft: '10px'*/}
+                            {/*}}>{getIntValue(notifyDetail.readed, 'length')}/{notifyDetail.allCount}</span>*/}
+                        {/*</div>*/}
+                        {/*<div>*/}
+                            {/*{receiveItems}*/}
+                        {/*</div>*/}
                     </div>
                 </div>
             </div>

+ 1 - 1
frontend/wechat-web/src/modules/principalMailbox/PrincipalMailbox.jsx

@@ -93,7 +93,7 @@ class PrincipalMailbox extends Component {
             mailboxContext: suggest,
             mailboxFiles: JSON.stringify(fileUrls),
             mailboxCreator: this.props.userInfo.user.userFunId,
-            isAnonymity: isAnonymous ? 2 : 1,
+            isAnonymity: isAnonymous ? 1 : 2,
             mailboxStatus: 1,
             mbStuid:this.props.userInfo.user.student.stuId,
             mbStudent:this.props.userInfo.user.student.stuName,

+ 10 - 1
frontend/wechat-web/src/utils/fetchRequest.js

@@ -1,9 +1,11 @@
 import {getStrValue, isObjNull} from "./common";
+import store from './../redux/store/store'
 
 export function fetchPost(url, params, header) {
     if (window.navigator.onLine == false) {
         return Promise.reject('网络连接失败,请检查网络连接')
     }
+    const userInfo = store.getState().redUserInfo
 
     if (isObjNull(header)) {
         header = {}
@@ -28,6 +30,7 @@ export function fetchPost(url, params, header) {
         headers: new Headers({
             'Accept': 'application/json',
             // "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
+            "Authorization": userInfo.token,
             ...header
         })
     })
@@ -35,11 +38,13 @@ export function fetchPost(url, params, header) {
     return fetchResult(request)
 }
 
-export function fetchPost2(url, params, header){
+export function fetchPostObj(url, params, header) {
     if (window.navigator.onLine == false) {
         return Promise.reject('网络连接失败,请检查网络连接')
     }
 
+    const userInfo = store.getState().redUserInfo
+
     if (isObjNull(header)) {
         header = {}
     }
@@ -53,6 +58,7 @@ export function fetchPost2(url, params, header){
         headers: new Headers({
             'Accept': 'application/json',
             // "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
+            "Authorization": userInfo.token,
             ...header
         })
     })
@@ -65,6 +71,8 @@ export function fetchGet(url, params, header) {
         return Promise.reject('网络连接失败,请检查网络连接')
     }
 
+    const userInfo = store.getState().redUserInfo
+
     if (isObjNull(header)) {
         header = {}
     }
@@ -92,6 +100,7 @@ export function fetchGet(url, params, header) {
         headers: new Headers({
             'Accept': 'application/json',
             "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
+            "Authorization": userInfo.token,
             ...header
         })
     })