11<template >
2- <div >
3- <!-- 初始版本自动化代码工具 -->
4- <el-form ref =" autoCodeForm" :rules =" rules" :model =" form" label-width =" 120px" :inline =" true" >
5- <el-form-item label =" Struct名称" prop =" structName" >
6- <el-input v-model =" form.structName" placeholder =" 首字母自动转换大写" ></el-input >
7- </el-form-item >
8- <el-form-item label =" Struct简称" prop =" abbreviation" >
9- <el-input v-model =" form.abbreviation" placeholder =" 简称会作为入参对象名和路由group" ></el-input >
10- </el-form-item >
11- <el-form-item label =" 文件名称" prop =" packageName" >
12- <el-input v-model =" form.packageName" ></el-input >
13- </el-form-item >
14- <el-form-item >
15- <el-checkbox v-model =" form.autoCreateApiToSql" >自动创建api</el-checkbox >
16- </el-form-item >
17- </el-form >
18- <!-- 组件列表 -->
19- <div class =" button-box clearflex" >
20- <el-button @click =" editAndAddField()" type =" primary" >新增Field</el-button >
21- </div >
22- <el-table
23- :data =" form.fields"
24- border stripe >
25- <el-table-column
26- type =" index"
27- label =" 序列"
28- width =" 280" >
29- </el-table-column >
30- <el-table-column
31- prop =" fieldName"
32- label =" Field名"
33- width =" 280" >
34- </el-table-column >
35- <el-table-column
36- prop =" fieldDesc"
37- label =" 中文名"
38- width =" 280" >
39- </el-table-column >
40- <el-table-column
41- prop =" fieldJson"
42- label =" FieldJson"
43- width =" 280" >
44- </el-table-column >
45- <el-table-column
46- prop =" fieldType"
47- label =" Field数据类型"
48- width =" 280" >
49- </el-table-column >
50- <el-table-column
51- label =" 操作" >
52- <template slot-scope="scope">
53- <el-button type =" primary" @click =" editAndAddField(scope.row)" >编辑</el-button >
54- <el-popover
55- placement =" top"
56- width =" 280"
57- v-model =" scope.row.visible" >
58- <p >这是一段内容这是一段内容确定删除吗?</p >
59- <div style =" text-align : right ; margin : 0 " >
60- <el-button size =" mini" type =" text" @click =" scope.row.visible = false" >取消</el-button >
61- <el-button type =" primary" size =" mini" @click =" deleteField(scope.$index)" >确定</el-button >
62- </div >
63- <el-button type =" danger" slot =" reference" >删除</el-button >
64- </el-popover >
65- </template >
66- </el-table-column >
67- </el-table >
68- <!-- 组件列表 -->
69- <div class =" button-box clearflex" >
70- <el-button @click =" enterForm" type =" primary" >生成代码包</el-button >
71- </div >
72- <!-- 组件弹窗 -->
73- <el-dialog title =" 组件内容" :visible.sync =" dialogFlag" >
74- <FieldDialog :dialogMiddle =" dialogMiddle" ref =" fieldDialog" />
75- <div slot =" footer" class =" dialog-footer" >
76- <el-button @click =" closeDialog" >取 消</el-button >
77- <el-button type =" primary" @click =" enterDialog" >确 定</el-button >
78- </div >
79- </el-dialog >
2+ <div >
3+ <!-- 初始版本自动化代码工具 -->
4+ <el-form ref =" autoCodeForm" :rules =" rules" :model =" form" label-width =" 120px" :inline =" true" >
5+ <el-form-item label =" Struct名称" prop =" structName" >
6+ <el-input v-model =" form.structName" placeholder =" 首字母自动转换大写" ></el-input >
7+ </el-form-item >
8+ <el-form-item label =" Struct简称" prop =" abbreviation" >
9+ <el-input v-model =" form.abbreviation" placeholder =" 简称会作为入参对象名和路由group" ></el-input >
10+ </el-form-item >
11+ <el-form-item label =" 文件名称" prop =" packageName" >
12+ <el-input v-model =" form.packageName" ></el-input >
13+ </el-form-item >
14+ <el-form-item >
15+ <el-checkbox v-model =" form.autoCreateApiToSql" >自动创建api</el-checkbox >
16+ </el-form-item >
17+ </el-form >
18+ <!-- 组件列表 -->
19+ <div class =" button-box clearflex" >
20+ <el-button @click =" editAndAddField()" type =" primary" >新增Field</el-button >
21+ </div >
22+ <el-table :data =" form.fields" border stripe >
23+ <el-table-column type =" index" label =" 序列" width =" 100" >
24+ </el-table-column >
25+ <el-table-column prop =" fieldName" label =" Field名" >
26+ </el-table-column >
27+ <el-table-column prop =" fieldDesc" label =" 中文名" >
28+ </el-table-column >
29+ <el-table-column prop =" fieldJson" label =" FieldJson" >
30+ </el-table-column >
31+ <el-table-column prop =" fieldType" label =" Field数据类型" width =" 130" >
32+ </el-table-column >
33+ <el-table-column label =" 操作" width =" 250" >
34+ <template slot-scope="scope">
35+ <el-button type =" primary" @click =" editAndAddField(scope.row)" >编辑</el-button >
36+ <el-button type =" success" :disabled =" scope.$index == 0" @click =" moveUpField(scope.$index)" >上移</el-button >
37+ <el-button type =" warning" :disabled =" (scope.$index + 1) == form.fields.length" @click =" moveDownField(scope.$index)" >下移</el-button >
38+ <el-popover placement =" top" v-model =" scope.row.visible" >
39+ <p >确定删除吗?</p >
40+ <div style =" text-align : right ; margin : 0 " >
41+ <el-button size =" mini" type =" text" @click =" scope.row.visible = false" >取消</el-button >
42+ <el-button type =" primary" size =" mini" @click =" deleteField(scope.$index)" >确定</el-button >
43+ </div >
44+ <el-button type =" danger" slot =" reference" >删除</el-button >
45+ </el-popover >
46+ </template >
47+ </el-table-column >
48+ </el-table >
49+ <!-- 组件列表 -->
50+ <div class =" button-box clearflex" >
51+ <el-button @click =" enterForm" type =" primary" >生成代码包</el-button >
8052 </div >
53+ <!-- 组件弹窗 -->
54+ <el-dialog title =" 组件内容" :visible.sync =" dialogFlag" >
55+ <FieldDialog :dialogMiddle =" dialogMiddle" ref =" fieldDialog" />
56+ <div slot =" footer" class =" dialog-footer" >
57+ <el-button @click =" closeDialog" >取 消</el-button >
58+ <el-button type =" primary" @click =" enterDialog" >确 定</el-button >
59+ </div >
60+ </el-dialog >
61+ </div >
8162</template >
8263<script >
83- const fieldTemplate = {
84- fieldName: " " ,
85- fieldDesc: " " ,
86- fieldType: " " ,
87- fieldJson: " " ,
88- columnName: " " ,
89- }
64+ const fieldTemplate = {
65+ fieldName: ' ' ,
66+ fieldDesc: ' ' ,
67+ fieldType: ' ' ,
68+ fieldJson: ' ' ,
69+ columnName: ' ' ,
70+ }
9071
91- import FieldDialog from " @/view/systemTools/autoCode/component/fieldDialog.vue"
92- import {toUpperCase } from " @/utils/stringFun.js"
93- import {createTemp } from " @/api/autoCode.js"
72+ import FieldDialog from ' @/view/systemTools/autoCode/component/fieldDialog.vue'
73+ import { toUpperCase } from ' @/utils/stringFun.js'
74+ import { createTemp } from ' @/api/autoCode.js'
9475export default {
95- name: " autoCode" ,
96- data (){
97- return {
98- addFlag: " " ,
99- form: {
100- structName: " " ,
101- packageName: " " ,
102- abbreviation: " " ,
103- autoCreateApiToSql: false ,
104- fields: []
105- },
106- rules: {
107- structName: [{required: true , message: ' 请输入结构体名称' , trigger: ' blur' }],
108- abbreviation: [{required: true , message: ' 请输入结构体简称' , trigger: ' blur' }],
109- packageName: [{required: true , message: ' 请输入包名称' , trigger: ' blur' }]
110- },
111- dialogMiddle: {},
112- bk: {},
113- dialogFlag: false
76+ name: ' autoCode' ,
77+ data () {
78+ return {
79+ addFlag: ' ' ,
80+ form: {
81+ structName: ' ' ,
82+ packageName: ' ' ,
83+ abbreviation: ' ' ,
84+ autoCreateApiToSql: false ,
85+ fields: [],
86+ },
87+ rules: {
88+ structName: [{ required: true , message: ' 请输入结构体名称' , trigger: ' blur' }],
89+ abbreviation: [{ required: true , message: ' 请输入结构体简称' , trigger: ' blur' }],
90+ packageName: [{ required: true , message: ' 请输入包名称' , trigger: ' blur' }],
91+ },
92+ dialogMiddle: {},
93+ bk: {},
94+ dialogFlag: false ,
95+ }
96+ },
97+ components: {
98+ FieldDialog,
99+ },
100+ methods: {
101+ editAndAddField (item ) {
102+ this .dialogFlag = true
103+ if (item) {
104+ this .addFlag = ' edit'
105+ this .bk = JSON .parse (JSON .stringify (item))
106+ this .dialogMiddle = item
107+ } else {
108+ this .addFlag = ' add'
109+ this .dialogMiddle = JSON .parse (JSON .stringify (fieldTemplate))
110+ }
111+ },
112+ moveUpField (index ) {
113+ if (index == 0 ) {
114+ return
115+ }
116+ const oldUpField = this .form .fields [index - 1 ]
117+ this .form .fields .splice (index - 1 , 1 )
118+ this .form .fields .splice (index, 0 , oldUpField)
119+ },
120+ moveDownField (index ) {
121+ const fCount = this .form .fields .length
122+ if (index == fCount - 1 ) {
123+ return
124+ }
125+ const oldDownField = this .form .fields [index + 1 ]
126+ this .form .fields .splice (index + 1 , 1 )
127+ this .form .fields .splice (index, 0 , oldDownField)
128+ },
129+ enterDialog () {
130+ this .$refs .fieldDialog .$refs .fieldDialogFrom .validate ((valid ) => {
131+ if (valid) {
132+ this .dialogMiddle .fieldName = toUpperCase (this .dialogMiddle .fieldName )
133+ if (this .addFlag == ' add' ) {
134+ this .form .fields .push (this .dialogMiddle )
135+ }
136+ this .dialogFlag = false
137+ } else {
138+ return false
114139 }
140+ })
115141 },
116- components: {
117- FieldDialog
142+ closeDialog () {
143+ if (this .addFlag == ' edit' ) {
144+ this .dialogMiddle = this .bk
145+ }
146+ this .dialogFlag = false
118147 },
119- methods: {
120- editAndAddField (item ){
121- this .dialogFlag = true
122- if (item){
123- this .addFlag = " edit"
124- this .bk = JSON .parse (JSON .stringify (item))
125- this .dialogMiddle = item
126- }else {
127- this .addFlag = " add"
128- this .dialogMiddle = JSON .parse (JSON .stringify (fieldTemplate))
129- }
130- },
131- enterDialog (){
132- this .$refs .fieldDialog .$refs .fieldDialogFrom .validate ((valid ) => {
133- if (valid) {
134- this .dialogMiddle .fieldName = toUpperCase (this .dialogMiddle .fieldName )
135- if (this .addFlag == " add" ){
136- this .form .fields .push (this .dialogMiddle )
137- }
138- this .dialogFlag = false
139- } else {
140- return false ;
148+ deleteField (index ) {
149+ this .form .fields .splice (index, 1 )
150+ },
151+ async enterForm () {
152+ if (this .form .fields .length <= 0 ) {
153+ this .$message ({
154+ type: ' error' ,
155+ message: ' 请填写至少一个field' ,
156+ })
157+ return false
158+ }
159+ this .$refs .autoCodeForm .validate (async (valid ) => {
160+ if (valid) {
161+ this .form .structName = toUpperCase (this .form .structName )
162+ if (this .form .structName == this .form .abbreviation ) {
163+ this .$message ({
164+ type: ' error' ,
165+ message: ' structName和struct简称不能相同' ,
166+ })
167+ return false
141168 }
142- });
143-
144- },
145- closeDialog (){
146- if (this .addFlag == " edit" ){
147- this .dialogMiddle = this .bk
148- }
149- this .dialogFlag = false
150- },
151- deleteField (index ){
152- this .form .fields .splice (index,1 )
153- },
154- async enterForm (){
155- if (this .form .fields .length <= 0 ){
156- this .$message ({
157- type: " error" ,
158- message: " 请填写至少一个field"
159- })
160- return false
161- }
162- this .$refs .autoCodeForm .validate (async (valid ) => {
163- if (valid) {
164- this .form .structName = toUpperCase (this .form .structName )
165- if (this .form .structName == this .form .abbreviation ){
166- this .$message ({
167- type: " error" ,
168- message: " structName和struct简称不能相同"
169- })
170- return false
171- }
172- const data = await createTemp (this .form )
173- const blob = new Blob ([data])
174- const fileName = ' ginvueadmin.zip'
175- if (' download' in document .createElement (' a' )) { // 不是IE浏览器
176- let url = window .URL .createObjectURL (blob)
177- let link = document .createElement (' a' )
178- link .style .display = ' none'
179- link .href = url
180- link .setAttribute (' download' , fileName)
181- document .body .appendChild (link)
182- link .click ()
183- document .body .removeChild (link) // 下载完成移除元素
184- window .URL .revokeObjectURL (url) // 释放掉blob对象
185- } else { // IE 10+
186- window .navigator .msSaveBlob (blob, fileName)
187- }
169+ const data = await createTemp (this .form )
170+ const blob = new Blob ([data])
171+ const fileName = ' ginvueadmin.zip'
172+ if (' download' in document .createElement (' a' )) {
173+ // 不是IE浏览器
174+ let url = window .URL .createObjectURL (blob)
175+ let link = document .createElement (' a' )
176+ link .style .display = ' none'
177+ link .href = url
178+ link .setAttribute (' download' , fileName)
179+ document .body .appendChild (link)
180+ link .click ()
181+ document .body .removeChild (link) // 下载完成移除元素
182+ window .URL .revokeObjectURL (url) // 释放掉blob对象
188183 } else {
189- return false ;
184+ // IE 10+
185+ window .navigator .msSaveBlob (blob, fileName)
190186 }
191- });
187+ } else {
188+ return false
192189 }
193- }
190+ })
191+ },
192+ },
194193}
195194 </script >
196195<style scope lang="scss">
@@ -200,4 +199,4 @@ export default {
200199 float : right ;
201200 }
202201}
203- </style >
202+ </style >
0 commit comments