Repository navigation
Conversation
背景:EasytierClient(172 个 Form.Item)、FrpClient(140 个)等页面中,
大量 Form.Item 是「<Col><Form.Item name label extra rules><Input/></Form.Item></Col>」
的复制粘贴,仅控件类型与文案不同。
新增两个共享组件:
- components/SectionTitle.tsx
此前该组件在 9 个页面各有一份逐字副本(仅缩进风格不同),
本次收敛为单一实现,样式与 UI 完全不变
- components/ConfigFields.tsx
- FieldRow:按字段声明渲染栅格行,支持
text/password/textarea/number/select/switch/checkbox
- CheckboxGrid:布尔开关网格,对应 EasytierClient 中
22 处重复的「Col + valuePropName=checked + marginBottom:4」结构
- 保留 escape hatch:children 字段透传自定义内容,
供 Form.List、条件渲染等无法声明式表达的字段使用
- when 字段支持 Form.useWatch 联动显隐
迁移与去重:
- EasytierClient:1259 → 1078 行(-181),6 个 Tab 的配置区改为声明式;
日志级别选项提为 LOG_LEVEL_OPTIONS,消除 2 处 6 行重复
- FrpClient:1211 → 1039 行(-172),主配置与连接设置两 Tab 改为声明式;
连接协议/认证方式/日志级别选项提为模块常量
- 其余 7 个页面替换为共享 SectionTitle
合计:+259 / -666,净减 407 行。
EasytierClient + FrpClient 两个目标文件合计 2470 → 2117 行(-14%)。
未达 issue 中「各砍一半」的预估——因为带业务逻辑的字段
(Form.List、联动显隐、自定义 addonAfter)不适合声明式,强行抽象会
损害可读性。按 issue「以删重复为准,不追求固定百分比」处理。
验收:tsc --noEmit 通过;npm run build 通过,产物 chunk 大小无异常。
(issue PIKACHUIM#124 PR-5)
This was referenced Sep 30, 2026
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
issue #124 PR-5。EasytierClient(172 个
Form.Item)、FrpClient(140 个)等页面里,大量Form.Item形如:只是控件类型与文案不同,属于复制粘贴式样板。
变更
新增 `components/SectionTitle.tsx
该组件此前在 9 个页面各有一份逐字副本,仅缩进风格不同(两种变体各若干份)。本 PR 收敛为单一实现,样式与 UI 完全不变。
新增
components/ConfigFields.tsxFieldRow— 按字段声明渲染栅格行,支持text/password/textarea/number/select/switch/checkboxCheckboxGrid— 布尔开关网格,对应 EasytierClient 中 22 处重复的Col + valuePropName="checked" + marginBottom:4结构children字段透传自定义内容,供Form.List、条件渲染等无法声明式表达的字段使用;不强行抽象when字段支持Form.useWatch联动显隐渲染结构与手写 JSX 完全一致(同样的
Row/Col/Form.Item层级),UI 零变化。迁移与去重
EasytierClient.tsxLOG_LEVEL_OPTIONS,消除 2 处 6 行重复FrpClient.tsxSectionTitle合计 +259 / -666,净减 407 行。两个目标文件合计 2470 → 2117 行(-14%)。
关于「各砍一半」预估的偏离
issue 原文预估两个文件各砍约一半。实际只减 14%,原因是:
带业务逻辑的字段不适合声明式化——包括
Form.List(端口转发规则、地址列表)、联动显隐、自定义addonAfter(私钥生成按钮)、跨字段校验。强行把这些塞进FieldSpec会让声明变成「一半是对象、一半是 JSX」的更差形态,损害可读性。按 issue「明确不做」中的「不追求固定百分比缩减指标,以删重复为准」处理,只迁移了真正同构的部分。
验收
tsc --noEmit通过npm run build通过,产物 chunk 大小无异常.gitignore中,未纳入提交EasytierClient.tsx中 3 个未使用的 import(Divider/parseAddrStr/randomStr)为上游既有,--noUnusedLocals下改动前后均报,未在本 PR 处理。后续
ConfigFields是纯展示组件,FieldSpec可直接复用到EasytierServer(132 个 Form.Item)、NpsServer(134 个)、FrpServer(82 个)。建议后续 PR 按同一模式推进。