Commit 336f68ee authored by 田翔's avatar 田翔

fix: 代码优化

parent 03867190
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "5.4.8", "version": "5.4.9",
"description": "5.4.8 配置修改", "description": "5.4.9 配置修改",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -75,8 +75,9 @@ const XRender = (props, ref) => { ...@@ -75,8 +75,9 @@ const XRender = (props, ref) => {
} }
childObj[s] = { childObj[s] = {
...child[s], ...child[s],
presetValue: value || child[s].presetValue, presetValue: value || child[s].presetValue || '',
textDefalut: child[s].presetValue, textDefalut: child[s].presetValue,
formDisabled: disabled,
disabled: disabledField, disabled: disabledField,
required, required,
} }
......
...@@ -204,7 +204,7 @@ const getFieldValue = (formValue, fieldName) => { ...@@ -204,7 +204,7 @@ const getFieldValue = (formValue, fieldName) => {
} }
//自动计算监听/隐藏条件监听 //自动计算监听/隐藏条件监听
const getAutoWatch = ({ schema, form, startTime, initField }) => { export const getWatch = ({ schema, form, startTime, initField }) => {
let watch = {} let watch = {}
let paths = [] let paths = []
let formValue = form?.getValues() let formValue = form?.getValues()
...@@ -212,6 +212,7 @@ const getAutoWatch = ({ schema, form, startTime, initField }) => { ...@@ -212,6 +212,7 @@ const getAutoWatch = ({ schema, form, startTime, initField }) => {
const configs = relationForm?.configs || [] const configs = relationForm?.configs || []
const AutoCalculate = getWidgetInfo(schema, 'NumberInput') const AutoCalculate = getWidgetInfo(schema, 'NumberInput')
const HiddenWidget = getHiddenWidget(schema) const HiddenWidget = getHiddenWidget(schema)
const RelevanceSelect = getWidgetInfo(schema, 'RelevanceSelect')
if (Array.isArray(AutoCalculate)) { if (Array.isArray(AutoCalculate)) {
AutoCalculate.forEach(item => { AutoCalculate.forEach(item => {
const { gorupName, fieldName, rules, calculateRule } = item const { gorupName, fieldName, rules, calculateRule } = item
...@@ -260,6 +261,26 @@ const getAutoWatch = ({ schema, form, startTime, initField }) => { ...@@ -260,6 +261,26 @@ const getAutoWatch = ({ schema, form, startTime, initField }) => {
} }
}) })
} }
if (Array.isArray(RelevanceSelect)) {
RelevanceSelect.forEach(v => {
let path = getPath(schema, v.fieldParent)
if (path) {
watch[path] = (value) => {
if (value) {
let params = {
startTime,
sourcePath: path,
targetPath: v.targetPath,
form: form,
dictionary: v.dictionary,
value
}
debounce(getSelectItemList)(params)
}
}
}
})
}
if (Array.isArray(paths)) { if (Array.isArray(paths)) {
paths.forEach(v => { paths.forEach(v => {
watch[v.path] = () => { watch[v.path] = () => {
...@@ -301,37 +322,3 @@ const getSelectItemList = async (params) => { ...@@ -301,37 +322,3 @@ const getSelectItemList = async (params) => {
} }
} }
} }
//关联选择监听
const getSelectWatch = ({ schema, form, startTime, initField }) => {
let watch = {}
const RelevanceSelect = getWidgetInfo(schema, 'RelevanceSelect')
if (Array.isArray(RelevanceSelect)) {
RelevanceSelect.forEach(v => {
let path = getPath(schema, v.fieldParent)
if (path) {
watch[path] = (value) => {
if (value) {
let params = {
startTime,
sourcePath: path,
targetPath: v.targetPath,
form: form,
dictionary: v.dictionary,
value
}
debounce(getSelectItemList)(params)
}
}
}
})
}
return watch
}
export const getWatch = ({ schema, form, startTime, initField }) => {
return {
...getAutoWatch({ schema, form, startTime, initField }),
...getSelectWatch({ schema, form, startTime, initField })
}
}
\ No newline at end of file
...@@ -73,8 +73,9 @@ const BaseForm = (props, ref) => { ...@@ -73,8 +73,9 @@ const BaseForm = (props, ref) => {
} }
childObj[s] = { childObj[s] = {
...child[s], ...child[s],
presetValue: disabledField ? (value || '') : (value || child[s].presetValue), presetValue: value || child[s].presetValue,
textDefalut: child[s].presetValue, textDefalut: child[s].presetValue,
formDisabled: disabled,
disabled: disabledField, disabled: disabledField,
required, required,
} }
......
...@@ -177,7 +177,7 @@ const RelationForm = (props) => { ...@@ -177,7 +177,7 @@ const RelationForm = (props) => {
addons.setValueByPath('relationForm', addons.setValueByPath('relationForm',
{ {
...relationForm, ...relationForm,
configs: [...relationForm.configs, { ...schema, queryWheres: queryWheres.map(v => ({ fieldName: v.field, fieldValue: v.value })) }] configs: [...relationForm.configs, { ...schema, id: schema.$id, queryWheres: queryWheres.map(v => ({ fieldName: v.field, fieldValue: v.value })) }]
}) })
return queryWheres return queryWheres
} }
...@@ -429,49 +429,10 @@ const RelationForm = (props) => { ...@@ -429,49 +429,10 @@ const RelationForm = (props) => {
getDataSourceOther({ pageIndex, pageSize }) getDataSourceOther({ pageIndex, pageSize })
} }
useEffect(() => {
try {
setTimeout(() => {
if (addons) {
let dataPath = addons?.dataPath?.split('.')[0]
let group = addons?.formData?.[dataPath]
let paths = Object.keys(group)
let hidden = true
paths.forEach(v => {
let info = addons?.getSchemaByPath(`${dataPath}.${v}`)
if (!info.hidden && addons?.dataPath !== `${dataPath}.${v}`) {
hidden = false
}
})
if (show) {
hidden = false
}
addons?.setSchemaByPath(dataPath, { hidden: hidden })
}
}, 500)
} catch (e) {
console.log('error', error)
}
}, [show])
useEffect(() => { useEffect(() => {
//初始化关联表单配置信息,初始显示隐藏 //初始化关联表单配置信息,初始显示隐藏
if (addons) { if (addons) {
getData() getData()
// console.log('addons', addons)
// setTimeout(() => {
// let queryWheres = []
// if (Array.isArray(mappedField)) {
// let formDataObj = getFormDataObj(addons?.formData)
// mappedField.forEach(v => {
// queryWheres.push({ field: v.toField, type: '等于', value: codes[v.fromField] || formDataObj[v.fromField] })
// })
// }
// let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
// addons.setValueByPath('relationForm', { ...relationForm, configs: [...relationForm.configs, { ...schema, queryWheres }] })
// }, 0)
} }
}, []) }, [])
......
...@@ -33,7 +33,22 @@ const TextInput = (props) => { ...@@ -33,7 +33,22 @@ const TextInput = (props) => {
const userInfo = preview === 'preview' ? initUserInfo : window?.globalConfig?.userInfo || initUserInfo const userInfo = preview === 'preview' ? initUserInfo : window?.globalConfig?.userInfo || initUserInfo
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const [showValue, setShowValue] = useState(value) const [showValue, setShowValue] = useState(value)
const { title, disabled, placeholder, presetValue, addonBefore, addonAfter, maxLength, rules, uniqueVerify, tableName, fieldName, isStoreID, textDefalut } = schema const {
title,
disabled,
placeholder,
presetValue,
addonBefore,
addonAfter,
maxLength,
rules,
uniqueVerify,
tableName,
fieldName,
isStoreID,
textDefalut,
formDisabled,
} = schema
const handleChange = (e) => { const handleChange = (e) => {
if (addons) { if (addons) {
...@@ -61,30 +76,39 @@ const TextInput = (props) => { ...@@ -61,30 +76,39 @@ const TextInput = (props) => {
} }
} }
const getValueNext = () => {
if (textDefalut === '【本人姓名】') {
if (isStoreID) {
return userInfo.OID + ''
} else {
return userInfo.fullName
}
} else if (textDefalut === '【本人部门】') {
if (isStoreID) {
return userInfo.depart.OID + ''
} else {
return userInfo.depart.name
}
} else if (textDefalut === '【本人电话】') {
return userInfo.Phone
}
return ''
}
useEffect(() => { useEffect(() => {
let valueNext = presetValue let valueNext = presetValue
if (preview !== 'preview') { if (preview !== 'preview') {
if (loaclPaths.includes(presetValue)) { if (loaclPaths.includes(presetValue)) {
if (disabled) { if (formDisabled) {
valueNext = '' valueNext = ''
} else { } else {
if (textDefalut === '【本人姓名】') { valueNext = getValueNext()
if (isStoreID) {
valueNext = userInfo.OID + ''
} else {
valueNext = userInfo.fullName
}
} else if (textDefalut === '【本人部门】') {
if (isStoreID) {
valueNext = userInfo.depart.OID + ''
} else {
valueNext = userInfo.depart.name
}
} else if (textDefalut === '【本人电话】') {
valueNext = userInfo.Phone
}
} }
} }
//编辑状态下需要被覆盖
if (!disabled) {
valueNext = getValueNext()
}
} }
if (addons) { if (addons) {
addons.setValue(addons.dataPath, valueNext || '') addons.setValue(addons.dataPath, valueNext || '')
......
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