Skip to content

Commit 53035aa

Browse files
authored
Merge pull request #1 from linxbin/master
add the new feature of restoring the specified article from the recycle bin
2 parents 285383c + 3e0fd4a commit 53035aa

File tree

7 files changed

+60
-7
lines changed

7 files changed

+60
-7
lines changed

blogserver/src/main/java/org/sang/controller/ArticleController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ public RespBean updateArticleState(Long[] aids, Integer state) {
9393
return new RespBean("error", "删除失败!");
9494
}
9595

96+
@RequestMapping(value = "/restore", method = RequestMethod.PUT)
97+
public RespBean restoreArticle(Integer articleId) {
98+
if (articleService.restoreArticle(articleId) == 1) {
99+
return new RespBean("success", "还原成功!");
100+
}
101+
return new RespBean("error", "还原失败!");
102+
}
103+
96104
@RequestMapping("/dataStatistics")
97105
public Map<String,Object> dataStatistics() {
98106
Map<String, Object> map = new HashMap<>();

blogserver/src/main/java/org/sang/controller/CategoryController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public RespBean deleteById(@PathVariable String ids) {
3636

3737
@RequestMapping(value = "/", method = RequestMethod.POST)
3838
public RespBean addNewCate(Category category) {
39+
40+
if ("".equals(category.getCateName()) || category.getCateName() == null) {
41+
return new RespBean("error", "请输入栏目名称!");
42+
}
43+
3944
int result = categoryService.addCategory(category);
45+
4046
if (result == 1) {
4147
return new RespBean("success", "添加成功!");
4248
}

blogserver/src/main/java/org/sang/mapper/ArticleMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public interface ArticleMapper {
2323

2424
int updateArticleState(@Param("aids") Long aids[], @Param("state") Integer state);
2525

26+
int updateArticleStateById(@Param("articleId") Integer articleId, @Param("state") Integer state);
27+
2628
int deleteArticleById(@Param("aids") Long[] aids);
2729

2830
Article getArticleById(Long aid);

blogserver/src/main/java/org/sang/mapper/ArticleMapper.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
#{aid}
6666
</foreach>
6767
</update>
68-
68+
<update id="updateArticleStateById" >
69+
UPDATE article SET state=#{state} WHERE id = #{articleId}
70+
</update>
6971
<delete id="deleteArticleById">
7072
DELETE FROM article WHERE id IN
7173
<foreach collection="aids" item="aid" open="(" close=")" separator=",">

blogserver/src/main/java/org/sang/service/ArticleService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public int updateArticleState(Long[] aids, Integer state) {
113113
}
114114
}
115115

116+
public int restoreArticle(Integer articleId) {
117+
return articleMapper.updateArticleStateById(articleId, 1); // 从回收站还原在原处
118+
}
119+
116120
public Article getArticleById(Long aid) {
117121
Article article = articleMapper.getArticleById(aid);
118122
articleMapper.pvIncrement(aid);

vueblog/src/components/ArticleList.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<el-main class="main">
44
<el-tabs v-model="activeName" @tab-click="handleClick" type="card">
55
<el-tab-pane label="全部文章" name="all">
6-
<blog_table state="-1" :showEdit="false" :showDelete="false" :activeName="activeName"></blog_table>
6+
<blog_table state="-1" :showEdit="false" :showDelete="false" :showRestore="false" :activeName="activeName"></blog_table>
77
</el-tab-pane>
88
<el-tab-pane label="已发表" name="post">
9-
<blog_table state="1" :showEdit="true" :showDelete="true" :activeName="activeName"></blog_table>
9+
<blog_table state="1" :showEdit="true" :showDelete="true" :showRestore="false" :activeName="activeName"></blog_table>
1010
</el-tab-pane>
1111
<el-tab-pane label="草稿箱" name="draft">
12-
<blog_table state="0" :showEdit="true" :showDelete="true" :activeName="activeName"></blog_table>
12+
<blog_table state="0" :showEdit="true" :showDelete="true" :showRestore="false" :activeName="activeName"></blog_table>
1313
</el-tab-pane>
1414
<el-tab-pane label="回收站" name="dustbin">
15-
<blog_table state="2" :showEdit="false" :showDelete="true" :activeName="activeName"></blog_table>
15+
<blog_table state="2" :showEdit="false" :showDelete="true" :showRestore="true" :activeName="activeName"></blog_table>
1616
</el-tab-pane>
1717
<el-tab-pane label="博客管理" name="blogmana" v-if="isAdmin">
18-
<blog_table state="-2" :showEdit="false" :showDelete="true" :activeName="activeName"></blog_table>
18+
<blog_table state="-2" :showEdit="false" :showDelete="true" :showRestore="false" :activeName="activeName"></blog_table>
1919
</el-tab-pane>
2020
<el-tab-pane label="博客配置" name="blogcfg">
2121
<blog_cfg></blog_cfg>

vueblog/src/components/BlogTable.vue

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
size="mini"
5858
@click="handleEdit(scope.$index, scope.row)" v-if="showEdit">编辑
5959
</el-button>
60+
<el-button
61+
size="mini"
62+
@click="handleRestore(scope.$index, scope.row)" v-if="showRestore">还原
63+
</el-button>
6064
<el-button
6165
size="mini"
6266
type="danger"
@@ -168,6 +172,33 @@
168172
this.dustbinData.push(row.id);
169173
this.deleteToDustBin(row.state);
170174
},
175+
handleRestore(index, row) {
176+
let _this = this;
177+
this.$confirm('将该文件还原到原处,是否继续?','提示',{
178+
confirmButtonText: '确定',
179+
cancelButtonText: '取消',
180+
type: 'warning'
181+
} ).then(() => {
182+
_this.loading = true;
183+
putRequest('/article/restore', {articleId: row.id}).then(resp=> {
184+
if (resp.status == 200) {
185+
var data = resp.data;
186+
_this.$message({type: data.status, message: data.msg});
187+
if (data.status == 'success') {
188+
window.bus.$emit('blogTableReload')//通过选项卡都重新加载数据
189+
}
190+
} else {
191+
_this.$message({type: 'error', message: '还原失败!'});
192+
}
193+
_this.loading = false;
194+
});
195+
}).catch(() => {
196+
_this.$message({
197+
type: 'info',
198+
message: '已取消还原'
199+
});
200+
});
201+
},
171202
deleteToDustBin(state){
172203
var _this = this;
173204
this.$confirm(state != 2 ? '将该文件放入回收站,是否继续?' : '永久删除该文件, 是否继续?', '提示', {
@@ -208,6 +239,6 @@
208239
});
209240
}
210241
},
211-
props: ['state', 'showEdit', 'showDelete', 'activeName']
242+
props: ['state', 'showEdit', 'showDelete', 'activeName', 'showRestore']
212243
}
213244
</script>

0 commit comments

Comments
 (0)