Commit 57002716 authored by 田翔's avatar 田翔

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

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