sunpengfei
2025-08-11 1759ab1a7d3e536eb812dcfbf5a7c8792ed28b2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace FlexJobApi.Core
{
    /// <summary>
    /// 菜单
    /// </summary>
    public class Menu : CommonEntity, IEntityTypeBuilder<Menu>, ITreeData<Menu>, IIsDisabled
    {
        public Menu()
        {
            Children = [];
        }
 
        /// <summary>
        /// 用户类型
        /// </summary>
        public EnumUserType UserType { get; set; }
 
        /// <summary>
        /// 客户端类型
        /// </summary>
        public EnumClientType ClientType { get; set; }
 
        /// <summary>
        /// 上级Id
        /// </summary>
        public Guid? ParentId { get; set; }
 
        /// <summary>
        /// 上级
        /// </summary>
        public Menu Parent { get; set; }
 
        /// <summary>
        /// 下级
        /// </summary>
        public List<Menu> Children { get; set; }
 
        /// <summary>
        /// 菜单路径
        /// </summary>
        public string Path { get; set; }
 
        /// <summary>
        /// 编号
        /// </summary>
        [Required]
        public string Code { get; set; }
 
        /// <summary>
        /// 名称
        /// </summary>
        [Required]
        [MaxLength(128)]
        public string Name { get; set; }
 
        /// <summary>
        /// 类型
        /// </summary>
        public EnumMenuType Type { get; set; }
 
        /// <summary>
        /// 访问级别
        /// </summary>
        public EnumMenuVisitLevel VisitLevel { get; set; }
 
        /// <summary>
        /// 图标
        /// </summary>
        public string Icon { get; set; }
 
        /// <summary>
        /// 链接地址
        /// </summary>
        public string Url { get; set; }
 
        /// <summary>
        /// 分组名称(用于按钮/字段)
        /// </summary>
        public string Group { get; set; }
 
        /// <summary>
        /// 位置(用于按钮)
        /// </summary>
        public string Location { get; set; }
 
        /// <summary>
        /// 列宽(用于按钮/列/元素)
        /// </summary>
        public string Width { get; set; }
 
        /// <summary>
        /// 是否禁用
        /// </summary>
        public bool IsDisabled { get; set; }
 
        /// <summary>
        /// 是否缓存
        /// </summary>
        public bool IsCache { get; set; }
 
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
 
        public void Configure(EntityTypeBuilder<Menu> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder
                .HasMany(x => x.Children)
                .WithOne(x => x.Parent)
                .HasForeignKey(x => x.ParentId)
                .OnDelete(DeleteBehavior.ClientSetNull);
        }
    }
}