Commit 431ecb15 authored by 田翔's avatar 田翔

fix: 字段名称处理

parent 468c8e53
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "1.5.4", "version": "1.5.5",
"description": "1.5.4: 样式更新", "description": "1.5.5: 字段名称处理",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -131,7 +131,7 @@ const textWidgets = [ ...@@ -131,7 +131,7 @@ const textWidgets = [
title: '字段名称', title: '字段名称',
type: 'string', type: 'string',
widget: 'FieldNames', widget: 'FieldNames',
tableName: "{{console.log('1',rootValue)}}", // tableName: "{{console.log('1',rootValue)}}",
required: true, required: true,
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
...@@ -1314,7 +1314,7 @@ const selectWidgets = [ ...@@ -1314,7 +1314,7 @@ const selectWidgets = [
placeholder: { placeholder: {
title: '提示语', title: '提示语',
type: 'string', type: 'string',
// widget: 'Placeholder', default: '点击下拉选择内容',
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
}, },
......
import React, { useRef, useEffect, useState, useContext, forwardRef, createContext, useMemo } from 'react' import React, { useRef, useEffect, useState, useContext, forwardRef, createContext, useMemo } from 'react'
import { ConfigProvider, message, Modal } from 'antd' import { ConfigProvider, message, Modal, Button } from 'antd'
import Generator from 'fr-generator' import Generator from 'fr-generator'
import { settings, baseSettings, globalSettings } from './config' import { settings, baseSettings, globalSettings } from './config'
import widgets from '../widgets' import widgets from '../widgets'
...@@ -17,6 +17,7 @@ const FormDesigner = (props, ref) => { ...@@ -17,6 +17,7 @@ const FormDesigner = (props, ref) => {
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [schema, setSchema] = useState({}) const [schema, setSchema] = useState({})
const designerRef = useRef(null) const designerRef = useRef(null)
const formRenderRef = useRef(null)
const settingsParent = useMemo(() => { const settingsParent = useMemo(() => {
let settingsParent = [] let settingsParent = []
...@@ -39,7 +40,7 @@ const FormDesigner = (props, ref) => { ...@@ -39,7 +40,7 @@ const FormDesigner = (props, ref) => {
if (typeof data === 'string') { if (typeof data === 'string') {
setTimeout(() => { setTimeout(() => {
designerRef?.current?.setValue(JSON.parse(data)) designerRef?.current?.setValue(JSON.parse(data))
setSchema(JSON.parse(data)) // setSchema(JSON.parse(data))
}, 0) }, 0)
} }
} else { } else {
...@@ -67,10 +68,15 @@ const FormDesigner = (props, ref) => { ...@@ -67,10 +68,15 @@ const FormDesigner = (props, ref) => {
text: '提交', text: '提交',
onClick: async (value) => { onClick: async (value) => {
const errors = designerRef.current.getErrorFields() const errors = designerRef.current.getErrorFields()
const json = designerRef.current.getValue()
if (errors.length) { if (errors.length) {
return message.error('请按照提示完善表单内容') return message.error('请按照提示完善表单内容')
} }
const { code, data, msg } = await saveTableConfig(designerRef.current.getValue()) // console.log('json.properties', json.properties)
// if (json.properties && Object.keys(json.properties).includes(v => !v.includes('分组名称'))) {
// return message.info('包含未分组形态!')
// }
const { code, data, msg } = await saveTableConfig(json)
if (code === 0) { if (code === 0) {
message.info('保存成功') message.info('保存成功')
} else { } else {
...@@ -80,12 +86,12 @@ const FormDesigner = (props, ref) => { ...@@ -80,12 +86,12 @@ const FormDesigner = (props, ref) => {
} }
] ]
const onChange = (value) => { const testSubmit = async () => {
// console.log('value', value) const { formValue, errors } = await formRenderRef?.current?.getValues()
} if (errors.length) {
return message.error('表单校验未通过!')
const onCanvasSelect = (schema) => { }
// console.log('schema', schema) console.log('formValue', formValue)
} }
return ( return (
...@@ -99,9 +105,7 @@ const FormDesigner = (props, ref) => { ...@@ -99,9 +105,7 @@ const FormDesigner = (props, ref) => {
validation={true} validation={true}
ref={designerRef} ref={designerRef}
extraButtons={extraButtons} extraButtons={extraButtons}
onChange={onChange}
widgets={widgets} widgets={widgets}
onCanvasSelect={onCanvasSelect}
settings={settingsParent} settings={settingsParent}
commonSettings={baseSettings} commonSettings={baseSettings}
globalSettings={globalSettings} globalSettings={globalSettings}
...@@ -113,9 +117,17 @@ const FormDesigner = (props, ref) => { ...@@ -113,9 +117,17 @@ const FormDesigner = (props, ref) => {
onOk={() => setVisible(false)} onOk={() => setVisible(false)}
onCancel={() => setVisible(false)} onCancel={() => setVisible(false)}
visible={visible} visible={visible}
getContainer={false}
destroyOnClose destroyOnClose
footer={
<div>
<Button onClick={() => setVisible(false)}>取消</Button>
<Button onClick={() => setVisible(false)}>确定</Button>
<Button onClick={testSubmit}>测试提交</Button>
</div>
}
> >
<FormRender schema={schema} /> <FormRender ref={formRenderRef} schema={schema} />
</Modal> </Modal>
</div> </div>
</div> </div>
......
import React, { useState, useContext, forwardRef, createContext } from 'react' import React, { useState, useContext, forwardRef, useImperativeHandle } from 'react'
import FormRender, { useForm } from 'form-render' import FormRender, { useForm } from 'form-render'
import { ConfigProvider } from 'antd' import { ConfigProvider } from 'antd'
import widgets from '../widgets' import widgets from '../widgets'
const XRender = (props, ref) => { const XRender = (props, ref) => {
const { schema } = props useImperativeHandle(ref, () => (
{
getValues
}
))
const { schema } = props
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext) const { getPrefixCls } = useContext(ConfigProvider.ConfigContext)
const prefixCls = getPrefixCls('pandaXform') const prefixCls = getPrefixCls('pandaXform')
const pandaXform = getPrefixCls() const pandaXform = getPrefixCls()
const [extraData, setExtraData] = useState({})
const [parseFormData, setParseFormData] = useState({})
const [listData, setListData] = useState([])
const form = useForm() const form = useForm()
const getValues = async () => {
let { data, errors } = await form.submit()
// console.log('form', form, errorFields)
// form.formData()
let formValue = []
Object.keys(data).map((k) => {
Object.keys(data[k]).map((key) => {
formValue.push({ fieldName: key, fieldValue: data[k][key] + '' })
})
})
return {
formValue,
errors,
}
}
return ( return (
<div className={prefixCls}> <div className={prefixCls}>
<FormRender <FormRender
configProvider={{ prefixCls: pandaXform }} configProvider={{ prefixCls: pandaXform }}
form={form} form={form}
schema={schema} schema={schema}
// onChange={form.setValues}
mapping={{ mapping={{
object: 'Header', object: 'Header',
}} }}
...@@ -33,5 +50,4 @@ const XRender = (props, ref) => { ...@@ -33,5 +50,4 @@ const XRender = (props, ref) => {
} }
export default forwardRef(XRender) export default forwardRef(XRender)
...@@ -4,8 +4,8 @@ import city from '../../../../constant/city' ...@@ -4,8 +4,8 @@ import city from '../../../../constant/city'
const CascadeSelector = (props) => { const CascadeSelector = (props) => {
const { value, onChange, schema } = props const { value, onChange, schema, addons } = props
const { presetValue, disabled, soruceType, options, dictionary } = schema const { presetValue, disabled, placeholder, soruceType, } = schema
const enums = useMemo(() => { const enums = useMemo(() => {
if (soruceType === '城市数据') { if (soruceType === '城市数据') {
...@@ -64,10 +64,10 @@ const CascadeSelector = (props) => { ...@@ -64,10 +64,10 @@ const CascadeSelector = (props) => {
} }
findCityData(city) findCityData(city)
// 分发监听 // 分发监听
const cityValue = result.map(item => { const cityValue = result.map(v => v.label)
return item.label; if (addons) {
}) onChange(cityValue.join('/'))
onChange && onChange(cityValue.join('/')); }
} }
useEffect(() => { useEffect(() => {
...@@ -76,6 +76,8 @@ const CascadeSelector = (props) => { ...@@ -76,6 +76,8 @@ const CascadeSelector = (props) => {
return ( return (
<Cascader <Cascader
allowClear
placeholder={placeholder}
value={value ? getDefaultValue(value) : []} value={value ? getDefaultValue(value) : []}
onChange={cascaderChange} onChange={cascaderChange}
disabled={disabled} disabled={disabled}
......
...@@ -93,22 +93,25 @@ const PersonSelector = (props) => { ...@@ -93,22 +93,25 @@ const PersonSelector = (props) => {
const selectChange = (value) => { const selectChange = (value) => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, isMultiple ? value.join(',') : value) onChange(isMultiple ? value.join(',') : value)
// addons.setValue(addons.dataPath, isMultiple ? value.join(',') : value)
} }
} }
const inputFocus = async () => { const inputFocus = async () => {
setVisible(true) if (addons) {
setLoading(true) setVisible(true)
const { code, data, msg } = await getUserListForRole({}) setLoading(true)
if (code === 0) { const { code, data, msg } = await getUserListForRole({})
if (Array.isArray(data)) { if (code === 0) {
setGroupPerson(data) if (Array.isArray(data)) {
setGroupPerson(data)
}
} else {
message.error(msg)
} }
} else { setLoading(false)
message.error(msg)
} }
setLoading(false)
} }
const getCount = (v) => { const getCount = (v) => {
...@@ -243,12 +246,6 @@ const PersonSelector = (props) => { ...@@ -243,12 +246,6 @@ const PersonSelector = (props) => {
) )
} }
// if (interactiveType === '树形模态') {
// return (
// )
// }
return ( return (
<Select <Select
mode={isMultiple ? 'multiple' : null} mode={isMultiple ? 'multiple' : null}
......
import React, { useContext, useMemo, useState } from 'react' import React, { useContext, useEffect, useMemo, useState } from 'react'
import { Input, Select, message } from 'antd' import { Input, Select, message } from 'antd'
import { LoadTableFields, ReloadTableFields } from '../../../../../apis/process' import { LoadTableFields, ReloadTableFields } from '../../../../../apis/process'
...@@ -9,7 +9,8 @@ const FieldNames = (props) => { ...@@ -9,7 +9,8 @@ const FieldNames = (props) => {
const [fieldName, setFieldName] = useState([]) const [fieldName, setFieldName] = useState([])
const change = (value) => { const selectChange = (value) => {
console.log('value', value)
onChange(value) onChange(value)
} }
...@@ -21,13 +22,23 @@ const FieldNames = (props) => { ...@@ -21,13 +22,23 @@ const FieldNames = (props) => {
if (Array.isArray(data.root)) { if (Array.isArray(data.root)) {
setFieldName(data.root) setFieldName(data.root)
} }
console.log('props', props)
} }
useEffect(() => {
if (value && value.includes('#/')) {
let array = value.split('/')
if (array.length === 3) {
onChange(array[2])
}
}
}, [value])
return ( return (
<Select <Select
onFocus={onFocus} onFocus={onFocus}
onChange={change} onChange={selectChange}
style={{ maxWidth: '208px' }} style={{ width: '100%' }}
showSearch showSearch
optionFilterProp='children' optionFilterProp='children'
value={value} value={value}
......
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