u
This commit is contained in:
1 parent
5221d1cc91
commit
a8a2657753
30 files changed
+552
-255
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
package cn.link56.post.controller;
|
||||
|
||||
import cn.link56.common.BasePageVO;
|
||||
import cn.link56.common.Result;
|
||||
import cn.link56.post.model.dto.*;
|
||||
import cn.link56.post.model.vo.EditorDashboardVO;
|
||||
import cn.link56.post.model.vo.EditorPostVO;
|
||||
import cn.link56.post.model.vo.QueryEditorPostVO;
|
||||
import cn.link56.post.service.PostService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/editor/post")
|
||||
public class EditorPostController {
|
||||
@Resource
|
||||
private PostService postService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Result<EditorPostVO> getEditDetail(@PathVariable("id") Long id) {
|
||||
EditorPostVO editorPostVO = postService.getEditDetail(id);
|
||||
return Result.success(editorPostVO);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public Result<EditorPostVO> createPost(@RequestBody @Validated CreatePostDTO createPostDTO) {
|
||||
EditorPostVO editorPostVO = postService.createPost(createPostDTO);
|
||||
return Result.success(editorPostVO);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Result<EditorPostVO> updatePost(@RequestBody @Validated UpdatePostDTO updatePostDTO){
|
||||
EditorPostVO editorPostVO = postService.updatePost(updatePostDTO);
|
||||
return Result.success(editorPostVO);
|
||||
}
|
||||
|
||||
@PostMapping("/update/status")
|
||||
public Result<EditorPostVO> updatePostStatus(@RequestBody @Validated UpdatePostStatusDTO updatePostStatusDTO){
|
||||
postService.updatePostStatus(updatePostStatusDTO);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Result<Void> deletePost(@RequestBody @Validated DeletePostDTO deletePostDTO){
|
||||
postService.deletePost(deletePostDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public Result<BasePageVO<QueryEditorPostVO>> queryEditorPosts(@RequestBody QueryEditorPostDTO queryEditorPostDTO){
|
||||
BasePageVO<QueryEditorPostVO> data = postService.queryEditorPosts(queryEditorPostDTO);
|
||||
return Result.success(data);
|
||||
}
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
public Result<EditorDashboardVO> getEditorDashboard(){
|
||||
EditorDashboardVO editorDashboardVO = postService.getEditorDashboard();
|
||||
|
||||
return Result.success(editorDashboardVO);
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package cn.link56.post.controller;
|
||||
|
||||
import cn.link56.common.Result;
|
||||
import cn.link56.post.model.vo.PostCategoryVO;
|
||||
import cn.link56.post.model.vo.PostTagVO;
|
||||
import cn.link56.post.service.PostCategoryService;
|
||||
import cn.link56.post.service.PostTagService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/post/category")
|
||||
public class PostCategoryController {
|
||||
@Resource
|
||||
private PostCategoryService postCategoryService;
|
||||
|
||||
@GetMapping
|
||||
public Result<List<PostCategoryVO>> listCategories(){
|
||||
List<PostCategoryVO> list = postCategoryService.listCategories();
|
||||
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
+14
-45
@@ -2,65 +2,34 @@ package cn.link56.post.controller;
|
||||
|
||||
import cn.link56.common.BasePageVO;
|
||||
import cn.link56.common.Result;
|
||||
import cn.link56.post.model.dto.*;
|
||||
import cn.link56.post.model.vo.EditPostVO;
|
||||
import cn.link56.post.model.vo.DashboardVO;
|
||||
import cn.link56.post.model.vo.QueryPostVO;
|
||||
import cn.link56.post.model.dto.QueryPublicPostDTO;
|
||||
import cn.link56.post.model.vo.PostTagVO;
|
||||
import cn.link56.post.model.vo.QueryPublicPostVO;
|
||||
import cn.link56.post.service.PostService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import cn.link56.post.service.PostTagService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/post")
|
||||
public class PostController {
|
||||
|
||||
@Resource
|
||||
private PostService postService;
|
||||
@Resource
|
||||
private PostTagService postTagService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Result<EditPostVO> getDetail(@PathVariable("id") Long id) {
|
||||
EditPostVO editPostVO = postService.getDetail(id);
|
||||
return Result.success(editPostVO);
|
||||
}
|
||||
@GetMapping("/tag")
|
||||
public Result<List<PostTagVO>> listTags(){
|
||||
List<PostTagVO> list = postTagService.listTags();
|
||||
|
||||
@PostMapping("/add")
|
||||
public Result<EditPostVO> addPost(@RequestBody @Validated AddPostDTO addPostDTO) {
|
||||
EditPostVO editPostVO = postService.addPost(addPostDTO);
|
||||
return Result.success(editPostVO);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public Result<EditPostVO> updatePost(@RequestBody @Validated UpdatePostDTO updatePostDTO){
|
||||
EditPostVO editPostVO = postService.updatePost(updatePostDTO);
|
||||
return Result.success(editPostVO);
|
||||
}
|
||||
|
||||
@PostMapping("/update/status")
|
||||
public Result<EditPostVO> updatePostStatus(@RequestBody @Validated UpdatePostStatusDTO updatePostStatusDTO){
|
||||
postService.updatePostStatus(updatePostStatusDTO);
|
||||
|
||||
return Result.success();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public Result<BasePageVO<QueryPostVO>> queryPost(@RequestBody QueryPostDTO queryPostDTO){
|
||||
BasePageVO<QueryPostVO> data = postService.queryPost(queryPostDTO);
|
||||
return Result.success(data);
|
||||
public Result<BasePageVO<QueryPublicPostVO>> queryPublicPosts(@RequestBody QueryPublicPostDTO dto){
|
||||
BasePageVO<QueryPublicPostVO> res = postService.queryPublicPosts(dto);
|
||||
return Result.success(res);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Result<Void> deletePost(@RequestBody @Validated DeletePostDTO deletePostDTO){
|
||||
postService.deletePost(deletePostDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
public Result<DashboardVO> getDashboardData(){
|
||||
DashboardVO dashboardVO = postService.getDashboardData();
|
||||
|
||||
return Result.success(dashboardVO);
|
||||
}
|
||||
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package cn.link56.post.controller;
|
||||
|
||||
import cn.link56.common.Result;
|
||||
import cn.link56.post.mapper.PostTagMapper;
|
||||
import cn.link56.post.model.vo.PostTagVO;
|
||||
import cn.link56.post.service.PostTagService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/post/tag")
|
||||
public class PostTagController {
|
||||
@Resource
|
||||
private PostTagService postTagService;
|
||||
|
||||
@GetMapping
|
||||
public Result<List<PostTagVO>> listTags(){
|
||||
List<PostTagVO> list = postTagService.listTags();
|
||||
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package cn.link56.post.mapper;
|
||||
|
||||
import cn.link56.post.model.po.Post;
|
||||
import cn.link56.post.model.vo.DashboardVO;
|
||||
import cn.link56.post.model.vo.QueryPostVO;
|
||||
import cn.link56.post.model.vo.EditorDashboardVO;
|
||||
import cn.link56.post.model.vo.QueryEditorPostVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper extends BaseMapper<Post> {
|
||||
List<QueryPostVO> selectPostPage(
|
||||
List<QueryEditorPostVO> selectEditorPostPage(
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit,
|
||||
@Param("userId") Long userId,
|
||||
@@ -21,7 +21,7 @@ public interface PostMapper extends BaseMapper<Post> {
|
||||
@Param("month") String month
|
||||
);
|
||||
|
||||
Long selectPostTotal(
|
||||
Long selectEditorPostTotal(
|
||||
@Param("userId") Long userId,
|
||||
@Param("title") String title,
|
||||
@Param("status") Integer status,
|
||||
@@ -29,8 +29,8 @@ public interface PostMapper extends BaseMapper<Post> {
|
||||
@Param("month") String month
|
||||
);
|
||||
|
||||
DashboardVO.Count selectDashboardOverview(@Param("userId") Long userId);
|
||||
EditorDashboardVO.Count selectDashboardOverview(@Param("userId") Long userId);
|
||||
|
||||
List<DashboardVO.Chart> selectDashboardViewStats(@Param("userId") Long userId);
|
||||
List<DashboardVO.Chart> selectDashboardNumberStats(@Param("userId") Long userId);
|
||||
List<EditorDashboardVO.Chart> selectDashboardViewStats(@Param("userId") Long userId);
|
||||
List<EditorDashboardVO.Chart> selectDashboardNumberStats(@Param("userId") Long userId);
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AddPostDTO {
|
||||
public class CreatePostDTO {
|
||||
@NotBlank(message = "帖子标题不能为空")
|
||||
private String title;
|
||||
@NotBlank(message = "帖子内容不能为空")
|
||||
+1
-1
@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPostDTO {
|
||||
public class QueryEditorPostDTO {
|
||||
private Integer currentPage;
|
||||
private Integer pageSize;
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.link56.post.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPublicPostDTO {
|
||||
private String title;
|
||||
private String tag;
|
||||
}
|
||||
@@ -18,6 +18,9 @@ public class PostTag {
|
||||
@TableField("b_name")
|
||||
private String name;
|
||||
|
||||
@TableField("b_icon")
|
||||
private String icon;
|
||||
|
||||
@TableField("b_canuse")
|
||||
private String canuse;
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DashboardVO {
|
||||
public class EditorDashboardVO {
|
||||
private Count allCount;
|
||||
private List<Chart> numberChart;
|
||||
private List<Chart> viewChart;
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EditPostVO {
|
||||
public class EditorPostVO {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String content;
|
||||
@@ -10,4 +10,5 @@ import lombok.NoArgsConstructor;
|
||||
public class PostCategoryVO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String icon;
|
||||
}
|
||||
@@ -10,4 +10,5 @@ import lombok.NoArgsConstructor;
|
||||
public class PostTagVO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String icon;
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPostVO {
|
||||
public class QueryEditorPostVO {
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package cn.link56.post.model.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryPublicPostVO {
|
||||
private Long id;
|
||||
private String title;
|
||||
private List<String> tags;
|
||||
|
||||
private Long companyId;
|
||||
private String companyName;
|
||||
|
||||
private Integer viewCount;
|
||||
private Integer commentCount;
|
||||
|
||||
private Date activeTime;
|
||||
}
|
||||
@@ -7,9 +7,10 @@ import cn.link56.post.mapper.PostMapper;
|
||||
import cn.link56.post.model.dto.*;
|
||||
import cn.link56.post.model.enums.PostStatusEnum;
|
||||
import cn.link56.post.model.po.Post;
|
||||
import cn.link56.post.model.vo.DashboardVO;
|
||||
import cn.link56.post.model.vo.EditPostVO;
|
||||
import cn.link56.post.model.vo.QueryPostVO;
|
||||
import cn.link56.post.model.vo.EditorDashboardVO;
|
||||
import cn.link56.post.model.vo.EditorPostVO;
|
||||
import cn.link56.post.model.vo.QueryEditorPostVO;
|
||||
import cn.link56.post.model.vo.QueryPublicPostVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -30,7 +31,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
private PostMapper postMapper;
|
||||
|
||||
@Transactional
|
||||
public EditPostVO addPost(AddPostDTO dto) {
|
||||
public EditorPostVO createPost(CreatePostDTO dto) {
|
||||
Post post = new Post();
|
||||
BeanUtils.copyProperties(dto, post);
|
||||
|
||||
@@ -44,7 +45,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
return buildEditPostVO(post);
|
||||
}
|
||||
|
||||
public EditPostVO updatePost(UpdatePostDTO dto) {
|
||||
public EditorPostVO updatePost(UpdatePostDTO dto) {
|
||||
Post post = postMapper.selectById(dto.getId());
|
||||
if (post == null) {
|
||||
return null;
|
||||
@@ -59,7 +60,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
return buildEditPostVO(post);
|
||||
}
|
||||
|
||||
public EditPostVO getDetail(Long id) {
|
||||
public EditorPostVO getEditDetail(Long id) {
|
||||
Post post = postMapper.selectById(id);
|
||||
if (post == null) {
|
||||
return null;
|
||||
@@ -68,11 +69,11 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
return buildEditPostVO(post);
|
||||
}
|
||||
|
||||
public BasePageVO<QueryPostVO> queryPost(QueryPostDTO dto) {
|
||||
public BasePageVO<QueryEditorPostVO> queryEditorPosts(QueryEditorPostDTO dto) {
|
||||
int offset = (dto.getCurrentPage() - 1) * dto.getPageSize() + 1;
|
||||
int limit = dto.getCurrentPage() * dto.getPageSize();
|
||||
|
||||
List<QueryPostVO> records = postMapper.selectPostPage(
|
||||
List<QueryEditorPostVO> records = postMapper.selectEditorPostPage(
|
||||
offset,
|
||||
limit,
|
||||
UserContext.getUserId(),
|
||||
@@ -82,7 +83,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
dto.getMonth()
|
||||
);
|
||||
|
||||
Long total = postMapper.selectPostTotal(
|
||||
Long total = postMapper.selectEditorPostTotal(
|
||||
UserContext.getUserId(),
|
||||
dto.getTitle(),
|
||||
dto.getStatus(),
|
||||
@@ -90,7 +91,7 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
dto.getMonth()
|
||||
);
|
||||
|
||||
BasePageVO<QueryPostVO> page = new BasePageVO<>();
|
||||
BasePageVO<QueryEditorPostVO> page = new BasePageVO<>();
|
||||
page.setRecords(records);
|
||||
page.setTotal(total);
|
||||
return page;
|
||||
@@ -98,8 +99,8 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
|
||||
/* ================= 私有方法 ================= */
|
||||
|
||||
private EditPostVO buildEditPostVO(Post post) {
|
||||
EditPostVO vo = new EditPostVO();
|
||||
private EditorPostVO buildEditPostVO(Post post) {
|
||||
EditorPostVO vo = new EditorPostVO();
|
||||
BeanUtils.copyProperties(post, vo);
|
||||
|
||||
vo.setTags(
|
||||
@@ -142,45 +143,45 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
postMapper.updateById(post);
|
||||
}
|
||||
|
||||
public DashboardVO getDashboardData() {
|
||||
public EditorDashboardVO getEditorDashboard() {
|
||||
Long userId = UserContext.getUserId();
|
||||
|
||||
DashboardVO dashboardVO = new DashboardVO();
|
||||
EditorDashboardVO editorDashboardVO = new EditorDashboardVO();
|
||||
|
||||
DashboardVO.Count count = postMapper.selectDashboardOverview(userId);
|
||||
EditorDashboardVO.Count count = postMapper.selectDashboardOverview(userId);
|
||||
|
||||
// 原始数据
|
||||
List<DashboardVO.Chart> viewCharts = postMapper.selectDashboardViewStats(userId);
|
||||
List<DashboardVO.Chart> numberCharts = postMapper.selectDashboardNumberStats(userId);
|
||||
List<DashboardVO.Chart> typeCharts = getDashboardTypeStats(userId);
|
||||
List<EditorDashboardVO.Chart> viewCharts = postMapper.selectDashboardViewStats(userId);
|
||||
List<EditorDashboardVO.Chart> numberCharts = postMapper.selectDashboardNumberStats(userId);
|
||||
List<EditorDashboardVO.Chart> typeCharts = getDashboardTypeStats(userId);
|
||||
|
||||
// 统一处理最近 7 天,补齐缺失值
|
||||
dashboardVO.setViewChart(fillLast7Days(viewCharts));
|
||||
dashboardVO.setNumberChart(fillLast7Days(numberCharts));
|
||||
dashboardVO.setTypeChart(typeCharts);
|
||||
editorDashboardVO.setViewChart(fillLast7Days(viewCharts));
|
||||
editorDashboardVO.setNumberChart(fillLast7Days(numberCharts));
|
||||
editorDashboardVO.setTypeChart(typeCharts);
|
||||
|
||||
dashboardVO.setAllCount(count);
|
||||
return dashboardVO;
|
||||
editorDashboardVO.setAllCount(count);
|
||||
return editorDashboardVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充最近7天的 chart 数据,如果 map 里没有,则补 0
|
||||
*/
|
||||
private List<DashboardVO.Chart> fillLast7Days(List<DashboardVO.Chart> originalCharts) {
|
||||
private List<EditorDashboardVO.Chart> fillLast7Days(List<EditorDashboardVO.Chart> originalCharts) {
|
||||
// 转 map,方便查
|
||||
Map<String, Integer> map = originalCharts.stream()
|
||||
.collect(Collectors.toMap(DashboardVO.Chart::getLabel, DashboardVO.Chart::getValue, (a, b) -> b));
|
||||
.collect(Collectors.toMap(EditorDashboardVO.Chart::getLabel, EditorDashboardVO.Chart::getValue, (a, b) -> b));
|
||||
|
||||
List<DashboardVO.Chart> result = new ArrayList<>();
|
||||
List<EditorDashboardVO.Chart> result = new ArrayList<>();
|
||||
for (int i = 6; i >= 0; i--) {
|
||||
String date = LocalDate.now().minusDays(i).toString();
|
||||
result.add(new DashboardVO.Chart(date, map.getOrDefault(date, 0)));
|
||||
result.add(new EditorDashboardVO.Chart(date, map.getOrDefault(date, 0)));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<DashboardVO.Chart> getDashboardTypeStats(Long userId) {
|
||||
private List<EditorDashboardVO.Chart> getDashboardTypeStats(Long userId) {
|
||||
LambdaQueryWrapper<Post> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper
|
||||
.select(Post::getTag)
|
||||
@@ -209,10 +210,19 @@ public class PostService extends ServiceImpl<PostMapper, Post> {
|
||||
}
|
||||
|
||||
// 转成 DashboardVO.Chart 列表
|
||||
List<DashboardVO.Chart> result = new ArrayList<>();
|
||||
tagCountMap.forEach((tag, count) -> result.add(new DashboardVO.Chart(tag, count)));
|
||||
List<EditorDashboardVO.Chart> result = new ArrayList<>();
|
||||
tagCountMap.forEach((tag, count) -> result.add(new EditorDashboardVO.Chart(tag, count)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public BasePageVO<QueryPublicPostVO> queryPublicPosts(QueryPublicPostDTO dto) {
|
||||
String title = dto.getTitle();
|
||||
String tag = dto.getTag();
|
||||
|
||||
|
||||
BasePageVO<QueryPublicPostVO> result = new BasePageVO<>();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.link56.post.mapper.PostMapper">
|
||||
|
||||
<resultMap id="QueryPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryPostVO">
|
||||
<resultMap id="QueryEditorPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryEditorPostVO">
|
||||
<id property="id" column="id"/>
|
||||
<result property="title" column="title"/>
|
||||
|
||||
@@ -25,7 +25,27 @@
|
||||
<result property="commentCount" column="commentCount"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPostPage" resultMap="QueryPostVOMap">
|
||||
<resultMap id="QueryPublicPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryPublicPostVO">
|
||||
<id property="id" column="id"/>
|
||||
<result property="title" column="title"/>
|
||||
|
||||
<!-- tags 字符串 → List<String> -->
|
||||
<result
|
||||
property="tags"
|
||||
column="tagsString"
|
||||
typeHandler="cn.link56.common.mybatis.StringListTypeHandler"/>
|
||||
|
||||
<result property="companyId" column="companyId"/>
|
||||
<result property="companyName" column="companyName"/>
|
||||
|
||||
<result property="viewCount" column="viewCount"/>
|
||||
<result property="commentCount" column="commentCount"/>
|
||||
|
||||
<result property="activeTime" column="activeTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectEditorPostPage" resultMap="QueryEditorPostVOMap">
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
@@ -68,7 +88,7 @@
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectPostTotal" resultType="java.lang.Long">
|
||||
<select id="selectEditorPostTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM b_post p
|
||||
<where>
|
||||
@@ -94,7 +114,7 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardOverview" resultType="cn.link56.post.model.vo.DashboardVO$Count">
|
||||
<select id="selectDashboardOverview" resultType="cn.link56.post.model.vo.EditorDashboardVO$Count">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM b_post WHERE b_create_by = #{userId}) AS postCount,
|
||||
(SELECT COUNT(*) FROM b_post_view WHERE b_post_id IN (SELECT b_id FROM b_post WHERE b_create_by = #{userId})) AS viewCount,
|
||||
@@ -102,7 +122,7 @@
|
||||
(SELECT COUNT(*) FROM b_post_favorite WHERE b_post_id IN (SELECT b_id FROM b_post WHERE b_create_by = #{userId})) AS favoriteCount
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardViewStats" resultType="cn.link56.post.model.vo.DashboardVO$Chart">
|
||||
<select id="selectDashboardViewStats" resultType="cn.link56.post.model.vo.EditorDashboardVO$Chart">
|
||||
SELECT
|
||||
CONVERT(VARCHAR(10), v.b_create_time, 120) AS label,
|
||||
COUNT(*) AS value
|
||||
@@ -115,7 +135,7 @@
|
||||
ORDER BY label
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardNumberStats" resultType="cn.link56.post.model.vo.DashboardVO$Chart">
|
||||
<select id="selectDashboardNumberStats" resultType="cn.link56.post.model.vo.EditorDashboardVO$Chart">
|
||||
SELECT
|
||||
CONVERT(VARCHAR(10), p.b_create_time, 120) AS label,
|
||||
COUNT(*) AS value
|
||||
@@ -127,4 +147,61 @@
|
||||
ORDER BY label
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectPublicPostPage" resultMap="QueryPublicPostVOMap">
|
||||
SELECT
|
||||
t.id,
|
||||
t.title,
|
||||
t.tagsString,
|
||||
t.companyId,
|
||||
t.companyName,
|
||||
t.viewCount,
|
||||
t.commentCount,
|
||||
t.activeTime
|
||||
FROM (
|
||||
SELECT
|
||||
p.b_id AS id,
|
||||
p.b_title AS title,
|
||||
p.b_tag AS tagsString,
|
||||
p.company_id AS companyId,
|
||||
bc.b_name AS companyName,
|
||||
|
||||
ISNULL(pv.viewCount, 0) AS viewCount,
|
||||
ISNULL(pc.commentCount, 0) AS commentCount,
|
||||
|
||||
-- 活跃时间:最后评论时间优先
|
||||
ISNULL(pc.lastCommentTime, p.b_update_time) AS activeTime,
|
||||
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY ISNULL(pc.lastCommentTime, p.b_update_time) DESC
|
||||
) AS rn
|
||||
FROM b_post p
|
||||
LEFT JOIN b_company bc ON bc.b_id = p.company_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS viewCount
|
||||
FROM b_post_view
|
||||
GROUP BY b_post_id
|
||||
) pv ON pv.b_post_id = p.b_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS commentCount,
|
||||
MAX(b_create_time) AS lastCommentTime
|
||||
FROM b_post_comment
|
||||
GROUP BY b_post_id
|
||||
) pc ON pc.b_post_id = p.b_id
|
||||
<where>
|
||||
<if test="title != null and title != ''">
|
||||
AND p.b_title LIKE '%' + #{title} + '%'
|
||||
</if>
|
||||
<if test="tag != null and tag != -1">
|
||||
AND p.b_tag LIKE '%' + #{tag} + '%'
|
||||
</if>
|
||||
</where>
|
||||
) t
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,8 +1,10 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PostTag } from './types/base'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { onMounted } from 'vue'
|
||||
import { initBaseApi } from '@/request/api/base'
|
||||
import { useCommonStore } from '@/store/common'
|
||||
import { getPostTagApi } from './request/api/post'
|
||||
|
||||
const commonOptions = useCommonStore()
|
||||
|
||||
@@ -25,6 +27,31 @@ function handleInitData() {
|
||||
ElMessage.error('初始化失败,请刷新页面后重试')
|
||||
})
|
||||
|
||||
getPostTagApi()
|
||||
.then((res) => {
|
||||
console.log(res)
|
||||
if (res.isSuccess) {
|
||||
const list: PostTag[] = res.data || []
|
||||
|
||||
commonOptions.postTagOptions.splice(
|
||||
0,
|
||||
commonOptions.postTagOptions.length,
|
||||
{
|
||||
id: 0,
|
||||
name: '全部',
|
||||
icon: 'fluent-color:apps-28',
|
||||
},
|
||||
...list,
|
||||
)
|
||||
}
|
||||
else {
|
||||
ElMessage.error(res.message || '初始化失败,请刷新页面后重试')
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
ElMessage.error('初始化失败,请刷新页面后重试')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -132,42 +132,25 @@ function isActive(path: string) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
color: #000;
|
||||
color: #9aa0a6;
|
||||
outline: none;
|
||||
margin-left: 36px;
|
||||
transition: color 0.3s ease;
|
||||
position: relative;
|
||||
|
||||
&:hover {
|
||||
color: #0f6fec !important;
|
||||
color: #2f2f2f !important;
|
||||
}
|
||||
&:first-child {
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: #0f6fec !important;
|
||||
}
|
||||
color: #2f2f2f !important;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
bottom: -8px;
|
||||
left: 50%;
|
||||
width: 0;
|
||||
height: 2px;
|
||||
background-color: #0f6fec;
|
||||
transition: all 0.3s ease;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
&:hover::after {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&.active::after {
|
||||
width: 100%;
|
||||
.menu-item-name {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-item-name {
|
||||
|
||||
@@ -8,9 +8,9 @@ import Header from './components/header.vue'
|
||||
<div class="content">
|
||||
<RouterView />
|
||||
</div>
|
||||
<footer class="footer">
|
||||
<!-- <footer class="footer">
|
||||
TODO
|
||||
</footer>
|
||||
</footer> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { DashboardData, PostTag } from '@/types/post'
|
||||
import type {
|
||||
CreatePostParams,
|
||||
DeletePostParams,
|
||||
Post,
|
||||
PostEditorForm,
|
||||
QueryPostParams,
|
||||
UpdatePostParams,
|
||||
UpdatePostStatusParams,
|
||||
} from '@/types/post/editor'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
// ===== 编辑端 API =====
|
||||
export function createPostApi(params: CreatePostParams) {
|
||||
return httpPostJson<PostEditorForm>('/editor/post/create', params)
|
||||
}
|
||||
|
||||
export function updatePostApi(params: UpdatePostParams) {
|
||||
return httpPostJson<PostEditorForm>('/editor/post/update', params)
|
||||
}
|
||||
|
||||
export function updatePostStatusApi(params: UpdatePostStatusParams) {
|
||||
return httpPostJson<PostEditorForm>('/editor/post/update/status', params)
|
||||
}
|
||||
|
||||
export function queryEditorPostsApi(params: QueryPostParams) {
|
||||
return httpPostJson<BasePageResult<Post>>('/editor/post/query', params)
|
||||
}
|
||||
|
||||
export function getEditorPostApi(id: number) {
|
||||
return httpGet<PostEditorForm>(`/editor/post/${id}`)
|
||||
}
|
||||
|
||||
export function deletePostApi(params: DeletePostParams) {
|
||||
return httpPostJson<void>('/editor/post/delete', params)
|
||||
}
|
||||
|
||||
export function getEditorDashboardApi() {
|
||||
return httpGet<DashboardData>(`/editor/post/dashboard`)
|
||||
}
|
||||
@@ -1,38 +1,7 @@
|
||||
import type { DashboardData, PostCategory, PostTag } from '@/types/post'
|
||||
import type { AddPostParams, DeletePostParams, Post, PostEditorForm, QueryPostParams, UpdatePostParams, UpdatePostStatusParams } from '@/types/post/editor'
|
||||
import type { PostTag } from '@/types/post'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
export function addPostApi(params: AddPostParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/add', params)
|
||||
}
|
||||
|
||||
export function updatePostApi(params: UpdatePostParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/update', params)
|
||||
}
|
||||
|
||||
export function updatePostStatusApi(params: UpdatePostStatusParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/update/status', params)
|
||||
}
|
||||
|
||||
export function queryPostApi(params: QueryPostParams) {
|
||||
return httpPostJson<BasePageResult<Post>>('/post/query', params)
|
||||
}
|
||||
|
||||
export function getPostApi(id: number) {
|
||||
return httpGet<PostEditorForm>(`/post/${id}`)
|
||||
}
|
||||
|
||||
export function deletePostApi(params: DeletePostParams) {
|
||||
return httpPostJson<void>('/post/delete', params)
|
||||
}
|
||||
|
||||
export function getDashboardDataApi() {
|
||||
return httpGet<DashboardData>(`/post/dashboard`)
|
||||
}
|
||||
|
||||
// ===== 公共接口 =====
|
||||
export function getPostTagApi() {
|
||||
return httpGet<PostTag[]>('/post/tag')
|
||||
}
|
||||
export function getPostCategoryApi() {
|
||||
return httpGet<PostCategory[]>('/post/category')
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Area, CompanyQuery, Industry } from '@/types/base'
|
||||
import type { Area, CompanyQuery, Industry, PostTag } from '@/types/base'
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
import { reactive, ref } from 'vue'
|
||||
@@ -8,6 +8,8 @@ export const useCommonStore = defineStore(
|
||||
() => {
|
||||
const areaOptions = reactive<Area[]>([])
|
||||
const industryOptions = reactive<Industry[]>([])
|
||||
const postTagOptions = reactive<PostTag[]>([])
|
||||
|
||||
const companyQuery = ref<CompanyQuery>({
|
||||
industries: [],
|
||||
areas: [],
|
||||
@@ -18,6 +20,7 @@ export const useCommonStore = defineStore(
|
||||
areaOptions,
|
||||
industryOptions,
|
||||
companyQuery,
|
||||
postTagOptions,
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -12,6 +12,12 @@ export interface Industry {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface PostTag {
|
||||
id: number
|
||||
name: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
export interface InitBaseDataResult {
|
||||
industries: Industry[]
|
||||
areas: Area[]
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface PostEditorForm {
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface AddPostParams {
|
||||
export interface CreatePostParams {
|
||||
title: string
|
||||
content: string
|
||||
status: number
|
||||
|
||||
@@ -16,10 +16,13 @@ export interface DashboardData {
|
||||
viewChart: DashboradChart[]
|
||||
typeChart: DashboradChart[]
|
||||
}
|
||||
|
||||
export interface PostTag {
|
||||
id: number
|
||||
name: string
|
||||
icon: string
|
||||
}
|
||||
|
||||
export interface PostCategory {
|
||||
id: number
|
||||
name: string
|
||||
|
||||
@@ -1,30 +1,96 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CollapseModelValue } from 'element-plus'
|
||||
import type { PostTag } from '@/types/base'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import CustomEmpty from '@/components/CustomEmpty.vue'
|
||||
import SvgIcon from '@/components/SvgIcon.vue'
|
||||
import { useCommonStore } from '@/store/common'
|
||||
|
||||
const { postTagOptions } = useCommonStore()
|
||||
|
||||
const activeNames = ref(['1'])
|
||||
const selectedTag = ref<PostTag>(postTagOptions[0])
|
||||
|
||||
function handleChange(val: CollapseModelValue) {
|
||||
console.log(val)
|
||||
function handleChangeSelectedTag(tag: PostTag) {
|
||||
selectedTag.value = tag
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="post-wrapper">
|
||||
<div class="sidebar">
|
||||
<div class="post-sidebar">
|
||||
<el-collapse v-model="activeNames" expand-icon-position="left">
|
||||
<el-collapse-item title="标签" name="1">
|
||||
<ul class="sidebar-tags">
|
||||
<li class="sidebar-tag">
|
||||
<SvgIcon icon="streamline-color:earth-airplane" :size="18" />
|
||||
<span class="sidebar-tag-text">空运</span>
|
||||
<ul class="tag-list">
|
||||
<li
|
||||
v-for="item in postTagOptions"
|
||||
:key="item.id"
|
||||
class="tag-item"
|
||||
:class="{ active: selectedTag.id === item.id }"
|
||||
@click="handleChangeSelectedTag(item)"
|
||||
>
|
||||
<SvgIcon v-if="item.icon" :icon="item.icon" />
|
||||
<span class="tag-item-text">{{ item.name }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</el-collapse-item>
|
||||
</el-collapse>
|
||||
</div>
|
||||
|
||||
<div class="post-main">
|
||||
<div class="post-main-header">
|
||||
<el-input
|
||||
:prefix-icon="Search"
|
||||
placeholder="搜索" size="large"
|
||||
/>
|
||||
<div class="post-pagination">
|
||||
<el-pagination layout="prev, pager, next,jumper" background :total="1000" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="post-content">
|
||||
<!-- <CustomEmpty :in-container="true" /> -->
|
||||
|
||||
<div class="post-list">
|
||||
<div v-for="i in 20" :key="i" class="post-item">
|
||||
<div class="post-title-row">
|
||||
<div class="post-title">
|
||||
新项目为什么推荐WebFlux,而非SpringMVC?
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-meta">
|
||||
<div class="post-meta-actions">
|
||||
<div class="post-meta-item">
|
||||
<div>刘大华</div>
|
||||
</div>
|
||||
|
||||
<div class="post-meta-divider" />
|
||||
|
||||
<div class="post-meta-item">
|
||||
<SvgIcon icon="mdi:eye-outline" />
|
||||
<span>1.7k</span>
|
||||
</div>
|
||||
<div class="post-meta-item">
|
||||
<SvgIcon icon="iconamoon:comment" />
|
||||
<span>1.7k</span>
|
||||
</div>
|
||||
|
||||
<div class="post-meta-divider" />
|
||||
|
||||
<div class="post-meta-item">
|
||||
<div>20分钟前</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-meta-tags">
|
||||
<div class="post-tag">
|
||||
后端
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -33,7 +99,8 @@ function handleChange(val: CollapseModelValue) {
|
||||
display: flex;
|
||||
padding: 0px 240px;
|
||||
background-color: #fff;
|
||||
.sidebar {
|
||||
|
||||
.post-sidebar {
|
||||
background-color: #fff;
|
||||
height: calc(100vh - var(--header-height));
|
||||
font-size: 16px;
|
||||
@@ -45,12 +112,12 @@ function handleChange(val: CollapseModelValue) {
|
||||
width: 240px;
|
||||
padding: 0px 16px;
|
||||
|
||||
.sidebar-tags {
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
|
||||
.sidebar-tag {
|
||||
.tag-item {
|
||||
height: 32px;
|
||||
display: inline-flex;
|
||||
width: 100%;
|
||||
@@ -59,24 +126,130 @@ function handleChange(val: CollapseModelValue) {
|
||||
cursor: pointer;
|
||||
padding: 0px 16px;
|
||||
font-size: 16px;
|
||||
transition:
|
||||
background-color 0.2s ease,
|
||||
color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.sidebar-tag-text {
|
||||
.tag-item-text {
|
||||
margin-left: 12px;
|
||||
color: #646464;
|
||||
transition:
|
||||
color 0.2s ease,
|
||||
transform 0.2s ease;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #f2f2f2;
|
||||
.tag-item-text {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.post-main {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
.post-main-header {
|
||||
position: sticky;
|
||||
top: calc(var(--header-height));
|
||||
background-color: #fff;
|
||||
padding: 8px 16px 0px 16px;
|
||||
box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.06);
|
||||
|
||||
.post-pagination {
|
||||
padding: 12px 0px;
|
||||
}
|
||||
}
|
||||
|
||||
.post-content {
|
||||
padding-bottom: 36px;
|
||||
}
|
||||
|
||||
.post-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.post-item {
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
|
||||
.post-title-row {
|
||||
display: flex;
|
||||
margin-bottom: 8px;
|
||||
.post-title {
|
||||
font-weight: 400;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #252933;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.post-meta {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
flex-wrap: wrap;
|
||||
.post-meta-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.post-meta-item {
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
color: #8a919f;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
& + .post-meta-item {
|
||||
margin-left: 12px;
|
||||
}
|
||||
span {
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.post-meta-divider {
|
||||
width: 1px;
|
||||
height: 12px;
|
||||
background-color: #e4e6eb;
|
||||
margin: 0 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.post-meta-tags {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
.post-tag {
|
||||
background-color: #f2f3f5;
|
||||
padding: 0 6px;
|
||||
border-radius: 2px;
|
||||
max-width: 65px;
|
||||
box-sizing: border-box;
|
||||
margin-left: 6px;
|
||||
color: #8a919f;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
min-height: 18px;
|
||||
line-height: 18px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 250px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
.post-list {
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
||||
@@ -8,10 +8,12 @@ import { computed, nextTick, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import CustomLoading from '@/components/CustomLoading.vue'
|
||||
import WangEditor from '@/components/wang-editor/index.vue'
|
||||
import { addPostApi, getPostApi, getPostCategoryApi, getPostTagApi, updatePostApi } from '@/request/api/post'
|
||||
import { createPostApi, getEditorPostApi, updatePostApi } from '@/request/api/post/editor'
|
||||
import { useCommonStore } from '@/store/common'
|
||||
import { PostStatusEnum } from '@/types/post/editor'
|
||||
|
||||
const route = useRoute()
|
||||
const { postTagOptions } = useCommonStore()
|
||||
|
||||
const titleInputRef = ref<HTMLInputElement | null>(null)
|
||||
const wangEditorRef = ref<any>(null)
|
||||
@@ -25,9 +27,6 @@ const loading = reactive({
|
||||
const showPushDrawer = ref<boolean>(false)
|
||||
const imageUpload = ref<UploadImageResponse | null>(null)
|
||||
|
||||
const tagOptions = ref<PostTag[]>([])
|
||||
const categoryOptions = ref<PostCategory[]>([])
|
||||
|
||||
const statusOptions = [
|
||||
{
|
||||
label: '草稿',
|
||||
@@ -78,7 +77,7 @@ onMounted(() => {
|
||||
if (id) {
|
||||
loading.init = true
|
||||
|
||||
getPostApi(id).then((res) => {
|
||||
getEditorPostApi(id).then((res) => {
|
||||
if (res.isSuccess) {
|
||||
form.value = res.data
|
||||
oldForm.value = JSON.parse(JSON.stringify(res.data))
|
||||
@@ -102,19 +101,6 @@ onMounted(() => {
|
||||
async function handleShowPushDrawer() {
|
||||
loading.init = true
|
||||
showPushDrawer.value = true
|
||||
|
||||
await getPostTagApi().then((res) => {
|
||||
if (res.isSuccess) {
|
||||
tagOptions.value = res.data
|
||||
}
|
||||
else {
|
||||
ElMessage.error(res.message || '获取帖子标签失败,请稍后再试')
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
ElMessage.error('获取帖子标签失败,请稍后再试')
|
||||
})
|
||||
|
||||
loading.init = false
|
||||
}
|
||||
|
||||
@@ -146,7 +132,7 @@ async function handleSave(formEl?: FormInstance) {
|
||||
|
||||
const res = isUpdate.value
|
||||
? await updatePostApi({ id: form.value.id, ...payload })
|
||||
: await addPostApi(payload)
|
||||
: await createPostApi(payload)
|
||||
|
||||
if (!res.isSuccess) {
|
||||
ElMessage.error(
|
||||
@@ -215,7 +201,7 @@ async function handleSave(formEl?: FormInstance) {
|
||||
<el-form-item label="标签" prop="tags">
|
||||
<el-select v-model="form.tags" multiple placeholder="请选择标签">
|
||||
<el-option
|
||||
v-for="item in tagOptions"
|
||||
v-for="item in postTagOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.name"
|
||||
|
||||
@@ -6,7 +6,7 @@ import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import CustomLoading from '@/components/CustomLoading.vue'
|
||||
import SvgIcon from '@/components/SvgIcon.vue'
|
||||
import { deletePostApi, queryPostApi, updatePostStatusApi } from '@/request/api/post'
|
||||
import { deletePostApi, queryEditorPostsApi, updatePostStatusApi } from '@/request/api/post/editor'
|
||||
import { PostStatusEnum } from '@/types/post/editor'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -89,7 +89,7 @@ onMounted(() => {
|
||||
|
||||
function queryPost() {
|
||||
loading.value = true
|
||||
queryPostApi({
|
||||
queryEditorPostsApi({
|
||||
...queryForm,
|
||||
currentPage: page.current,
|
||||
pageSize: page.pageSize,
|
||||
|
||||
@@ -295,11 +295,9 @@ const activeCollapseNames = ref(['1', '2', '3'])
|
||||
background-color: #fff;
|
||||
|
||||
:deep(.el-button) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
width: 360px;
|
||||
height: 40px;
|
||||
border-radius: 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user