GenInfoForm.vue
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<script setup lang="ts">
import { onMounted, PropType, reactive, ref, watch } from 'vue'
import { required } from '@/utils/formRules'
import { Form } from '@/components/Form'
import { handleTree } from '@/utils/tree'
import { ElTreeSelect } from 'element-plus'
import { useForm } from '@/hooks/web/useForm'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { listSimpleMenusApi } from '@/api/system/menu'
import { CodegenTableVO } from '@/api/infra/codegen/types'
import { FormSchema } from '@/types/form'
const props = defineProps({
genInfo: {
type: Object as PropType<Nullable<CodegenTableVO>>,
default: () => null
}
})
const menuProps = {
checkStrictly: true,
children: 'children',
label: 'name',
value: 'id'
}
const rules = reactive({
templateType: [required],
scene: [required],
moduleName: [required],
businessName: [required],
businessPackage: [required],
className: [required],
classComment: [required]
})
const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
const treeRef = ref<InstanceType<typeof ElTreeSelect>>()
const menuOptions = ref<any>([]) // 树形结构
const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
const schema = reactive<FormSchema[]>([
{
label: '生成模板',
field: 'templateType',
component: 'Select',
componentProps: {
options: templateTypeOptions
},
colProps: {
span: 12
}
},
{
label: '生成场景',
field: 'scene',
component: 'Select',
componentProps: {
options: sceneOptions
},
colProps: {
span: 12
}
},
{
label: '模块名',
field: 'moduleName',
component: 'Input',
labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
colProps: {
span: 12
}
},
{
label: '业务名',
field: 'businessName',
component: 'Input',
labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
colProps: {
span: 12
}
},
{
label: '类名称',
field: 'className',
component: 'Input',
labelMessage: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等',
colProps: {
span: 12
}
},
{
label: '类描述',
field: 'classComment',
component: 'Input',
labelMessage: '用作类描述,例如 用户',
colProps: {
span: 12
}
},
{
label: '上级菜单',
field: 'parentMenuId',
componentProps: {
optionsSlot: true
},
labelMessage: '分配到指定菜单下,例如 系统管理',
colProps: {
span: 12
}
}
])
const { register, methods, elFormRef } = useForm({
schema
})
const parentMenuId = ref<number>()
//子组件像父组件传值
const emit = defineEmits(['menu'])
const handleNodeClick = () => {
emit('menu', parentMenuId.value)
}
// ========== 初始化 ==========
onMounted(async () => {
await getTree()
})
watch(
() => props.genInfo,
(genInfo) => {
if (!genInfo) return
const { setValues } = methods
setValues(genInfo)
},
{
deep: true,
immediate: true
}
)
defineExpose({
elFormRef,
getFormData: methods.getFormData
})
</script>
<template>
<Form :rules="rules" @register="register">
<template #parentMenuId>
<el-tree-select
v-model="parentMenuId"
ref="treeRef"
node-key="id"
:props="menuProps"
:data="menuOptions"
check-strictly
@node-click="handleNodeClick"
/>
</template>
</Form>
</template>