新增加文章目录管理
This commit is contained in:
commit
87943d150e
169
ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs
Normal file
169
ZR.Admin.WebApi/Controllers/System/ArticleCategoryController.cs
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
using Infrastructure;
|
||||||
|
using Infrastructure.Attribute;
|
||||||
|
using Infrastructure.Enums;
|
||||||
|
using Infrastructure.Model;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ZR.Model.Dto;
|
||||||
|
using ZR.Admin.WebApi.Extensions;
|
||||||
|
using ZR.Admin.WebApi.Filters;
|
||||||
|
using ZR.Common;
|
||||||
|
using ZR.Service.System.IService;
|
||||||
|
using ZR.Model.System;
|
||||||
|
|
||||||
|
namespace ZR.Admin.WebApi.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 文章目录Controller
|
||||||
|
///
|
||||||
|
/// @tableName articleCategory
|
||||||
|
/// @author zr
|
||||||
|
/// @date 2022-05-13
|
||||||
|
/// </summary>
|
||||||
|
[Verify]
|
||||||
|
[Route("article/ArticleCategory")]
|
||||||
|
public class ArticleCategoryController : BaseController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 文章目录接口
|
||||||
|
/// </summary>
|
||||||
|
private readonly IArticleCategoryService _ArticleCategoryService;
|
||||||
|
|
||||||
|
public ArticleCategoryController(IArticleCategoryService ArticleCategoryService)
|
||||||
|
{
|
||||||
|
_ArticleCategoryService = ArticleCategoryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询文章目录列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("list")]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||||
|
public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
var response = _ArticleCategoryService.GetList(parm);
|
||||||
|
return SUCCESS(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询文章目录列表树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("treeList")]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:list")]
|
||||||
|
public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
var response = _ArticleCategoryService.GetTreeList(parm);
|
||||||
|
return SUCCESS(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询文章目录详情
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="CategoryId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{CategoryId}")]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:query")]
|
||||||
|
public IActionResult GetArticleCategory(int CategoryId)
|
||||||
|
{
|
||||||
|
var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
|
||||||
|
|
||||||
|
return SUCCESS(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加文章目录
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:add")]
|
||||||
|
[Log(Title = "文章目录", BusinessType = BusinessType.INSERT)]
|
||||||
|
public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||||
|
{
|
||||||
|
if (parm == null)
|
||||||
|
{
|
||||||
|
throw new CustomException("请求参数错误");
|
||||||
|
}
|
||||||
|
//从 Dto 映射到 实体
|
||||||
|
var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
|
||||||
|
|
||||||
|
var response = _ArticleCategoryService.AddArticleCategory(modal);
|
||||||
|
|
||||||
|
return ToResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新文章目录
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:edit")]
|
||||||
|
[Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)]
|
||||||
|
public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||||
|
{
|
||||||
|
if (parm == null)
|
||||||
|
{
|
||||||
|
throw new CustomException("请求实体不能为空");
|
||||||
|
}
|
||||||
|
//从 Dto 映射到 实体
|
||||||
|
var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
|
||||||
|
|
||||||
|
var response = _ArticleCategoryService.Update(w => w.CategoryId == modal.CategoryId, it => new ArticleCategory()
|
||||||
|
{
|
||||||
|
//Update 字段映射
|
||||||
|
Name = modal.Name,
|
||||||
|
ParentId = modal.ParentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return ToResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除文章目录
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("{ids}")]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:delete")]
|
||||||
|
[Log(Title = "文章目录", BusinessType = BusinessType.DELETE)]
|
||||||
|
public IActionResult DeleteArticleCategory(string ids)
|
||||||
|
{
|
||||||
|
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||||
|
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||||
|
|
||||||
|
var response = _ArticleCategoryService.Delete(idsArr);
|
||||||
|
|
||||||
|
return ToResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出文章目录
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Log(Title = "文章目录", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||||
|
[HttpGet("export")]
|
||||||
|
[ActionPermissionFilter(Permission = "articlecategory:export")]
|
||||||
|
public IActionResult Export([FromQuery] ArticleCategoryQueryDto parm)
|
||||||
|
{
|
||||||
|
parm.PageSize = 10000;
|
||||||
|
var list = _ArticleCategoryService.GetList(parm).Result;
|
||||||
|
|
||||||
|
string sFileName = ExportExcel(list, "ArticleCategory", "文章目录");
|
||||||
|
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取文章目录,前端没用到
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("CategoryList")]
|
||||||
|
public IActionResult CategoryList()
|
||||||
|
{
|
||||||
|
var response = _ArticleCategoryService.GetAll();
|
||||||
|
return SUCCESS(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,17 +1,15 @@
|
|||||||
using Infrastructure.Attribute;
|
using Infrastructure;
|
||||||
|
using Infrastructure.Attribute;
|
||||||
|
using Infrastructure.Enums;
|
||||||
|
using Infrastructure.Model;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SqlSugar;
|
||||||
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Service.System.IService;
|
|
||||||
using Infrastructure.Model;
|
|
||||||
using SqlSugar;
|
|
||||||
using Mapster;
|
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
using Infrastructure.Enums;
|
using ZR.Service.System.IService;
|
||||||
using Infrastructure;
|
|
||||||
using ZR.Admin.WebApi.Extensions;
|
|
||||||
using System.Reflection;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers
|
namespace ZR.Admin.WebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -75,28 +73,6 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
return SUCCESS(response);
|
return SUCCESS(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取文章目录,前端没用到
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("CategoryList")]
|
|
||||||
public IActionResult CategoryList()
|
|
||||||
{
|
|
||||||
var response = _ArticleCategoryService.GetAll();
|
|
||||||
return SUCCESS(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取文章目录树
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet("CategoryTreeList")]
|
|
||||||
public IActionResult CategoryTreeList()
|
|
||||||
{
|
|
||||||
var response = _ArticleCategoryService.BuildCategoryTree(_ArticleCategoryService.GetAll());
|
|
||||||
return SUCCESS(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询文章详情
|
/// 查询文章详情
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -125,7 +101,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
}
|
}
|
||||||
//从 Dto 映射到 实体
|
//从 Dto 映射到 实体
|
||||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||||
addModel.AuthorName = User.Identity.Name;
|
addModel.AuthorName = HttpContext.GetName();
|
||||||
|
|
||||||
return SUCCESS(_ArticleService.Add(addModel));
|
return SUCCESS(_ArticleService.Add(addModel));
|
||||||
}
|
}
|
||||||
|
|||||||
28
ZR.Model/Dto/Article/ArticleCategoryDto.cs
Normal file
28
ZR.Model/Dto/Article/ArticleCategoryDto.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using ZR.Model.Dto;
|
||||||
|
using ZR.Model.Models;
|
||||||
|
|
||||||
|
namespace ZR.Model.Dto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 文章目录输入对象
|
||||||
|
/// </summary>
|
||||||
|
public class ArticleCategoryDto
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "目录id不能为空")]
|
||||||
|
public int CategoryId { get; set; }
|
||||||
|
[Required(ErrorMessage = "目录名不能为空")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
public DateTime? CreateTime { get; set; }
|
||||||
|
public int? ParentId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文章目录查询对象
|
||||||
|
/// </summary>
|
||||||
|
public class ArticleCategoryQueryDto : PagerInfo
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,9 +13,15 @@ namespace ZR.Model.System
|
|||||||
[Tenant("0")]
|
[Tenant("0")]
|
||||||
public class ArticleCategory
|
public class ArticleCategory
|
||||||
{
|
{
|
||||||
public int Category_Id { get; set; }
|
/// <summary>
|
||||||
|
/// 目录id
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsPrimaryKey = true, ColumnName = "Category_id")]
|
||||||
|
public int CategoryId { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int ParentId { get; set; }
|
public int ParentId { get; set; }
|
||||||
|
[SugarColumn(ColumnName = "create_time")]
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
||||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
|||||||
@ -3,72 +3,78 @@ using SqlSugar;
|
|||||||
using SqlSugar.IOC;
|
using SqlSugar.IOC;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using ZR.Model;
|
||||||
|
using ZR.Model.Dto;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
|
using ZR.Repository;
|
||||||
using ZR.Repository.System;
|
using ZR.Repository.System;
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
|
|
||||||
namespace ZR.Service.System
|
namespace ZR.Service.System
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文章目录
|
/// 文章目录Service业务层处理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
|
[AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
|
||||||
public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
|
public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
|
||||||
{
|
{
|
||||||
/// <summary>
|
private readonly ArticleCategoryRepository _ArticleCategoryRepository;
|
||||||
/// 构建前端所需要树结构
|
public ArticleCategoryService(ArticleCategoryRepository repository)
|
||||||
/// </summary>
|
|
||||||
/// <param name="categories">目录列表</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories)
|
|
||||||
{
|
{
|
||||||
List<ArticleCategory> returnList = new List<ArticleCategory>();
|
_ArticleCategoryRepository = repository;
|
||||||
List<int> tempList = categories.Select(f => f.Category_Id).ToList();
|
|
||||||
foreach (var dept in categories)
|
|
||||||
{
|
|
||||||
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
||||||
if (!tempList.Contains(dept.ParentId))
|
|
||||||
{
|
|
||||||
RecursionFn(categories, dept);
|
|
||||||
returnList.Add(dept);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!returnList.Any())
|
|
||||||
{
|
|
||||||
returnList = categories;
|
|
||||||
}
|
|
||||||
return returnList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 递归列表
|
/// 查询文章目录列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="list"></param>
|
/// <param name="parm"></param>
|
||||||
/// <param name="t"></param>
|
/// <returns></returns>
|
||||||
private void RecursionFn(List<ArticleCategory> list, ArticleCategory t)
|
public PagedInfo<ArticleCategory> GetList(ArticleCategoryQueryDto parm)
|
||||||
{
|
{
|
||||||
//得到子节点列表
|
//开始拼装查询条件
|
||||||
List<ArticleCategory> childList = GetChildList(list, t);
|
var predicate = Expressionable.Create<ArticleCategory>();
|
||||||
t.Children = childList;
|
|
||||||
foreach (var item in childList)
|
//搜索条件查询语法参考Sqlsugar
|
||||||
{
|
var response = _ArticleCategoryRepository
|
||||||
if (GetChildList(list, item).Count() > 0)
|
.Queryable()
|
||||||
{
|
.Where(predicate.ToExpression())
|
||||||
RecursionFn(list, item);
|
.ToPage(parm);
|
||||||
}
|
|
||||||
}
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 递归获取子菜单
|
/// 查询文章目录树列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="list">所有菜单</param>
|
/// <param name="parm"></param>
|
||||||
/// <param name="dept"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private List<ArticleCategory> GetChildList(List<ArticleCategory> list, ArticleCategory t)
|
public List<ArticleCategory> GetTreeList(ArticleCategoryQueryDto parm)
|
||||||
{
|
{
|
||||||
return list.Where(p => p.ParentId == t.Category_Id).ToList();
|
//开始拼装查询条件
|
||||||
|
var predicate = Expressionable.Create<ArticleCategory>();
|
||||||
|
|
||||||
|
//搜索条件查询语法参考Sqlsugar
|
||||||
|
|
||||||
|
var response = _ArticleCategoryRepository.Queryable().Where(predicate.ToExpression())
|
||||||
|
.ToTree(it => it.Children, it => it.ParentId, 0);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加文章目录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int AddArticleCategory(ArticleCategory parm)
|
||||||
|
{
|
||||||
|
var response = _ArticleCategoryRepository.Insert(parm, it => new
|
||||||
|
{
|
||||||
|
it.Name,
|
||||||
|
it.CreateTime,
|
||||||
|
it.ParentId,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using ZR.Model;
|
||||||
using System.Linq;
|
using ZR.Model.Dto;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
|
|
||||||
namespace ZR.Service.System.IService
|
namespace ZR.Service.System.IService
|
||||||
{
|
{
|
||||||
public interface IArticleCategoryService : IBaseService<ArticleCategory>
|
public interface IArticleCategoryService : IBaseService<ArticleCategory>
|
||||||
{
|
{
|
||||||
List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories);
|
PagedInfo<ArticleCategory> GetList(ArticleCategoryQueryDto parm);
|
||||||
|
List<ArticleCategory> GetTreeList(ArticleCategoryQueryDto parm);
|
||||||
|
int AddArticleCategory(ArticleCategory parm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
ZRAdmin-vue/src/api/article/articlecategory.js
Normal file
70
ZRAdmin-vue/src/api/article/articlecategory.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章目录分页查询
|
||||||
|
* @param {查询条件} data
|
||||||
|
*/
|
||||||
|
export function listArticleCategory(query) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增文章目录
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export function addArticleCategory(data) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory',
|
||||||
|
method: 'post',
|
||||||
|
data: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改文章目录
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export function updateArticleCategory(data) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory',
|
||||||
|
method: 'PUT',
|
||||||
|
data: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文章目录详情
|
||||||
|
* @param {Id}
|
||||||
|
*/
|
||||||
|
export function getArticleCategory(id) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory/' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文章目录
|
||||||
|
* @param {主键} pid
|
||||||
|
*/
|
||||||
|
export function delArticleCategory(pid) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory/' + pid,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出文章目录
|
||||||
|
export function exportArticleCategory(query) {
|
||||||
|
return request({
|
||||||
|
url: 'article/ArticleCategory/export',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
286
ZRAdmin-vue/src/views/article/ArticleCategory.vue
Normal file
286
ZRAdmin-vue/src/views/article/ArticleCategory.vue
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
<!--
|
||||||
|
* @Descripttion: (文章目录/articleCategory)
|
||||||
|
* @version: (1.0)
|
||||||
|
* @Author: (zr)
|
||||||
|
* @Date: (2022-05-13)
|
||||||
|
* @LastEditors: (zr)
|
||||||
|
* @LastEditTime: (2022-05-13)
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
|
||||||
|
<el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
|
||||||
|
<el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<!-- 工具区域 -->
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" v-hasPermi="['articlecategory:add']" plain icon="plus" @click="handleAdd">
|
||||||
|
{{ $t('btn.add') }}
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="success" :disabled="single" v-hasPermi="['articlecategory:edit']" plain icon="edit" @click="handleUpdate">
|
||||||
|
{{ $t('btn.edit') }}
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" :disabled="multiple" v-hasPermi="['articlecategory:delete']" plain icon="delete" @click="handleDelete">
|
||||||
|
{{ $t('btn.delete') }}
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="warning" plain icon="download" @click="handleExport" v-hasPermi="['articlecategory:export']">
|
||||||
|
{{ $t('btn.export') }}
|
||||||
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<!-- 数据区域 -->
|
||||||
|
<el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="50" align="center"/>
|
||||||
|
|
||||||
|
<el-table-column prop="categoryId" label="目录id" align="center" />
|
||||||
|
<el-table-column prop="name" label="目录名" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column prop="createTime" label="添加时间" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column prop="parentId" label="父级id" align="center" />
|
||||||
|
|
||||||
|
<el-table-column label="操作" align="center" width="140">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button v-hasPermi="['articlecategory:edit']" type="success" icon="edit" title="编辑"
|
||||||
|
@click="handleUpdate(scope.row)"></el-button>
|
||||||
|
<el-button v-hasPermi="['articlecategory:delete']" type="danger" icon="delete" title="删除"
|
||||||
|
@click="handleDelete(scope.row)"></el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<pagination class="mt10" background :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||||||
|
|
||||||
|
<!-- 添加或修改文章目录对话框 -->
|
||||||
|
<el-dialog :title="title" :lock-scroll="false" v-model="open" >
|
||||||
|
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||||
|
<el-row :gutter="20">
|
||||||
|
|
||||||
|
<el-col :lg="12" v-if="opertype == 2">
|
||||||
|
<el-form-item label="目录id">{{form.categoryId}}</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :lg="12">
|
||||||
|
<el-form-item label="目录名" prop="name">
|
||||||
|
<el-input v-model="form.name" placeholder="请输入目录名" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :lg="12">
|
||||||
|
<el-form-item label="添加时间" prop="createTime">
|
||||||
|
<el-date-picker v-model="form.createTime" type="datetime" placeholder="选择日期时间"></el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :lg="12">
|
||||||
|
<el-form-item label="父级id" prop="parentId">
|
||||||
|
<el-input v-model="form.parentId" placeholder="请输入父级id" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button type="text" @click="cancel">{{ $t('btn.cancel') }}</el-button>
|
||||||
|
<el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<script setup name="articlecategory">
|
||||||
|
import { listArticleCategory, addArticleCategory, delArticleCategory, updateArticleCategory, getArticleCategory,
|
||||||
|
exportArticleCategory, } from '@/api/article/articlecategory.js'
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance()
|
||||||
|
// 选中categoryId数组数组
|
||||||
|
const ids = ref([])
|
||||||
|
// 非单选禁用
|
||||||
|
const single = ref(true)
|
||||||
|
// 非多个禁用
|
||||||
|
const multiple = ref(true)
|
||||||
|
// 遮罩层
|
||||||
|
const loading = ref(false)
|
||||||
|
// 显示搜索条件
|
||||||
|
const showSearch = ref(true)
|
||||||
|
// 查询参数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
sort: undefined,
|
||||||
|
sortType: undefined,
|
||||||
|
})
|
||||||
|
// 弹出层标题
|
||||||
|
const title = ref("")
|
||||||
|
// 操作类型 1、add 2、edit
|
||||||
|
const opertype = ref(0)
|
||||||
|
// 是否显示弹出层
|
||||||
|
const open = ref(false)
|
||||||
|
// 表单参数
|
||||||
|
const state = reactive({
|
||||||
|
form: {},
|
||||||
|
rules: {
|
||||||
|
name: [{ required: true, message: "目录名不能为空", trigger: "blur" }],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const { form, rules } = toRefs(state)
|
||||||
|
// 总记录数
|
||||||
|
const total = ref(0)
|
||||||
|
const dataList = ref([])
|
||||||
|
const queryRef = ref()
|
||||||
|
const formRef = ref()
|
||||||
|
|
||||||
|
var dictParams = [
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
function getList(){
|
||||||
|
loading.value = true
|
||||||
|
listArticleCategory(queryParams).then(res => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
dataList.value = res.data.result
|
||||||
|
total.value = res.data.totalNum
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭dialog
|
||||||
|
function cancel(){
|
||||||
|
open.value = false
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置表单
|
||||||
|
function reset() {
|
||||||
|
proxy.resetForm("formRef")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询
|
||||||
|
function handleQuery() {
|
||||||
|
queryParams.pageNum = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加
|
||||||
|
function handleAdd() {
|
||||||
|
reset();
|
||||||
|
open.value = true
|
||||||
|
title.value = '添加'
|
||||||
|
opertype.value = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除按钮操作
|
||||||
|
function handleDelete(row) {
|
||||||
|
const Ids = row.categoryId || ids.value
|
||||||
|
|
||||||
|
proxy.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项?')
|
||||||
|
.then(function () {
|
||||||
|
return delArticleCategory(Ids)
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
handleQuery()
|
||||||
|
proxy.$modal.msgSuccess("删除成功")
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改按钮操作
|
||||||
|
function handleUpdate(row) {
|
||||||
|
reset()
|
||||||
|
const id = row.categoryId || ids.value
|
||||||
|
getArticleCategory(id).then((res) => {
|
||||||
|
const { code, data } = res
|
||||||
|
if (code == 200) {
|
||||||
|
open.value = true
|
||||||
|
title.value = "修改数据"
|
||||||
|
opertype.value = 2
|
||||||
|
|
||||||
|
form.value = {
|
||||||
|
...data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单提交
|
||||||
|
function submitForm() {
|
||||||
|
proxy.$refs["formRef"].validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
if (form.value.categoryId != undefined && opertype.value === 2) {
|
||||||
|
updateArticleCategory(form.value).then((res) => {
|
||||||
|
proxy.$modal.msgSuccess("修改成功")
|
||||||
|
open.value = false
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
} else {
|
||||||
|
addArticleCategory(form.value).then((res) => {
|
||||||
|
proxy.$modal.msgSuccess("新增成功")
|
||||||
|
open.value = false
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
//TODO 错误逻辑
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置查询操作
|
||||||
|
function resetQuery(){
|
||||||
|
proxy.resetForm("queryRef")
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
// 导出按钮操作
|
||||||
|
function handleExport() {
|
||||||
|
proxy
|
||||||
|
.$confirm("是否确认导出所有文章目录数据项?", "警告", {
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
type: "warning",
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
return exportArticleCategory(queryParams)
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
proxy.download(response.data.path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 多选框选中数据
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection.map((item) => item.categoryId);
|
||||||
|
single.value = selection.length != 1
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义排序
|
||||||
|
function sortChange(column) {
|
||||||
|
if (column.prop == null || column.order == null) {
|
||||||
|
queryParams.sort = undefined
|
||||||
|
queryParams.sortType = undefined
|
||||||
|
} else {
|
||||||
|
queryParams.sort = column.prop
|
||||||
|
queryParams.sortType = column.order
|
||||||
|
}
|
||||||
|
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleQuery()
|
||||||
|
</script>
|
||||||
@ -404,6 +404,25 @@ VALUES ('删除', @langMenuId, 3, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:d
|
|||||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
VALUES ('修改', @langMenuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:edit', '', 'system', sysdate());
|
VALUES ('修改', @langMenuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:edit', '', 'system', sysdate());
|
||||||
|
|
||||||
|
|
||||||
|
-- 文章目录菜单
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('文章目录', 118, 999, 'ArticleCategory', 'system/article/articleCategory', 0, 0, 'C', '0', '0', 'articlecategory:list', 'tree-table', 'system', sysdate());
|
||||||
|
-- 按钮父菜单id
|
||||||
|
SELECT @cmenuId := LAST_INSERT_ID();
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('查询', @cmenuId, 1, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:query', '', 'system', sysdate());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('新增', @cmenuId, 2, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:add', '', 'system', sysdate());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('删除', @cmenuId, 3, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:delete', '', 'system', sysdate());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('修改', @cmenuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:edit', '', 'system', sysdate());
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for sys_oper_log
|
-- Table structure for sys_oper_log
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
|||||||
@ -386,8 +386,29 @@ VALUES ('修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:edit'
|
|||||||
|
|
||||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:export', '', 'system', GETDATE());
|
VALUES ('导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', 'system:lang:export', '', 'system', GETDATE());
|
||||||
|
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
-- 文章目录菜单
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time)
|
||||||
|
VALUES ('文章目录', 118, 999, 'ArticleCategory', 'system/article/articleCategory', 0, 0, 'C', '0', '0', 'articlecategory:list', 'tree-table', 'system', GETDATE());
|
||||||
|
-- 按钮父菜单id
|
||||||
|
DECLARE @cmenuId int = @@identity
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
|
VALUES ('查询', @cmenuId, 1, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:query', '', 'system', GETDATE());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
|
VALUES ('新增', @cmenuId, 2, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:add', '', 'system', GETDATE());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
|
VALUES ('删除', @cmenuId, 3, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:delete', '', 'system', GETDATE());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
|
VALUES ('修改', @cmenuId, 4, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:edit', '', 'system', GETDATE());
|
||||||
|
|
||||||
|
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||||
|
VALUES ('导出', @cmenuId, 5, '#', NULL, 0, 0, 'F', '0', '0', 'articlecategory:export', '', 'system', GETDATE());
|
||||||
|
GO
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- = '操作日志记录'
|
-- = '操作日志记录'
|
||||||
-- Table structure for sys_oper_log
|
-- Table structure for sys_oper_log
|
||||||
@ -653,7 +674,7 @@ CREATE TABLE articleCategory (
|
|||||||
create_time datetime NULL DEFAULT NULL , -- '创建时间',
|
create_time datetime NULL DEFAULT NULL , -- '创建时间',
|
||||||
parentId int NULL DEFAULT 0 , -- '父级ID',
|
parentId int NULL DEFAULT 0 , -- '父级ID',
|
||||||
)
|
)
|
||||||
|
GO
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of articleCategory
|
-- Records of articleCategory
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user