Browse Source

fix: 解决设置默认分组的问题 (#385)

pull/390/head
ssongliu 2 years ago committed by GitHub
parent
commit
d70c22dde8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      backend/app/dto/group.go
  2. 6
      backend/app/repo/group.go
  3. 2
      backend/app/service/group.go
  4. 1
      frontend/src/components/group/index.vue
  5. 2
      frontend/src/views/login/components/login-form.vue

1
backend/app/dto/group.go

@ -13,6 +13,7 @@ type GroupSearch struct {
type GroupUpdate struct {
ID uint `json:"id"`
Name string `json:"name"`
Type string `json:"type" validate:"required"`
IsDefault bool `json:"isDefault"`
}

6
backend/app/repo/group.go

@ -14,7 +14,7 @@ type IGroupRepo interface {
Create(group *model.Group) error
Update(id uint, vars map[string]interface{}) error
Delete(opts ...DBOption) error
CancelDefault() error
CancelDefault(groupType string) error
WithByIsDefault(isDefault bool) DBOption
}
@ -64,6 +64,6 @@ func (u *GroupRepo) Delete(opts ...DBOption) error {
return db.Delete(&model.Group{}).Error
}
func (u *GroupRepo) CancelDefault() error {
return global.DB.Model(&model.Group{}).Where("`is_default` = 1").Updates(map[string]interface{}{"is_default": 0}).Error
func (u *GroupRepo) CancelDefault(groupType string) error {
return global.DB.Model(&model.Group{}).Where("is_default = ? AND type = ?", 1, groupType).Updates(map[string]interface{}{"is_default": 0}).Error
}

2
backend/app/service/group.go

@ -73,7 +73,7 @@ func (u *GroupService) Delete(id uint) error {
func (u *GroupService) Update(req dto.GroupUpdate) error {
if req.IsDefault {
if err := groupRepo.CancelDefault(); err != nil {
if err := groupRepo.CancelDefault(req.Type); err != nil {
return err
}
}

1
frontend/src/components/group/index.vue

@ -124,6 +124,7 @@ const saveGroup = async (formEl: FormInstance, group: Group.GroupInfo) => {
const setDefault = (group: Group.GroupInfo) => {
group.isDefault = true;
group.type = type.value;
UpdateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
search();

2
frontend/src/views/login/components/login-form.vue

@ -70,7 +70,7 @@
</div>
<div v-else-if="mfaShow">
<div class="login-form">
<el-form @submit.prevent="mfaLogin()">
<el-form @submit.prevent>
<div class="login-title">{{ $t('commons.login.mfaTitle') }}</div>
<el-form-item class="no-border">
<el-input

Loading…
Cancel
Save