Skip to content

Commit db76d78

Browse files
author
piexlMax(奇淼
committed
feat(字典详情): 添加disabled字段并根据status动态计算
1 parent 1c749b0 commit db76d78

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

server/model/system/sys_dictionary_detail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type SysDictionaryDetail struct {
1818
Children []SysDictionaryDetail `json:"children" gorm:"foreignKey:ParentID"` // 子字典详情
1919
Level int `json:"level" form:"level" gorm:"column:level;comment:层级深度"` // 层级深度,从0开始
2020
Path string `json:"path" form:"path" gorm:"column:path;comment:层级路径"` // 层级路径,如 "1,2,3"
21+
Disabled bool `json:"disabled" gorm:"-"` // 禁用状态,根据status字段动态计算
2122
}
2223

2324
func (SysDictionaryDetail) TableName() string {

server/service/system/sys_dictionary_detail.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,15 @@ func (dictionaryDetailService *DictionaryDetailService) GetDictionaryTreeList(di
225225
return nil, err
226226
}
227227

228-
// 递归加载子项
228+
// 递归加载子项并设置disabled属性
229229
for i := range sysDictionaryDetails {
230+
// 设置disabled属性:当status为false时,disabled为true
231+
if sysDictionaryDetails[i].Status != nil {
232+
sysDictionaryDetails[i].Disabled = !*sysDictionaryDetails[i].Status
233+
} else {
234+
sysDictionaryDetails[i].Disabled = false // 默认不禁用
235+
}
236+
230237
err = dictionaryDetailService.loadChildren(&sysDictionaryDetails[i])
231238
if err != nil {
232239
return nil, err
@@ -245,6 +252,13 @@ func (dictionaryDetailService *DictionaryDetailService) loadChildren(detail *sys
245252
}
246253

247254
for i := range children {
255+
// 设置disabled属性:当status为false时,disabled为true
256+
if children[i].Status != nil {
257+
children[i].Disabled = !*children[i].Status
258+
} else {
259+
children[i].Disabled = false // 默认不禁用
260+
}
261+
248262
err = dictionaryDetailService.loadChildren(&children[i])
249263
if err != nil {
250264
return err
@@ -270,6 +284,15 @@ func (dictionaryDetailService *DictionaryDetailService) GetDictionaryDetailsByPa
270284
return list, err
271285
}
272286

287+
// 设置disabled属性
288+
for i := range list {
289+
if list[i].Status != nil {
290+
list[i].Disabled = !*list[i].Status
291+
} else {
292+
list[i].Disabled = false // 默认不禁用
293+
}
294+
}
295+
273296
// 如果需要包含子级数据,使用递归方式加载所有层级的子项
274297
if req.IncludeChildren {
275298
for i := range list {
@@ -304,8 +327,15 @@ func (dictionaryDetailService *DictionaryDetailService) GetDictionaryTreeListByT
304327
return nil, err
305328
}
306329

307-
// 递归加载子项
330+
// 递归加载子项并设置disabled属性
308331
for i := range sysDictionaryDetails {
332+
// 设置disabled属性:当status为false时,disabled为true
333+
if sysDictionaryDetails[i].Status != nil {
334+
sysDictionaryDetails[i].Disabled = !*sysDictionaryDetails[i].Status
335+
} else {
336+
sysDictionaryDetails[i].Disabled = false // 默认不禁用
337+
}
338+
309339
err = dictionaryDetailService.loadChildren(&sysDictionaryDetails[i])
310340
if err != nil {
311341
return nil, err

0 commit comments

Comments
 (0)