Browse Source

field列表添加上移和下移的功能

main
DZero 5 years ago
committed by GitHub
parent
commit
a40a6d2b2d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 177
      web/src/view/systemTools/autoCode/index.vue

177
web/src/view/systemTools/autoCode/index.vue

@ -19,43 +19,24 @@
<div class="button-box clearflex"> <div class="button-box clearflex">
<el-button @click="editAndAddField()" type="primary">新增Field</el-button> <el-button @click="editAndAddField()" type="primary">新增Field</el-button>
</div> </div>
<el-table
:data="form.fields"
border stripe>
<el-table-column
type="index"
label="序列"
width="280">
<el-table :data="form.fields" border stripe>
<el-table-column type="index" label="序列" width="100">
</el-table-column> </el-table-column>
<el-table-column
prop="fieldName"
label="Field名"
width="280">
<el-table-column prop="fieldName" label="Field名">
</el-table-column> </el-table-column>
<el-table-column
prop="fieldDesc"
label="中文名"
width="280">
<el-table-column prop="fieldDesc" label="中文名">
</el-table-column> </el-table-column>
<el-table-column
prop="fieldJson"
label="FieldJson"
width="280">
<el-table-column prop="fieldJson" label="FieldJson">
</el-table-column> </el-table-column>
<el-table-column
prop="fieldType"
label="Field数据类型"
width="280">
<el-table-column prop="fieldType" label="Field数据类型" width="130">
</el-table-column> </el-table-column>
<el-table-column
label="操作">
<el-table-column label="操作" width="250">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="primary" @click="editAndAddField(scope.row)">编辑</el-button> <el-button type="primary" @click="editAndAddField(scope.row)">编辑</el-button>
<el-popover
placement="top"
width="280"
v-model="scope.row.visible">
<p>这是一段内容这是一段内容确定删除吗</p>
<el-button type="success" :disabled="scope.$index == 0" @click="moveUpField(scope.$index)">上移</el-button>
<el-button type="warning" :disabled="(scope.$index + 1) == form.fields.length" @click="moveDownField(scope.$index)">下移</el-button>
<el-popover placement="top" v-model="scope.row.visible">
<p>确定删除吗</p>
<div style="text-align: right; margin: 0"> <div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button> <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
<el-button type="primary" size="mini" @click="deleteField(scope.$index)">确定</el-button> <el-button type="primary" size="mini" @click="deleteField(scope.$index)">确定</el-button>
@ -71,7 +52,7 @@
</div> </div>
<!-- 组件弹窗 --> <!-- 组件弹窗 -->
<el-dialog title="组件内容" :visible.sync="dialogFlag"> <el-dialog title="组件内容" :visible.sync="dialogFlag">
<FieldDialog :dialogMiddle="dialogMiddle" ref="fieldDialog"/>
<FieldDialog :dialogMiddle="dialogMiddle" ref="fieldDialog" />
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="closeDialog"> </el-button> <el-button @click="closeDialog"> </el-button>
<el-button type="primary" @click="enterDialog"> </el-button> <el-button type="primary" @click="enterDialog"> </el-button>
@ -80,99 +61,116 @@
</div> </div>
</template> </template>
<script> <script>
const fieldTemplate={
fieldName:"",
fieldDesc:"",
fieldType:"",
fieldJson:"",
columnName:"",
}
const fieldTemplate = {
fieldName: '',
fieldDesc: '',
fieldType: '',
fieldJson: '',
columnName: '',
}
import FieldDialog from "@/view/systemTools/autoCode/component/fieldDialog.vue"
import {toUpperCase} from "@/utils/stringFun.js"
import {createTemp} from "@/api/autoCode.js"
import FieldDialog from '@/view/systemTools/autoCode/component/fieldDialog.vue'
import { toUpperCase } from '@/utils/stringFun.js'
import { createTemp } from '@/api/autoCode.js'
export default { export default {
name:"autoCode",
data(){
return{
addFlag:"",
form:{
structName:"",
packageName:"",
abbreviation:"",
autoCreateApiToSql:false,
fields:[]
name: 'autoCode',
data() {
return {
addFlag: '',
form: {
structName: '',
packageName: '',
abbreviation: '',
autoCreateApiToSql: false,
fields: [],
}, },
rules:{
structName:[{required: true, message: '请输入结构体名称', trigger: 'blur'}],
abbreviation:[{required: true, message: '请输入结构体简称', trigger: 'blur'}],
packageName:[{required: true, message: '请输入包名称', trigger: 'blur'}]
rules: {
structName: [{ required: true, message: '请输入结构体名称', trigger: 'blur' }],
abbreviation: [{ required: true, message: '请输入结构体简称', trigger: 'blur' }],
packageName: [{ required: true, message: '请输入包名称', trigger: 'blur' }],
}, },
dialogMiddle:{},
bk:{},
dialogFlag:false
dialogMiddle: {},
bk: {},
dialogFlag: false,
} }
}, },
components:{
FieldDialog
components: {
FieldDialog,
}, },
methods:{
editAndAddField(item){
methods: {
editAndAddField(item) {
this.dialogFlag = true this.dialogFlag = true
if(item){
this.addFlag="edit"
this.bk=JSON.parse(JSON.stringify(item))
if (item) {
this.addFlag = 'edit'
this.bk = JSON.parse(JSON.stringify(item))
this.dialogMiddle = item this.dialogMiddle = item
}else{
this.addFlag="add"
} else {
this.addFlag = 'add'
this.dialogMiddle = JSON.parse(JSON.stringify(fieldTemplate)) this.dialogMiddle = JSON.parse(JSON.stringify(fieldTemplate))
} }
}, },
enterDialog(){
moveUpField(index) {
if (index == 0) {
return
}
const oldUpField = this.form.fields[index - 1]
this.form.fields.splice(index - 1, 1)
this.form.fields.splice(index, 0, oldUpField)
},
moveDownField(index) {
const fCount = this.form.fields.length
if (index == fCount - 1) {
return
}
const oldDownField = this.form.fields[index + 1]
this.form.fields.splice(index + 1, 1)
this.form.fields.splice(index, 0, oldDownField)
},
enterDialog() {
this.$refs.fieldDialog.$refs.fieldDialogFrom.validate((valid) => { this.$refs.fieldDialog.$refs.fieldDialogFrom.validate((valid) => {
if (valid) { if (valid) {
this.dialogMiddle.fieldName = toUpperCase(this.dialogMiddle.fieldName) this.dialogMiddle.fieldName = toUpperCase(this.dialogMiddle.fieldName)
if(this.addFlag=="add"){
if (this.addFlag == 'add') {
this.form.fields.push(this.dialogMiddle) this.form.fields.push(this.dialogMiddle)
} }
this.dialogFlag = false this.dialogFlag = false
} else { } else {
return false;
return false
} }
});
})
}, },
closeDialog(){
if(this.addFlag=="edit"){
closeDialog() {
if (this.addFlag == 'edit') {
this.dialogMiddle = this.bk this.dialogMiddle = this.bk
} }
this.dialogFlag = false this.dialogFlag = false
}, },
deleteField(index){
this.form.fields.splice(index,1)
deleteField(index) {
this.form.fields.splice(index, 1)
}, },
async enterForm(){
if(this.form.fields.length<=0){
async enterForm() {
if (this.form.fields.length <= 0) {
this.$message({ this.$message({
type:"error",
message:"请填写至少一个field"
type: 'error',
message: '请填写至少一个field',
}) })
return false return false
} }
this.$refs.autoCodeForm.validate(async (valid) => { this.$refs.autoCodeForm.validate(async (valid) => {
if (valid) { if (valid) {
this.form.structName = toUpperCase(this.form.structName) this.form.structName = toUpperCase(this.form.structName)
if(this.form.structName == this.form.abbreviation){
if (this.form.structName == this.form.abbreviation) {
this.$message({ this.$message({
type:"error",
message:"structName和struct简称不能相同"
type: 'error',
message: 'structName和struct简称不能相同',
}) })
return false return false
} }
const data = await createTemp(this.form) const data = await createTemp(this.form)
const blob = new Blob([data]) const blob = new Blob([data])
const fileName = 'ginvueadmin.zip' const fileName = 'ginvueadmin.zip'
if ('download' in document.createElement('a')) { // IE
if ('download' in document.createElement('a')) {
// IE
let url = window.URL.createObjectURL(blob) let url = window.URL.createObjectURL(blob)
let link = document.createElement('a') let link = document.createElement('a')
link.style.display = 'none' link.style.display = 'none'
@ -182,15 +180,16 @@ export default {
link.click() link.click()
document.body.removeChild(link) // document.body.removeChild(link) //
window.URL.revokeObjectURL(url) // blob window.URL.revokeObjectURL(url) // blob
} else { // IE 10+
} else {
// IE 10+
window.navigator.msSaveBlob(blob, fileName) window.navigator.msSaveBlob(blob, fileName)
} }
} else { } else {
return false;
}
});
}
return false
} }
})
},
},
} }
</script> </script>
<style scope lang="scss"> <style scope lang="scss">

Loading…
Cancel
Save