提交 8dbb169b authored 作者: 钟是志's avatar 钟是志

24999 学生签约审核 拖拽范围和组件顺序优化

上级 b7af1ad5
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
* web端文件预览功能 * web端文件预览功能
*/ */
import React, {Component} from 'react'; import React, {Component} from 'react';
import { Popconfirm } from 'antd';
import {checkIsImage} from '@/webPublic/one_stop_public/libs/UploadCom'; import {checkIsImage} from '@/webPublic/one_stop_public/libs/UploadCom';
import { getModal } from '@/webPublic/one_stop_public/utils/utils'; import { getModal, getPopconfirm } from '@/webPublic/one_stop_public/utils/utils';
const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer'); const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer');
const Modal = getModal(); const Modal = getModal();
const Popconfirm = getPopconfirm();
export default class index extends Component { export default class index extends Component {
......
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import styles from './styles.less'; import styles from './styles.less';
import { Button, Icon, message } from 'antd'; import { Button, Icon } from 'antd';
import ShowItem, { dragEventList, zipImage } from './ShowItem'; import ShowItem, { dragEventList, zipImage } from './ShowItem';
import { apiRequest } from '../../utils/request'; import { apiRequest } from '../../utils/request';
import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils'; import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils';
import { getModal } from '@/webPublic/one_stop_public/utils/utils'; import { getMessage, getModal, getPopconfirm } from '@/webPublic/one_stop_public/utils/utils';
const Modal = getModal(); const Modal = getModal();
const message = getMessage();
const styleList = { const styleList = {
modalParentDiv: { modalParentDiv: {
display: 'grid', display: 'grid',
...@@ -24,18 +25,18 @@ const styleList = { ...@@ -24,18 +25,18 @@ const styleList = {
}, },
oneSetItem: { oneSetItem: {
position: 'absolute', position: 'absolute',
border: '1px solid red',
}, },
oneSetItemP: { oneSetItemP: {
marginBottom: 0, marginBottom: 0,
userSelect: 'none', userSelect: 'none',
}, },
draggableIcon:{ draggableIcon: {
position: 'absolute', // position: 'absolute',
left: '10', // left: '10',
top: '10', // top: '10',
color: 'red', // color: 'red',
zIndex: '10000', zIndex: '10000',
border: '1px solid red',
}, },
readOnlyImage: { readOnlyImage: {
width: '100%', width: '100%',
...@@ -77,19 +78,19 @@ export default function PictureSignature({ ...@@ -77,19 +78,19 @@ export default function PictureSignature({
form, form,
// fileInfo, // fileInfo,
...others ...others
}) { }) {
let imageRef = useRef(); let imageRef = useRef();
const [fileInfo, setFileInfo] = useState({ ...others?.fileInfo }); const [fileInfo, setFileInfo] = useState({ ...others?.fileInfo });
// const [fileInfo, setFileInfo] = useState(fakeFileInfo); // const [fileInfo, setFileInfo] = useState(fakeFileInfo);
const [openEdit, setOpenEdit] = useState(false); const [openEdit, setOpenEdit] = useState(false);
const [originSignConfig, setOriginConfig] = useState([]);
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [otherProps, setOtherProps] = useState({}); const [otherProps, setOtherProps] = useState({});
const [imageInfo, setImageInfo] = useState(null); const [imageInfo, setImageInfo] = useState(null);
const changeShowModal = () => { const changeShowModal = () => {
if (!showModal) { if (!showModal) {
if (!imageInfo && !disabled) { if (!imageInfo && !disabled) {
zipImage(fileInfo.path, fileInfo.name, otherProps?.backgroundImageWidth) zipImage(fileInfo.path, fileInfo.name, otherProps?.backgroundImageWidth).then(res => {
.then(res => {
let image = new Image(); //新建一个img标签(还没嵌入DOM节点) let image = new Image(); //新建一个img标签(还没嵌入DOM节点)
image.src = basicUrl + res; image.src = basicUrl + res;
image.onload = () => { image.onload = () => {
...@@ -124,6 +125,7 @@ export default function PictureSignature({ ...@@ -124,6 +125,7 @@ export default function PictureSignature({
let func = new Function(json.otherProps); let func = new Function(json.otherProps);
let otherPropsX = func(); let otherPropsX = func();
setOtherProps(otherPropsX); setOtherProps(otherPropsX);
setOriginConfig([...otherPropsX.signConfig]);
} catch (e) { } catch (e) {
console.log('签章组件 其余配置项出错,没有返回一个正确的值'); console.log('签章组件 其余配置项出错,没有返回一个正确的值');
return false; return false;
...@@ -140,11 +142,24 @@ export default function PictureSignature({ ...@@ -140,11 +142,24 @@ export default function PictureSignature({
saveSignConfigValue = '', saveSignConfigValue = '',
showImageWidth = 1200, showImageWidth = 1200,
} = otherProps; } = otherProps;
const deleteSignConfig = key => {
let findX = signConfig.findIndex(g => g.key === key);
signConfig.splice(findX, 1);
setOtherProps({
...otherProps,
signConfig,
});
};
const handleClickButton = clickType => { const handleClickButton = clickType => {
switch (clickType) { switch (clickType) {
case 'startEdit': // 开始签章 case 'startEdit': // 开始签章
// console.log(imageInfo); // console.log(imageInfo);
if (signConfig && signConfig.length < originSignConfig.length) {
setOtherProps({
...otherProps,
signConfig: originSignConfig,
});
}
setOpenEdit(true); setOpenEdit(true);
break; break;
case 'confirm': // 确定 case 'confirm': // 确定
...@@ -152,16 +167,18 @@ export default function PictureSignature({ ...@@ -152,16 +167,18 @@ export default function PictureSignature({
changeShowModal(); changeShowModal();
break; break;
case 'save': // 保存签章 case 'save': // 保存签章
Modal.confirm({
title: '是否确认生成签章图片?',
content: '生成后图片不能还原,请谨慎操作!',
okText: '确定',
cancelText: '取消',
onOk: () => {
let ratioX = backgroundImageWidth / showImageWidth; // 本来是 1500 的 图片 宽度变成了 1200 高度变成了 1200/1500 * imageInfo.height; let ratioX = backgroundImageWidth / showImageWidth; // 本来是 1500 的 图片 宽度变成了 1200 高度变成了 1200/1500 * imageInfo.height;
// let ratioY = 1200 / backgroundImageWidth * imageInfo.height;
// console.log(ratioX);
// return ;
let content = getContent(otherProps.signConfig, ratioX); let content = getContent(otherProps.signConfig, ratioX);
apiRequest('/ImageLibApi/merge', { apiRequest('/ImageLibApi/merge', {
background: fileInfo?.path, background: fileInfo?.path,
content, content,
}) }).then(res => {
.then(res => {
if (form && saveSignConfigValue) { if (form && saveSignConfigValue) {
form.setFieldsValue({ form.setFieldsValue({
[saveSignConfigValue]: content, [saveSignConfigValue]: content,
...@@ -176,6 +193,10 @@ export default function PictureSignature({ ...@@ -176,6 +193,10 @@ export default function PictureSignature({
setOpenEdit(false); setOpenEdit(false);
} }
}); });
}
})
break; break;
case 'restore': // 还原图片 case 'restore': // 还原图片
if (fileInfo.originPath) { if (fileInfo.originPath) {
...@@ -209,6 +230,32 @@ export default function PictureSignature({ ...@@ -209,6 +230,32 @@ export default function PictureSignature({
}); });
} else { } else {
return originButtons.map(g => { return originButtons.map(g => {
// if (g.clickType === 'startEdit') {
// console.log(signConfig);
// return <Popconfirm
// title={<div>
// <p>选择签章组件</p>
// <div>
// {signConfig.map((g) => {
// return <p key={g.key}>{g.name}</p>
// })}
// </div>
// </div>}
// onConfirm={()=>{
// handleClickButton(g.clickType);
// }}
// onCancel={()=>{}}
// okText="确定"
// key={g.key}
// cancelText="取消"
// >
// <Button
// type={g.type}
// >
// {g.name}
// </Button>
// </Popconfirm>
// }
return ( return (
<Button <Button
type={g.type} type={g.type}
...@@ -263,7 +310,7 @@ export default function PictureSignature({ ...@@ -263,7 +310,7 @@ export default function PictureSignature({
...styleList.modalDiv, ...styleList.modalDiv,
backgroundImage: `url(${basicUrl + fileInfo?.path})`, backgroundImage: `url(${basicUrl + fileInfo?.path})`,
width: showImageWidth, width: showImageWidth,
height: imageInfo.height / (imageInfo.width / showImageWidth), height: (imageInfo && imageInfo.height / (imageInfo.width / showImageWidth)) || 0,
}} }}
alt={'拖拽区域'} alt={'拖拽区域'}
draggable={false} draggable={false}
...@@ -282,24 +329,43 @@ export default function PictureSignature({ ...@@ -282,24 +329,43 @@ export default function PictureSignature({
left: g.x, left: g.x,
}} }}
> >
<div style={styleList.draggableIcon} <div style={styleList.draggableIcon} data-mes={g.key} draggable={true}>
data-mes={g.key} <div
draggable={true} style={{
display: 'inline',
}}
> >
<Icon type='scissor' /> <Icon
type="close-circle"
onClick={e => {
if (e && e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
deleteSignConfig(g.key);
}
}}
style={{
position: 'absolute',
top: 0,
right: 0,
cursor: 'pointer',
color: 'red',
}}
/>
</div> </div>
<ShowItem {...g} basicUrl={basicUrl} /> <ShowItem {...g} basicUrl={basicUrl} />
</div> </div>
</div>
); );
})} })}
</div> </div>
)} )}
{!openEdit && ( // 不开启签章功能 只是预览图片 {!openEdit && ( // 不开启签章功能 只是预览图片
<div style={styleList.readOnlyImage} <div style={styleList.readOnlyImage} draggable={false}>
>
<img <img
src={basicUrl + fileInfo?.path + `?v=${Math.random()}`} src={basicUrl + fileInfo?.path + `?v=${Math.random()}`}
alt={fileInfo.name} alt={fileInfo.name}
draggable={false}
style={{ style={{
width: `${showImageWidth}px`, width: `${showImageWidth}px`,
height: 'auto', height: 'auto',
...@@ -315,13 +381,7 @@ export default function PictureSignature({ ...@@ -315,13 +381,7 @@ export default function PictureSignature({
} }
export function SignArray(props) { export function SignArray(props) {
const { const { value, onChange, basicUrl, json, form } = props;
value,
onChange,
basicUrl,
json,
form,
} = props;
let files = value?.files || []; let files = value?.files || [];
const onChangeFile = (newFielInfo, imageIndex) => { const onChangeFile = (newFielInfo, imageIndex) => {
if (newFielInfo && newFielInfo.path) { if (newFielInfo && newFielInfo.path) {
......
...@@ -6,6 +6,8 @@ const oneSetItemP = { ...@@ -6,6 +6,8 @@ const oneSetItemP = {
marginBottom: 0, marginBottom: 0,
userSelect: 'none', userSelect: 'none',
}; };
let startX = 0;
let startY = 0;
const ShowItem = ({ basicUrl, type, x, y, ...otherInfo }) => { const ShowItem = ({ basicUrl, type, x, y, ...otherInfo }) => {
switch (type) { switch (type) {
...@@ -50,13 +52,17 @@ const ShowItem = ({ basicUrl, type, x, y, ...otherInfo }) => { ...@@ -50,13 +52,17 @@ const ShowItem = ({ basicUrl, type, x, y, ...otherInfo }) => {
export const dragEventList = (setOtherProps, otherProps) => { export const dragEventList = (setOtherProps, otherProps) => {
let draggedRef = null; let draggedRef = null;
let documentThis = window?.parent?.iframeParentComponent?.Modal ? window?.parent?.document : document; let documentThis = window?.parent?.iframeParentComponent?.Modal ? window?.parent?.document : document;
documentThis.onmousedown = function(evt){
startX = evt.offsetX;
startY = evt.offsetY;
}
documentThis.addEventListener( documentThis.addEventListener(
'dragstart', 'dragstart',
function(event) { function(event) {
// 保存拖动元素的引用(ref.) // 保存拖动元素的引用(ref.)
draggedRef = event.target; draggedRef = event.target;
event.target.style.opacity = 0.5; event.target.style.opacity = 0.2;
}, },
false, false,
); );
...@@ -85,8 +91,11 @@ export const dragEventList = (setOtherProps, otherProps) => { ...@@ -85,8 +91,11 @@ export const dragEventList = (setOtherProps, otherProps) => {
event.preventDefault(); event.preventDefault();
// 将拖动的元素到所选择的放置目标节点中 // 将拖动的元素到所选择的放置目标节点中
let infoClientRect = documentThis.getElementById('dropZone').getBoundingClientRect(); let infoClientRect = documentThis.getElementById('dropZone').getBoundingClientRect();
let leftNew = Math.ceil(event.clientX - infoClientRect.left); // console.log(startX, typeof startX, startY);
let topNew = Math.ceil(event.clientY - infoClientRect.top); // return ;
let leftNew = Math.ceil(event.clientX - infoClientRect.left) - startX;
let topNew = Math.ceil(event.clientY - infoClientRect.top) - startY;
// console.log(leftNew, topNew);
if(leftNew < 0 || leftNew > infoClientRect.width || topNew < 0 || topNew > infoClientRect.height){ if(leftNew < 0 || leftNew > infoClientRect.width || topNew < 0 || topNew > infoClientRect.height){
console.log('拖拽到了图片区域外部,不能进行拖拽'); console.log('拖拽到了图片区域外部,不能进行拖拽');
return false; return false;
......
...@@ -4,17 +4,14 @@ import { ...@@ -4,17 +4,14 @@ import {
Card, Card,
DatePicker, DatePicker,
Divider, Divider,
Table,
Form, Form,
Row, Row,
Col, Col,
Input, Input,
InputNumber, InputNumber,
message, message,
Modal,
Select, Select,
Tree, Tree,
Popconfirm,
Tooltip, Tooltip,
Spin, Spin,
} from 'antd'; } from 'antd';
...@@ -35,7 +32,10 @@ import { isEmpty } from 'lodash'; ...@@ -35,7 +32,10 @@ import { isEmpty } from 'lodash';
import FilePreview from '@/webPublic/one_stop_public/filePreview'; import FilePreview from '@/webPublic/one_stop_public/filePreview';
import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfig'; import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
import UploadCom from '@/webPublic/one_stop_public/libs/UploadCom'; import UploadCom from '@/webPublic/one_stop_public/libs/UploadCom';
import { getModal, getPopconfirm } from '@/webPublic/one_stop_public/utils/utils';
const Popconfirm = getPopconfirm();
const Modal = getModal();
const FormItem = Form.Item; const FormItem = Form.Item;
let AllWidth = 0; // 表格总长度 let AllWidth = 0; // 表格总长度
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
......
...@@ -9,9 +9,7 @@ import { ...@@ -9,9 +9,7 @@ import {
Col, Col,
Input, Input,
message, message,
Modal,
Select, Select,
Popconfirm,
Tooltip, Tooltip,
Spin, Spin,
Popover, Popover,
...@@ -37,8 +35,11 @@ import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfi ...@@ -37,8 +35,11 @@ import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfi
import UploadCom from '@/webPublic/one_stop_public/libs/UploadCom'; import UploadCom from '@/webPublic/one_stop_public/libs/UploadCom';
import ButtonDiy from '../../App/ButtonDiy/ButtonDiy'; import ButtonDiy from '../../App/ButtonDiy/ButtonDiy';
import { cloneDeep } from '../../copy/index'; import { cloneDeep } from '../../copy/index';
import { getPopconfirm, getModal } from '@/webPublic/one_stop_public/utils/utils';
const FormItem = Form.Item; const FormItem = Form.Item;
const Popconfirm = getPopconfirm();
const Modal = getModal();
let AllWidth = 0; // 表格总长度 let AllWidth = 0; // 表格总长度
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
......
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import styles from './styles.less'; import styles from './styles.less';
import Location from './components'; import Location from './components';
import { Button, Popconfirm } from 'antd'; import { Button } from 'antd';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { openToast } from './Notification'; import { openToast } from './Notification';
import { successToast, failToast } from './Toast'; import { successToast, failToast } from './Toast';
import { getPopconfirm } from '@/webPublic/one_stop_public/utils/utils';
const Popconfirm = getPopconfirm();
export default class location extends Component { export default class location extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
......
/* eslint no-useless-escape:0 import/prefer-default-export:0 */ /* eslint no-useless-escape:0 import/prefer-default-export:0 */
import { Modal } from 'antd'; import { Modal, Popconfirm } from 'antd';
const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
...@@ -41,3 +41,19 @@ export const getModal = () => { ...@@ -41,3 +41,19 @@ export const getModal = () => {
return Modal; return Modal;
} }
}; };
export const getPopconfirm = () => {
if (window?.parent?.iframeParentComponent?.Popconfirm) {
return window?.parent?.iframeParentComponent?.Popconfirm;
} else {
return Popconfirm;
}
};
export const getMessage = () => {
if (window?.parent?.iframeParentComponent?.Popconfirm) {
return window?.parent?.iframeParentComponent?.message;
} else {
return message;
}
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论