获取焦点

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 || '-',
},
+34 -11
View File
@@ -90,6 +90,9 @@ const calcUnitRefPrice = (total: number, spec: string): number => {
const calcLevelAmount = (amount: number, percent: number): number =>
Math.trunc(amount * (100 + percent)) / 100;
/** 输入框聚焦时全选已有内容,方便直接键入覆盖(Input / InputNumber / TextArea 通用) */
const selectAllOnFocus = (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => e.target.select();
/**
* 采购单管理(C1 在门店订单页合并生成 / C2-C3 导出 / C4 明细矩阵修改)
* 采购单无独立明细表,明细直接溯源门店订货明细:商品行 × 门店列
@@ -560,6 +563,7 @@ const PurchaseOrderPage: React.FC = () => {
prefix="¥"
className="w-full"
defaultValue={Number(row.cost_price)}
onFocus={selectAllOnFocus}
onPressEnter={(e) => void handleInlineSave(row, dataIndex, (e.target as HTMLInputElement).value)}
onBlur={(e) => void handleInlineSave(row, dataIndex, e.target.value)}
/>
@@ -573,6 +577,7 @@ const PurchaseOrderPage: React.FC = () => {
style={{ textAlign: 'center' }}
defaultValue={row[dataIndex]}
maxLength={dataIndex === 'unit' ? 20 : 100}
onFocus={selectAllOnFocus}
onPressEnter={(e) => void handleInlineSave(row, dataIndex, (e.target as HTMLInputElement).value)}
onBlur={(e) => void handleInlineSave(row, dataIndex, e.target.value)}
/>
@@ -770,6 +775,7 @@ const PurchaseOrderPage: React.FC = () => {
precision={0}
className="w-full"
defaultValue={quantity}
onFocus={selectAllOnFocus}
onPressEnter={(e) => void handleStoreCellSave(row, store.id, (e.target as HTMLInputElement).value)}
onBlur={(e) => void handleStoreCellSave(row, store.id, e.target.value)}
/>
@@ -1092,23 +1098,32 @@ const PurchaseOrderPage: React.FC = () => {
{
title: '实际成本',
dataIndex: 'actual_amount',
hideInTable: true,
hideInSearch: true,
valueType: "digit",
fieldProps: {
min: 0,
precision: 3,
placeholder: "请输入单价"
placeholder: "请输入单价",
onFocus: selectAllOnFocus,
},
align: 'center',
},
{
title: '账单总金额',
dataIndex: 'bill_total_amount',
hideInForm: true,
hideInSearch: true,
align: 'center',
render: (_, record) =>
Number(record.actual_amount) > 0 ? (
<Text strong>¥{record.actual_amount}</Text>
record.bill_total_amount != null ? (
<Text strong type="danger">¥{Number(record.bill_total_amount).toFixed(2)}</Text>
) : (
<Text type="secondary"></Text>
<Text type="secondary"></Text>
),
},
{
title: '应付商品金额',
title: '商品金额',
dataIndex: 'bill_product_amount',
hideInForm: true,
hideInSearch: true,
@@ -1132,7 +1147,10 @@ const PurchaseOrderPage: React.FC = () => {
dataIndex: 'remark',
valueType: "textarea",
hideInTable: true,
hideInSearch: true
hideInSearch: true,
fieldProps: {
onFocus: selectAllOnFocus,
},
},
{
title: '总重量',
@@ -1528,6 +1546,7 @@ const PurchaseOrderPage: React.FC = () => {
precision={2}
disabled={billed}
placeholder="配送费"
onFocus={selectAllOnFocus}
/>
</Form.Item>
<Form.Item
@@ -1540,6 +1559,7 @@ const PurchaseOrderPage: React.FC = () => {
precision={0}
disabled={billed}
placeholder="正压负回"
onFocus={selectAllOnFocus}
/>
</Form.Item>
<Form.Item
@@ -1552,6 +1572,7 @@ const PurchaseOrderPage: React.FC = () => {
precision={0}
disabled={billed}
placeholder="正压负回"
onFocus={selectAllOnFocus}
/>
</Form.Item>
<div className="w-50 shrink-0 px-1! flex justify-center">
@@ -1571,6 +1592,7 @@ const PurchaseOrderPage: React.FC = () => {
prefix={'¥'}
disabled={billed}
placeholder="可正负,计入总额"
onFocus={selectAllOnFocus}
/>
</Form.Item>
</Space.Compact>
@@ -1584,6 +1606,7 @@ const PurchaseOrderPage: React.FC = () => {
maxLength={255}
disabled={billed}
placeholder="备注(可选)"
onFocus={selectAllOnFocus}
/>
</Form.Item>
<div className="w-28 shrink-0 text-center">
@@ -1641,10 +1664,10 @@ const PurchaseOrderPage: React.FC = () => {
name="quantity"
rules={[{ required: true, message: '请输入采购数量' }]}
>
<InputNumber className="w-full" min={1} precision={0} placeholder="请输入采购数量(包数)" />
<InputNumber className="w-full" min={1} precision={0} placeholder="请输入采购数量(包数)" onFocus={selectAllOnFocus} />
</Form.Item>
<Form.Item label="称重(斤,可选)" name="weight">
<InputNumber className="w-full" min={0} precision={3} placeholder="请输入称重" />
<InputNumber className="w-full" min={0} precision={3} placeholder="请输入称重" onFocus={selectAllOnFocus} />
</Form.Item>
</Form>
</Modal>
@@ -1668,17 +1691,17 @@ const PurchaseOrderPage: React.FC = () => {
name="price"
rules={[{ required: true, message: '请输入单价' }]}
>
<InputNumber className="w-full" min={0} precision={2} placeholder="请输入单价" />
<InputNumber className="w-full" min={0} precision={2} placeholder="请输入单价" onFocus={selectAllOnFocus} />
</Form.Item>
<Form.Item
label="采购数量"
name="quantity"
rules={[{ required: true, message: '请输入采购数量' }]}
>
<InputNumber className="w-full" min={0} precision={0} placeholder="请输入采购数量" />
<InputNumber className="w-full" min={0} precision={0} placeholder="请输入采购数量" onFocus={selectAllOnFocus} />
</Form.Item>
<Form.Item label="称重(斤)" name="weight" rules={[{ required: true, message: '请输入称重' }]}>
<InputNumber className="w-full" min={0} precision={3} placeholder="请输入称重" />
<InputNumber className="w-full" min={0} precision={3} placeholder="请输入称重" onFocus={selectAllOnFocus} />
</Form.Item>
</Form>
</Modal>