Skip to content

Commit 802dd40

Browse files
Merge branch 'lowcoder-org:main' into remove-moment
2 parents 7dcf837 + 730c161 commit 802dd40

File tree

5 files changed

+97
-15
lines changed

5 files changed

+97
-15
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComp.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ import { RatingComp } from "./columnTypeComps/columnRatingComp";
1515
import { BadgeStatusComp } from "./columnTypeComps/columnStatusComp";
1616
import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
1717
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
18+
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";
1819

1920
const actionOptions = [
2021
{
2122
label: trans("table.text"),
2223
value: "text",
2324
},
25+
{
26+
label: trans("table.number"),
27+
value: "number",
28+
},
2429
{
2530
label: trans("table.link"),
2631
value: "link",
@@ -73,6 +78,7 @@ const actionOptions = [
7378

7479
export const ColumnTypeCompMap = {
7580
text: SimpleTextComp,
81+
number: ColumnNumberComp,
7682
button: ButtonComp,
7783
badgeStatus: BadgeStatusComp,
7884
link: LinkComp,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Input } from "antd";
2+
import { NumberControl, StringControl } from "comps/controls/codeControl";
3+
import { BoolControl } from "comps/controls/boolControl";
4+
import { trans } from "i18n";
5+
import { ColumnTypeCompBuilder, ColumnTypeViewFn } from "../columnTypeCompBuilder";
6+
import { ColumnValueTooltip } from "../simpleColumnTypeComps";
7+
8+
const childrenMap = {
9+
text: NumberControl,
10+
float: BoolControl,
11+
prefix: StringControl,
12+
suffix: StringControl,
13+
};
14+
15+
let float = false;
16+
const getBaseValue: ColumnTypeViewFn<typeof childrenMap, number, number> = (
17+
props
18+
) => {
19+
return props.text
20+
};
21+
22+
export const ColumnNumberComp = (function () {
23+
return new ColumnTypeCompBuilder(
24+
childrenMap,
25+
(props, dispatch) => {
26+
float = props.float;
27+
const value = !float ? Math.floor(props.changeValue ?? getBaseValue(props, dispatch)) : props.changeValue ?? getBaseValue(props, dispatch);
28+
return props.prefix + value + props.suffix;
29+
},
30+
(nodeValue) => nodeValue.text.value,
31+
getBaseValue,
32+
)
33+
.setEditViewFn((props) => {
34+
return (
35+
<Input
36+
type="number"
37+
step={float?"0.01": "1"}
38+
defaultValue={props.value}
39+
autoFocus
40+
bordered={false}
41+
onChange={(e) => {
42+
props.onChange(!float ? Math.floor(e.target.valueAsNumber) : e.target.valueAsNumber);
43+
}}
44+
onBlur={props.onChangeEnd}
45+
onPressEnter={props.onChangeEnd}
46+
/>
47+
)})
48+
.setPropertyViewFn((children) => {
49+
return (
50+
<>
51+
{children.text.propertyView({
52+
label: trans("table.columnValue"),
53+
tooltip: ColumnValueTooltip,
54+
})}
55+
{children.prefix.propertyView({
56+
label: trans("table.prefix"),
57+
// tooltip: ColumnValueTooltip,
58+
})}
59+
{children.suffix.propertyView({
60+
label: trans("table.suffix"),
61+
// tooltip: ColumnValueTooltip,
62+
})}
63+
{children.float.propertyView({
64+
label: trans("table.float"),
65+
// tooltip: ColumnValueTooltip,
66+
})}
67+
</>
68+
);
69+
})
70+
.build();
71+
})();

client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -945,45 +945,42 @@ export type CarouselStyleType = StyleConfigType<typeof CarouselStyle>;
945945
export type RichTextEditorStyleType = StyleConfigType<typeof RichTextEditorStyle>;
946946

947947
export function widthCalculator(margin: string) {
948-
const marginArr = margin?.trim().split(" ") || "";
948+
const marginArr = margin?.trim().replace(/\s+/g,' ').split(" ") || "";
949949
if (marginArr.length === 1) {
950950
return `calc(100% - ${
951-
parseInt(margin.replace(/[^\d.]/g, "")) * 2 + margin.replace(/[0-9]/g, "")
951+
parseInt(margin.replace(/[^\d.]/g, "")) * 2 +
952+
(margin.replace(/[0-9]/g, "") || "px")
952953
})`;
953954
} else if (marginArr.length === 2 || marginArr.length === 3) {
954955
return `calc(100% - ${
955956
parseInt(marginArr[1].replace(/[^\d.]/g, "")) * 2 +
956-
marginArr[1].replace(/[0-9]/g, "")
957+
(marginArr[1].replace(/[0-9]/g, "") || 'px')
957958
})`;
958959
} else {
959960
return `calc(100% - ${
960961
parseInt(marginArr[1]?.replace(/[^\d.]/g, "") || "0") +
961-
marginArr[1]?.replace(/[0-9]/g, "" || "px")
962+
(marginArr[1]?.replace(/[0-9]/g, "") || "px")
962963
} - ${
963964
parseInt(marginArr[3]?.replace(/[^\d.]/g, "") || "0") +
964-
marginArr[3]?.replace(/[0-9]/g, "" || "px")
965+
(marginArr[3]?.replace(/[0-9]/g, "") || "px")
965966
})`;
966967
}
967968
}
968969

969970
export function heightCalculator(margin: string) {
970971
const marginArr = margin?.trim().split(" ") || "";
971-
if (marginArr.length === 1) {
972-
return `calc(100% - ${
973-
parseInt(margin.replace(/[^\d.]/g, "")) * 2 + margin.replace(/[0-9]/g, "")
974-
})`;
975-
} else if (marginArr.length === 2) {
972+
if (marginArr.length === 1 || marginArr.length === 2) {
976973
return `calc(100% - ${
977-
parseInt(marginArr[0].replace(/[^\d.]/g, "")) * 2 +
978-
marginArr[0].replace(/[0-9]/g, "")
974+
parseInt(marginArr[0].replace(/[^\d.]/g, "")) * 2 +
975+
(marginArr[0].replace(/[0-9]/g, "") || 'px')
979976
})`;
980-
} else {
977+
}else if(marginArr.length >2){
981978
return `calc(100% - ${
982979
parseInt(marginArr[0]?.replace(/[^\d.]/g, "") || "0") +
983-
marginArr[0]?.replace(/[0-9]/g, "") || "px"
980+
(marginArr[0]?.replace(/[0-9]/g, "") || "px")
984981
} - ${
985982
parseInt(marginArr[2]?.replace(/[^\d.]/g, "") || "0") +
986-
marginArr[2]?.replace(/[0-9]/g, "") || "px"
983+
(marginArr[2]?.replace(/[0-9]/g, "") || "px")
987984
})`;
988985
}
989986
}

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,11 @@ export const en = {
11491149
auto: "Auto",
11501150
fixed: "Fixed",
11511151
columnType: "Column type",
1152+
float: "Float",
1153+
prefix: "Prefix",
1154+
suffix: "Suffix",
11521155
text: "Text",
1156+
number: "Number",
11531157
link: "Link",
11541158
links: "Links",
11551159
tag: "Tag",

client/packages/lowcoder/src/i18n/locales/zh.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,11 @@ table: {
11301130
auto: "自动",
11311131
fixed: "固定",
11321132
columnType: "列类型",
1133+
float: "分数",
1134+
prefix: "字首",
1135+
suffix: "后缀",
11331136
text: "文本",
1137+
number: "数字",
11341138
link: "链接",
11351139
links: "多链接",
11361140
tag: "标签",

0 commit comments

Comments
 (0)