Commit eb9da6e3 authored by 田翔's avatar 田翔

手动处理未分组情况

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