From 49d3cc2c48b8bf98cc580d21289e007b0d66a48d Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Fri, 19 Jul 2019 17:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=A4=A7=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/common/educoder.js | 1 + .../react/src/common/hooks/ImageLayerHook.js | 47 +++++++++++++++++++ .../members/modal/CourseGroupChooserModal.js | 4 +- .../modules/page/main/CodeEvaluateView.css | 1 + .../user/modal/RealNameCertificationModal.js | 14 ++++-- 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 public/react/src/common/hooks/ImageLayerHook.js diff --git a/public/react/src/common/educoder.js b/public/react/src/common/educoder.js index 263e08808..749d2a1e5 100644 --- a/public/react/src/common/educoder.js +++ b/public/react/src/common/educoder.js @@ -50,3 +50,4 @@ export { default as DMDEditor } from './components/markdown/DMDEditor' +export { default as ImageLayerHook } from './hooks/ImageLayerHook' \ No newline at end of file diff --git a/public/react/src/common/hooks/ImageLayerHook.js b/public/react/src/common/hooks/ImageLayerHook.js new file mode 100644 index 000000000..c9f0a14a4 --- /dev/null +++ b/public/react/src/common/hooks/ImageLayerHook.js @@ -0,0 +1,47 @@ +import React, { useState, useEffect, memo } from 'react' +import ImageLayer from '../../modules/page/layers/ImageLayer' +import { isImageExtension } from 'educoder' +function ImageLayerHook(props) { + const [showImage, setShowImage] = useState(false) + const [imageSrc, setImageSrc] = useState('') + + const { parentSel, childSel, watchPropsArray } = props + + const onImageLayerClose = () => { + setShowImage(false) + setImageSrc('') + } + const onDelegateClick = (event) => { + const imageSrc = event.target.src || event.target.getAttribute('src') || event.target.getAttribute('href') + // 判断imageSrc是否是图片 + const fileName = event.target.innerHTML.trim() + if (isImageExtension(imageSrc.trim()) || isImageExtension(fileName) || event.target.tagName == 'IMG' || imageSrc.indexOf('base64,') != -1) { + // 非回复里的头像图片; 非emoticons + if (imageSrc.indexOf('/images/avatars/User') === -1 && + imageSrc.indexOf('kindeditor/plugins/emoticons') === -1 ) { + setShowImage(true) + setImageSrc(imageSrc) + } + event.stopPropagation() + event.preventDefault && event.preventDefault() + event.originalEvent.preventDefault() + // event.originalEvent.stopPropagation() + // event.originalEvent.cancelBubble = true + return false; + } + } + useEffect(() => { + $(parentSel) + .delegate(childSel, "click", onDelegateClick); + + return () => { + $(parentSel).undelegate(childSel, "click", onDelegateClick ) + } + }) + + return ( + + ) +} + +export default memo(ImageLayerHook) \ No newline at end of file diff --git a/public/react/src/modules/courses/members/modal/CourseGroupChooserModal.js b/public/react/src/modules/courses/members/modal/CourseGroupChooserModal.js index dc3044cc0..3f4f1a0ca 100644 --- a/public/react/src/modules/courses/members/modal/CourseGroupChooserModal.js +++ b/public/react/src/modules/courses/members/modal/CourseGroupChooserModal.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef, memo } from 'react' +import React, { useState, useEffect, useRef, useMemo } from 'react' import { trigger } from 'educoder' import { Input, Checkbox } from "antd"; import CourseGroupChooser from '../CourseGroupChooser' @@ -105,4 +105,4 @@ function CourseGroupChooserModal({ course_groups = [], isAdminOrCreator, item, i ) } -export default memo(CourseGroupChooserModal) \ No newline at end of file +export default useMemo(CourseGroupChooserModal) \ No newline at end of file diff --git a/public/react/src/modules/page/main/CodeEvaluateView.css b/public/react/src/modules/page/main/CodeEvaluateView.css index bd0427d7b..137174d95 100644 --- a/public/react/src/modules/page/main/CodeEvaluateView.css +++ b/public/react/src/modules/page/main/CodeEvaluateView.css @@ -126,4 +126,5 @@ display: inline-block; height: 10px; margin: 5px 0; + float: right; } \ No newline at end of file diff --git a/public/react/src/modules/user/modal/RealNameCertificationModal.js b/public/react/src/modules/user/modal/RealNameCertificationModal.js index ccb301a32..6c92423cd 100644 --- a/public/react/src/modules/user/modal/RealNameCertificationModal.js +++ b/public/react/src/modules/user/modal/RealNameCertificationModal.js @@ -2,7 +2,7 @@ import React, { Component } from "react"; import { message, Icon, Input, Form, Upload} from "antd"; import axios from 'axios' import ModalWrapper from "../../courses/common/ModalWrapper" -import { City, getUploadActionUrl,getImageUrl } from 'educoder' +import { City, getUploadActionUrl, getImageUrl, ImageLayerHook } from 'educoder' import '../account/common.css' import authImg from '../../../images/account/auth.png' @@ -201,7 +201,11 @@ class RealNameCertificationModal extends Component{ } .applyForModal .ant-form-item-label label { color: #979797 + } + .applyForModal .ant-upload.ant-upload-drag .ant-upload { + padding: 0px; } + .certificationModal .ant-modal-body{ padding:20px; } @@ -295,9 +299,9 @@ class RealNameCertificationModal extends Component{ {imageUrl2 ? - + // avatar - : + :

@@ -311,7 +315,9 @@ class RealNameCertificationModal extends Component{

示例图片 - 查看大图 + + 查看大图