当前位置:   article > 正文

React+Ant Design Pro 模态框modal拖动_react antd4 modal draggable弹出框如何实现拖动

react antd4 modal draggable弹出框如何实现拖动

先看效果

 

 先要下载插件:react-draggable

全部代码: 

  1. import React, { useEffect, useRef, useState } from 'react';
  2. import { ModalForm } from '@ant-design/pro-form';
  3. import Draggable from 'react-draggable';
  4. import styles from './style.less';
  5. import SetEfficacyTwo from '../setEfficacy_two';
  6. const addModel = (props) => {
  7. const { isShow, getIsShow, typeData, data, addConfirmCallBack } = props;
  8. const [bounds, setBounds] = useState({
  9. left: 0,
  10. top: 0,
  11. bottom: 0,
  12. right: 0,
  13. });
  14. const [disabled, setDisabled] = useState(false);
  15. const draggleRef = useRef(null);
  16. // 效验手机号设置_修改
  17. const [EfficacyOneModalVisible, setEfficacyOneModalVisible] = useState(false);
  18. const handleModalVisible = (e) => {
  19. getIsShow(e);
  20. };
  21. const onStart = (_event, uiData) => {
  22. const { clientWidth, clientHeight } = window.document.documentElement;
  23. const targetRect = draggleRef.current?.getBoundingClientRect();
  24. if (!targetRect) {
  25. return;
  26. }
  27. setBounds({
  28. left: -targetRect.left + uiData.x,
  29. right: clientWidth - (targetRect.right - uiData.x),
  30. top: -targetRect.top + uiData.y,
  31. bottom: clientHeight - (targetRect.bottom - uiData.y),
  32. });
  33. };
  34. return (
  35. <ModalForm
  36. title={
  37. <div
  38. onMouseOver={() => {
  39. if (disabled) {
  40. setDisabled(false);
  41. }
  42. }}
  43. onMouseOut={() => {
  44. setDisabled(true);
  45. }}
  46. style={{
  47. width: '100%',
  48. cursor: 'move',
  49. }}
  50. >
  51. 效验手机号设置
  52. </div>
  53. }
  54. width="480px"
  55. layout="horizontal"
  56. visible={isShow}
  57. modalProps={{
  58. destroyOnClose: true,
  59. modalRender: (modal) => {
  60. return (
  61. <Draggable
  62. disabled={disabled}
  63. bounds={bounds}
  64. onStart={(event, uiData) => onStart(event, uiData)}
  65. >
  66. <div ref={draggleRef}>{modal}</div>
  67. </Draggable>
  68. );
  69. },
  70. }}
  71. initialValues={data}
  72. submitter={{
  73. searchConfig: {
  74. submitText: '修改',
  75. resetText: '',
  76. },
  77. }}
  78. // request={async ()=> {
  79. // await waitTime(2000);
  80. // console.log(listData())
  81. // console.log(data)
  82. // return data
  83. // }}
  84. onVisibleChange={handleModalVisible}
  85. onFinish={async (value) => {
  86. console.log(value, 1);
  87. // addConfirmCallBack(value);
  88. setEfficacyOneModalVisible(true);
  89. }}
  90. >
  91. <div className="word flex flex_align_center flex_column_normal">
  92. <div className={styles.phone_num} style={{ marginLeft: '-80px' }}>
  93. <span className={styles.xing}>*&nbsp;</span>手机所属人&nbsp;
  94. <span className={styles.font_weight}>李三</span>
  95. </div>
  96. <div className={styles.phone_num}>
  97. <span className={styles.xing}>*&nbsp;</span>手机号码&nbsp;
  98. <span className={styles.font_weight}>11187850121</span>
  99. </div>
  100. </div>
  101. <SetEfficacyTwo
  102. isShow={EfficacyOneModalVisible}
  103. getShow={(e) => setEfficacyOneModalVisible(e)}
  104. ></SetEfficacyTwo>
  105. </ModalForm>
  106. );
  107. };
  108. export default addModel;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/115670
推荐阅读
相关标签
  

闽ICP备14008679号