当前位置: 首页 > news >正文

青岛网站建设公司排行电子商务网站建设总结与体会

青岛网站建设公司排行,电子商务网站建设总结与体会,2014网站建设,抚州北京网站建设效果图:如下 效果说明: 1. 点击“选择”按钮,打开弹窗 2. 左侧数据是调接口回显来的 3. 点击左侧某条数据,这条被点击的数据就会被添加到右侧 4. 右侧的数据可以上下拖动换位置 5. 右侧有数据时,点击"确定"…

效果图:如下

效果说明:

        1. 点击“选择”按钮,打开弹窗

        2. 左侧数据是调接口回显来的

        3. 点击左侧某条数据,这条被点击的数据就会被添加到右侧

        4. 右侧的数据可以上下拖动换位置

        5.  右侧有数据时,点击"确定" 按钮,数据就会以字符串拼接形式回显到TextArea框里,以顿号(、)分割 

        6. antd3里面的拖拽组件用的 react-dnd的

<DndProvider backend={HTML5Backend}> 。但在我这项目里DndProvider就不适用(项目react版本16.8.6),换一种react-dnd的低版本的写法即DragDropContext

        7. 还有一些样式的问题,没写全,需要细调

         

        

代码难免会涉及到业务需求,展示部分代码,全部复制不能实现效果,仅供参考

1. 父

import React, { PureComponent } from 'react'
import { Row, Input, Button, Modal, Spin } from 'antd'
import DragSortingTable from './DragSortingTable' // 拖拽组件const TextArea = Input.TextArea;class SelectProject extends PureComponent {constructor(props){super(props)this.state= {modalVisible: false,loading: false,disabled: false,rightList: [],leftList: [],value: '',}}// 打开弹窗openModal = () => {this.setState({ modalVisible: true })}// 关闭弹窗onCloseModal = () => {this.setState({ modalVisible: false })}// 确定onOkModal = () => {const { rightList } = this.state;let stringData = ''rightList && rightList.forEach((item, index) => {if(index < rightList.length -1){stringData += `${item.destOrgName}`} else {stringData += item.destOrgName}})this.setState({ modalVisible: false, value: stringData })}// 点击左侧数据okDataClick = (item) => {const { rightList } = this.state;let list = JSON.parse(JSON.stringify(rightList))if(JSON.stringify(list).indexOf(JSON.stringify(item)) > -1){message.warning(`已选择${item.destOrgName}`)return false;}list.push(item)this.setState({ rightList: list })}// 左侧数据展示treeLeftList = () => {const { leftList } = this.state;const radioLeftList = []if(leftList[0]){leftList.forEach(item => {radioLeftList.push(<div onClick={() => this.okDataClick(item)} style={{ lineHeight: '24px', padding: '4px 0', cursor: 'pointer' }}>{item.destOrgName}</div>)})}return radioLeftList}// 拖拽后,更新右侧数据updataSetState = (newData) => {this.setState({ rightList: newData })}// 删除当前行数据clearHang = (item) => {const { rightList } = this.state;const radioLeftList = []rightList.map(subItem => {if(subItem.destOrgName !== item.destOrgName){radioLeftList.push(subItem)}})this.setState({ rightList: radioLeftList })}// 左右两列整体展示buttonForm = () => {const { rightList } = this.state;return (<div><Row><Col span={12}><span>选择xx</span><div>{this.treeLeftList()}</div></Col><Col span={12}><div><span>已选中xx</span><a>清空</a></div><div><DragSortingTable2 rightList={rightList} updata={this.updataSetState} clearHang={this.clearHang} /> // 重点:用的antd3的表格可拖拽</div></Col></Row></div>)}render () {return (<div><Row><TextArea autoSize disabled={} value={this.state.value} /><Button onClick={() => {this.setState({ modalVisible: true,loading: true,}); this.openModal()}}disabled={this.state.disabled}>选择</Button></Row>{ this.state.modalVisible ?<Modal title='' visible={this.state.modalVisible} maskCloseable={false}width='60%' onCancel={this.onCloseModal} footer={<div style={{ textAlign: 'center'}}><Button onClick={this.onOkModal} type='primary'>确定</Button><Button onClick={this.onCloseModal}>关闭</Button></div>}><Spin spin={this.state.loading} tip='Loading'>{this.buttonForm()}</Spin></Modal> : null}</div>)}}export default SelectProject

拖拽子组件

