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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// WTM默认页面 Wtm buidin page
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkMenuVMs;
 
namespace WalkingTec.Mvvm.Mvc.Admin.Controllers
{
    [Area("_Admin")]
    [ActionDescription("MenuKey.MenuMangement")]
    [MainTenantOnly]
    public class FrameworkMenuController : BaseController
    {
        [ActionDescription("Sys.Search")]
        public ActionResult Index()
        {
            var vm = Wtm.CreateVM<FrameworkMenuListVM>();
            return PartialView(vm);
        }
 
        [ActionDescription("Sys.Search")]
        [HttpPost]
        public string Search(FrameworkMenuSearcher searcher)
        {
            var vm = Wtm.CreateVM<FrameworkMenuListVM>(passInit: true);
            if (ModelState.IsValid)
            {
                vm.Searcher = searcher;
                return vm.GetJson(false);
            }
            else
            {
                return vm.GetError();
            }
        }
 
        [ActionDescription("Sys.Create")]
        public ActionResult Create(Guid? id)
        {
            var vm = Wtm.CreateVM<FrameworkMenuVM>();
            if (id != null)
            {
                vm.Entity.ParentId = id;
            }
            vm.Entity.IsInside = true;
            vm.Entity.IsPublic = false;
            vm.Entity.FolderOnly = false;
            vm.Entity.ShowOnMenu = true;
            return PartialView(vm);
        }
 
        [HttpPost]
        [Public]
        [ActionDescription("Sys.Create")]
        public ActionResult Create(FrameworkMenuVM vm)
        {
            if (!ModelState.IsValid)
            {
                return PartialView(vm);
            }
            else
            {
                vm.DoAdd();
                if (!ModelState.IsValid)
                {
                    vm.DoReInit();
                    return PartialView(vm);
                }
                else
                {
                    return FFResult().CloseDialog().RefreshGrid();
                }
            }
        }
 
        [ActionDescription("Sys.Edit")]
        public ActionResult Edit(Guid id)
        {
            var vm = Wtm.CreateVM<FrameworkMenuVM>(id);
            vm.IconSelectItems = !string.IsNullOrEmpty(vm.IconFont) && IconFontsHelper
                    .IconFontDicItems
                    .ContainsKey(vm.IconFont)
                    ? IconFontsHelper
                        .IconFontDicItems[vm.IconFont]
                        .Select(x => new ComboSelectListItem()
                        {
                            Text = x.Text,
                            Value = x.Value,
                            Icon = x.Icon
                        }).ToList()
                    : new List<ComboSelectListItem>();
 
            return PartialView(vm);
        }
 
        [ActionDescription("Sys.Edit")]
        [HttpPost]
        public ActionResult Edit(FrameworkMenuVM vm)
        {
            if (!ModelState.IsValid)
            {
                vm.IconSelectItems = !string.IsNullOrEmpty(vm.IconFont) && IconFontsHelper
                        .IconFontDicItems
                        .ContainsKey(vm.IconFont)
                        ? IconFontsHelper
                            .IconFontDicItems[vm.IconFont]
                            .Select(x => new ComboSelectListItem()
                            {
                                Text = x.Text,
                                Value = x.Value,
                                Icon = x.Icon
                            }).ToList()
                        : new List<ComboSelectListItem>();
                return PartialView(vm);
            }
            else
            {
                vm.DoEdit();
                if (!ModelState.IsValid)
                {
                    vm.DoReInit();
                    return PartialView(vm);
                }
                else
                {
                    return FFResult().CloseDialog().RefreshGrid();
                }
            }
        }
 
        [ActionDescription("Sys.Delete")]
        public ActionResult Delete(Guid id)
        {
            var vm = Wtm.CreateVM<FrameworkMenuVM>(id);
            return PartialView(vm);
        }
 
        [ActionDescription("Sys.Delete")]
        [HttpPost]
        public ActionResult Delete(Guid id, IFormCollection noUser)
        {
            var vm = Wtm.CreateVM<FrameworkMenuVM>(id);
            vm.DoDelete();
            if (!ModelState.IsValid)
            {
                return PartialView(vm);
            }
            else
            {
                return FFResult().CloseDialog().RefreshGrid();
            }
        }
 
        [ActionDescription("Sys.Details")]
        public PartialViewResult Details(Guid id)
        {
            var v = Wtm.CreateVM<FrameworkMenuVM>(id);
            return PartialView("Details", v);
        }
 
        [ActionDescription("_Admin.UnsetPages")]
        public ActionResult UnsetPages()
        {
            var vm = Wtm.CreateVM<FrameworkActionListVM>();
            return PartialView(vm);
        }
 
        [ActionDescription("_Admin.RefreshMenu")]
        public ActionResult RefreshMenu()
        {
            Cache.Delete(nameof(GlobalData.AllMenus));
            return FFResult().Alert(Localizer["Sys.OprationSuccess"]);
        }
 
        [ActionDescription("GetActionsByModelId")]
        [AllRights]
        public ActionResult GetActionsByModelId(string Id)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return JsonMore(new List<ComboSelectListItem>());
            }
            var modules = Wtm.GlobaInfo.AllModule;
            var m =Utils.ResetModule(modules);
 
            List<ComboSelectListItem> AllActions = new List<ComboSelectListItem>();
            var action = m.Where(x => x.FullName == Id)?.FirstOrDefault().Actions;
            if (action != null)
            {
                var mList = action?.Where(x => x.MethodName != "Index" && x.IgnorePrivillege == false)?.ToList();
                AllActions = mList.ToListItems(y => y.ActionName, y => y.Url);
                AllActions.ForEach(x => x.Selected = true);
            }
 
            return JsonMore(AllActions);
        }
 
        [HttpGet]
        [ResponseCache(Duration = 3600)]
        [AllRights]
        public IActionResult GetIconFontItems(string id)
        {
            if (!string.IsNullOrEmpty(id) && IconFontsHelper.IconFontDicItems.ContainsKey(id))
                return JsonMore(IconFontsHelper.IconFontDicItems[id]);
            else
                return JsonMore(null);
        }
 
    }
 
}