picModal.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React from "react";
  2. import {
  3. Spin,
  4. Button,
  5. Tabs,
  6. Table,
  7. message,
  8. Modal,
  9. Upload,
  10. Tooltip,
  11. } from "antd";
  12. import { splitUrl } from "@/tools";
  13. import "./remove.less"
  14. const PicModal = React.createClass({
  15. getInitialState() {
  16. return {
  17. newVisible: false,
  18. rotateDeg: 0,
  19. };
  20. },
  21. componentWillReceiveProps(nextProps) {
  22. this.setState({
  23. newVisible: nextProps.ShowModal,
  24. });
  25. },
  26. handleOk() {
  27. this.setState({
  28. newVisible: false,
  29. });
  30. // window.setTimeout( () => {
  31. // this.setState({
  32. // newVisible: true
  33. // });
  34. // },)
  35. },
  36. downImg() {
  37. let num = 0;
  38. for (let i = 0; i < this.props.picUrl.length; i++) {
  39. if (globalConfig.avatarHost + "/upload" + this.props.picUrl[i] == this.state.previewImage) {
  40. num = i;
  41. }
  42. }
  43. if (num == this.props.picUrl.length - 1) {
  44. return message.warning("已经是最后一张了哦");
  45. }
  46. this.state.previewImage = globalConfig.avatarHost + "/upload" + this.props.picUrl[num + 1];
  47. this.setState({
  48. previewImage: this.state.previewImage,
  49. rotateDeg: 0
  50. });
  51. },
  52. upImg() {
  53. let num = 0;
  54. for (let i = 0; i < this.props.picUrl.length; i++) {
  55. if (globalConfig.avatarHost + "/upload" + this.props.picUrl[i] == this.state.previewImage) {
  56. num = i;
  57. }
  58. }
  59. if (num == 0) {
  60. return message.warning("已经是第一张了哦");
  61. }
  62. this.state.previewImage = globalConfig.avatarHost + "/upload" + this.props.picUrl[num - 1];
  63. this.setState({
  64. previewImage: this.state.previewImage,
  65. rotateDeg: 0
  66. });
  67. },
  68. rotate() {
  69. let rotateDeg = this.state.rotateDeg + 90;
  70. this.setState({
  71. rotateDeg
  72. });
  73. },
  74. render() {
  75. return (
  76. <div>
  77. {this.props.picUrl.map((item, index) => {
  78. return (
  79. <div style={{ display: "inline-block" }}>
  80. <Upload
  81. className="demandDetailShow-upload"
  82. listType="picture-card"
  83. onChange={this.props.remove}
  84. fileList={
  85. item
  86. ? splitUrl(item, ",", globalConfig.avatarHost + "/upload")
  87. : []
  88. }
  89. onPreview={(file) => {
  90. this.setState({
  91. previewImage: file.url || file.thumbUrl,
  92. previewVisible: true,
  93. });
  94. }}
  95. />
  96. <Tooltip placement="top" title={this.props.remarks[index]}>
  97. <div style={{ textAlign: "center" }}>
  98. {this.props.remarks[index].length > 7 ? this.props.remarks[index].substring(0,7) + "..." : this.props.remarks[index]}
  99. </div>
  100. </Tooltip>
  101. </div>
  102. );
  103. })}
  104. <Modal
  105. maskClosable={false}
  106. footer={null}
  107. width={"50%"}
  108. visible={this.state.previewVisible}
  109. onCancel={() => {
  110. this.setState({ previewVisible: false, rotateDeg: 0 }, () => {
  111. });
  112. }}
  113. >
  114. <img
  115. alt=""
  116. style={{
  117. width: "100%",
  118. transform: `rotate(${this.state.rotateDeg}deg)`,
  119. }}
  120. src={this.state.previewImage || ""}
  121. />
  122. <Button
  123. onClick={this.rotate}
  124. style={{
  125. position: "relative",
  126. left: "50%",
  127. transform: "translateX(-50%)",
  128. }}
  129. >
  130. 旋转
  131. </Button>
  132. <Button
  133. onClick={this.upImg}
  134. style={{
  135. position: "absolute",
  136. left: -81,
  137. top: "50%",
  138. transform: "translateY(-50%)",
  139. }}
  140. >
  141. 上一张
  142. </Button>
  143. <Button
  144. onClick={this.downImg}
  145. style={{
  146. position: "absolute",
  147. right: -81,
  148. top: "50%",
  149. transform: "translateY(-50%)",
  150. }}
  151. >
  152. 下一张
  153. </Button>
  154. </Modal>
  155. </div>
  156. );
  157. },
  158. });
  159. export default PicModal;