Commit 79b905ae authored by 田翔's avatar 田翔

附件控件优化

parent 6905ba0b
{
"name": "panda-xform",
"version": "1.4.0",
"description": "1.4.0: 统一表单配置信息",
"version": "1.4.1",
"description": "1.4.1: 附件控件优化",
"keywords": [
"panda-xform"
],
......
......@@ -137,7 +137,7 @@ const globalSettings = {
title: '整体布局',
type: 'number',
enum: [1, 2, 3],
default: 1,
default: 3,
enumNames: ['一行一列', '一行两列', '一行三列'],
widget: 'select',
props: {
......@@ -167,8 +167,6 @@ const globalSettings = {
},
},
},
}
export {
......
......@@ -6,6 +6,70 @@ const allSetting = {
...elementSettings
}
const base = {
groupBase: {
title: '基础信息',
type: 'object',
properties: {}
},
fieldName: {
title: '字段名称',
type: 'string',
widget: 'FieldNames',
required: true,
displayType: 'row',
labelWidth: 80,
},
title: {
title: '标题',
required: true,
type: 'string',
widget: 'htmlInput',
displayType: 'row',
labelWidth: 80,
},
placeholder: {
title: '提示语',
type: 'string',
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
// dependencies: ['title']
},
presetValue: {
title: '默认值',
type: 'string',
widget: 'InputDefault',
displayType: 'row',
labelWidth: 80,
},
}
const groupStyle = {
groupStyle: {
title: '控件样式',
type: 'object',
properties: {}
},
width: {
title: '元素宽度',
type: 'string',
widget: 'percentSlider',
// default: '100%',
},
labelWidth: {
title: '标签宽度',
description: '默认值110',
default: 110,
type: 'number',
widget: 'slider',
max: 400,
props: {
hideNumber: true,
},
},
}
const layoutWidgets = [
{
text: '分组名称',
......@@ -24,7 +88,6 @@ const layoutWidgets = [
title: {
title: '标题',
type: 'string',
widget: 'FieldNames',
required: true,
displayType: 'row',
labelWidth: 80,
......@@ -51,11 +114,6 @@ const textWidgets = [
title: '文本',
type: 'string',
widget: 'TextInput',
props: {
style: {
color: 'pink'
}
}
},
setting: {
groupBase: {
......@@ -83,10 +141,10 @@ const textWidgets = [
placeholder: {
title: '提示语',
type: 'string',
widget: 'Placeholder',
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
dependencies: ['title']
// dependencies: ['title']
},
presetValue: {
title: '默认值',
......@@ -95,21 +153,6 @@ const textWidgets = [
displayType: 'row',
labelWidth: 80,
},
// groupSource: {
// title: '数据来源',
// type: 'object',
// properties: {}
// },
// source: {
// title: '数据来源',
// name: '数据来源',
// type: 'string',
// widget: 'select',
// displayType: 'row',
// labelWidth: 80,
// enum: [1, 2, 3],
// enumNames: ['一行一列', '一行两列', '一行三列'],
// },
groupVerify: {
title: '数据校验',
type: 'object',
......@@ -175,14 +218,20 @@ const textWidgets = [
type: 'string',
widget: 'InputAddon',
displayType: 'row',
labelWidth: 80,
labelWidth: 60,
},
suffix: {
title: '后缀',
type: 'string',
widget: 'InputAddon',
displayType: 'row',
labelWidth: 80,
labelWidth: 60,
},
width: {
title: '元素宽度',
type: 'string',
widget: 'percentSlider',
// default: '100%',
},
labelWidth: {
title: '标签宽度',
......@@ -206,7 +255,7 @@ const textWidgets = [
widget: 'UniqueValue'
},
setting: {
// ...allSetting
},
},
{
......@@ -218,7 +267,124 @@ const textWidgets = [
widget: 'TextArea'
},
setting: {
...allSetting
groupBase: {
title: '基础信息',
type: 'object',
properties: {}
},
fieldName: {
title: '字段名称',
type: 'string',
widget: 'FieldNames',
required: true,
displayType: 'row',
labelWidth: 80,
},
title: {
title: '标题',
required: true,
type: 'string',
widget: 'htmlInput',
displayType: 'row',
labelWidth: 80,
},
placeholder: {
title: '提示语',
type: 'string',
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
// dependencies: ['title']
},
presetValue: {
title: '默认值',
type: 'string',
displayType: 'row',
labelWidth: 80,
},
groupVerify: {
title: '数据校验',
type: 'object',
properties: {}
},
required: {
title: '必填',
type: 'boolean',
widget: 'BooleanSwitch',
default: false,
displayType: 'row',
labelWidth: 100,
},
maxLength: {
title: '最大长度',
type: 'number',
widget: 'number',
default: 500,
displayType: 'row',
labelWidth: 100,
description: '可输入最大字节长度'
},
groupSetting: {
title: '控件设置',
type: 'object',
properties: {}
},
disabled: {
title: '只读',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
hidden: {
title: '隐藏',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
emphasis: {
title: '强调',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
groupStyle: {
title: '控件样式',
type: 'object',
properties: {}
},
rows: {
title: '高度',
description: '多行文本占据的行数',
type: 'number',
widget: 'number',
max: 10,
default: 5,
widget: 'slider',
props: {
hideNumber: true,
},
},
width: {
title: '元素宽度',
description: '默认值100%',
type: 'string',
widget: 'percentSlider',
// default: '100%',
},
labelWidth: {
title: '标签宽度',
description: '默认值110',
default: 110,
type: 'number',
widget: 'slider',
max: 400,
props: {
hideNumber: true,
},
},
},
},
{
......@@ -230,6 +396,11 @@ const textWidgets = [
widget: 'number'
},
setting: {
groupBase: {
title: '基础信息',
type: 'object',
properties: {}
},
fieldName: {
title: '字段名称',
type: 'string',
......@@ -249,37 +420,66 @@ const textWidgets = [
placeholder: {
title: '提示语',
type: 'string',
widget: 'Placeholder',
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
dependencies: ['title']
// dependencies: ['title']
},
presetValue: {
title: '默认值',
type: 'string',
displayType: 'row',
labelWidth: 80,
},
groupVerify: {
title: '数据校验',
type: 'object',
properties: {}
},
{
text: '本人部门',
name: '本人部门',
schema: {
title: '本人部门',
type: 'string',
name: '本人部门',
widget: 'SelfInfo'
required: {
title: '必填',
type: 'boolean',
widget: 'BooleanSwitch',
default: false,
displayType: 'row',
labelWidth: 100,
},
setting: {
...allSetting
// maxLength: {
// title: '最大长度',
// type: 'number',
// widget: 'number',
// default: 500,
// displayType: 'row',
// labelWidth: 100,
// description: '可输入最大字节长度'
// },
groupSetting: {
title: '控件设置',
type: 'object',
properties: {}
},
disabled: {
title: '只读',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
{
text: '本人姓名',
name: '本人姓名',
schema: {
title: '本人姓名',
name: '本人姓名',
type: 'string',
widget: 'SelfInfo'
hidden: {
title: '隐藏',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
setting: {
...allSetting
emphasis: {
title: '强调',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
...groupStyle,
},
},
{
......@@ -292,7 +492,7 @@ const textWidgets = [
widget: 'SelfInfo'
},
setting: {
...allSetting
},
},
{
......@@ -302,17 +502,72 @@ const textWidgets = [
title: '富文本',
name: '富文本',
type: 'string',
widget: 'RichText'
widget: 'RichText',
width: '100%',
},
setting: {
...allSetting,
width: {
title: '元素宽度',
groupBase: {
title: '基础信息',
type: 'object',
properties: {}
},
fieldName: {
title: '字段名称',
type: 'string',
hidden: true,
widget: 'percentSlider',
default: '100%',
widget: 'FieldNames',
required: true,
displayType: 'row',
labelWidth: 80,
},
title: {
title: '标题',
required: true,
type: 'string',
widget: 'htmlInput',
displayType: 'row',
labelWidth: 80,
},
presetValue: {
title: '默认值',
type: 'string',
displayType: 'row',
labelWidth: 80,
},
// placeholder: {
// title: '提示语',
// type: 'string',
// // widget: 'Placeholder',
// displayType: 'row',
// labelWidth: 80,
// // dependencies: ['title']
// },
groupSetting: {
title: '控件设置',
type: 'object',
properties: {}
},
disabled: {
title: '只读',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
hidden: {
title: '隐藏',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
emphasis: {
title: '强调',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
...groupStyle,
},
},
]
......@@ -354,9 +609,9 @@ const selectWidgets = [
placeholder: {
title: '提示语',
type: 'string',
// widget: 'Placeholder',
displayType: 'row',
labelWidth: 80,
default: '123'
},
presetValue: {
title: '默认值',
......@@ -412,9 +667,10 @@ const selectWidgets = [
required: {
title: '必填',
type: 'boolean',
widget: 'checkbox',
widget: 'BooleanSwitch',
default: false,
width: '33%',
displayType: 'row',
labelWidth: 70,
},
'控件设置': {
title: '控件设置',
......@@ -621,6 +877,134 @@ const selectWidgets = [
},
]
const fileWidgets = [
{
text: '附件',
name: '附件',
schema: {
title: '附件',
type: 'string',
widget: 'FileUpload',
width: '100%'
},
setting: {
groupBase: {
title: '基础信息',
type: 'object',
properties: {}
},
fieldName: {
title: '字段名称',
type: 'string',
widget: 'FieldNames',
required: true,
displayType: 'row',
labelWidth: 80,
},
title: {
title: '标题',
required: true,
type: 'string',
widget: 'htmlInput',
displayType: 'row',
labelWidth: 80,
},
placeholder: {
title: '提示语',
type: 'string',
displayType: 'row',
labelWidth: 80,
},
groupSetting: {
title: '控件设置',
type: 'object',
properties: {}
},
fileType: {
title: '文件类型',
type: 'string',
required: true,
widget: 'select',
enum: ['全部', '图片', '文档', '音频', '视频'],
enumNames: ['全部', '图片', '文档', '音频', '视频'],
default: '全部',
displayType: 'row',
labelWidth: 80,
},
disabled: {
title: '只读',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
required: {
title: '必填',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
hidden: {
title: '隐藏',
type: 'boolean',
widget: 'checkbox',
default: false,
width: '33%',
},
preview: {
title: '预览',
type: 'boolean',
widget: 'checkbox',
default: true,
width: '33%',
},
download: {
title: '下载',
type: 'boolean',
widget: 'checkbox',
default: true,
width: '33%',
},
photo: {
title: '允许从相册选取',
type: 'boolean',
widget: 'checkbox',
default: false,
hidden: "{{formData.fileType !== '图片'}}"
},
groupStyle: {
title: '控件样式',
type: 'object',
properties: {}
},
showType: {
title: '显示方式',
type: 'string',
default: 'picture',
enum: ['picture', 'text', 'picture-card'],
enumNames: ['列表_详细', '列表_省略', '卡片'],
},
// width: {
// title: '元素宽度',
// type: 'string',
// widget: 'percentSlider',
// default: '100%',
// },
labelWidth: {
title: '标签宽度',
description: '默认值110',
default: 110,
type: 'number',
widget: 'slider',
max: 400,
props: {
hideNumber: true,
},
},
},
},
]
const settings = [
{
......@@ -701,49 +1085,7 @@ const settings = [
title: '附件控件',
show: true,
useCommon: true,
widgets: [
{
text: '附件',
name: '附件',
schema: {
title: '附件',
type: 'string',
widget: 'FileUpload',
},
setting: {
...commonSettings,
presetValue: {},
fileType: {
title: '文件类型',
type: 'string',
required: true,
widget: 'select',
enum: ['图片', '文档', '音频', '视频'],
enumNames: ['图片', '文档', '音频', '视频'],
default: '图片',
displayType: 'row',
labelWidth: 80,
},
listType: {
title: '显示样式',
type: 'string',
default: 'picture',
enum: ['picture', 'text', 'picture-card'],
enumNames: ['列表', '文本', '卡片'],
displayType: 'row',
labelWidth: 80,
},
...switchSettings,
width: {
title: '元素宽度',
type: 'string',
widget: 'percentSlider',
default: '100%',
},
...elementSettings,
},
},
],
widgets: fileWidgets,
},
{
title: '地图控件',
......@@ -772,6 +1114,7 @@ const settings = [
name: '关联表单',
type: 'string',
widget: 'RelationForm',
width: '100%',
},
setting: {
fieldName: {
......@@ -809,7 +1152,7 @@ const settings = [
title: '元素宽度',
type: 'string',
widget: 'percentSlider',
default: '100%',
// default: '100%',
},
...elementSettings,
},
......
import React, { useEffect, useMemo, useState } from 'react'
import styles from './index.less'
import { Upload, Button, message, Modal } from 'antd'
import { UploadOutlined, FileOutlined } from '@ant-design/icons'
import { UploadOutlined, FileOutlined, ArrowDownOutlined } from '@ant-design/icons'
import FileViewer from 'react-file-viewer'
import { uploadFileUrl, downloadFileUrl, downloadFile } from '../../../../apis/process'
import { downloadFunc, filenameVerification } from '../../../../utils/utils'
const accepts = {
'全部': [],
'图片': ['.bmp', '.gif', '.jpeg', 'tiff', '.png', '.svg', '.jpg'],
// '文档': ['.docx', '.xlsx', '.pdf'],
'文档': [],
'文档': ['.docx', '.xlsx', '.pdf'],
'视频': ['.mp4'],
'音频': ['.mp3'],
}
......@@ -51,7 +51,7 @@ const getFileType = (fileName) => {
const FileUpload = (props) => {
const { value, schema, onChange } = props
const { disabled, fileType, listType, presetValue, placeholder } = schema
const { disabled, fileType, showType, presetValue, placeholder, preview, download } = schema
const [showList, setShowList] = useState('')
const [visible, setVisible] = useState(false)
......@@ -60,8 +60,13 @@ const FileUpload = (props) => {
const option = {
name: 'file',
action: `${window.location.origin}${uploadFileUrl}`,
listType: listType,
listType: showType,
withCredentials: true,
showUploadList: download ?
{
showDownloadIcon: '下载',
downloadIcon: <ArrowDownOutlined />,
} : {},
beforeUpload(file, fileList) {
/** @Tips: 解决提交文件中存在特殊字符的问题 */
let _continueUpload = true;
......@@ -104,6 +109,7 @@ const FileUpload = (props) => {
}
},
onPreview: (file) => {
if (!preview) return message.info('该附件禁止预览')
let fileType = getFileType(file.name)
if (fileType) {
setShowFile({ name: file.name, fileType: fileType, filePath: file.url })
......@@ -161,7 +167,11 @@ const FileUpload = (props) => {
iconRender={iconRender}
{...option}
>
{listType !== 'picture-card' ? <Button icon={<UploadOutlined />}>{placeholder || '上传'}</Button> : (disabled ? null : (placeholder || '+ 上传'))}
{
showType !== 'picture-card' ?
<Button icon={<UploadOutlined />}>{placeholder || '上传'}</Button>
: (disabled ? null : (placeholder || '+ 上传'))
}
</Upload>
<Modal
width={'70%'}
......
......@@ -33,12 +33,12 @@ const VerifyTextInput = (props) => {
}, [value])
const selectChange = (value) => {
if (value) {
const item = options.find(v => v.value === value)
onChange([{
pattern: value,
message: item.message,
}])
onChange([{ pattern: value, message: item.message }])
} else {
onChange([])
}
}
return (
......
......@@ -9,34 +9,29 @@ const options = [
const InputDefault = (props) => {
console.log('props', props)
const { value, onChange } = props
const [visible, setVisible] = useState(false)
const style = useMemo(() => {
},)
const iconClick = () => {
setVisible(true)
let paths = ['【本人姓名】', '【本人部门】']
if (paths.includes(value)) {
return { color: 'blue' }
}
return null
}, [value])
const onOk = () => {
const selectChange = (value) => {
onChange(value)
}
const onCancel = () => {
setVisible(false)
}
const selectChange = (value) => {
onChange(value)
const inputChange = (e) => {
onChange(e.target.value)
}
const content = (
<Select
allowClear
placeholder='请选择环境变量'
style={{ width: '100%' }}
options={options}
onChange={selectChange}
......@@ -48,13 +43,13 @@ const InputDefault = (props) => {
<div className='InputDefault'>
<Input
value={value}
onChange={(e) => onChange(e.target.value)}
onChange={inputChange}
style={style}
addonAfter={
<Popover
placement="topRight"
content={content}
title="数据将从环境变量读取"
title="环境变量"
trigger="click"
>
<EllipsisOutlined />
......
......@@ -6,6 +6,8 @@ const Placeholder = (props) => {
const { value, addons, onChange } = props
const { title } = addons.formData
console.log('props', props)
const inputChange = (e) => {
onChange(e.target.value)
}
......
import InputDefault from "./InputDefault"
import InputDefault from './InputDefault'
import Placeholder from './Placeholder'
const base = {
InputDefault,
Placeholder,
}
export default base
\ No newline at end of file
......@@ -3,7 +3,6 @@ import BooleanSwitch from './BooleanSwitch'
import EnumOptions from './EnumOptions'
import FieldNames from './FieldNames'
import InputAddon from './InputAddon'
import Placeholder from './Placeholder'
import CascadeField from './CascadeField'
import DateSelect from './DateSelect'
import DataSource from './DataSource'
......@@ -15,7 +14,6 @@ const settings = {
EnumOptions,
FieldNames,
InputAddon,
Placeholder,
CascadeField,
DateSelect,
DataSource,
......
......@@ -4,7 +4,7 @@ import style from '../../style'
const NumberInput = ({ value, onChange, schema }) => {
const { disabled, presetValue } = schema
const { disabled, presetValue, placeholder } = schema
const valueShow = useMemo(() => {
return presetValue || value
......@@ -12,6 +12,7 @@ const NumberInput = ({ value, onChange, schema }) => {
return (
<InputNumber
placeholder={placeholder}
disabled={disabled}
value={valueShow}
onChange={value => onChange(value)}
......
......@@ -25,31 +25,6 @@ const RichText = forwardRef(({ schema, onChange, value }, ref) => {
return value || presetValue
}, [presetValue, value])
// 图片上传
const uploadImg = file => {
const formData = new FormData();
formData.append('file', file);
setLoading(true);
request({
url: uploadFileAPI,
method: 'POST',
data: formData,
})
.then(res => {
if (!res.data) return;
// eslint-disable-next-line no-useless-escape
const img = res.data.replace(/[\\ \/=]/g, '/');
const imgHtml = `
<img contenteditable="false" style="display: block;" width="50%" src="${downFileAPI}?filePath=${img}" >
`;
editor.cmd.do('insertHTML', imgHtml);
setLoading(false);
})
.catch(err => {
setLoading(false);
});
}
const editorChange = (editor) => {
onChange(editor.getHtml())
}
......
......@@ -5,7 +5,7 @@ const TextArea = ({ value, onChange, schema }) => {
console.log('多行文本', schema)
const { disabled, placeholder, presetValue } = schema
const { disabled, placeholder, presetValue, maxLength, rows } = schema
const valueShow = useMemo(() => {
return presetValue || value
......@@ -18,9 +18,10 @@ const TextArea = ({ value, onChange, schema }) => {
return (
<Input.TextArea
maxLength={maxLength}
disabled={disabled}
value={valueShow}
rows={5}
rows={rows}
placeholder={placeholder}
onChange={handleChange}
/>
......
......@@ -7,21 +7,35 @@ const iconList = Object.keys(icons).filter((item) => typeof icons[item] === 'obj
const TextInput = (props) => {
const userInfo = window?.globalConfig?.userInfo || { fullName: '【本人姓名】', depart: { name: '【本人部门】' } }
const { value, onChange, schema } = props
const { disabled, placeholder, presetValue, prefix, suffix, maxLength, rules } = schema
const valueShow = useMemo(() => {
return presetValue || value
}, [presetValue, value])
return value || presetValue
}, [value, presetValue])
const style = useMemo(() => {
let paths = ['【本人姓名】', '【本人部门】']
if (paths.includes(presetValue)) {
if (presetValue === '【本人姓名】') {
onChange(userInfo.fullName)
} else if (presetValue === '【本人部门】') {
onChange(userInfo.depart.name)
}
return { color: 'blue' }
}
return null
}, [presetValue])
const handleChange = (e) => {
onChange(e.target.value)
}
console.log('rules', rules)
return (
<Input
style={style}
rules={rules}
disabled={disabled}
value={valueShow}
......
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