Commit 00d395c0 authored by 田翔's avatar 田翔

下拉框形态修复

parent 6433e07a
{
"name": "panda-xform",
"version": "1.4.8",
"description": "1.4.8: 增加表数据以及下拉框数据来源",
"version": "1.4.9",
"description": "1.4.9: 下拉框形态修复",
"keywords": [
"panda-xform"
],
......
......@@ -150,7 +150,6 @@ const textWidgets = [
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
// dependencies: ['title']
},
presetValue: {
title: '默认值',
......@@ -188,6 +187,37 @@ const textWidgets = [
displayType: 'row',
labelWidth: 100,
},
uniqueVerify: {
title: '唯一值校验',
type: 'string',
widget: 'select',
enum: ['表名/字段名'],
default: null,
enumNames: ['表名/字段名'],
displayType: 'row',
labelWidth: 100,
props: {
allowClear: true
}
},
tableName: {
title: '表名',
type: 'string',
hidden: "{{formData.uniqueVerify !== '表名/字段名'}}",
// required: "{{formData.uniqueVerify === '表名/字段名'}}",
displayType: 'row',
labelWidth: 100,
dependencies: ['uniqueVerify'],
},
fieldName: {
title: '字段名',
type: 'string',
hidden: "{{formData.uniqueVerify !== '表名/字段名'}}",
// required: "{{formData.uniqueVerify === '表名/字段名'}}",
displayType: 'row',
labelWidth: 100,
dependencies: ['uniqueVerify'],
},
groupSetting: {
title: '控件设置',
type: 'object',
......
// 自定义时间组件
import React, { useState, useEffect, useMemo } from 'react'
import { DatePicker, Input } from 'antd'
import style from '../../style'
import moment from 'moment'
import locale from 'antd/lib/date-picker/locale/zh_CN'
......@@ -45,7 +44,7 @@ const DateTime = (props) => {
onChange={dateChange}
showNow
showTime={format === 'dateTime'}
style={style}
style={{ width: '100%' }}
locale={locale}
onOk={onOk}
/>
......
import React, { useMemo } from 'react'
import { TimePicker } from 'antd'
import moment from 'moment'
import style from '../../style'
const Time = (props) => {
......@@ -18,10 +17,8 @@ const Time = (props) => {
onChange(timeStr)
}
console.log('valueShow', valueShow)
return (
<TimePicker style={style} value={valueShow} onChange={timeChange} />
<TimePicker style={{ width: '100%' }} value={valueShow} onChange={timeChange} />
)
}
......
......@@ -25,7 +25,7 @@ const ComboBox = ({ value, onChange, schema }) => {
case '手动输入':
return Array.isArray(options) ? options.map(v => v.value) : []
case '数据字典':
return Array.isArray(dictionaryList) ? dictionaryList.map(v => v.nodeName) : []
return Array.isArray(dictionaryList) ? dictionaryList.map(v => v.nodeValue) : []
case '表数据':
return Array.isArray(tableData) ? tableData : []
case '站点':
......@@ -76,7 +76,7 @@ const ComboBox = ({ value, onChange, schema }) => {
}
}
if (soruceType === '站点') {
const { code, data, msg } = await getStationListByUserID(userID, isMySite)
const { code, data, msg } = await getStationListByUserID(userID, !isMySite)
if (code === 0) {
if (Array.isArray(data)) {
setSite(data)
......@@ -99,6 +99,7 @@ const ComboBox = ({ value, onChange, schema }) => {
value={valueShow}
placeholder={placeholder}
onChange={handleChange}
allowClear
>
{enums.map(v => <Option value={v} key={v}>{v}</Option>)}
</Select>
......
import React, { useState, useEffect, useMemo } from 'react'
import './index.less'
import { TreeSelect } from 'antd'
import { DownOutlined } from '@ant-design/icons'
import { getDeptList } from '../../../../apis/process'
const selectDept = ({ value, onChange, schema }) => {
const { isMultiple, disabled, placeholder } = schema
const [data, setData] = useState([])
const valueShow = useMemo(() => {
let valueShow = value || schema.default
if (valueShow.includes('请求错误')) {
return isMultiple ? '' : []
}
if (isMultiple) {
return Array.isArray(valueShow) ? valueShow : (valueShow ? valueShow.split(',') : [])
} else {
return valueShow || null
}
}, [schema, value])
const iconClick = async () => {
let { code, data } = await getDeptList()
if (code === 0) {
setData(data)
} else {
onChange('请求错误')
}
}
const onSelect = (value) => {
if (isMultiple) {
onChange(value.join(','));
} else {
onChange(value)
}
}
const filterTreeNode = (inputValue, treeNode) => {
if (treeNode.deptName.includes(inputValue)) {
return true
}
return false
}
useEffect(() => {
onChange(value || schema.default)
}, [])
return (
<TreeSelect
disabled={disabled}
multiple={isMultiple}
switcherIcon={<DownOutlined />}
fieldNames={{ label: 'deptName', value: 'deptName', children: 'childDepts' }}
treeData={data}
onChange={onSelect}
onFocus={iconClick}
value={valueShow}
filterTreeNode={filterTreeNode}
showSearch
showArrow={!disabled}
allowClear
treeDefaultExpandAll={true}
placeholder={placeholder}
>
</TreeSelect>
)
}
export default selectDept
@import '~antd/es/style/themes/default.less';
.select-dept-body {
width: 100%;
height: 100%;
display: flex;
.dept-body-left,
.dept-body-right {
flex: 1;
border-radius: 5px;
border: 1px solid #DDDDDD;
margin: 0 5px;
.dept-body-header {
height: 40px;
line-height: 40px;
border-bottom: 1px solid #DDDDDD;
padding-left: 5%;
position: relative;
.dept-body-header-del {
position: absolute;
right: 10px;
&:hover {
cursor: pointer;
}
}
}
.dept-body-box {
height: 400px;
overflow-y: auto;
padding: 0 5% 10px 5%;
.dept-body-box-li {
height: 35px;
line-height: 35px;
}
}
}
}
\ No newline at end of file
// 站点选择器
import React, { useState, useEffect, useMemo } from 'react';
import { Select } from 'antd';
import { getStationListByUserID } from '../../../../apis/process';
const { Option } = Select;
const SiteSelect = ({ value, onChange, schema }) => {
const { disabled, placeholder, config } = schema
const [selectList, setSelectList] = useState([])
const isMultiple = config && config.includes('.') && config.split('.')[1] === 'n'
const userID = window?.globalConfig?.userInfo?.OID
const valueShow = useMemo(() => {
let val = value || schema.default
if (isMultiple) {
return val ? val.split(',') : []
}
return val ? val : null
}, [value, schema])
const handleChange = value => {
if (isMultiple) {
onChange(value.join(','))
} else {
onChange(value)
}
};
const getData = () => {
// 全部、全部.n,本人、本人.n,’‘
// [id,sysType,isAll]
let _params = [];
if (!config || config.includes('全部')) {
// 未配置,则默认全部
_params = [userID];
} else {
_params = [userID, '', false];
}
getStationListByUserID(..._params).then(res => {
if (res.code === 0) {
setSelectList(res.data || []);
} else {
onChange('请求错误');
}
});
};
useEffect(() => {
getData()
}, [])
return (
<Select
disabled={disabled}
showSearch
showArrow={!disabled}
mode={isMultiple ? 'multiple' : ''}
optionFilterProp="children"
value={valueShow}
onChange={handleChange}
placeholder={placeholder}
>
{selectList.map((item, index) => <Option value={item} key={index}>{item}</Option>)}
</Select>
)
}
export default SiteSelect
import React, { useMemo, useState } from 'react'
import { Button, Form, Input, Select, Space, Modal } from 'antd'
import style from '../../style'
import { LoadLedgers } from '../../../../apis/process'
const DataSource = (props) => {
console.log('props', props)
const { value, onChange } = props
const { formData } = props.addons
const { widget } = formData
......@@ -34,9 +32,7 @@ const DataSource = (props) => {
},
]
case '':
return [
]
return []
default: []
}
return []
......@@ -100,7 +96,7 @@ const DataSource = (props) => {
}
</Form>
</Modal>
<Input value={valueShow} onChange={inputChange} style={style} onClick={onFocus} />
<Input value={valueShow} onChange={inputChange} style={{ width: '100%' }} onClick={onFocus} />
</>
)
......
import React from 'react'
import { Form, Input } from 'antd'
const UniqueVerify = (props) => {
return (
<Form
layout='inline'
>
<Form.Item
label='表名'
name='表名'
>
<Input />
</Form.Item>
<Form.Item
label='字段名'
name='字段名'
>
<Input />
</Form.Item>
</Form>
)
}
export default UniqueVerify
\ No newline at end of file
import VerifyTextInput from './VerifyTextInput'
import UniqueVerify from './UniqueVerify'
const groupVerify = {
VerifyTextInput,
UniqueVerify,
}
export default groupVerify
\ No newline at end of file
const style = {
width: '100%'
}
export default style
\ No newline at end of file
import React, { useEffect, useMemo } from 'react'
import { InputNumber } from 'antd'
import style from '../../style'
const NumberInput = (props) => {
const { value, onChange, schema } = props
const { disabled, presetValue, placeholder, prefix, formatter } = schema
console.log('props', props)
useEffect(() => {
onChange(presetValue)
}, [presetValue, formatter])
......@@ -23,7 +20,7 @@ const NumberInput = (props) => {
formatter={(value) => value && formatter ? `${value}${formatter}` : value}
parser={(value) => value && formatter && value.replace(formatter, '')}
onChange={value => onChange(value)}
style={style}
style={{ width: '100%' }}
/>
)
......
import React, { useState, useEffect, useMemo } from 'react'
import { Input } from 'antd'
import { StarFilled } from '@ant-design/icons'
import IconPack from '../../IconPack'
const SelfInfo = ({ value, onChange, schema }) => {
const { disabled, placeholder, presetValue } = schema
const addonAfter = useMemo(() => {
if (schema.title === '本人部门') {
return <StarFilled />
} else if (schema.title === '本人姓名') {
return <IconPack.User />
} else if (schema.title === '本人ID') {
return <IconPack.User />
}
return null
}, [schema])
const handleChange = (e) => {
setInitValue(e.target.value)
onChange(e.target.value)
}
// useEffect(() => {
// const val = value || schema.default
// setInitValue(val)
// onChange(val)
// }, [])
return (
<Input
disabled={disabled}
value={presetValue}
placeholder={placeholder}
addonAfter={disabled ? null : addonAfter}
onChange={handleChange}
/>
)
}
export default SelfInfo
import React, { useState, useEffect, useMemo } from 'react'
import { Input } from 'antd'
import { Input, message } from 'antd'
import Icon, { EllipsisOutlined } from '@ant-design/icons'
import * as icons from '@ant-design/icons'
import { GetFieldValueFromTable } from '../../../../apis/process'
const iconList = Object.keys(icons).filter((item) => typeof icons[item] === 'object')
......@@ -9,11 +10,45 @@ const TextInput = (props) => {
const userInfo = window?.globalConfig?.userInfo || { fullName: '【本人姓名】', depart: { name: '【本人部门】' } }
const { value, onChange, schema } = props
const { disabled, placeholder, presetValue, addonBefore, addonAfter, maxLength, rules } = schema
const { value, onChange, schema, addons } = props
const { disabled, placeholder, presetValue, addonBefore, addonAfter, maxLength, rules, uniqueVerify, tableName, fieldName } = schema
// const [fields, setFields] = useState([])
// const [uniqueRules, setUniqueRules] = useState([])
// const uniqueRules = useMemo(() => {
// if (uniqueVerify === '表名/字段名') {
// if (tableName && fieldName) {
// return [
// {
// validator: async (rule, value, callback) => {
// console.log('validator', value)
// const { code, data, msg } = await GetFieldValueFromTable(tableName, fieldName)
// if (code === 0) {
// if (!disabled && res.data.includes(value)) {
// callback(new Error(`${12}已重复,请重新输入`));
// }
// }
// callback()
// }
// }
// ]
// }
// }
// return []
// }, [uniqueVerify, tableName, fieldName])
// const inputRules = useMemo(() => {
// let array = Array.isArray(rules) ? rules : []
// return array.concat(uniqueRules)
// }, [rules, uniqueRules])
useEffect(() => {
onChange(presetValue)
if (addons) {
addons.setValue(addons.dataPath, presetValue)
} else {
onChange(presetValue)
}
}, [presetValue])
const style = useMemo(() => {
......@@ -30,13 +65,47 @@ const TextInput = (props) => {
}, [value])
const handleChange = (e) => {
onChange(e.target.value)
if (addons) {
onChange(e.target.value)
// addons.setValue(addons.dataPath, e.target.value)
}
}
// useEffect(async () => {
// if (uniqueVerify === '表名/字段名') {
// if (tableName && fieldName) {
// setUniqueRules([
// {
// validator: async (rule, value, callback) => {
// const { code, data, msg } = await GetFieldValueFromTable(tableName, fieldName)
// if (code === 0) {
// if (!disabled && res.data.includes(value)) {
// callback(new Error(`${dataObj.alias}已重复,请重新输入`));
// }
// }
// callback()
// }
// }
// ])
// // const { code, data, msg } = await GetFieldValueFromTable(tableName, fieldName)
// // if (code === 0) {
// // if (Array.isArray(data)) {
// // setFields(data)
// // } else {
// // setFields([])
// // }
// // } else {
// // message.error(msg)
// // }
// }
// }
// }, [uniqueVerify, disabled])
return (
<Input
style={style}
rules={rules}
// rules={inputRules}
disabled={disabled}
value={value}
maxLength={maxLength}
......
import React, { useState, useEffect, useMemo } from 'react'
import { Input } from 'antd'
import { FilterFilled } from '@ant-design/icons'
const UniqueValue = ({ value, onChange, schema }) => {
const { disabled, placeholder, presetValue } = schema
const valueShow = useMemo(() => {
return presetValue || value
}, [presetValue, value])
const handleChange = (e) => {
setInitValue(e.target.value)
onChange(e.target.value)
}
// useEffect(() => {
// // const val = value || schema.default
// // setInitValue(val)
// onChange(val)
// }, [])
return (
<Input
disabled={disabled}
value={valueShow}
placeholder={placeholder}
addonAfter={disabled ? null : <FilterFilled />}
onChange={handleChange}
/>
)
}
export default UniqueValue
import TextInput from './TextInput'
import UniqueValue from './UniqueValue'
import TextArea from './TextArea'
import NumberInput from './NumberInput'
import SelfInfo from './SelfInfo'
import RichText from './RichText'
const text = {
TextInput,
TextArea,
NumberInput,
SelfInfo,
UniqueValue,
RichText,
}
......
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