Commit 8c996669 authored by 田翔's avatar 田翔

增加自动计算形态

parent 45c42e52
{
"name": "panda-xform",
"version": "1.10.0",
"description": "1.10.0: 附件,富文本,多行文本,关联表单宽度配置放出",
"version": "2.0.0",
"description": "2.0.0: 增加自动计算形态",
"keywords": [
"panda-xform"
],
......
......@@ -38,6 +38,23 @@ export function getStationListByUserID(id, isAll) {
});
}
//自动计算字符串转化
export function getFormFieldAnalysisDtos(formula) {
return request({
url: `/PandaWorkFlow/WorkFlow/BPM/CaseManage/GetFormFieldAnalysisDtos?formula=${formula}`,
method: 'get',
})
}
//表单字段自动计算
export function formAutomaticComputation(data) {
return request({
url: `/PandaWorkFlow/WorkFlow/BPM/CaseManage/FormAutomaticComputation`,
method: 'post',
data
})
}
//人员选择器获取(三种形态)
export function getUserSelector(role, userID) {
return request({
......@@ -269,7 +286,7 @@ export function GetTableConfigJson(paramas) {
//获取台账的json
export function GetTableJson(accountName) {
return request({
url: `/PandaWorkFlow/WorkFlow/AccountManage/GetTableJson?accountName=${accountName}`,
url: `/PandaOMS/OMS/CaseManage/GetAccountTableJson?accountName=${accountName}`,
method: 'get',
})
}
......
......@@ -441,6 +441,7 @@ const textWidgets = [
title: '数值',
type: 'number',
widget: 'NumberInput',
presetValue: 0,
},
setting: {
groupBase: {
......@@ -2956,6 +2957,18 @@ const advancedWidgets = [
displayType: 'row',
labelWidth: 55,
},
gorupSoruce: {
title: '数据来源',
type: 'object',
properties: {},
},
calculateRule: {
title: '计算规则',
type: 'string',
widget: 'CalculateRule',
displayType: 'row',
labelWidth: 80,
},
groupStyle: {
title: '控件样式',
type: 'object',
......
......@@ -3,6 +3,7 @@ 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)
......@@ -21,16 +22,9 @@ const XRender = (props, ref) => {
const form = useForm()
const watch = useMemo(() => {
console.log('schema', schema)
return {}
return getWatch(schema, form)
}, [schema])
// const watch = {
// '#': (value) => {
// console.log('value', value)
// }
// }
const getValues = async () => {
let { data, errors } = await form.submit()
let formValue = []
......
import { message } from 'antd'
import { isObject } from '../../utils'
import { formAutomaticComputation } from '../../apis/process'
export const debounce = (fn) => {
let t = null
return function (e) {
const context = this
const args = arguments
if (t) {
clearTimeout(t)
}
t = setTimeout(function () {
fn.call(context, ...args)
}, 500)
}
}
//json值结构转化为数组值
export const jsonToValues = (data, paths) => {
let formValue = []
Object.keys(data).map((k) => {
if (isObject(data[k])) {
Object.keys(data[k]).map((key) => {
formValue.push({ fieldName: key, fieldValue: data[k][key] + '' })
})
}
})
let values = []
if (Array.isArray(paths)) {
paths.forEach(v => {
let fieldName = v.split('.')[1]
let fieldValue = '0'
let item = formValue.find(s => s.fieldName === fieldName)
if (item) {
fieldValue = item.fieldValue
}
values.push({
fieldName,
fieldValue,
})
})
}
console.log('paths', paths)
return {
formValue: values,
relationForm: data.relationForm
}
}
const getRules = (json) => {
let parent = json?.properties
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
if (isObject(child)) {
for (let s in child) {
if (child[s].widget === 'AutoCalculate') {
return {
filedName: s,
...child[s],
targetPath: `${v}.${s}`,
}
}
}
}
}
}
return {}
}
const getPath = (json, filed) => {
let parent = json?.properties
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
if (isObject(child)) {
for (let s in child) {
if (s === filed) {
return `${v}.${s}`
}
}
}
}
}
return ''
}
const automaticComputation = async (params) => {
let param = {
tableName: params.tableName,
filedFormulas: params.filedFormulas,
values: jsonToValues(params.form.getValues(), params.paths).formValue
}
const { code, data, msg } = await formAutomaticComputation(param)
if (code === 0) {
if (Array.isArray(data)) {
data.forEach(v => {
let path = getPath(params.schema, v.fieldName)
if (path) {
params.form.setValueByPath(path, v.fieldValue)
}
})
}
} else {
message.error(msg)
}
}
const setValue = debounce(automaticComputation)
export const getWatch = (schema, form) => {
let watch = {}
let { rules, calculateRule, filedName } = getRules(schema)
let paths = []
if (Array.isArray(rules)) {
let item = rules.find(v => v.tableName === schema.tableName)
if (item) {
if (Array.isArray(item.fields)) {
item.fields.forEach(v => {
let path = getPath(schema, v)
if (path) {
paths.push(path)
}
})
}
}
}
if (Array.isArray(paths)) {
paths.forEach(v => {
watch[v] = () => {
let params = {
tableName: schema.tableName,
filedFormulas: [{ fieldName: filedName, formula: calculateRule }],
form: form,
paths: paths,
schema: schema
}
setValue(params)
}
})
}
return watch
}
export default getWatch
\ No newline at end of file
......@@ -8,6 +8,7 @@ const AutoCalculate = (props) => {
return (
<InputNumber
value={value}
style={{ width: '100%' }}
disabled={disabled}
>
......
......@@ -168,16 +168,19 @@ const AccountSelector = (props) => {
getContainer={false}
bodyStyle={{ height: 570, overflowY: 'auto' }}
>
<Input.Search
value={params.info}
placeholder="请输入检索内容"
allowClear
onChange={(e) => setParams({ ...params, info: e.target.value })}
onSearch={onSearch}
enterButton
size={'middle'}
style={{ width: '400px', marginBottom: '10px' }}
/>
<div style={{ display: 'flex' }}>
<div style={{ lineHeight: '31px', paddingRight: '10px' }}>快捷搜索:</div>
<Input.Search
value={params.info}
placeholder="请输入检索内容"
allowClear
onChange={(e) => setParams({ ...params, info: e.target.value })}
onSearch={onSearch}
enterButton
size={'middle'}
style={{ width: '400px', marginBottom: '10px' }}
/>
</div>
<Table
rowKey={r => r.ID}
loading={loading}
......
import React, { useState } from 'react'
import { Input, Modal, message } from 'antd'
import { getFormFieldAnalysisDtos } from '../../../../../apis/process'
const { TextArea } = Input
const CalculateRule = (props) => {
const { value, onChange, addons } = props
const [visible, setVisible] = useState(false)
const [text, setText] = useState()
const inputClick = () => {
setVisible(true)
setText(value)
}
const onOk = async () => {
const { code, data, msg } = await getFormFieldAnalysisDtos(text)
if (code === 0) {
addons.setValue('rules', data)
setVisible(false)
onChange(text)
} else {
message.error(msg)
}
}
const onCancel = () => {
setVisible(false)
}
return (
<div>
<Input value={value} onClick={inputClick} />
<Modal
title='计算规则'
visible={visible}
onOk={onOk}
onCancel={onCancel}
>
<TextArea
value={text}
onChange={e => setText(e.target.value)}
/>
</Modal>
</div>
)
}
export default CalculateRule
\ No newline at end of file
......@@ -6,6 +6,7 @@ import ControlShow from './ControlShow'
import SoruceType from './SoruceType'
import TableName from './TableName'
import FieldName from './FieldName'
import CalculateRule from './CalculateRule'
const groupSource = {
Dictionary,
......@@ -16,6 +17,7 @@ const groupSource = {
SoruceType,
TableName,
FieldName,
CalculateRule,
}
export default groupSource
\ No newline at end of file
......@@ -97,3 +97,19 @@ export const isJson = (json) => {
}
export const isObject = (obj) => typeof obj === 'object'
//防抖
export const debounce = (fn) => {
let t = null
return function (e) {
const context = this
const args = arguments
if (t) {
clearTimeout(t)
}
t = setTimeout(function () {
fn.call(context, args)
}, 500)
}
}
\ 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