# 工序字段配置指南

## 1. 基本结构

工序字段配置采用 JSON 格式，每个字段都是一个键值对，其中：

- 键（key）：字段的唯一标识符，建议使用驼峰命名法
- 值（value）：字段的配置对象，包含该字段的所有属性

基本结构示例：

```json
{
  "fieldName": {
    "type": "string",
    "label": "字段中文名",
    "order": 1,
    ...
  }
}
```

## 2. 字段通用属性

每个字段都支持以下通用属性：

| 属性名 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| type | string | 是 | 字段类型，支持 "string"、"number"、"select" | "type": "string" |
| label | string | 是 | 字段的显示名称（中文） | "label": "焊接方法" |
| order | number | 否 | 显示顺序，数字越小越靠前 | "order": 1 |
| editable | boolean | 是 | 是否可编辑 | "editable": true |
| required | boolean | 否 | 是否必填 | "required": true |
| showInTable | boolean | 否 | 是否在主表格中显示 | "showInTable": true |
| placeholder | string | 否 | 输入框占位文本 | "placeholder": "请输入焊接方法" |

## 3. 字段类型特有属性

### 3.1 字符串类型 (string)

```json
{
  "weldingMethod": {
    "type": "string",
    "label": "焊接方法",
    "order": 1,
    "editable": true,
    "required": true
  }
}
```

### 3.2 数字类型 (number)

数字类型特有属性：

| 属性名 | 类型   | 必填 | 说明     | 示例         |
| ------ | ------ | ---- | -------- | ------------ |
| unit   | string | 否   | 单位     | "unit": "°C" |
| rules  | object | 否   | 数值规则 | 见下方示例   |

rules 对象包含：

- min: 最小值
- max: 最大值
- step: 步进值

示例：

```json
{
  "temperature": {
    "type": "number",
    "label": "温度",
    "unit": "°C",
    "rules": {
      "min": 0,
      "max": 1000,
      "step": 0.1
    },
    "required": true
  }
}
```

### 3.3 选择器类型 (select)

选择器类型特有属性：

| 属性名   | 类型    | 必填 | 说明         | 示例             |
| -------- | ------- | ---- | ------------ | ---------------- |
| options  | array   | 是   | 选项列表     | 见下方示例       |
| multiple | boolean | 否   | 是否支持多选 | "multiple": true |

options 数组中的每个选项包含：

- label: 选项显示文本
- value: 选项值

示例：

```json
{
  "inspectionResult": {
    "type": "select",
    "label": "检验结果",
    "options": [
      { "label": "合格", "value": "合格" },
      { "label": "不合格", "value": "不合格" }
    ],
    "multiple": false,
    "required": true
  }
}
```

## 4. 完整示例

### 4.1 焊接工序配置示例

```json
{
  "weldingMethod": {
    "type": "string",
    "label": "焊接方法",
    "order": 2,
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "weldingTemperature": {
    "type": "number",
    "label": "焊接温度",
    "order": 1,
    "unit": "°C",
    "rules": {
      "max": 1000,
      "min": 0,
      "step": 0.1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "inspectionResult": {
    "type": "select",
    "label": "检验结果",
    "order": 3,
    "options": [
      { "label": "合格", "value": "合格" },
      { "label": "不合格", "value": "不合格" }
    ],
    "editable": true,
    "required": true,
    "showInTable": true
  }
}
```

### 4.2 装配工序配置示例

```json
{
  "assemblyParts": {
    "type": "select",
    "label": "装配零件",
    "order": 1,
    "options": [
      { "label": "轴承", "value": "轴承" },
      { "label": "轴套", "value": "轴套" },
      { "label": "螺栓", "value": "螺栓" }
    ],
    "multiple": true,
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "gapValue": {
    "type": "number",
    "label": "间隙值",
    "order": 2,
    "unit": "mm",
    "rules": {
      "max": 1,
      "min": 0,
      "step": 0.01
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "alignmentError": {
    "type": "number",
    "label": "对中误差",
    "order": 3,
    "unit": "mm",
    "rules": {
      "max": 0.1,
      "min": 0,
      "step": 0.001
    },
    "editable": true,
    "required": true,
    "showInTable": true
  }
}
```

