@@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'
44import LoadingIcon from '../LoadingIcon'
55import ErrorIcon from '../ErrorIcon'
66import Image from '../Image'
7- import { createObserver } from '../Image/observer'
7+ import { createObserver } from '../Image/observer'
88// import Store from './imgViewStore'
99function find ( list , arg ) {
1010 return list . findIndex ( each => each === arg )
@@ -286,7 +286,6 @@ export default class ImgPpreview extends React.PureComponent {
286286 }
287287
288288 imgOnError = ( ) => {
289- console . log ( 'onError' )
290289 this . setState ( {
291290 loaded : true ,
292291 error : true
@@ -310,8 +309,6 @@ export default class ImgPpreview extends React.PureComponent {
310309 return {
311310 left : left + 'px' ,
312311 top : top + 'px' ,
313- // width: ((rotate / 90) % 2 === 0 ? width : height) * scaleFixed + 'px',
314- // height: ((rotate / 90) % 2 === 0 ? height : width) * scaleFixed + 'px',
315312 transform : `rotate(${ rotate } deg) scale(${ scaleFixed } )`
316313 }
317314 }
@@ -341,64 +338,75 @@ export default class ImgPpreview extends React.PureComponent {
341338 }
342339 }
343340
344- render ( ) {
341+ _renderIcon ( ) {
342+ return (
343+ < >
344+ < div className = "img-viewer-close" >
345+ < i
346+ ref = { el => {
347+ this . $close = el
348+ } }
349+ className = "react-image-icon"
350+ style = { { pointerEvents : 'none' } }
351+ >
352+ 
353+ </ i >
354+ </ div >
355+ < i className = "img-viewer-prev react-image-icon" onClick = { this . prev } >
356+ 
357+ </ i >
358+ < i className = "img-viewer-next react-image-icon" onClick = { this . next } >
359+ 
360+ </ i >
361+ </ >
362+ )
363+ }
364+
365+ _renderImg ( ) {
345366 const {
346367 state,
347368 currentImg,
348- mouseUpHandle,
349- mouseWheelHandle,
350369 mouseDownHandle,
351370 imgOnLoad,
352371 imgOnError,
353- imgSty,
354- prev,
355- next,
356- rotateFnc
372+ imgSty
357373 } = this
358- const { current, images } = state
359374 return (
360- < div
361- id = "imgPreview"
362- ref = { el => {
363- this . $el = el
364- } }
365- className = "img-viewer-container"
366- style = { { display : state . open ? 'flex' : 'none' } }
367- onMouseUp = { mouseUpHandle }
368- onWheel = { mouseWheelHandle }
369- draggable = "false"
370- >
371- < div
372- className = "img-viewer-close"
373- ref = { el => {
374- this . $close = el
375- } }
376- >
377- < i className = "react-image-icon" style = { { pointerEvents : 'none' } } >
378- 
379- </ i >
380- </ div >
381- { state . changed && (
382- < React . Fragment >
383- < img
384- className = { [
385- 'img-viewer-current' ,
386- state . loaded && ! state . error ? '' : 'dis-none'
387- ] . join ( ' ' ) }
388- onMouseDown = { mouseDownHandle }
389- onLoad = { imgOnLoad }
390- onError = { imgOnError }
391- src = { currentImg }
392- alt = ""
393- draggable = "false"
394- style = { imgSty }
395- />
396- { ! state . loaded && < LoadingIcon /> }
397- { state . error && (
398- < ErrorIcon style = { { width : '300px' , height : '300px' } } />
399- ) }
400- </ React . Fragment >
375+ < >
376+ < img
377+ className = { [
378+ 'img-viewer-current' ,
379+ state . loaded && ! state . error ? '' : 'dis-none'
380+ ] . join ( ' ' ) }
381+ onMouseDown = { mouseDownHandle }
382+ onLoad = { imgOnLoad }
383+ onError = { imgOnError }
384+ src = { state . changed ? currentImg : '' }
385+ alt = ""
386+ draggable = { false }
387+ style = { imgSty }
388+ />
389+ { ! state . loaded && (
390+ < div className = "img-viewer-status" >
391+ < LoadingIcon />
392+ </ div >
401393 ) }
394+ { state . error && (
395+ < div className = "img-viewer-status" >
396+ < ErrorIcon style = { { width : '300px' , height : '300px' } } />
397+ </ div >
398+ ) }
399+ </ >
400+ )
401+ }
402+
403+ _renderFooter ( ) {
404+ const {
405+ state, prev, next, rotateFnc
406+ } = this
407+ const { images, current } = state
408+ return (
409+ < >
402410 < div
403411 className = "img-viewer-footer"
404412 ref = { ref => {
@@ -407,23 +415,23 @@ export default class ImgPpreview extends React.PureComponent {
407415 >
408416 < div className = "img-viewer-ctrl" >
409417 < i
410- className = "icon react-image-icon"
418+ className = "react-image-icon"
411419 onClick = { prev }
412420 style = { { transform : 'rotateY(180deg)' } }
413421 >
414422 
415423 </ i >
416- < i className = "icon react-image-icon" onClick = { ( ) => rotateFnc ( 90 ) } >
424+ < i className = "react-image-icon" onClick = { ( ) => rotateFnc ( 90 ) } >
417425 
418426 </ i >
419427 < i
420- className = "icon react-image-icon"
428+ className = "react-image-icon"
421429 onClick = { ( ) => rotateFnc ( - 90 ) }
422430 style = { { transform : 'rotateY(180deg)' } }
423431 >
424432 
425433 </ i >
426- < i className = "icon react-image-icon" onClick = { next } >
434+ < i className = "react-image-icon" onClick = { next } >
427435 
428436 </ i >
429437 </ div >
@@ -453,6 +461,29 @@ export default class ImgPpreview extends React.PureComponent {
453461 </ div >
454462 </ div >
455463 </ div >
464+ </ >
465+ )
466+ }
467+
468+ render ( ) {
469+ const { state, mouseUpHandle, mouseWheelHandle } = this
470+ return (
471+ < div
472+ id = "imgPreview"
473+ ref = { el => {
474+ this . $el = el
475+ } }
476+ className = "img-viewer-container"
477+ style = { { display : state . open ? 'flex' : 'none' } }
478+ onMouseUp = { mouseUpHandle }
479+ onWheel = { mouseWheelHandle }
480+ draggable = "false"
481+ >
482+ { this . _renderIcon ( ) }
483+
484+ { this . _renderImg ( ) }
485+
486+ { this . _renderFooter ( ) }
456487 </ div >
457488 )
458489 }
0 commit comments