feat:增加loop容器组件
This commit is contained in:
parent
90180fc913
commit
b5b6278d1a
|
|
@ -134,7 +134,7 @@ const dndList2 = [
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
drapStore.setState(dndList)
|
// drapStore.setState(dndList)
|
||||||
|
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import drapStore from "@/mobx/DrapStore";
|
||||||
import {Content, StepDragType, StepType} from "@/component/type";
|
import {Content, StepDragType, StepType} from "@/component/type";
|
||||||
import style from "./css/DrapItem.module.less"
|
import style from "./css/DrapItem.module.less"
|
||||||
import {stepMap} from "@/component/step";
|
import {stepMap} from "@/component/step";
|
||||||
|
let id = 0
|
||||||
export const getDropStoreId = (type?:string) =>{
|
export const getDropStoreId = (type?:string) =>{
|
||||||
const DropStore = {
|
const DropStore = {
|
||||||
id:0,
|
id:0,
|
||||||
|
|
@ -15,8 +15,9 @@ export const getDropStoreId = (type?:string) =>{
|
||||||
DropStore.type = type
|
DropStore.type = type
|
||||||
}
|
}
|
||||||
return function (){
|
return function (){
|
||||||
DropStore.id +=1
|
id +=1
|
||||||
const store = {...DropStore}
|
const store = {...DropStore}
|
||||||
|
store.id = id;
|
||||||
store.tag = store.type+"-"+store.id
|
store.tag = store.type+"-"+store.id
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +59,7 @@ const CardItem = memo((props:CardItemProps) => {
|
||||||
moveCard(droppedId, originalIndex,item, props.parent)
|
moveCard(droppedId, originalIndex,item, props.parent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log(props.tag,tag)
|
||||||
// 相同组件不允许移动
|
// 相同组件不允许移动
|
||||||
if(props.tag===tag){
|
if(props.tag===tag){
|
||||||
return
|
return
|
||||||
|
|
@ -94,9 +96,10 @@ const CardItem = memo((props:CardItemProps) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { index: overIndex } = findCard(id,item)
|
||||||
|
// 不同组件之间 tag不一样
|
||||||
// 存在id,id不同时,移动
|
// 存在id,id不同时,移动
|
||||||
if (tag===data.tag&&draggedId !== id) {
|
if (draggedId !== id&&overIndex>-1) {
|
||||||
const { index: overIndex } = findCard(id,item)
|
|
||||||
moveCard(draggedId, overIndex,item,props.parent)
|
moveCard(draggedId, overIndex,item,props.parent)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -111,7 +114,7 @@ const CardItem = memo((props:CardItemProps) => {
|
||||||
let { index: overIndex } = findCard(id,item)
|
let { index: overIndex } = findCard(id,item)
|
||||||
console.log(overIndex,id,tag,Propstag,item)
|
console.log(overIndex,id,tag,Propstag,item)
|
||||||
if(positionRef.current === 'bottom') overIndex += 1
|
if(positionRef.current === 'bottom') overIndex += 1
|
||||||
if(tag!==Propstag){
|
if(tag!==Propstag&&overIndex===-1){
|
||||||
const newItem = { ...item, id: String(new Date().getTime()) }
|
const newItem = { ...item, id: String(new Date().getTime()) }
|
||||||
console.log(data, props.data, props.data===props.parent)
|
console.log(data, props.data, props.data===props.parent)
|
||||||
insertCard(props.parent,overIndex, newItem)
|
insertCard(props.parent,overIndex, newItem)
|
||||||
|
|
@ -174,9 +177,7 @@ const CardItem = memo((props:CardItemProps) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{props.data.children&&props.data.children.length>0&&(<div ref={(node)=>childrenDrop(node)} className={style.woodExampleChildren}>
|
{props.data.children&&props.data.children.length>0&&(<div ref={(node)=>childrenDrop(node)} className={style.woodExampleChildren}>
|
||||||
|
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|
||||||
</div>)}
|
</div>)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ interface DragListProps {
|
||||||
const _tagStore = getDropStoreId()
|
const _tagStore = getDropStoreId()
|
||||||
const tagStore = _tagStore()
|
const tagStore = _tagStore()
|
||||||
const DragList = ({data,parent}:DragListProps) => {
|
const DragList = ({data,parent}:DragListProps) => {
|
||||||
|
console.log(data)
|
||||||
if(!Array.isArray(data)){
|
if(!Array.isArray(data)){
|
||||||
data = []
|
data = []
|
||||||
}
|
}
|
||||||
|
|
@ -99,4 +100,4 @@ const DragList = ({data,parent}:DragListProps) => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export default DragList
|
export default DragList
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,15 @@ import Options from "@/component/step/http/Options";
|
||||||
import style from "@/component/step/http/Http.module.less";
|
import style from "@/component/step/http/Http.module.less";
|
||||||
import {stepProps} from "@/component/step/type";
|
import {stepProps} from "@/component/step/type";
|
||||||
import Body from "./Body";
|
import Body from "./Body";
|
||||||
import {allData, HttpData, OptionsDataType} from "@/component/step/http/type";
|
import {allData, HttpData, OptionsDataType, UrlData} from "@/component/step/http/type";
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
data:HttpData
|
data:HttpData
|
||||||
}
|
}
|
||||||
|
const urlDefaultData:UrlData = {
|
||||||
|
path:"",
|
||||||
|
method:"GET"
|
||||||
|
}
|
||||||
|
|
||||||
const defaultMetod = ["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"].map(method=>{
|
const defaultMetod = ["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"].map(method=>{
|
||||||
return {
|
return {
|
||||||
|
|
@ -28,8 +31,9 @@ const defaultMetod = ["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"].map(
|
||||||
class HttpEditComponent extends Component<stepProps, State> {
|
class HttpEditComponent extends Component<stepProps, State> {
|
||||||
constructor(props: stepProps) {
|
constructor(props: stepProps) {
|
||||||
super(props);
|
super(props);
|
||||||
const content = props.data
|
const content = Object.assign({
|
||||||
console.log(props.data)
|
url:urlDefaultData
|
||||||
|
},props.data)
|
||||||
this.state = {
|
this.state = {
|
||||||
data:content
|
data:content
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import {Content, StepDragEnum, StepDragType} from "@/component/type";
|
import {Content, StepDragEnum, StepDragType} from "@/component/type";
|
||||||
import {getDropStoreId} from "@/component/CardItem";
|
import {getDropStoreId} from "@/component/CardItem";
|
||||||
import HttpEditComponent from "./edit"
|
import HttpEditComponent from "./Edit"
|
||||||
import {StepComponentExport} from "@/component/step";
|
import {StepComponentExport} from "@/component/step";
|
||||||
const name = "HttpStepComponent"
|
const name = "HttpStepComponent"
|
||||||
const tagStore = getDropStoreId()
|
const tagStore = getDropStoreId("http")
|
||||||
interface HttpInterface extends Content{
|
interface HttpInterface extends Content{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +35,6 @@ const defaultDataFunc = () =>{
|
||||||
data:data
|
data:data
|
||||||
}
|
}
|
||||||
return defaultData
|
return defaultData
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import HttpStepComponent from "./http"
|
import HttpStepComponent from "./http"
|
||||||
|
import LoopEditComponent from "./loop"
|
||||||
import {ComponentClass} from "react"
|
import {ComponentClass} from "react"
|
||||||
import {Content, StepDragType} from "@/component/type";
|
import {Content, StepDragType} from "@/component/type";
|
||||||
import {stepProps} from "@/component/step/type";
|
import {stepProps} from "@/component/step/type";
|
||||||
|
|
@ -20,7 +21,8 @@ interface stepMapType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const stepList = [
|
export const stepList = [
|
||||||
HttpStepComponent
|
HttpStepComponent,
|
||||||
|
LoopEditComponent
|
||||||
]
|
]
|
||||||
|
|
||||||
export const stepMap: stepMapType = {}
|
export const stepMap: stepMapType = {}
|
||||||
|
|
@ -30,4 +32,4 @@ stepList.forEach(step => {
|
||||||
export default {
|
export default {
|
||||||
stepList,
|
stepList,
|
||||||
stepMap
|
stepMap
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {Component} from "react";
|
||||||
|
import {LoopProps, LoopState} from "@/component/step/loop/type";
|
||||||
|
interface Interface {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoopEditComponent extends Component<LoopProps, LoopState>{
|
||||||
|
render() {
|
||||||
|
return <div>loop</div>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoopEditComponent
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
import {StepDragEnum, StepDragType} from "@/component/type";
|
||||||
|
import {LoopInterface} from "@/component/step/loop/type";
|
||||||
|
import {getDropStoreId} from "@/component/CardItem";
|
||||||
|
import {StepComponentExport} from "@/component/step";
|
||||||
|
import HttpEditComponent from "@/component/step/http/Edit";
|
||||||
|
import LoopEditComponent from "@/component/step/loop/Edit";
|
||||||
|
const tagStore = getDropStoreId("loop")
|
||||||
|
const name = "LoopStepComponent"
|
||||||
|
const LoopData:LoopInterface = {
|
||||||
|
content: "",
|
||||||
|
id:0,
|
||||||
|
label:"循环组件",
|
||||||
|
remark:"",
|
||||||
|
color:"red",
|
||||||
|
tag:"LOOP",
|
||||||
|
value:"",
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultDataFunc = () =>{
|
||||||
|
|
||||||
|
const data = {...LoopData}
|
||||||
|
|
||||||
|
const store = tagStore()
|
||||||
|
data.id = store.id
|
||||||
|
// data.mold = name
|
||||||
|
const defaultData:StepDragType<LoopInterface> = {
|
||||||
|
mold:name,
|
||||||
|
type:StepDragEnum.CONTAINER,
|
||||||
|
tag:store.tag,
|
||||||
|
id:String(store.id),
|
||||||
|
index:store.id,
|
||||||
|
originalIndex:store.id,
|
||||||
|
children:[],
|
||||||
|
parent:null,
|
||||||
|
data:data
|
||||||
|
}
|
||||||
|
return defaultData
|
||||||
|
}
|
||||||
|
const LoopStepOption = {
|
||||||
|
|
||||||
|
}
|
||||||
|
const exportData:StepComponentExport = {
|
||||||
|
Menu:{
|
||||||
|
label:"LOOP",
|
||||||
|
key:name,
|
||||||
|
options:LoopStepOption,
|
||||||
|
component:LoopEditComponent
|
||||||
|
},
|
||||||
|
defaultDataFunc
|
||||||
|
}
|
||||||
|
export default exportData
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import {Content, StepDragEnum, StepDragType} from "@/component/type";
|
||||||
|
import {HttpData} from "@/component/step/http/type";
|
||||||
|
|
||||||
|
interface LoopData {
|
||||||
|
|
||||||
|
}
|
||||||
|
interface LoopProps {
|
||||||
|
updateData:(data:string)=>void
|
||||||
|
data:HttpData
|
||||||
|
}
|
||||||
|
interface LoopState {
|
||||||
|
data:LoopData
|
||||||
|
}
|
||||||
|
interface LoopInterface extends Content{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import {Content, StepDragType} from "@/component/type";
|
import {Content, StepDragType} from "@/component/type";
|
||||||
import {HttpData} from "@/component/step/http/type";
|
import {HttpData} from "@/component/step/http/type";
|
||||||
|
import {LoopData} from "@/component/step/loop/type";
|
||||||
|
|
||||||
export interface stepProps {
|
export interface stepProps {
|
||||||
updateData:(data:string)=>void
|
updateData:(data:string)=>void
|
||||||
data:HttpData
|
data:HttpData|LoopData
|
||||||
}
|
}
|
||||||
export interface stepState {
|
export interface stepState {
|
||||||
data:string
|
data:string
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class DrapStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@action
|
@action
|
||||||
addChildren(drop: StepDragType<Content>, dropNew: StepDragType<Content>) {
|
addChildren(drop: StepDragType<Content>|null, dropNew: StepDragType<Content>) {
|
||||||
console.log(drop)
|
console.log(drop)
|
||||||
if(drop===null){
|
if(drop===null){
|
||||||
this.state.push(dropNew)
|
this.state.push(dropNew)
|
||||||
|
|
@ -116,7 +116,7 @@ class DrapStore {
|
||||||
DrapChildren[to] = drop
|
DrapChildren[to] = drop
|
||||||
DrapChildren[index] = ord
|
DrapChildren[index] = ord
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateState()
|
this.updateState()
|
||||||
}
|
}
|
||||||
@action
|
@action
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue