Browse Source

自动化代码修改完成

main
piexlmax 3 years ago
parent
commit
0c61b9457e
  1. 70
      server/resource/template/web/form.vue.tpl
  2. 205
      server/resource/template/web/table.vue.tpl
  3. 4
      web/src/view/systemTools/autoCode/index.vue
  4. 8
      web/src/view/systemTools/system/system.vue

70
server/resource/template/web/form.vue.tpl

@ -37,22 +37,29 @@
</template> </template>
<script> <script>
export default {
name: '{{.StructName}}'
}
</script>
<script setup>
import { import {
create{{.StructName}}, create{{.StructName}},
update{{.StructName}}, update{{.StructName}},
find{{.StructName}} find{{.StructName}}
} from '@/api/{{.PackageName}}' // 此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
name: '{{.StructName}}',
mixins: [infoList],
data() {
return {
type: '',
} from '@/api/{{.PackageName}}'
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref } from 'vue'
const route = useRoute()
const router = useRouter()
const type = ref('')
{{- range $index, $element := .DictTypes}} {{- range $index, $element := .DictTypes}}
{{ $element }}Options: [],
const {{ $element }}Options = ref([])
{{- end }} {{- end }}
formData: {
const formData = ref({
{{- range .Fields}} {{- range .Fields}}
{{- if eq .FieldType "bool" }} {{- if eq .FieldType "bool" }}
{{.FieldJson}}: false, {{.FieldJson}}: false,
@ -70,50 +77,49 @@ export default {
{{.FieldJson}}: 0, {{.FieldJson}}: 0,
{{- end }} {{- end }}
{{- end }} {{- end }}
}
}
},
async created() {
})
const init = async () => {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if (this.$route.query.id) {
const res = await find{{.StructName}}({ ID: this.$route.query.id })
if (route.query.id) {
const res = await find{{.StructName}}({ ID: route.query.id })
if (res.code === 0) { if (res.code === 0) {
this.formData = res.data.re{{.Abbreviation}}
this.type = 'update'
formData.value = res.data.re{{.Abbreviation}}
type.value = 'update'
} }
} else { } else {
this.type = 'create'
type.value = 'create'
} }
{{- range $index, $element := .DictTypes }} {{- range $index, $element := .DictTypes }}
await this.getDict('{{$element}}')
{{ $element }}Options.value = await getDictFunc('{{$element}}')
{{- end }} {{- end }}
},
methods: {
async save() {
}
init()
const save = async() => {
let res let res
switch (this.type) {
switch (type.value) {
case 'create': case 'create':
res = await create{{.StructName}}(this.formData)
res = await create{{.StructName}}(formData.value)
break break
case 'update': case 'update':
res = await update{{.StructName}}(this.formData)
res = await update{{.StructName}}(formData.value)
break break
default: default:
res = await create{{.StructName}}(this.formData)
res = await create{{.StructName}}(formData.value)
break break
} }
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: '创建/更改成功' message: '创建/更改成功'
}) })
} }
},
back() {
this.$router.go(-1)
}
} }
const back = () => {
router.go(-1)
} }
</script> </script>
<style> <style>

205
server/resource/template/web/table.vue.tpl

