From a92f3c4d10bebbdc55270e72ccd97cd1ba7d4e28 Mon Sep 17 00:00:00 2001
From: LAPTOP-RI7D261L\Mr Ke <545800322@qq.com>
Date: Wed, 26 Feb 2020 16:40:55 +0800
Subject: [PATCH] Merge branch 'master' of http://120.79.193.119:9090/r/nsjcy/frontEnd/nsjcy

---
 SunshineIns/src/page/ActiveManageEdit.jsx |  127 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/SunshineIns/src/page/ActiveManageEdit.jsx b/SunshineIns/src/page/ActiveManageEdit.jsx
index c1aa82a..c7651cd 100644
--- a/SunshineIns/src/page/ActiveManageEdit.jsx
+++ b/SunshineIns/src/page/ActiveManageEdit.jsx
@@ -5,13 +5,15 @@
  */
 import React from 'react';
 
-import { Row, Col, Input, DatePicker, Button, Modal, Upload, Icon, message, Divider, TimePicker, Badge, Select, Popconfirm, Spin } from 'antd';
+import { Row, Col, Input, DatePicker, Button, Modal, Upload, Icon, message, Divider, TimePicker, Badge, Select, Popconfirm, Spin, Breadcrumb } from 'antd';
 const { TextArea } = Input;
 import HeadView from '../view/HeadView';
 import BusDetailView from '../view/BusDetailView';
 import TableView from '../view/TableView';
 import ImageBoxView from '../view/ImageBoxView'
 // 引入编辑器以及编辑器样式
+import BraftEditor from 'braft-editor'
+import 'braft-editor/dist/index.css'
 import Fetch from '../fetch';
 import moment from 'moment';
 const format = 'HH:mm';
@@ -53,6 +55,8 @@
             disabled: true,
             status: '',
             loading: false,
+            code: '',
+            editorState: BraftEditor.createEditorState(null)
         };
     }
 
@@ -73,6 +77,7 @@
                 if (endTime == null) {
                     endTime = Date.now();
                 }
+                console.log
                 this.setState({
                     savedate: {
                         ...res.activity,
@@ -82,6 +87,8 @@
                         endHour: moment(endTime).format(format),
                         activityType: res.activity.activityType || 'act_1',
                     },
+                    code: res.code || '',
+                    editorState: BraftEditor.createEditorState(res.activity.course),
                     activityType: res.activity.activityType || 'act_1',
                     status: res.activity.activityStatus || '',
                     disabled: res.activity.activityStatus == 0 ? false : true,
@@ -111,8 +118,8 @@
             return;
         }
         if (savedate.activityPhone) {
-            if (!validator.phone(savedate.activityPhone)) {
-                return message.warning("联系电话格式不正确");
+            if (!savedate.activityPhone) {
+                return message.warning("联系电话不能为空");
             }
         }
         Fetch.saveActive(savedate)
@@ -225,9 +232,70 @@
         )
     }
 
