Commit eb9da6e3 authored by 田翔's avatar 田翔

手动处理未分组情况

parent 94f06ddb
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.0.5", "version": "2.0.6",
"description": "2.0.5: 公式接口传参", "description": "2.0.6: 手动处理未分组情况",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
"moment": "^2.29.1", "moment": "^2.29.1",
"qrcode.react": "^3.1.0", "qrcode.react": "^3.1.0",
"react": "17.0.2", "react": "17.0.2",
"react-draggable": "^4.4.5",
"react-file-viewer": "^1.2.1", "react-file-viewer": "^1.2.1",
"react-sign2": "^0.0.3", "react-sign2": "^0.0.3",
"react-svg": "15.1.9", "react-svg": "15.1.9",
......
import React, { useRef, useEffect, useState, useContext, forwardRef, createContext, useMemo, useLayoutEffect } from 'react' import React, { useRef, useState, useContext, forwardRef, createContext, useMemo, useLayoutEffect } from 'react'
import { ConfigProvider, message, Modal, Button } from 'antd' import { ConfigProvider, message, Modal, Button } from 'antd'
import { ExclamationCircleOutlined } from '@ant-design/icons' import { ExclamationCircleOutlined } from '@ant-design/icons'
import Generator, { defaultSettings } from 'fr-generator' import Generator, { defaultSettings } from 'fr-generator'
...@@ -25,7 +25,7 @@ const FormDesigner = (props, ref) => { ...@@ -25,7 +25,7 @@ const FormDesigner = (props, ref) => {
let settingsParent = [] let settingsParent = []
settings.forEach(v => { settings.forEach(v => {
v.widgets.forEach(s => { v.widgets.forEach(s => {
s.schema.parent = { tableName } s.schema.tableNameParent = tableName
}) })
settingsParent.push(v) settingsParent.push(v)
}) })
...@@ -33,21 +33,52 @@ const FormDesigner = (props, ref) => { ...@@ -33,21 +33,52 @@ const FormDesigner = (props, ref) => {
}, [settings, tableName]) }, [settings, tableName])
const getJSON = (json, tableName) => { const getJSON = (json, tableName) => {
let parent = json?.properties let properties = json?.properties
let parent = {}
let paths = [] let paths = []
if (isObject(parent)) { let ungroupedChild = {}
for (let v in parent) { if (isObject(properties)) {
paths.push(v) for (let v in properties) {
let child = parent[v]?.properties if (properties[v].type === 'object') {
if (isObject(child)) { parent[v] = properties[v]
for (let s in child) { if (v !== '未分组') {
child[s].parent = { tableName } paths.push(v)
}
let child = properties[v]?.properties
if (isObject(child)) {
for (let s in child) {
child[s].tableNameParent = tableName
if (v === '未分组') {
ungroupedChild[s] = child[s]
}
}
}
} else {
ungroupedChild[v] = {
...properties[v],
tableNameParent: tableName
} }
} }
} }
} }
json.paths = paths if (JSON.stringify(ungroupedChild) !== '{}') {
return json parent['未分组'] = {
title: "(未分组)",
type: "object",
collapsed: false,
groupBase: {},
properties: {
...ungroupedChild
}
}
paths.push('未分组')
}
return {
...json,
paths,
properties: parent,
}
} }
const getTableConfig = async (tableName) => { const getTableConfig = async (tableName) => {
...@@ -105,6 +136,7 @@ const FormDesigner = (props, ref) => { ...@@ -105,6 +136,7 @@ const FormDesigner = (props, ref) => {
setVisible(true) setVisible(true)
let json = getJSON(designerRef.current.getValue(), tableName) let json = getJSON(designerRef.current.getValue(), tableName)
setSchema(json) setSchema(json)
designerRef.current.setValue(json)
} }
}, },
{ {
...@@ -112,13 +144,10 @@ const FormDesigner = (props, ref) => { ...@@ -112,13 +144,10 @@ const FormDesigner = (props, ref) => {
onClick: async (value) => { onClick: async (value) => {
const errors = designerRef.current.getErrorFields() const errors = designerRef.current.getErrorFields()
let json = getJSON(designerRef.current.getValue(), tableName) let json = getJSON(designerRef.current.getValue(), tableName)
designerRef.current.setValue(json)
if (errors.length) { if (errors.length) {
return message.error('请按照提示完善表单内容') return message.error('请按照提示完善表单内容')
} }
// 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) const { code, data, msg } = await saveTableConfig(json)
if (code === 0) { if (code === 0) {
message.info('保存成功') message.info('保存成功')
...@@ -155,7 +184,6 @@ const FormDesigner = (props, ref) => { ...@@ -155,7 +184,6 @@ const FormDesigner = (props, ref) => {
if (errors.length) { if (errors.length) {
return message.error('表单校验未通过!') return message.error('表单校验未通过!')
} }
console.log('获取数据', formValue, relationForm)
} }
return ( return (
......
...@@ -7,7 +7,7 @@ const FieldNames = (props) => { ...@@ -7,7 +7,7 @@ const FieldNames = (props) => {
let fieldsStr = window.sessionStorage.getItem('designerRef') || '' let fieldsStr = window.sessionStorage.getItem('designerRef') || ''
let fields = fieldsStr.split(',') || [] let fields = fieldsStr.split(',') || []
const { value, onChange, addons } = props const { value, onChange, addons } = props
const { parent, name } = addons.formData const { tableNameParent, name } = addons.formData
const [fieldName, setFieldName] = useState([]) const [fieldName, setFieldName] = useState([])
const options = useMemo(() => { const options = useMemo(() => {
...@@ -27,10 +27,10 @@ const FieldNames = (props) => { ...@@ -27,10 +27,10 @@ const FieldNames = (props) => {
} }
const onFocus = async () => { const onFocus = async () => {
if (!parent.tableName) { if (!tableNameParent) {
return message.info('缺少表名!') return message.info('缺少表名!')
} }
const { data } = await ReloadTableFields({ tableName: parent.tableName }) const { data } = await ReloadTableFields({ tableName: tableNameParent })
if (Array.isArray(data.root)) { if (Array.isArray(data.root)) {
setFieldName(data.root) setFieldName(data.root)
} }
......
...@@ -20,7 +20,7 @@ const fnList = [ ...@@ -20,7 +20,7 @@ const fnList = [
const CalculateRule = (props) => { const CalculateRule = (props) => {
const { value, onChange, addons } = props const { value, onChange, addons } = props
const { parent, name } = addons.formData const { tableNameParent, name } = addons.formData
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [fieldList, setFieldList] = useState([]) const [fieldList, setFieldList] = useState([])
const [rule, setRule] = useState([]) const [rule, setRule] = useState([])
...@@ -28,7 +28,7 @@ const CalculateRule = (props) => { ...@@ -28,7 +28,7 @@ const CalculateRule = (props) => {
const ruleText = useRef() const ruleText = useRef()
const getFieldList = async () => { const getFieldList = async () => {
let { code, data, msg } = await getTableNumberList(parent.tableName) let { code, data, msg } = await getTableNumberList(tableNameParent)
if (code === 0) { if (code === 0) {
let array = [] let array = []
if (isObject(data)) { if (isObject(data)) {
...@@ -129,7 +129,7 @@ const CalculateRule = (props) => { ...@@ -129,7 +129,7 @@ const CalculateRule = (props) => {
<div className={styles.leftTree}> <div className={styles.leftTree}>
<Tree <Tree
blockNode blockNode
defaultExpandedKeys={[parent.tableName]} defaultExpandedKeys={[tableNameParent]}
autoExpandParent={true} autoExpandParent={true}
onSelect={onSelect} onSelect={onSelect}
selectedKeys={[currentSelectId]} selectedKeys={[currentSelectId]}
......
...@@ -13,7 +13,7 @@ const fnList = [ ...@@ -13,7 +13,7 @@ const fnList = [
const ControlRules = (props) => { const ControlRules = (props) => {
const { value, onChange, addons } = props const { value, onChange, addons } = props
const { parent, name } = addons.formData const { tableNameParent, name } = addons.formData
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [fieldList, setFieldList] = useState([]) const [fieldList, setFieldList] = useState([])
const [rule, setRule] = useState([]) const [rule, setRule] = useState([])
...@@ -21,13 +21,13 @@ const ControlRules = (props) => { ...@@ -21,13 +21,13 @@ const ControlRules = (props) => {
const ruleText = useRef() const ruleText = useRef()
const getFieldList = async () => { const getFieldList = async () => {
let { code, data, msg } = await ReloadTableFields({ tableName: parent.tableName }) let { code, data, msg } = await ReloadTableFields({ tableName: tableNameParent })
if (code === 0) { if (code === 0) {
setFieldList([ setFieldList([
{ {
title: parent.tableName, title: tableNameParent,
key: parent.tableName, key: tableNameParent,
children: data.root.map(v => { return { title: v.name, key: `${parent.tableName}.${v.name}` } }) children: data.root.map(v => { return { title: v.name, key: `${tableNameParent}.${v.name}` } })
} }
]) ])
} else { } else {
...@@ -110,12 +110,12 @@ const ControlRules = (props) => { ...@@ -110,12 +110,12 @@ const ControlRules = (props) => {
getContainer={false} getContainer={false}
> >
{ {
parent?.tableName ? ( tableNameParent ? (
<div className={styles.configContent}> <div className={styles.configContent}>
<div className={styles.leftTree}> <div className={styles.leftTree}>
<Tree <Tree
blockNode blockNode
defaultExpandedKeys={[parent.tableName]} defaultExpandedKeys={[tableNameParent]}
autoExpandParent={true} autoExpandParent={true}
onSelect={onSelect} onSelect={onSelect}
selectedKeys={[currentSelectId]} selectedKeys={[currentSelectId]}
......
...@@ -9,7 +9,7 @@ const { TreeNode } = TreeSelect ...@@ -9,7 +9,7 @@ const { TreeNode } = TreeSelect
const Fieldshine = (props) => { const Fieldshine = (props) => {
const { addons, onChange, value } = props const { addons, onChange, value } = props
const { $id, accountName, parent } = addons.formData const { $id, accountName, tableNameParent } = addons.formData
const [form] = Form.useForm() const [form] = Form.useForm()
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
...@@ -40,7 +40,7 @@ const Fieldshine = (props) => { ...@@ -40,7 +40,7 @@ const Fieldshine = (props) => {
return message.info('请选择台账名称') return message.info('请选择台账名称')
} }
const req1 = QueryFields(accountName) const req1 = QueryFields(accountName)
const req2 = ReloadTableFields({ tableName: parent.tableName }) const req2 = ReloadTableFields({ tableName: tableNameParent })
const [res1, res2] = await Promise.all([req1, req2]) const [res1, res2] = await Promise.all([req1, req2])
if (res1.code === 0) { if (res1.code === 0) {
if (Array.isArray(res1.data)) { if (Array.isArray(res1.data)) {
......
...@@ -9,7 +9,7 @@ const { TreeNode } = TreeSelect ...@@ -9,7 +9,7 @@ const { TreeNode } = TreeSelect
const MappedField = (props) => { const MappedField = (props) => {
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { accountName, parent } = addons.formData const { accountName, tableNameParent } = addons.formData
const [form] = Form.useForm() const [form] = Form.useForm()
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [fromField, setFromField] = useState([]) const [fromField, setFromField] = useState([])
...@@ -20,7 +20,7 @@ const MappedField = (props) => { ...@@ -20,7 +20,7 @@ const MappedField = (props) => {
message.info('请选择台账名称') message.info('请选择台账名称')
} }
const req1 = QueryFields(accountName) const req1 = QueryFields(accountName)
const req2 = ReloadTableFields({ tableName: parent.tableName }) const req2 = ReloadTableFields({ tableName: tableNameParent })
const [res1, res2] = await Promise.all([req1, req2]) const [res1, res2] = await Promise.all([req1, req2])
if (res1.code === 0) { if (res1.code === 0) {
setToField(res1.data) setToField(res1.data)
......
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