Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions mock/cfc/mock/template/chartData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = function (req, res) {
let book_type = req.body?.book_type;
if (book_type == '四大名著') {
res.json({
status: 0,
msg: 'ok',
data: { "xdata": ["四大名著"], "ydata": [4] }
});
} else if (book_type == '小说') {
res.json({
status: 0,
msg: 'ok',
data: { "xdata": ["小说"], "ydata": [5] }
});
} else if (book_type == '测试') {
res.json({
status: 0,
msg: 'ok',
data: { "xdata": ["测试"], "ydata": [1] }
});
} else if (book_type == '经典') {
res.json({
status: 0,
msg: 'ok',
data: { "xdata": ["经典"], "ydata": [1] }
});
}else{
res.json({
status: 0,
msg: 'ok',
data: {
"xdata": [
"四大名著",
"小说",
"测试",
"经典"
],
"ydata": [
4,
5,
1,
1
]
}
});
}
};
33 changes: 33 additions & 0 deletions mock/cfc/mock/template/getCurrentDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = function (req, res) {
function getDaysInMonth(month, year) {
const daysInMonth = new Date(year, month, 0).getDate();
const daysArray = [];

for (let day = 1; day <= daysInMonth; day++) {
const dateStr = `${month}月${day}日`;
daysArray.push({
"label": dateStr,
"value": dateStr
});
}

return daysArray;
}

// 获取当前日期
const currentDate = new Date();

// 获取当前年份和月份
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1; // 注意月份是从0开始的,所以要加1

// 获取当前月份的每一天数组
const daysInCurrentMonth = getDaysInMonth(currentMonth, currentYear);


res.json({
status: 0,
msg: 'ok',
data: daysInCurrentMonth
});
};
83 changes: 83 additions & 0 deletions mock/cfc/mock/template/getUserInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module.exports = function (req, res) {
let stuId = req.query?.stuId;
let ret = {};
if (isNaN(stuId) || stuId < 1 || stuId > data.length) {
ret = {
status: 0,
msg: 'ok',
data: data[0]
};
} else {
stuId = Number(stuId);
ret = {
status: 0,
msg: 'ok',
data: data[stuId - 1]
};
}
res.json(ret);


};

const data = [
{
"name": "张三",
"class": "软件工程1班",
"age": 20,
"birth": "2005-05-08",
"phone": "18888888888",
"email": "zhangsan@example.edu",
"addr": "北京市海淀区中关村大街1号",
"sid": "20230001",
"img": "https://api.dicebear.com/7.x/avataaars/svg?seed=ZhangSan"
},
{
"name": "李四",
"class": "软件工程2班",
"age": 21,
"birth": "2004-03-15",
"phone": "18888888889",
"email": "lisi@example.edu",
"addr": "上海市浦东新区张江高科技园区2号",
"sid": "20230002",
"img": "https://api.dicebear.com/7.x/avataaars/svg?seed=LiSi"
},
{
"name": "王五",
"class": "计算机科学1班",
"age": 19,
"birth": "2006-07-22",
"phone": "18888888890",
"email": "wangwu@example.edu",
"addr": "广州市天河区五山路3号",
"sid": "20230003",
"img": "https://api.dicebear.com/7.x/avataaars/svg?seed=WangWu"
},
{
"name": "赵六",
"class": "人工智能1班",
"age": 20,
"birth": "2005-11-30",
"phone": "18888888891",
"email": "zhaoliu@example.edu",
"addr": "杭州市西湖区文三路4号",
"sid": "20230004",
"img": "https://api.dicebear.com/7.x/avataaars/svg?seed=ZhaoLiu"
},
{
"name": "孙七",
"class": "网络工程1班",
"age": 22,
"birth": "2003-09-10",
"phone": "18888888892",
"email": "sunqi@example.edu",
"addr": "成都市武侯区一环路南一段5号",
"sid": "20230005",
"img": "https://api.dicebear.com/7.x/avataaars/svg?seed=SunQi"
}
].map(function (item, index) {
return Object.assign({}, item, {
id: index + 1
});
});
17 changes: 17 additions & 0 deletions mock/cfc/mock/template/testResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mockReq = {
body:{
book_type: "经典"
},
query:{
stuId:"4"
}
}; // 模拟 req 对象(空对象即可)
const mockRes = {
json: (data) => console.log('API Response:', JSON.stringify(data, null, 2))
};

// 导入你的模块
const yourModule = require('./getUserInfo.js'); // 替换为你的文件名

// 调用模块
yourModule(mockReq, mockRes);