throw err;
}
})
}
});
});
}
/**
- 全体查询
*/
function searchAllFiles() {
getAllFiles(files => {
let length = files.length;
for (let i = length - 1; i >= 0; i–) {
console.log(文件${length - i}:${files[i]}
)
}
choice();
})
}
/**
- 关键词查询
*/
function searchAllFilesTitle() {
getAllFiles(files => {
let length = files.length;
for (let i = length - 1; i >= 0; i–) {
fs.readFile(filesPath + /${files[i]}
, (err, data) => {
if (!err) {
let dataString = data.toString();
let dataJson = JSON.parse(dataString);
console.log(文件${length - i}名称,${files[i]},标题:${dataJson.title}
)
}
if (i === 0) {
choice();
}
});
}
})
}
/**
-
根据序号查询记录的详细内容
-
@param order 序号
*/
function searchFileContent(order) {
getAllFiles(files => {
let length = files.length;
fs.readFile(filesPath + /${files[length - order]}
, (err, data) => {
if (!err) {
let dataString = data.toString();
let dataJson = JSON.parse(dataString);
console.log(文件${length - order}名称,${files[length - order]},详细内容:${dataJson.content}
)
choice();
} else {
choice();
}
});
})
}
/**
-
根据序号删除记录
-
@param order 序号
*/
function deleteFile(order) {
getAllFiles(files => {
let length = files.length;
fs.unlink(filesPath + /${files[length - order]}
, (err, data) => {
if (!err) {
console.log(文件${files[length - order]}删除成功!
)
choice()
} else {
choice()
}
});
})
}
/**
- 退出程序
*/
function exit() {
console.clear();
console.log(‘欢迎下次使用’);
process.exit()
}
/**
- 显示菜单
*/
function showMenu() {
// 1. 清空控制台
console.clear();
process.stdout.write(‘\033[2J’);
process.stdout.write(‘\n’);
// 2. 输入选择条件
console.log(
`********************************
请输入操作名称
C:记录创建
S:全体查询
K:关键字查询
T:查询记录的详细内容
D:删除记录
E:退出记事本应用
*********************************`);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(‘请选择你的操作:’, answer => {
switch (answer.toUpperCase()) {
case ‘C’:
console.clear();
createFile();
break;
case ‘S’:
searchAllFiles();
break;
case ‘K’:
searchAllFilesTitle();
break;
case ‘T’:
readLine(‘输入格式:v1.请输入查询内容:’, answer => {
searchFileContent(Number(answer.substring(1)));
})
break;
case ‘D’:
readLine(‘输入格式:d1.请输入查询内容:’, answer => {
deleteFile(Number(answer.substring(1)));
})
break;
case ‘E’:
exit();
break;
}
})
}
showMenu()
[
新人创作打卡挑战赛
发博客就能抽奖!定制产品红包拿不停!
](https://blogdev.blog.csdn.net/article/details/124124117?utm_campaign=marketingcard&utm_source=KaiSarH&utm_content=111769723)
总结
根据路线图上的重点去进行有针对性的学习,在学习过程中,学会写笔记,做总结。
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
这里分享一些前端学习笔记:
-
html5 / css3 学习笔记
-
JavaScript 学习笔记
-
Vue 学习笔记
tml5 / css3 学习笔记**
-
JavaScript 学习笔记
-
Vue 学习笔记