feat(biji): 添加最近更新笔记功能
- 在前端添加 getRecentFiles API 接口 - 在后端添加 getRecentFiles 接口和相关服务方法 - 实现最近更新笔记的获取和展示 - 优化首页初始化逻辑,加载最近更新笔记
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<knife4j.version>4.5.0</knife4j.version>
|
<knife4j.version>4.5.0</knife4j.version>
|
||||||
<mybatis-plus.version>3.5.12</mybatis-plus.version>
|
<mybatis-plus.version>3.5.7</mybatis-plus.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.test.bijihoudaun.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加分页插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQLITE));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,4 +94,11 @@ public class MarkdownController {
|
|||||||
}
|
}
|
||||||
return R.fail("文件未找到或更新失败");
|
return R.fail("文件未找到或更新失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "获取最近更新的笔记")
|
||||||
|
@GetMapping("/recent")
|
||||||
|
public R<List<MarkdownFile>> getRecentFiles() {
|
||||||
|
List<MarkdownFile> files = markdownFileService.getRecentFiles(10);
|
||||||
|
return R.success(files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,11 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
|||||||
* @return 更新后的文件对象
|
* @return 更新后的文件对象
|
||||||
*/
|
*/
|
||||||
MarkdownFile updateMarkdownTitle(Long id, String title);
|
MarkdownFile updateMarkdownTitle(Long id, String title);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最近更新的笔记
|
||||||
|
* @param limit 数量
|
||||||
|
* @return 文件列表
|
||||||
|
*/
|
||||||
|
List<MarkdownFile> getRecentFiles(int limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.test.bijihoudaun.service.impl;
|
package com.test.bijihoudaun.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||||
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||||
@@ -86,4 +86,12 @@ public class MarkdownFileServiceImpl
|
|||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MarkdownFile> getRecentFiles(int limit) {
|
||||||
|
Page<MarkdownFile> page = new Page<>(1, limit);
|
||||||
|
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.orderByDesc("updated_at");
|
||||||
|
return this.page(page, queryWrapper).getRecords();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ export const updateMarkdownTitle = (id, newTitle) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取最近更新的笔记
|
||||||
|
export const getRecentFiles = () => axiosApi.get('/api/markdown/recent');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,8 @@ import {
|
|||||||
searchMarkdown,
|
searchMarkdown,
|
||||||
updateGroupingName,
|
updateGroupingName,
|
||||||
updateMarkdownTitle,
|
updateMarkdownTitle,
|
||||||
deleteGrouping as apiDeleteGrouping
|
deleteGrouping as apiDeleteGrouping,
|
||||||
|
getRecentFiles
|
||||||
} from '@/api/CommonApi.js'
|
} from '@/api/CommonApi.js'
|
||||||
import { Plus, Fold, Expand, Folder, Document, Search, Edit, Delete } from "@element-plus/icons-vue";
|
import { Plus, Fold, Expand, Folder, Document, Search, Edit, Delete } from "@element-plus/icons-vue";
|
||||||
import { useUserStore } from '../stores/user';
|
import { useUserStore } from '../stores/user';
|
||||||
@@ -221,7 +222,7 @@ const searchKeyword = ref('');
|
|||||||
|
|
||||||
const markdownFiles = ref([]);
|
const markdownFiles = ref([]);
|
||||||
const categoryTree = ref([]);
|
const categoryTree = ref([]);
|
||||||
const groupMarkdownFiles = ref({});
|
const groupMarkdownFiles = ref([]);
|
||||||
const showEditor = ref(false);
|
const showEditor = ref(false);
|
||||||
const selectedFile = ref(null);
|
const selectedFile = ref(null);
|
||||||
const activeMenu = ref('all');
|
const activeMenu = ref('all');
|
||||||
@@ -695,6 +696,7 @@ onMounted(() => {
|
|||||||
const chushihua = async () => {
|
const chushihua = async () => {
|
||||||
await fetchMarkdownFiles();
|
await fetchMarkdownFiles();
|
||||||
await fetchGroupings();
|
await fetchGroupings();
|
||||||
|
await fetchRecentFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
const goToLogin = () => {
|
const goToLogin = () => {
|
||||||
@@ -796,9 +798,20 @@ const handleDeleteGroup = async (group) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchRecentFiles = async () => {
|
||||||
|
try {
|
||||||
|
const res = await getRecentFiles();
|
||||||
|
// 与 selectFile 等接口保持一致,axios拦截器已处理一层data
|
||||||
|
groupMarkdownFiles.value = res.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取最近文件失败:', error);
|
||||||
|
ElMessage.error('获取最近文件失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const resetToHomeView = () => {
|
const resetToHomeView = () => {
|
||||||
selectedFile.value = null;
|
selectedFile.value = null;
|
||||||
groupMarkdownFiles.value = []; // 清空笔记列表
|
fetchRecentFiles();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user