feat(WechatSmallProject): 新增 微信小程序 课程(包含实验1-4)

This commit is contained in:
2026-05-05 14:38:52 +08:00
parent 69db4c1c07
commit f1679c1767
177 changed files with 1977 additions and 10 deletions

View File

@@ -0,0 +1,2 @@
node_modules
pnpm-lock.yaml

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,42 @@
// 引入 Node.js 的 fs 模块,该模块用于处理文件系统操作,比如读取文件
let fs = require("fs");
// 引入 express 模块express 是一个流行的 Node.js Web 应用框架,用于快速搭建 Web 服务器
var express = require("express");
// 读取 JSON 数据
// 使用 fs.readFileSync 同步读取当前目录下的 data.json 文件
// 第二个参数指定以 UTF-8 编码读取文件,读取结果存储在 jsonStr 变量中
let jsonStr = fs.readFileSync("./data.json", {
encoding: "utf8",
});
// 将读取到的 JSON 字符串解析为 JavaScript 对象,存储在 data 变量中
let data = JSON.parse(jsonStr);
// 创建 Web 服务器对象
// 调用 express 函数创建一个 express 应用实例,后续使用该实例来配置和启动服务器
var app = express();
// 静态资源处理
// 使用 express.static 中间件来处理静态资源,这里指定 public 目录为静态资源目录
// 客户端可以直接访问 public 目录下的文件例如图片、CSS、JavaScript 文件等
app.use(express.static("public"));
// 定义一个 GET 请求的路由,当客户端访问 /data 路径时会触发该路由处理函数
app.get("/data", (req, res) => {
// 使用扩展运算符将 data 数组复制一份到 arr 数组中 。扩展运算符是 ES6 中引入的新特性它可以将一个可迭代对象如数组、字符串、Map、Set 等)展开成一个个独立的元素。数组复制:在代码中 let [ ...arr ] = data 就是利用扩展运算符将 data 数组中的元素展开,然后复制到一个新的数组 arr 中。这样就创建了一个 data 数组的浅拷贝arr 和 data 是两个不同的数组对象,但是它们内部的元素(如果是基本类型)是相同的,或者(如果是引用类型)是指向同一个对象的引用。
let [...arr] = data;
// 计算当前页数据的起始索引
// req.query.page 是客户端请求中传递的页码参数req.query.pageSize 是每页显示的数据条数
let start = (req.query.page - 1) * req.query.pageSize;
// 设置响应头 X-Total-Count用于告知客户端数据的总条数
res.setHeader("X-Total-Count", data.length);
// 从 arr 数组中截取从 start 索引开始,长度为 req.query.pageSize 的数据,并将其作为响应发送给客户端
res.send(arr.splice(start, req.query.pageSize));
});
// 启动服务器,监听 3000 端口
// 当服务器启动成功后,会在控制台输出提示信息,告知服务器的访问地址
app.listen(3000, () => {
console.log("服务器启动成功地址为http://127.0.0.1:3000");
});

View File

@@ -0,0 +1,15 @@
{
"name": "json-data-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.1"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB