Commit da9ad30c authored by 田翔's avatar 田翔

fix: 去除滚动条

parent ac3bc805
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.7.5", "version": "2.7.6",
"description": "2.7.5: 去除滚动条", "description": "2.7.6: 去除滚动条",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -406,15 +406,35 @@ const textWidgets = [ ...@@ -406,15 +406,35 @@ const textWidgets = [
widget: 'htmlInput', widget: 'htmlInput',
}, },
formatter: { formatter: {
title: '格式化', title: '数值格式',
type: 'string', type: 'string',
widget: 'select', widget: 'Formatting',
enum: ['%', '‰'], },
default: '', // isStoreFormatter: {
enumNames: ['%', '‰'], // title: '存储为转化值',
props: { // type: 'boolean',
allowClear: true // displayType: 'row',
} // labelWidth: 120,
// hidden: '{{Boolean(formData.formatter !== "${百分比}")}}',
// widget: 'BooleanSwitch',
// description: '存储格式化后的值(10%会存储为0.1)'
// },
decimalDigits: {
title: '小数位数',
type: 'string',
widget: 'DecimalDigits',
hidden: '{{!["${小数}", "${货币}"].includes(formData.formatter)}}',
dependencies: ['formatter']
},
min: {
title: '最小值',
type: 'string',
widget: 'NumerDefault',
},
max: {
title: '最大值',
type: 'string',
widget: 'NumerDefault',
}, },
groupStyle: { groupStyle: {
title: '控件样式', title: '控件样式',
......
...@@ -44,7 +44,7 @@ const InputAddon = (props) => { ...@@ -44,7 +44,7 @@ const InputAddon = (props) => {
onCancel={onCancel} onCancel={onCancel}
bodyStyle={{ height: '450px', overflow: 'auto' }} bodyStyle={{ height: '450px', overflow: 'auto' }}
> >
<div className={`iconBox`}> <div className={styles.iconBox}>
{ {
iconList.map((v, i) => { iconList.map((v, i) => {
if (i === 0) return null if (i === 0) return null
......
@import '~antd/es/style/themes/default.less'; @import '~antd/es/style/themes/default.less';
@pandaXform: ~'@{ant-prefix}-pandaXform'; .inputAddon {
.@{pandaXform} { position: relative;
.inputAddon { .@{ant-prefix}-input {
position: relative; padding-right: 30px;
.@{ant-prefix}-input { }
padding-right: 30px; .addon {
position: absolute;
right: 10px;
top: 5px;
&:hover {
color: #4096ff;
} }
.addon { }
position: absolute; .iconBox {
right: 10px; width: 100%;
top: 5px; height: 100%;
display: flex;
flex-wrap: wrap;
.iconItem {
display: flex;
align-items: center;
justify-content: center;
width: 70px;
height: 70px;
font-size: 50px;
&:hover { &:hover {
color: #4096ff; cursor: pointer;
} }
} &[active='true'] {
.iconBox { transition: all 0.3s ease;
width: 100%; background: #4096ff;
height: 100%; border-radius: 5px;
display: flex; color: white;
flex-wrap: wrap; transform: scale(1.2);
.iconItem {
display: flex;
align-items: center;
justify-content: center;
width: 70px;
height: 70px;
font-size: 50px;
&:hover {
cursor: pointer;
}
&[active='true'] {
transition: all 0.3s ease;
background: #4096ff;
border-radius: 5px;
color: white;
transform: scale(1.2);
}
} }
} }
} }
......
import React, { useEffect } from 'react'
import { InputNumber } from 'antd'
const DecimalDigits = (props) => {
const { value, onChange } = props
useEffect(() => {
if (!value) {
onChange('2')
}
}, [])
return (
<InputNumber
min={1}
value={Number(value)}
onChange={value => onChange(value ? `${parseInt(value)}` : '2')}
/>
)
}
export default DecimalDigits
\ No newline at end of file
import React from 'react'
import { Input, Dropdown, Menu } from 'antd'
import { PlusOutlined } from '@ant-design/icons'
import styles from './index.less'
const options = [
{ label: '整数', key: '${整数}' },
{ label: '小数', key: '${小数}' },
{ label: '货币', key: '${货币}' },
{ label: '百分比', key: '${百分比}' },
]
const Formatting = (props) => {
const { value, onChange, addons } = props
const inputChange = (e) => {
onChange(e.target.value)
}
const menuClick = (item) => {
onChange(item.key)
}
return (
<div className={styles.formatting}>
<Input
style={{ color: options.map(v => v.key).includes(value) ? '#4096ff' : '' }}
value={value}
onChange={inputChange}
>
</Input>
<div className={styles.formattingIcon}>
<Dropdown
overlay={(
<Menu
onClick={menuClick}
items={options}
/>
)}
trigger='click'
>
<PlusOutlined />
</Dropdown>
</div>
</div>
)
}
export default Formatting
\ No newline at end of file
.formatting {
position: relative;
.formattingIcon {
position: absolute;
top: 5px;
right: 10px;
&:hover {
color: #4096ff;
}
}
}
\ No newline at end of file
import PercentSlider from './PercentSlider' import PercentSlider from './PercentSlider'
import ShowText from './ShowText' import ShowText from './ShowText'
import Formatting from './Formatting'
import DecimalDigits from './DecimalDigits'
const groupStyle = { const groupStyle = {
PercentSlider, PercentSlider,
ShowText, ShowText,
Formatting,
DecimalDigits,
} }
export default groupStyle export default groupStyle
\ No newline at end of file
import React, { useEffect, useMemo } from 'react' import React, { useEffect, useMemo, useState } from 'react'
import { InputNumber } from 'antd' import { InputNumber } from 'antd'
function formatMoney(number, places, symbol, thousand, decimal) {
number = number || 0;
places = !isNaN(places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : "$";
thousand = thousand || ",";
decimal = decimal || ".";
var negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}
const NumberInput = (props) => { const NumberInput = (props) => {
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { disabled, presetValue, placeholder, prefix, formatter, addonBefore, addonAfter } = schema const { disabled, presetValue, placeholder, prefix, formatter, decimalDigits, isStoreFormatter, addonBefore, addonAfter, min, max } = schema
const [once, setOnce] = useState(true)
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
...@@ -16,19 +29,39 @@ const NumberInput = (props) => { ...@@ -16,19 +29,39 @@ const NumberInput = (props) => {
const inputChange = (value) => { const inputChange = (value) => {
if (addons) { if (addons) {
onChange(value + '') onChange(`${value}`)
}
}
const formatterFn = (value) => {
if (value) {
if (formatter === '${百分比}') {
return `${value}%`
} else if (formatter === '${货币}') {
return formatMoney(Number(value), Number(decimalDigits))
} else if (formatter === '${整数}') {
return `${parseInt(value)}`
} else if (formatter === '${小数}') {
return Number(value).toFixed(Number(decimalDigits))
} else if (formatter) {
return `${value}${formatter}`
}
} }
return value
} }
return ( return (
<InputNumber <InputNumber
min={min || Number.MIN_SAFE_INTEGER}
max={max || Number.MAX_SAFE_INTEGER}
step={(formatter === '${百分比}' && isStoreFormatter) ? 0.01 : 1}
addonBefore={addonBefore} addonBefore={addonBefore}
addonAfter={addonAfter} addonAfter={addonAfter}
prefix={prefix} prefix={prefix}
placeholder={placeholder} placeholder={placeholder}
disabled={disabled} disabled={disabled}
value={Number(value)} value={Number(value)}
formatter={(value) => value && formatter ? `${value}${formatter}` : value} formatter={formatterFn}
onChange={inputChange} onChange={inputChange}
style={{ width: '100%' }} style={{ width: '100%' }}
/> />
......
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