mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
增加必填校验 提升casbin版本 (#1170)
* 添加rule检测 * 调整初始化顺序,防止在数据库创建错误的时候,修改了配置文件。 * (feat):自动生产代码新增校验 * 增加校验功能 升级casbin Co-authored-by: bypanghu <bypanghu@163.com>
This commit is contained in:
committed by
GitHub
co-authored by
bypanghu
parent
14de145c02
commit
f0d31fd48d
@@ -93,32 +93,32 @@
|
||||
</div>
|
||||
</div>
|
||||
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" title="弹窗操作">
|
||||
<el-form :model="formData" label-position="right" label-width="80px">
|
||||
<el-form :model="formData" label-position="right" ref="elFormRef" :rules="rule" label-width="80px">
|
||||
{{- range .Fields}}
|
||||
<el-form-item label="{{.FieldDesc}}:">
|
||||
<el-form-item label="{{.FieldDesc}}:" prop="{{.FieldJson}}" >
|
||||
{{- if eq .FieldType "bool" }}
|
||||
<el-switch v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
|
||||
{{- end }}
|
||||
{{- if eq .FieldType "string" }}
|
||||
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" />
|
||||
<el-input v-model="formData.{{.FieldJson}}" :clearable="{{.Clearable}}" placeholder="请输入" />
|
||||
{{- end }}
|
||||
{{- if eq .FieldType "int" }}
|
||||
{{- if .DictType}}
|
||||
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" style="width:100%" clearable>
|
||||
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" style="width:100%" :clearable="{{.Clearable}}" >
|
||||
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
{{- else }}
|
||||
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入" />
|
||||
<el-input v-model.number="formData.{{ .FieldJson }}" :clearable="{{.Clearable}}" placeholder="请输入" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if eq .FieldType "time.Time" }}
|
||||
<el-date-picker v-model="formData.{{ .FieldJson }}" type="date" style="width:100%" placeholder="选择日期" clearable />
|
||||
<el-date-picker v-model="formData.{{ .FieldJson }}" type="date" style="width:100%" placeholder="选择日期" :clearable="{{.Clearable}}" />
|
||||
{{- end }}
|
||||
{{- if eq .FieldType "float64" }}
|
||||
<el-input-number v-model="formData.{{ .FieldJson }}" style="width:100%" :precision="2" clearable />
|
||||
<el-input-number v-model="formData.{{ .FieldJson }}" style="width:100%" :precision="2" :clearable="{{.Clearable}}" />
|
||||
{{- end }}
|
||||
{{- if eq .FieldType "enum" }}
|
||||
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" style="width:100%" clearable>
|
||||
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" style="width:100%" :clearable="{{.Clearable}}" >
|
||||
<el-option v-for="item in [{{.DataTypeLong}}]" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
{{- end }}
|
||||
@@ -154,7 +154,7 @@ import {
|
||||
// 全量引入格式化工具 请按需保留
|
||||
import { getDictFunc, formatDate, formatBoolean, filterDict } from '@/utils/format'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { ref } from 'vue'
|
||||
import { ref, reactive } from 'vue'
|
||||
|
||||
// 自动化生成的字典(可能为空)以及字段
|
||||
{{- range $index, $element := .DictTypes}}
|
||||
@@ -180,6 +180,22 @@ const formData = ref({
|
||||
{{- end }}
|
||||
})
|
||||
|
||||
// 验证规则
|
||||
const rule = reactive({
|
||||
{{- range .Fields }}
|
||||
{{- if eq .Require true }}
|
||||
{{.FieldJson }} : [{
|
||||
required: true,
|
||||
message: '{{ .ErrorText }}',
|
||||
trigger: ['input','blur'],
|
||||
}],
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
})
|
||||
|
||||
const elFormRef = ref()
|
||||
|
||||
|
||||
// =========== 表格控制部分 ===========
|
||||
const page = ref(1)
|
||||
const total = ref(0)
|
||||
@@ -354,26 +370,29 @@ const closeDialog = () => {
|
||||
}
|
||||
// 弹窗确定
|
||||
const enterDialog = async () => {
|
||||
let res
|
||||
switch (type.value) {
|
||||
case 'create':
|
||||
res = await create{{.StructName}}(formData.value)
|
||||
break
|
||||
case 'update':
|
||||
res = await update{{.StructName}}(formData.value)
|
||||
break
|
||||
default:
|
||||
res = await create{{.StructName}}(formData.value)
|
||||
break
|
||||
}
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '创建/更改成功'
|
||||
})
|
||||
closeDialog()
|
||||
getTableData()
|
||||
}
|
||||
elFormRef.value?.validate( async (valid) => {
|
||||
if (!valid) return
|
||||
let res
|
||||
switch (type.value) {
|
||||
case 'create':
|
||||
res = await create{{.StructName}}(formData.value)
|
||||
break
|
||||
case 'update':
|
||||
res = await update{{.StructName}}(formData.value)
|
||||
break
|
||||
default:
|
||||
res = await create{{.StructName}}(formData.value)
|
||||
break
|
||||
}
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '创建/更改成功'
|
||||
})
|
||||
closeDialog()
|
||||
getTableData()
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user