Commit bd8fd13d authored by 田翔's avatar 田翔

fix: 关联表单完善

parent dbd05bb4
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "1.5.6", "version": "1.5.7",
"description": "1.5.6: 增加地址以及设备二维码配置,台账选择器隐射字段默认设置", "description": "1.5.7: 关联表单完善",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -250,6 +250,14 @@ export function GetTableConfigJson(paramas) { ...@@ -250,6 +250,14 @@ export function GetTableConfigJson(paramas) {
}) })
} }
//获取台账的json
export function GetTableJson(accountName) {
return request({
url: `/PandaWorkFlow/WorkFlow/AccountManage/GetTableJson?accountName=${accountName}`,
method: 'get',
})
}
//保存附加表信息,支持台账6.0 //保存附加表信息,支持台账6.0
export function saveTableConfig(data) { export function saveTableConfig(data) {
return request({ return request({
......
...@@ -81,7 +81,6 @@ const layoutWidgets = [ ...@@ -81,7 +81,6 @@ const layoutWidgets = [
schema: { schema: {
title: '分组名称', title: '分组名称',
type: 'object', type: 'object',
collapsed: true,
// theme: 'collapse:pure', // theme: 'collapse:pure',
// properties: { // properties: {
// title: { // title: {
...@@ -124,8 +123,8 @@ const textWidgets = [ ...@@ -124,8 +123,8 @@ const textWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true, properties: {},
properties: {} default: null
}, },
$id: { $id: {
title: '字段名称', title: '字段名称',
...@@ -154,7 +153,6 @@ const textWidgets = [ ...@@ -154,7 +153,6 @@ const textWidgets = [
presetValue: { presetValue: {
title: '默认值', title: '默认值',
type: 'string', type: 'string',
widget: 'InputDefault',
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
}, },
...@@ -669,7 +667,6 @@ const selectWidgets = [ ...@@ -669,7 +667,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -879,7 +876,6 @@ const selectWidgets = [ ...@@ -879,7 +876,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1045,7 +1041,6 @@ const selectWidgets = [ ...@@ -1045,7 +1041,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1204,7 +1199,6 @@ const selectWidgets = [ ...@@ -1204,7 +1199,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1309,7 +1303,6 @@ const selectWidgets = [ ...@@ -1309,7 +1303,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1432,7 +1425,6 @@ const selectWidgets = [ ...@@ -1432,7 +1425,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1467,7 +1459,6 @@ const selectWidgets = [ ...@@ -1467,7 +1459,6 @@ const selectWidgets = [
gorupSoruce: { gorupSoruce: {
title: '数据来源', title: '数据来源',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
role: { role: {
...@@ -1560,7 +1551,6 @@ const selectWidgets = [ ...@@ -1560,7 +1551,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1670,7 +1660,6 @@ const selectWidgets = [ ...@@ -1670,7 +1660,6 @@ const selectWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1705,7 +1694,6 @@ const selectWidgets = [ ...@@ -1705,7 +1694,6 @@ const selectWidgets = [
gorupSoruce: { gorupSoruce: {
title: '数据来源', title: '数据来源',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
accountName: { accountName: {
...@@ -1810,7 +1798,6 @@ const dateWidgets = [ ...@@ -1810,7 +1798,6 @@ const dateWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -1945,7 +1932,6 @@ const dateWidgets = [ ...@@ -1945,7 +1932,6 @@ const dateWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -2215,7 +2201,6 @@ const mapWidgets = [ ...@@ -2215,7 +2201,6 @@ const mapWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -2302,7 +2287,6 @@ const mapWidgets = [ ...@@ -2302,7 +2287,6 @@ const mapWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -2389,7 +2373,6 @@ const mapWidgets = [ ...@@ -2389,7 +2373,6 @@ const mapWidgets = [
groupBase: { groupBase: {
title: '基础信息', title: '基础信息',
type: 'object', type: 'object',
collapsed: true,
properties: {} properties: {}
}, },
$id: { $id: {
...@@ -2471,7 +2454,7 @@ const advancedWidgets = [ ...@@ -2471,7 +2454,7 @@ const advancedWidgets = [
text: '关联表单', text: '关联表单',
name: '关联表单', name: '关联表单',
schema: { schema: {
title: '关联表单', title: '',
name: '关联表单', name: '关联表单',
type: 'string', type: 'string',
widget: 'RelationForm', widget: 'RelationForm',
...@@ -2491,10 +2474,11 @@ const advancedWidgets = [ ...@@ -2491,10 +2474,11 @@ const advancedWidgets = [
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
}, },
title: { titleShow: {
title: '标题', title: '标题',
type: 'string', type: 'string',
widget: 'htmlInput', widget: 'htmlInput',
default: '关联表单',
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
}, },
...@@ -2550,12 +2534,13 @@ const advancedWidgets = [ ...@@ -2550,12 +2534,13 @@ const advancedWidgets = [
labelWidth: 80, labelWidth: 80,
required: true, required: true,
default: [], default: [],
dependencies: ['accountName'],
}, },
defaultShow: { defaultShow: {
title: '默认显示', title: '默认显示',
type: 'boolean', type: 'boolean',
widget: 'BooleanSwitch', widget: 'BooleanSwitch',
default: false, default: true,
displayType: 'row', displayType: 'row',
labelWidth: 80, labelWidth: 80,
}, },
...@@ -2566,7 +2551,27 @@ const advancedWidgets = [ ...@@ -2566,7 +2551,27 @@ const advancedWidgets = [
labelWidth: 80, labelWidth: 80,
widget: 'ControlShow', widget: 'ControlShow',
}, },
...groupStyle, groupStyle: {
title: '控件样式',
type: 'object',
properties: {}
},
width: {
title: '元素宽度',
type: 'string',
widget: 'percentSlider',
},
labelWidth: {
title: '标签宽度',
description: '默认值10',
default: 10,
type: 'number',
widget: 'slider',
max: 400,
props: {
hideNumber: true,
},
},
}, },
}, },
{ {
......
import React, { useRef, useEffect, useState, useContext, forwardRef, createContext, useMemo } from 'react' import React, { useRef, useEffect, useState, useContext, forwardRef, createContext, useMemo, useLayoutEffect } from 'react'
import { ConfigProvider, message, Modal, Button } 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'
...@@ -30,27 +30,22 @@ const FormDesigner = (props, ref) => { ...@@ -30,27 +30,22 @@ const FormDesigner = (props, ref) => {
return settingsParent return settingsParent
}, [settings, tableName]) }, [settings, tableName])
const getTableField = () => { const getTableConfig = async (tableName) => {
console.log('setSchema', settings)
}
const getTableConfig = async () => {
const { code, data, msg } = await GetTableConfigJson({ tableName }) const { code, data, msg } = await GetTableConfigJson({ tableName })
if (code === 0) { if (code === 0) {
if (typeof data === 'string') { if (data && typeof data === 'string') {
setTimeout(() => {
designerRef?.current?.setValue(JSON.parse(data)) designerRef?.current?.setValue(JSON.parse(data))
// setSchema(JSON.parse(data))
}, 0)
} }
} else { } else {
message.error(msg) message.error(msg)
} }
} }
useEffect(() => { useLayoutEffect(() => {
getTableConfig() if (tableName) {
}, []) getTableConfig(tableName)
}
}, [tableName])
const extraButtons = [ const extraButtons = [
false, false,
...@@ -87,10 +82,11 @@ const FormDesigner = (props, ref) => { ...@@ -87,10 +82,11 @@ const FormDesigner = (props, ref) => {
] ]
const testSubmit = async () => { const testSubmit = async () => {
const { formValue, errors } = await formRenderRef?.current?.getValues() const { formValue, relationForm, errors } = await formRenderRef?.current?.getValues()
if (errors.length) { if (errors.length) {
return message.error('表单校验未通过!') return message.error('表单校验未通过!')
} }
console.log('获取数据', formValue, relationForm)
} }
return ( return (
......
import React, { useState, useContext, forwardRef, useImperativeHandle } from 'react' import React, { useState, useContext, forwardRef, useImperativeHandle, createContext } 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'
export const GlobalStore = createContext(null)
const XRender = (props, ref) => { const XRender = (props, ref) => {
useImperativeHandle(ref, () => ( useImperativeHandle(ref, () => (
...@@ -15,22 +17,22 @@ const XRender = (props, ref) => { ...@@ -15,22 +17,22 @@ const XRender = (props, ref) => {
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 form = useForm() const form = useForm()
const getValues = async () => { const getValues = async () => {
let { data, errors } = await form.submit() let { data, errors } = await form.submit()
// console.log('form', form, errorFields)
// form.formData()
let formValue = [] let formValue = []
Object.keys(data).map((k) => { Object.keys(data).map((k) => {
if (k !== 'relationForm') {
Object.keys(data[k]).map((key) => { Object.keys(data[k]).map((key) => {
formValue.push({ fieldName: key, fieldValue: data[k][key] + '' }) formValue.push({ fieldName: key, fieldValue: data[k][key] })
}) })
}
}) })
return { return {
formValue, formValue,
errors, errors,
relationForm: data.relationForm
} }
} }
......
import React, { useMemo, forwardRef, useContext, useImperativeHandle } from 'react'
import { ConfigProvider } from 'antd'
import FormRender, { useForm } from 'form-render'
import widgets from './widgets'
const isObject = (obj) => typeof obj === 'object'
const BaseForm = (props, ref) => {
useImperativeHandle(ref, () => (
{
getValues
}
))
const { schemaForm, config, formState } = props
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext)
const prefixCls = getPrefixCls('pandaXform')
const pandaXform = getPrefixCls()
const form = useForm()
//表单需要显示的字段
const field = useMemo(() => {
const { fieldGroup, editFieldGroup, addFieldGroup } = config
let field = []
if (formState === '详情') {
field = fieldGroup ? fieldGroup.split(',') : []
} else if (formState === '添加') {
field = addFieldGroup ? addFieldGroup.split(',') : []
} else if (formState === '编辑') {
field = editFieldGroup ? editFieldGroup.split(',') : []
}
return field
}, [config, formState])
const schema = useMemo(() => {
const { group, values } = schemaForm
let parent = group?.properties
let parentObj = {}
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
let childObj = {}
if (isObject(child)) {
for (let s in child) {
if (field.includes(s)) {
let value = ''
values.forEach(v => {
if (v.fieldName === s) {
value = v.fieldValue
}
})
childObj[s] = { ...child[s], presetValue: value || child[s].presetValue }
} else {
}
}
}
if (JSON.stringify(childObj) !== '{}') {
parentObj[v] = { ...parent[v], properties: childObj }
}
}
}
return { ...group, properties: parentObj }
}, [schemaForm, field, formState])
const getValues = async () => {
let { data, errors } = await form.submit()
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 (
<div className={prefixCls}>
<FormRender
configProvider={{ prefixCls: pandaXform }}
mapping={{
object: 'Header',
}}
form={form}
schema={schema}
widgets={widgets}
/>
</div>
)
}
export default forwardRef(BaseForm)
\ No newline at end of file
import Header from '../../../Header'
import text from '../../../text'
import date from '../../../date'
import select from '../../../select'
import file from '../../../file'
import Signature from '../../Signature'
const coord = {
Signature
}
const widgets = {
Header,
...text,
...date,
...select,
...file,
...coord,
}
export default widgets
\ No newline at end of file
import React, { useEffect, useMemo, useState, useRef, useContext } from 'react' import React, { useEffect, useMemo, useState, useRef, useLayoutEffect, useContext, createContext } from 'react'
import styles from './index.less' import styles from './index.less'
import { import {
GetAccountPageList, GetAccountPageList,
...@@ -9,9 +9,10 @@ import { ...@@ -9,9 +9,10 @@ import {
EditTableDataInfo, EditTableDataInfo,
DeleteTableDataInfo DeleteTableDataInfo
} from '../../../../apis/process' } from '../../../../apis/process'
import { Table, Button, Modal, message, Popconfirm } from 'antd' import { Table, Button, Modal, message, Popconfirm, ConfigProvider } from 'antd'
import { SnippetsOutlined, PlusOutlined, FormOutlined, DeleteOutlined, } from '@ant-design/icons' import { SnippetsOutlined, PlusOutlined, FormOutlined, DeleteOutlined } from '@ant-design/icons'
import FormRender, { useForm } from 'form-render' import { GetTableJson } from '../../../../apis/process'
import BaseForm from './BaseForm'
const icons = { const icons = {
'详情': <SnippetsOutlined />, '详情': <SnippetsOutlined />,
...@@ -20,132 +21,105 @@ const icons = { ...@@ -20,132 +21,105 @@ const icons = {
} }
let formStateStr = '添加' let formStateStr = '添加'
const getFormDataObj = (formData) => {
let formDataObj = {}
Object.keys(formData).map((k) => {
if (k !== 'relationForm') {
Object.keys(formData[k]).map((key) => {
formDataObj[key] = formData[k][key] || ''
})
}
})
return formDataObj
}
const RelationForm = (props) => { const RelationForm = (props) => {
const fieldNames = ['事件编号', '工单编号'] const fieldNames = ['事件编号', '工单编号']
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { disabled, source, accountName } = schema const { disabled, accountName, defaultShow, controlShow, titleShow, mappedField } = schema
const [listData, setListData] = useState([])
const { codes } = parent const { codes } = parent
const form = useForm()
const [config, setConfig] = useState({ webShowFieldGroup: '', fieldGroup: '' }) const [config, setConfig] = useState({ webShowFieldGroup: '', fieldGroup: '' })
const [dataSource, setDataSource] = useState([]) const [dataSource, setDataSource] = useState([])
const [groupMeta, setGroupMeta] = useState([]) const [groupMeta, setGroupMeta] = useState([])
const [formData, setFormData] = useState([])
const [visible, setVisible] = useState(false) const [visible, setVisible] = useState(false)
const [formState, setFormState] = useState('详情') const [formState, setFormState] = useState('详情')
const [row, setRow] = useState({}) const [row, setRow] = useState({})
const parseFormRef = useRef(null) const [schemaGroup, setSchemaGroup] = useState({})
const [schemaValues, setSchemaValues] = useState([])
// const getMsg = () => { const baseFormRef = useRef(null)
// let fields = configInfo['映射字段'].map(v => v.toField)
// return `台账【${accountName}】缺少${fields.join('、')}字段`
// }
// const show = useMemo(() => {
// let str = configInfo['控制规则']
// try {
// let matchArr = str ? str.match(/\{(.+?)\}/g) : []
// matchArr?.forEach(v => {
// let value = v.replace(/{/g, '').replace(/}/g, '')
// let valueArr = value ? value.split('.') : []
// let fieldValue = parseFormData[valueArr[1]]
// str = str.replace(v, `'${fieldValue}'`)
// })
// str = str.replace(/=/g, '==')
// str = str.replace(/and/g, '&&')
// str = str.replace(/or/, '||')
// if (str && eval(str)) {
// return !configInfo['默认显示']
// }
// return configInfo['默认显示']
// } catch {
// message.error('字符串规则解析失败')
// return configInfo['默认显示']
// }
// }, [parseFormData, configInfo])
// const localForm = useMemo(() => {
// const { addFieldGroup } = config
// let array = []
// let field = addFieldGroup ? addFieldGroup.split(',') : []
// const getFieldValue = (s, parseFormData, codes) => {
// return codes ? (codes[s.fromField] || parseFormData[s.fromField]) : parseFormData[s.fromField]
// }
// field.forEach(v => {
// configInfo['映射字段'].forEach(s => {
// if (s.toField === v) {
// array.push({ fieldName: s.toField, fieldValue: getFieldValue(s, parseFormData, codes) })
// }
// })
// })
// return array
// }, [parseFormData, config, configInfo, codes, dataSource])
const localForm = []
const tablesSchema = useMemo(() => { const formDataObj = useMemo(() => {
const { fieldGroup, editFieldGroup, addFieldGroup } = config let formDataObj = {}
let field = [] if (addons) {
if (formState === '详情') { formDataObj = getFormDataObj(addons?.formData)
field = fieldGroup ? fieldGroup.split(',') : []
} else if (formState === '添加') {
field = addFieldGroup ? addFieldGroup.split(',') : []
} else if (formState === '编辑') {
field = editFieldGroup ? editFieldGroup.split(',') : []
}
let groups = []
groupMeta.forEach(v => {
let schema = []
v.schema.forEach(s => {
if (field.includes(s.fieldName)) {
schema.push({ ...s, readOnly: fieldNames.includes(s.fieldName) ? 1 : s.readOnly })
} }
return formDataObj
}, [addons?.formData])
const show = useMemo(() => {
if (addons) {
let str = controlShow
try {
let matchArr = str ? str.match(/\{(.+?)\}/g) : []
matchArr?.forEach(v => {
let value = v.replace(/{/g, '').replace(/}/g, '')
let valueArr = value ? value.split('.') : []
let fieldValue = formDataObj[valueArr[1]]
str = str.replace(v, `'${fieldValue}'`)
}) })
if (schema.length > 0) { str = str.replace(/and/g, '&&')
groups.push({ ...v, schema, }) str = str.replace(/or/, '||')
// console.log('str', str)
if (str && eval(str)) {
// addons.setSchemaByPath(addons.dataPath, { ...schema, hidden: !schema.hidden })
// console.log(addons)
return !defaultShow
}
return defaultShow
} catch {
// message.error('字符串规则解析失败')
return defaultShow
} }
})
return {
groups,
values: formState === '添加' ? localForm : formData
} }
}, [formState, localForm, groupMeta, formData, config]) return defaultShow
}, [formDataObj, defaultShow])
const groupMetaInfo = useMemo(() => { const localForm = useMemo(() => {
const { addFieldGroup } = config
let array = [] let array = []
const { webShowFieldGroup } = config let field = addFieldGroup ? addFieldGroup.split(',') : []
let field = webShowFieldGroup ? webShowFieldGroup.split(',') : [] const getFieldValue = (s, formDataObj, codes) => {
let groupArr = groupMeta.length ? groupMeta.reduce((f, n) => f.concat(n.schema), []) : [] return codes ? (codes[s.fromField] || formDataObj[s.fromField]) : formDataObj[s.fromField]
if (field.length > 0) { }
field.forEach(v => { field.forEach(v => {
groupArr.forEach(s => { mappedField.forEach(s => {
if (s.fieldName === v) { if (s.toField === v) {
array.push(s) array.push({ fieldName: s.toField, fieldValue: getFieldValue(s, formDataObj, codes) })
} }
}) })
}) })
}
return array return array
}, [groupMeta, config]) }, [formDataObj, config, mappedField, codes, dataSource])
const columns = useMemo(() => { const columns = useMemo(() => {
let btn = ['详情'] let btn = ['详情']
if (!disabled) { if (!disabled) {
btn = ['详情', '编辑', '删除'] btn = ['详情', '编辑', '删除']
} }
const { webShowFieldGroup } = config
let field = webShowFieldGroup ? webShowFieldGroup.split(',').filter(v => v) : []
let array = [] let array = []
if (groupMetaInfo.length > 0) { if (field.length > 0) {
array.push({ title: '序号', width: 50, align: 'center', render: (_, r, i) => i + 1 }) array.push({ title: '序号', width: 50, align: 'center', render: (_, r, i) => i + 1 })
groupMetaInfo.forEach(v => { field.forEach(v => {
array.push({ array.push({
title: v.alias, title: v,
dataIndex: v.fieldName, dataIndex: v,
key: v.fieldName, key: v,
ellipsis: { ellipsis: {
visibleTitle: false, visibleTitle: false,
}, },
// width: 120
}) })
}) })
array.push({ array.push({
...@@ -189,23 +163,16 @@ const RelationForm = (props) => { ...@@ -189,23 +163,16 @@ const RelationForm = (props) => {
}) })
} }
return array return array
}, [disabled, groupMetaInfo, dataSource, formState]) }, [disabled, config, dataSource, formState])
const isReadOnly = useMemo(() => {
if (formState === '编辑' || formState == '添加') {
return false
}
return true
}, [formState])
const rowClick = async (v, r) => { const rowClick = async (v, r) => {
if (addons) { if (addons) {
setRow(r) setRow(r)
if (v === '详情') { if (v === '详情') {
setFormData(getItem(r)) setSchemaValues(getItem(r))
setVisible(true) setVisible(true)
} else if (v === '编辑') { } else if (v === '编辑') {
setFormData(getItem(r)) setSchemaValues(getItem(r))
setVisible(true) setVisible(true)
} else if (v === '删除') { } else if (v === '删除') {
deleteTableInfo(r) deleteTableInfo(r)
...@@ -237,27 +204,20 @@ const RelationForm = (props) => { ...@@ -237,27 +204,20 @@ const RelationForm = (props) => {
const deleteTableInfo = (r) => { const deleteTableInfo = (r) => {
let listItem = { type: 'delete', accountTable: accountName, id: r.ID, values: getItem('delete', r) } let listItem = { type: 'delete', accountTable: accountName, id: r.ID, values: getItem('delete', r) }
let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
if (r.ID.includes('前端ID')) { if (r.ID.includes('前端ID')) {
let list = listData.filter(v => v.id !== r.ID) let list = relationForm.data.filter(v => v.id !== r.ID)
setListData(list) // setRelationForm({ ...relationForm, data: list })
addons.setValue('relationForm', { ...relationForm, data: list })
} else { } else {
setListData([...listData, listItem]) // setRelationForm({ ...relationForm, data: [...relationForm, listItem] })
addons.setValue('relationForm', { ...relationForm, data: [...relationForm.data, listItem] })
} }
let tableData = dataSource.filter(v => v.ID !== r.ID) let tableData = dataSource.filter(v => v.ID !== r.ID)
setDataSource(tableData) setDataSource(tableData)
onChange(`${tableData.length}`) onChange(`${tableData.length}`)
} }
const getTableInfo = async (r) => {
const { code, data } = await GetTableDataInfo({ accountName: accountName, id: Number(r.ID) })
if (code === 0) {
setFormData(data)
setVisible(true)
} else {
message.error('数据请求失败!')
}
}
const getConfig = async () => { const getConfig = async () => {
let { code, data, msg } = await GetAccountConfigInfo(accountName) let { code, data, msg } = await GetAccountConfigInfo(accountName)
if (code === 0) { if (code === 0) {
...@@ -269,9 +229,11 @@ const RelationForm = (props) => { ...@@ -269,9 +229,11 @@ const RelationForm = (props) => {
} }
const getGroupMeta = async () => { const getGroupMeta = async () => {
const { code, data, msg } = await GetTableGroupMeta(accountName) const { code, data, msg } = await GetTableJson(accountName)
if (code === 0) { if (code === 0) {
setGroupMeta(data) if (data && typeof data === 'string') {
setSchemaGroup(JSON.parse(data))
}
} else { } else {
message.error(msg) message.error(msg)
} }
...@@ -279,10 +241,11 @@ const RelationForm = (props) => { ...@@ -279,10 +241,11 @@ const RelationForm = (props) => {
const getQueryWheres = (addFieldGroup) => { const getQueryWheres = (addFieldGroup) => {
let queryWheres = [] let queryWheres = []
let formDataObj = getFormDataObj(addons?.formData)
addFieldGroup.forEach(v => { addFieldGroup.forEach(v => {
configInfo['映射字段'].forEach(s => { mappedField.forEach(s => {
if (s.toField === v) { if (s.toField === v) {
queryWheres.push({ field: s.toField, type: '等于', value: codes ? (codes[s.fromField] || parseFormData[s.fromField]) : parseFormData[s.fromField] }) queryWheres.push({ field: s.toField, type: '等于', value: codes ? (codes[s.fromField] || formDataObj[s.fromField]) : formDataObj[s.fromField] })
} }
}) })
}) })
...@@ -290,19 +253,20 @@ const RelationForm = (props) => { ...@@ -290,19 +253,20 @@ const RelationForm = (props) => {
} }
const getTableData = async (addFieldGroup) => { const getTableData = async (addFieldGroup) => {
// let queryWheres = getQueryWheres(addFieldGroup) if (!addons) return
// if (!queryWheres.length) { let queryWheres = getQueryWheres(addFieldGroup)
// onChange(`出错了,${getMsg()}`) if (!queryWheres.length) {
// } message.info('映射字段配置错误!')
}
let params = { let params = {
accountName: accountName, accountName: accountName,
direction: 'desc', direction: 'desc',
timeField: '录入时间', timeField: '录入时间',
pageIndex: 0, pageIndex: 0,
pageSize: 0, pageSize: 0,
// queryWheres queryWheres
} }
// if (queryWheres.every(v => !v.value)) return if (queryWheres.every(v => !v.value)) return
const { code, data, msg } = await GetAccountPageList(params) const { code, data, msg } = await GetAccountPageList(params)
if (code === 0) { if (code === 0) {
let tableData = JSON.parse(data.jsonData) let tableData = JSON.parse(data.jsonData)
...@@ -324,14 +288,19 @@ const RelationForm = (props) => { ...@@ -324,14 +288,19 @@ const RelationForm = (props) => {
} }
const onOk = async () => { const onOk = async () => {
let formData = parseFormRef.current.getFormValues() if (addons) {
console.log('addons', addons)
const { formValue, errors } = await baseFormRef.current.getValues()
if (errors.length) {
return message.error('请按照提示完善表单内容')
}
let type = row.ID.includes('前端ID') ? 'add' : 'edit' let type = row.ID.includes('前端ID') ? 'add' : 'edit'
let itemData = { type, accountTable: accountName, id: row.ID, values: formData } let itemData = { type, accountTable: accountName, id: row.ID, values: formValue }
if (formStateStr !== '添加') { if (formStateStr !== '添加') {
let array = [] let array = []
dataSource.forEach(v => { dataSource.forEach(v => {
if (v.ID === row.ID) { if (v.ID === row.ID) {
array.push({ ...v, ...getItem(formData) }) array.push({ ...v, ...getItem(formValue) })
} else { } else {
array.push({ ...v }) array.push({ ...v })
} }
...@@ -339,39 +308,53 @@ const RelationForm = (props) => { ...@@ -339,39 +308,53 @@ const RelationForm = (props) => {
setDataSource(array) setDataSource(array)
onChange(`${array.length}`) onChange(`${array.length}`)
} else if (formStateStr === '添加') { } else if (formStateStr === '添加') {
let array = [getItem(formData), ...dataSource] let array = [getItem(formValue), ...dataSource]
setDataSource(array) setDataSource(array)
onChange(`${array.length}`) onChange(`${array.length}`)
} }
let listArray = listData.filter(v => v.id !== itemData.id) let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
let listArray = relationForm.data.filter(v => v.id !== itemData.id)
listArray.push({ ...itemData }) listArray.push({ ...itemData })
setListData(listArray) addons.setValue('relationForm', { ...relationForm, data: listArray })
setVisible(false) setVisible(false)
} }
}
const addClick = () => { const addClick = () => {
// if (!localForm.length) { if (!localForm.length) {
// return message.error(getMsg()) return message.error(getMsg())
// } }
if (addons) { if (addons) {
if (JSON.stringify(schemaGroup) === '{}') {
return message.info(`台账[${accountName}]未配置形态!`)
}
setRow({ ID: `前端ID${new Date().getTime()}` }) setRow({ ID: `前端ID${new Date().getTime()}` })
setFormState('添加') setFormState('添加')
setSchemaValues(localForm)
formStateStr = '添加' formStateStr = '添加'
setVisible(true) setVisible(true)
} }
} }
useEffect(() => { useLayoutEffect(() => {
if (accountName) { if (accountName) {
getData() getData()
} }
}, [accountName]) }, [accountName])
console.log('tablesSchema', tablesSchema) useLayoutEffect(() => {
//初始化关联表单配置信息,初始显示隐藏
if (addons) {
let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
addons.setValue('relationForm', { ...relationForm, configs: [...relationForm.configs, schema] })
// addons.setSchemaByPath(addons.dataPath, { ...schema, hidden: !defaultShow })
}
}, [])
return ( return (
<div className={styles.relationForm}> <div className={styles.relationForm} style={{ display: show ? 'block' : 'none' }}>
<div className={styles.header}> <div className={styles.header}>
<span className='account-header-title'>{titleShow}</span>
{disabled ? null : <Button className={styles.headerBtn} type='primary' size='middle' icon={<PlusOutlined />} onClick={addClick}>添加</Button>} {disabled ? null : <Button className={styles.headerBtn} type='primary' size='middle' icon={<PlusOutlined />} onClick={addClick}>添加</Button>}
</div> </div>
<Table <Table
...@@ -384,16 +367,21 @@ const RelationForm = (props) => { ...@@ -384,16 +367,21 @@ const RelationForm = (props) => {
/> />
<Modal <Modal
title={accountName} title={accountName}
width='90%' width='80%'
bodyStyle={{ height: '700px', overflow: 'auto' }}
visible={visible} visible={visible}
onOk={onOk} onOk={onOk}
onCancel={() => setVisible(false)} onCancel={() => setVisible(false)}
bodyStyle={{ height: 700 }}
destroyOnClose destroyOnClose
> >
<FormRender <BaseForm
form={form} schemaForm={{
schema={tablesSchema} group: schemaGroup,
values: schemaValues,
}}
formState={formState}
config={config}
ref={baseFormRef}
/> />
</Modal> </Modal>
</div> </div>
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
height: 45px; height: 45px;
line-height: 45px; line-height: 45px;
position: relative; position: relative;
text-align: center;
// .account-header-title { // .account-header-title {
// width: 100%; // width: 100%;
// text-align: center; // text-align: center;
......
import React, { useState, useMemo } from 'react' import React, { useState, useMemo, useEffect } from 'react'
import { Select, message } from 'antd' import { Select, message } from 'antd'
import { GetSelectItemList, GetFieldValueFromTable, getStationListByUserID } from '../../../../apis/process' import { GetSelectItemList, GetFieldValueFromTable, getStationListByUserID } from '../../../../apis/process'
...@@ -13,13 +13,21 @@ const ComboBox = (props) => { ...@@ -13,13 +13,21 @@ const ComboBox = (props) => {
const [tableData, setTableData] = useState([]) const [tableData, setTableData] = useState([])
const [site, setSite] = useState([]) const [site, setSite] = useState([])
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue)
} else {
onChange(presetValue)
}
}, [presetValue])
const valueShow = useMemo(() => { const valueShow = useMemo(() => {
if (isMultiple || isEdit) { if (isMultiple || isEdit) {
return (value || presetValue) ? (value || presetValue).split(',') : [] return value ? value.split(',') : []
} else { } else {
return value || presetValue || null return value || null
} }
}, [isEdit, isMultiple, presetValue, value]) }, [isEdit, isMultiple, value])
const enums = useMemo(() => { const enums = useMemo(() => {
switch (soruceType) { switch (soruceType) {
......
...@@ -188,7 +188,7 @@ const PersonSelector = (props) => { ...@@ -188,7 +188,7 @@ const PersonSelector = (props) => {
{ {
v.userList.map(s => { v.userList.map(s => {
return ( return (
<Col span={8} style={{ margin: '8px 0', display: s.noShow ? 'none' : 'block' }}> <Col span={8} key={s.userID} style={{ margin: '8px 0', display: s.noShow ? 'none' : 'block' }}>
<Checkbox <Checkbox
value={s.userName} value={s.userName}
> >
......
...@@ -5,11 +5,16 @@ import { LoadTableFields, ReloadTableFields } from '../../../../../apis/process' ...@@ -5,11 +5,16 @@ import { LoadTableFields, ReloadTableFields } from '../../../../../apis/process'
const FieldNames = (props) => { const FieldNames = (props) => {
const { value, onChange, addons } = props const { value, onChange, addons } = props
const { tableNameParent } = addons.formData const { tableNameParent, name } = addons.formData
const [fieldName, setFieldName] = useState([]) const [fieldName, setFieldName] = useState([])
const selectChange = (value) => { const selectChange = (value) => {
if (name !== '关联表单') {
addons.setValueByPath('title', value)
} else {
addons.setValueByPath('titleShow', value)
}
onChange(value) onChange(value)
} }
...@@ -21,7 +26,6 @@ const FieldNames = (props) => { ...@@ -21,7 +26,6 @@ const FieldNames = (props) => {
if (Array.isArray(data.root)) { if (Array.isArray(data.root)) {
setFieldName(data.root) setFieldName(data.root)
} }
console.log('props', props)
} }
useEffect(() => { useEffect(() => {
......
...@@ -22,10 +22,12 @@ const AccountName = (props) => { ...@@ -22,10 +22,12 @@ const AccountName = (props) => {
} }
const selectChange = (value) => { const selectChange = (value) => {
onChange(value)
if (name === '台账选择器') { if (name === '台账选择器') {
addons.setValues({ ...addons.formData, fieldshine: [] }) addons.setValueByPath('fieldshine', [])
} else if (name === '关联表单') {
addons.setValueByPath('mappedField', [])
} }
onChange(value)
} }
return ( return (
......
import React, { useState } from 'react' import React, { useEffect, useState } from 'react'
import { Form, Space, TreeSelect, Button, Input, Modal, message } from 'antd' import { Form, Space, TreeSelect, Button, Input, Modal, message } from 'antd'
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons' import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import styles from './index.less' import styles from './index.less'
...@@ -22,7 +22,6 @@ const MappedField = (props) => { ...@@ -22,7 +22,6 @@ const MappedField = (props) => {
const req1 = QueryFields(accountName) const req1 = QueryFields(accountName)
const req2 = ReloadTableFields({ tableName: tableNameParent }) const req2 = ReloadTableFields({ tableName: tableNameParent })
const [res1, res2] = await Promise.all([req1, req2]) const [res1, res2] = await Promise.all([req1, req2])
console.log(res1, res2)
if (res1.code === 0) { if (res1.code === 0) {
setToField(res1.data) setToField(res1.data)
} else { } else {
...@@ -33,6 +32,7 @@ const MappedField = (props) => { ...@@ -33,6 +32,7 @@ const MappedField = (props) => {
} else { } else {
message.error(res2.msg) message.error(res2.msg)
} }
form.setFieldsValue({ field: value })
setVisible(true) setVisible(true)
} }
......
import React, { useState, useEffect, useRef, useImperativeHandle, forwardRef, useMemo } from 'react' import React, { useState, useEffect, useRef, useImperativeHandle, forwardRef, useMemo, useLayoutEffect } from 'react'
import styles from './index.less' import styles from './index.less'
import { request } from '@wisdom-utils/utils' import { request } from '@wisdom-utils/utils'
import { Editor, Toolbar } from '@wangeditor/editor-for-react' import { Editor, Toolbar } from '@wangeditor/editor-for-react'
...@@ -41,7 +41,6 @@ const RichText = forwardRef(({ schema, onChange, value }, ref) => { ...@@ -41,7 +41,6 @@ const RichText = forwardRef(({ schema, onChange, value }, ref) => {
} }
}, [editor]) }, [editor])
return ( return (
<div className={styles.richText} disabled={disabled}> <div className={styles.richText} disabled={disabled}>
{ {
......
...@@ -27,14 +27,6 @@ const TextInput = (props) => { ...@@ -27,14 +27,6 @@ const TextInput = (props) => {
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { title, disabled, placeholder, presetValue, addonBefore, addonAfter, maxLength, rules, uniqueVerify, tableName, fieldName } = schema const { title, disabled, placeholder, presetValue, addonBefore, addonAfter, maxLength, rules, uniqueVerify, tableName, fieldName } = schema
useEffect(() => {
if (addons) {
addons.setValue(addons.dataPath, presetValue)
} else {
onChange(presetValue)
}
}, [presetValue])
const style = useMemo(() => { const style = useMemo(() => {
let paths = ['【本人姓名】', '【本人部门】'] let paths = ['【本人姓名】', '【本人部门】']
if (paths.includes(value)) { if (paths.includes(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