获取焦点

This commit is contained in:
liu
2026-09-13 01:46:00 +08:00
parent 3005646179
commit 3d1ec9c833
13 changed files with 65 additions and 27 deletions
+11 -3
View File
@@ -37,6 +37,9 @@ const { Title, Text } = Typography;
/** 四舍五入保留两位 */
const round2 = (v: number) => Math.round(v * 100) / 100;
/** 输入框聚焦时全选已有内容,方便直接键入覆盖(文本 Input / 数字 InputNumber 通用) */
const selectAllOnFocus = (e: React.FocusEvent<HTMLInputElement>) => e.target.select();
/** 商品表单用分类树:有子分类的节点禁选(商品只能挂在末级分类上) */
const markParentDisabled = (nodes: IProductCategoryTree[]): IProductCategoryTree[] =>
nodes.map((node) => ({
@@ -309,6 +312,7 @@ const ProductGoodsPage: React.FC = () => {
valueType: 'text',
colProps: { span: 24 },
required: true,
fieldProps: { onFocus: selectAllOnFocus },
render: (_, record) => {
return (
<div>
@@ -359,6 +363,7 @@ const ProductGoodsPage: React.FC = () => {
hideInSearch: true,
hideInTable: true,
colProps: { span: 24 },
fieldProps: { onFocus: selectAllOnFocus },
},
{
title: '成本价',
@@ -367,7 +372,7 @@ const ProductGoodsPage: React.FC = () => {
hideInSearch: true,
align: 'center',
tooltip: '各等级售价 = 成本价 × (100 + 等级上浮比例) / 100',
fieldProps: { min: 0, precision: 2, prefix: '¥' },
fieldProps: { min: 0, precision: 2, prefix: '¥', onFocus: selectAllOnFocus },
render: (_, record) => {
const cost = Number(record.cost_price ?? 0);
return cost > 0 ? `¥${record.cost_price}` : <Text type="secondary"></Text>;
@@ -379,6 +384,7 @@ const ProductGoodsPage: React.FC = () => {
valueType: 'text',
hideInSearch: true,
align: "center",
fieldProps: { onFocus: selectAllOnFocus },
},
{
title: '单位',
@@ -387,6 +393,7 @@ const ProductGoodsPage: React.FC = () => {
hideInSearch: true,
initialValue: '斤',
align: "center",
fieldProps: { onFocus: selectAllOnFocus },
},
{
title: '单价单位',
@@ -395,14 +402,14 @@ const ProductGoodsPage: React.FC = () => {
hideInTable: true,
hideInSearch: true,
initialValue: '元/斤',
fieldProps: { placeholder: '如:元/斤、元/箱', maxLength: 20 },
fieldProps: { placeholder: '如:元/斤、元/箱', maxLength: 20, onFocus: selectAllOnFocus },
},
{
title: '排序',
dataIndex: 'sort',
valueType: 'digit',
hideInSearch: true,
fieldProps: { min: 0 },
fieldProps: { min: 0, onFocus: selectAllOnFocus },
align: 'center',
},
{
@@ -448,6 +455,7 @@ const ProductGoodsPage: React.FC = () => {
placeholder: '市场名称,如:新发地',
maxLength: 50,
allowClear: true,
onFocus: selectAllOnFocus,
},
render: (_, record) => record.market || '-',
},