'use strict'; import React, { useEffect, useState, useRef } from 'react'; import { connect } from 'react-redux'; import { push } from 'react-router-redux'; import { Popconfirm, Button, Popover, Skeleton, Form, Tag, Modal, Collapse, Input } from '@douyinfe/semi-ui'; import { IconSearch, IconHelpCircle, IconAlertCircle, IconMinusCircle, IconPlusCircle, IconPlus, IconRefresh } from '@douyinfe/semi-icons'; import { SkeletonScreen } from "$components"; const AddModel = props => { const { dispatch, user, error, actions, close, dataToModal, editionData, cancel } = props const { edition } = actions const [query, setQuery] = useState({ limit: 10, page: 0 }); //页码信息 const [limits, setLimits] = useState()//每页实际条数 const [detailV, setDetailV] = useState(false) const [property, setProperty] = useState([{ key: 'hb', value: 'ture' }]) const [attributeValue, setattributeValue] = useState({}) const api = useRef() useEffect(() => { if (dataToModal?.properties) { let data = [] for (let k in dataToModal?.properties) { data.push({ key: k, value: dataToModal?.properties[k] }) } setProperty(data) } }, []) useEffect(() => { let data = {} property?.map(v => { if (v.key) { data[v.key] = v.value } }) setattributeValue(data) }, [property]) return ( <> { api.current.validate().then(r => { // console.log(r); r.properties = JSON.stringify(attributeValue) if (dataToModal?.id) { dispatch(edition.putedge(dataToModal?.id, r)).then(res => { console.log(res) if (res.success) { close() } }) } else { dispatch(edition.postedge(r)).then(res => { // console.log(res); if (res.success) { close() } }) } }) }} width={500} onCancel={() => cancel()} >
(api.current = formApi)} layout="horizontal" labelAlign="right" labelWidth="114px" style={{ display: 'flex', flexDirection: 'column' }} > {/* */} {editionData?.map((v, i) => {v})}
设备属性:
{JSON.stringify(attributeValue)}
} itemKey="1">
key:
value:
{property?.map((v, i) =>
{ console.log(e); property?.splice(i, 1, { key: e, value: v.value }) setProperty([...property]) }} /> -- { property?.splice(i, 1, { key: v.key, value: e }) setProperty([...property]) }} /> {property?.length > 1 ? { console.log(i); console.log(property); property?.splice(i, 1) setProperty([...property]) }} /> : ""}
)} { setProperty([...property, { key: '', value: '' }]) }} />
); } function mapStateToProps (state) { const { auth, global } = state; return { user: auth.user, error: auth.error, actions: global.actions, apiRoot: global.apiRoot, isRequesting: auth.isRequesting } } export default connect(mapStateToProps)(AddModel);