mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
Merge branches 'gva_gormv2_dev', 'gva_workflow' and 'master' of https://github.com/flipped-aurora/gin-vue-admin into gva_workflow
Conflicts: server/cmd/datas/init.go
This commit is contained in:
@@ -90,7 +90,7 @@ func InitSysApi(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_apis表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Apis).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -20,7 +20,7 @@ func InitSysAuthority(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_authorities表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Authorities).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -24,7 +24,7 @@ func InitSysDataAuthorityId(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_data_authority_id表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&DataAuthorityId).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -75,7 +75,7 @@ func InitSysAuthorityMenus(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_authority_menus表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&AuthorityMenus).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -159,16 +159,11 @@ var Carbines = []gormadapter.CasbinRule{
|
||||
|
||||
func InitCasbinModel(db *gorm.DB) (err error) {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
if !tx.Migrator().HasTable("casbin_rule") {
|
||||
if err := tx.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if tx.Where("p_type = ? AND v0 IN ?", "p", []string{"888", "8881", "9528"}).Find(&[]gormadapter.CasbinRule{}).RowsAffected == 142 {
|
||||
color.Danger.Println("casbin_rule表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Carbines).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Carbines).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -19,7 +19,7 @@ func InitExaCustomer(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("exa_customers表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Customers).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -9,15 +9,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SysDictionaryToPostgresql struct {
|
||||
global.GVA_MODEL
|
||||
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"`
|
||||
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"`
|
||||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"`
|
||||
Description string `json:"description" form:"description" gorm:"column:description;comment:'描述'"`
|
||||
SysDictionaryDetails []model.SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
|
||||
}
|
||||
|
||||
func InitSysDictionary(db *gorm.DB) (err error) {
|
||||
var status = new(bool)
|
||||
*status = true
|
||||
@@ -34,32 +25,9 @@ func InitSysDictionary(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_dictionaries表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Dictionaries).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) {
|
||||
status := new(bool)
|
||||
*status = true
|
||||
Dictionaries := []SysDictionaryToPostgresql{
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"},
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"},
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"},
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Description: "数据库浮点型"},
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"},
|
||||
{GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"},
|
||||
}
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
if tx.Where("id IN ?", []int{1, 6}).Find(&[]model.SysDictionary{}).RowsAffected == 2 {
|
||||
color.Danger.Println("sys_dictionaries表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func InitSysDictionaryDetail(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_dictionary_details表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&DictionaryDetail).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -20,7 +20,7 @@ func InitExaFileUploadAndDownload(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Files).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -31,6 +31,9 @@ func InitMysqlData(db *gorm.DB) {
|
||||
|
||||
func InitMysqlTables(db *gorm.DB) {
|
||||
var err error
|
||||
if !db.Migrator().HasTable("casbin_rule") {
|
||||
err = db.Migrator().CreateTable(&gormadapter.CasbinRule{})
|
||||
}
|
||||
err = db.AutoMigrate(
|
||||
model.SysApi{},
|
||||
model.SysUser{},
|
||||
|
||||
@@ -48,7 +48,7 @@ func InitSysBaseMenus(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_base_menus表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&BaseMenus).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -21,7 +21,7 @@ func InitSysUser(db *gorm.DB) (err error) {
|
||||
color.Danger.Println("sys_users表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务
|
||||
if err := tx.Create(&Users).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -47,8 +47,7 @@ var initdbCmd = &cobra.Command{
|
||||
datas.InitMysqlTables(db)
|
||||
datas.InitMysqlData(db)
|
||||
case "postgresql":
|
||||
datas.InitPostgresqlTables(db)
|
||||
datas.InitPostgresqlData(db)
|
||||
color.Info.Println("postgresql功能开发中")
|
||||
case "sqlite":
|
||||
color.Info.Println("sqlite功能开发中")
|
||||
case "sqlserver":
|
||||
@@ -56,7 +55,6 @@ var initdbCmd = &cobra.Command{
|
||||
default:
|
||||
datas.InitMysqlTables(db)
|
||||
datas.InitMysqlData(db)
|
||||
color.Info.Println("sqlserver功能开发中")
|
||||
}
|
||||
frame, _ := cmd.Flags().GetString("frame")
|
||||
if frame == "gf" {
|
||||
|
||||
@@ -92,7 +92,33 @@
|
||||
></el-pagination>
|
||||
|
||||
<el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
|
||||
此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key
|
||||
<el-form :model="formData" label-position="right" label-width="80px">
|
||||
{{- range .Fields}}
|
||||
<el-form-item label="{{.FieldDesc}}:">
|
||||
{{- if eq .FieldType "bool" }}
|
||||
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "string" }}
|
||||
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "int" }}
|
||||
{{- if .DictType}}
|
||||
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
|
||||
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
|
||||
</el-select>
|
||||
{{ else -}}
|
||||
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "time.Time" }}
|
||||
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "float64" }}
|
||||
<el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
|
||||
{{ end -}}
|
||||
</el-form-item>
|
||||
{{ end -}}
|
||||
</el-form>
|
||||
<div class="dialog-footer" slot="footer">
|
||||
<el-button @click="closeDialog">取 消</el-button>
|
||||
<el-button @click="enterDialog" type="primary">确 定</el-button>
|
||||
@@ -110,15 +136,14 @@ import {
|
||||
find{{.StructName}},
|
||||
get{{.StructName}}List
|
||||
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
|
||||
import { formatTimeToStr } from "@/utils/date";
|
||||
import infoList from "@/components/mixins/infoList";
|
||||
|
||||
import { formatTimeToStr } from "@/utils/data";
|
||||
import infoList from "@/mixins/infoList";
|
||||
export default {
|
||||
name: "{{.StructName}}",
|
||||
mixins: [infoList],
|
||||
data() {
|
||||
return {
|
||||
listApi: get{{.StructName}}List,
|
||||
listApi: get{{ .StructName }}List,
|
||||
dialogFormVisible: false,
|
||||
visible: false,
|
||||
type: "",
|
||||
@@ -126,11 +151,27 @@ export default {
|
||||
multipleSelection: [],
|
||||
{{- range .Fields}}
|
||||
{{- if .DictType }}
|
||||
{{.DictType}}Options:[],
|
||||
{{ .DictType }}Options:[],
|
||||
{{ end -}}
|
||||
{{end -}}
|
||||
formData: {
|
||||
{{range .Fields}}{{.FieldJson}}:null,{{ end }}
|
||||
{{range .Fields}}
|
||||
{{- if eq .FieldType "bool" -}}
|
||||
{{.FieldJson}}:false,
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "string" -}}
|
||||
{{.FieldJson}}:"",
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "int" -}}
|
||||
{{.FieldJson}}:0,
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "time.Time" -}}
|
||||
{{.FieldJson}}:new Date(),
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "float64" -}}
|
||||
{{.FieldJson}}:0,
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
}
|
||||
};
|
||||
},
|
||||
@@ -192,8 +233,23 @@ export default {
|
||||
closeDialog() {
|
||||
this.dialogFormVisible = false;
|
||||
this.formData = {
|
||||
{{range .Fields}}
|
||||
{{.FieldJson}}:null,{{ end }}
|
||||
{{range .Fields}}
|
||||
{{- if eq .FieldType "bool" -}}
|
||||
{{.FieldJson}}:false,
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "string" -}}
|
||||
{{.FieldJson}}:"",
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "int" -}}
|
||||
{{.FieldJson}}:0,
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "time.Time" -}}
|
||||
{{.FieldJson}}:new Date(),
|
||||
{{ end -}}
|
||||
{{- if eq .FieldType "float64" -}}
|
||||
{{.FieldJson}}:0,
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
};
|
||||
},
|
||||
async delete{{.StructName}}(row) {
|
||||
@@ -236,11 +292,11 @@ export default {
|
||||
},
|
||||
async created() {
|
||||
await this.getTableData();
|
||||
{{- range .Fields -}}
|
||||
{{- if .DictType -}}
|
||||
await this.getDict("{{.DictType}}")
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ range .Fields -}}
|
||||
{{- if .DictType }}
|
||||
await this.getDict("{{.DictType}}");
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user