refactor: 代码生成配置页面重构 去除步骤条
This commit is contained in:
parent
233817c2ed
commit
ac9e76ae93
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- 菜单选择组件重构为Table形式
|
- 菜单选择组件重构为Table形式
|
||||||
- 字典相关功能重构 采用一个Map储存字典(之前为两个Map)
|
- 字典相关功能重构 采用一个Map储存字典(之前为两个Map)
|
||||||
|
- 代码生成配置页面重构 去除步骤条
|
||||||
|
|
||||||
**Features**
|
**Features**
|
||||||
|
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { GenInfo } from '#/api/tool/gen/model';
|
import type { GenInfo } from '#/api/tool/gen/model';
|
||||||
|
|
||||||
import { onMounted, provide, ref } from 'vue';
|
import { onMounted, provide, ref, unref, useTemplateRef } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { useTabs } from '@vben/hooks';
|
import { useTabs } from '@vben/hooks';
|
||||||
import { safeParseNumber } from '@vben/utils';
|
import { cloneDeep, safeParseNumber } from '@vben/utils';
|
||||||
|
|
||||||
import { Skeleton, Step, Steps } from 'ant-design-vue';
|
import { Card, Skeleton, TabPane, Tabs } from 'ant-design-vue';
|
||||||
|
|
||||||
import { genInfo } from '#/api/tool/gen';
|
import { editSave, genInfo } from '#/api/tool/gen';
|
||||||
|
|
||||||
import { BasicSetting, GenConfig, GenSuccess } from './edit-steps';
|
import { BasicSetting, GenConfig } from './edit-steps';
|
||||||
import { emitter } from './mitt';
|
|
||||||
|
|
||||||
const current = ref(0);
|
const { setTabTitle, closeCurrentTab } = useTabs();
|
||||||
|
|
||||||
const { setTabTitle } = useTabs();
|
|
||||||
const routes = useRoute();
|
const routes = useRoute();
|
||||||
// 获取路由参数
|
// 获取路由参数
|
||||||
const tableId = routes.params.tableId as string;
|
const tableId = routes.params.tableId as string;
|
||||||
@ -34,29 +31,89 @@ onMounted(async () => {
|
|||||||
setTabTitle(`生成配置: ${resp.info.tableName}`);
|
setTabTitle(`生成配置: ${resp.info.tableName}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
const currentTab = ref<'fields' | 'setting'>('setting');
|
||||||
* 事件总线 监听切换步骤
|
const basicSettingRef = useTemplateRef('basicSettingRef');
|
||||||
*/
|
const genConfigRef = useTemplateRef('genConfigRef');
|
||||||
emitter.on('to', (step: number) => {
|
|
||||||
current.value = step;
|
const router = useRouter();
|
||||||
});
|
async function handleSave() {
|
||||||
|
try {
|
||||||
|
// 校验tab1
|
||||||
|
const settingValidate = await basicSettingRef.value?.validateForm();
|
||||||
|
if (!settingValidate) {
|
||||||
|
currentTab.value = 'setting';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验tab2
|
||||||
|
const genConfigValidate = await genConfigRef.value?.validateTable();
|
||||||
|
if (!genConfigValidate) {
|
||||||
|
currentTab.value = 'fields';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const requestData = cloneDeep(unref(genInfoData)!);
|
||||||
|
// 获取表单数据
|
||||||
|
const formValues = await basicSettingRef.value?.getFormValues();
|
||||||
|
// 合并
|
||||||
|
Object.assign(requestData, formValues);
|
||||||
|
// 从表格获取最新的
|
||||||
|
requestData.columns = genConfigRef.value?.getTableRecords() ?? [];
|
||||||
|
// 树表需要添加这个参数
|
||||||
|
if (requestData && requestData.tplCategory === 'tree') {
|
||||||
|
const { treeCode, treeName, treeParentCode } = requestData;
|
||||||
|
requestData.params = {
|
||||||
|
treeCode,
|
||||||
|
treeName,
|
||||||
|
treeParentCode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// 需要进行参数转化
|
||||||
|
if (requestData) {
|
||||||
|
const transform = (ret: boolean) => (ret ? '1' : '0');
|
||||||
|
requestData.columns.forEach((column) => {
|
||||||
|
const { edit, insert, query, required, list } = column;
|
||||||
|
column.isInsert = transform(insert);
|
||||||
|
column.isEdit = transform(edit);
|
||||||
|
column.isList = transform(list);
|
||||||
|
column.isQuery = transform(query);
|
||||||
|
column.isRequired = transform(required);
|
||||||
|
});
|
||||||
|
// 需要手动添加父级菜单 弹窗类型
|
||||||
|
requestData.params = {
|
||||||
|
...requestData.params,
|
||||||
|
parentMenuId: requestData.parentMenuId,
|
||||||
|
popupComponent: requestData.popupComponent,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// 保存
|
||||||
|
await editSave(requestData);
|
||||||
|
// 关闭 & 跳转
|
||||||
|
await closeCurrentTab();
|
||||||
|
router.push({ path: '/tool/gen', replace: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page content-class="bg-background p-5 rounded-lg">
|
<Page :auto-content-height="true">
|
||||||
<div class="flex items-center justify-center">
|
<Card
|
||||||
<Steps :current="current" class="w-fit">
|
class="h-full"
|
||||||
<Step title="生成信息" />
|
v-if="genInfoData"
|
||||||
<Step disabled title="字段信息" />
|
:body-style="{ padding: '0 16px 16px' }"
|
||||||
<Step disabled title="完成" />
|
>
|
||||||
</Steps>
|
<Tabs v-model:active-key="currentTab" size="middle">
|
||||||
</div>
|
<template #rightExtra>
|
||||||
<!-- content -->
|
<a-button type="primary" @click="handleSave">保存配置</a-button>
|
||||||
<div v-if="genInfoData">
|
</template>
|
||||||
<BasicSetting v-if="current === 0" />
|
<TabPane key="setting" tab="生成信息" :force-render="true">
|
||||||
<GenConfig v-if="current === 1" />
|
<BasicSetting ref="basicSettingRef" />
|
||||||
<GenSuccess v-if="current === 2" />
|
</TabPane>
|
||||||
</div>
|
<TabPane key="fields" tab="字段信息" :force-render="true">
|
||||||
|
<GenConfig ref="genConfigRef" />
|
||||||
|
</TabPane>
|
||||||
|
</Tabs>
|
||||||
|
</Card>
|
||||||
<Skeleton v-else :active="true" />
|
<Skeleton v-else :active="true" />
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
@ -13,7 +13,6 @@ import { Col, Row } from 'ant-design-vue';
|
|||||||
|
|
||||||
import { menuList } from '#/api/system/menu';
|
import { menuList } from '#/api/system/menu';
|
||||||
|
|
||||||
import { toCurrentStep } from '../mitt';
|
|
||||||
import { formSchema } from './basic';
|
import { formSchema } from './basic';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,28 +117,34 @@ onMounted(async () => {
|
|||||||
await Promise.all([initTreeSelect(info.columns), initMenuSelect()]);
|
await Promise.all([initTreeSelect(info.columns), initMenuSelect()]);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleNext() {
|
/**
|
||||||
try {
|
* 校验表单
|
||||||
|
*/
|
||||||
|
async function validateForm() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return null;
|
return false;
|
||||||
}
|
|
||||||
const data = await formApi.getValues();
|
|
||||||
Object.assign(genInfoData.value, data);
|
|
||||||
toCurrentStep(1);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单值
|
||||||
|
*/
|
||||||
|
async function getFormValues() {
|
||||||
|
return await formApi.getValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
validateForm,
|
||||||
|
getFormValues,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Row justify="center">
|
<Row justify="center">
|
||||||
<Col v-bind="{ xs: 24, sm: 24, md: 20, lg: 16, xl: 16 }">
|
<Col v-bind="{ xs: 24, sm: 24, md: 20, lg: 16, xl: 16 }">
|
||||||
<BasicForm />
|
<BasicForm />
|
||||||
<div class="flex justify-center">
|
|
||||||
<a-button type="primary" @click="handleNext">下一步</a-button>
|
|
||||||
</div>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</template>
|
</template>
|
||||||
|
@ -4,15 +4,10 @@ import type { Ref } from 'vue';
|
|||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||||
import type { GenInfo } from '#/api/tool/gen/model';
|
import type { GenInfo } from '#/api/tool/gen/model';
|
||||||
|
|
||||||
import { inject, unref } from 'vue';
|
import { inject } from 'vue';
|
||||||
|
|
||||||
import { message, Space } from 'ant-design-vue';
|
|
||||||
import { cloneDeep } from 'lodash-es';
|
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { editSave } from '#/api/tool/gen';
|
|
||||||
|
|
||||||
import { toCurrentStep } from '../mitt';
|
|
||||||
import { validRules, vxeTableColumns } from './gen-data';
|
import { validRules, vxeTableColumns } from './gen-data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,9 +31,7 @@ const gridOptions: VxeGridProps = {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: false,
|
enabled: false,
|
||||||
zoom: false,
|
|
||||||
custom: false,
|
|
||||||
},
|
},
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
pagerConfig: {
|
pagerConfig: {
|
||||||
@ -49,62 +42,31 @@ const gridOptions: VxeGridProps = {
|
|||||||
|
|
||||||
const [BasicTable, tableApi] = useVbenVxeGrid({ gridOptions });
|
const [BasicTable, tableApi] = useVbenVxeGrid({ gridOptions });
|
||||||
|
|
||||||
async function handleSubmit() {
|
/**
|
||||||
try {
|
* 校验表格数据
|
||||||
|
*/
|
||||||
|
async function validateTable() {
|
||||||
const hasError = await tableApi.grid.validate();
|
const hasError = await tableApi.grid.validate();
|
||||||
if (hasError) {
|
return !hasError;
|
||||||
message.error('校验未通过');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const requestData = cloneDeep(unref(genInfoData));
|
|
||||||
// 从表格获取最新的
|
|
||||||
requestData.columns = tableApi.grid.getData();
|
|
||||||
// 树表需要添加这个参数
|
|
||||||
if (requestData && requestData.tplCategory === 'tree') {
|
|
||||||
const { treeCode, treeName, treeParentCode } = requestData;
|
|
||||||
requestData.params = {
|
|
||||||
treeCode,
|
|
||||||
treeName,
|
|
||||||
treeParentCode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// 需要进行参数转化
|
|
||||||
if (requestData) {
|
|
||||||
const transform = (ret: boolean) => (ret ? '1' : '0');
|
|
||||||
requestData.columns.forEach((column) => {
|
|
||||||
const { edit, insert, query, required, list } = column;
|
|
||||||
column.isInsert = transform(insert);
|
|
||||||
column.isEdit = transform(edit);
|
|
||||||
column.isList = transform(list);
|
|
||||||
column.isQuery = transform(query);
|
|
||||||
column.isRequired = transform(required);
|
|
||||||
});
|
|
||||||
// 需要手动添加父级菜单 弹窗类型
|
|
||||||
requestData.params = {
|
|
||||||
...requestData.params,
|
|
||||||
parentMenuId: requestData.parentMenuId,
|
|
||||||
popupComponent: requestData.popupComponent,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
await editSave(requestData);
|
|
||||||
// 跳转到成功页面
|
|
||||||
toCurrentStep(2);
|
|
||||||
} catch (error: unknown) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表格数据
|
||||||
|
*/
|
||||||
|
function getTableRecords() {
|
||||||
|
return tableApi?.grid?.getData?.() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
validateTable,
|
||||||
|
getTableRecords,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-[16px] p-[12px]">
|
<div class="flex flex-col gap-[16px]">
|
||||||
<div class="h-[calc(100vh-235px)] overflow-y-hidden">
|
<div class="h-[calc(100vh-200px)] overflow-y-hidden">
|
||||||
<BasicTable />
|
<BasicTable />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center">
|
|
||||||
<Space>
|
|
||||||
<a-button @click="toCurrentStep(0)">上一步</a-button>
|
|
||||||
<a-button type="primary" @click="handleSubmit">下一步</a-button>
|
|
||||||
</Space>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { useTabs } from '@vben/hooks';
|
|
||||||
|
|
||||||
import { Result } from 'ant-design-vue';
|
|
||||||
|
|
||||||
const { closeCurrentTab } = useTabs();
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
async function handleClose() {
|
|
||||||
await closeCurrentTab();
|
|
||||||
router.push({ path: '/tool/gen', replace: true });
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Result status="success" title="修改成功">
|
|
||||||
<template #extra>
|
|
||||||
<a-button type="primary" @click="handleClose"> 关闭 </a-button>
|
|
||||||
</template>
|
|
||||||
</Result>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
@ -1,3 +1,2 @@
|
|||||||
export { default as BasicSetting } from './basic-setting.vue';
|
export { default as BasicSetting } from './basic-setting.vue';
|
||||||
export { default as GenConfig } from './gen-config.vue';
|
export { default as GenConfig } from './gen-config.vue';
|
||||||
export { default as GenSuccess } from './gen-success.vue';
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
import { mitt } from '@vben/utils';
|
|
||||||
|
|
||||||
type Events = {
|
|
||||||
to: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const emitter = mitt<Events>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 跳转到指定步骤
|
|
||||||
* @param step 步骤
|
|
||||||
*/
|
|
||||||
export function toCurrentStep(step: number) {
|
|
||||||
emitter.emit('to', step);
|
|
||||||
}
|
|
@ -59,6 +59,7 @@ const gridOptions: VxeGridProps = {
|
|||||||
{
|
{
|
||||||
title: '表描述',
|
title: '表描述',
|
||||||
field: 'tableComment',
|
field: 'tableComment',
|
||||||
|
align: 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
@ -88,9 +89,7 @@ const gridOptions: VxeGridProps = {
|
|||||||
keyField: 'tableId',
|
keyField: 'tableId',
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: false,
|
enabled: false,
|
||||||
zoom: false,
|
|
||||||
custom: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user