fix 字典页面布局修改,单图删除删除功能

This commit is contained in:
yxh 2025-06-10 09:45:48 +08:00
parent 4524d88708
commit 60da0c349b
11 changed files with 71 additions and 7 deletions

View File

@ -35,6 +35,7 @@ type DictDataSearchReq struct {
DictType string `p:"dictType"` //字典类型 DictType string `p:"dictType"` //字典类型
DictLabel string `p:"dictLabel"` //字典标签 DictLabel string `p:"dictLabel"` //字典标签
Status string `p:"status"` //状态 Status string `p:"status"` //状态
TypeId uint64 `p:"typeId"` // 字典类型ID
commonApi.PageReq commonApi.PageReq
} }

View File

@ -30,6 +30,7 @@ type DictTypeSearchRes struct {
type DictTypeAddReq struct { type DictTypeAddReq struct {
g.Meta `path:"/dict/type/add" tags:"系统后台/字典管理" method:"post" summary:"添加字典类型"` g.Meta `path:"/dict/type/add" tags:"系统后台/字典管理" method:"post" summary:"添加字典类型"`
Pid uint64 `p:"pid"`
DictName string `p:"dictName" v:"required#字典名称不能为空"` DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"` DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"` Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
@ -52,6 +53,7 @@ type DictTypeGetRes struct {
type DictTypeEditReq struct { type DictTypeEditReq struct {
g.Meta `path:"/dict/type/edit" tags:"系统后台/字典管理" method:"put" summary:"修改字典类型"` g.Meta `path:"/dict/type/edit" tags:"系统后台/字典管理" method:"put" summary:"修改字典类型"`
DictId int64 `p:"dictId" v:"required|min:1#主键ID不能为空|主键ID必须为大于0的值"` DictId int64 `p:"dictId" v:"required|min:1#主键ID不能为空|主键ID必须为大于0的值"`
Pid uint64 `p:"pid"`
DictName string `p:"dictName" v:"required#字典名称不能为空"` DictName string `p:"dictName" v:"required#字典名称不能为空"`
DictType string `p:"dictType" v:"required#字典类型不能为空"` DictType string `p:"dictType" v:"required#字典类型不能为空"`
Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"` Status uint `p:"status" v:"required|in:0,1#状态不能为空|状态只能为0或1"`
@ -71,6 +73,7 @@ type DictTypeDeleteRes struct {
type DictTypeAllReq struct { type DictTypeAllReq struct {
g.Meta `path:"/dict/type/optionSelect" tags:"系统后台/字典管理" method:"get" summary:"获取字典选择框列表"` g.Meta `path:"/dict/type/optionSelect" tags:"系统后台/字典管理" method:"get" summary:"获取字典选择框列表"`
All bool `p:"all"`
} }
type DictTYpeAllRes struct { type DictTYpeAllRes struct {

View File

@ -20,6 +20,7 @@ type SysDictTypeDao struct {
// SysDictTypeColumns defines and stores column names for table sys_dict_type. // SysDictTypeColumns defines and stores column names for table sys_dict_type.
type SysDictTypeColumns struct { type SysDictTypeColumns struct {
DictId string // 字典主键 DictId string // 字典主键
Pid string // 上级ID
DictName string // 字典名称 DictName string // 字典名称
DictType string // 字典类型 DictType string // 字典类型
Status string // 状态0正常 1停用 Status string // 状态0正常 1停用
@ -33,6 +34,7 @@ type SysDictTypeColumns struct {
// sysDictTypeColumns holds the columns for table sys_dict_type. // sysDictTypeColumns holds the columns for table sys_dict_type.
var sysDictTypeColumns = SysDictTypeColumns{ var sysDictTypeColumns = SysDictTypeColumns{
DictId: "dict_id", DictId: "dict_id",
Pid: "pid",
DictName: "dict_name", DictName: "dict_name",
DictType: "dict_type", DictType: "dict_type",
Status: "status", Status: "status",

View File

@ -86,6 +86,11 @@ func (s *sSysDictData) List(ctx context.Context, req *system.DictDataSearchReq)
err = g.Try(ctx, func(ctx context.Context) { err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysDictData.Ctx(ctx) m := dao.SysDictData.Ctx(ctx)
if req != nil { if req != nil {
if req.TypeId != 0 {
var dictTypes []string
dictTypes, err = service.SysDictType().GetDictTypesByTypeIds(ctx, req.TypeId)
m = m.Where(dao.SysDictData.Columns().DictType, dictTypes)
}
if req.DictLabel != "" { if req.DictLabel != "" {
m = m.Where(dao.SysDictData.Columns().DictLabel+" like ?", "%"+req.DictLabel+"%") m = m.Where(dao.SysDictData.Columns().DictLabel+" like ?", "%"+req.DictLabel+"%")
} }

View File

@ -72,6 +72,7 @@ func (s *sSysDictType) Add(ctx context.Context, req *system.DictTypeAddReq, user
err = s.ExistsDictType(ctx, req.DictType) err = s.ExistsDictType(ctx, req.DictType)
liberr.ErrIsNil(ctx, err) liberr.ErrIsNil(ctx, err)
_, err = dao.SysDictType.Ctx(ctx).Insert(do.SysDictType{ _, err = dao.SysDictType.Ctx(ctx).Insert(do.SysDictType{
Pid: req.Pid,
DictName: req.DictName, DictName: req.DictName,
DictType: req.DictType, DictType: req.DictType,
Status: req.Status, Status: req.Status,
@ -97,6 +98,7 @@ func (s *sSysDictType) Edit(ctx context.Context, req *system.DictTypeEditReq, us
liberr.ValueIsNil(dictType, "字典类型不存在") liberr.ValueIsNil(dictType, "字典类型不存在")
//修改字典类型 //修改字典类型
_, e = dao.SysDictType.Ctx(ctx).TX(tx).WherePri(req.DictId).Update(do.SysDictType{ _, e = dao.SysDictType.Ctx(ctx).TX(tx).WherePri(req.DictId).Update(do.SysDictType{
Pid: req.Pid,
DictName: req.DictName, DictName: req.DictName,
DictType: req.DictType, DictType: req.DictType,
Status: req.Status, Status: req.Status,
@ -168,19 +170,57 @@ func (s *sSysDictType) Delete(ctx context.Context, dictIds []int) (err error) {
} }
// GetAllDictType 获取所有正常状态下的字典类型 // GetAllDictType 获取所有正常状态下的字典类型
func (s *sSysDictType) GetAllDictType(ctx context.Context) (list []*entity.SysDictType, err error) { func (s *sSysDictType) GetAllDictType(ctx context.Context, all ...bool) (list []*entity.SysDictType, err error) {
cache := service.Cache() cache := service.Cache()
cacheKey := consts.CacheSysDict + "_dict_type_all"
if len(all) > 0 && !all[0] {
cacheKey = consts.CacheSysDict + "_dict_type_some"
}
//从缓存获取 //从缓存获取
data := cache.Get(ctx, consts.CacheSysDict+"_dict_type_all") data := cache.Get(ctx, cacheKey)
if !data.IsNil() { if !data.IsNil() {
err = data.Structs(&list) err = data.Structs(&list)
return return
} }
err = g.Try(ctx, func(ctx context.Context) { err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysDictType.Ctx(ctx).Where("status", 1).Order("dict_id ASC").Scan(&list) m := dao.SysDictType.Ctx(ctx)
if len(all) > 0 && !all[0] {
m = m.Where("status", 1)
}
err = m.Order("dict_id ASC").Scan(&list)
liberr.ErrIsNil(ctx, err, "获取字典类型数据出错") liberr.ErrIsNil(ctx, err, "获取字典类型数据出错")
//缓存 //缓存
cache.Set(ctx, consts.CacheSysDict+"_dict_type_all", list, 0, consts.CacheSysDictTag) cache.Set(ctx, cacheKey, list, 0, consts.CacheSysDictTag)
}) })
return return
} }
func (s *sSysDictType) GetDictTypesByTypeIds(ctx context.Context, id uint64) (dictTypeCodes []string, err error) {
err = g.Try(ctx, func(ctx context.Context) {
var dictAll []*entity.SysDictType
dictAll, err = s.GetAllDictType(ctx, true)
liberr.ErrIsNil(ctx, err)
dictTypeCodes = make([]string, 0, len(dictAll))
for _, dict := range dictAll {
if dict.DictId == id {
dictTypeCodes = append(dictTypeCodes, dict.DictType)
}
}
dictList := s.GetChildrenDictType(ctx, dictAll, id)
for _, dict := range dictList {
dictTypeCodes = append(dictTypeCodes, dict.DictType)
}
})
return
}
func (s *sSysDictType) GetChildrenDictType(ctx context.Context, dictAll []*entity.SysDictType, dictId uint64) (dictType []*entity.SysDictType) {
dictType = make([]*entity.SysDictType, 0, len(dictAll))
for _, dict := range dictAll {
if dict.Pid == dictId {
dictType = append(dictType, dict)
dictType = append(dictType, s.GetChildrenDictType(ctx, dictAll, dict.DictId)...)
}
}
return
}

View File

@ -13,6 +13,7 @@ import (
type SysDictType struct { type SysDictType struct {
g.Meta `orm:"table:sys_dict_type, do:true"` g.Meta `orm:"table:sys_dict_type, do:true"`
DictId interface{} // 字典主键 DictId interface{} // 字典主键
Pid interface{} // 上级ID
DictName interface{} // 字典名称 DictName interface{} // 字典名称
DictType interface{} // 字典类型 DictType interface{} // 字典类型
Status interface{} // 状态0正常 1停用 Status interface{} // 状态0正常 1停用

View File

@ -11,6 +11,7 @@ import (
// SysDictType is the golang structure for table sys_dict_type. // SysDictType is the golang structure for table sys_dict_type.
type SysDictType struct { type SysDictType struct {
DictId uint64 `json:"dictId" description:"字典主键"` DictId uint64 `json:"dictId" description:"字典主键"`
Pid uint64 `json:"pid" description:"上级ID"`
DictName string `json:"dictName" description:"字典名称"` DictName string `json:"dictName" description:"字典名称"`
DictType string `json:"dictType" description:"字典类型"` DictType string `json:"dictType" description:"字典类型"`
Status uint `json:"status" description:"状态0正常 1停用"` Status uint `json:"status" description:"状态0正常 1停用"`

View File

@ -11,6 +11,7 @@ import "github.com/gogf/gf/v2/os/gtime"
type SysDictTypeInfoRes struct { type SysDictTypeInfoRes struct {
DictId uint64 `orm:"dict_id,primary" json:"dictId"` // 字典主键 DictId uint64 `orm:"dict_id,primary" json:"dictId"` // 字典主键
Pid uint64 `orm:"pid" json:"pid"` // 上级ID
DictName string `orm:"dict_name" json:"dictName"` // 字典名称 DictName string `orm:"dict_name" json:"dictName"` // 字典名称
DictType string `orm:"dict_type,unique" json:"dictType"` // 字典类型 DictType string `orm:"dict_type,unique" json:"dictType"` // 字典类型
Status uint `orm:"status" json:"status"` // 状态0正常 1停用 Status uint `orm:"status" json:"status"` // 状态0正常 1停用

View File

@ -19,7 +19,8 @@ type ISysDictType interface {
Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error) Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error)
ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error) ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error)
Delete(ctx context.Context, dictIds []int) (err error) Delete(ctx context.Context, dictIds []int) (err error)
GetAllDictType(ctx context.Context) (list []*entity.SysDictType, err error) GetAllDictType(ctx context.Context, all ...bool) (list []*entity.SysDictType, err error)
GetDictTypesByTypeIds(ctx context.Context, id uint64) ([]string, error)
} }
var localSysDictType ISysDictType var localSysDictType ISysDictType

View File

@ -52,6 +52,6 @@ func (c *SysDictTypeController) Delete(ctx context.Context, req *system.DictType
// OptionSelect 获取字典选择框列表 // OptionSelect 获取字典选择框列表
func (c *SysDictTypeController) OptionSelect(ctx context.Context, req *system.DictTypeAllReq) (res *system.DictTYpeAllRes, err error) { func (c *SysDictTypeController) OptionSelect(ctx context.Context, req *system.DictTypeAllReq) (res *system.DictTYpeAllRes, err error) {
res = new(system.DictTYpeAllRes) res = new(system.DictTYpeAllRes)
res.DictType, err = commonService.SysDictType().GetAllDictType(ctx) res.DictType, err = commonService.SysDictType().GetAllDictType(ctx, req.All)
return return
} }

View File

@ -187,7 +187,12 @@
class="avatar-uploader" class="avatar-uploader"
name="file" name="file"
> >
<img v-if="!proxy.isEmpty(imageUrl{{$column.GoField}})" :src="imageUrl{{$column.GoField}}" class="avatar"> <div v-if="!proxy.isEmpty(imageUrlThumb)">
<el-link type="danger" style="position: absolute; right: 5px; top: 6px;font-size: 18px;" :underline="false" @click.stop="deleteImageUrl{{$column.GoField}}" title="删除">
<el-icon><ele-DeleteFilled /></el-icon>
</el-link>
<img :src="imageUrl{{$column.GoField}}" class="avatar">
</div>
<el-icon v-else class="avatar-uploader-icon"><ele-Plus /></el-icon> <el-icon v-else class="avatar-uploader-icon"><ele-Plus /></el-icon>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
@ -624,6 +629,10 @@ const setUpData = () => {
} }
{{$setUpData = false}} {{$setUpData = false}}
{{end}} {{end}}
const deleteImageUrl{{$column.GoField}} = ()=>{
state.formData.{{$column.HtmlField}} = ''
imageUrl{{$column.GoField}}.value = ''
}
{{else if eq $column.HtmlType "keyValue"}} {{else if eq $column.HtmlType "keyValue"}}
// 新增{{$column.ColumnComment}}行 // 新增{{$column.ColumnComment}}行
const onAddRow{{$column.GoField}} = () => { const onAddRow{{$column.GoField}} = () => {