Commit 9acbe134 authored by 田翔's avatar 田翔

fix: 增加一键布局功能

parent cfbce225
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.9.4", "version": "2.9.5",
"description": "2.9.4: 时间传参问题,数值校验问题", "description": "2.9.5: 增加一键布局功能",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -46,6 +46,10 @@ const layoutWidgets = [ ...@@ -46,6 +46,10 @@ const layoutWidgets = [
required: true, required: true,
disabled: '{{formData.title === "物联数据"}}', disabled: '{{formData.title === "物联数据"}}',
}, },
// description: {
// title: '分组说明',
// type: 'string',
// },
}, },
}, },
] ]
...@@ -772,7 +776,6 @@ const selectWidgets = [ ...@@ -772,7 +776,6 @@ const selectWidgets = [
title: '', title: '',
name: '选项', name: '选项',
type: 'array', type: 'array',
required: '{{formData.sourceType === "手动输入"}}',
hidden: '{{formData.sourceType !== "手动输入"}}', hidden: '{{formData.sourceType !== "手动输入"}}',
default: [{ value: '选项一' }], default: [{ value: '选项一' }],
widget: 'simpleList', widget: 'simpleList',
...@@ -805,7 +808,6 @@ const selectWidgets = [ ...@@ -805,7 +808,6 @@ const selectWidgets = [
dictionary: { dictionary: {
title: '{{formData.sourceType}}', title: '{{formData.sourceType}}',
name: '{{formData.sourceType}}', name: '{{formData.sourceType}}',
required: '{{formData.sourceType === "数据字典"}}',
hidden: '{{formData.sourceType !== "数据字典"}}', hidden: '{{formData.sourceType !== "数据字典"}}',
type: 'string', type: 'string',
widget: 'Dictionary', widget: 'Dictionary',
...@@ -815,7 +817,6 @@ const selectWidgets = [ ...@@ -815,7 +817,6 @@ const selectWidgets = [
tableName: { tableName: {
title: '表名', title: '表名',
name: '表名', name: '表名',
required: '{{formData.sourceType === "表数据"}}',
hidden: '{{formData.sourceType !== "表数据"}}', hidden: '{{formData.sourceType !== "表数据"}}',
type: 'string', type: 'string',
widget: 'TableName', widget: 'TableName',
...@@ -824,8 +825,6 @@ const selectWidgets = [ ...@@ -824,8 +825,6 @@ const selectWidgets = [
fieldName: { fieldName: {
title: '字段名', title: '字段名',
name: '字段名', name: '字段名',
required: true,
required: '{{formData.sourceType === "表数据"}}',
hidden: '{{formData.sourceType !== "表数据"}}', hidden: '{{formData.sourceType !== "表数据"}}',
type: 'string', type: 'string',
widget: 'FieldName', widget: 'FieldName',
...@@ -833,7 +832,6 @@ const selectWidgets = [ ...@@ -833,7 +832,6 @@ const selectWidgets = [
}, },
isMySite: { isMySite: {
title: '仅显示本人所属的站点', title: '仅显示本人所属的站点',
required: true,
default: false, default: false,
hidden: '{{formData.sourceType !== "站点"}}', hidden: '{{formData.sourceType !== "站点"}}',
type: 'boolean', type: 'boolean',
...@@ -972,7 +970,6 @@ const selectWidgets = [ ...@@ -972,7 +970,6 @@ const selectWidgets = [
title: '', title: '',
name: '选项', name: '选项',
type: 'array', type: 'array',
required: '{{formData.sourceType === "手动输入"}}',
hidden: '{{formData.sourceType !== "手动输入"}}', hidden: '{{formData.sourceType !== "手动输入"}}',
default: [{ value: '选项一' }], default: [{ value: '选项一' }],
widget: 'simpleList', widget: 'simpleList',
...@@ -1003,7 +1000,6 @@ const selectWidgets = [ ...@@ -1003,7 +1000,6 @@ const selectWidgets = [
dictionary: { dictionary: {
title: '{{formData.sourceType}}', title: '{{formData.sourceType}}',
name: '{{formData.sourceType}}', name: '{{formData.sourceType}}',
required: '{{formData.sourceType === "数据字典"}}',
hidden: '{{formData.sourceType !== "数据字典"}}', hidden: '{{formData.sourceType !== "数据字典"}}',
type: 'string', type: 'string',
widget: 'Dictionary', widget: 'Dictionary',
...@@ -1109,7 +1105,6 @@ const selectWidgets = [ ...@@ -1109,7 +1105,6 @@ const selectWidgets = [
title: '', title: '',
name: '选项', name: '选项',
type: 'array', type: 'array',
required: '{{formData.sourceType === "手动输入"}}',
hidden: '{{formData.sourceType !== "手动输入"}}', hidden: '{{formData.sourceType !== "手动输入"}}',
default: [{ value: '选项一' }], default: [{ value: '选项一' }],
widget: 'simpleList', widget: 'simpleList',
...@@ -1139,7 +1134,6 @@ const selectWidgets = [ ...@@ -1139,7 +1134,6 @@ const selectWidgets = [
dictionary: { dictionary: {
title: '{{formData.sourceType}}', title: '{{formData.sourceType}}',
name: '{{formData.sourceType}}', name: '{{formData.sourceType}}',
required: '{{formData.sourceType === "数据字典"}}',
hidden: '{{formData.sourceType !== "数据字典"}}', hidden: '{{formData.sourceType !== "数据字典"}}',
type: 'string', type: 'string',
widget: 'Dictionary', widget: 'Dictionary',
......
...@@ -6,7 +6,7 @@ import { settings, baseSettings, globalSettings } from './config' ...@@ -6,7 +6,7 @@ import { settings, baseSettings, globalSettings } from './config'
import widgets from '../widgets' import widgets from '../widgets'
import { saveTableConfig, GetTableConfigJson, ReloadTableFields } from '../../apis/process' import { saveTableConfig, GetTableConfigJson, ReloadTableFields } from '../../apis/process'
import FormRender from '../FormRender' import FormRender from '../FormRender'
import { isObject } from '../../utils' import { isObject, getVerify, setFieldJson, getNanoid } from '../../utils'
import Drag from '../components/Drag' import Drag from '../components/Drag'
import styles from '../../main.less' import styles from '../../main.less'
...@@ -43,6 +43,7 @@ const FormDesigner = (props, ref) => { ...@@ -43,6 +43,7 @@ const FormDesigner = (props, ref) => {
}, [settings, tableName]) }, [settings, tableName])
const getJSON = (json, fieldName) => { const getJSON = (json, fieldName) => {
let nanoid = getNanoid()
let properties = json?.properties let properties = json?.properties
let parent = {} let parent = {}
let paths = [] let paths = []
...@@ -69,30 +70,30 @@ const FormDesigner = (props, ref) => { ...@@ -69,30 +70,30 @@ const FormDesigner = (props, ref) => {
child[s].tableNameParent = tableName child[s].tableNameParent = tableName
child[s].tableTypeParent = json.tableType child[s].tableTypeParent = json.tableType
child[s].IsSystemField = IsSystemField child[s].IsSystemField = IsSystemField
if (v === '(未分组)') { // if (v === '(未分组)') {
ungroupedChild[s] = child[s] // ungroupedChild[s] = child[s]
} // }
} }
} }
} else { } else {
ungroupedChild[v] = { ungroupedChild[v] = {
...properties[v], ...properties[v],
tableTypeParent: json.tableType,
tableNameParent: tableName tableNameParent: tableName
} }
} }
} }
} }
if (JSON.stringify(ungroupedChild) !== '{}') { if (JSON.stringify(ungroupedChild) !== '{}') {
parent['(未分组)'] = { parent[nanoid] = {
title: title, title: title,
type: "object", type: 'object',
collapsed: false, collapsed: false,
groupBase: {},
properties: { properties: {
...ungroupedChild ...ungroupedChild
} }
} }
paths.push('(未分组)') paths.push(nanoid)
} }
return { return {
...json, ...json,
...@@ -150,11 +151,14 @@ const FormDesigner = (props, ref) => { ...@@ -150,11 +151,14 @@ const FormDesigner = (props, ref) => {
if (errors.length) { if (errors.length) {
return message.error('请按照提示完善表单内容') return message.error('请按照提示完善表单内容')
} }
setVisible(true)
let json = getJSON(designerRef.current.getValue(), fieldName) let json = getJSON(designerRef.current.getValue(), fieldName)
let verify = getVerify(json)
if (verify === true) {
setVisible(true)
setSchema(json) setSchema(json)
designerRef.current.setValue(json) designerRef.current.setValue(json)
} }
}
const submit = async () => { const submit = async () => {
const errors = designerRef.current.getErrorFields() const errors = designerRef.current.getErrorFields()
...@@ -162,10 +166,8 @@ const FormDesigner = (props, ref) => { ...@@ -162,10 +166,8 @@ const FormDesigner = (props, ref) => {
return message.error('请按照提示完善表单内容') return message.error('请按照提示完善表单内容')
} }
let json = getJSON(designerRef.current.getValue(), fieldName) let json = getJSON(designerRef.current.getValue(), fieldName)
// let groups = Object.keys(json.properties) let verify = getVerify(json)
// if (groups.some(v => v.includes('_'))) { if (verify === true) {
// return message.error('分组包含重复字段!')
// }
designerRef.current.setValue(json) designerRef.current.setValue(json)
const { code, data, msg } = await saveTableConfig(json) const { code, data, msg } = await saveTableConfig(json)
if (code === 0) { if (code === 0) {
...@@ -174,6 +176,31 @@ const FormDesigner = (props, ref) => { ...@@ -174,6 +176,31 @@ const FormDesigner = (props, ref) => {
message.error(msg) message.error(msg)
} }
} }
}
const initLayout = () => {
const errors = designerRef.current.getErrorFields()
if (errors.length) {
return message.error('请按照提示完善表单内容')
}
let json = getJSON(designerRef.current.getValue(), fieldName)
let verify = getVerify(json)
if (verify === true) {
Modal.confirm({
title: '是否确定使用剩余附加字段一键生成表单?',
icon: <ExclamationCircleOutlined />,
centered: true,
cancelText: '取消',
okText: '确定',
onCancel: () => {
console.log('取消一键生成')
},
onOk: () => {
designerRef.current.setValue(setFieldJson(json, fieldName))
}
})
}
}
const extraButtons = useMemo(() => { const extraButtons = useMemo(() => {
if (extra) { if (extra) {
...@@ -186,6 +213,10 @@ const FormDesigner = (props, ref) => { ...@@ -186,6 +213,10 @@ const FormDesigner = (props, ref) => {
text: '清空', text: '清空',
onClick: clear onClick: clear
}, },
{
text: '一键布局',
onClick: initLayout,
},
{ {
text: '预览', text: '预览',
onClick: preview onClick: preview
...@@ -193,8 +224,8 @@ const FormDesigner = (props, ref) => { ...@@ -193,8 +224,8 @@ const FormDesigner = (props, ref) => {
{ {
text: '提交', text: '提交',
type: 'primary', type: 'primary',
onClick: submit onClick: submit,
} },
] ]
} }
return [false, false, false, false] return [false, false, false, false]
......
...@@ -21,9 +21,9 @@ const CheckBox = (props) => { ...@@ -21,9 +21,9 @@ const CheckBox = (props) => {
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, presetValue) addons.setValue(addons.dataPath, presetValue || '')
} else { } else {
onChange(presetValue) onChange(presetValue || '')
} }
}, [presetValue]) }, [presetValue])
......
...@@ -15,9 +15,9 @@ const ComboBox = (props) => { ...@@ -15,9 +15,9 @@ const ComboBox = (props) => {
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, presetValue) addons.setValue(addons.dataPath, presetValue || '')
} else { } else {
onChange(presetValue) onChange(presetValue || '')
} }
}, [presetValue]) }, [presetValue])
...@@ -58,11 +58,11 @@ const ComboBox = (props) => { ...@@ -58,11 +58,11 @@ const ComboBox = (props) => {
return children return children
}, [sourceType, enums, isStoreID]) }, [sourceType, enums, isStoreID])
const handleChange = value => { const handleChange = (value) => {
if (isMultiple || isEdit) { if (isMultiple || isEdit) {
onChange(value.join(',')) onChange(value.join(',') || '')
} else { } else {
onChange(value) onChange(value || '')
} }
} }
......
...@@ -10,7 +10,7 @@ const RadioButton = (props) => { ...@@ -10,7 +10,7 @@ const RadioButton = (props) => {
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, presetValue) addons.setValue(addons.dataPath, presetValue || '')
} }
}, [presetValue]) }, [presetValue])
......
import React, { useState } from 'react'; import React, { useState } from 'react';
import { message } from 'antd';
export function downloadFunc(url, name, target = '_self') { export function downloadFunc(url, name, target = '_self') {
const a = document.createElement('a'); const a = document.createElement('a');
...@@ -124,3 +125,99 @@ export const debounce = (fn) => { ...@@ -124,3 +125,99 @@ export const debounce = (fn) => {
}, 500) }, 500)
} }
} }
//生成随机ID
export function getNanoid(len = 6) {
var orgStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let returnStr = "";
for (var i = 0; i < len; i++) {
returnStr += orgStr.charAt(Math.floor((Math.random() * orgStr.length)));
}
return `分组名称_${returnStr}`
}
//手动校验配置信息
export const getVerify = (json) => {
if (isObject(json)) {
let properties = json?.properties
if (isObject(properties)) {
for (let v in properties) {
// if (properties[v].title === '(未分组)') {
// return message.error(`包含未分组字段,请将分组命名`)
// }
let child = properties[v]?.properties
if (isObject(child)) {
for (let s in child) {
const { widget, sourceType, options } = child[s]
if (['ComboBox', 'RadioButton', 'CheckBox'].includes(widget)) {
if (sourceType === '手动输入' && !options.length) {
return message.error(`字段【${s}】配置,选项值必填!`)
}
if (sourceType === '数据字典' && !dictionary) {
return message.error(`字段【${s}】配置,数据字典必填!`)
}
if (sourceType === '表数据' && !tableName && !fieldName) {
return message.error(`字段【${s}】配置,表名与字段名!`)
}
}
}
}
}
}
}
return true
}
const getInputSetting = ({ title, tableName, tableType }) => {
return {
"title": title,
"type": "string",
"widget": "TextInput",
"placeholder": "请输入内容",
"tableNameParent": tableName,
tableTypeParent: tableType,
"maxLength": 200,
"rules": [],
"uniqueVerify": null,
"required": false,
"disabled": false,
"isStoreID": false,
"isQRCode": false,
"groupStyle": {},
"labelWidth": 110
}
}
//将字段设置
export const setFieldJson = (json, fieldName) => {
let properties = json?.properties
let keys = []
let parent = {}
let extaObj = {}
Object.keys(properties).forEach(v => {
parent[v] = properties[v]
let child = properties[v]?.properties
if (isObject(child)) {
Object.keys(child).forEach(s => {
keys.push(s)
})
}
})
fieldName.forEach(j => {
if (!keys.includes(j.name)) {
extaObj[j.name] = getInputSetting({ ...json, title: j.name })
}
})
if (JSON.stringify(extaObj) !== '{}') {
parent[getNanoid()] = {
title: '(未分组)',
type: "object",
collapsed: false,
properties: extaObj
}
}
return {
...json,
properties: parent,
}
}
\ No newline at end of file
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