109 lines
3.8 KiB
Markdown
109 lines
3.8 KiB
Markdown
|
|
# Hide Auto-Increment IDs in Create Forms Implementation Plan
|
||
|
|
|
||
|
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||
|
|
|
||
|
|
**Goal:** Hide generated auto-increment fields in create dialogs while showing them read-only in edit and view dialogs.
|
||
|
|
|
||
|
|
**Architecture:** Keep field metadata unchanged and implement visibility in the Qing Vue template with a runtime `v-if` keyed to the generated primary-key value. Add a template-rendering regression test so both frontend and admin-frontend generation inherit the behavior.
|
||
|
|
|
||
|
|
**Tech Stack:** Java 8, JUnit 4, Apache Velocity, Vue 2, Element UI, Maven
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Task 1: Template rendering behavior
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Modify: `ruoyi-generator/src/test/java/com/ruoyi/generator/util/QingTemplateSupportTest.java`
|
||
|
|
- Modify: `ruoyi-generator/src/main/resources/qing/index.vue.vm`
|
||
|
|
|
||
|
|
- [ ] **Step 1: Write the failing rendering test**
|
||
|
|
|
||
|
|
Add a test that renders `qing/index.vue.vm` for a table with:
|
||
|
|
|
||
|
|
```java
|
||
|
|
GenTableColumn id = column("id", "ID", "Long", "id", "1", "1", "1", "1", "EQ", "input");
|
||
|
|
GenTableColumn name = column("name", "Name", "String", "name", "0", "1", "1", "1", "LIKE", "input");
|
||
|
|
```
|
||
|
|
|
||
|
|
Assert the rendered template contains:
|
||
|
|
|
||
|
|
```java
|
||
|
|
assertTrue(rendered.contains("<el-form-item v-if=\"form.id\" label=\"ID\" prop=\"id\">"));
|
||
|
|
assertTrue(rendered.contains("<el-input v-model=\"form.id\" disabled"));
|
||
|
|
assertFalse(rendered.contains("prop=\"id\" :rules="));
|
||
|
|
assertTrue(rendered.contains("<el-form-item label=\"Name\" prop=\"name\""));
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run the focused test and verify RED**
|
||
|
|
|
||
|
|
Run:
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -pl ruoyi-generator -am "-Dtest=QingTemplateSupportTest#qingCrudFormHidesAutoIncrementIdOnCreateAndShowsItReadOnlyOnEdit" "-Dsurefire.failIfNoSpecifiedTests=false" test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: the new assertions fail because the generated ID field is unconditional, editable, and required.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Implement the minimal template condition**
|
||
|
|
|
||
|
|
In the form-field loop:
|
||
|
|
|
||
|
|
```velocity
|
||
|
|
#set($autoIncrementField = $column.isIncrement == "1")
|
||
|
|
<el-form-item#if($autoIncrementField) v-if="form.${pkColumn.javaField}"#end label="${columnComment}" prop="${javaField}"#if($column.isRequired == "1" && !$autoIncrementField) :rules="..."#end>
|
||
|
|
```
|
||
|
|
|
||
|
|
For input fields:
|
||
|
|
|
||
|
|
```velocity
|
||
|
|
<el-input v-model="form.${javaField}"#if($autoIncrementField) disabled#end placeholder="请输入${columnComment}" />
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 4: Run focused and related tests**
|
||
|
|
|
||
|
|
Run:
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -pl ruoyi-generator -am "-Dtest=QingTemplateSupportTest" "-Dsurefire.failIfNoSpecifiedTests=false" test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: all `QingTemplateSupportTest` tests pass.
|
||
|
|
|
||
|
|
- [ ] **Step 5: Verify generated output**
|
||
|
|
|
||
|
|
Render or regenerate project 106 and confirm the generated book form contains:
|
||
|
|
|
||
|
|
```vue
|
||
|
|
<el-form-item v-if="form.id" label="图书ID" prop="id">
|
||
|
|
<el-input v-model="form.id" disabled ... />
|
||
|
|
</el-form-item>
|
||
|
|
```
|
||
|
|
|
||
|
|
Open `http://127.0.0.1:20178/#/admin/books` and verify:
|
||
|
|
|
||
|
|
- clicking “新增” does not show ID;
|
||
|
|
- editing an existing record shows ID read-only;
|
||
|
|
- saving a new record still succeeds.
|
||
|
|
|
||
|
|
### Task 2: Final verification
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Verify: `ruoyi-generator/src/main/resources/qing/index.vue.vm`
|
||
|
|
- Verify: `ruoyi-generator/src/test/java/com/ruoyi/generator/util/QingTemplateSupportTest.java`
|
||
|
|
|
||
|
|
- [ ] **Step 1: Run regression tests**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -pl ruoyi-generator -am "-Dtest=QingTemplateSupportTest,FrontProjectServiceImplTest,MysqlDdlBuilderTest" "-Dsurefire.failIfNoSpecifiedTests=false" test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: zero failures and zero errors.
|
||
|
|
|
||
|
|
- [ ] **Step 2: Check the patch**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
git diff --check -- ruoyi-generator/src/main/resources/qing/index.vue.vm ruoyi-generator/src/test/java/com/ruoyi/generator/util/QingTemplateSupportTest.java
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: exit code 0.
|