姜旭之 1 year ago
parent
commit
7f930d4e10
  1. 2
      docs/demo/src/WTA.Shared/Controllers/GenericController.cs
  2. 13
      docs/demo/src/WTA.Shared/Data/BaseDbContext.cs
  3. 10
      docs/demo/src/WTA.Shared/Data/EfRepository.cs
  4. 5
      docs/demo/src/WTA.Shared/Data/IRepository.cs
  5. 2
      docs/demo/src/WTA/wwwroot/components/form/form-item.js
  6. 14
      docs/demo/src/WTA/wwwroot/layouts/tabs.js

2
docs/demo/src/WTA.Shared/Controllers/GenericController.cs

@ -171,7 +171,7 @@ public class GenericController<TEntity, TModel, TListModel, TSearchModel, TImpor
{ {
try try
{ {
this.Repository.Delete(o => guids.Contains(o.Id)); this.Repository.Delete(guids);
this.Repository.SaveChanges(); this.Repository.SaveChanges();
return NoContent(); return NoContent();
} }

13
docs/demo/src/WTA.Shared/Data/BaseDbContext.cs

@ -80,11 +80,14 @@ public abstract class BaseDbContext<T> : DbContext where T : DbContext
} }
else if (item.State == EntityState.Deleted) else if (item.State == EntityState.Deleted)
{ {
//if (entity is ISoftDeleteEntity) if (entity is ISoftDeleteEntity)
//{ {
// throw new Exception("内置数据无法删除"); item.State = EntityState.Modified;
//} entity.IsDeleted = true;
if (entity.IsReadonly.HasValue && entity.IsReadonly.Value) entity.DeletedOn = now;
entity.DeletedBy = userName;
}
else if (entity.IsReadonly.HasValue && entity.IsReadonly.Value)
{ {
throw new Exception("内置数据无法删除"); throw new Exception("内置数据无法删除");
} }

10
docs/demo/src/WTA.Shared/Data/EfRepository.cs

@ -42,6 +42,11 @@ public class EfRepository<TEntity> : IRepository<TEntity> where TEntity : BaseEn
this._dbContext.Set<TEntity>().Where(predicate).ExecuteDelete(); this._dbContext.Set<TEntity>().Where(predicate).ExecuteDelete();
} }
public void Delete(Guid[] guids)
{
this._dbContext.Set<TEntity>().RemoveRange(this._dbContext.Set<TEntity>().Where(o => guids.Contains(o.Id)));
}
public void Insert(TEntity entity) public void Insert(TEntity entity)
{ {
this._dbContext.Set<TEntity>().Add(entity); this._dbContext.Set<TEntity>().Add(entity);
@ -52,6 +57,11 @@ public class EfRepository<TEntity> : IRepository<TEntity> where TEntity : BaseEn
this._dbContext.SaveChanges(); this._dbContext.SaveChanges();
} }
public DbContext DbContext()
{
return this._dbContext;
}
public void DisableSoftDeleteFilter() public void DisableSoftDeleteFilter()
{ {
this._dbContext.GetType().GetProperty("DisableSoftDeleteFilter")?.SetValue(this._dbContext, true); this._dbContext.GetType().GetProperty("DisableSoftDeleteFilter")?.SetValue(this._dbContext, true);

5
docs/demo/src/WTA.Shared/Data/IRepository.cs

@ -1,4 +1,5 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query;
using WTA.Shared.Domain; using WTA.Shared.Domain;
@ -14,12 +15,16 @@ public interface IRepository<TEntity> where TEntity : BaseEntity
void Update(Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls, Expression<Func<TEntity, bool>> predicate); void Update(Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls, Expression<Func<TEntity, bool>> predicate);
void Delete(Guid[] guids);
void Delete(Expression<Func<TEntity, bool>> predicate); void Delete(Expression<Func<TEntity, bool>> predicate);
void Insert(TEntity entity); void Insert(TEntity entity);
void SaveChanges(); void SaveChanges();
DbContext DbContext();
void DisableSoftDeleteFilter(); void DisableSoftDeleteFilter();
void DisableTenantFilter(); void DisableTenantFilter();

2
docs/demo/src/WTA/wwwroot/components/form/form-item.js

@ -32,7 +32,7 @@ export default {
if (props.schema.hidden) { if (props.schema.hidden) {
return false; 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 false;
} }
return true; return true;

14
docs/demo/src/WTA/wwwroot/layouts/tabs.js

@ -1,5 +1,5 @@
import html from "html"; 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 { useRoute, onBeforeRouteUpdate, useRouter } from "vue-router";
import { useAppStore } from "../store/index.js"; 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) => { const remove = (name) => {
if (appStore.routes.length > 1) { if (appStore.routes.length > 1) {
const index = appStore.routes.findIndex((o) => o.fullPath === name); const index = appStore.routes.findIndex((o) => o.fullPath === name);
const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath);
appStore.routes.splice(index, 1); deleteItem(index, 1);
if (index === currentIndex) { if (index === currentIndex) {
if (appStore.routes[index]) { if (appStore.routes[index]) {
router.push(appStore.routes[index]); router.push(appStore.routes[index]);
@ -129,7 +135,7 @@ export default {
const removeLeft = (index) => { const removeLeft = (index) => {
const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath);
const route = appStore.routes[index]; const route = appStore.routes[index];
appStore.routes.splice(0, index); deleteItem(0, index);
if (currentIndex < index) { if (currentIndex < index) {
router.push(route); router.push(route);
} }
@ -137,7 +143,7 @@ export default {
const removeRight = (index) => { const removeRight = (index) => {
const currentIndex = appStore.routes.findIndex((o) => o.fullPath === currentRoute.fullPath); 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) { if (currentIndex > index) {
router.push(appStore.routes[index]); router.push(appStore.routes[index]);
} }

Loading…
Cancel
Save