From 5e1ff4dc1c6d384af39cac1d3fbe6bf4b58566f2 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 19 十月 2023 17:59:22 +0800 Subject: [PATCH] 2023-10-19 --- src/templates/zshare/editTable/index.jsx | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx index 24902d3..eeb913e 100644 --- a/src/templates/zshare/editTable/index.jsx +++ b/src/templates/zshare/editTable/index.jsx @@ -2,13 +2,12 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { DndProvider, DragSource, DropTarget } from 'react-dnd' -import { Table, Input, InputNumber, Popconfirm, Form, Select, Radio, Cascader, notification, message, Modal, Typography } from 'antd' +import { Table, Input, InputNumber, Popconfirm, Switch, Form, Select, Radio, Cascader, notification, message, Modal, Typography } from 'antd' import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined, PlusOutlined } from '@ant-design/icons' import Utils from '@/utils/utils.js' import ColorSketch from '@/mob/colorsketch' import asyncComponent from '@/utils/asyncComponent' -import CusSwitch from './cusSwitch' import MKEmitter from '@/utils/events.js' import './index.scss' @@ -19,6 +18,52 @@ let dragingIndex = -1 const { Paragraph } = Typography +class CusSwitch extends Component { + static propTpyes = { + defaultValue: PropTypes.any, + value: PropTypes.any, + onChange: PropTypes.func + } + state = { + status: true + } + + UNSAFE_componentWillMount () { + const { defaultValue, value } = this.props + let initVal = 'true' + + if (this.props['data-__meta']) { + initVal = this.props['data-__meta'].initialValue + } else if (defaultValue) { + initVal = defaultValue + } else if (value) { + initVal = value + } + + if (initVal === 'false') { + initVal = false + } else { + initVal = true + } + + this.setState({status: initVal}) + } + + changeStatus = (val) => { + this.setState({ status: val }, () => { + let _val = val ? 'true' : 'false' + this.props.onChange && this.props.onChange(_val) + }) + } + + render() { + const { status } = this.state + return ( + <Switch checkedChildren="鏄�" unCheckedChildren="鍚�" checked={status} onChange={this.changeStatus} /> + ) + } +} + class BodyRow extends React.Component { render() { const { isOver, moveAble, connectDragSource, connectDropTarget, moveRow, ...restProps } = this.props -- Gitblit v1.8.0