houzhongjian
2024-07-11 759b1c71011abd6b58c37d2566f3f3c208c2f1b2
提交 | 用户 | 时间
759b1c 1 <template>
H 2   <el-card>
3     <el-tabs v-model="activeName">
4       <el-tab-pane label="基本信息" name="basic">
5         <basic-info-form ref="basicInfo" :info="formData.table"/>
6       </el-tab-pane>
7       <el-tab-pane label="字段信息" name="cloum">
8         <el-table ref="dragTable" :data="formData.columns" row-key="columnId"
9                   :max-height="tableHeight">
10           <el-table-column
11             label="字段列名"
12             prop="columnName"
13             min-width="10%"
14             :show-overflow-tooltip="true"
15           />
16           <el-table-column label="字段描述" min-width="10%">
17             <template v-slot="scope">
18               <el-input v-model="scope.row.columnComment"></el-input>
19             </template>
20           </el-table-column>
21           <el-table-column
22             label="物理类型"
23             prop="dataType"
24             min-width="10%"
25             :show-overflow-tooltip="true"
26           />
27           <el-table-column label="Java类型" min-width="11%">
28             <template v-slot="scope">
29               <el-select v-model="scope.row.javaType">
30                 <el-option label="Long" value="Long"/>
31                 <el-option label="String" value="String"/>
32                 <el-option label="Integer" value="Integer"/>
33                 <el-option label="Double" value="Double"/>
34                 <el-option label="BigDecimal" value="BigDecimal"/>
35                 <el-option label="LocalDateTime" value="LocalDateTime"/>
36                 <el-option label="Boolean" value="Boolean"/>
37               </el-select>
38             </template>
39           </el-table-column>
40           <el-table-column label="java属性" min-width="10%">
41             <template v-slot="scope">
42               <el-input v-model="scope.row.javaField"></el-input>
43             </template>
44           </el-table-column>
45           <el-table-column label="插入" min-width="4%">
46             <template v-slot="scope">
47               <el-checkbox true-label="true" false-label="false" v-model="scope.row.createOperation"></el-checkbox>
48             </template>
49           </el-table-column>
50           <el-table-column label="编辑" min-width="4%">
51             <template v-slot="scope">
52               <el-checkbox true-label="true" false-label="false" v-model="scope.row.updateOperation"></el-checkbox>
53             </template>
54           </el-table-column>
55           <el-table-column label="列表" min-width="4%">
56             <template v-slot="scope">
57               <el-checkbox true-label="true" false-label="false" v-model="scope.row.listOperationResult"></el-checkbox>
58             </template>
59           </el-table-column>
60           <el-table-column label="查询" min-width="4%">
61             <template v-slot="scope">
62               <el-checkbox true-label="true" false-label="false" v-model="scope.row.listOperation"></el-checkbox>
63             </template>
64           </el-table-column>
65           <el-table-column label="查询方式" min-width="10%">
66             <template v-slot="scope">
67               <el-select v-model="scope.row.listOperationCondition">
68                 <el-option label="=" value="="/>
69                 <el-option label="!=" value="!="/>
70                 <el-option label=">" value=">"/>
71                 <el-option label=">=" value=">="/>
72                 <el-option label="<" value="<>"/>
73                 <el-option label="<=" value="<="/>
74                 <el-option label="LIKE" value="LIKE"/>
75                 <el-option label="BETWEEN" value="BETWEEN"/>
76               </el-select>
77             </template>
78           </el-table-column>
79           <el-table-column label="允许空" min-width="5%">
80             <template v-slot="scope">
81               <el-checkbox true-label="true" false-label="false" v-model="scope.row.nullable"></el-checkbox>
82             </template>
83           </el-table-column>
84           <el-table-column label="显示类型" min-width="12%">
85             <template v-slot="scope">
86               <el-select v-model="scope.row.htmlType">
87                 <el-option label="文本框" value="input"/>
88                 <el-option label="文本域" value="textarea"/>
89                 <el-option label="下拉框" value="select"/>
90                 <el-option label="单选框" value="radio"/>
91                 <el-option label="复选框" value="checkbox"/>
92                 <el-option label="日期控件" value="datetime"/>
93                 <el-option label="图片上传" value="imageUpload"/>
94                 <el-option label="文件上传" value="fileUpload"/>
95                 <el-option label="富文本控件" value="editor"/>
96               </el-select>
97             </template>
98           </el-table-column>
99           <el-table-column label="字典类型" min-width="12%">
100             <template v-slot="scope">
101               <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
102                 <el-option
103                   v-for="dict in dictOptions"
104                   :key="dict.id"
105                   :label="dict.name"
106                   :value="dict.type"
107                 />
108               </el-select>
109             </template>
110           </el-table-column>
111           <el-table-column label="示例" min-width="10%">
112             <template v-slot="scope">
113               <el-input v-model="scope.row.example"></el-input>
114             </template>
115           </el-table-column>
116         </el-table>
117       </el-tab-pane>
118       <el-tab-pane label="生成信息" name="genInfo">
119         <gen-info-form ref="genInfo" :form-data="formData.table" :columns="formData.columns" :menus="menus"/>
120       </el-tab-pane>
121     </el-tabs>
122     <el-form label-width="100px">
123       <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
124         <el-button type="primary" @click="submitForm()">提交</el-button>
125         <el-button @click="close()">返回</el-button>
126       </el-form-item>
127     </el-form>
128   </el-card>
129 </template>
130 <script>
131 import {getCodegenDetail, updateCodegen} from "@/api/infra/codegen";
132 import {listAllSimple as listAllSimpleDictType} from "@/api/system/dict/type";
133 import {listSimpleMenus} from "@/api/system/menu";
134 import basicInfoForm from "./basicInfoForm";
135 import genInfoForm from "./genInfoForm";
136 import Sortable from 'sortablejs'
137
138 export default {
139   name: "GenEdit",
140   components: {
141     basicInfoForm,
142     genInfoForm
143   },
144   data() {
145     return {
146       // 选中选项卡的 name
147       activeName: "cloum",
148       // 表格的高度
149       tableHeight: document.documentElement.scrollHeight - 245 + "px",
150       // 字典信息
151       dictOptions: [],
152       formData: {},
153       // 菜单信息
154       menus: []
155     };
156   },
157   created() {
158     const tableId = this.$route.params && this.$route.params.tableId;
159     if (tableId) {
160       // 获取表详细信息
161       getCodegenDetail(tableId).then(res => {
162         this.formData = res.data;
163       });
164       /** 查询字典下拉列表 */
165       listAllSimpleDictType().then(response => {
166         this.dictOptions = response.data;
167       });
168       /** 查询菜单下拉列表 */
169       listSimpleMenus().then(response => {
170         this.menus = [];
171         this.menus.push(...this.handleTree(response.data, "id"));
172       });
173     }
174   },
175   methods: {
176     /** 提交按钮 */
177     submitForm() {
178       const basicForm = this.$refs.basicInfo.$refs.basicInfoForm;
179       const genForm = this.$refs.genInfo.$refs.genInfoForm;
180       Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => {
181         const validateResult = res.every(item => !!item);
182         if (validateResult) {
183           const genTable = {};
184           genTable.table = Object.assign({}, basicForm.model, genForm.model);
185           genTable.columns = this.formData.columns;
186           genTable.params = {
187             treeCode: genTable.treeCode,
188             treeName: genTable.treeName,
189             treeParentCode: genTable.treeParentCode,
190             parentMenuId: genTable.parentMenuId
191           };
192           updateCodegen(genTable).then(res => {
193             this.$modal.msgSuccess("修改成功!");
194             this.close();
195           });
196         } else {
197           this.$modal.msgError("表单校验未通过,请重新检查提交内容");
198         }
199       });
200     },
201     getFormPromise(form) {
202       return new Promise(resolve => {
203         form.validate(res => {
204           resolve(res);
205         });
206       });
207     },
208     /** 关闭按钮 */
209     close() {
210       this.$tab.closeOpenPage({
211           path: "/infra/codegen",
212           query: {t: Date.now(), pageNum: this.$route.query.pageNum}
213         }
214       );
215     }
216   },
217   mounted() {
218     const el = this.$refs.dragTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
219     const sortable = Sortable.create(el, {
220       handle: ".allowDrag",
221       onEnd: evt => {
222         const targetRow = this.columns.splice(evt.oldIndex, 1)[0];
223         this.columns.splice(evt.newIndex, 0, targetRow);
224         for (let index in this.columns) {
225           this.columns[index].sort = parseInt(index) + 1;
226         }
227       }
228     });
229   }
230 };
231 </script>