asp.net core + layui.js 搭建仓储系统
先放几张网站图片:
第一步先从layui 网站https://www.layui.com/doc/ 下载相关文件,复制到项目 wwwroot 目录下:
然后在 _Layout.cshtml 中引用 layui.js 和 layui.css,以及添加左侧栏和头部布局(具体操作见 : https://www.layui.com/doc/element/nav.html)
后端框架:
控制器通过依赖注入引用服务(asp.net core 默认支持)。
Startup.cs 配置数据库连接,Session(用于登录和菜单缓存),添加服务到服务容器。
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(10); }); services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(); services.AddMvc( options => { options.Filters.Add<HttpGlobalExceptionFilter>(); //加入全局异常类 }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext<AccessManagementContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), providerOptions => providerOptions.EnableRetryOnFailure())); services.AddDbContext<LuJCDBContext>(options => options.UseSqlServer(Configuration["WMSConnectionStrings:DefaultConnection"], providerOptions => providerOptions.EnableRetryOnFailure())); services.AddTransient<CompanyServices, CompanyServices>(); services.AddTransient<BasicInfoServices, BasicInfoServices>(); services.AddTransient<AppMenuServices>(); services.AddTransient<IAccountServices,AccountServices>(); services.AddTransient<BranchServices>(); services.AddTransient<PresetFunctionServices>(); services.AddTransient<RoleServices>(); services.AddTransient<LocationServices>(); services.AddTransient<SupplierServices>(); services.AddTransient<CustomerServices>(); services.AddTransient<MeasureServices>(); services.AddTransient<ProductCategoryServices>(); services.AddTransient<ProductServices>(); services.AddTransient<InStorageServices>(); services.AddTransient<OutStorageServices>(); services.AddTransient<BadReportServices>(); services.AddTransient<CheckStockServices>(); services.AddTransient<LocalProductServices>(); //services.AddScoped<AddHeaderFilterWithDI>(); services.AddAutoMapper(typeof(Startup)); Mapper.Initialize(cfg => { cfg.AddProfile<AccessManagementProfile>(); } ); //Mapper.Initialize(cfg => cfg.CreateMap<AppMenu, AppMenuViewModel>()); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory) { app.UseSession(); loggerFactory.AddNLog(); //添加NLog NLog.LogManager.LoadConfiguration("nlog.config"); app.UseLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseAuthentication(); app.UseHttpsRedirection(); app.UseStaticFiles(); var cookiePolicyOptions = new CookiePolicyOptions { MinimumSameSitePolicy = SameSiteMode.Strict, }; app.UseCookiePolicy(cookiePolicyOptions); app.UseAccountSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapAreaRoute("IMS", "IMS", "IMS/{controller}/{action}/{id?}", defaults: new { Controller = "Location", Action = "Index" }); routes.MapAreaRoute("WMS", "WMS", "WMS/{controller}/{action}/{id?}", defaults: new { Controller = "InStorage", Action = "Index" }); routes.MapAreaRoute("Report", "Report", "Report/{controller}/{action}/{id?}", defaults: new { Controller = "LocalProduct", Action = "Index" }); }); } }