Compare commits
16
Commits
aa227ab369
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c03afab4f | ||
|
|
5a2e1e29c7 | ||
|
|
ec963134bd | ||
|
|
8f31fbe081 | ||
|
|
9fc30aaadf | ||
|
|
f52b91e06c | ||
|
|
864b67ef87 | ||
|
|
a3bc44f845 | ||
|
|
f488c2fdd4 | ||
|
|
84c60ab758 | ||
|
|
7d0854127a | ||
|
|
9ce0c5704a | ||
|
|
4f687ba457 | ||
|
|
4725e373c2 | ||
|
|
812f0b291f | ||
|
|
46ab81ae3b |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
dist
|
||||
.deploy
|
||||
.git
|
||||
.gitignore
|
||||
*.log
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
# =============================================================================
|
||||
# 仅用于「构建」:容器内完成 npm ci + npm run build,产出 /app/dist
|
||||
#
|
||||
# Jenkins 用 `docker build --target build` 构建本阶段,再用 docker cp 把
|
||||
# /app/dist 导出到宿主机,最后由 1Panel 的 Nginx 托管。
|
||||
# 宿主机的 Jenkins 无需安装 Node。
|
||||
#
|
||||
# 本地验证:
|
||||
# docker build --target build -t index-build .
|
||||
# docker create --name tmp index-build && docker cp tmp:/app/dist/. ./dist && docker rm tmp
|
||||
# =============================================================================
|
||||
FROM node:22-alpine AS build
|
||||
WORKDIR /app
|
||||
|
||||
# 先拷依赖清单,单独成层以复用构建缓存
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
# 再拷源码与构建脚本(忽略项见 .dockerignore)
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
Vendored
+92
@@ -0,0 +1,92 @@
|
||||
// =============================================================================
|
||||
// Jenkins 声明式流水线(容器化构建)
|
||||
// 流程:Gitea push -> 检出 -> docker 构建 dist -> 导出 -> 同步到 Nginx 站点目录
|
||||
//
|
||||
// 前置条件(见 README「自动部署(Jenkins)」):
|
||||
// 1. Jenkins 用户能用 docker(通常在 docker 组里)。
|
||||
// 2. 服务器预置 /usr/local/bin/index-deploy-prepare 及其 sudo 免密规则(权限自愈)。
|
||||
// 3. Job 的 SCM 指向本仓库,并开启 Gitea push 触发 + 配置 Gitea webhook。
|
||||
// 说明:构建跑在 node:22-alpine 容器里,宿主机 Jenkins 不需要安装 Node。
|
||||
// =============================================================================
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
options {
|
||||
timestamps()
|
||||
disableConcurrentBuilds() // 避免两次部署互相覆盖
|
||||
buildDiscarder(logRotator(numToKeepStr: '20'))
|
||||
skipDefaultCheckout(true) // 用下面的显式 checkout
|
||||
}
|
||||
|
||||
environment {
|
||||
// Nginx 站点根目录(1Panel 管理)。换站点只改这里。
|
||||
DEPLOY_DIR = '/opt/1panel/www/sites/xiaozhou233.cn/index'
|
||||
IMAGE_NAME = 'xiaozhou-index-build'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
cleanWs()
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build (Docker)') {
|
||||
steps {
|
||||
sh '''
|
||||
set -euo pipefail
|
||||
IMAGE="${IMAGE_NAME}:latest"
|
||||
# 只在容器内构建,得到 /app/dist;不产生运行镜像
|
||||
# 固定 tag:新构建会顶掉旧 tag,旧的变成悬空镜像,由 post 里的 prune 清理
|
||||
docker build --target build -t "$IMAGE" .
|
||||
# 把 dist 导出到工作区(docker cp 出来的文件属主是 jenkins,便于后续 rsync)
|
||||
rm -rf .deploy && mkdir -p .deploy
|
||||
cid=$(docker create "$IMAGE")
|
||||
docker cp "$cid:/app/dist/." .deploy/
|
||||
docker rm "$cid" >/dev/null
|
||||
echo "--- 构建产物 ---"
|
||||
ls -la .deploy
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sh '''
|
||||
set -euo pipefail
|
||||
|
||||
# 1) 权限自愈:目录属主若被 1Panel 改回 root 等情况,自动修正为 jenkins
|
||||
# (服务器已预置 sudo 规则,仅允许免密执行这一个脚本)
|
||||
sudo -n /usr/local/bin/index-deploy-prepare
|
||||
|
||||
# 2) 备份当前线上版本(保留最近 10 份,便于回滚)
|
||||
BK_DIR=/var/backups/index-site
|
||||
mkdir -p "$BK_DIR"
|
||||
if [ -n "$(ls -A "$DEPLOY_DIR" 2>/dev/null)" ]; then
|
||||
tar czf "$BK_DIR/index-$(date +%Y%m%d-%H%M%S)-build${BUILD_NUMBER}.tar.gz" -C "$DEPLOY_DIR" .
|
||||
ls -1t "$BK_DIR"/index-*.tar.gz | tail -n +11 | xargs -r rm -f
|
||||
fi
|
||||
|
||||
# 3) 覆盖式发布:不清空目标目录,只覆盖同名文件,保留现场已有文件
|
||||
find .deploy -name .gitkeep -delete
|
||||
cp -a .deploy/. "$DEPLOY_DIR"/
|
||||
echo "✅ Deployed to $DEPLOY_DIR"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo "部署成功:${env.DEPLOY_DIR}"
|
||||
}
|
||||
failure {
|
||||
echo '构建或部署失败,请查看上方日志'
|
||||
}
|
||||
always {
|
||||
// 清理本次构建产生的悬空镜像,避免磁盘膨胀
|
||||
sh 'docker image prune -f >/dev/null 2>&1 || true'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +1,323 @@
|
||||
# React + TypeScript + Vite
|
||||
# 筱周の网站 (XiaoZhou's Website)
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
个人主页 —— 终端 / 黑客风格,黑底 + emerald 主题,等宽字体 Geist。
|
||||
|
||||
Currently, two official plugins are available:
|
||||
- 首页 `/`:视差 Hero、打字机标题、导航卡片,以及「关于我 / 项目展示 / 联系我」三个区块。
|
||||
- 更多 `/more`:应用聚合页,把自建的小工具集中到一个入口。
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
## 技术栈
|
||||
|
||||
## React Compiler
|
||||
| 类别 | 选型 |
|
||||
| --- | --- |
|
||||
| 框架 | React 19 + TypeScript |
|
||||
| 构建 | Vite 8 |
|
||||
| 样式 | Tailwind CSS 4 |
|
||||
| 图标 | lucide-react |
|
||||
| 字体 | Geist Variable (`@fontsource-variable/geist`) |
|
||||
| 路由 | 自研轻量路由(零依赖,见 `src/router/`) |
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
## 快速开始
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```bash
|
||||
npm install # 安装依赖
|
||||
npm run dev # 启动开发服务器(HMR)
|
||||
npm run build # 生产构建 + 后处理
|
||||
npm run preview # 本地预览构建产物
|
||||
npm run lint # ESLint 检查
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
> 构建脚本为 `tsc -b && vite build && node scripts/postbuild.mjs`,最后一步会把
|
||||
> `dist/index.html` 复制成 `dist/more/index.html`,用于静态托管,并把项目根目录
|
||||
> `extra/` 里的所有文件复制进 `dist/`(见下方「额外静态文件」)。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
src/
|
||||
├── App.tsx 根组件:解析当前路由并渲染对应页面
|
||||
├── main.tsx React 挂载入口
|
||||
├── index.css Tailwind 入口 + 全局基础样式
|
||||
├── router/ 轻量路由
|
||||
│ ├── routes.ts 路由表(页面的唯一数据源)
|
||||
│ ├── history.ts normalizePath / navigate / subscribe
|
||||
│ ├── useRoute.ts 基于 useSyncExternalStore 的路由 hook
|
||||
│ ├── Link.tsx 站内跳转链接组件
|
||||
│ └── index.ts 统一导出
|
||||
├── components/
|
||||
│ ├── Banner.tsx 首页 Hero(背景 + 打字机 + 导航卡片)
|
||||
│ ├── NavCard.tsx 导航卡片
|
||||
│ ├── layout/ Header / Footer
|
||||
│ └── sections/ About / Projects / Contact 区块
|
||||
├── pages/
|
||||
│ ├── HomePage.tsx 首页
|
||||
│ └── MorePage.tsx /more 应用聚合页
|
||||
├── data/navigation.ts 首页导航卡片数据
|
||||
├── hooks/ useTypewriter / useParallax
|
||||
├── types/index.ts NavItem 类型
|
||||
└── assets/banner.png 全站背景图
|
||||
extra/ 额外静态文件(构建时原样复制进 dist/)
|
||||
Dockerfile 容器化构建(node:22-alpine)
|
||||
.dockerignore 构建上下文忽略项
|
||||
Jenkinsfile Jenkins 自动部署流水线
|
||||
scripts/postbuild.mjs 构建后处理(生成 dist/more/index.html、复制 extra/)
|
||||
```
|
||||
|
||||
## 添加 Item
|
||||
|
||||
有 3 种情况,按你想加的东西选择。
|
||||
|
||||
### 方式一:首页 Banner 上的导航卡片
|
||||
|
||||
编辑 `src/data/navigation.ts`,往 `NAV_ITEMS` 数组追加一项:
|
||||
|
||||
```ts
|
||||
import { LayoutDashboard, ListCollapse, BookOpen } from "lucide-react"; // 1. 引入图标
|
||||
import type { NavItem } from "@/types";
|
||||
|
||||
export const NAV_ITEMS: NavItem[] = [
|
||||
// ...已有项
|
||||
{
|
||||
name: "Blog", // 卡片标题
|
||||
desc: "我的博客", // 卡片副标题
|
||||
path: "https://blog.xiaozhou233.cn", // 链接(见下方说明)
|
||||
Icon: BookOpen, // lucide 图标组件
|
||||
color: "text-sky-400", // 图标颜色
|
||||
borderHover: // hover 时的边框 + 光晕
|
||||
"hover:border-sky-500/50 hover:shadow-[0_0_20px_rgba(56,189,248,0.2)]",
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
字段说明:
|
||||
|
||||
| 字段 | 说明 |
|
||||
| --- | --- |
|
||||
| `name` | 卡片标题,同时作为 React `key`,**不要重复** |
|
||||
| `desc` | 卡片副标题 |
|
||||
| `path` | 以 `/` 开头 → 站内路由、当前页 SPA 跳转;其他(`http...`、`#`)→ 新标签页打开。由 `NavCard.tsx` 自动判断 |
|
||||
| `Icon` | 任意 `lucide-react` 图标组件 |
|
||||
| `color` | 图标 Tailwind 颜色类 |
|
||||
| `borderHover` | hover 的边框色 + 阴影类 |
|
||||
|
||||
> 卡片网格会自动排版,无需改动布局。
|
||||
|
||||
### 方式二:`/more` 页的应用卡片
|
||||
|
||||
编辑 `src/pages/MorePage.tsx`,需要动两个地方:图标定义和列表。
|
||||
|
||||
```ts
|
||||
// 1. 在 appIcons 里加图标(SVG 内容,通常从 lucide 复制 path)
|
||||
const appIcons = {
|
||||
water: <path d="M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z" />,
|
||||
atom: (<>...</>),
|
||||
book: <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" />, // 新增
|
||||
};
|
||||
|
||||
// 2. 在 apps 数组里追加一项
|
||||
const apps = [
|
||||
// ...已有项
|
||||
{
|
||||
name: "新应用",
|
||||
desc: "一句话描述",
|
||||
color: "#10b981", // 图标底色,渐变自动生成
|
||||
link: "https://example.com", // 跳转地址
|
||||
icon: appIcons.book, // 指向上面定义的图标
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
| 字段 | 说明 |
|
||||
| --- | --- |
|
||||
| `name` | 应用名,同时作为 React `key`,**不要重复** |
|
||||
| `desc` | 一句话描述 |
|
||||
| `color` | 图标十六进制底色,卡片会自动生成同色渐变与光晕 |
|
||||
| `link` | 目标地址(站内相对路径或完整 URL) |
|
||||
| `icon` | 引用 `appIcons` 里的 SVG 片段 |
|
||||
|
||||
### 方式三:新增一个独立页面(路由)
|
||||
|
||||
如果卡片要指向站内新页面(例如 `/blog`):
|
||||
|
||||
**1. 新建页面组件**,如 `src/pages/BlogPage.tsx`。
|
||||
|
||||
**2. 注册路由**,在 `src/router/routes.ts` 的 `ROUTES` 追加:
|
||||
|
||||
```ts
|
||||
import BlogPage from "@/pages/BlogPage";
|
||||
|
||||
export const ROUTES: RouteDefinition[] = [
|
||||
// ...已有路由
|
||||
{
|
||||
name: "blog",
|
||||
path: "/blog",
|
||||
pattern: /^\/blog$/, // 路径匹配正则
|
||||
title: "博客 - 筱周の网站", // 会自动设置 document.title
|
||||
Component: BlogPage,
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
**3.(可选)让该路径能被直接访问。** 目前 `scripts/postbuild.mjs` 只为 `/more`
|
||||
生成了静态入口。若希望直接打开 `https://你的域名/blog` 也能命中(而不是只从首页点进去),
|
||||
照抄一份:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
const blogDir = resolve(root, "dist", "blog");
|
||||
mkdirSync(blogDir, { recursive: true });
|
||||
writeFileSync(resolve(blogDir, "index.html"), indexHtml);
|
||||
```
|
||||
|
||||
> 如果托管平台已配置 SPA history fallback(如 Cloudflare Pages / Netlify 的 rewrite),
|
||||
> 这一步可以省略。
|
||||
|
||||
## 额外静态文件(`extra/`)
|
||||
|
||||
如果有一些**不属于源码、但希望每次构建都出现在站点里**的文件(例如独立的小工具页面、
|
||||
验证文件、下载资源等),把它们放进项目根目录的 `extra/` 即可,无需改配置:
|
||||
|
||||
```
|
||||
extra/
|
||||
├── hello.txt -> dist/hello.txt
|
||||
├── tools/ -> dist/tools/
|
||||
│ └── index.html -> dist/tools/index.html
|
||||
└── .well-known/ -> dist/.well-known/
|
||||
└── verification -> dist/.well-known/verification
|
||||
```
|
||||
|
||||
- **构建时**:`scripts/postbuild.mjs` 会递归复制 `extra/` 里的所有内容到 `dist/` 根目录
|
||||
(是合并,不会生成 `dist/extra/`)。所以 `extra/a.txt` 最终可访问路径是 `/a.txt`。
|
||||
- **目录不存在时**:自动跳过,构建不会报错。空目录不会被 git 跟踪,仓库里用
|
||||
`extra/.gitkeep` 占位。
|
||||
- **只影响构建产物**:`extra/` 不参与 `npm run dev`,文件不会出现在开发服务器上;
|
||||
若开发时也要能访问,请改用 Vite 原生的 `public/` 目录。
|
||||
- **注意**:`extra/` 中的文件会覆盖 `dist/` 里的同名文件。比如放一个 `index.html` 会
|
||||
覆盖站点首页,请避免。
|
||||
|
||||
## 路由
|
||||
|
||||
路由是自研的零依赖实现,核心思路:
|
||||
|
||||
- **路由表唯一数据源**:`src/router/routes.ts` 里的 `ROUTES`,每条包含 `path`、
|
||||
`pattern`、`title`、`Component`。加页面只改这里。
|
||||
- **路径归一化**:`normalizePath()` 把 `/more`、`/more/`、`/more/index.html`
|
||||
统一成 `/more`。
|
||||
- **响应式**:`useRoute()` 基于 `useSyncExternalStore`,监听 `popstate`,
|
||||
浏览器前进/后退正常工作。
|
||||
- **站内跳转**:用 `src/router/Link.tsx` 的 `<Link to="/more">` 做客户端跳转;
|
||||
中键 / Ctrl 点击等仍会走浏览器默认行为(新标签页)。
|
||||
- **兜底**:未知路径回落到首页(`FALLBACK_ROUTE`)。
|
||||
|
||||
## 样式约定
|
||||
|
||||
- 主色 `emerald`,背景 `black`,卡片统一使用玻璃拟态:
|
||||
`bg-white/5 border border-white/5 backdrop-blur-sm rounded-2xl`。
|
||||
- 强调/交互用 emerald 光晕:`hover:border-emerald-500/30 hover:shadow-[0_0_25px_rgba(52,211,153,0.1)]`。
|
||||
- 标题、终端提示符用 `font-mono`;正文描述用 `font-sans`(Geist)。
|
||||
- Tailwind 4 语法:渐变用 `bg-linear-to-r`,字体族通过 `@theme` 覆盖。
|
||||
|
||||
## 部署
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
产物在 `dist/`,可直接托管到任意静态平台。注意构建会自动把
|
||||
`dist/index.html` 复制成 `dist/more/index.html`,保证 `/more` 可直达,并把 `extra/`
|
||||
的内容合并进 `dist/`。
|
||||
|
||||
日常开发不需要手动构建——推送到 Gitea 后由 Jenkins 自动构建并发布,见下节。
|
||||
|
||||
## 自动部署(Jenkins)
|
||||
|
||||
`git push` → Gitea webhook → Jenkins 用 Docker 构建 → 发布到 Nginx 站点目录,本地无需
|
||||
手动 build / 上传。
|
||||
|
||||
```
|
||||
Gitea push ─webhook─▶ Jenkins ─docker build(node)─▶ dist ─同步─▶ /opt/1panel/www/sites/xiaozhou233.cn/index
|
||||
```
|
||||
|
||||
构建在 `node:22-alpine` 容器内完成(见 `Dockerfile`),**宿主机的 Jenkins 不需要安装
|
||||
Node,也不依赖 rsync**,只要能跑 Docker 即可。整条流水线定义在仓库根的 `Jenkinsfile`。
|
||||
|
||||
### 一、服务器准备
|
||||
|
||||
1. Jenkins 主机安装 Docker 并让 `jenkins` 用户可用:
|
||||
|
||||
```bash
|
||||
docker version
|
||||
sudo usermod -aG docker jenkins # 之后重启 jenkins 使组生效
|
||||
```
|
||||
|
||||
2. 预置「权限自愈」脚本与免密 sudo 规则(`Deploy` 阶段会 `sudo` 调它,把被 1Panel
|
||||
改回 root 的站点目录重新修正为 `jenkins`):
|
||||
|
||||
```bash
|
||||
sudo tee /usr/local/bin/index-deploy-prepare >/dev/null <<'EOF'
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
DIR=/opt/1panel/www/sites/xiaozhou233.cn/index
|
||||
mkdir -p "$DIR"
|
||||
chown -R jenkins:jenkins "$DIR"
|
||||
chmod u+rwx "$DIR"
|
||||
EOF
|
||||
sudo chmod 755 /usr/local/bin/index-deploy-prepare
|
||||
|
||||
# 仅允许 jenkins 免密执行这一个脚本
|
||||
echo 'jenkins ALL=(root) NOPASSWD: /usr/local/bin/index-deploy-prepare' \
|
||||
| sudo tee /etc/sudoers.d/index-deploy >/dev/null
|
||||
sudo chmod 440 /etc/sudoers.d/index-deploy
|
||||
sudo visudo -cf /etc/sudoers.d/index-deploy # 看到 parsed OK 即通过
|
||||
```
|
||||
|
||||
3. 建备份目录(`Deploy` 阶段每次发布前会在此留一份上一版,保留最近 10 份,便于回滚):
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /var/backups/index-site
|
||||
sudo chown jenkins:jenkins /var/backups/index-site
|
||||
```
|
||||
|
||||
4. (可选)安装 `rsync`:流水线发布用 `cp`/`find`,并不依赖它;装了只是方便手工
|
||||
同步 / 回滚。
|
||||
|
||||
```bash
|
||||
sudo apt-get install -y rsync
|
||||
```
|
||||
|
||||
### 二、Jenkins 配置
|
||||
|
||||
1. **插件**:需要 `Workspace Cleanup`(流水线里用了 `cleanWs()`)和 Gitea 插件。
|
||||
2. **凭据**:系统管理 → 凭据 → 新增「用户名密码」,填 Gitea 账号 + 密码/访问令牌,ID 记为 `gitea`。
|
||||
3. **新建任务**:类型「Pipeline」(或「多分支流水线」):
|
||||
- Definition:`Pipeline script from SCM`
|
||||
- SCM:Git,URL `https://git.xiaozhou233.cn/xiaozhou233/index.git`,凭据 `gitea`,分支 `main`
|
||||
- Script Path:`Jenkinsfile`
|
||||
- 触发:勾选 Gitea 插件提供的「当代码被推送时构建」,复制它显示的 Webhook URL
|
||||
|
||||
### 三、Gitea 配置 Webhook
|
||||
|
||||
仓库 → 设置 → Web 钩子 → 添加 Web 钩子 → 类型 `Gitea` → 目标 URL 填上一步 Jenkins
|
||||
给出的地址 → 触发事件勾选「推送」→ 保存。
|
||||
|
||||
此后 `git push` 即自动构建 + 发布。
|
||||
|
||||
### 四、常见问题
|
||||
|
||||
- **docker: permission denied**:Jenkins 用户不在 docker 组,见「一、服务器准备」第 1 步。
|
||||
- **cp/find: Permission denied**:`Deploy` 会先跑权限自愈脚本;若仍失败,确认「一、服务器准备」第 2 步的 sudo 规则已生效。
|
||||
- **回滚到上一版**:每次发布前会把上一版备份到 `/var/backups/index-site/`(最近 10 份),
|
||||
在站点目录解压覆盖即可,例如
|
||||
`tar xzf /var/backups/index-site/index-<时间>.tar.gz -C /opt/1panel/www/sites/xiaozhou233.cn/index`。
|
||||
- **想回滚**:`git revert <坏提交>` 后 push,Jenkins 重新构建;或改回上一个提交。
|
||||
- **发布是覆盖式、不清空目录**:`Deploy` 只覆盖同名文件,现场已有的其它文件会保留。
|
||||
代价是旧的内容哈希文件(如 `assets/index-<旧hash>.js`)不会自动删除,长期会累积;
|
||||
需要时手工清理,或改用「发布到新目录 + 软链切换」的原子方案。
|
||||
- **更稳的原子发布**(可选):产物先放到带时间戳的 `releases/<时间>/`,再用 `ln -sfn`
|
||||
切换软链接,可做到发布瞬间无中断、旧版本自然保留。需要的话我可以改成这种。
|
||||
|
||||
> `dist/` 已在 `.gitignore` 中,不会进仓库,全部由 Jenkins 构建产生。
|
||||
|
||||
## 备注
|
||||
|
||||
- 全站背景图为 `src/assets/banner.png`,由 Vite 打包(带 hash)。
|
||||
- `index.html` 中接入了 umami 访问统计(`umami.xiaozhou233.cn`),如不需要可移除该 `<script>`。
|
||||
- 首页导航当前包含 Git / Jenkins / Workstation / More 四项。
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "radix-nova",
|
||||
"rsc": false,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "src/index.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
},
|
||||
"iconLibrary": "lucide",
|
||||
"rtl": false,
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils",
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"menuColor": "default",
|
||||
"menuAccent": "subtle",
|
||||
"registries": {}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="refresh" content="0; url=/forces">
|
||||
<title>Redirecting...</title>
|
||||
<script defer src="https://umami.xiaozhou233.cn/script.js" data-website-id="5a5128e4-1e6c-4c0f-8f45-536d929aa2a1"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>正在跳转到 <a href="/forces">/forces</a>...</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,225 @@
|
||||
/* 力的课堂 — 样式表 */
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
:root{
|
||||
--primary:#4f8cff;
|
||||
--primary-dark:#2a5bd7;
|
||||
--accent:#ff6b6b;
|
||||
--gravity:#ff6b6b;
|
||||
--elastic:#51cf66;
|
||||
--friction:#ffd43b;
|
||||
--bg:#f4f6fb;
|
||||
--card:#ffffff;
|
||||
--text:#1a202c;
|
||||
--text-light:#5a6478;
|
||||
--shadow:0 8px 32px rgba(30,50,90,.08);
|
||||
--radius:16px;
|
||||
}
|
||||
html{scroll-behavior:smooth}
|
||||
body{
|
||||
font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei","Helvetica Neue",Arial,sans-serif;
|
||||
background:var(--bg);
|
||||
color:var(--text);
|
||||
line-height:1.7;
|
||||
overflow-x:hidden;
|
||||
}
|
||||
nav{
|
||||
position:fixed;top:0;left:0;right:0;z-index:100;
|
||||
background:rgba(255,255,255,.85);
|
||||
backdrop-filter:blur(20px);
|
||||
-webkit-backdrop-filter:blur(20px);
|
||||
border-bottom:1px solid rgba(0,0,0,.05);
|
||||
padding:14px 0;
|
||||
}
|
||||
.nav-inner{
|
||||
max-width:1200px;margin:0 auto;padding:0 24px;
|
||||
display:flex;align-items:center;justify-content:space-between;
|
||||
}
|
||||
.logo{
|
||||
font-size:1.25rem;font-weight:700;
|
||||
background:linear-gradient(135deg,var(--primary),var(--accent));
|
||||
-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;
|
||||
}
|
||||
.nav-links{display:flex;gap:28px;list-style:none;flex-wrap:wrap}
|
||||
.nav-links a{
|
||||
text-decoration:none;color:var(--text-light);font-size:.92rem;font-weight:500;
|
||||
transition:color .2s;
|
||||
}
|
||||
.nav-links a:hover{color:var(--primary)}
|
||||
.hero{
|
||||
min-height:100vh;
|
||||
background:linear-gradient(135deg,#667eea 0%,#764ba2 50%,#f093fb 100%);
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
text-align:center;padding:120px 24px 80px;
|
||||
position:relative;overflow:hidden;
|
||||
}
|
||||
.hero::before{
|
||||
content:"";position:absolute;inset:0;
|
||||
background:
|
||||
radial-gradient(circle at 20% 30%,rgba(255,255,255,.15),transparent 40%),
|
||||
radial-gradient(circle at 80% 70%,rgba(255,255,255,.1),transparent 40%);
|
||||
}
|
||||
.hero-content{position:relative;z-index:1;max-width:800px;color:#fff}
|
||||
.hero h1{
|
||||
font-size:clamp(2.5rem,6vw,4.5rem);
|
||||
font-weight:800;margin-bottom:20px;
|
||||
text-shadow:0 4px 24px rgba(0,0,0,.15);
|
||||
letter-spacing:.02em;
|
||||
}
|
||||
.hero p{
|
||||
font-size:clamp(1.05rem,2vw,1.35rem);
|
||||
opacity:.95;margin-bottom:36px;max-width:600px;margin-left:auto;margin-right:auto;
|
||||
}
|
||||
.hero-btn{
|
||||
display:inline-block;padding:14px 40px;border-radius:50px;
|
||||
background:#fff;color:var(--primary-dark);
|
||||
text-decoration:none;font-weight:700;font-size:1.05rem;
|
||||
box-shadow:0 8px 24px rgba(0,0,0,.15);
|
||||
transition:transform .2s,box-shadow .2s;
|
||||
}
|
||||
.hero-btn:hover{transform:translateY(-3px);box-shadow:0 12px 32px rgba(0,0,0,.2)}
|
||||
section{padding:80px 24px;max-width:1200px;margin:0 auto}
|
||||
.section-title{
|
||||
font-size:clamp(1.75rem,3vw,2.5rem);
|
||||
font-weight:800;text-align:center;margin-bottom:12px;
|
||||
}
|
||||
.section-sub{
|
||||
text-align:center;color:var(--text-light);margin-bottom:56px;
|
||||
font-size:1.05rem;
|
||||
}
|
||||
.card{
|
||||
background:var(--card);border-radius:var(--radius);
|
||||
padding:36px;box-shadow:var(--shadow);
|
||||
margin-bottom:28px;
|
||||
transition:transform .25s,box-shadow .25s;
|
||||
}
|
||||
.card:hover{transform:translateY(-4px);box-shadow:0 12px 40px rgba(30,50,90,.12)}
|
||||
.grid-2{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:24px}
|
||||
.grid-3{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:24px}
|
||||
.concept-item{
|
||||
padding:28px;border-radius:14px;background:#f8faff;
|
||||
border-left:4px solid var(--primary);
|
||||
}
|
||||
.concept-item h3{color:var(--primary-dark);margin-bottom:8px;font-size:1.2rem}
|
||||
.concept-item p{color:var(--text-light)}
|
||||
.vector-diagram{
|
||||
display:flex;justify-content:center;align-items:center;
|
||||
margin:20px 0;
|
||||
}
|
||||
.vector-diagram svg{max-width:100%;height:auto}
|
||||
.tag{
|
||||
display:inline-block;padding:4px 12px;border-radius:20px;
|
||||
font-size:.8rem;font-weight:600;margin-right:6px;
|
||||
}
|
||||
.tag-gravity{background:#ffe8e8;color:#c92a2a}
|
||||
.tag-elastic{background:#d3f9d8;color:#2b8a3e}
|
||||
.tag-friction{background:#fff3bf;color:#b8860b}
|
||||
.tag-primary{background:#d0ebff;color:#1971c2}
|
||||
.formula{
|
||||
display:inline-block;padding:4px 14px;border-radius:8px;
|
||||
background:linear-gradient(135deg,#e7f5ff,#f3f0ff);
|
||||
font-family:"Cambria Math",Times New Roman,serif;
|
||||
font-weight:700;font-size:1.15rem;color:var(--primary-dark);
|
||||
margin:6px 4px;
|
||||
}
|
||||
.experiment-card{
|
||||
background:var(--card);border-radius:var(--radius);
|
||||
padding:28px;box-shadow:var(--shadow);
|
||||
border-top:4px solid var(--primary);
|
||||
}
|
||||
.experiment-card.gravity{border-top-color:var(--gravity)}
|
||||
.experiment-card.elastic{border-top-color:var(--elastic)}
|
||||
.experiment-card.friction{border-top-color:var(--friction)}
|
||||
.exp-header{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}
|
||||
.exp-header h3{font-size:1.25rem}
|
||||
.exp-badge{
|
||||
background:linear-gradient(135deg,var(--primary),var(--accent));
|
||||
color:#fff;padding:3px 10px;border-radius:20px;font-size:.75rem;font-weight:600;
|
||||
}
|
||||
.exp-desc{color:var(--text-light);margin-bottom:20px;font-size:.95rem}
|
||||
.canvas-wrap{
|
||||
position:relative;background:#f8faff;border-radius:12px;
|
||||
padding:12px;border:1px solid #eef2f7;
|
||||
margin-bottom:16px;
|
||||
}
|
||||
canvas{display:block;width:100%;height:auto;border-radius:8px}
|
||||
.controls{
|
||||
display:flex;flex-wrap:wrap;gap:12px;align-items:center;
|
||||
padding:14px;background:#f8faff;border-radius:10px;margin-bottom:14px;
|
||||
}
|
||||
.controls label{font-size:.88rem;color:var(--text-light);display:flex;align-items:center;gap:8px}
|
||||
.controls input[type=range]{
|
||||
width:140px;accent-color:var(--primary);
|
||||
}
|
||||
.controls .val{
|
||||
min-width:48px;text-align:right;font-weight:700;color:var(--primary-dark);
|
||||
font-variant-numeric:tabular-nums;
|
||||
}
|
||||
.btn{
|
||||
padding:8px 20px;border:none;border-radius:8px;
|
||||
background:var(--primary);color:#fff;font-weight:600;font-size:.9rem;
|
||||
cursor:pointer;transition:all .2s;
|
||||
}
|
||||
.btn:hover{background:var(--primary-dark)}
|
||||
.btn.secondary{background:#e9ecef;color:var(--text)}
|
||||
.btn.secondary:hover{background:#dee2e6}
|
||||
.data-display{
|
||||
display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px;
|
||||
padding:14px;background:linear-gradient(135deg,#f8faff,#f0f4ff);
|
||||
border-radius:10px;font-size:.9rem;
|
||||
}
|
||||
.data-item{display:flex;justify-content:space-between;align-items:center}
|
||||
.data-item span:first-child{color:var(--text-light)}
|
||||
.data-item span:last-child{font-weight:700;color:var(--primary-dark);font-variant-numeric:tabular-nums}
|
||||
.data-item .g{color:#c92a2a}
|
||||
.data-item .e{color:#2b8a3e}
|
||||
.data-item .f{color:#b8860b}
|
||||
.comparison-table{
|
||||
width:100%;border-collapse:separate;border-spacing:0;
|
||||
background:var(--card);border-radius:var(--radius);
|
||||
overflow:hidden;box-shadow:var(--shadow);
|
||||
margin-bottom:24px;
|
||||
}
|
||||
.comparison-table th,.comparison-table td{
|
||||
padding:16px 18px;text-align:left;font-size:.95rem;
|
||||
border-bottom:1px solid #eef2f7;
|
||||
}
|
||||
.comparison-table th{
|
||||
background:linear-gradient(135deg,#e7f5ff,#f3f0ff);
|
||||
font-weight:700;color:var(--primary-dark);font-size:1rem;
|
||||
}
|
||||
.comparison-table tr:last-child td{border-bottom:none}
|
||||
.comparison-table td:first-child{font-weight:600;color:var(--text)}
|
||||
.comparison-table .gravity-row td:first-child{color:#c92a2a}
|
||||
.comparison-table .elastic-row td:first-child{color:#2b8a3e}
|
||||
.comparison-table .friction-row td:first-child{color:#b8860b}
|
||||
.life-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:24px}
|
||||
.life-card{
|
||||
padding:28px;border-radius:14px;color:#fff;position:relative;overflow:hidden;
|
||||
min-height:180px;display:flex;flex-direction:column;justify-content:flex-end;
|
||||
}
|
||||
.life-card.gravity{background:linear-gradient(135deg,#ff6b6b,#ee5a5a)}
|
||||
.life-card.elastic{background:linear-gradient(135deg,#51cf66,#40c057)}
|
||||
.life-card.friction{background:linear-gradient(135deg,#ffd43b,#fab005)}
|
||||
.life-card h4{font-size:1.2rem;margin-bottom:8px}
|
||||
.life-card p{font-size:.9rem;opacity:.95}
|
||||
.life-card .icon{position:absolute;top:20px;right:20px;font-size:3rem;opacity:.3}
|
||||
.life-examples{display:flex;flex-wrap:wrap;gap:10px;margin-top:12px}
|
||||
.life-examples span{
|
||||
background:rgba(255,255,255,.2);padding:4px 12px;border-radius:20px;font-size:.82rem;
|
||||
}
|
||||
footer{
|
||||
text-align:center;padding:40px 24px;color:var(--text-light);
|
||||
font-size:.9rem;border-top:1px solid #eef2f7;margin-top:40px;
|
||||
}
|
||||
@media(max-width:768px){
|
||||
.nav-links{gap:16px;font-size:.85rem}
|
||||
.nav-links a{font-size:.82rem}
|
||||
section{padding:56px 18px}
|
||||
.card{padding:24px}
|
||||
.experiment-card{padding:20px}
|
||||
.controls{flex-direction:column;align-items:stretch}
|
||||
.controls input[type=range]{width:100%}
|
||||
.comparison-table th,.comparison-table td{padding:10px 12px;font-size:.82rem}
|
||||
}
|
||||
.animate-in{opacity:0;transform:translateY(30px);transition:opacity .6s,transform .6s}
|
||||
.animate-in.visible{opacity:1;transform:translateY(0)}
|
||||
@@ -0,0 +1,291 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>认识力 — 经典力学互动课堂</title>
|
||||
<link rel="stylesheet" href="./css/styles.css">
|
||||
<script defer src="https://umami.xiaozhou233.cn/script.js" data-website-id="5a5128e4-1e6c-4c0f-8f45-536d929aa2a1"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav>
|
||||
<div class="nav-inner">
|
||||
<div class="logo">⚡ 力的课堂</div>
|
||||
<ul class="nav-links">
|
||||
<li><a href="#concept">概念</a></li>
|
||||
<li><a href="#unit">单位</a></li>
|
||||
<li><a href="#gravity">重力</a></li>
|
||||
<li><a href="#elastic">弹力</a></li>
|
||||
<li><a href="#friction">摩擦</a></li>
|
||||
<li><a href="#compare">对比</a></li>
|
||||
<li><a href="#life">生活</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="hero">
|
||||
<div class="hero-content">
|
||||
<h1>认识力</h1>
|
||||
<p>力是物体对物体的作用。从苹果落地到弓箭弹射,从走路摩擦到弹簧拉伸——让我们一起走进力的奇妙世界。</p>
|
||||
<a href="#concept" class="hero-btn">开始探索 →</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="concept" class="animate-in">
|
||||
<h2 class="section-title">📐 力的概念</h2>
|
||||
<p class="section-sub">力是物体对物体的作用,力不能脱离物体而独立存在</p>
|
||||
<div class="card">
|
||||
<h3 style="margin-bottom:16px;color:var(--primary-dark);font-size:1.3rem">力的三要素</h3>
|
||||
<p style="color:var(--text-light);margin-bottom:20px">力的作用效果与力的<strong>大小</strong>、<strong>方向</strong>和<strong>作用点</strong>有关,这三者称为力的三要素。</p>
|
||||
<div class="grid-3">
|
||||
<div class="concept-item">
|
||||
<h3>📏 大小</h3>
|
||||
<p>力的大小不同,作用效果不同。用力越大,弹簧伸长越长。</p>
|
||||
</div>
|
||||
<div class="concept-item" style="border-left-color:var(--accent)">
|
||||
<h3>➡️ 方向</h3>
|
||||
<p>力的方向不同,作用效果不同。推车门和拉车门,效果完全不同。</p>
|
||||
</div>
|
||||
<div class="concept-item" style="border-left-color:var(--elastic)">
|
||||
<h3>📍 作用点</h3>
|
||||
<p>力的作用点不同,作用效果不同。推门的不同位置,用力的大小不同。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="vector-diagram">
|
||||
<svg viewBox="0 0 500 200" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" fill="#4f8cff"/>
|
||||
</marker>
|
||||
<marker id="arrowRed" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" fill="#ff6b6b"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<line x1="60" y1="100" x2="200" y2="100" stroke="#4f8cff" stroke-width="3" marker-end="url(#arrow)"/>
|
||||
<text x="130" y="85" text-anchor="middle" fill="#4f8cff" font-weight="bold" font-size="14">F₁ (较大)</text>
|
||||
<line x1="250" y1="100" x2="340" y2="100" stroke="#ff6b6b" stroke-width="3" marker-end="url(#arrowRed)"/>
|
||||
<text x="295" y="85" text-anchor="middle" fill="#ff6b6b" font-weight="bold" font-size="14">F₂ (较小)</text>
|
||||
<circle cx="100" cy="100" r="6" fill="#4f8cff"/>
|
||||
<circle cx="270" cy="100" r="6" fill="#ff6b6b"/>
|
||||
<text x="100" y="130" text-anchor="middle" fill="#5a6478" font-size="12">作用点</text>
|
||||
<text x="270" y="130" text-anchor="middle" fill="#5a6478" font-size="12">作用点</text>
|
||||
<text x="250" y="180" text-anchor="middle" fill="#1a202c" font-size="13" font-weight="600">力是矢量:既有大小又有方向</text>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="unit" class="animate-in">
|
||||
<h2 class="section-title">🔬 力的单位与测量</h2>
|
||||
<p class="section-sub">用牛顿(N)作为力的单位,使用弹簧测力计进行测量</p>
|
||||
<div class="grid-2">
|
||||
<div class="card">
|
||||
<span class="tag tag-primary">单位</span>
|
||||
<h3 style="margin:12px 0;font-size:1.3rem">牛顿 (N)</h3>
|
||||
<p style="color:var(--text-light)">为纪念英国科学家艾萨克·牛顿而命名。</p>
|
||||
<div style="margin-top:16px"><span class="formula">1 N ≈ 100 g 物体的重力</span></div>
|
||||
<p style="color:var(--text-light);margin-top:12px;font-size:.9rem">托起两个鸡蛋的力大约为 1N;一个中学生的体重大约为 500N。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<span class="tag tag-primary">测量工具</span>
|
||||
<h3 style="margin:12px 0;font-size:1.3rem">弹簧测力计</h3>
|
||||
<p style="color:var(--text-light)">利用弹簧的弹性形变来测量力的大小。<strong>原理:</strong>在弹性限度内,弹簧的伸长量与所受拉力成正比。</p>
|
||||
<div style="margin-top:16px;padding:12px;background:#f8faff;border-radius:10px">
|
||||
<strong style="color:var(--primary-dark)">使用注意:</strong>
|
||||
<ul style="margin-top:8px;padding-left:20px;color:var(--text-light);font-size:.9rem">
|
||||
<li>使用前调零</li>
|
||||
<li>被测力的方向沿弹簧轴线方向</li>
|
||||
<li>不能超过量程</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="gravity" class="animate-in">
|
||||
<h2 class="section-title">🌍 重力</h2>
|
||||
<p class="section-sub">由于地球的吸引而使物体受到的力,方向总是竖直向下</p>
|
||||
<div class="grid-2" style="margin-bottom:28px">
|
||||
<div class="card">
|
||||
<span class="tag tag-gravity">重力</span>
|
||||
<h3 style="margin:12px 0;font-size:1.3rem">重力的三要素</h3>
|
||||
<p style="color:var(--text-light)">
|
||||
<strong>大小:</strong><span class="formula">G = mg</span> <br>
|
||||
<strong>方向:</strong>总是<strong>竖直向下</strong>(垂直于水平面向下)<br>
|
||||
<strong>作用点:</strong>重心(形状规则、质量均匀的物体重心在其几何中心)
|
||||
</p>
|
||||
<p style="color:var(--text-light);margin-top:12px;font-size:.9rem">g 为重力加速度,通常取 g = 9.8 N/kg 或 g ≈ 10 N/kg。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3 style="margin-bottom:12px;font-size:1.2rem">🎮 交互实验:自由落体</h3>
|
||||
<p style="color:var(--text-light);font-size:.95rem">两个质量不同的球从同一高度同时下落,验证"同时落地"。忽略空气阻力时,下落时间与质量无关。</p>
|
||||
<div style="margin-top:12px;padding:12px;background:#fff5f5;border-radius:10px;color:#c92a2a;font-size:.88rem">💡 提示:在真空环境中,羽毛和铁球会同时落地!</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="experiment-card gravity">
|
||||
<div class="exp-header">
|
||||
<h3>🎮 自由落体模拟</h3>
|
||||
<span class="exp-badge">Canvas 交互</span>
|
||||
</div>
|
||||
<p class="exp-desc">点击"开始下落"按钮,观察两个质量不同的球是否同时落地。开启"空气阻力"后,重球会先落地。</p>
|
||||
<div class="canvas-wrap">
|
||||
<canvas id="gravityCanvas" width="800" height="400"></canvas>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label><input type="checkbox" id="airResistance"> 开启空气阻力</label>
|
||||
<button class="btn" id="dropBtn">▶ 开始下落</button>
|
||||
<button class="btn secondary" id="resetGravity">↻ 重置</button>
|
||||
</div>
|
||||
<div class="data-display">
|
||||
<div class="data-item"><span>大球落地时间</span><span class="g" id="bigTime">0.00 s</span></div>
|
||||
<div class="data-item"><span>小球落地时间</span><span class="g" id="smallTime">0.00 s</span></div>
|
||||
<div class="data-item"><span>当前状态</span><span id="gStatus">待开始</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="elastic" class="animate-in">
|
||||
<h2 class="section-title">🔩 弹力</h2>
|
||||
<p class="section-sub">物体发生弹性形变时产生的力,胡克定律描述了弹力与形变的关系</p>
|
||||
<div class="grid-2" style="margin-bottom:28px">
|
||||
<div class="card">
|
||||
<span class="tag tag-elastic">弹力</span>
|
||||
<h3 style="margin:12px 0;font-size:1.3rem">弹力的产生</h3>
|
||||
<p style="color:var(--text-light)">弹力是物体发生<strong>弹性形变</strong>时,在物体内部产生的恢复原状的力。</p>
|
||||
<p style="color:var(--text-light);margin-top:12px"><strong>产生条件:</strong>① 两物体相互接触;② 发生弹性形变。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3 style="margin-bottom:12px;font-size:1.2rem">📐 胡克定律</h3>
|
||||
<div style="margin:12px 0"><span class="formula">F = kx</span></div>
|
||||
<p style="color:var(--text-light)">在弹性限度内,弹簧的弹力 F 与形变量 x 成正比。</p>
|
||||
<div style="margin-top:12px;color:var(--text-light);font-size:.88rem"><strong>k — 弹簧的劲度系数 (N/m)</strong>,由弹簧本身的性质决定。</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="experiment-card elastic">
|
||||
<div class="exp-header">
|
||||
<h3>🎮 拉伸弹簧实验</h3>
|
||||
<span class="exp-badge">Canvas 交互</span>
|
||||
</div>
|
||||
<p class="exp-desc">拖动滑块拉伸弹簧,实时观察形变量 x 与弹力 F 的变化,直观验证 F = kx 的线性关系。</p>
|
||||
<div class="canvas-wrap">
|
||||
<canvas id="elasticCanvas" width="800" height="340"></canvas>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label>弹簧原长 L₀:<span class="val" id="l0Val">100</span> px</label>
|
||||
<label>劲度系数 k:<span class="val" id="kVal">50</span> N/m</label>
|
||||
<input type="range" id="kSlider" min="10" max="200" value="50" step="5">
|
||||
<button class="btn secondary" id="resetElastic">↻ 重置</button>
|
||||
</div>
|
||||
<div class="data-display">
|
||||
<div class="data-item"><span>形变量 x</span><span class="e" id="xVal">0 px</span></div>
|
||||
<div class="data-item"><span>弹力 F</span><span class="e" id="fVal">0.00 N</span></div>
|
||||
<div class="data-item"><span>弹簧长度</span><span id="lenVal">100 px</span></div>
|
||||
<div class="data-item"><span>弹性势能</span><span class="e" id="epVal">0.00 J</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="friction" class="animate-in">
|
||||
<h2 class="section-title">🧱 摩擦力</h2>
|
||||
<p class="section-sub">两个互相接触的物体,当它们要发生或已经发生相对运动时,在接触面上产生的阻碍相对运动的力</p>
|
||||
<div class="grid-3" style="margin-bottom:28px">
|
||||
<div class="card">
|
||||
<span class="tag tag-friction">滑动摩擦</span>
|
||||
<h3 style="margin:12px 0;font-size:1.15rem">滑动摩擦力</h3>
|
||||
<div style="margin:8px 0"><span class="formula">f = μN</span></div>
|
||||
<p style="color:var(--text-light);font-size:.9rem">物体滑动时受到的摩擦力,与<strong>压力大小</strong>和<strong>接触面粗糙程度</strong>有关。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<span class="tag tag-friction">静摩擦</span>
|
||||
<h3 style="margin:12px 0;font-size:1.15rem">静摩擦力</h3>
|
||||
<p style="color:var(--text-light);font-size:.9rem">物体有相对运动趋势但未滑动时受到的摩擦力,大小<strong>等于推力</strong>,随推力增大而增大,直到最大静摩擦。</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<span class="tag tag-friction">滚动摩擦</span>
|
||||
<h3 style="margin:12px 0;font-size:1.15rem">滚动摩擦力</h3>
|
||||
<p style="color:var(--text-light);font-size:.9rem">一个物体在另一个物体上滚动时产生的摩擦力。在相同条件下,滚动摩擦比滑动摩擦小得多。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="experiment-card friction">
|
||||
<div class="exp-header">
|
||||
<h3>🎮 推动木块实验</h3>
|
||||
<span class="exp-badge">拖拽或按住按钮</span>
|
||||
</div>
|
||||
<p class="exp-desc">点击并拖拽木块(左右皆可)模拟推力,或按住"左推/右推"按钮。调节压力和粗糙度,观察静摩擦→滑动摩擦的转变。</p>
|
||||
<div class="canvas-wrap">
|
||||
<canvas id="frictionCanvas" width="800" height="340"></canvas>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<button class="btn secondary" id="pushLeftBtn">◀ 左推</button>
|
||||
<button class="btn" id="pushBtn">▶ 右推</button>
|
||||
<button class="btn secondary" id="resetBtn">↻ 重置木块</button>
|
||||
<label>压力 N:<input type="range" id="normalSlider" min="50" max="300" value="100"><span class="val" id="normalVal">100</span> N</label>
|
||||
<label>粗糙度 μ:<input type="range" id="muSlider" min="0.05" max="0.8" value="0.3" step="0.05"><span class="val" id="muVal">0.30</span></label>
|
||||
</div>
|
||||
<div class="data-display">
|
||||
<div class="data-item"><span>状态</span><span class="f" id="motionState">静止</span></div>
|
||||
<div class="data-item"><span>推力</span><span id="forceVal">0 N</span></div>
|
||||
<div class="data-item"><span>摩擦力</span><span class="f" id="frictionForce">0.00 N</span></div>
|
||||
<div class="data-item"><span>最大静摩擦</span><span class="f" id="maxStatic">30.00 N</span></div>
|
||||
<div class="data-item"><span>滑动摩擦</span><span class="f" id="slidingF">24.00 N</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="compare" class="animate-in">
|
||||
<h2 class="section-title">📊 三种力对比</h2>
|
||||
<p class="section-sub">重力、弹力、摩擦力是力学中最常见的三种力,它们既有区别又有联系</p>
|
||||
<table class="comparison-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>对比项</th>
|
||||
<th><span class="tag tag-gravity">重力</span></th>
|
||||
<th><span class="tag tag-elastic">弹力</span></th>
|
||||
<th><span class="tag tag-friction">摩擦力</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="gravity-row"><td>产生原因</td><td>地球的吸引</td><td>物体发生弹性形变</td><td>接触面有相对运动或趋势</td></tr>
|
||||
<tr class="elastic-row"><td>大小</td><td>G = mg</td><td>F = kx(胡克定律)</td><td>静摩擦=推力;滑动 f = μN</td></tr>
|
||||
<tr class="friction-row"><td>方向</td><td>竖直向下</td><td>指向恢复形变方向</td><td>阻碍相对运动(趋势)</td></tr>
|
||||
<tr class="gravity-row"><td>作用点</td><td>重心</td><td>接触面上</td><td>接触面上</td></tr>
|
||||
<tr class="elastic-row"><td>施力物体</td><td>地球</td><td>发生形变的物体</td><td>接触面</td></tr>
|
||||
<tr class="friction-row"><td>联系</td><td colspan="3">弹力是摩擦力产生的必要条件;重力可影响压力大小,从而影响摩擦力;三种力都是接触力(重力除外),在日常生活中常常同时存在</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="life" class="animate-in">
|
||||
<h2 class="section-title">🌿 生活实例</h2>
|
||||
<p class="section-sub">力学无处不在,观察生活中的力现象</p>
|
||||
<div class="life-grid">
|
||||
<div class="life-card gravity">
|
||||
<div class="icon">🍎</div>
|
||||
<h4>重力的世界</h4>
|
||||
<p>熟透的苹果落地、瀑布飞流直下、雨滴从天空落下、抛出去的篮球最终落回地面……</p>
|
||||
<div class="life-examples"><span>苹果落地</span><span>瀑布</span><span>雨滴</span><span>篮球</span></div>
|
||||
</div>
|
||||
<div class="life-card elastic">
|
||||
<div class="icon">🏹</div>
|
||||
<h4>弹力的妙用</h4>
|
||||
<p>拉弓射箭、弹簧床垫、蹦蹦床、橡皮筋弹射、汽车减震器……都是弹力的应用。</p>
|
||||
<div class="life-examples"><span>弓箭</span><span>床垫</span><span>蹦床</span><span>减震器</span></div>
|
||||
</div>
|
||||
<div class="life-card friction">
|
||||
<div class="icon">👟</div>
|
||||
<h4>摩擦的利与弊</h4>
|
||||
<p>走路靠摩擦、轮胎抓地、刹车制动;但机器磨损、能量损耗又需要减小摩擦。</p>
|
||||
<div class="life-examples"><span>走路</span><span>轮胎</span><span>刹车</span><span>润滑</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<p>⚡ 力的课堂 — 认识力学的奇妙世界</p>
|
||||
<p style="margin-top:6px;font-size:.82rem">纯 HTML5 Canvas 实现 · 无第三方依赖 · 响应式设计</p>
|
||||
</footer>
|
||||
|
||||
<script src="./js/forces.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,737 @@
|
||||
/* 力的课堂 — 交互脚本 */
|
||||
// ============ 自由落体实验 ============
|
||||
(function(){
|
||||
const canvas = document.getElementById('gravityCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const W = canvas.width, H = canvas.height;
|
||||
const balls = {
|
||||
big: { x: 250, y: 40, r: 22, vy: 0, color: '#ff6b6b', mass: 3 },
|
||||
small: { x: 550, y: 40, r: 12, vy: 0, color: '#4f8cff', mass: 1 }
|
||||
};
|
||||
const floorY = 350;
|
||||
const g = 9.8;
|
||||
let running = false, startTime = 0;
|
||||
let landedBig = false, landedSmall = false;
|
||||
let timeBig = 0, timeSmall = 0;
|
||||
let airResistance = false;
|
||||
|
||||
function drawScene(){
|
||||
ctx.clearRect(0,0,W,H);
|
||||
ctx.fillStyle = '#e9ecef';
|
||||
ctx.fillRect(0, floorY, W, H - floorY);
|
||||
ctx.strokeStyle = '#adb5bd';
|
||||
ctx.setLineDash([4,4]);
|
||||
ctx.beginPath(); ctx.moveTo(0, floorY); ctx.lineTo(W, floorY); ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.font = '14px sans-serif';
|
||||
ctx.fillText('地面', 10, floorY - 6);
|
||||
ctx.strokeStyle = '#dee2e6'; ctx.lineWidth = 1;
|
||||
for(let y = 40; y < floorY; y += 40){
|
||||
ctx.beginPath(); ctx.moveTo(40, y); ctx.lineTo(60, y); ctx.stroke();
|
||||
ctx.fillStyle = '#adb5bd';
|
||||
ctx.fillText((floorY - y) + ' px', 10, y + 4);
|
||||
}
|
||||
drawBall(balls.big); drawBall(balls.small);
|
||||
ctx.fillStyle = '#495057'; ctx.font = 'bold 13px sans-serif';
|
||||
ctx.fillText('大球 (m=3kg)', balls.big.x - 30, 30);
|
||||
ctx.fillText('小球 (m=1kg)', balls.small.x - 30, 30);
|
||||
ctx.strokeStyle = 'rgba(255,107,107,.3)'; ctx.lineWidth = 2; ctx.setLineDash([6,4]);
|
||||
ctx.beginPath(); ctx.moveTo(balls.big.x, balls.big.y); ctx.lineTo(balls.big.x, floorY); ctx.stroke();
|
||||
ctx.strokeStyle = 'rgba(79,140,255,.3)';
|
||||
ctx.beginPath(); ctx.moveTo(balls.small.x, balls.small.y); ctx.lineTo(balls.small.x, floorY); ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
if(!running && !landedBig && !landedSmall){
|
||||
ctx.fillStyle = '#868e96'; ctx.font = '16px sans-serif';
|
||||
ctx.fillText('点击"开始下落"', W/2 - 60, H/2);
|
||||
}
|
||||
}
|
||||
function drawBall(b){
|
||||
const grad = ctx.createRadialGradient(b.x - b.r*0.3, b.y - b.r*0.3, b.r*0.1, b.x, b.y, b.r);
|
||||
grad.addColorStop(0, '#fff'); grad.addColorStop(0.3, b.color); grad.addColorStop(1, shadeColor(b.color, -30));
|
||||
ctx.fillStyle = grad;
|
||||
ctx.beginPath(); ctx.arc(b.x, b.y, b.r, 0, Math.PI*2); ctx.fill();
|
||||
ctx.strokeStyle = 'rgba(0,0,0,.2)'; ctx.lineWidth = 1; ctx.stroke();
|
||||
}
|
||||
function shadeColor(hex, percent){
|
||||
const f = parseInt(hex.slice(1),16); const t = percent < 0 ? 0 : 255;
|
||||
const p = Math.abs(percent)/100;
|
||||
const R = f >> 16, G = (f >> 8) & 0xff, B = f & 0xff;
|
||||
return '#' + (0x1000000 + (Math.round((t-R)*p)+R)*0x10000 + (Math.round((t-G)*p)+G)*0x100 + (Math.round((t-B)*p)+B)).toString(16).slice(1);
|
||||
}
|
||||
let lastTime = 0;
|
||||
function animate(t){
|
||||
if(!lastTime) lastTime = t;
|
||||
const dt = Math.min((t - lastTime)/1000, 0.05); lastTime = t;
|
||||
if(running){
|
||||
const elapsed = (t - startTime)/1000;
|
||||
if(!landedBig){
|
||||
const a = airResistance ? g - 0.001 * balls.big.vy * balls.big.vy / balls.big.mass : g;
|
||||
balls.big.vy += a * dt * 50;
|
||||
if(balls.big.vy < 0) balls.big.vy = 0;
|
||||
balls.big.y += balls.big.vy * dt * 2;
|
||||
if(balls.big.y >= floorY - balls.big.r){ balls.big.y = floorY - balls.big.r; balls.big.vy = 0; landedBig = true; timeBig = elapsed; }
|
||||
}
|
||||
if(!landedSmall){
|
||||
const a = airResistance ? g - 0.001 * balls.small.vy * balls.small.vy / balls.small.mass : g;
|
||||
balls.small.vy += a * dt * 50;
|
||||
if(balls.small.vy < 0) balls.small.vy = 0;
|
||||
balls.small.y += balls.small.vy * dt * 2;
|
||||
if(balls.small.y >= floorY - balls.small.r){ balls.small.y = floorY - balls.small.r; balls.small.vy = 0; landedSmall = true; timeSmall = elapsed; }
|
||||
}
|
||||
if(landedBig && landedSmall){ running = false; updateGravityUI(); }
|
||||
else updateGravityUI(elapsed);
|
||||
}
|
||||
drawScene(); requestAnimationFrame(animate);
|
||||
}
|
||||
function updateGravityUI(elapsed){
|
||||
document.getElementById('bigTime').textContent = landedBig ? timeBig.toFixed(2) + ' s' : (elapsed ? elapsed.toFixed(2) + ' s' : '0.00 s');
|
||||
document.getElementById('smallTime').textContent = landedSmall ? timeSmall.toFixed(2) + ' s' : (elapsed ? elapsed.toFixed(2) + ' s' : '0.00 s');
|
||||
if(!running && !landedBig && !landedSmall) document.getElementById('gStatus').textContent = '待开始';
|
||||
else if(landedBig && landedSmall){ const d = Math.abs(timeBig - timeSmall); document.getElementById('gStatus').textContent = d < 0.01 ? '同时落地!🎉' : (timeBig < timeSmall ? '大球先落地' : '小球先落地'); }
|
||||
else document.getElementById('gStatus').textContent = '下落中...';
|
||||
}
|
||||
document.getElementById('dropBtn').addEventListener('click', () => { if(running) return; resetBalls(); running = true; startTime = performance.now(); updateGravityUI(0); });
|
||||
document.getElementById('resetGravity').addEventListener('click', () => { resetBalls(); updateGravityUI(); });
|
||||
document.getElementById('airResistance').addEventListener('change', (e) => { airResistance = e.target.checked; });
|
||||
function resetBalls(){ balls.big.y = 40; balls.big.vy = 0; balls.small.y = 40; balls.small.vy = 0; landedBig = false; landedSmall = false; timeBig = 0; timeSmall = 0; running = false; updateGravityUI(); }
|
||||
updateGravityUI(); requestAnimationFrame(animate);
|
||||
})();
|
||||
|
||||
// ============ 拉伸弹簧实验 ============
|
||||
(function(){
|
||||
const canvas = document.getElementById('elasticCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const W = canvas.width, H = canvas.height;
|
||||
|
||||
let wallX = 80;
|
||||
let springY = H / 2;
|
||||
let l0 = 100;
|
||||
let k = 50;
|
||||
let dragging = false;
|
||||
let hoverHandle = false;
|
||||
let dragHandleX = wallX + l0;
|
||||
|
||||
function drawScene(){
|
||||
ctx.clearRect(0, 0, W, H);
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.fillRect(wallX - 20, springY - 80, 160, 160);
|
||||
ctx.strokeStyle = '#495057';
|
||||
ctx.lineWidth = 2;
|
||||
for(let i = 0; i < 10; i++){
|
||||
const y = springY - 80 + i * 18;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(wallX - 20, y);
|
||||
ctx.lineTo(wallX, y + 15);
|
||||
ctx.stroke();
|
||||
}
|
||||
const endX = dragHandleX;
|
||||
const currentLen = endX - wallX;
|
||||
const x = currentLen - l0;
|
||||
drawSpring(wallX, springY, endX, springY, 14);
|
||||
const isHover = hoverHandle;
|
||||
const glowR = isHover ? 40 : 0;
|
||||
if(glowR > 0){
|
||||
const glow = ctx.createRadialGradient(endX, springY, 5, endX, springY, glowR);
|
||||
glow.addColorStop(0, 'rgba(79,140,255,.35)');
|
||||
glow.addColorStop(1, 'rgba(79,140,255,0)');
|
||||
ctx.fillStyle = glow;
|
||||
ctx.beginPath(); ctx.arc(endX, springY, glowR, 0, Math.PI*2); ctx.fill();
|
||||
}
|
||||
ctx.fillStyle = '#2a5bd7';
|
||||
ctx.fillRect(endX - 14, springY - 38, 28, 76);
|
||||
ctx.fillStyle = isHover ? '#4f8cff' : '#5c7cfa';
|
||||
ctx.fillRect(endX - 12, springY - 36, 24, 72);
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.font = 'bold 11px sans-serif';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText('⇔', endX, springY + 4);
|
||||
ctx.textAlign = 'start';
|
||||
if(x > 0){
|
||||
ctx.strokeStyle = '#ff6b6b';
|
||||
ctx.fillStyle = '#ff6b6b';
|
||||
ctx.lineWidth = 2;
|
||||
const forceLen = Math.min(x * 0.7, 100);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(endX, springY + 50);
|
||||
ctx.lineTo(endX + forceLen, springY + 50);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(endX + forceLen, springY + 50);
|
||||
ctx.lineTo(endX + forceLen - 8, springY + 45);
|
||||
ctx.lineTo(endX + forceLen - 8, springY + 55);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.fillStyle = '#c92a2a';
|
||||
ctx.font = 'bold 14px sans-serif';
|
||||
const forceN = (k * x / 50).toFixed(1);
|
||||
ctx.fillText('F = ' + forceN + ' N', endX + forceLen + 8, springY + 55);
|
||||
}
|
||||
ctx.strokeStyle = '#adb5bd';
|
||||
ctx.setLineDash([4,4]);
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath(); ctx.moveTo(wallX + l0, springY - 60); ctx.lineTo(wallX + l0, springY + 60); ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.font = '12px sans-serif';
|
||||
ctx.fillText('原长 L₀=' + l0 + 'px', wallX + l0 - 30, springY - 70);
|
||||
ctx.fillStyle = '#495057';
|
||||
ctx.font = '13px sans-serif';
|
||||
ctx.fillText('当前长度 L=' + currentLen + 'px', 20, 30);
|
||||
ctx.fillText('形变量 x=' + x + 'px', 20, 55);
|
||||
drawFXChart(x);
|
||||
}
|
||||
|
||||
function drawSpring(x1, y1, x2, y2, coils){
|
||||
const len = x2 - x1;
|
||||
const amplitude = 10;
|
||||
ctx.strokeStyle = '#5c7cfa';
|
||||
ctx.lineWidth = 3;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x1, y1);
|
||||
for(let i = 0; i <= coils * 2; i++){
|
||||
const t = i / (coils * 2);
|
||||
const px = x1 + len * t;
|
||||
const py = y1 + (i % 2 === 0 ? -amplitude : amplitude);
|
||||
ctx.lineTo(px, py);
|
||||
}
|
||||
ctx.lineTo(x2, y2);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function drawFXChart(currentX){
|
||||
const cx = 500, cy = 100;
|
||||
const cw = 250, ch = 140;
|
||||
ctx.fillStyle = 'rgba(248,250,255,.8)';
|
||||
ctx.fillRect(cx, cy, cw, ch);
|
||||
ctx.strokeStyle = '#dee2e6';
|
||||
ctx.strokeRect(cx, cy, cw, ch);
|
||||
ctx.strokeStyle = '#868e96';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cx, cy + ch - 20);
|
||||
ctx.lineTo(cx + cw - 10, cy + ch - 20);
|
||||
ctx.lineTo(cx, cy + ch - 20);
|
||||
ctx.lineTo(cx, cy + 10);
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.font = '10px sans-serif';
|
||||
ctx.fillText('x (px)', cx + cw - 30, cy + ch - 5);
|
||||
ctx.save();
|
||||
ctx.translate(cx + 10, cy + ch - 20);
|
||||
ctx.rotate(-Math.PI/2);
|
||||
ctx.fillText('F (N)', 0, 0);
|
||||
ctx.restore();
|
||||
ctx.strokeStyle = '#51cf66';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.beginPath();
|
||||
for(let i = 0; i <= 40; i++){
|
||||
const px = i / 40;
|
||||
const xVal = px * 400;
|
||||
const fVal = k * xVal / 50;
|
||||
const px_ = cx + 10 + (xVal / 400) * (cw - 20);
|
||||
const py_ = cy + ch - 20 - (fVal / 80) * (ch - 30);
|
||||
if(i === 0) ctx.moveTo(px_, py_);
|
||||
else ctx.lineTo(px_, py_);
|
||||
}
|
||||
ctx.stroke();
|
||||
const curF = k * currentX / 50;
|
||||
const dotPx = cx + 10 + (Math.max(0, currentX) / 400) * (cw - 20);
|
||||
const dotPy = cy + ch - 20 - (Math.max(0, curF) / 80) * (ch - 30);
|
||||
ctx.fillStyle = '#ff6b6b';
|
||||
ctx.beginPath(); ctx.arc(dotPx, dotPy, 5, 0, Math.PI*2); ctx.fill();
|
||||
ctx.strokeStyle = '#fff';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function updateUI(){
|
||||
const curLen = dragHandleX - wallX;
|
||||
const x = curLen - l0;
|
||||
const F = k * x / 50;
|
||||
const ep = 0.5 * k * x * x / 2500;
|
||||
document.getElementById('l0Val').textContent = l0;
|
||||
document.getElementById('kVal').textContent = k;
|
||||
document.getElementById('xVal').textContent = x + ' px';
|
||||
document.getElementById('fVal').textContent = (x > 0 ? F.toFixed(2) : '0.00') + ' N';
|
||||
document.getElementById('lenVal').textContent = curLen + ' px';
|
||||
document.getElementById('epVal').textContent = (x > 0 ? ep.toFixed(2) : '0.00') + ' J';
|
||||
}
|
||||
|
||||
function toCanvasXY(clientX, clientY){
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
return {
|
||||
x: (clientX - rect.left) * (W / rect.width),
|
||||
y: (clientY - rect.top) * (H / rect.height)
|
||||
};
|
||||
}
|
||||
|
||||
canvas.addEventListener('mousedown', (e) => {
|
||||
const {x:mx, y:my} = toCanvasXY(e.clientX, e.clientY);
|
||||
if(Math.abs(mx - dragHandleX) < 50 && Math.abs(my - springY) < 50){
|
||||
dragging = true;
|
||||
canvas.style.cursor = 'grabbing';
|
||||
}
|
||||
});
|
||||
window.addEventListener('mousemove', (e) => {
|
||||
const {x:mx, y:my} = toCanvasXY(e.clientX, e.clientY);
|
||||
const nearHandle = Math.abs(mx - dragHandleX) < 50 && Math.abs(my - springY) < 50;
|
||||
hoverHandle = nearHandle;
|
||||
if(!dragging){
|
||||
canvas.style.cursor = nearHandle ? 'grab' : 'default';
|
||||
return;
|
||||
}
|
||||
dragHandleX = Math.max(wallX + 20, Math.min(mx, W - 40));
|
||||
updateUI();
|
||||
});
|
||||
window.addEventListener('mouseup', () => {
|
||||
dragging = false;
|
||||
canvas.style.cursor = hoverHandle ? 'grab' : 'default';
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
const t = e.touches[0];
|
||||
const {x:mx, y:my} = toCanvasXY(t.clientX, t.clientY);
|
||||
if(Math.abs(mx - dragHandleX) < 70 && Math.abs(my - springY) < 70){
|
||||
dragging = true;
|
||||
}
|
||||
e.preventDefault();
|
||||
}, {passive: false});
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
if(!dragging) return;
|
||||
const t = e.touches[0];
|
||||
const {x:mx} = toCanvasXY(t.clientX, t.clientY);
|
||||
dragHandleX = Math.max(wallX + 20, Math.min(mx, W - 40));
|
||||
updateUI();
|
||||
e.preventDefault();
|
||||
}, {passive: false});
|
||||
canvas.addEventListener('touchend', () => dragging = false);
|
||||
|
||||
document.getElementById('kSlider').addEventListener('input', (e) => {
|
||||
k = parseInt(e.target.value);
|
||||
updateUI();
|
||||
});
|
||||
document.getElementById('resetElastic').addEventListener('click', () => {
|
||||
dragHandleX = wallX + l0;
|
||||
k = 50;
|
||||
document.getElementById('kSlider').value = 50;
|
||||
updateUI();
|
||||
});
|
||||
|
||||
function loop(){
|
||||
drawScene();
|
||||
requestAnimationFrame(loop);
|
||||
}
|
||||
updateUI();
|
||||
loop();
|
||||
})();
|
||||
|
||||
// ============ 推动木块实验 ============
|
||||
(function(){
|
||||
const canvas = document.getElementById('frictionCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const W = canvas.width, H = canvas.height;
|
||||
|
||||
let box = { x: 160, y: 130, w: 110, h: 75 };
|
||||
let gY = 230;
|
||||
let nF = 100, mu = 0.3;
|
||||
let vel = 0, moving = false;
|
||||
let appF = 0, maxAppF = 300;
|
||||
let forceTarget = 0;
|
||||
let holding = false;
|
||||
let holdingLeft = false;
|
||||
let dragging = false, dragTargetX = 0, dragOffsetX = 0, hoverBox = false;
|
||||
let squash = 0;
|
||||
|
||||
const muK = 0.8;
|
||||
|
||||
function maxStaticF(){ return mu * nF; }
|
||||
function slidingF(){ return mu * muK * nF; }
|
||||
|
||||
function toCanvasXY(clientX, clientY){
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
return {
|
||||
x: (clientX - rect.left) * (W / rect.width),
|
||||
y: (clientY - rect.top) * (H / rect.height)
|
||||
};
|
||||
}
|
||||
|
||||
function drawScene(){
|
||||
ctx.clearRect(0, 0, W, H);
|
||||
const groundGrad = ctx.createLinearGradient(0, gY, 0, H);
|
||||
groundGrad.addColorStop(0, '#f1f3f5');
|
||||
groundGrad.addColorStop(1, '#e9ecef');
|
||||
ctx.fillStyle = groundGrad;
|
||||
ctx.fillRect(0, gY, W, H - gY);
|
||||
ctx.strokeStyle = '#adb5bd';
|
||||
ctx.lineWidth = 1;
|
||||
const rough = Math.floor(mu * 25);
|
||||
for(let x = 0; x < W; x += 6){
|
||||
const off = Math.sin(x * 0.15) * rough;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x, gY);
|
||||
ctx.lineTo(x + 3, gY - 2 - off);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.font = '11px sans-serif';
|
||||
ctx.fillText('接触面 (μ=' + mu.toFixed(2) + ')', 10, gY + 18);
|
||||
drawForceBars();
|
||||
const sq = squash;
|
||||
const bw = box.w * (1 - sq * 0.15);
|
||||
const bh = box.h * (1 + sq * 0.2);
|
||||
const bx = box.x + (box.w - bw) / 2;
|
||||
const by = box.y + (box.h - bh);
|
||||
if(hoverBox && !dragging){
|
||||
ctx.shadowColor = '#4f8cff';
|
||||
ctx.shadowBlur = 12;
|
||||
} else if(moving){
|
||||
ctx.shadowColor = '#ff6b6b';
|
||||
ctx.shadowBlur = 10;
|
||||
} else {
|
||||
ctx.shadowColor = 'rgba(0,0,0,.15)';
|
||||
ctx.shadowBlur = 6;
|
||||
}
|
||||
const grad = ctx.createLinearGradient(bx, by, bx, by + bh);
|
||||
grad.addColorStop(0, '#ffd43b');
|
||||
grad.addColorStop(1, '#fab005');
|
||||
ctx.fillStyle = grad;
|
||||
ctx.fillRect(bx, by, bw, bh);
|
||||
ctx.shadowBlur = 0;
|
||||
ctx.strokeStyle = hoverBox ? '#4f8cff' : '#b8860b';
|
||||
ctx.lineWidth = hoverBox ? 3 : 2;
|
||||
ctx.strokeRect(bx, by, bw, bh);
|
||||
ctx.fillStyle = '#868e96';
|
||||
ctx.font = 'bold 14px sans-serif';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText('m', bx + bw / 2, by + bh / 2 + 5);
|
||||
ctx.textAlign = 'start';
|
||||
const absAppF = Math.abs(appF);
|
||||
if(absAppF > 0.5){
|
||||
const aLen = Math.min(absAppF * 0.55, 150);
|
||||
const label = 'F推=' + Math.round(absAppF) + 'N';
|
||||
if(appF >= 0){
|
||||
drawArrow(bx - aLen - 18, by + bh / 2, bx - 5, by + bh / 2, '#4f8cff', label);
|
||||
} else {
|
||||
drawArrow(bx + bw + aLen + 18, by + bh / 2, bx + bw + 5, by + bh / 2, '#4f8cff', label);
|
||||
}
|
||||
}
|
||||
const maxS = maxStaticF();
|
||||
if(absAppF > 0.5 || moving){
|
||||
if(moving){
|
||||
const fricVal = slidingF();
|
||||
const fLen = Math.min(fricVal * 0.55, 150);
|
||||
if(vel > 0){
|
||||
drawArrow(bx + bw + fLen + 18, by + bh / 2 + 18, bx + bw + 5, by + bh / 2 + 18, '#ff6b6b', 'f滑=' + fricVal.toFixed(1) + 'N');
|
||||
} else {
|
||||
drawArrow(bx - fLen - 18, by + bh / 2 + 18, bx - 5, by + bh / 2 + 18, '#ff6b6b', 'f滑=' + fricVal.toFixed(1) + 'N');
|
||||
}
|
||||
} else {
|
||||
const fricVal = Math.min(absAppF, maxS);
|
||||
const fLen = Math.min(fricVal * 0.55, 150);
|
||||
if(appF >= 0){
|
||||
drawArrow(bx + bw + fLen + 18, by + bh / 2 + 18, bx + bw + 5, by + bh / 2 + 18, '#f76707', 'f静=' + fricVal.toFixed(1) + 'N');
|
||||
} else {
|
||||
drawArrow(bx - fLen - 18, by + bh / 2 + 18, bx - 5, by + bh / 2 + 18, '#f76707', 'f静=' + fricVal.toFixed(1) + 'N');
|
||||
}
|
||||
}
|
||||
}
|
||||
drawArrow(bx + bw / 2, by - 5, bx + bw / 2, by - 50, '#5c7cfa', 'G=' + nF + 'N');
|
||||
drawArrow(bx + bw / 2, by + bh + 5, bx + bw / 2, by + bh + 50, '#51cf66', 'N=' + nF + 'N');
|
||||
ctx.fillStyle = moving ? '#c92a2a' : (absAppF > maxS ? '#e67700' : '#2b8a3e');
|
||||
ctx.font = 'bold 15px sans-serif';
|
||||
const stateTxt = moving ? ('运动中 ' + (vel > 0 ? '→' : '←') + ' (v=' + Math.abs(vel).toFixed(1) + ')') : (absAppF > maxS ? '即将滑动…' : '■ 静止');
|
||||
ctx.fillText(stateTxt, 20, 28);
|
||||
if(hoverBox && !dragging){
|
||||
ctx.fillStyle = '#4f8cff';
|
||||
ctx.font = '12px sans-serif';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText('← 拖拽木块施加推力 →', bx + bw / 2, by - 60);
|
||||
ctx.textAlign = 'start';
|
||||
}
|
||||
if(dragging){
|
||||
const boxCenter = box.x + box.w / 2;
|
||||
const cy = box.y + box.h / 2;
|
||||
const tx = Math.max(20, Math.min(W - 20, dragTargetX));
|
||||
ctx.strokeStyle = 'rgba(79,140,255,.6)';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.setLineDash([5, 4]);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tx, cy);
|
||||
ctx.lineTo(boxCenter, cy);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.fillStyle = 'rgba(79,140,255,.3)';
|
||||
ctx.beginPath();
|
||||
ctx.arc(tx, cy, 7, 0, Math.PI*2);
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = '#4f8cff';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
function drawForceBars(){
|
||||
const barY = gY + 35;
|
||||
const barH = 14;
|
||||
const barW = 220;
|
||||
const barX = W - barW - 30;
|
||||
const maxVal = Math.max(maxStaticF() * 1.2, maxAppF);
|
||||
ctx.fillStyle = '#e9ecef';
|
||||
ctx.fillRect(barX, barY, barW, barH);
|
||||
ctx.fillRect(barX, barY + 22, barW, barH);
|
||||
ctx.fillRect(barX, barY + 44, barW, barH);
|
||||
const maxS = maxStaticF();
|
||||
const sF = slidingF();
|
||||
const absAppF = Math.abs(appF);
|
||||
const appRatio = Math.min(absAppF / maxVal, 1);
|
||||
const maxSRatio = Math.min(maxS / maxVal, 1);
|
||||
const sFRatio = Math.min(sF / maxVal, 1);
|
||||
const appColor = absAppF > maxS ? '#ff6b6b' : '#4f8cff';
|
||||
ctx.fillStyle = appColor;
|
||||
ctx.fillRect(barX, barY, barW * appRatio, barH);
|
||||
ctx.fillStyle = '#fcc419';
|
||||
ctx.fillRect(barX, barY + 22, barW * maxSRatio, barH);
|
||||
ctx.fillStyle = '#ff8787';
|
||||
ctx.fillRect(barX, barY + 44, barW * sFRatio, barH);
|
||||
if(maxS > 0){
|
||||
const thX = barX + barW * maxSRatio;
|
||||
ctx.strokeStyle = '#e67700';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.setLineDash([4, 3]);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(thX, barY - 4);
|
||||
ctx.lineTo(thX, barY + barH + 70);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
ctx.fillStyle = '#e67700';
|
||||
ctx.font = '10px sans-serif';
|
||||
ctx.fillText('最大静摩擦阈值', thX + 4, barY - 6);
|
||||
}
|
||||
ctx.fillStyle = '#495057';
|
||||
ctx.font = 'bold 11px sans-serif';
|
||||
ctx.textAlign = 'right';
|
||||
ctx.fillText('推力', barX - 5, barY + 11);
|
||||
ctx.fillText('最大静摩擦', barX - 5, barY + 33);
|
||||
ctx.fillText('滑动摩擦', barX - 5, barY + 55);
|
||||
ctx.textAlign = 'start';
|
||||
ctx.fillStyle = appColor;
|
||||
ctx.font = 'bold 10px sans-serif';
|
||||
ctx.fillText(Math.round(absAppF) + ' N', barX + barW + 5, barY + 11);
|
||||
ctx.fillStyle = '#b8860b';
|
||||
ctx.fillText(maxS.toFixed(1) + ' N', barX + barW + 5, barY + 33);
|
||||
ctx.fillStyle = '#c92a2a';
|
||||
ctx.fillText(sF.toFixed(1) + ' N', barX + barW + 5, barY + 55);
|
||||
}
|
||||
|
||||
function drawArrow(x1, y1, x2, y2, color, label){
|
||||
ctx.strokeStyle = color;
|
||||
ctx.fillStyle = color;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x1, y1);
|
||||
ctx.lineTo(x2, y2);
|
||||
ctx.stroke();
|
||||
const angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
const headLen = 10;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x2, y2);
|
||||
ctx.lineTo(x2 - headLen * Math.cos(angle - Math.PI / 6), y2 - headLen * Math.sin(angle - Math.PI / 6));
|
||||
ctx.lineTo(x2 - headLen * Math.cos(angle + Math.PI / 6), y2 - headLen * Math.sin(angle + Math.PI / 6));
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
if(label){
|
||||
const mx = (x1 + x2) / 2;
|
||||
const my = (y1 + y2) / 2;
|
||||
ctx.font = 'bold 11px sans-serif';
|
||||
const metrics = ctx.measureText(label);
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.fillRect(mx - metrics.width / 2 - 3, my - 8, metrics.width + 6, 16);
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(mx - metrics.width / 2 - 3, my - 8, metrics.width + 6, 16);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fillText(label, mx - metrics.width / 2, my + 4);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePhysics(){
|
||||
const maxS = maxStaticF();
|
||||
const sF = slidingF();
|
||||
const mass = nF / 10;
|
||||
if(holding){
|
||||
forceTarget = Math.min(forceTarget + 4, maxAppF);
|
||||
} else if(holdingLeft){
|
||||
forceTarget = Math.max(forceTarget - 4, -maxAppF);
|
||||
} else if(dragging){
|
||||
const boxCenter = box.x + box.w / 2;
|
||||
const pull = dragTargetX - boxCenter;
|
||||
forceTarget = Math.max(-maxAppF, Math.min(pull * 2.5, maxAppF));
|
||||
} else {
|
||||
forceTarget *= 0.92;
|
||||
if(Math.abs(forceTarget) < 0.5) forceTarget = 0;
|
||||
}
|
||||
appF += (forceTarget - appF) * 0.25;
|
||||
const absAppF = Math.abs(appF);
|
||||
if(Math.abs(vel) < 0.01 && absAppF <= maxS + 0.5){
|
||||
vel = 0;
|
||||
moving = false;
|
||||
} else {
|
||||
moving = true;
|
||||
vel += (appF / mass) * 0.016;
|
||||
if(Math.abs(vel) > 0.01){
|
||||
const fricStep = (sF / mass) * 0.016;
|
||||
if(vel > 0) vel = Math.max(0, vel - fricStep);
|
||||
else vel = Math.min(0, vel + fricStep);
|
||||
}
|
||||
}
|
||||
// 拖拽时按距光标的剩余距离限制速度,越接近光标限速越低,
|
||||
// 避免速度过大冲过光标后弹簧反向拉回造成左右摆动
|
||||
if(dragging && moving){
|
||||
const pullNow = dragTargetX - (box.x + box.w / 2);
|
||||
const limitV = Math.abs(pullNow) * 0.18 + 0.5;
|
||||
if(vel > limitV) vel = limitV;
|
||||
else if(vel < -limitV) vel = -limitV;
|
||||
}
|
||||
if(moving){
|
||||
box.x += vel * 0.016 * 60;
|
||||
if(box.x < 20){ box.x = 20; vel = 0; moving = false; }
|
||||
if(box.x + box.w > W - 20){ box.x = W - 20 - box.w; vel = 0; moving = false; }
|
||||
}
|
||||
squash *= 0.85;
|
||||
if(moving && Math.abs(vel) > 5) squash = Math.min(Math.abs(vel) / 40, 0.6);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function updateUI(){
|
||||
document.getElementById('forceVal').textContent = Math.round(Math.abs(appF)) + ' N';
|
||||
document.getElementById('normalVal').textContent = nF;
|
||||
document.getElementById('muVal').textContent = mu.toFixed(2);
|
||||
const maxS = maxStaticF();
|
||||
const sF = slidingF();
|
||||
document.getElementById('maxStatic').textContent = maxS.toFixed(2) + ' N';
|
||||
document.getElementById('slidingF').textContent = sF.toFixed(2) + ' N';
|
||||
const absAppF = Math.abs(appF);
|
||||
if(moving){
|
||||
const dir = vel > 0 ? '→' : '←';
|
||||
document.getElementById('frictionForce').textContent = '滑动摩擦 ' + sF.toFixed(2) + ' N';
|
||||
document.getElementById('motionState').textContent = '运动中 ' + dir + ' (滑动摩擦)';
|
||||
} else if(absAppF > 0.5){
|
||||
const dir = appF > 0 ? '→' : '←';
|
||||
if(absAppF <= maxS){
|
||||
document.getElementById('frictionForce').textContent = '静摩擦 ' + absAppF.toFixed(2) + ' N';
|
||||
document.getElementById('motionState').textContent = '静止 ' + dir + ' (静摩擦)';
|
||||
} else {
|
||||
document.getElementById('frictionForce').textContent = '静摩擦 ' + maxS.toFixed(2) + ' N';
|
||||
document.getElementById('motionState').textContent = '即将滑动 ' + dir + '…';
|
||||
}
|
||||
} else {
|
||||
document.getElementById('frictionForce').textContent = '0.00 N';
|
||||
document.getElementById('motionState').textContent = '静止';
|
||||
}
|
||||
}
|
||||
|
||||
canvas.addEventListener('mousemove', (e) => {
|
||||
const p = toCanvasXY(e.clientX, e.clientY);
|
||||
hoverBox = p.x >= box.x && p.x <= box.x + box.w && p.y >= box.y && p.y <= box.y + box.h;
|
||||
canvas.style.cursor = hoverBox ? 'grab' : 'default';
|
||||
});
|
||||
|
||||
canvas.addEventListener('mousedown', (e) => {
|
||||
const p = toCanvasXY(e.clientX, e.clientY);
|
||||
if(hoverBox){
|
||||
dragging = true;
|
||||
dragTargetX = box.x + box.w / 2;
|
||||
dragOffsetX = p.x - (box.x + box.w / 2);
|
||||
canvas.style.cursor = 'grabbing';
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('mousemove', (e) => {
|
||||
if(!dragging) return;
|
||||
const p = toCanvasXY(e.clientX, e.clientY);
|
||||
dragTargetX = p.x - dragOffsetX;
|
||||
});
|
||||
|
||||
window.addEventListener('mouseup', () => {
|
||||
if(dragging){
|
||||
dragging = false;
|
||||
canvas.style.cursor = hoverBox ? 'grab' : 'default';
|
||||
}
|
||||
});
|
||||
|
||||
canvas.addEventListener('touchstart', (e) => {
|
||||
e.preventDefault();
|
||||
const t = e.touches[0];
|
||||
const p = toCanvasXY(t.clientX, t.clientY);
|
||||
if(p.x >= box.x && p.x <= box.x + box.w && p.y >= box.y && p.y <= box.y + box.h){
|
||||
dragging = true;
|
||||
dragTargetX = box.x + box.w / 2;
|
||||
dragOffsetX = p.x - (box.x + box.w / 2);
|
||||
}
|
||||
}, { passive: false });
|
||||
|
||||
canvas.addEventListener('touchmove', (e) => {
|
||||
e.preventDefault();
|
||||
if(!dragging) return;
|
||||
const t = e.touches[0];
|
||||
const p = toCanvasXY(t.clientX, t.clientY);
|
||||
dragTargetX = p.x - dragOffsetX;
|
||||
}, { passive: false });
|
||||
|
||||
window.addEventListener('touchend', () => {
|
||||
dragging = false;
|
||||
});
|
||||
|
||||
const pushBtn = document.getElementById('pushBtn');
|
||||
pushBtn.addEventListener('mousedown', () => { holding = true; });
|
||||
pushBtn.addEventListener('mouseup', () => { holding = false; });
|
||||
pushBtn.addEventListener('mouseleave', () => { holding = false; });
|
||||
pushBtn.addEventListener('touchstart', (e) => { e.preventDefault(); holding = true; });
|
||||
pushBtn.addEventListener('touchend', () => { holding = false; });
|
||||
|
||||
const pushLeftBtn = document.getElementById('pushLeftBtn');
|
||||
pushLeftBtn.addEventListener('mousedown', () => { holdingLeft = true; });
|
||||
pushLeftBtn.addEventListener('mouseup', () => { holdingLeft = false; });
|
||||
pushLeftBtn.addEventListener('mouseleave', () => { holdingLeft = false; });
|
||||
pushLeftBtn.addEventListener('touchstart', (e) => { e.preventDefault(); holdingLeft = true; });
|
||||
pushLeftBtn.addEventListener('touchend', () => { holdingLeft = false; });
|
||||
|
||||
document.getElementById('resetBtn').addEventListener('click', () => {
|
||||
box.x = 160;
|
||||
vel = 0;
|
||||
moving = false;
|
||||
appF = 0;
|
||||
forceTarget = 0;
|
||||
squash = 0;
|
||||
});
|
||||
|
||||
document.getElementById('normalSlider').addEventListener('input', (e) => {
|
||||
nF = parseInt(e.target.value);
|
||||
});
|
||||
document.getElementById('muSlider').addEventListener('input', (e) => {
|
||||
mu = parseFloat(e.target.value);
|
||||
});
|
||||
|
||||
function animate(){
|
||||
updatePhysics();
|
||||
drawScene();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
updateUI();
|
||||
animate();
|
||||
})();
|
||||
|
||||
// ============ 滚动显示动画 ============
|
||||
(function(){
|
||||
const els = document.querySelectorAll('.animate-in');
|
||||
const io = new IntersectionObserver((entries) => {
|
||||
entries.forEach(e => {
|
||||
if(e.isIntersecting){
|
||||
e.target.classList.add('visible');
|
||||
io.unobserve(e.target);
|
||||
}
|
||||
});
|
||||
}, { threshold: 0.1 });
|
||||
els.forEach(el => io.observe(el));
|
||||
})();
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="refresh" content="0; url=https://git.xiaozhou233.cn/xiaozhou233/RiverWaterQualityMonitoring">
|
||||
<title>Redirecting...</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>正在跳转到 <a href="https://git.xiaozhou233.cn/xiaozhou233/RiverWaterQualityMonitoring">https://git.xiaozhou233.cn/xiaozhou233/RiverWaterQualityMonitoring</a>...</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,7 +2,6 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>筱周の网站 - XiaoZhou's Website</title>
|
||||
<script defer src="https://umami.xiaozhou233.cn/script.js" data-website-id="5a5128e4-1e6c-4c0f-8f45-536d929aa2a1"></script>
|
||||
|
||||
Generated
+412
-3662
File diff suppressed because it is too large.
Load diff
+1
-6
@@ -12,17 +12,12 @@
|
||||
"dependencies": {
|
||||
"@fontsource-variable/geist": "^5.2.9",
|
||||
"@tailwindcss/vite": "^4.3.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^1.17.0",
|
||||
"react": "^19.2.6",
|
||||
"react-dom": "^19.2.6",
|
||||
"tailwind-merge": "^3.6.0",
|
||||
"tailwindcss": "^4.3.0",
|
||||
"tw-animate-css": "^1.4.0"
|
||||
"tailwindcss": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"shadcn": "^4.8.2",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@types/node": "^24.12.4",
|
||||
"@types/react": "^19.2.14",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB |
+14
-3
@@ -1,12 +1,23 @@
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const indexHtml = readFileSync(resolve(root, "dist", "index.html"), "utf8");
|
||||
const distDir = resolve(root, "dist");
|
||||
const indexHtml = readFileSync(resolve(distDir, "index.html"), "utf8");
|
||||
|
||||
const moreDir = resolve(root, "dist", "more");
|
||||
const moreDir = resolve(distDir, "more");
|
||||
mkdirSync(moreDir, { recursive: true });
|
||||
writeFileSync(resolve(moreDir, "index.html"), indexHtml);
|
||||
|
||||
console.log("Copied dist/index.html -> dist/more/index.html");
|
||||
|
||||
// 把项目根目录 extra/ 里的所有文件递归复制到 dist/(每次构建)
|
||||
// 目录不存在时跳过,方便用户按需启用
|
||||
const extraDir = resolve(root, "extra");
|
||||
if (existsSync(extraDir)) {
|
||||
cpSync(extraDir, distDir, { recursive: true });
|
||||
console.log("Copied extra/ -> dist/");
|
||||
} else {
|
||||
console.log("Skipped extra/ (not found)");
|
||||
}
|
||||
+14
-22
@@ -1,22 +1,14 @@
|
||||
import Banner from "./components/Banner";
|
||||
import AboutSection from "./components/sections/AboutSection";
|
||||
import ProjectsSection from "./components/sections/ProjectsSection";
|
||||
import ContactSection from "./components/sections/ContactSection";
|
||||
import MorePage from "./pages/MorePage";
|
||||
|
||||
export default function App() {
|
||||
const { pathname } = window.location;
|
||||
|
||||
if (/^\/more(\/index\.html)?\/?$/.test(pathname)) {
|
||||
return <MorePage />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-black">
|
||||
<Banner />
|
||||
<AboutSection />
|
||||
<ProjectsSection />
|
||||
<ContactSection />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import { useEffect } from "react";
|
||||
import { useRoute } from "@/router";
|
||||
|
||||
// Resolves the current path to a page via the route registry.
|
||||
export default function App() {
|
||||
const { route } = useRoute();
|
||||
|
||||
useEffect(() => {
|
||||
document.title = route.title;
|
||||
}, [route.title]);
|
||||
|
||||
const { Component } = route;
|
||||
return <Component />;
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
import { Link } from "@/router";
|
||||
import type { NavItem } from "@/types";
|
||||
|
||||
interface NavCardProps {
|
||||
item: NavItem;
|
||||
}
|
||||
|
||||
// A clickable navigation card with icon, title, and description
|
||||
// A clickable navigation card with icon, title, and description.
|
||||
// Internal paths ("/...") route client-side; external URLs open in a new tab.
|
||||
export default function NavCard({ item }: NavCardProps) {
|
||||
const { name, desc, path, Icon, color, borderHover } = item;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={path}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={`flex items-center md:flex-col md:text-center gap-5 md:gap-4 p-6 md:py-8 rounded-2xl bg-black/35 backdrop-blur-md border border-white/5 transition-all duration-300 cursor-pointer hover:-translate-y-1 hover:bg-black/45 ${borderHover} group block`}
|
||||
>
|
||||
const className = `flex items-center md:flex-col md:text-center gap-5 md:gap-4 p-6 md:py-8 rounded-2xl bg-black/35 backdrop-blur-md border border-white/5 transition-all duration-300 cursor-pointer hover:-translate-y-1 hover:bg-black/45 ${borderHover} group`;
|
||||
|
||||
const content = (
|
||||
<>
|
||||
<div className="shrink-0 transition-transform duration-300 group-hover:scale-105">
|
||||
<Icon className={color} size={36} />
|
||||
</div>
|
||||
@@ -26,6 +25,20 @@ export default function NavCard({ item }: NavCardProps) {
|
||||
{desc}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
if (path.startsWith("/")) {
|
||||
return (
|
||||
<Link to={path} className={className}>
|
||||
{content}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a href={path} target="_blank" rel="noopener noreferrer" className={className}>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +1,8 @@
|
||||
import { LayoutDashboard, GitFork, MonitorCog, ListCollapse, Workflow } from "lucide-react";
|
||||
import { GitFork, MonitorCog, ListCollapse, Workflow } from "lucide-react";
|
||||
import type { NavItem } from "@/types";
|
||||
|
||||
// External links displayed as navigation cards on the banner
|
||||
export const NAV_ITEMS: NavItem[] = [
|
||||
{
|
||||
name: "Blog",
|
||||
desc: "技术随笔与生活记录",
|
||||
path: "https://blog.xiaozhou233.cn",
|
||||
Icon: LayoutDashboard,
|
||||
color: "text-emerald-400",
|
||||
borderHover: "hover:border-emerald-500/50 hover:shadow-[0_0_20px_rgba(52,211,153,0.2)]",
|
||||
},
|
||||
{
|
||||
name: "Git",
|
||||
desc: "开源项目与代码托管",
|
||||
|
||||
@@ -6,14 +6,18 @@ export function useTypewriter(text: string, speed = 100) {
|
||||
|
||||
useEffect(() => {
|
||||
let i = 0;
|
||||
setDisplayed("");
|
||||
|
||||
const timer = setInterval(() => {
|
||||
i++;
|
||||
setDisplayed(text.slice(0, i));
|
||||
if (i === text.length) clearInterval(timer);
|
||||
|
||||
if (i === text.length) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, speed);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [text, speed]);
|
||||
|
||||
return displayed;
|
||||
}
|
||||
}
|
||||
+9
-122
@@ -1,129 +1,16 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "@fontsource-variable/geist";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--font-heading: var(--font-sans);
|
||||
--font-sans: 'Geist Variable', sans-serif;
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-ring: var(--ring);
|
||||
--color-input: var(--input);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-card: var(--card);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-background: var(--background);
|
||||
--radius-sm: calc(var(--radius) * 0.6);
|
||||
--radius-md: calc(var(--radius) * 0.8);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) * 1.4);
|
||||
--radius-2xl: calc(var(--radius) * 1.8);
|
||||
--radius-3xl: calc(var(--radius) * 2.2);
|
||||
--radius-4xl: calc(var(--radius) * 2.6);
|
||||
}
|
||||
|
||||
:root {
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.97 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--radius: 0.625rem;
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--secondary: oklch(0.269 0 0);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.269 0 0);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.269 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
@theme {
|
||||
--font-sans: "Geist Variable", system-ui, sans-serif;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
html {
|
||||
@apply font-sans;
|
||||
}
|
||||
}
|
||||
font-family: var(--font-sans);
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-black text-white antialiased;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
// Merges Tailwind classes, resolving conflicts via tailwind-merge
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import Banner from "@/components/Banner";
|
||||
import AboutSection from "@/components/sections/AboutSection";
|
||||
import ProjectsSection from "@/components/sections/ProjectsSection";
|
||||
import ContactSection from "@/components/sections/ContactSection";
|
||||
|
||||
// Landing page: hero banner followed by the content sections.
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<div className="bg-black">
|
||||
<Banner />
|
||||
<AboutSection />
|
||||
<ProjectsSection />
|
||||
<ContactSection />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+56
-24
@@ -1,5 +1,7 @@
|
||||
import { useEffect } from "react";
|
||||
import "./more.css";
|
||||
import { Link } from "@/router";
|
||||
import Header from "@/components/layout/Header";
|
||||
import Footer from "@/components/layout/Footer";
|
||||
import bannerImg from "@/assets/banner.png";
|
||||
|
||||
const appIcons = {
|
||||
water: <path d="M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z" />,
|
||||
@@ -17,31 +19,55 @@ const apps = [
|
||||
{ name: "力的课题", desc: "认识三种基本的力", color: "#ef4444", link: "/forces.html", icon: appIcons.atom },
|
||||
];
|
||||
|
||||
// App hub at /more, styled to match the main site's terminal aesthetic.
|
||||
export default function MorePage() {
|
||||
useEffect(() => {
|
||||
document.title = "更多应用";
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="more-page">
|
||||
<div className="more-page-inner">
|
||||
<header className="more-banner">
|
||||
<h1 className="more-banner-title">更多应用</h1>
|
||||
<p className="more-banner-subtitle">一个入口,汇聚所有工具</p>
|
||||
<a className="more-home-link" href="/">
|
||||
返回主站
|
||||
</a>
|
||||
</header>
|
||||
<div
|
||||
className="relative w-full min-h-screen flex flex-col text-white overflow-hidden font-mono"
|
||||
style={{
|
||||
backgroundImage: `url(${bannerImg})`,
|
||||
backgroundSize: "cover",
|
||||
backgroundPosition: "center",
|
||||
}}
|
||||
>
|
||||
<div className="absolute inset-0 bg-black/80 pointer-events-none" />
|
||||
|
||||
<main className="more-app-grid">
|
||||
<Header />
|
||||
|
||||
<main className="relative z-10 flex-1 w-full max-w-5xl mx-auto px-4 py-16 md:py-24">
|
||||
<div className="text-center mb-14">
|
||||
<h1 className="text-4xl md:text-6xl font-extrabold tracking-tighter text-transparent bg-clip-text bg-linear-to-r from-emerald-50 via-white to-emerald-50 drop-shadow-[0_0_15px_rgba(52,211,153,0.4)]">
|
||||
更多应用
|
||||
</h1>
|
||||
<p className="mt-5 text-emerald-400/80 text-sm md:text-base tracking-tight font-light">
|
||||
{"< 一个入口,汇聚所有工具 >"}
|
||||
</p>
|
||||
<div className="w-12 h-0.5 bg-emerald-500 mt-5 mx-auto shadow-[0_0_8px_#10b981]" />
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex items-center mt-8 px-4 py-2 rounded-full bg-white/5 border border-white/10 text-sm text-gray-200 transition-colors hover:bg-white/10 hover:border-emerald-500/40 hover:text-white"
|
||||
>
|
||||
返回主站
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{apps.map((app) => (
|
||||
<a key={app.name} className="more-app-card" href={app.link}>
|
||||
<a
|
||||
key={app.name}
|
||||
href={app.link}
|
||||
className="flex items-center gap-5 p-6 rounded-2xl bg-white/5 border border-white/5 backdrop-blur-sm transition-all duration-300 hover:-translate-y-1 hover:bg-white/10 hover:border-emerald-500/30 hover:shadow-[0_0_25px_rgba(52,211,153,0.1)] group"
|
||||
>
|
||||
<span
|
||||
className="more-app-icon"
|
||||
style={{ background: `linear-gradient(135deg, ${app.color}, ${app.color}cc)` }}
|
||||
className="shrink-0 flex items-center justify-center w-12 h-12 rounded-xl text-white transition-transform duration-300 group-hover:scale-105"
|
||||
style={{
|
||||
background: `linear-gradient(135deg, ${app.color}, ${app.color}cc)`,
|
||||
boxShadow: `0 0 18px ${app.color}40`,
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
className="w-6 h-6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
@@ -52,14 +78,20 @@ export default function MorePage() {
|
||||
{app.icon}
|
||||
</svg>
|
||||
</span>
|
||||
<div className="more-app-info">
|
||||
<h2 className="more-app-name">{app.name}</h2>
|
||||
<p className="more-app-desc">{app.desc}</p>
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-lg font-bold text-gray-100 transition-colors group-hover:text-white">
|
||||
{app.name}
|
||||
</h2>
|
||||
<p className="text-sm text-gray-400/80 mt-1 tracking-wide font-sans transition-colors group-hover:text-gray-300">
|
||||
{app.desc}
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
))}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
.more-page {
|
||||
position: relative;
|
||||
min-height: 100svh;
|
||||
box-sizing: border-box;
|
||||
color: #94a3b8;
|
||||
font-family: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
|
||||
}
|
||||
|
||||
.more-page::before {
|
||||
content: "";
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
background: linear-gradient(rgba(15, 23, 42, 0.6), rgba(15, 23, 42, 0.6)),
|
||||
url("/banner.jpg") center / cover no-repeat, #0f172a;
|
||||
}
|
||||
|
||||
.more-page *,
|
||||
.more-page *::before,
|
||||
.more-page *::after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
.more-page-inner {
|
||||
max-width: 1120px;
|
||||
margin: 0 auto;
|
||||
padding: 0 24px 64px;
|
||||
}
|
||||
|
||||
.more-banner {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
padding: 88px 24px;
|
||||
margin: 32px 0 48px;
|
||||
border-radius: 20px;
|
||||
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
|
||||
.more-home-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 24px;
|
||||
padding: 8px 16px;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
color: #e2e8f0;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
transition:
|
||||
background 0.2s ease,
|
||||
border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.more-home-link:hover {
|
||||
background: rgba(255, 255, 255, 0.16);
|
||||
border-color: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.more-banner-title {
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -1px;
|
||||
margin: 0 0 12px;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
.more-banner-subtitle {
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.more-app-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.more-app-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 20px;
|
||||
border-radius: 16px;
|
||||
background: #1e293b;
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
text-decoration: none;
|
||||
transition:
|
||||
transform 0.25s ease,
|
||||
box-shadow 0.25s ease,
|
||||
border-color 0.25s ease;
|
||||
}
|
||||
|
||||
.more-app-card:hover {
|
||||
transform: translateY(-4px);
|
||||
border-color: rgba(255, 255, 255, 0.14);
|
||||
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.more-app-icon {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 14px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.more-app-icon svg {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
.more-app-info {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.more-app-name {
|
||||
font-size: 17px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 4px;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
.more-app-desc {
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
color: #94a3b8;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.more-banner {
|
||||
padding: 64px 20px;
|
||||
}
|
||||
|
||||
.more-app-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.more-banner {
|
||||
padding: 48px 16px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.more-banner-title {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.more-app-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.more-app-desc {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { AnchorHTMLAttributes, MouseEvent } from "react";
|
||||
import { navigate } from "./history";
|
||||
|
||||
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
||||
to: string;
|
||||
}
|
||||
|
||||
// In-app link that routes client-side while keeping normal anchor semantics
|
||||
// (middle-click / modifier-click still open a new tab and get a real href).
|
||||
export function Link({ to, onClick, ...props }: LinkProps) {
|
||||
function handleClick(event: MouseEvent<HTMLAnchorElement>) {
|
||||
onClick?.(event);
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.button !== 0 ||
|
||||
event.metaKey ||
|
||||
event.ctrlKey ||
|
||||
event.shiftKey ||
|
||||
event.altKey
|
||||
) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
navigate(to);
|
||||
}
|
||||
|
||||
return <a href={to} onClick={handleClick} {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Minimal history-based routing primitives (no external router dependency).
|
||||
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function notify() {
|
||||
listeners.forEach((listener) => listener());
|
||||
}
|
||||
|
||||
// Normalizes a pathname so "/more", "/more/" and "/more/index.html" all match.
|
||||
export function normalizePath(pathname: string): string {
|
||||
let path = pathname.replace(/\/index\.html$/, "");
|
||||
if (path.length > 1) path = path.replace(/\/+$/, "");
|
||||
return path || "/";
|
||||
}
|
||||
|
||||
// `useSyncExternalStore` subscribes here; `popstate` covers back/forward.
|
||||
export function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
window.addEventListener("popstate", listener);
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
window.removeEventListener("popstate", listener);
|
||||
};
|
||||
}
|
||||
|
||||
export function getPath(): string {
|
||||
return normalizePath(window.location.pathname);
|
||||
}
|
||||
|
||||
// Client-side navigation. Same-path navigations are ignored.
|
||||
export function navigate(to: string): void {
|
||||
const url = new URL(to, window.location.origin);
|
||||
if (url.pathname === window.location.pathname) return;
|
||||
window.history.pushState(null, "", url);
|
||||
notify();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export { Link } from "./Link";
|
||||
export { useRoute } from "./useRoute";
|
||||
export { ROUTES, FALLBACK_ROUTE, matchRoute, type RouteDefinition } from "./routes";
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { ComponentType } from "react";
|
||||
import HomePage from "@/pages/HomePage";
|
||||
import MorePage from "@/pages/MorePage";
|
||||
|
||||
export interface RouteDefinition {
|
||||
name: string;
|
||||
path: string;
|
||||
pattern: RegExp;
|
||||
title: string;
|
||||
Component: ComponentType;
|
||||
}
|
||||
|
||||
// Single source of truth for pages. Add a route here and it is wired up.
|
||||
export const ROUTES: RouteDefinition[] = [
|
||||
{
|
||||
name: "home",
|
||||
path: "/",
|
||||
pattern: /^\/$/,
|
||||
title: "筱周の网站 - XiaoZhou's Website",
|
||||
Component: HomePage,
|
||||
},
|
||||
{
|
||||
name: "more",
|
||||
path: "/more",
|
||||
pattern: /^\/more$/,
|
||||
title: "更多应用 - 筱周の网站",
|
||||
Component: MorePage,
|
||||
},
|
||||
];
|
||||
|
||||
// Unknown paths fall back to home (preserves the previous behaviour).
|
||||
export const FALLBACK_ROUTE = ROUTES[0];
|
||||
|
||||
export function matchRoute(pathname: string): RouteDefinition {
|
||||
return ROUTES.find((route) => route.pattern.test(pathname)) ?? FALLBACK_ROUTE;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
import { getPath, subscribe } from "./history";
|
||||
import { matchRoute, type RouteDefinition } from "./routes";
|
||||
|
||||
export function useRoute(): { path: string; route: RouteDefinition } {
|
||||
const path = useSyncExternalStore(subscribe, getPath, () => "/");
|
||||
return { path, route: matchRoute(path) };
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
"@": path.resolve(import.meta.dirname, "./src"),
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user