@ -57,7 +57,7 @@
{{- if .DictType}} {{- if .DictType}}
<el-table-column align="left" label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"> <el-table-column align="left" label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
<template #default="scope"> <template #default="scope">
{{"{{"}} filterDict(scope.row.{{.FieldJson}},"{{.DictType}}") {{"}}"}}
{{"{{"}} filterDict(scope.row.{{.FieldJson}},{{.DictType}}Options) {{"}}"}}
</template> </template>
</el-table-column> </el-table-column>
{{- else if eq .FieldType "bool" }} {{- else if eq .FieldType "bool" }}
@ -69,7 +69,7 @@
{{- end }} {{- end }}
<el-table-column align="left" label="按钮组"> <el-table-column align="left" label="按钮组">
<template #default="scope"> <template #default="scope">
<el-button type="text" icon="edit" size="small" class="table-button" @click="update{{.StructName}}(scope.row)">变更</el-button>
<el-button type="text" icon="edit" size="small" class="table-button" @click="update{{.StructName}}Func(scope.row)">变更</el-button>
<el-button type="text" icon="delete" size="mini" @click="deleteRow(scope.row)">删除</el-button> <el-button type="text" icon="delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
@ -125,6 +125,12 @@
</template> </template>
<script> <script>
export default {
name: '{{.StructName}}'
}
</script>
<script setup>
import { import {
create{{.StructName}}, create{{.StructName}},
delete{{.StructName}}, delete{{.StructName}},
@ -132,22 +138,20 @@ import {
update{{.StructName}}, update{{.StructName}},
find{{.StructName}}, find{{.StructName}},
get{{.StructName}}List get{{.StructName}}List
} from '@/api/{{.PackageName}}' // 此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
name: '{{.StructName}}',
mixins: [infoList],
data() {
return {
listApi: get{{ .StructName }}List,
dialogFormVisible: false,
type: '',
deleteVisible: false,
multipleSelection: [],
{{- range $index, $element := .DictTypes }}
{{ $element }}Options: [],
} from '@/api/{{.PackageName}}'
import { getDictFunc, formatDate, formatBoolean, filterDict } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref } from 'vue'
const dialogFormVisible = ref(false)
const type = ref('')
const deleteVisible = ref(false)
const multipleSelection = ref([])
{{- range $index, $element := .DictTypes}}
const {{ $element }}Options = ref([])
{{- end }} {{- end }}
formData: {
const formData = ref({
{{- range .Fields}} {{- range .Fields}}
{{- if eq .FieldType "bool" }} {{- if eq .FieldType "bool" }}
{{.FieldJson}}: false, {{.FieldJson}}: false,
@ -156,7 +160,7 @@ export default {
{{.FieldJson}}: '', {{.FieldJson}}: '',
{{- end }} {{- end }}
{{- if eq .FieldType "int" }} {{- if eq .FieldType "int" }}
{{.FieldJson}}: {{- if .DictType}} undefined{{ else }} 0{{- end }},
{{.FieldJson}}: {{- if .DictType }} undefined{{ else }} 0{{- end }},
{{- end }} {{- end }}
{{- if eq .FieldType "time.Time" }} {{- if eq .FieldType "time.Time" }}
{{.FieldJson}}: new Date(), {{.FieldJson}}: new Date(),
@ -165,78 +169,111 @@ export default {
{{.FieldJson}}: 0, {{.FieldJson}}: 0,
{{- end }} {{- end }}
{{- end }} {{- end }}
})
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})
const onReset = () => {
searchInfo.value = {}
}
// 搜索
const onSubmit = () => {
page.value = 1
pageSize.value = 10
{{- range .Fields}}{{- if eq .FieldType "bool" }}
if (searchInfo.value.{{.FieldJson}} === ""){
searchInfo.value.{{.FieldJson}}=null
}{{ end }}{{ end }}
getTableData()
}
// 分页
const handleSizeChange = (val) => {
pageSize.value = val
getTableData()
}
const handleCurrentChange = (val) => {
page.value = val
getTableData()
}
// 查询
const getTableData = async() => {
const table = await get{{.StructName}}List({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
if (table.code === 0) {
tableData.value = table.data.list
total.value = table.data.total
page.value = table.data.page
pageSize.value = table.data.pageSize
} }
}
},
async created() {
await this.getTableData()
}
getTableData()
const setOptions = async () =>{
{{- range $index, $element := .DictTypes }} {{- range $index, $element := .DictTypes }}
await this.getDict('{{$element}}')
{{ $element }}Options.value = await getDictFunc('{{$element}}')
{{- end }} {{- end }}
},
methods: {
onReset() {
this.searchInfo = {}
},
// 条件搜索前端看此方法
onSubmit() {
this.page = 1
this.pageSize = 10
{{- range .Fields}}{{- if eq .FieldType "bool" }}
if (this.searchInfo.{{.FieldJson}} === ""){
this.searchInfo.{{.FieldJson}}=null
}{{ end }}{{ end }}
this.getTableData()
},
handleSelectionChange(val) {
this.multipleSelection = val
},
deleteRow(row) {
this.$confirm('确定要删除吗?', '提示', {
}
setOptions()
const handleSelectionChange = (val) => {
multipleSelection.value = val
}
const deleteRow = (row) => {
ElMessageBox.confirm('确定要删除吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.delete{{.StructName}}(row)
delete{{.StructName}}Func(row)
}) })
},
async onDelete() {
}
const onDelete = async() => {
const ids = [] const ids = []
if (this.multipleSelection.length === 0) {
this.$message({
if (multipleSelection.value.length === 0) {
ElMessage({
type: 'warning', type: 'warning',
message: '请选择要删除的数据' message: '请选择要删除的数据'
}) })
return return
} }
this.multipleSelection &&
this.multipleSelection.map(item => {
multipleSelection.value &&
multipleSelection.value.map(item => {
ids.push(item.ID) ids.push(item.ID)
}) })
const res = await delete{{.StructName}}ByIds({ ids }) const res = await delete{{.StructName}}ByIds({ ids })
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: '删除成功' message: '删除成功'
}) })
if (this.tableData.length === ids.length && this.page > 1) {
this.page--
if (tableData.value.length === ids.length && page.value > 1) {
page.value--
} }
this.deleteVisible = false
this.getTableData()
deleteVisible.value = false
getTableData()
} }
},
async update{{.StructName}}(row) {
}
const update{{.StructName}}Func = async(row) => {
const res = await find{{.StructName}}({ ID: row.ID }) const res = await find{{.StructName}}({ ID: row.ID })
this.type = 'update'
type.value = 'update'
if (res.code === 0) { if (res.code === 0) {
this.formData = res.data.re{{.Abbreviation}}
this.dialogFormVisible = true
formData.value = res.data.re{{.Abbreviation}}
dialogFormVisible.value = true
} }
},
closeDialog() {
this.dialogFormVisible = false
this.formData = {
}
const closeDialog = () => {
dialogFormVisible.value = false
formData.value = {
{{- range .Fields}} {{- range .Fields}}
{{- if eq .FieldType "bool" }} {{- if eq .FieldType "bool" }}
{{.FieldJson}}: false, {{.FieldJson}}: false,
@ -255,47 +292,45 @@ export default {
{{- end }} {{- end }}
{{- end }} {{- end }}
} }
},
async delete{{.StructName}}(row) {
}
const delete{{.StructName}}Func = async (row) => {
const res = await delete{{.StructName}}({ ID: row.ID }) const res = await delete{{.StructName}}({ ID: row.ID })
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: '删除成功' message: '删除成功'
}) })
if (this.tableData.length === 1 && this.page > 1) {
this.page--
if (tableData.value.length === 1 && page.value > 1) {
page.value--
} }
this.getTableData()
getTableData()
} }
},
async enterDialog() {
}
const enterDialog = async () => {
let res let res
switch (this.type) {
switch (type.value) {
case 'create': case 'create':
res = await create{{.StructName}}(this.formData)
res = await create{{.StructName}}(formData.value)
break break
case 'update': case 'update':
res = await update{{.StructName}}(this.formData)
res = await update{{.StructName}}(formData.value)
break break
default: default:
res = await create{{.StructName}}(this.formData)
res = await create{{.StructName}}(formData.value)
break break
} }
if (res.code === 0) { if (res.code === 0) {
this.$message({
ElMessage({
type: 'success', type: 'success',
message: '创建/更改成功' message: '创建/更改成功'
}) })
this.closeDialog()
this.getTableData()
closeDialog()
getTableData()
} }
},
openDialog() {
this.type = 'create'
this.dialogFormVisible = true
}
},
}
const openDialog = () => {
type.value = 'create'
dialogFormVisible.value = true
} }
</script> </script>

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

