houzhongjian
2024-07-11 759b1c71011abd6b58c37d2566f3f3c208c2f1b2
提交 | 用户 | 时间
759b1c 1 <template>
H 2   <el-form ref="genInfoForm" :model="formData" :rules="rules" label-width="150px">
3     <el-row>
4       <el-col :span="12">
5         <el-form-item prop="templateType">
6           <span slot="label">生成模板</span>
7           <el-select v-model="formData.templateType">
8             <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)"
9                 :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
10           </el-select>
11         </el-form-item>
12       </el-col>
13       <el-col :span="12">
14         <el-form-item prop="templateType">
15           <span slot="label">前端类型</span>
16           <el-select v-model="formData.frontType">
17             <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_CODEGEN_FRONT_TYPE)"
18                        :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
19           </el-select>
20         </el-form-item>
21       </el-col>
22
23       <el-col :span="12">
24         <el-form-item prop="scene">
25           <span slot="label">生成场景</span>
26           <el-select v-model="formData.scene">
27             <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_CODEGEN_SCENE)"
28                        :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
29           </el-select>
30         </el-form-item>
31       </el-col>
32       <el-col :span="12">
33         <el-form-item>
34           <span slot="label">
35             上级菜单
36             <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
37               <i class="el-icon-question"></i>
38             </el-tooltip>
39           </span>
40           <treeselect :append-to-body="true" v-model="formData.parentMenuId" :options="menus"
41                       :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单" />
42         </el-form-item>
43       </el-col>
44
45 <!--      <el-col :span="12">-->
46 <!--        <el-form-item prop="packageName">-->
47 <!--          <span slot="label">-->
48 <!--            生成包路径-->
49 <!--            <el-tooltip content="生成在哪个java包下,例如 com.ruoyi.system" placement="top">-->
50 <!--              <i class="el-icon-question"></i>-->
51 <!--            </el-tooltip>-->
52 <!--          </span>-->
53 <!--          <el-input v-model="formData.packageName" />-->
54 <!--        </el-form-item>-->
55 <!--      </el-col>-->
56
57       <el-col :span="12">
58         <el-form-item prop="moduleName">
59           <span slot="label">
60             模块名
61             <el-tooltip content="模块名,即一级目录,例如 system、infra、tool 等等" placement="top">
62               <i class="el-icon-question"></i>
63             </el-tooltip>
64           </span>
65           <el-input v-model="formData.moduleName" />
66         </el-form-item>
67       </el-col>
68
69       <el-col :span="12">
70         <el-form-item prop="businessName">
71           <span slot="label">
72             业务名
73             <el-tooltip content="业务名,即二级目录,例如 user、permission、dict 等等" placement="top">
74               <i class="el-icon-question"></i>
75             </el-tooltip>
76           </span>
77           <el-input v-model="formData.businessName" />
78         </el-form-item>
79       </el-col>
80
81 <!--      <el-col :span="12">-->
82 <!--        <el-form-item prop="businessPackage">-->
83 <!--          <span slot="label">-->
84 <!--            业务包-->
85 <!--            <el-tooltip content="业务包,自定义二级目录。例如说,我们希望将 dictType 和 dictData 归类成 dict 业务" placement="top">-->
86 <!--              <i class="el-icon-question"></i>-->
87 <!--            </el-tooltip>-->
88 <!--          </span>-->
89 <!--          <el-input v-model="formData.businessPackage" />-->
90 <!--        </el-form-item>-->
91 <!--      </el-col>-->
92
93       <el-col :span="12">
94         <el-form-item prop="className">
95           <span slot="label">
96             类名称
97             <el-tooltip content="类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等" placement="top">
98               <i class="el-icon-question"></i>
99             </el-tooltip>
100           </span>
101           <el-input v-model="formData.className" />
102         </el-form-item>
103       </el-col>
104
105       <el-col :span="12">
106         <el-form-item prop="classComment">
107           <span slot="label">
108             类描述
109             <el-tooltip content="用作类描述,例如 用户" placement="top">
110               <i class="el-icon-question"></i>
111             </el-tooltip>
112           </span>
113           <el-input v-model="formData.classComment" />
114         </el-form-item>
115       </el-col>
116
117       <el-col :span="24" v-if="formData.genType === '1'">
118         <el-form-item prop="genPath">
119           <span slot="label">
120             自定义路径
121             <el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
122               <i class="el-icon-question"></i>
123             </el-tooltip>
124           </span>
125           <el-input v-model="formData.genPath">
126             <el-dropdown slot="append">
127               <el-button type="primary">
128                 最近路径快速选择
129                 <i class="el-icon-arrow-down el-icon--right"></i>
130               </el-button>
131               <el-dropdown-menu slot="dropdown">
132                 <el-dropdown-item @click.native="formData.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
133               </el-dropdown-menu>
134             </el-dropdown>
135           </el-input>
136         </el-form-item>
137       </el-col>
138     </el-row>
139
140     <!-- 树表信息 -->
141     <el-row v-if="formData.templateType == 2">
142       <el-col :span="24">
143         <h4 class="form-header">树表信息</h4>
144       </el-col>
145       <el-col :span="12">
146         <el-form-item prop="treeParentColumnId">
147           <template #label>
148             <span>
149               父编号字段
150               <el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top">
151                 <Icon icon="ep:question-filled" />
152               </el-tooltip>
153             </span>
154           </template>
155           <el-select v-model="formData.treeParentColumnId" placeholder="请选择">
156             <el-option
157               v-for="(column, index) in columns"
158               :key="index"
159               :label="column.columnName + ':' + column.columnComment"
160               :value="column.id"
161             />
162           </el-select>
163         </el-form-item>
164       </el-col>
165       <el-col :span="12">
166         <el-form-item prop="treeNameColumnId">
167           <template #label>
168             <span>
169               树名称字段
170               <el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top">
171                 <Icon icon="ep:question-filled" />
172               </el-tooltip>
173             </span>
174           </template>
175           <el-select v-model="formData.treeNameColumnId" placeholder="请选择">
176             <el-option
177               v-for="(column, index) in columns"
178               :key="index"
179               :label="column.columnName + ':' + column.columnComment"
180               :value="column.id"
181             />
182           </el-select>
183         </el-form-item>
184       </el-col>
185     </el-row>
186
187     <!-- 主表信息 -->
188     <el-row v-if="formData.templateType == 15">
189       <el-col :span="24">
190         <h4 class="form-header">主表信息</h4>
191       </el-col>
192       <el-col :span="12">
193         <el-form-item prop="masterTableId">
194           <template #label>
195             <span>
196               关联的主表
197               <el-tooltip content="关联主表(父表)的表名, 如:system_user" placement="top">
198                 <Icon icon="ep:question-filled" />
199               </el-tooltip>
200             </span>
201           </template>
202           <el-select v-model="formData.masterTableId" placeholder="请选择">
203             <el-option
204               v-for="(table0, index) in tables"
205               :key="index"
206               :label="table0.tableName + ':' + table0.tableComment"
207               :value="table0.id"
208             />
209           </el-select>
210         </el-form-item>
211       </el-col>
212       <el-col :span="12">
213         <el-form-item prop="subJoinColumnId">
214           <template #label>
215             <span>
216               子表关联的字段
217               <el-tooltip content="子表关联的字段, 如:user_id" placement="top">
218                 <Icon icon="ep:question-filled" />
219               </el-tooltip>
220             </span>
221           </template>
222           <el-select v-model="formData.subJoinColumnId" placeholder="请选择">
223             <el-option
224               v-for="(column, index) in columns"
225               :key="index"
226               :label="column.columnName + ':' + column.columnComment"
227               :value="column.id"
228             />
229           </el-select>
230         </el-form-item>
231       </el-col>
232       <el-col :span="12">
233         <el-form-item prop="subJoinMany">
234           <template #label>
235             <span>
236               关联关系
237               <el-tooltip content="主表与子表的关联关系" placement="top">
238                 <Icon icon="ep:question-filled" />
239               </el-tooltip>
240             </span>
241           </template>
242           <el-radio-group v-model="formData.subJoinMany" placeholder="请选择">
243             <el-radio :label="true">一对多</el-radio>
244             <el-radio :label="false">一对一</el-radio>
245           </el-radio-group>
246         </el-form-item>
247       </el-col>
248     </el-row>
249   </el-form>
250 </template>
251 <script>
252 import Treeselect from "@riophae/vue-treeselect";
253 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
254 import { getCodegenTableList } from "@/api/infra/codegen";
255
256 export default {
257   name: "GenInfoForm",
258   components: { Treeselect },
259   props: {
260     formData: {
261       type: Object,
262       default: null
263     },
264     columns:{
265       type: Array,
266       default: []
267     },
268     menus: {
269       type: Array,
270       default: []
271     },
272   },
273   data() {
274     return {
275       rules: {
276         templateType: [ { required: true, message: "请选择生成模板", trigger: "blur" }],
277         frontType: [ { required: true, message: "请选择前端类型", trigger: "blur" }],
278         scene: [ { required: true, message: "请选择生成场景", trigger: "blur" }],
279         moduleName: [ { required: true, message: "请输入生成模块名", trigger: "blur" }],
280         businessName: [ { required: true, message: "请输入生成业务名", trigger: "blur" }],
281         businessPackage: [ { required: true, message: "请输入生成业务包", trigger: "blur" }],
282         className: [ { required: true, message: "请输入生成类名称", trigger: "blur" }],
283         classComment: [ { required: true, message: "请输入生成类描述", trigger: "blur" }],
284         masterTableId: [ { required: true, message: "请选择关联的主表", trigger: "blur" }],
285         subJoinColumnId: [ { required: true, message: "请选择子表关联的字段", trigger: "blur" }],
286         subJoinMany: [ { required: true, message: "请选择关联关系", trigger: "blur" }],
287         treeParentColumnId: [ { required: true, message: "请选择父编号字段", trigger: "blur" }],
288         treeNameColumnId: [ { required: true, message: "请选择树名称字段", trigger: "blur" }]
289       },
290       tables:[] // 表定义列表
291     };
292   },
293   watch: {
294     formData: {
295       handler(val){
296         // 加载表列表
297         if (val.dataSourceConfigId >= 0) {
298           getCodegenTableList(val.dataSourceConfigId).then(res=>{
299             this.tables = res.data
300           })
301         }
302       },
303       deep: true,
304       immediate: true
305     }
306   },
307   methods: {
308     /** 转换菜单数据结构 */
309     normalizer(node) {
310       if (node.children && !node.children.length) {
311         delete node.children;
312       }
313       return {
314         id: node.id,
315         label: node.name,
316         children: node.children
317       };
318     }
319   }
320 };
321 </script>