+    uploadFn = (param) => {
+
+        const serverURL = domain + 'api/v1/attachment/upload'
+        const xhr = new XMLHttpRequest
+        const fd = new FormData()
+        const successFn = (response) => {
+            // 假设服务端直接返回文件上传后的地址
+            // 上传成功后调用param.success并传入上传后的文件地址
+            //Pz
+            const res = JSON.parse(xhr.responseText);
+            param.success({
+                url: domain + 'api/v1/attachment/image/' + res[0].id,
+                meta: {
+                    id: res[0].id,
+                    title: res[0].name,
+                    alt: res[0].name,
+                    loop: true, // 指定音视频是否循环播放
+                    autoPlay: true, // 指定音视频是否自动播放
+                    controls: true, // 指定音视频是否显示控制栏
+                    poster: domain + 'api/v1/attachment/image/' + res[0].id, // 指定视频播放器的封面
+                }
+            })
+        }
+
+
+        const progressFn = (event) => {
+            // 上传进度发生变化时调用param.progress
+            param.progress(event.loaded / event.total * 100)
+        }
+
+        const errorFn = (response) => {
+            // 上传发生错误时调用param.error
+            param.error({
+                msg: 'unable to upload.'
+            })
+        }
+        xhr.upload.addEventListener("progress", progressFn, false)
+        xhr.addEventListener("load", successFn, false)
+        xhr.addEventListener("error", errorFn, false)
+        xhr.addEventListener("abort", errorFn, false)
+        fd.append('file', param.file)
+        xhr.open('POST', serverURL, true)
+        xhr.send(fd)
+    }
+
+    handleEditorChange = (editorState) => {
+        this.setState({ editorState })
+    }
+
+    submitContent = () => {
+        // 在编辑器获得焦点时按下ctrl+s会执行此方法
+        // 编辑器内容提交到服务端之前,可直接调用editorState.toHTML()来获取HTML格式的内容
+        const htmlContent = this.state.editorState.toHTML()
+        this.setState(({ savedate }) => ({
+            savedate: {
+                ...savedate,
+                course: htmlContent
+            }
+        }))
+    }
+
     handleCancel = () => this.setState({ previewVisible: false })
     render() {
-        const { savedate, previewVisible, previewImage, fileList, dateSource, hitList, activityType, disabled, loading } = this.state;
+        const { savedate, previewVisible, previewImage,editorState, fileList, dateSource, code, hitList, activityType, disabled, loading } = this.state;
         console.log('disabled', disabled)
         const props = {
             action: domain + 'api/v1/attachment/materials?entityId=' + savedate.id,
@@ -313,6 +381,10 @@
             <div className="app-page">
                 <Spin spinning={loading}>
                     <HeadView history={this.props.history} />
+                    <Breadcrumb style={{ padding: '20px' }}>
+                        <Breadcrumb.Item><a href="index.html#/activeManage">活动管理</a></Breadcrumb.Item>
+                        <Breadcrumb.Item>活动发布</Breadcrumb.Item>
+                    </Breadcrumb>
                     <BusDetailView type='活动发布' >
                         <div style={divStyle}>
                             <Row type="flex" align='middle' justify="space-around">
@@ -324,15 +396,8 @@
                                         <Option value='act_3'>普法预约</Option>
                                     </Select>
                                 </Col>
-                                <Col span={12} pull={0}></Col>
-                            </Row>
-                        </div>
-                        <div style={divStyle}>
-                            <Row type="flex" align='middle' justify="space-around">
                                 <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>主持人</span></Col>
                                 <Col span={6} push={0} ><Input disabled={disabled} placeholder="请输入主持人姓名" style={{ width: '300px' }} name='host' onChange={this.saveInputChange} value={savedate.host || ""} /></Col>
-                                <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>报名要求</span></Col>
-                                <Col span={6} push={0} ><Input disabled={disabled} placeholder="请输入报名要求" style={{ width: '300px' }} name='requirement' onChange={this.saveInputChange} value={savedate.requirement || ""} /></Col>
                             </Row>
                         </div>
 
@@ -376,6 +441,12 @@
                                 <Col span={18} push={0} ><TextArea disabled={disabled} rows={4} placeholder="请输入活动描述" style={{ width: '92%' }} value={savedate.activityDesc || ""} onChange={this.saveInputChange} name='activityDesc' /></Col>
                             </Row>
                         </div>
+                        <div style={divStyle}>
+                            <Row type="flex" align='middle' justify="space-around">
+                                <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>报名要求</span></Col>
+                                <Col span={18} push={0} ><TextArea disabled={disabled} placeholder="请输入报名要求" style={{ width: '92%' }} name='requirement' onChange={this.saveInputChange} value={savedate.requirement || ""} /></Col>
+                            </Row>
+                        </div>
 
                         <div style={divStyle}>
                             <Row type="flex" align='top' justify="space-around">
@@ -395,6 +466,40 @@
                         </div>
 
                         {
+                            code && <div style={divStyle}>
+                                <Row type="flex" align='middle' justify="space-around">
+                                    <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>活动二维码</span></Col>
+                                    <Col span={18} push={0} ><img style={{ width: '150px', height: '150px' }} src={`data:image/png;base64,${code}`} /></Col>
+                                </Row>
+                            </div>
+
+                        }
+
+                        <div style={divStyle}>
+                            <Row type="flex" align='top' justify="space-around">
+                                <Col span={6} pull={0} style={{ textAlign: 'center' }}><span>活动进程</span></Col>
+                                <Col span={18} push={0} style={{ border: 'solid 1px rgba(0, 0, 0, 0.25)', borderRadius: '5PX' }} >
+                                    <BraftEditor
+                                        value={editorState}
+                                        disabled={disabled}
+                                        placeholder='请输入活动进程'
+                                        media={{
+                                            allowPasteImage: true, // 是否允许直接粘贴剪贴板图片(例如QQ截图等)到编辑器
+                                            image: true, // 开启图片插入功能
+                                            video: false, // 开启视频插入功能
+                                            audio: false, // 开启音频插入功能
+                                            uploadFn: this.uploadFn
+                                        }}
+                                        excludeControls={['emoji']}
+                                        onChange={this.handleEditorChange}
+                                        onSave={this.submitContent}
+                                        onBlur={this.submitContent}
+                                    />
+                                </Col>
+                            </Row>
+                        </div>
+
+                        {
                             activityType == 'act_1' ? (dateSource.length > 0 ?
                                 <div style={divStyle}>
                                     <Divider orientation="left" style={{ margin: '20px', width: '97%' }}>报名人员信息</Divider>

--
Gitblit v1.8.0