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

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

No files matched your search

@@ -109,13 +109,13 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item label="页面类型"> <el-form-item label="页面类型">
<el-radio-group v-model="formData.pageType"> <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-radio-button value="crud">
<el-icon><SetUp /></el-icon> <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-button>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
@@ -131,6 +131,7 @@
:key="key" :key="key"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
:disabled="isQueryTypeDisabled(row, key)"
/> />
</el-select> </el-select>
</div> </div>
@@ -212,9 +213,20 @@ const props = defineProps<{
aiChanges?: Record<string, AiChangeItem[]>; aiChanges?: Record<string, AiChangeItem[]>;
}>(); }>();
type FieldConfig = NonNullable<GenConfigForm["fieldConfigs"]>[number];
const formTypeOptions: Record<string, OptionItem> = FormTypeEnum; const formTypeOptions: Record<string, OptionItem> = FormTypeEnum;
const queryTypeOptions: Record<string, OptionItem> = QueryTypeEnum; 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 listRef = ref<HTMLElement>();
const sortFlag = ref<Sortable | null>(null); const sortFlag = ref<Sortable | null>(null);
@@ -387,7 +387,7 @@ async function handleAiFill() {
snapshotConfig(genConfigFormData.value); snapshotConfig(genConfigFormData.value);
const filled = await GeneratorAPI.aiFillConfig(currentTableName.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); const diff = resolveDiff(filled);
genConfigFormData.value = applyDefaults(filled); genConfigFormData.value = applyDefaults(filled);
if (diff.changeCount === 0) { if (diff.changeCount === 0) {
@@ -484,7 +484,7 @@ async function handleNext() {
} }
if (currentStep.value === STEP.PREVIEW) { 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"); await GeneratorAPI.download(currentTableName.value, pageType as "classic" | "crud", "ts");
} }
} }
+1 -1
View File
@@ -228,7 +228,7 @@ const fileCount = computed(() => {
* 下载生成的代码 * 下载生成的代码
*/ */
function handleDownload() { function handleDownload() {
const pageType = props.genConfigFormData.pageType || "classic"; const pageType = props.genConfigFormData.pageType || "crud";
return GeneratorAPI.download(props.tableName, pageType as "classic" | "crud", "ts"); return GeneratorAPI.download(props.tableName, pageType as "classic" | "crud", "ts");
} }
@@ -37,7 +37,7 @@ export function useCodePreview(genConfigFormData: Ref<GenConfigForm>) {
*/ */
async function handlePreview(tableName: string) { async function handlePreview(tableName: string) {
treeData.value = []; 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 data = await GeneratorAPI.getPreviewData(tableName, pageType as "classic" | "crud", "ts");
const previewList = data || []; const previewList = data || [];
@@ -11,7 +11,7 @@ import type { OptionItem } from "@/api/common";
export function useGenConfig() { export function useGenConfig() {
const genConfigFormData = ref<GenConfigForm>({ const genConfigFormData = ref<GenConfigForm>({
fieldConfigs: [], fieldConfigs: [],
pageType: "classic", pageType: "crud",
}); });
const genConfigFormRules = { const genConfigFormRules = {
@@ -63,11 +63,11 @@ export function useGenConfig() {
); );
/** /**
* 未保存过的表页面类型为空,统一补成普通表单 * 未保存过的表页面类型为空,统一补成 CrudPage 页面
*/ */
function applyDefaults(config: GenConfigForm): GenConfigForm { function applyDefaults(config: GenConfigForm): GenConfigForm {
if (!config.pageType) { if (!config.pageType) {
config.pageType = "classic"; config.pageType = "crud";
} }
return config; return config;
} }