### 4.3 番茄酱生产工序配置示例

```json
{
  "rawMaterialBatch": {
    "type": "string",
    "label": "原料批次号",
    "order": 1,
    "editable": true,
    "required": true,
    "showInTable": true,
    "placeholder": "请输入原料批次号"
  },
  "cookingTemperature": {
    "type": "number",
    "label": "加热温度",
    "order": 2,
    "unit": "°C",
    "rules": {
      "max": 120,
      "min": 60,
      "step": 1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "cookingTime": {
    "type": "number",
    "label": "加热时间",
    "order": 3,
    "unit": "min",
    "rules": {
      "max": 120,
      "min": 30,
      "step": 5
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "seasonings": {
    "type": "select",
    "label": "调味料",
    "order": 4,
    "options": [
      { "label": "食用盐", "value": "salt" },
      { "label": "白砂糖", "value": "sugar" },
      { "label": "白胡椒粉", "value": "pepper" },
      { "label": "香辛料", "value": "spices" }
    ],
    "multiple": true,
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "consistency": {
    "type": "select",
    "label": "稠度检测",
    "order": 5,
    "options": [
      { "label": "合格", "value": "qualified" },
      { "label": "过稀", "value": "thin" },
      { "label": "过稠", "value": "thick" }
    ],
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "ph": {
    "type": "number",
    "label": "pH值",
    "order": 6,
    "rules": {
      "max": 7,
      "min": 3,
      "step": 0.1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  }
}
```

### 4.4 甜菊糖生产工序配置示例

```json
{
  "extractionTemperature": {
    "type": "number",
    "label": "提取温度",
    "order": 1,
    "unit": "°C",
    "rules": {
      "max": 80,
      "min": 40,
      "step": 1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "extractionTime": {
    "type": "number",
    "label": "提取时间",
    "order": 2,
    "unit": "min",
    "rules": {
      "max": 180,
      "min": 60,
      "step": 5
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "solventType": {
    "type": "select",
    "label": "溶剂类型",
    "order": 3,
    "options": [
      { "label": "纯净水", "value": "water" },
      { "label": "乙醇", "value": "ethanol" },
      { "label": "混合溶剂", "value": "mixed" }
    ],
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "solventConcentration": {
    "type": "number",
    "label": "溶剂浓度",
    "order": 4,
    "unit": "%",
    "rules": {
      "max": 100,
      "min": 0,
      "step": 1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "purityTest": {
    "type": "number",
    "label": "纯度检测",
    "order": 5,
    "unit": "%",
    "rules": {
      "max": 100,
      "min": 90,
      "step": 0.1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "crystalForm": {
    "type": "select",
    "label": "结晶形态",
    "order": 6,
    "options": [
      { "label": "针状", "value": "needle" },
      { "label": "片状", "value": "flake" },
      { "label": "粒状", "value": "granular" }
    ],
    "editable": true,
    "required": true,
    "showInTable": true
  },
  "moistureContent": {
    "type": "number",
    "label": "水分含量",
    "order": 7,
    "unit": "%",
    "rules": {
      "max": 10,
      "min": 0,
      "step": 0.1
    },
    "editable": true,
    "required": true,
    "showInTable": true
  }
}
```

## 5. 注意事项

1. 字段命名规范：

   - 使用驼峰命名法
   - 避免使用特殊字符
   - 建议使用英文

2. 数值类型注意事项：

   - 必须设置合理的最大值和最小值
   - step 建议根据精度需求设置
   - 单位使用通用符号，如 °C、mm、MPa 等

3. 选择器类型注意事项：

   - options 中的 value 建议使用简单的字符串或数字
   - 多选时注意设置 multiple: true
   - 选项建议不要太多，否则影响用户体验

4. 显示规则：

   - order 值越小越靠前显示
   - showInTable 为 true 的字段会显示在主表格中
   - 建议重要字段设置 showInTable: true

5. 编辑权限：

   - editable 为 false 的字段用户无法修改
   - 关键参数建议设置 editable: false
   - required 为 true 的字段必须填写

6. 字段数量：
   - 建议每个工序的字段数量控制在 10 个以内
   - 必填字段不要太多，影响操作效率
