Commit 57002716 authored by 田翔's avatar 田翔

增加关联选择自动选上第一个监听逻辑

parent 50ea5ee5
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.4.6", "version": "2.4.7",
"description": "2.4.6: 增加显示控件类型,多行文本提示语优化,点击关联表单报错修复", "description": "2.4.7: 增加关联选择自动选上第一个监听逻辑",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -2949,6 +2949,13 @@ const advancedWidgets = [ ...@@ -2949,6 +2949,13 @@ const advancedWidgets = [
type: 'object', type: 'object',
properties: {} properties: {}
}, },
widget: {
title: '控件类型',
type: 'string',
widget: 'WidgetType',
displayType: 'row',
labelWidth: 80,
},
$id: { $id: {
title: '字段名称', title: '字段名称',
type: 'string', type: 'string',
...@@ -3071,6 +3078,13 @@ const advancedWidgets = [ ...@@ -3071,6 +3078,13 @@ const advancedWidgets = [
type: 'object', type: 'object',
properties: {} properties: {}
}, },
widget: {
title: '控件类型',
type: 'string',
widget: 'WidgetType',
displayType: 'row',
labelWidth: 80,
},
$id: { $id: {
title: '字段名称', title: '字段名称',
type: 'string', type: 'string',
......
...@@ -9,16 +9,14 @@ import FormRender, { useForm } from 'form-render' ...@@ -9,16 +9,14 @@ import FormRender, { useForm } from 'form-render'
import { ConfigProvider } from 'antd' import { ConfigProvider } from 'antd'
import widgets from '../widgets' import widgets from '../widgets'
import { isObject } from '../../utils' import { isObject } from '../../utils'
import getWatch from './watch' import { getWatch } from './watch'
export const GlobalStore = createContext(null)
const XRender = (props, ref) => { const XRender = (props, ref) => {
useImperativeHandle(ref, () => ( useImperativeHandle(ref, () => (
{ {
getValues, getValues,
form form,
} }
)) ))
......
import { message } from 'antd' import { message } from 'antd'
import { isObject } from '../../utils' import { isObject } from '../../utils'
import { formAutomaticComputation } from '../../apis/process' import { formAutomaticComputation, GetSelectItemList } from '../../apis/process'
export const debounce = (fn) => { export const debounce = (fn) => {
let t = null let t = null
...@@ -47,7 +47,7 @@ export const jsonToValues = (data, paths) => { ...@@ -47,7 +47,7 @@ export const jsonToValues = (data, paths) => {
} }
} }
const getRules = (json) => { const getWidgetInfo = (json, widget) => {
let AutoCalculate = [] let AutoCalculate = []
let parent = json?.properties let parent = json?.properties
if (isObject(parent)) { if (isObject(parent)) {
...@@ -55,7 +55,7 @@ const getRules = (json) => { ...@@ -55,7 +55,7 @@ const getRules = (json) => {
let child = parent[v]?.properties let child = parent[v]?.properties
if (isObject(child)) { if (isObject(child)) {
for (let s in child) { for (let s in child) {
if (child[s].widget === 'AutoCalculate') { if (child[s].widget === widget) {
AutoCalculate.push({ AutoCalculate.push({
fieldName: s, fieldName: s,
...child[s], ...child[s],
...@@ -119,14 +119,13 @@ const automaticComputation = async (params) => { ...@@ -119,14 +119,13 @@ const automaticComputation = async (params) => {
} }
} }
const setValue = debounce(automaticComputation) //自动计算监听
const getAutoWatch = (schema, form, startTime) => {
export const getWatch = (schema, form, startTime) => {
let watch = {} let watch = {}
let paths = [] let paths = []
let { relationForm } = form?.getValues() let { relationForm } = form?.getValues()
const configs = relationForm?.configs || [] const configs = relationForm?.configs || []
const AutoCalculate = getRules(schema) const AutoCalculate = getWidgetInfo(schema, 'AutoCalculate')
if (Array.isArray(AutoCalculate)) { if (Array.isArray(AutoCalculate)) {
AutoCalculate.forEach(item => { AutoCalculate.forEach(item => {
const { fieldName, rules, calculateRule } = item const { fieldName, rules, calculateRule } = item
...@@ -163,11 +162,57 @@ export const getWatch = (schema, form, startTime) => { ...@@ -163,11 +162,57 @@ export const getWatch = (schema, form, startTime) => {
schema: schema, schema: schema,
startTime startTime
} }
setValue(params) debounce(automaticComputation)(params)
}
})
}
return watch
}
const getSelectItemList = async (params) => {
if ((new Date().getTime() - params.startTime) < 1000) return
const { sourcePath, form, targetPath, dictionary, value } = params
const { code, data, msg } = await GetSelectItemList({ nodeName: dictionary })
if (code === 0) {
let array = data.filter(v => v.nodeName === value)
console.log(data, array)
if (Array.isArray(array) && array.length) {
form.setValueByPath(targetPath, array[0].nodeValue)
}
}
}
//关联选择监听
const getSelectWatch = (schema, form, startTime) => {
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 return watch
} }
export default getWatch export const getWatch = (schema, form, startTime) => {
\ No newline at end of file return {
...getAutoWatch(schema, form, startTime),
...getSelectWatch(schema, form, startTime)
}
}
\ No newline at end of file
...@@ -47,6 +47,7 @@ const RelevanceSelect = (props) => { ...@@ -47,6 +47,7 @@ const RelevanceSelect = (props) => {
return ( return (
<Select <Select
value={value}
onFocus={onfocus} onFocus={onfocus}
style={{ width: '100%' }} style={{ width: '100%' }}
onChange={selectChange} onChange={selectChange}
......
...@@ -21,6 +21,8 @@ const data = { ...@@ -21,6 +21,8 @@ const data = {
'Coordinate': '坐标控件', 'Coordinate': '坐标控件',
'Device': '设备选择', 'Device': '设备选择',
'SearchLocation': '位置坐标', 'SearchLocation': '位置坐标',
'RelationForm': '关联表单',
'AutoCalculate': '自动计算',
} }
const WidgetType = (props) => { const WidgetType = (props) => {
......
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