diff --git a/packages/amis-ui/scss/components/form/_range.scss b/packages/amis-ui/scss/components/form/_range.scss index fb13bd1a5..bafca5b23 100644 --- a/packages/amis-ui/scss/components/form/_range.scss +++ b/packages/amis-ui/scss/components/form/_range.scss @@ -291,10 +291,16 @@ div { position: absolute; top: 0; + transform: translateX(-50%); + span { position: absolute; left: 50%; transform: translateX(-50%); + white-space: nowrap; + max-width: 100%; + overflow: hidden; + text-overflow: ellipsis; } } } diff --git a/packages/amis-ui/src/components/DatePicker.tsx b/packages/amis-ui/src/components/DatePicker.tsx index ab2dab501..2f4e5ab4f 100644 --- a/packages/amis-ui/src/components/DatePicker.tsx +++ b/packages/amis-ui/src/components/DatePicker.tsx @@ -7,6 +7,7 @@ import React from 'react'; import moment from 'moment'; import 'moment/locale/zh-cn'; +import 'moment/locale/de'; import {Icon} from './icons'; import {PopOver} from 'amis-core'; import PopUp from './PopUp'; diff --git a/packages/amis-ui/src/components/Range.tsx b/packages/amis-ui/src/components/Range.tsx index 660033c09..e0e209f24 100644 --- a/packages/amis-ui/src/components/Range.tsx +++ b/packages/amis-ui/src/components/Range.tsx @@ -9,6 +9,7 @@ import keys from 'lodash/keys'; import isString from 'lodash/isString'; import difference from 'lodash/difference'; import React from 'react'; +import TooltipWrapper from './TooltipWrapper'; import {uncontrollable} from 'amis-core'; import {Overlay} from 'amis-core'; @@ -451,6 +452,30 @@ export class Range extends React.Component { return ((value - min) * 100) / (max - min) + '%'; } + /** + * 计算每个刻度标记mark 的最大宽度 max-width + * 通过给父元素div的width赋值,从而继承 + * @param value 刻度标记key + * @param marks 整个刻度标记对象 + * @returns 刻度标记的最大宽度 string + */ + @autobind + getMarkMaxWidth(value: keyof MarksType, marks: MarksType) { + const {max, min} = this.props; + const curNum = isString(value) ? parseInt(value, 10) : value; + // 给最大宽度赋初始值 默认最大 + let maxWidth = Math.abs(max - min); + // 遍历刻度标记masks 寻找距离当前节点最近的刻度标记 并记录差值 + keys(marks).forEach((mKey: keyof MarksType) => { + const mNum = isString(mKey) ? parseInt(mKey, 10) : mKey; + if (mKey !== value) { + maxWidth = Math.min(Math.abs(curNum - mNum), maxWidth); + } + }); + // 差值的1/2 即为此刻度标记的最大宽度 + return Math.floor(maxWidth / 2) + '%'; + } + render() { const { classnames: cx, @@ -552,12 +577,23 @@ export class Range extends React.Component {
{keys(marks).map((key: keyof MarksType) => { const offsetLeft = this.getOffsetLeft(key); + const markMaxWidth = this.getMarkMaxWidth(key, marks); if (MARKS_REG.test(offsetLeft)) { return ( -
- - {(marks[key] as any)?.label || marks[key]} - +
+ + + {(marks[key] as any)?.label || marks[key]} + +
); } else { diff --git a/packages/amis-ui/src/components/Tree.tsx b/packages/amis-ui/src/components/Tree.tsx index d053745d1..3dfae5bf2 100644 --- a/packages/amis-ui/src/components/Tree.tsx +++ b/packages/amis-ui/src/components/Tree.tsx @@ -449,7 +449,7 @@ export class TreeSelector extends React.Component< return; } - if (onlyLeaf && node.children) { + if (onlyLeaf && (Array.isArray(node.children) && node.children.length)) { return; } @@ -1096,7 +1096,7 @@ export class TreeSelector extends React.Component< const iconValue = item[iconField] || (enableDefaultIcon !== false - ? item.children + ? (Array.isArray(item.children) && item.children.length) ? 'folder' : 'file' : false); @@ -1159,7 +1159,7 @@ export class TreeSelector extends React.Component< diff --git a/packages/amis/__tests__/renderers/Form/__snapshots__/range.test.tsx.snap b/packages/amis/__tests__/renderers/Form/__snapshots__/range.test.tsx.snap index c3680c0cb..f6880a408 100644 --- a/packages/amis/__tests__/renderers/Form/__snapshots__/range.test.tsx.snap +++ b/packages/amis/__tests__/renderers/Form/__snapshots__/range.test.tsx.snap @@ -170,42 +170,42 @@ exports[`Renderer:range with marks 1`] = ` class="cxd-InputRange-marks" >
0
20Mbps
40Mbps
60Mbps
80Mbps
100 diff --git a/packages/amis/__tests__/renderers/__snapshots__/CRUD.test.tsx.snap b/packages/amis/__tests__/renderers/__snapshots__/CRUD.test.tsx.snap index 7fd420e6d..f7233c332 100644 --- a/packages/amis/__tests__/renderers/__snapshots__/CRUD.test.tsx.snap +++ b/packages/amis/__tests__/renderers/__snapshots__/CRUD.test.tsx.snap @@ -4649,6 +4649,7 @@ exports[`Renderer:crud loadDataOnce 1`] = `