ruoyi-plus-vben5/apps/web-antd/src/views/tool/gen/edit-steps/basic-setting.vue

134 lines
2.9 KiB
Vue
Raw Normal View History

2024-09-24 10:18:07 +08:00
<script setup lang="ts">
import type { Column, GenInfo } from '#/api/tool/gen/model';
import { inject, onMounted, type Ref } from 'vue';
import { useVbenForm } from '@vben/common-ui';
import { addFullName, listToTree } from '@vben/utils';
import { Col, Row } from 'ant-design-vue';
import { menuList } from '#/api/system/menu';
import { toCurrentStep } from '../mitt';
import { formSchema } from './basic';
/**
* 从父组件注入
*/
2024-09-26 11:35:16 +08:00
const genInfoData = inject('genInfoData') as Ref<GenInfo['info']>;
2024-09-24 10:18:07 +08:00
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
formItemClass: 'col-span-1',
},
labelWidth: 150,
},
schema: formSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
/**
* 树表需要用到的数据
*/
async function initTreeSelect(columns: Column[]) {
const options = columns.map((item) => {
const label = `${item.columnName} | ${item.columnComment}`;
return { label, value: item.columnName };
});
formApi.updateSchema([
{
componentProps: {
options,
},
fieldName: 'treeCode',
},
{
componentProps: {
options,
},
fieldName: 'treeParentCode',
},
{
componentProps: {
options,
},
fieldName: 'treeName',
},
]);
}
/**
* 加载菜单选择
*/
async function initMenuSelect() {
const list = await menuList();
const tree = listToTree(list, { id: 'menuId', pid: 'parentId' });
const treeData = [
{
fullName: '根目录',
menuId: 0,
menuName: '根目录',
children: tree,
},
];
addFullName(treeData, 'menuName', ' / ');
formApi.updateSchema([
{
componentProps: {
fieldNames: {
label: 'menuName',
value: 'menuId',
},
// 设置弹窗滚动高度 默认256
listHeight: 300,
treeData,
treeDefaultExpandAll: false,
// 默认展开的树节点
treeDefaultExpandedKeys: [0],
treeLine: { showLeafIcon: false },
treeNodeLabelProp: 'fullName',
},
fieldName: 'parentMenuId',
},
]);
}
onMounted(async () => {
2024-09-26 11:35:16 +08:00
const info = genInfoData.value;
2024-09-24 10:18:07 +08:00
for (const key in info) {
formApi.setFieldValue(key, info[key as keyof typeof info]);
}
await Promise.all([initTreeSelect(info.columns), initMenuSelect()]);
});
async function handleNext() {
try {
const { valid } = await formApi.validate();
if (!valid) {
return null;
}
const data = await formApi.getValues();
2024-09-26 11:35:16 +08:00
Object.assign(genInfoData.value, data);
2024-09-24 10:18:07 +08:00
toCurrentStep(1);
} catch (error) {
console.error(error);
}
}
</script>
<template>
<Row justify="center">
<Col v-bind="{ xs: 24, sm: 24, md: 20, lg: 16, xl: 16 }">
<BasicForm />
<div class="flex justify-center">
<a-button type="primary" @click="handleNext">下一步</a-button>
</div>
</Col>
</Row>
</template>