相当于拖拽的table组件全部复制过来,然后主要改动是moveRow,和render里面的。

        1. 至于table有表格样式,就把表格样式设置border: 0   

        2. 页码不显示pagination={false}

        3. 当table没数据时,会显示一个空数据的图标,把空数据图标隐藏起来:z-index: -2

2. 子

import { Table } from 'antd';
import { DragDropContext, DragSource, DropTarget } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';let dragingIndex = -1;class DragSortingTable extends PureComponent {render() {const { isOver, connectDragSource, connectDropTarget, moveRow, ...restProps } = this.props;const style = { ...restProps.style, cursor: 'move' };let { className } = restProps;if (isOver) {if (restProps.index > dragingIndex) {className += ' drop-over-downward';}if (restProps.index < dragingIndex) {className += ' drop-over-upward';}}return connectDragSource(connectDropTarget(<tr {...restProps} className={className} style={style} />),);}
}const rowSource = {beginDrag(props) {dragingIndex = props.index;return {index: props.index,};},
};const rowTarget = {drop(props, monitor) {const dragIndex = monitor.getItem().index;const hoverIndex = props.index;// Don't replace items with themselvesif (dragIndex === hoverIndex) {return;}// Time to actually perform the actionprops.moveRow(dragIndex, hoverIndex);// Note: we're mutating the monitor item here!// Generally it's better to avoid mutations,// but it's good here for the sake of performance// to avoid expensive index searches.monitor.getItem().index = hoverIndex;},
};const DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({connectDropTarget: connect.dropTarget(),isOver: monitor.isOver(),
}))(DragSource('row', rowSource, connect => ({connectDragSource: connect.dragSource(),}))(BodyRow),
);class DragSortingTable extends React.Component {components = {body: {row: DragableBodyRow,},};// 拖拽moveRow = (dragIndex, hoverIndex) => {const {rightList, updataSetState} = this.props;const dragRow = rightList[dragIndex];const newDataList = [...rightList]newDataList.splice(dragIndex, 1)newDataList.splice(hoverIndex, 0, dragRow)updataSetState(newDataList)};render() {const columns = [{title: <span style={{fontSize:'12px', color: '#71bbff'}}>{'长按可拖动排序'}</span>,dataIndex: 'destOrgName',key: 'destOrgName',render: (text, record) => {return (<span>{text}</span><a onClick={() => this.props.clearHang(record)} style={{ float:'right'}}>x</a>)}}];return (<Tablecolumns={columns}dataSource={this.props.rightList} // 父级传过来的components={this.components}onRow={(record, index) => ({index,moveRow: this.moveRow,})}pagination={false} // 不显示页码className='dataListTable'/>);}
}}const DragSortingTable2 = DragDropContext(HTML5Backend)(DragSortingTable)
export default DragSortingTable2

http://www.yayakq.cn/news/261779/

相关文章:

  • 旅游网站建设那家好国内做网站的企业
  • 六安网站关键词排名优化报价河北省正定县城乡建设网站
  • 家用宽带怎么做网站 访问网站建设中界面模板
  • 工信部查询网站备案奉节网站建设公司
  • wordpress子目录建站怎么选择主题网上免费自己设计商标
  • wex5做网站建设企业网站企业网上银行登录官网下载
  • 外贸 礼品 网站shopex网站
  • 网站备案收录下降wordpress 配置模板
  • h5网站制作案例分析专门做家具的网站
  • 网站建设中常用的技术有哪些专门做二维码的网站
  • 海棠网站是什么意思网站优化建设方案
  • ih5做的网站怎么上传无锡哪里做网站
  • 信阳做网站汉狮网络建设银行防钓鱼网站
  • 做网站的广告词重庆网站建设外包公司
  • 中国建设教育协会网站培训中心艺术字体设计网
  • 做网站有哪些好处杭州关键词排名系统
  • 平原县网站建设nginx wordpress 404
  • 做30个精品网站网站前后台建设难吗
  • 滨州建设厅网站杭州市住房和城乡建设厅网站
  • 做冲压件加工有什么好网站ui设计师的工作内容包括哪些
  • 青州哪里做网站公司宣传策划方案
  • 惠州建站方案创建网站怎么弄
  • 快速建立平台网站开发需要多少钱深圳发布稳增长措施
  • 好的建筑设计网站学做电商的网站
  • 番号网站怎么做母婴用品网站建设规划
  • 网站 数据库模板wordpress去掉搜索
  • 石家庄做外贸网站做网站一年的费用
  • 先进网站建设有哪些江苏建设标准网站
  • 淄博网站推广公司网站建设襄阳
  • excel做网页放进网站前端个人介绍网站模板下载