diff --git a/internal/db/models/admin_dao.go b/internal/db/models/admin_dao.go index bdecc3e9..778f1d50 100644 --- a/internal/db/models/admin_dao.go +++ b/internal/db/models/admin_dao.go @@ -35,7 +35,7 @@ func init() { }) } -// 启用条目 +// EnableAdmin 启用条目 func (this *AdminDAO) EnableAdmin(tx *dbs.Tx, id int64) (rowsAffected int64, err error) { return this.Query(tx). Pk(id). @@ -43,7 +43,7 @@ func (this *AdminDAO) EnableAdmin(tx *dbs.Tx, id int64) (rowsAffected int64, err Update() } -// 禁用条目 +// DisableAdmin 禁用条目 func (this *AdminDAO) DisableAdmin(tx *dbs.Tx, id int64) (rowsAffected int64, err error) { return this.Query(tx). Pk(id). @@ -51,7 +51,7 @@ func (this *AdminDAO) DisableAdmin(tx *dbs.Tx, id int64) (rowsAffected int64, er Update() } -// 查找启用中的条目 +// FindEnabledAdmin 查找启用中的条目 func (this *AdminDAO) FindEnabledAdmin(tx *dbs.Tx, id int64) (*Admin, error) { result, err := this.Query(tx). Pk(id). @@ -63,7 +63,7 @@ func (this *AdminDAO) FindEnabledAdmin(tx *dbs.Tx, id int64) (*Admin, error) { return result.(*Admin), err } -// 检查管理员是否存在 +// ExistEnabledAdmin 检查管理员是否存在 func (this *AdminDAO) ExistEnabledAdmin(tx *dbs.Tx, adminId int64) (bool, error) { return this.Query(tx). Pk(adminId). @@ -71,7 +71,7 @@ func (this *AdminDAO) ExistEnabledAdmin(tx *dbs.Tx, adminId int64) (bool, error) Exist() } -// 获取管理员名称 +// FindAdminFullname 获取管理员名称 func (this *AdminDAO) FindAdminFullname(tx *dbs.Tx, adminId int64) (string, error) { return this.Query(tx). Pk(adminId). @@ -79,7 +79,7 @@ func (this *AdminDAO) FindAdminFullname(tx *dbs.Tx, adminId int64) (string, erro FindStringCol("") } -// 检查用户名、密码 +// CheckAdminPassword 检查用户名、密码 func (this *AdminDAO) CheckAdminPassword(tx *dbs.Tx, username string, encryptedPassword string) (int64, error) { if len(username) == 0 || len(encryptedPassword) == 0 { return 0, nil @@ -94,7 +94,7 @@ func (this *AdminDAO) CheckAdminPassword(tx *dbs.Tx, username string, encryptedP FindInt64Col(0) } -// 根据用户名查询管理员ID +// FindAdminIdWithUsername 根据用户名查询管理员ID func (this *AdminDAO) FindAdminIdWithUsername(tx *dbs.Tx, username string) (int64, error) { one, err := this.Query(tx). Attr("username", username). @@ -110,7 +110,7 @@ func (this *AdminDAO) FindAdminIdWithUsername(tx *dbs.Tx, username string) (int6 return int64(one.(*Admin).Id), nil } -// 更改管理员密码 +// UpdateAdminPassword 更改管理员密码 func (this *AdminDAO) UpdateAdminPassword(tx *dbs.Tx, adminId int64, password string) error { if adminId <= 0 { return errors.New("invalid adminId") @@ -122,7 +122,7 @@ func (this *AdminDAO) UpdateAdminPassword(tx *dbs.Tx, adminId int64, password st return err } -// 创建管理员 +// CreateAdmin 创建管理员 func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte) (int64, error) { op := NewAdminOperator() op.IsOn = true @@ -144,7 +144,7 @@ func (this *AdminDAO) CreateAdmin(tx *dbs.Tx, username string, canLogin bool, pa return types.Int64(op.Id), nil } -// 修改管理员个人资料 +// UpdateAdminInfo 修改管理员个人资料 func (this *AdminDAO) UpdateAdminInfo(tx *dbs.Tx, adminId int64, fullname string) error { if adminId <= 0 { return errors.New("invalid adminId") @@ -156,7 +156,7 @@ func (this *AdminDAO) UpdateAdminInfo(tx *dbs.Tx, adminId int64, fullname string return err } -// 修改管理员详细信息 +// UpdateAdmin 修改管理员详细信息 func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, canLogin bool, password string, fullname string, isSuper bool, modulesJSON []byte, isOn bool) error { if adminId <= 0 { return errors.New("invalid adminId") @@ -180,7 +180,7 @@ func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, ca return err } -// 检查用户名是否存在 +// CheckAdminUsername 检查用户名是否存在 func (this *AdminDAO) CheckAdminUsername(tx *dbs.Tx, adminId int64, username string) (bool, error) { query := this.Query(tx). State(AdminStateEnabled). @@ -193,7 +193,7 @@ func (this *AdminDAO) CheckAdminUsername(tx *dbs.Tx, adminId int64, username str return query.Exist() } -// 修改管理员登录信息 +// UpdateAdminLogin 修改管理员登录信息 func (this *AdminDAO) UpdateAdminLogin(tx *dbs.Tx, adminId int64, username string, password string) error { if adminId <= 0 { return errors.New("invalid adminId") @@ -208,7 +208,7 @@ func (this *AdminDAO) UpdateAdminLogin(tx *dbs.Tx, adminId int64, username strin return err } -// 修改管理员可以管理的模块 +// UpdateAdminModules 修改管理员可以管理的模块 func (this *AdminDAO) UpdateAdminModules(tx *dbs.Tx, adminId int64, allowModulesJSON []byte) error { if adminId <= 0 { return errors.New("invalid adminId") @@ -223,25 +223,25 @@ func (this *AdminDAO) UpdateAdminModules(tx *dbs.Tx, adminId int64, allowModules return nil } -// 查询所有管理的权限 +// FindAllAdminModules 查询所有管理的权限 func (this *AdminDAO) FindAllAdminModules(tx *dbs.Tx) (result []*Admin, err error) { _, err = this.Query(tx). State(AdminStateEnabled). Attr("isOn", true). - Result("id", "modules", "isSuper", "fullname"). + Result("id", "modules", "isSuper", "fullname", "theme"). Slice(&result). FindAll() return } -// 计算所有管理员数量 +// CountAllEnabledAdmins 计算所有管理员数量 func (this *AdminDAO) CountAllEnabledAdmins(tx *dbs.Tx) (int64, error) { return this.Query(tx). State(AdminStateEnabled). Count() } -// 列出单页的管理员 +// ListEnabledAdmins 列出单页的管理员 func (this *AdminDAO) ListEnabledAdmins(tx *dbs.Tx, offset int64, size int64) (result []*Admin, err error) { _, err = this.Query(tx). State(AdminStateEnabled). @@ -253,3 +253,11 @@ func (this *AdminDAO) ListEnabledAdmins(tx *dbs.Tx, offset int64, size int64) (r FindAll() return } + +// UpdateAdminTheme 设置管理员Theme +func (this *AdminDAO) UpdateAdminTheme(tx *dbs.Tx, adminId int64, theme string) error { + return this.Query(tx). + Pk(adminId). + Set("theme", theme). + UpdateQuickly() +} diff --git a/internal/db/models/admin_model.go b/internal/db/models/admin_model.go index 73a2906c..2035e5ff 100644 --- a/internal/db/models/admin_model.go +++ b/internal/db/models/admin_model.go @@ -1,6 +1,6 @@ package models -// 管理员 +// Admin 管理员 type Admin struct { Id uint32 `field:"id"` // ID IsOn uint8 `field:"isOn"` // 是否启用 @@ -13,6 +13,7 @@ type Admin struct { State uint8 `field:"state"` // 状态 Modules string `field:"modules"` // 允许的模块 CanLogin uint8 `field:"canLogin"` // 是否可以登录 + Theme string `field:"theme"` // 模板设置 } type AdminOperator struct { @@ -27,6 +28,7 @@ type AdminOperator struct { State interface{} // 状态 Modules interface{} // 允许的模块 CanLogin interface{} // 是否可以登录 + Theme interface{} // 模板设置 } func NewAdminOperator() *AdminOperator { diff --git a/internal/rpc/services/service_admin.go b/internal/rpc/services/service_admin.go index f627aa86..0a3e881f 100644 --- a/internal/rpc/services/service_admin.go +++ b/internal/rpc/services/service_admin.go @@ -298,6 +298,7 @@ func (this *AdminService) FindAllAdminModules(ctx context.Context, req *pb.FindA AdminId: int64(admin.Id), IsSuper: admin.IsSuper == 1, Fullname: admin.Fullname, + Theme: admin.Theme, Modules: pbModules, } result = append(result, list) @@ -633,3 +634,17 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com return resp, nil } + +// UpdateAdminTheme 修改管理员使用的界面风格 +func (this *AdminService) UpdateAdminTheme(ctx context.Context, req *pb.UpdateAdminThemeRequest) (*pb.RPCSuccess, error) { + _, err := this.ValidateAdmin(ctx, req.AdminId) + if err != nil { + return nil, err + } + var tx = this.NullTx() + err = models.SharedAdminDAO.UpdateAdminTheme(tx, req.AdminId, req.Theme) + if err != nil { + return nil, err + } + return this.Success() +}