Commit ffa08e5a authored by 田翔's avatar 田翔

支持只读字段与全局只读

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