代码生成树形列表

This commit is contained in:
yxh
2020-08-14 18:11:46 +08:00
parent 854fc00099
commit 04d3ddadd1
8 changed files with 867 additions and 379 deletions
-360
View File
@@ -1,360 +0,0 @@
{{$tableComment:=.table.TableComment}}
<template>
<div class="app-container">
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px" >
{{range $index, $column := .table.Columns}}
{{ $x := $column.IsQuery }}
{{ if eq $x "1"}}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.GoField}}">
<el-input v-model="queryParams.{{$column.GoField}}" placeholder="请输入{{$column.ColumnComment}}" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
{{end}}
{{ end }}
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
>删除</el-button>
</el-col>
</el-row>
{{if eq .table.TplCategory "crud"}}
<!--单表-->
<el-table v-loading="loading" :data="{{.table.ModuleName}}List" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
{{range $index,$column:=.table.Columns}}
{{ $x := $column.IsList }}
{{ if eq $x "1"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.GoField}}" :show-overflow-tooltip="true" />
{{end }}
{{end }}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageIndex"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
{{else}}
<!--树形菜单-->
<el-table
v-loading="loading"
:data="deptList"
row-key="deptId"
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
{{range $index,$column:=.table.Columns}}
{{ $x := $column.IsList }}
{{ if eq $x "1"}}
<el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.GoField}}" :show-overflow-tooltip="true" />
{{ end }}
{{ end }}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-plus"
@click="handleAdd(scope.row)"
>新增</el-button>
<el-button
v-if="scope.row.parentId != 0"
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
{{end}}
<!-- 添加或修改对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px">
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
{{ range $index,$column:=.table.Columns }}
{{ $x := $column.IsInsert }}
{{ if eq $x "1"}}
{{ if eq $column.IsPk "1" }}
{{else if eq $column.GoField "CreatedAt" }}
{{else if eq $column.GoField "UpdatedAt" }}
{{else if eq $column.GoField "DeletedAt" }}
{{else if eq $column.GoField "UpdateBy" }}
{{else if eq $column.GoField "CreateBy" }}
{{else }}
<el-form-item label="{{$column.ColumnComment}}" prop="{{$column.GoField}}" >
{{ if eq "input" $column.HtmlType }}
<el-input v-model="form.{{$column.GoField}}" placeholder="{{$column.ColumnComment}}" {{if eq $column.IsEdit "false" }}:disabled="isEdit" {{ end}}/>
{{ else if eq "select" $column.HtmlType }}
<el-select v-model="form.{{$column.GoField}}" {{if eq $column.IsEdit "false" }} :disabled="isEdit" {{end }}>
<el-option label="demo1" value="demo1" />
<el-option label="demo2" value="demo2" />
</el-select>
{{else if eq "radio" $column.HtmlType }}
<el-radio-group v-model="form.{{$column.GoField}}">
<el-radio
v-for="dict in {{$column.GoField}}Options"
:key="dict.dictValue"
:label="dict.dictValue"
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
</el-radio-group>
{{ end }}
</el-form-item>
{{ end }}
{{ end }}
{{ end }}
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { list{{.table.BusinessName|UcFirst}}, get{{.table.BusinessName|UcFirst}}, del{{.table.BusinessName|UcFirst}}, add{{.table.BusinessName|UcFirst}}, update{{.table.BusinessName|UcFirst}} } from '@/api/{{.table.ModuleName}}/{{.table.BusinessName}}'
export default {
name: '{{.table.BusinessName|UcFirst}}',
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// 弹出层标题
title: '',
// 是否显示弹出层
open: false,
isEdit: false,
// 类型数据字典
typeOptions: [],
// 查询参数
queryParams: {
pageIndex: 1,
pageSize: 10,
{{ range $index,$column:=.table.Columns }}
{{if eq $column.IsQuery "1"}}
{{$column.GoField}}:undefined,
{{ end }}
{{ end }}
},
// 表单参数
form: {
},
// 表单校验
rules: {
{{range $index,$column :=.table.Columns }}
{{ $x := $column.IsQuery }}
{{ if eq $x "1"}}
{{$column.GoField}}:
[
{required: true, message: '{{$column.ColumnComment}}不能为空', trigger: 'blur'}
],
{{ end }}
{{ end }}
}
}
},
created() {
this.getList()
{{range $index,$column:=.table.Columns}}
{{ if ne $column.DictType "" }}
this.getDicts('{{$column.DictType}}').then(response => {
this.{{$column.GoField}}Options = response.data
})
{{ end }}
{{ end }}
},
methods: {
/** 查询参数列表 */
getList() {
this.loading = true
list{{.table.BusinessName|UcFirst}}(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.{{.table.ModuleName}}List = response.data.list
this.total = response.data.count
this.loading = false
}
)
},
// 取消按钮
cancel() {
this.open = false
this.reset()
},
// 表单重置
reset() {
this.form = {
{{ range $index,$column:=.table.Columns}}
{{ $x := $column.IsInsert }}
{{ if eq $x "1"}}
{{if eq $column.GoField "CreatedAt" }}
{{else if eq $column.GoField "UpdatedAt" }}
{{else if eq $column.GoField "DeletedAt" }}
{{else if eq $column.GoField "UpdateBy" }}
{{else if eq $column.GoField "CreateBy" }}
{{else }}
{{$column.GoField}}: undefined,
{{ end }}
{{ end }}
{{ end }}
}
this.resetForm('form')
},
{{$pk:=""}}
{{ range $index,$column:=.table.Columns}}
{{if eq $column.IsPk "1"}}
{{$pk =$column.GoField}}
{{end}}
{{ if ne $column.DictType "" }}
{{$column.GoField}}Format(row) {
return this.selectDictLabel(this.{{$column.GoField}}Options, row.{{$column.GoField}})
},
{{ end }}
{{ end }}
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageIndex = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = []
this.resetForm('queryForm')
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = '添加{{.table.TableComment}}'
this.isEdit = false
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{$pk}})
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const {{$pk}} = row.{{$pk}} || this.ids
get{{.table.BusinessName|UcFirst}}({{$pk}}).then(response => {
this.form = response.data
this.open = true
this.title = '修改{{.table.TableComment}}'
this.isEdit = true
})
},
/** 提交按钮 */
submitForm: function() {
this.$refs['form'].validate(valid => {
if (valid) {
if (this.form.{{$pk}} !== undefined) {
update{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess('修改成功')
this.open = false
this.getList()
} else {
this.msgError(response.msg)
}
})
} else {
add{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess('新增成功')
this.open = false
this.getList()
} else {
this.msgError(response.msg)
}
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const Ids = row.{{$pk}} || this.ids
this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return del{{.table.BusinessName|UcFirst}}(Ids)
}).then(() => {
this.getList()
this.msgSuccess('删除成功')
}).catch(function() {})
}
}
}
</script>
+421
View File
@@ -0,0 +1,421 @@
{{$columns:=.table.Columns}}
{{$pk:=""}}
{{$pkColumnName:=""}}
{{range $index, $column := .table.Columns}} {{if eq $column.IsPk "1"}}
{{$pk = $column.ColumnName}}
{{$pkColumnName = $column.ColumnName}}
{{end}}{{end}}
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
{{range $index,$column := $columns}}
{{if eq $column.IsQuery "1"}}
{{$dictType:=$column.DictType}}
{{$AttrName:=$column.ColumnName }}
{{$comment:=$column.ColumnComment}}
{{if eq $column.HtmlType "input"}}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-input
v-model="queryParams.{$column.ColumnName}}"
placeholder="请输入{{$comment}}"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
{{else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (ne $dictType "") }}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-select v-model="queryParams.{{$column.ColumnName}}" placeholder="请选择{{$comment}}" clearable size="small">
<el-option
v-for="dict in {{$column.ColumnName}}Options"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
{{else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (eq $dictType "") }}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-select v-model="queryParams.{{$column.ColumnName}}" placeholder="请选择{{$comment}}" clearable size="small">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="queryParams.{{$column.ColumnName}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$comment}}">
</el-date-picker>
</el-form-item>
{{end}}
{{end}}
{{end}}
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
>删除</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="{{.table.BusinessName}}List" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
{{range $index,$column := $columns}}
{{$ColumnName:=$column.ColumnName}}
{{$comment:=$column.ColumnComment}}
{{if eq $column.IsPk "1"}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" />
{{else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" width="180">
<template slot-scope="scope">
<span>{{ "{{" }} parseTime(scope.row.{{$ColumnName}}, '{y}-{m}-{d}') {{"}}"}}</span>
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (ne $column.DictType "")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" :formatter="{{$ColumnName}}Format" />
{{else if and (eq $column.IsList "1") (ne $ColumnName "")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" />
{{end}}
{{end}}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改{{.table.FunctionName}}对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
{{range $index,$column := $columns}}
{{$field := $column.ColumnName}}
{{if and (eq $column.IsInsert "1") (ne $column.IsPk "1") }}
{{$comment :=$column.ColumnComment}}
{{$dictType := $column.DictType }}
{{if eq $column.HtmlType "input"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-input v-model="form.{{$field}}" placeholder="请输入{{$comment}}" />
</el-form-item>
{{else if and (eq $column.HtmlType "select") (ne $dictType "") }}
<el-form-item label="{{$comment}}">
<el-select v-model="form.{{$field}}" placeholder="请选择{{$comment}}">
<el-option
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
:label="dict.dictLabel"
{{if or (eq $column.GoType "int") (eq $column.GoType "int64")}}:value="parseInt(dict.dictValue)"{{else}}:value="dict.dictValue"{{end}}
></el-option>
</el-select>
</el-form-item>
{{else if and (eq $column.HtmlType "select") $dictType}}
<el-form-item label="{{$comment}}">
<el-select v-model="form.{{$field}}" placeholder="请选择{{$comment}}">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{else if and (eq $column.HtmlType "checkbox") (ne $dictType "")}}
<el-form-item label="{{$comment}}">
<el-checkbox-group v-model="form.{{$field}}">
<el-checkbox
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
:label="dict.dictValue">
{{"{{"}}dict.dictLabel{{"}}"}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{else if and (eq $column.HtmlType "checkbox") $dictType }}
<el-form-item label="{{$comment}}">
<el-checkbox-group v-model="form.{{$field}}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{else if and (eq $column.HtmlType "radio") (ne $dictType "") }}
<el-form-item label="{{$comment}}">
<el-radio-group v-model="form.{{$field}}">
<el-radio
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
{{if or (eq $column.GoType "int") (eq $column.GoType "int64")}}:label="parseInt(dict.dictValue)"{{else}}:label="dict.dictValue"{{end}}
>{{"{{"}}dict.dictLabel{{"}}"}}</el-radio>
</el-radio-group>
</el-form-item>
{{else if and (eq $column.HtmlType "radio") $dictType }}
<el-form-item label="{{$comment}}">
<el-radio-group v-model="form.{{$field}}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="form.{{$field}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$comment}}">
</el-date-picker>
</el-form-item>
{{else if eq $column.HtmlType "textarea"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-input v-model="form.{{$field}}" type="textarea" placeholder="请输入内容" />
</el-form-item>
{{end}}
{{end}}
{{end}}
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { list{{.table.BusinessName|UcFirst}}, get{{.table.BusinessName|UcFirst}}, del{{.table.BusinessName|UcFirst}}, add{{.table.BusinessName|UcFirst}}, update{{.table.BusinessName|UcFirst}} } from '@/api/{{.table.ModuleName}}/{{.table.BusinessName}}'
export default {
name: "{{.table.BusinessName}}",
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// {{.table.FunctionName}}表格数据
{{.table.BusinessName}}List: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
{{range $index,$column := $columns}}
{{$comment :=$column.ColumnComment}}
{{if ne $column.DictType ""}}
// $comment字典
{{$column.ColumnName}}Options: [],
{{end}}
{{end}}
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if eq $column.IsQuery "1"}}
{{$column.ColumnName}}: null
{{end}}
{{end}}
},
// 表单参数
form: {},
// 表单校验
rules: {
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if and (eq $column.IsRequired "1") (eq $column.IsPk "0")}}
{{$comment:=$column.ColumnComment}}
{{$column.ColumnName}}: [
{ required: true, message: "{{$comment}}不能为空", trigger: "blur" }
]{{if ne $velocityCount (len $columns)}},{{end}}
{{end}}
{{end}}
}
};
},
created() {
this.getList();
{{range $index,$column := $columns}}
{{if ne $column.DictType ""}}
this.getDicts("{{$column.DictType}}").then(response => {
this.{{$column.ColumnName}}Options = response.data.values || [];
});
{{end}}
{{end}}
},
methods: {
/** 查询{{.table.FunctionName}}列表 */
getList() {
this.loading = true;
list{{.table.BusinessName|UcFirst}}(this.queryParams).then(response => {
this.{{.table.BusinessName}}List = response.rows;
this.total = response.total;
this.loading = false;
});
},
{{range $index,$column := $columns}}
{{if ne $column.DictType ""}}
{{$comment:=$column.ColumnComment}}
// $comment字典翻译
{{$column.ColumnName}}Format(row, column) {
return this.selectDictLabel{{if eq $column.HtmlType "checkbox"}}s{{end}}(this.{{$column.ColumnName}}Options, row.{{$column.ColumnName}});
},
{{end}}
{{end}}
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if eq $column.HtmlType "radio"}}
{{$column.ColumnName}}: {{if or (eq $column.GoType "int") (eq $column.GoType "int64") }}0{{else}}"0"{{end}} {{if ne $velocityCount (len $columns)}},{{end}}
{{else if eq $column.HtmlType "checkbox"}}
{{$column.ColumnName}}: []{{if ne $velocityCount (len $columns)}},{{end}}
{{else}}
{{$column.ColumnName}}: null{{if ne $velocityCount (len $columns)}},{{end}}
{{end}}
{{end}}
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.{{$pkColumnName}})
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加{{.table.FunctionName}}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const {{$pkColumnName}} = row.{{$pkColumnName}} || this.ids
get{{.table.BusinessName}}({{$pkColumnName}}).then(response => {
this.form = response.data;
{{range $index,$column := $columns}}
{{if eq $column.HtmlType "checkbox"}}
this.form.{{$column.ColumnName}} = this.form.{{$column.ColumnName}}.split(",");
{{end}}
{{end}}
this.open = true;
this.title = "修改{{.table.FunctionName}}";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
{{range $index,$column := $columns}}
{{if eq $column.HtmlType "checkbox"}}
this.form.{{$column.ColumnName}} = this.form.{{$column.ColumnName}}.join(",");
{{end}}
{{end}}
if (this.form.{{$pkColumnName}} != null) {
update{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
add{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const {{$pkColumnName}}s = row.{{$pkColumnName}} || this.ids;
this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + {{$pkColumnName}}s + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return del{{.table.BusinessName|UcFirst}}({{$pkColumnName}}s);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
},
} //methods结束
};
</script>
+420
View File
@@ -0,0 +1,420 @@
{{$columns:=.table.Columns}}
{{$pk:=""}}
{{$pkColumnName:=""}}
{{range $index, $column := .table.Columns}} {{if eq $column.IsPk "1"}}
{{$pk = $column.ColumnName}}
{{$pkColumnName = $column.ColumnName}}
{{end}}{{end}}
{{$treeCode:=index .options "tree_code"}}
{{$treeName:=index .options "tree_name"}}
{{$treeParentCode:=index .options "tree_parent_code"}}
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
{{range $index,$column := $columns}}
{{if eq $column.IsQuery "1"}}
{{$dictType:=$column.DictType}}
{{$AttrName:=$column.ColumnName }}
{{$comment:=$column.ColumnComment}}
{{if eq $column.HtmlType "input"}}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-input
v-model="queryParams.{$column.ColumnName}}"
placeholder="请输入{{$comment}}"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
{{else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (ne $dictType "") }}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-select v-model="queryParams.{{$column.ColumnName}}" placeholder="请选择{{$comment}}" clearable size="small">
<el-option
v-for="dict in {{$column.ColumnName}}Options"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
{{else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (eq $dictType "") }}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-select v-model="queryParams.{{$column.ColumnName}}" placeholder="请选择{{$comment}}" clearable size="small">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$comment}}" prop="{{$column.ColumnName}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="queryParams.{{$column.ColumnName}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$comment}}">
</el-date-picker>
</el-form-item>
{{end}}
{{end}}
{{end}}
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table
v-loading="loading"
:data="{{.table.BusinessName}}List"
row-key="{{$treeCode}}"
default-expand-all
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
{{range $index,$column := $columns}}
{{$ColumnName:=$column.ColumnName}}
{{$comment:=$column.ColumnComment}}
{{if eq $column.IsPk "1"}}
{{else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" width="180">
<template slot-scope="scope">
<span>{{ "{{" }} parseTime(scope.row.{{$ColumnName}}, '{y}-{m}-{d}') {{"}}"}}</span>
</template>
</el-table-column>
{{else if and (eq $column.IsList "1") (ne $column.DictType "")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" :formatter="{{$ColumnName}}Format" />
{{else if and (eq $column.IsList "1") (ne $ColumnName "")}}
<el-table-column label="{{$comment}}" align="center" prop="{{$ColumnName}}" />
{{end}}
{{end}}
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改{{.table.FunctionName}}对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
{{range $index,$column := $columns}}
{{$field := $column.ColumnName}}
{{if and (eq $column.IsInsert "1") (ne $column.IsPk "1") }}
{{$comment :=$column.ColumnComment}}
{{$dictType := $column.DictType }}
{{if and (ne $treeParentCode "") (eq $column.ColumnName $treeParentCode) }}
<el-form-item label="{{$comment}}" prop="{{$treeParentCode}}">
<treeselect v-model="form.{{$treeParentCode}}" :options="{{$.table.BusinessName}}Options" :normalizer="normalizer" placeholder="请选择{{$comment}}" />
</el-form-item>
{{else if eq $column.HtmlType "input"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-input v-model="form.{{$field}}" placeholder="请输入{{$comment}}" />
</el-form-item>
{{else if and (eq $column.HtmlType "select") (ne $dictType "") }}
<el-form-item label="{{$comment}}">
<el-select v-model="form.{{$field}}" placeholder="请选择{{$comment}}">
<el-option
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
:label="dict.dictLabel"
{{if or (eq $column.GoType "int") (eq $column.GoType "int64")}}:value="parseInt(dict.dictValue)"{{else}}:value="dict.dictValue"{{end}}
></el-option>
</el-select>
</el-form-item>
{{else if and (eq $column.HtmlType "select") $dictType}}
<el-form-item label="{{$comment}}">
<el-select v-model="form.{{$field}}" placeholder="请选择{{$comment}}">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
{{else if and (eq $column.HtmlType "checkbox") (ne $dictType "")}}
<el-form-item label="{{$comment}}">
<el-checkbox-group v-model="form.{{$field}}">
<el-checkbox
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
:label="dict.dictValue">
{{"{{"}}dict.dictLabel{{"}}"}}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{else if and (eq $column.HtmlType "checkbox") $dictType }}
<el-form-item label="{{$comment}}">
<el-checkbox-group v-model="form.{{$field}}">
<el-checkbox>请选择字典生成</el-checkbox>
</el-checkbox-group>
</el-form-item>
{{else if and (eq $column.HtmlType "radio") (ne $dictType "") }}
<el-form-item label="{{$comment}}">
<el-radio-group v-model="form.{{$field}}">
<el-radio
v-for="dict in {{$field}}Options"
:key="dict.dictValue"
{{if or (eq $column.GoType "int") (eq $column.GoType "int64")}}:label="parseInt(dict.dictValue)"{{else}}:label="dict.dictValue"{{end}}
>{{"{{"}}dict.dictLabel{{"}}"}}</el-radio>
</el-radio-group>
</el-form-item>
{{else if and (eq $column.HtmlType "radio") $dictType }}
<el-form-item label="{{$comment}}">
<el-radio-group v-model="form.{{$field}}">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
{{else if eq $column.HtmlType "datetime"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-date-picker clearable size="small" style="width: 200px"
v-model="form.{{$field}}"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择{{$comment}}">
</el-date-picker>
</el-form-item>
{{else if eq $column.HtmlType "textarea"}}
<el-form-item label="{{$comment}}" prop="{{$field}}">
<el-input v-model="form.{{$field}}" type="textarea" placeholder="请输入内容" />
</el-form-item>
{{end}}
{{end}}
{{end}}
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { list{{.table.BusinessName|UcFirst}}, get{{.table.BusinessName|UcFirst}}, del{{.table.BusinessName|UcFirst}}, add{{.table.BusinessName|UcFirst}}, update{{.table.BusinessName|UcFirst}} } from '@/api/{{.table.ModuleName}}/{{.table.BusinessName}}'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "{{.table.BusinessName}}",
components: { Treeselect },
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// {{.table.FunctionName}}表格数据
{{.table.BusinessName}}List: [],
// ${functionName}树选项
{{.table.BusinessName}}Options: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
{{range $index,$column := $columns}}
{{$comment :=$column.ColumnComment}}
{{if ne $column.DictType ""}}
// $comment字典
{{$column.ColumnName}}Options: [],
{{end}}
{{end}}
// 查询参数
queryParams: {
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if eq $column.IsQuery "1"}}
{{$column.ColumnName}}: null
{{end}}
{{end}}
},
// 表单参数
form: {},
// 表单校验
rules: {
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if and (eq $column.IsRequired "1") (eq $column.IsPk "0")}}
{{$comment:=$column.ColumnComment}}
{{$column.ColumnName}}: [
{ required: true, message: "{{$comment}}不能为空", trigger: "blur" }
]{{if ne $velocityCount (len $columns)}},{{end}}
{{end}}
{{end}}
}
};
},
created() {
this.getList();
{{range $index,$column := $columns}}
{{if ne $column.DictType ""}}
this.getDicts("{{$column.DictType}}").then(response => {
this.{{$column.ColumnName}}Options = response.data.values || [];
});
{{end}}
{{end}}
},
methods: {
/** 查询{{.table.FunctionName}}列表 */
getList() {
this.loading = true;
list{{.table.BusinessName|UcFirst}}(this.queryParams).then(response => {
this.{{.table.BusinessName}}List = this.handleTree(response.data, "{{$treeCode}}", "{{$treeParentCode}}");
this.loading = false;
});
},
/** 转换${functionName}数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.{{$treeCode}},
label: node.{{$treeName}},
children: node.children
};
},
/** 查询部门下拉树结构 */
getTreeselect() {
list{{.table.BusinessName}}().then(response => {
this.{{.table.BusinessName}}Options = [];
const data = { {{$treeCode}}: 0, {{$treeName}}: '顶级节点', children: [] };
data.children = this.handleTree(response.data, "{{$treeCode}}", "{{$treeParentCode}}");
this.{{.table.BusinessName}}Options.push(data);
});
},
{{range $index,$column := $columns}}
{{if ne $column.DictType ""}}
{{$comment:=$column.ColumnComment}}
// $comment字典翻译
{{$column.ColumnName}}Format(row, column) {
return this.selectDictLabel{{if eq $column.HtmlType "checkbox"}}s{{end}}(this.{{$column.ColumnName}}Options, row.{{$column.ColumnName}});
},
{{end}}
{{end}}
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
{{range $index,$column := $columns}}
{{$velocityCount := add $index 1}}
{{if eq $column.HtmlType "radio"}}
{{$column.ColumnName}}: {{if or (eq $column.GoType "int") (eq $column.GoType "int64") }}0{{else}}"0"{{end}} {{if ne $velocityCount (len $columns)}},{{end}}
{{else if eq $column.HtmlType "checkbox"}}
{{$column.ColumnName}}: []{{if ne $velocityCount (len $columns)}},{{end}}
{{else}}
{{$column.ColumnName}}: null{{if ne $velocityCount (len $columns)}},{{end}}
{{end}}
{{end}}
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.getTreeselect();
this.open = true;
this.title = "添加{{.table.FunctionName}}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
if (row != null) {
this.form.{{$treeParentCode}} = row.{{$treeCode}};
}
get{{.table.BusinessName}}({{$pkColumnName}}).then(response => {
this.form = response.data;
{{range $index,$column := $columns}}
{{if eq $column.HtmlType "checkbox"}}
this.form.{{$column.ColumnName}} = this.form.{{$column.ColumnName}}.split(",");
{{end}}
{{end}}
this.open = true;
this.title = "修改{{.table.FunctionName}}";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
{{range $index,$column := $columns}}
{{if eq $column.HtmlType "checkbox"}}
this.form.{{$column.ColumnName}} = this.form.{{$column.ColumnName}}.join(",");
{{end}}
{{end}}
if (this.form.{{$pkColumnName}} != null) {
update{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
}
});
} else {
add{{.table.BusinessName|UcFirst}}(this.form).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
}
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + row.{{$pkColumnName}} + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return del{{.table.BusinessName|UcFirst}}(row.{{$pkColumnName}});
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
}).catch(function() {});
},
} //methods结束
};
</script>