feat(codegen): 默认生成 CRUD 页面并限制不适用的查询方式

生成配置默认页面类型改为 crud,普通页面标注为兼容选项
IN 查询不适用于 byte[],BETWEEN 不适用于 Boolean 与 byte[]
This commit is contained in:
Ray.Hao
2026-11-04 11:22:08 +08:00
parent 93b18090f4
commit 7cfcba3635
6 changed files with 24 additions and 12 deletions

View File

@@ -109,13 +109,13 @@
<el-col :span="12">
<el-form-item label="页面类型">
<el-radio-group v-model="formData.pageType">
<el-radio-button value="classic">
<el-icon><DocumentChecked /></el-icon>
普通
</el-radio-button>
<el-radio-button value="crud">
<el-icon><SetUp /></el-icon>
封装(CRUD)
封装 CRUD(推荐)
</el-radio-button>
<el-radio-button value="classic">
<el-icon><DocumentChecked /></el-icon>
普通(兼容)
</el-radio-button>
</el-radio-group>
</el-form-item>

View File

@@ -131,6 +131,7 @@
:key="key"
:label="item.label"
:value="item.value"
:disabled="isQueryTypeDisabled(row, key)"
/>
</el-select>
</div>
@@ -212,9 +213,20 @@ const props = defineProps<{
aiChanges?: Record<string, AiChangeItem[]>;
}>();
type FieldConfig = NonNullable<GenConfigForm["fieldConfigs"]>[number];
const formTypeOptions: Record<string, OptionItem> = FormTypeEnum;
const queryTypeOptions: Record<string, OptionItem> = QueryTypeEnum;
/**
* 判断查询方式是否适用于字段类型
*/
function isQueryTypeDisabled(row: FieldConfig, key: string): boolean {
if (key === "IN") return row.fieldType === "byte[]";
if (key === "BETWEEN") return row.fieldType === "Boolean" || row.fieldType === "byte[]";
return false;
}
const listRef = ref<HTMLElement>();
const sortFlag = ref<Sortable | null>(null);

View File

@@ -387,7 +387,7 @@ async function handleAiFill() {
snapshotConfig(genConfigFormData.value);
const filled = await GeneratorAPI.aiFillConfig(currentTableName.value);
// 接口按表结构重建配置,页面类型等非字段项可能为空,沿用当前选择再补默认
filled.pageType = filled.pageType || genConfigFormData.value.pageType || "classic";
filled.pageType = filled.pageType || genConfigFormData.value.pageType || "crud";
const diff = resolveDiff(filled);
genConfigFormData.value = applyDefaults(filled);
if (diff.changeCount === 0) {
@@ -484,7 +484,7 @@ async function handleNext() {
}
if (currentStep.value === STEP.PREVIEW) {
const pageType = genConfigFormData.value.pageType || "classic";
const pageType = genConfigFormData.value.pageType || "crud";
await GeneratorAPI.download(currentTableName.value, pageType as "classic" | "crud", "ts");
}
}

View File

@@ -228,7 +228,7 @@ const fileCount = computed(() => {
* 下载生成的代码
*/
function handleDownload() {
const pageType = props.genConfigFormData.pageType || "classic";
const pageType = props.genConfigFormData.pageType || "crud";
return GeneratorAPI.download(props.tableName, pageType as "classic" | "crud", "ts");
}

View File

@@ -37,7 +37,7 @@ export function useCodePreview(genConfigFormData: Ref<GenConfigForm>) {
*/
async function handlePreview(tableName: string) {
treeData.value = [];
const pageType = genConfigFormData.value.pageType || "classic";
const pageType = genConfigFormData.value.pageType || "crud";
const data = await GeneratorAPI.getPreviewData(tableName, pageType as "classic" | "crud", "ts");
const previewList = data || [];

View File

@@ -11,7 +11,7 @@ import type { OptionItem } from "@/api/common";
export function useGenConfig() {
const genConfigFormData = ref<GenConfigForm>({
fieldConfigs: [],
pageType: "classic",
pageType: "crud",
});
const genConfigFormRules = {
@@ -63,11 +63,11 @@ export function useGenConfig() {
);
/**
* 未保存过的表页面类型为空,统一补成普通表单
* 未保存过的表页面类型为空,统一补成 CrudPage 页面
*/
function applyDefaults(config: GenConfigForm): GenConfigForm {
if (!config.pageType) {
config.pageType = "classic";
config.pageType = "crud";
}
return config;
}