From fdfd725254bcc31ef7fd46d74155f15063d188c6 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sat, 8 Jul 2023 15:33:46 +0800 Subject: [PATCH] update --- .../WTA.Shared/Controllers/GenericController.cs | 2 +- docs/demo/src/WTA.Shared/Data/BaseDbContext.cs | 13 ++++++++----- docs/demo/src/WTA.Shared/Data/EfRepository.cs | 10 ++++++++++ docs/demo/src/WTA.Shared/Data/IRepository.cs | 5 +++++ .../src/WTA/wwwroot/components/form/form-item.js | 2 +- docs/demo/src/WTA/wwwroot/layouts/tabs.js | 14 ++++++++++---- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/docs/demo/src/WTA.Shared/Controllers/GenericController.cs b/docs/demo/src/WTA.Shared/Controllers/GenericController.cs index cea4d81c..cb7e0295 100644 --- a/docs/demo/src/WTA.Shared/Controllers/GenericController.cs +++ b/docs/demo/src/WTA.Shared/Controllers/GenericController.cs @@ -171,7 +171,7 @@ public class GenericController guids.Contains(o.Id)); + this.Repository.Delete(guids); this.Repository.SaveChanges(); return NoContent(); } diff --git a/docs/demo/src/WTA.Shared/Data/BaseDbContext.cs b/docs/demo/src/WTA.Shared/Data/BaseDbContext.cs index 581b6d13..b7a13764 100644 --- a/docs/demo/src/WTA.Shared/Data/BaseDbContext.cs +++ b/docs/demo/src/WTA.Shared/Data/BaseDbContext.cs @@ -80,11 +80,14 @@ public abstract class BaseDbContext : DbContext where T : DbContext } else if (item.State == EntityState.Deleted) { - //if (entity is ISoftDeleteEntity) - //{ - // throw new Exception("内置数据无法删除"); - //} - if (entity.IsReadonly.HasValue && entity.IsReadonly.Value) + if (entity is ISoftDeleteEntity) + { + item.State = EntityState.Modified; + entity.IsDeleted = true; + entity.DeletedOn = now; + entity.DeletedBy = userName; + } + else if (entity.IsReadonly.HasValue && entity.IsReadonly.Value) { throw new Exception("内置数据无法删除"); } diff --git a/docs/demo/src/WTA.Shared/Data/EfRepository.cs b/docs/demo/src/WTA.Shared/Data/EfRepository.cs index 5e764903..4959af13 100644 --- a/docs/demo/src/WTA.Shared/Data/EfRepository.cs +++ b/docs/demo/src/WTA.Shared/Data/EfRepository.cs @@ -42,6 +42,11 @@ public class EfRepository : IRepository where TEntity : BaseEn this._dbContext.Set().Where(predicate).ExecuteDelete(); } + public void Delete(Guid[] guids) + { + this._dbContext.Set().RemoveRange(this._dbContext.Set().Where(o => guids.Contains(o.Id))); + } + public void Insert(TEntity entity) { this._dbContext.Set().Add(entity); @@ -52,6 +57,11 @@ public class EfRepository : IRepository where TEntity : BaseEn this._dbContext.SaveChanges(); } + public DbContext DbContext() + { + return this._dbContext; + } + public void DisableSoftDeleteFilter() { this._dbContext.GetType().GetProperty("DisableSoftDeleteFilter")?.SetValue(this._dbContext, true); diff --git a/docs/demo/src/WTA.Shared/Data/IRepository.cs b/docs/demo/src/WTA.Shared/Data/IRepository.cs index 00329b71..4dcddc49 100644 --- a/docs/demo/src/WTA.Shared/Data/IRepository.cs +++ b/docs/demo/src/WTA.Shared/Data/IRepository.cs @@ -1,4 +1,5 @@ using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Query; using WTA.Shared.Domain; @@ -14,12 +15,16 @@ public interface IRepository where TEntity : BaseEntity void Update(Expression, SetPropertyCalls>> setPropertyCalls, Expression> predicate); + void Delete(Guid[] guids); + void Delete(Expression> predicate); void Insert(TEntity entity); void SaveChanges(); + DbContext DbContext(); + void DisableSoftDeleteFilter(); void DisableTenantFilter(); diff --git a/docs/demo/src/WTA/wwwroot/components/form/form-item.js b/docs/demo/src/WTA/wwwroot/components/form/form-item.js index aeebaffe..ae49e013 100644 --- a/docs/demo/src/WTA/wwwroot/components/form/form-item.js +++ b/docs/demo/src/WTA/wwwroot/components/form/form-item.js @@ -32,7 +32,7 @@ export default { if (props.schema.hidden) { return false; } - if (props.schema.readOnly && (props.mode === "query" || props.mode === "create" || props.mode === "update")) { + if (props.schema.readOnly && (props.mode === "create" || props.mode === "update")) { return false; } return true; diff --git a/docs/demo/src/WTA/wwwroot/layouts/tabs.js b/docs/demo/src/WTA/wwwroot/layouts/tabs.js index b00302d1..f3882578 100644 --- a/docs/demo/src/WTA/wwwroot/layouts/tabs.js +++ b/docs/demo/src/WTA/wwwroot/layouts/tabs.js @@ -1,5 +1,5 @@ import html from "html"; -import { defineAsyncComponent, ref, nextTick } from "vue"; +import { defineAsyncComponent, ref, nextTick, getCurrentInstance } from "vue"; import { useRoute, onBeforeRouteUpdate, useRouter } from "vue-router"; import { useAppStore } from "../store/index.js"; @@ -111,11 +111,17 @@ export default { }); }; + const deleteItem = (start, end) => { + appStore.routes.splice(start, end); + const vue = getCurrentInstance(); + console.log(vue); + }; + const remove = (name) => { if (appStore.routes.length > 1) { const index = appStore.routes.findIndex((o) => o.fullPath === name); const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); - appStore.routes.splice(index, 1); + deleteItem(index, 1); if (index === currentIndex) { if (appStore.routes[index]) { router.push(appStore.routes[index]); @@ -129,7 +135,7 @@ export default { const removeLeft = (index) => { const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); const route = appStore.routes[index]; - appStore.routes.splice(0, index); + deleteItem(0, index); if (currentIndex < index) { router.push(route); } @@ -137,7 +143,7 @@ export default { const removeRight = (index) => { const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); - appStore.routes.splice(index + 1, appStore.routes.length - index); + deleteItem(index + 1, appStore.routes.length - index); if (currentIndex > index) { router.push(appStore.routes[index]); }