Commit a831958d authored by wty's avatar wty

新增可拖动的弹窗组件,现在所有弹窗都可以拖动了

parent ff18bb58
...@@ -16,16 +16,20 @@ ...@@ -16,16 +16,20 @@
background: rgba(0, 0, 0, 0.7); background: rgba(0, 0, 0, 0.7);
button { button {
padding: 0;
border-radius: 5px; border-radius: 5px;
} }
.close { .close {
width: 23px; width: 23px;
height: 23px; height: 23px;
font-size: 18px;
color: #ffffff; color: #ffffff;
text-align: left;
background: rgba(0, 0, 0, 0.8); background: rgba(0, 0, 0, 0.8);
img {
width: 18px;
height: 18px;
vertical-align: sub;
}
} }
} }
......
...@@ -4,7 +4,8 @@ import notFollow from '../../static/notFollow.png' ...@@ -4,7 +4,8 @@ import notFollow from '../../static/notFollow.png'
import followed from '../../static/followed.png' import followed from '../../static/followed.png'
import setting from '../../static/setting.svg' import setting from '../../static/setting.svg'
import trash from '../../static/trash.svg' import trash from '../../static/trash.svg'
import {useContext} from "react"; import dragIcon from '../../static/dragIcon.svg'
import {useContext, useState} from "react";
import {PopContext, Root} from "../../dataCenter/Root"; import {PopContext, Root} from "../../dataCenter/Root";
import PopToolBoxConfig from "../Pop_ToolBoxConfig/Pop_toolBoxConfig"; import PopToolBoxConfig from "../Pop_ToolBoxConfig/Pop_toolBoxConfig";
...@@ -12,6 +13,7 @@ function ContentItem(props) { ...@@ -12,6 +13,7 @@ function ContentItem(props) {
const {fetchData, updateIndex} = useContext(Root) const {fetchData, updateIndex} = useContext(Root)
const {showPop} = useContext(PopContext) const {showPop} = useContext(PopContext)
const {toolBoxIcon, toolBoxName, toolBoxDesc, toolBoxUrl, follow, toolBoxId} = props.value const {toolBoxIcon, toolBoxName, toolBoxDesc, toolBoxUrl, follow, toolBoxId} = props.value
const [itemIcon, setItemIcon] = useState(toolBoxIcon)
const jumpUrl = url => { const jumpUrl = url => {
window.location.href = url window.location.href = url
} }
...@@ -22,11 +24,12 @@ function ContentItem(props) { ...@@ -22,11 +24,12 @@ function ContentItem(props) {
return ( return (
<div className="content-item"> <div className="content-item">
<div className="content-adminTool"> <div className="content-adminTool">
<img src={dragIcon} alt=""/>
<img src={setting} alt="" onClick={()=>showPop((<PopToolBoxConfig value={props.value}/>))}/> <img src={setting} alt="" onClick={()=>showPop((<PopToolBoxConfig value={props.value}/>))}/>
<img src={trash} alt="" onClick={() => deleteItem(toolBoxId)}/> <img src={trash} alt="" onClick={() => deleteItem(toolBoxId)}/>
</div> </div>
<div className="item-icon" onClick={() => jumpUrl(toolBoxUrl)}> <div className="item-icon" onClick={() => jumpUrl(toolBoxUrl)}>
<img src={toolBoxIcon ? toolBoxIcon : defaultIcon} alt={toolBoxName}/> <img src={itemIcon} onError={(e)=> setItemIcon(defaultIcon)}/>
</div> </div>
<div className="item-name" onClick={() => jumpUrl(toolBoxUrl)}>{toolBoxName}</div> <div className="item-name" onClick={() => jumpUrl(toolBoxUrl)}>{toolBoxName}</div>
<div className="item-desc">{toolBoxDesc}</div> <div className="item-desc">{toolBoxDesc}</div>
......
import {useContext, useRef, useState} from "react";
import {PopContext} from "../../dataCenter/Root";
import closeIcon from '../../static/closeIcon.svg'
function PopContainer(props) {
const dragRef = useRef()
const {hidePop} = useContext(PopContext)
const [offset, setOffset] = useState({x: 0, y: 0})
const [draggable, setDraggable] = useState(false)
const handleMouseDown = e => {
e.stopPropagation()
setDraggable(true)
setOffset({
x: e.clientX - dragRef.current['getBoundingClientRect']().x,
y: e.clientY - dragRef.current['getBoundingClientRect']().y
})
}
const handleMouseUp = () => setDraggable(false)
const handleMouseMove = e => {
if (draggable) {
dragRef.current.style.transform = `translate(${e.clientX - offset.x}px,${e.clientY - offset.y}px)`
}
}
return (
<div className="drag-Container"
onMouseUp={() => handleMouseUp()}
onMouseMove={(e) => handleMouseMove(e)}>
<div className="Pop-container"
ref={dragRef}
>
<div className="Pop-tool" onMouseDown={e => handleMouseDown(e)}>
<button className="close" onClick={() => hidePop()}><img src={closeIcon}/></button>
</div>
{props.children}
</div>
</div>
)
}
export default PopContainer
...@@ -2,11 +2,12 @@ import {useContext} from "react"; ...@@ -2,11 +2,12 @@ import {useContext} from "react";
import {PopContext, Root} from "../../dataCenter/Root"; import {PopContext, Root} from "../../dataCenter/Root";
import {useFormState} from "../../utils/hook"; import {useFormState} from "../../utils/hook";
import PopConfirm from "../PopConfirm/PopConfirm"; import PopConfirm from "../PopConfirm/PopConfirm";
import PopContainer from "../PopContainer/PopContainer";
function Pop_toolBoxConfig(props) { function Pop_toolBoxConfig(props) {
const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, toolBoxId} = props.value const {toolBoxName, toolBoxIcon, toolBoxDesc, toolBoxUrl, toolBoxId} = props.value
const {fetchData, updateIndex} = useContext(Root) const {fetchData, updateIndex} = useContext(Root)
const {hidePop,showPop} = useContext(PopContext) const {hidePop, showPop} = useContext(PopContext)
const [input, setInput] = useFormState({ const [input, setInput] = useFormState({
toolBoxName, toolBoxName,
toolBoxIcon, toolBoxIcon,
...@@ -21,10 +22,7 @@ function Pop_toolBoxConfig(props) { ...@@ -21,10 +22,7 @@ function Pop_toolBoxConfig(props) {
return ( return (
<div className="Pop-container"> <PopContainer>
<div className="Pop-tool">
<button className="close" onClick={() => hidePop()}>X</button>
</div>
<h2 className='Pop-title'>{toolBoxName}</h2> <h2 className='Pop-title'>{toolBoxName}</h2>
<div className="formArea"> <div className="formArea">
<div className="input-group "> <div className="input-group ">
...@@ -53,9 +51,12 @@ function Pop_toolBoxConfig(props) { ...@@ -53,9 +51,12 @@ function Pop_toolBoxConfig(props) {
</div> </div>
</div> </div>
<div className="Pop-bottom"> <div className="Pop-bottom">
<button className='btn-submit-addToolBox' onClick={() => showPop((<PopConfirm title={`确定要修改${toolBoxName}吗?`}/>))}>提交</button> <button className='btn-submit-addToolBox'
</div> onClick={() => updateToolBox()}>提交
</button>
</div> </div>
</PopContainer>
) )
} }
......
...@@ -2,6 +2,7 @@ import './Pop_addToolBox.scss' ...@@ -2,6 +2,7 @@ import './Pop_addToolBox.scss'
import {useContext, useRef} from "react"; import {useContext, useRef} from "react";
import {PopContext, Root} from "../../dataCenter/Root"; import {PopContext, Root} from "../../dataCenter/Root";
import {useFormState} from "../../utils/hook"; import {useFormState} from "../../utils/hook";
import PopContainer from "../PopContainer/PopContainer";
function Pop_addToolBox() { function Pop_addToolBox() {
const {fetchData, updateIndex} = useContext(Root) const {fetchData, updateIndex} = useContext(Root)
...@@ -15,11 +16,7 @@ function Pop_addToolBox() { ...@@ -15,11 +16,7 @@ function Pop_addToolBox() {
} }
return ( return (
<div className="Pop-container" <PopContainer>
ref={PopRef}>
<div className="Pop-tool">
<button className="close" onClick={() => hidePop()}>X</button>
</div>
<h2 className='Pop-title'>新建工具盒</h2> <h2 className='Pop-title'>新建工具盒</h2>
<div className="formArea"> <div className="formArea">
<div className="input-group "> <div className="input-group ">
...@@ -50,7 +47,7 @@ function Pop_addToolBox() { ...@@ -50,7 +47,7 @@ function Pop_addToolBox() {
<div className="Pop-bottom"> <div className="Pop-bottom">
<button className='btn-submit-addToolBox' onClick={() => addToolBox()}>提交</button> <button className='btn-submit-addToolBox' onClick={() => addToolBox()}>提交</button>
</div> </div>
</div> </PopContainer>
) )
} }
......
import {useContext} from "react"; import {useContext} from "react";
import {PopContext, Root} from "../../dataCenter/Root"; import {PopContext, Root} from "../../dataCenter/Root";
import {useFormState} from "../../utils/hook"; import {useFormState} from "../../utils/hook";
import PopContainer from "../PopContainer/PopContainer";
import './Pop_addType.scss'
function Pop_addType(props) {
function Pop_addType(props){
const {fetchData, updateIndex} = useContext(Root) const {fetchData, updateIndex} = useContext(Root)
const {hidePop} = useContext(PopContext) const {hidePop} = useContext(PopContext)
const [input, setInput] = useFormState() const [input, setInput] = useFormState()
const addType = () => { const addType = () => {
...@@ -13,14 +17,12 @@ function Pop_addType(props){ ...@@ -13,14 +17,12 @@ function Pop_addType(props){
} }
return ( return (
<div className="Pop-container"> <PopContainer>
<div className="Pop-tool">
<button className="close" onClick={() => hidePop()}>X</button>
</div>
<h2 className='Pop-title'>新建类型</h2> <h2 className='Pop-title'>新建类型</h2>
<div className="formArea"> <div className="formArea">
<div className="input-group "> <div className="input-group ">
<input type="text" onChange={e => setInput('typeName', e.target.value)} defaultValue={input?.typeName} <input type="text" onChange={e => setInput('typeName', e.target.value)}
defaultValue={input?.typeName}
min={1} required/> min={1} required/>
<span> 类型名称</span> <span> 类型名称</span>
</div> </div>
...@@ -28,9 +30,8 @@ function Pop_addType(props){ ...@@ -28,9 +30,8 @@ function Pop_addType(props){
<div className="Pop-bottom"> <div className="Pop-bottom">
<button className='btn-submit-addToolBox' onClick={() => addType()}>提交</button> <button className='btn-submit-addToolBox' onClick={() => addType()}>提交</button>
</div> </div>
</div> </PopContainer>
) )
} }
export default Pop_addType export default Pop_addType
@import "../../common/popStyle"; @import "../../common/popStyle";
.drag-Container{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.Pop-container{ .Pop-container{
position: absolute; position: absolute;
top: 100px; top: 0;
left: 200px; left: 0;
} }
...@@ -4,9 +4,12 @@ import {Root} from "../../dataCenter/Root"; ...@@ -4,9 +4,12 @@ import {Root} from "../../dataCenter/Root";
function ToolType (props) { function ToolType (props) {
const {dataCenter} = useContext(Root) const {dataCenter} = useContext(Root)
const [typeId, setTypeId] = useState(1) const [typeId, setTypeId] = useState(0)
return ( return (
<div className="tab-tool-type"> <div className="tab-tool-type">
{
<div className={typeId === 0 ?'item-tool-type item-tool-type-selected' : 'item-tool-type'} onClick={()=>setTypeId(0)}>全部</div>
}
{ {
dataCenter?.type?.length && dataCenter.type.map(v => { dataCenter?.type?.length && dataCenter.type.map(v => {
const classNameArr = ['item-tool-type '] const classNameArr = ['item-tool-type ']
......
...@@ -5,6 +5,7 @@ import {useContext, useEffect, useState} from "react"; ...@@ -5,6 +5,7 @@ import {useContext, useEffect, useState} from "react";
import PopAddToolBox from "../component/Pop_addToolBox/Pop_addToolBox"; import PopAddToolBox from "../component/Pop_addToolBox/Pop_addToolBox";
import {PopContext, Root} from "../dataCenter/Root"; import {PopContext, Root} from "../dataCenter/Root";
import PopAddType from "../component/Pop_addType/Pop_addType"; import PopAddType from "../component/Pop_addType/Pop_addType";
import logo from '../static/logo.png'
function Index() { function Index() {
const {updateIndex} = useContext(Root) const {updateIndex} = useContext(Root)
...@@ -23,7 +24,7 @@ function Index() { ...@@ -23,7 +24,7 @@ function Index() {
<div className="index"> <div className="index">
<div className="nav"> <div className="nav">
<div className="nav-title">Dui123</div> <div className="nav-title"><img src={logo} alt=""/></div>
</div> </div>
<div className="adminTool"> <div className="adminTool">
<button className='btn-admin' onClick={() => setPop((<PopAddToolBox/>))}>新建工具盒</button> <button className='btn-admin' onClick={() => setPop((<PopAddToolBox/>))}>新建工具盒</button>
......
...@@ -32,6 +32,11 @@ body { ...@@ -32,6 +32,11 @@ body {
line-height: 40px; line-height: 40px;
font-weight: bold;; font-weight: bold;;
text-align: center; text-align: center;
margin-left: 20px;
img {
width: 100%;
}
} }
} }
......
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1630047440929" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1458" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M257.28 212.053333a32 32 0 0 0-45.226667 45.226667L466.773333 512l-254.72 254.72a32 32 0 1 0 45.226667 45.226667L512 557.226667l254.72 254.72a32 32 0 1 0 45.226667-45.226667L557.226667 512l254.72-254.72a32 32 0 0 0-45.226667-45.226667L512 466.773333 257.28 212.053333z" fill="#ffffff" p-id="1459"></path></svg>
\ No newline at end of file
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1630047561806" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1233" data-spm-anchor-id="a313x.7781069.0.i1" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M544 256h-64v512h64V256z" fill="#040000" p-id="1234"></path><path d="M493.29 210.71l-64.11 64.11c-16.67 16.67-4.87 45.18 18.71 45.18h128.22c23.58 0 35.38-28.51 18.71-45.18l-64.11-64.11a26.47 26.47 0 0 0-37.42 0zM493.29 813.29l-64.11-64.11c-16.67-16.67-4.87-45.18 18.71-45.18h128.22c23.58 0 35.38 28.51 18.71 45.18l-64.11 64.11a26.47 26.47 0 0 1-37.42 0zM768 480.01H256V544h512v-63.99z" fill="#000000" p-id="1235" data-spm-anchor-id="a313x.7781069.0.i0" class="selected"></path><path d="M209.84 530.8l65.06 64.5c16.71 16.56 45.1 4.7 45.1-18.8v-129c0-23.52-28.39-35.35-45.1-18.79l-65.06 64.5a26.47 26.47 0 0 0 0 37.59zM813.29 530.71l-64.11 64.11C732.5 611.49 704 599.69 704 576.11V447.89c0-23.58 28.5-35.39 45.18-18.71l64.11 64.11a26.47 26.47 0 0 1 0 37.42z" fill="#000000" p-id="1236" data-spm-anchor-id="a313x.7781069.0.i4" class="selected"></path></svg>
\ No newline at end of file
import {useCallback, useState} from "react"; import {useCallback, useRef, useState} from "react";
const useFormState = (initialValues = {}) => { const useFormState = (initialValues = {}) => {
const [input, setInput] = useState(initialValues) const [input, setInput] = useState(initialValues)
...@@ -10,6 +10,51 @@ const useFormState = (initialValues = {}) => { ...@@ -10,6 +10,51 @@ const useFormState = (initialValues = {}) => {
return [input, setInputData] return [input, setInputData]
} }
const useDrag = () => {
}
//这个hook很有意思,怎么样保存return出去的那个组件的数据呢
function usePopContainer(props) {
const dragRef = useRef()
const [offset, setOffset] = useState({x: 0, y: 0})
const [draggable, setDraggable] = useState(false)
const handleMouseDown = e => {
e.stopPropagation()
setDraggable(true)
setOffset({
x: e.clientX - dragRef.current['getBoundingClientRect']().x,
y: e.clientY - dragRef.current['getBoundingClientRect']().y
})
}
const handleMouseUp = () => setDraggable(false)
const handleMouseMove = e => {
if (draggable) {
dragRef.current.style.transform = `translate(${e.clientX - offset.x}px,${e.clientY - offset.y}px)`
console.log(dragRef.current.style.transform)
}
}
return {
PopContainer: props => (
<div className="drag-Container"
onMouseUp={() => handleMouseUp()}
onMouseMove={(e) => handleMouseMove(e)}>
<div className="Pop-container"
ref={dragRef}
>
{props.children}
</div>
</div>
),
dragMouseDown: e => handleMouseDown(e)
}
}
export { export {
useFormState useFormState,
useDrag,
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment