Commit ffa08e5a authored by 田翔's avatar 田翔

支持只读字段与全局只读

parent c9ff2ccc
{
"name": "panda-xform",
"version": "2.1.5",
"description": "2.1.5: 样式i修改",
"version": "2.1.6",
"description": "2.1.6: 支持只读字段与全局只读",
"keywords": [
"panda-xform"
],
......
/**
* 表单组件
* @author tianxiang
* @params schemaValues:表单结构与数据,disabledFields:需要只读的字段, disabled:所有字段只读
* 2023年2月23日 增加参数
*/
import React, { useMemo, useContext, forwardRef, useImperativeHandle, createContext, useState } from 'react'
import FormRender, { useForm } from 'form-render'
import { ConfigProvider } from 'antd'
......@@ -15,7 +21,7 @@ const XRender = (props, ref) => {
}
))
const { schemaValues } = props
const { schemaValues, disabledFields, disabled } = props
const { schema, values } = schemaValues
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext)
const prefixCls = getPrefixCls('pandaXform')
......@@ -25,33 +31,39 @@ const XRender = (props, ref) => {
const schemaForm = useMemo(() => {
let schemaForm = schema ? (isObject(schema) ? schema : JSON.parse(schema)) : {}
if (Array.isArray(values)) {
let parent = schemaForm?.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) {
let value = ''
let parent = schemaForm?.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) {
let value = ''
if (Array.isArray(values)) {
values.forEach(v => {
if (v.fieldName === s) {
value = v.fieldValue
}
})
childObj[s] = { ...child[s], presetValue: value || child[s].presetValue }
}
let disabledField = child[s].disabled
if (Array.isArray(disabledFields) && disabledFields.includes(s)) {
disabledField = true
}
if (disabled) {
disabledField = true
}
childObj[s] = { ...child[s], presetValue: value || child[s].presetValue, disabled: disabledField }
}
if (JSON.stringify(childObj) !== '{}') {
parentObj[v] = { ...parent[v], properties: childObj }
}
}
if (JSON.stringify(childObj) !== '{}') {
parentObj[v] = { ...parent[v], properties: childObj }
}
}
return { ...schemaForm, properties: parentObj }
}
return schemaForm
}, [schema, values])
return { ...schemaForm, properties: parentObj }
}, [schema, values, disabledFields, disabled])
const watch = useMemo(() => {
return getWatch(schema, form, startTime)
......
......@@ -44,6 +44,8 @@ const RadioButton = (props) => {
}
}, [sourceType, options, dictionaryList])
console.log('props', props, enums)
return (
<Radio.Group onChange={radioChange} value={value} disabled={disabled}>
{enums.map(v => <Radio key={v} value={v}>{v}</Radio>)}
......
......@@ -17,7 +17,7 @@ const options = [
{
name: 'mobile',
label: '手机号(mobile)',
value: '/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/',
value: '1[3-9]\\d{9}',
message: '手机号校验未通过',
},
{
......
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