liaoxujun@qq.com
2024-02-18 b73ffe97fc885b652b20328c1c3d079a9124fb89
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
// WTM默认页面 Wtm buidin page
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using WalkingTec.Mvvm.Core;
 
namespace WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs
{
    public class FrameworkActionListVM : BasePagedListVM<FrameworkAction_ListView, BaseSearcher>
    {
 
        public FrameworkActionListVM()
        {
            NeedPage = false;
        }
 
        protected override List<GridAction> InitGridAction()
        {
            var actions = new List<GridAction>
            {
            };
            return actions;
        }
 
        protected override IEnumerable<IGridColumn<FrameworkAction_ListView>> InitGridHeader()
        {
            var header = new List<GridColumn<FrameworkAction_ListView>>();
 
            header.Add(this.MakeGridHeader(x => x.ModuleName, 150));
            header.Add(this.MakeGridHeader(x => x.ActionName, 150));
            header.Add(this.MakeGridHeader(x => x.ClassName, 150));
            header.Add(this.MakeGridHeader(x => x.MethodName, 150));
 
            return header;
        }
 
        /// <summary>
        /// 查询结果
        /// </summary>
        public override IOrderedQueryable<FrameworkAction_ListView> GetSearchQuery()
        {
            var newdc = DC as FrameworkContext;
            List<FrameworkAction_ListView> actions = new List<FrameworkAction_ListView>();
            var urls = newdc.BaseFrameworkMenus.Where(y => y.IsInside == true && y.FolderOnly == false).Select(y => y.Url).Distinct().ToList();
            if (ControllerName.Contains("/api") == false)
            {
                actions = Wtm.GlobaInfo.AllModule.SelectMany(x=>x.Actions)
                    .Where(x => urls.Contains(x.Url) == false)
                    .Select(x => new FrameworkAction_ListView
                    {
                        ID = x.ID,
                        ModuleID = x.ModuleId,
                        ModuleName = x.Module.ModuleName,
                        ActionName = x.ActionName,
                        ClassName = x.Module.ClassName,
                        MethodName = x.MethodName,
                        AreaName = x.Module.Area?.AreaName
                    }).ToList();
            }
            else
            {
                actions = Wtm.GlobaInfo.AllModule.SelectMany(x => x.Actions)
                   .Where(x => x.Module.IsApi == true && urls.Contains(x.Url) == false)
                   .Select(x => new FrameworkAction_ListView
                    {
                        ID = x.ID,
                        ModuleID = x.ModuleId,
                        ModuleName = x.Module.ModuleName,
                        ActionName = x.ActionName,
                        ClassName = x.Module.ClassName,
                        MethodName = x.MethodName,
                        AreaName = x.Module.Area?.AreaName
                    }).ToList();
 
            }
 
            var modules = Wtm.GlobaInfo.AllModule;
            List<FrameworkAction_ListView> toremove = new List<FrameworkAction_ListView>();
            foreach (var item in actions)
            {
                var m = modules.Where(x => x.ClassName == item.ClassName && x.Area?.AreaName == item.AreaName).FirstOrDefault();
                var a = m?.Actions.Where(x => x.MethodName == item.MethodName).FirstOrDefault();
                if(m?.IgnorePrivillege == true || a?.IgnorePrivillege == true)
                {
                    toremove.Add(item);
                }
            }
            toremove.ForEach(x => actions.Remove(x));
            return actions.AsQueryable().OrderBy(x=>x.AreaName).ThenBy(x=>x.ModuleName).ThenBy(x=>x.MethodName);
        }
 
    }
 
    public class FrameworkAction_ListView : BasePoco
    {
        public Guid? ModuleID { get; set; }
 
        [Display(Name = "Codegen.ModuleName")]
        public string ModuleName { get; set; }
        [Display(Name = "_Admin.ActionName")]
        public string ActionName { get; set; }
        [Display(Name = "_Admin.ClassName")]
        public string ClassName { get; set; }
        [Display(Name = "_Admin.MethodName")]
        public string MethodName { get; set; }
 
        public string AreaName { get; set; }
 
    }
}