@ -185,12 +185,12 @@ import PreviewCodeDialog from '@/view/systemTools/autoCode/component/previewCode
import { toUpperCase, toHump, toSQLLine, toLowerCase } from '@/utils/stringFun' import { toUpperCase, toHump, toSQLLine, toLowerCase } from '@/utils/stringFun'
import { createTemp, getDB, getTable, getColumn, preview, getMeta } from '@/api/autoCode' import { createTemp, getDB, getTable, getColumn, preview, getMeta } from '@/api/autoCode'
import { getDict } from '@/utils/dictionary' import { getDict } from '@/utils/dictionary'
import { ref, getCurrentInstance } from 'vue'
import { ref, getCurrentInstance, reactive } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const route = useRoute() const route = useRoute()
const activeNames = ref([''])
const activeNames = reactive([])
const preViewCode = ref({}) const preViewCode = ref({})
const dbform = ref({ const dbform = ref({
dbName: '', dbName: '',

8
web/src/view/systemTools/system/system.vue

@ -347,11 +347,15 @@ export default {
<script setup> <script setup>
import { getSystemConfig, setSystemConfig } from '@/api/system' import { getSystemConfig, setSystemConfig } from '@/api/system'
import { emailTest } from '@/api/email' import { emailTest } from '@/api/email'
import { ref } from 'vue'
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
const activeNames = reactive([])
const config = ref({ const config = ref({
system: {},
system: {
iplimitCount: 0,
iplimitTime: 0
},
jwt: {}, jwt: {},
casbin: {}, casbin: {},
mysql: {}, mysql: {},

Loading…
Cancel
Save