Commit ecfe39da authored by 彭俊龙's avatar 彭俊龙

关联表单编辑数据联动

parent 26671d8e
......@@ -171,7 +171,7 @@ const TablePack = (props, ref) => {
//关联表单表头
const getRelevanceColumnProps = ({ json, field, isEdit, autoArray, accountFieids }) => {
const { fieldName, columnWidth, isSort, accurateSearch, alignment } = field
const { widget } = json?.[fieldName] || {}
const { widget, disabled } = json?.[fieldName] || {}
let searchProps = {}
if (accurateSearch) {
searchProps = {
......@@ -254,14 +254,19 @@ const TablePack = (props, ref) => {
},
}),
render: (value, record) => {
let jsonData = json[fieldName]
if(jsonData.hasOwnProperty('fieldName')){
jsonData['_fieldName'] = jsonData['fieldName']
}
let props = {
...json[fieldName],
...jsonData,
fieldName,
value,
autoArray,
disabled: !accountFieids?.some(v => v.fieldName === fieldName && v.isEdit),
disabled: disabled || false, // || !accountFieids?.some(v => v.fieldName === fieldName && v.isEdit), 从台账设置中获取只读属性
record: { ...record },
}
if (isEdit && !notUse?.includes('edit')) {
return (
<ValueEdit
......
......@@ -41,8 +41,8 @@ const Drag = (props) => {
getContainer={false}
cancelText='取消'
okText='确定'
{...props}
style={style}
{...props}
title={
<div style={{ width: '100%', cursor: 'move' }} onMouseDown={onMouseDown}>
{props.title}
......
......@@ -40,6 +40,8 @@ const RelationForm = (props) => {
sql,
fieldList,
} = schema
const initParams = {
user: userID,
accountName: otherSource?.accountName,
......@@ -73,6 +75,8 @@ const RelationForm = (props) => {
return formDataObj
}, [addons?.formData])
const localForm = useMemo(() => {
const { addFieldGroup } = config
let array = []
......@@ -443,6 +447,46 @@ const RelationForm = (props) => {
}
}, [])
useEffect(() => {
if (otherSource?.sql && addons) {
const sql = dealSql(otherSource.sql)
setParamsOther({ ...paramsOther, condition: window.btoa(encodeURIComponent(sql)) })
console.log(paramsOther, sql, 'paramsOther');
}
}, [otherSource])
const dealSql = (sql) => {
let _sql = sql;
if(!addons){
return _sql;
}
// 使用正则表达式匹配括号内的内容
const regex = /{([^}]+)}/g;
const matches = [];
let match;
while ((match = regex.exec(_sql)) !== null) {
matches.push({
text: `{${match[1]}}`,
value: match[1]
});
}
if(matches.length > 0) {
const formData = addons?.formData;
Object.keys(formData).forEach((k) => {
if (isObject(formData[k])) {
Object.keys(formData[k]).forEach((key) => {
const d = matches.find((m) => m.value === key);
if(d){
_sql = _sql.replace(d.text, `'${formData[k][key]}'` || `''`);
}
});
}
})
}
return _sql;
}
return (
<div className={styles.relationForm}>
<div>
......
......@@ -76,6 +76,39 @@ const AccountSelector = (props) => {
}
}
const dealSql = (sql) => {
let _sql = sql;
if(!addons){
return _sql;
}
// 使用正则表达式匹配括号内的内容
const regex = /{([^}]+)}/g;
const matches = [];
let match;
while ((match = regex.exec(_sql)) !== null) {
matches.push({
text: `{${match[1]}}`,
value: match[1]
});
}
if(matches.length > 0) {
const formData = addons?.formData;
Object.keys(formData).forEach((k) => {
if (isObject(formData[k])) {
Object.keys(formData[k]).forEach((key) => {
const d = matches.find((m) => m.value === key);
if(d){
_sql = _sql.replace(d.text, `'${formData[k][key]}'` || `''`);
}
});
}
})
}
return _sql;
}
const getConfig = async () => {
const { code, data } = await GetAccountConfigInfo(accountName);
if (code == 0) {
......@@ -100,7 +133,7 @@ const AccountSelector = (props) => {
user: userID,
accountName: accountName,
...outParams,
condition: sql ? window.btoa(encodeURIComponent(sql)) : (outParams.condition || params.condition || ''),
condition: sql ? window.btoa(encodeURIComponent(dealSql(sql))) : (outParams.condition || params.condition || ''),
};
const { data, code, msg } = await GetAccountPageList(param);
if (code === 0) {
......
......@@ -4,19 +4,19 @@ import styles from './index.less'
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'
import Drag from '../../../../components/Drag'
import { LoadLedgers, QueryFields, ReloadTableFields } from '../../../../../apis/process'
import SqlFilter from '../SqlFilter'
const { TreeNode } = TreeSelect
const OtherSource = (props) => {
const { addons, onChange, value } = props
const { '台账名称': accountName } = addons?.formData || {}
const { '台账名称': accountName, tableNameParent } = addons?.formData || {}
const [visible, setVisible] = useState(false)
const [options, setOptions] = useState([])
const [fromField, setFromField] = useState([])
const [toField, setToField] = useState([])
const [form] = Form.useForm()
console.log(addons.formData, 'addons.formData');
const toFieldFocus = async () => {
const { code, data } = await QueryFields(accountName)
if (code === 0) {
......@@ -93,11 +93,12 @@ const OtherSource = (props) => {
label={'SQL过滤'}
name={'sql'}
>
<Input.TextArea
{/* <Input.TextArea
style={{ width: '100%' }}
rows={3}
placeholder='示例:部门="XX部门"'
/>
/> */}
<SqlFilter addons={addons}/>
</Form.Item>
<Space align="baseline">
<div style={{ width: '60px' }}>字段映射:</div>
......
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Input, Modal, Dropdown, Menu } from 'antd'
import styles from './index.less'
import Drag from '../../../../components/Drag'
import { LoadTableFields, ReloadTableFields } from '../../../../../apis/process';
const fnList = [
{ label: '本人姓名', value: '$本人姓名' },
{ label: '本人ID', value: '$本人ID' },
......@@ -14,9 +14,14 @@ const fnList = [
const SqlFilter = (props) => {
const { value, onChange, addons } = props
const { tableNameParent, widget, $id } = addons.formData;
const [visible, setVisible] = useState(false)
const [inputValue, setInputValue] = useState('')
const [fields, setFields] = useState([]);
useEffect(() => {
getFieldData();
}, []);
const onFocus = () => {
setInputValue(value || '')
setVisible(true)
......@@ -30,6 +35,21 @@ const SqlFilter = (props) => {
ruleText.current.focus()
}
const getFieldData = async () => {
if (!tableNameParent) {
return message.info('缺少表名!')
}
const { data } = await ReloadTableFields({ tableName: tableNameParent });
if (Array.isArray(data.root)) {
const fields = data.root.map(x=> {
return { value: `{${x.name}}`, label: x.name }
});
setFields(fields);
}
console.log(data, 'data');
};
const onOk = () => {
onChange(inputValue)
setVisible(false)
......@@ -59,19 +79,43 @@ const SqlFilter = (props) => {
onOk={onOk}
title={'SQL过滤'}
visible={visible}
width={800}
bodyStyle={{
height: 350,
}}
>
<div className={styles.textAreaBox}>
<Input.TextArea
id="SqlFilter"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
rows={4}
placeholder='示例:部门="XX部门"'
/>
<Dropdown overlay={fnListRender} placement="bottom" arrow>
<div className={styles.insertFn}>自定义变量</div>
</Dropdown>
<div style={{
width: '100%',
height: '100%',
display: 'flex',
}}>
<div className={styles.fieldListBox}>
<div style={{
fontSize: 14,
fontWeight: 'bold',
marginBottom: 5,
paddingRight: 10
}}>{tableNameParent}</div>
<div className={styles.fieldList}>
{fields.map((item, index) => (
<div key={index} onClick={()=> insertFn(item.value)}>{item.label}</div>))}
</div>
</div>
<div className={styles.textAreaBox}>
<Input.TextArea
id="SqlFilter"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
rows={4}
placeholder='示例:部门="XX部门"'
/>
<Dropdown overlay={fnListRender} placement="bottom" arrow>
<div className={styles.insertFn}>自定义变量</div>
</Dropdown>
</div>
</div>
</Drag>
</div>
)
......
......@@ -2,21 +2,39 @@
width: 100%;
.textAreaBox {
position: relative;
flex: 1;
.insertFn {
position: absolute;
bottom: 10px;
right: 10px;
border: 1px solid #1890FF;
padding: 2px 15px;
border-radius: 5px;
z-index: 1;
cursor: pointer;
border: 1px solid #1890FF;
}
textArea {
max-height: 360px !important;
min-height: 250px !important;
min-height: 330px !important;
border: 1px solid transparent;
background-color: #F0F2F6;
}
}
.fieldListBox{
max-height: 370px;
.fieldList{
>div{
padding: 5px 10px;
white-space: nowrap;
cursor: pointer;
transition: background-color 0.3s ease;
&:hover {
background-color: #e0e0e0;
}
}
max-height: 300px;
overflow-y: auto;
}
}
}
\ 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