Browse Source

附件上传带token问题解决

FANGLH 6 years ago
parent
commit
bf04ba9d57

+ 15 - 1
frontend/wechat-web/src/components/UploadEnclosure.jsx

@@ -11,6 +11,7 @@ import ImagesViewer from '../components/imagesVIewer/index'
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 import 'css/upload.css'
 import 'css/upload.css'
 import {_baseURL} from "../configs/api.config";
 import {_baseURL} from "../configs/api.config";
+import store from './../redux/store/store'
 
 
 let uploadFail = false;
 let uploadFail = false;
 export default class UploadEnclosure extends Component {
 export default class UploadEnclosure extends Component {
@@ -18,6 +19,7 @@ export default class UploadEnclosure extends Component {
     static propTypes = {
     static propTypes = {
         action: PropTypes.string.isRequired,//上传地址
         action: PropTypes.string.isRequired,//上传地址
         data: PropTypes.object,//上传所需参数
         data: PropTypes.object,//上传所需参数
+        headers: PropTypes.object,//上传所需头部参数
         accept: PropTypes.string,//接受上传的文件类型
         accept: PropTypes.string,//接受上传的文件类型
         listType: PropTypes.string,//附件列表格式,默认picture-card
         listType: PropTypes.string,//附件列表格式,默认picture-card
         count: PropTypes.number,//附件限制数量,默认为1
         count: PropTypes.number,//附件限制数量,默认为1
@@ -36,6 +38,9 @@ export default class UploadEnclosure extends Component {
         count: 1,
         count: 1,
         data: {
         data: {
             folderId: 0
             folderId: 0
+        },
+        headers: {
+
         },
         },
         multiple: false,
         multiple: false,
         title: '附件',
         title: '附件',
@@ -70,7 +75,7 @@ export default class UploadEnclosure extends Component {
         const {fileList} = this.state
         const {fileList} = this.state
         const {
         const {
             action, listType, count, multiple,
             action, listType, count, multiple,
-            title, needPoint, limit, accept, data
+            title, needPoint, limit, accept, data, headers
         } = this.props
         } = this.props
 
 
         const imgs = []
         const imgs = []
@@ -84,6 +89,13 @@ export default class UploadEnclosure extends Component {
         if (imgs.length > 9) {
         if (imgs.length > 9) {
             pointAble = false
             pointAble = false
         }
         }
+        const userInfo = store.getState().redUserInfo
+
+        const headerParams = {
+            // headers?...headers:{},
+            "Authorization": userInfo.token,
+            ...headers,
+        }
 
 
         const uploadButton = (
         const uploadButton = (
             <div>
             <div>
@@ -106,6 +118,8 @@ export default class UploadEnclosure extends Component {
                         listType={listType}
                         listType={listType}
                         fileList={fileList}
                         fileList={fileList}
                         multiple={multiple}
                         multiple={multiple}
+                        withCredentials={true}
+                        headers={headerParams}
                         beforeUpload={this.beforeUpload}
                         beforeUpload={this.beforeUpload}
                         onPreview={this.handlePreview}
                         onPreview={this.handlePreview}
                         onChange={this.handleChange}
                         onChange={this.handleChange}

+ 2 - 2
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
  * Created by RaoMeng on 2018/11/21
  * Desc: 项目接口
  * 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.47:9520' //顾群
 // export const _host = 'http://10.1.80.180: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 + '/api/school'
 // export const _baseURL = _host
 // export const _baseURL = _host

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

@@ -172,7 +172,6 @@ class AnnounceRelease extends Component {
         if (this.isRequesting == true) {
         if (this.isRequesting == true) {
             return
             return
         }
         }
-
         const {announceTitle, announceContent, fileList} = this.state
         const {announceTitle, announceContent, fileList} = this.state
 
 
         if (isObjEmpty(announceTitle)) {
         if (isObjEmpty(announceTitle)) {
@@ -183,11 +182,6 @@ class AnnounceRelease extends Component {
             Toast.fail('请输入通知内容')
             Toast.fail('请输入通知内容')
             return
             return
         }
         }
-        // if (isObjEmpty(this.checkNodes)) {
-        //     Toast.fail('请选择通知对象')
-        //     return
-        // }
-
         if (announceTitle.length > 50) {
         if (announceTitle.length > 50) {
             Toast.fail('通知标题过长')
             Toast.fail('通知标题过长')
             return
             return
@@ -206,28 +200,7 @@ class AnnounceRelease extends Component {
                 }
                 }
             })
             })
         }
         }
-        // const stuList = [], teacherList = []
-        // if (!isObjEmpty(this.checkNodes)) {
-        //     this.checkNodes.forEach((node, index) => {
-        //         if (node.value.startWith('0')) {
-        //             teacherList.push(node.userId)
-        //         } else if (node.value.startWith('2')) {
-        //             stuList.push(node.userId)
-        //         }
-        //     })
-        // }
-
         const paramObj = {
         const paramObj = {
-          /*  notifyTitle: announceTitle,
-            notifyType: 3,
-            notifyDetails: announceContent,
-            notifyCreator: this.props.userInfo.user.userFunId,
-            notifyStatus: 1,
-            notifyFiles: JSON.stringify(fileUrls),
-            notifyRemarks: '',*/
-            // notifyTeacher: JSON.stringify(teacherList),
-            // notifyStu: JSON.stringify(stuList),
-
             notify_title:announceTitle,
             notify_title:announceTitle,
             notify_details:announceContent,
             notify_details:announceContent,
             notify_status:1,
             notify_status:1,
@@ -235,8 +208,8 @@ class AnnounceRelease extends Component {
             creator:this.props.userInfo.user.userName,
             creator:this.props.userInfo.user.userName,
             notify_files:JSON.stringify(fileUrls)
             notify_files:JSON.stringify(fileUrls)
         }
         }
-
-        console.log(paramObj)
+        console.log('fileList',fileList)
+        console.log('paramObj',paramObj)
 
 
         this.isRequesting = true
         this.isRequesting = true
         Toast.loading('正在发布...', 0)
         Toast.loading('正在发布...', 0)