<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Yucol</title>
    <description>个人的一个技术博客站点，主要用于记录个人在学习过程中遇到的技术问题及解决方法、以及一些比较有趣的事情。</description>
    <link>https://yucol.top//</link>
    <atom:link href="https://yucol.top/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Fri, 05 Jun 2026 01:27:36 +0000</pubDate>
    <lastBuildDate>Fri, 05 Jun 2026 01:27:36 +0000</lastBuildDate>
    <generator>Jekyll v4.4.1</generator>
    
      <item>
        <title>用纯前端优雅地解析并渲染 Shapefile：RxView</title>
        <description>&lt;h1 id=&quot;纯前端实现基于-vue3--leaflet-的变量施肥处方图渲染系统&quot;&gt;纯前端实现基于 Vue3 + Leaflet 的变量施肥处方图渲染系统&lt;/h1&gt;

&lt;p&gt;在农业空间数据处理中，变量施肥处方图通常以 Shapefile 格式进行流转。传统的 Web GIS 方案往往依赖后端的 GeoServer 或 PostGIS 进行数据解析和切片服务发布。但在最近推进白矖（Baixi）生态系统的开发中，我们需要为前端提供一个轻量级的预览工具——用户上传包含处方图的 ZIP 压缩包，前端直接在浏览器内完成解析、属性提取、色彩分级计算并叠加到高精度卫星底图上。&lt;/p&gt;

&lt;p&gt;本文将复盘我们如何使用 Vue3、Leaflet 以及几个核心开源库，构建这套轻巧、流畅的纯前端 RxView 渲染系统，并分享在这个过程中遇到的一些经典交互“天坑”及解决思路。&lt;/p&gt;

&lt;h2 id=&quot;核心技术栈与选型&quot;&gt;核心技术栈与选型&lt;/h2&gt;

&lt;p&gt;在不依赖后端 GIS 引擎的前提下，前端独立完成空间数据的解析与渲染需要合理的工具链组合：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;框架与基础地图&lt;/strong&gt;：Vue 3 (Composition API) + Leaflet。Leaflet 以其轻量级和极高的定制性，非常适合用来做单纯的数据叠加上图。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;空间数据解析&lt;/strong&gt;：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shpjs&lt;/code&gt;。它可以直接在浏览器端将 Shapefile 的 ZIP 压缩包转换为标准的 GeoJSON 格式，这是连接业务数据与地图渲染的关键桥梁。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;色彩分级与计算&lt;/strong&gt;：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chroma-js&lt;/code&gt;。处方图的核心在于将数值（如施肥量）映射为视觉色彩。利用该库可以非常方便地计算数据的极值、进行数值分段（离散化）并生成对应的色带。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;核心业务流程与实现逻辑&quot;&gt;核心业务流程与实现逻辑&lt;/h2&gt;

&lt;h3 id=&quot;1-文件的纯前端解析与智能选段&quot;&gt;1. 文件的纯前端解析与智能选段&lt;/h3&gt;

&lt;p&gt;系统的第一步是拦截原生文件上传，通过 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FileReader&lt;/code&gt; 读取为 ArrayBuffer 后直接丢给 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shpjs&lt;/code&gt; 处理。解析出 GeoJSON 后，面临的一个实际业务问题是：一个 Shapefile 中可能包含多个属性字段（例如面积、作物类型、各单一元素的推荐量等）。&lt;/p&gt;

&lt;p&gt;为了减少用户的操作路径，我们在前端加入了一层简单的智能推断逻辑：在提取出所有数值型字段后，优先匹配包含业务特征的字段。例如在我们的实际应用场景中，很多农机只支持混配肥的单一变量作业，因此我们会在前端正则优先匹配 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mixed&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;混配&lt;/code&gt; 等关键字作为默认渲染字段。如果找不到，再降级渲染纯地理边界。&lt;/p&gt;

&lt;h3 id=&quot;2-基于-chroma-js-的动态分级渲染&quot;&gt;2. 基于 Chroma-js 的动态分级渲染&lt;/h3&gt;

&lt;p&gt;拿到目标字段的数据后，需要将具体的施肥量数值转化为地图上的颜色。农业图层通常采用经典的“浅黄-浅绿-深绿”色谱。&lt;/p&gt;

&lt;p&gt;渲染的难点在于不同地块的数值分布差异极大。如果直接按极值做线性映射，极少量的异常高值会导致大部分网格颜色区分度极低。因此，我们通过 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chroma.limits&lt;/code&gt; 将有效数值分为最多 5 个区间（Class），并利用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chroma.scale&lt;/code&gt; 将基础色板扩展至对应的阶数，从而实现离散型分级图例。这样不仅视觉层次更鲜明，也符合农学上的分级指导习惯。&lt;/p&gt;

&lt;h3 id=&quot;3-高精度卫星底图的融合&quot;&gt;3. 高精度卫星底图的融合&lt;/h3&gt;

&lt;p&gt;传统的街道底图在农业场景下缺乏参考价值，我们需要让用户清晰地看到地块与实际地貌的贴合度。在此系统中，我们去除了 Leaflet 的默认控件，直接引入了 ArcGIS 的高清卫星影像服务（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;World_Imagery&lt;/code&gt;）作为底图，并将处方图的网格透明度设定为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.85&lt;/code&gt;，以确保底图纹理若隐若现。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/05/ee739245a7342ed5c9b61d3eb3595b7d.png&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/05/824f0dcd6d5be1fd89c1d8a4a21df0fe.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;实战踩坑如何消灭网格交互的高亮残影&quot;&gt;实战踩坑：如何消灭网格交互的“高亮残影”&lt;/h2&gt;

&lt;p&gt;在系统基本成型后，我们遇到了一个严重影响用户体验的交互问题。&lt;/p&gt;

&lt;p&gt;为了方便用户查看数据，我们为每个网格通过 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onEachFeature&lt;/code&gt; 绑定了 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mouseover&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mouseout&lt;/code&gt; 事件，并在其上叠加了 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sticky: true&lt;/code&gt; 的原生跟随注记（Tooltip）。但在实际操作中：&lt;strong&gt;当用户按住某个网格拖动地图进行平移时，拖动路径上的所有网格都会被依次点亮，并留下一长串无法复原的高亮残影。&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;起初我们以为是 Leaflet 的性能瓶颈，但经过排查，这实际上是浏览器原生拖拽机制与地图事件流的冲突：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;事件丢失&lt;/strong&gt;：在地图拖动状态下，浏览器的焦点被地图容器的平移事件捕获，导致之前触发了 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mouseover&lt;/code&gt; 的元素在鼠标移出时，无法稳定接收到 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mouseout&lt;/code&gt; 恢复原始样式的指令。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DOM 滞后&lt;/strong&gt;：跟随鼠标的 HTML 注记在快速平移时，DOM 重绘跟不上计算速度，甚至会被浏览器误识别为可拖拽对象。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;最终的解决思路（事件穿透与状态拦截）：&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;这绝非简单的 CSS 调整可以解决，我们需要从状态和样式两端进行双重拦截：&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;第一步：JS 层面的拖拽状态拦截&lt;/strong&gt;
我们在 Vue 的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onMounted&lt;/code&gt; 中监听了地图实例的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dragstart&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dragend&lt;/code&gt; 事件，维护了一个全局的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isMapDragging&lt;/code&gt; 状态。在网格的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mouseover&lt;/code&gt; 事件触发时，首先判断该状态：如果地图正在被拖拽，则直接 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; 拦截高亮逻辑。这就从源头上切断了残影的产生。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;第二步：CSS 层面的事件穿透与幽灵化&lt;/strong&gt;
针对卡顿的注记，如果用 JS 强制在拖拽瞬间销毁它（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closeTooltip&lt;/code&gt;），会导致深层的图层事件链断裂，直接导致地图彻底卡死无法拖拽。&lt;/p&gt;

&lt;p&gt;因此我们采用了更优雅的“幽灵化”方案：
首先，通过 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pointer-events: none&lt;/code&gt; 让鼠标事件强制穿透 Tooltip 注记，防止浏览器将其视作拖拽目标。
其次，在顶层容器动态绑定 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;is-dragging&lt;/code&gt; 类名。当处于拖拽状态时，利用 CSS 的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;opacity: 0&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;visibility: hidden&lt;/code&gt; 瞬间隐藏所有注记。拖拽结束后状态解除，注记无缝恢复。&lt;/p&gt;

&lt;h2 id=&quot;结语&quot;&gt;结语&lt;/h2&gt;

&lt;p&gt;通过 Vue3 结合 Leaflet、shpjs 与 chroma-js，我们成功在浏览器端实现了一套不依赖后端的处方图渲染闭环。这种纯前端的处理方式极大地降低了后端的并发压力和存储成本，对于白矖这类需要支持多农场、高频次数据查看的生态系统来说，是一个高性价比的方案。目前，RxView已经成功地在白矖（Baixi）系统的生产环境中部署，为用户提供了稳定、高效的处方图渲染服务。&lt;/p&gt;
</description>
        <pubDate>Fri, 15 May 2026 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/RxView.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/RxView.html</guid>
        
        <category>处方图</category>
        
        <category>Shapefile</category>
        
        <category>Leaflet</category>
        
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>实战 FastAPI + JWT：如何优雅实现单设备登录与账号有效期控制</title>
        <description>&lt;h1 id=&quot;实战-fastapi--jwt如何优雅实现单设备登录与账号有效期控制&quot;&gt;实战 FastAPI + JWT：如何优雅实现单设备登录与账号有效期控制&lt;/h1&gt;

&lt;p&gt;在开发多平台接入的综合管理系统时，统一的账号认证是整个架构的安全基石。对于前后端分离的项目，JSON Web Token (JWT) 是目前最主流的鉴权方案。&lt;/p&gt;

&lt;p&gt;然而，标准的 JWT 存在一个天然的痛点：&lt;strong&gt;无状态&lt;/strong&gt;。一旦服务端签发了 Token，在它自然过期之前，服务端很难直接主动废弃它。这会导致在处理“多端互踢（单设备登录）”以及“临时账号到期管控”时遇到麻烦。&lt;/p&gt;

&lt;p&gt;本文将基于 FastAPI 和 PostgreSQL，详细拆解一套在真实生产环境中运行的权限控制方案。这套方案通过引入 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt;（会话版本号）机制，巧妙地融合了无状态的轻量感与有状态的强管控。&lt;/p&gt;

&lt;h2 id=&quot;一-核心设计思路&quot;&gt;一 核心设计思路&lt;/h2&gt;

&lt;p&gt;为了打破纯 JWT 的无状态限制，我们在数据库的用户表中引入一个核心字段：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt;（会话版本号）。&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;登录埋点&lt;/strong&gt;：用户每次成功登录时，服务端生成一个当前的时间戳作为新的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt;，更新到数据库中，并将这个版本号一并打包写入 JWT 的 Payload 中。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;鉴权校验&lt;/strong&gt;：用户携带 Token 请求接口时，路由守卫不仅会校验 Token 的合法性和有效期，还会从数据库中查出该用户最新的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;互踢裁决&lt;/strong&gt;：如果 Token 携带的版本号与数据库中的最新版本号&lt;strong&gt;不一致&lt;/strong&gt;，说明该账号在其他地方进行了登录（旧 Token 被“顶号”），服务端直接拒绝请求。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;安全退出&lt;/strong&gt;：用户主动退出时，只需将数据库中的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt; 重置为 0，该用户持有的所有旧 Token 即可瞬间失效。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;二-基础安全与环境配置&quot;&gt;二 基础安全与环境配置&lt;/h2&gt;

&lt;p&gt;首先，集中管理我们的全局配置和密钥。在系统根目录下，我们需要定义 JWT 的加密密钥、算法以及 Token 的默认存活周期。&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# core/config.py
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Path&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# JWT 与安全配置
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SECRET_KEY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;your-super-secret-key&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 生产环境务必使用复杂随机字符串并从环境变量读取
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ALGORITHM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;HS256&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ACCESS_TOKEN_EXPIRE_MINUTES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;60&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# Token 有效期：24小时
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;三-登录接口签发门禁卡与版本号更迭&quot;&gt;三 登录接口：签发门禁卡与版本号更迭&lt;/h2&gt;

&lt;p&gt;登录接口承担着多项校验任务。除了常规的密码比对（推荐使用 bcrypt），还需要处理账号的禁用状态以及临时账号的到期拦截。&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# api/auth.py
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fastapi&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;APIRouter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Depends&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timedelta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;core.database&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_dash_db&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;core.security&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;verify_password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;create_access_token&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;router&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;APIRouter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;nd&quot;&gt;@router.post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/login&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;login_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoginRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_dash_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;SELECT * FROM users WHERE username = %s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;login_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fetchone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;# 1. 验证用户和密码
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;verify_password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;login_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;用户名或密码错误&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        
    &lt;span class=&quot;c1&quot;&gt;# 2. 检查账户启用状态
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;403&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;账户已被禁用，请联系管理员&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# 3. 检查账户有效期 (针对临时账号)
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;expire_time&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;current_utc_now&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datetime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;expire_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;expire_time&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 容错处理：确保时间对象具备时区信息，避免时区天真(naive)导致的比对异常
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expire_time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tzinfo&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;expire_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expire_time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tzinfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timezone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;expire_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_utc_now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;403&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;账户已过期，请联系管理员&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# 4. 生成并写入新的会话版本号，实现“顶号”逻辑
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;session_version&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;UPDATE users SET session_version = %s WHERE id = %s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;session_version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;commit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# 5. 将 session_version 塞进 JWT 的 payload 中
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;access_token_expires&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;timedelta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;minutes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ACCESS_TOKEN_EXPIRE_MINUTES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;create_access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; 
            &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; 
            &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
            &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;session_version&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session_version&lt;/span&gt;  
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;expires_delta&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token_expires&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;token_type&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bearer&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;值得注意的是，在时间处理上，后端必须保持高度的一致性。Python 原生的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;datetime&lt;/code&gt; 容易出现 Naive Time（无时区时间）与 Aware Time（带时区时间）比较报错的问题，使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;replace(tzinfo=timezone.utc)&lt;/code&gt; 强制对齐时区是一个极其稳妥的工程实践。&lt;/p&gt;

&lt;h2 id=&quot;四-路由守卫拦截器中的核心裁决&quot;&gt;四 路由守卫：拦截器中的核心裁决&lt;/h2&gt;

&lt;p&gt;有了带版本号的 Token，接下来需要在所有受保护的路由前加装一层守卫（FastAPI 的 Depends 机制）。&lt;/p&gt;

&lt;p&gt;这里的关键在于：不仅要解密 Token，还要回源数据库比对版本号。&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# core/security.py
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jwt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fastapi&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Depends&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fastapi.security&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPBearer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPAuthorizationCredentials&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;core.config&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SECRET_KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALGORITHM&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;core.database&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;get_dash_db&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;security&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPBearer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;credentials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPAuthorizationCredentials&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Depends&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;security&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;credentials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;credentials&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 解密 Token 提取 Payload
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jwt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SECRET_KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;algorithms&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ALGORITHM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;token_version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;session_version&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
        
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;无效的认证凭证&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;# 查库比对版本号
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_dash_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;SELECT session_version FROM users WHERE id = %s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fetchone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# 核心裁决：如果数据库里的版本号跟 Token 里的对不上
&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;session_version&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;token_version&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;# 抛出特定的 401 详情，前端可捕获 &apos;KICKED_OUT&apos; 来弹窗提示“您的账号已在别处登录”
&lt;/span&gt;            &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;KICKED_OUT&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;
        
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jwt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ExpiredSignatureError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;登录已过期，请重新登录&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jwt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;InvalidTokenError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HTTPException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;detail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;无效的 Token&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;前端在全局请求拦截器中，只需捕获 HTTP 401 且 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;detail === &apos;KICKED_OUT&apos;&lt;/code&gt; 的响应，就可以平滑地清除本地缓存并弹出友好的互踢提示。&lt;/p&gt;

&lt;h2 id=&quot;五-安全退出物理级失效&quot;&gt;五 安全退出：物理级失效&lt;/h2&gt;

&lt;p&gt;在纯 JWT 架构中，退出登录通常只能依赖前端删除本地存储的 Token，服务端无能为力。但在我们的版本号机制下，服务端的退出接口变得极具掌控力。&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# api/auth.py
&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@router.post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/logout&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;logout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Depends&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_dash_db&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 将会话版本号置为 0，让该用户流通在外的所有 Token 瞬间失去校验资格
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;UPDATE users SET session_version = 0 WHERE id = %s&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,))&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;commit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;已安全退出&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;六-总结与进阶思考&quot;&gt;六 总结与进阶思考&lt;/h2&gt;

&lt;p&gt;这套基于 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session_version&lt;/code&gt; 的鉴权方案，完美解决了 JWT 无法主动失效的顽疾，同时也实现了对多平台登录状态的精确控制。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;性能考量：&lt;/strong&gt;
当前的实现中，路由守卫每次拦截请求都需要进行一次 PostgreSQL 数据库查询。在常规的并发量下，数据库连接池加上单字段主键查询的速度完全可以胜任。但如果系统流量进一步膨胀，遇到高频次的空间数据接口或频繁的瓦片请求，鉴权层的查库操作可能会成为瓶颈。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;进阶优化方向：&lt;/strong&gt;
可以将 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user_id : session_version&lt;/code&gt; 的键值对缓存到 Redis 中。登录时更新 Redis，鉴权时直接读 Redis，从而将 I/O 成本降到最低，进一步释放系统在高并发环境下的性能潜力。&lt;/p&gt;
</description>
        <pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/JWT.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/JWT.html</guid>
        
        <category>FastAPI</category>
        
        <category>JWT</category>
        
        <category>单设备登录</category>
        
        <category>账号有效期控制</category>
        
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>我的现场编年史：不只是听歌！</title>
        <description>&lt;h1 id=&quot;-我的演唱会流浪计划&quot;&gt;🚀 我的演唱会流浪计划&lt;/h1&gt;

&lt;hr /&gt;
&lt;h3 id=&quot;-no001--房东的猫---世界青年-2024巡回演唱会&quot;&gt;🎵 NO.[001] | [房东的猫] - [世界/青年 2024巡回演唱会]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2024 年 06 月 29 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [首都体育馆]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ 看台山顶 ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #第一次演唱会 #合唱 #太治愈了&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;到北京上学后，有机会看到了人生中的第一次演唱会。那个周末是最开心的时候（周六听房东的猫，周日看成果🥳），从此激起了对演唱会的热爱。&lt;del&gt;直到现在工作后的平淡无趣&lt;/del&gt;&lt;/p&gt;

&lt;h4 id=&quot;2--memory&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/03c35fc6b5402510d671a28704338784.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/b08933f2fec09709c5e4ce5c72c7b710.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/6dc51b2e507b801b2d4e1237202e5d50.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/4f880cf7da00e9bf01004dac6542c814.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/ecfa47753c2c0d15679f02a36afb924c.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/eb23d7c5e5d14d200732fbcd4574e803.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/6af2fb0d633f677461f94a63cc649083.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/52158116f13f17fac1f55f5cc1313a47.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/04d872bbc0a16cfc83e5431853dbd6e4.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;h3 id=&quot;-no002--成果---海王星飞船&quot;&gt;🎵 NO.[002] | [成果] - [海王星飞船]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2024 年 06 月 30 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [晓剧场]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ 3排 16号 ]&lt;br /&gt;
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #音乐 #舞台剧 #合影（线下真实版）&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-1&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;狗哥的第一次舞台剧（成年儿童版😄），虽然不是演唱会，但却是第一次线下见面。&lt;/p&gt;

&lt;h4 id=&quot;2--memory-1&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/09010902d25eba6b5e0d4c03d192dc18.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/3a61aeeadff176eade7bf7c7a1ffafbe.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/71176807134ee73c254b0ae91fe8f165.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/25f11ae3934295c98afea56033a64f2c.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-1&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;演员状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-no003--夏日入侵企画---温暖人心的冬日聚会-不插电特别专场&quot;&gt;🎵 NO.[003] | [夏日入侵企画] - [温暖人心的冬日聚会-不插电特别专场]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2024 年 12 月 26 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [福浪LIVEHOUSE-福]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ Live House ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #欢乐 #蹦迪 #近距离&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-2&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;首次参加live house，夏企的魅力太足了，从开头蹦到结尾！我去的比较早，所以抢到了比较靠前的位置 &lt;del&gt;（早去早罚站）&lt;/del&gt;。&lt;/p&gt;

&lt;h4 id=&quot;2--memory-2&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/d30bfd4a68f4dc0b0ae8ea722758091e.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/9ce5697d3c3a05e611248f2a1756fb61.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/a07dfafb65d1067e68bacb9cb98fb3e2.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/9214b0d4ecb795c553c7a016c6e0502f.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/0423acd25e4b2249b3d44caadcbe9d6a.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/510149ef4a309514aba2e355bde0f8e8.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/fb7ee9c7157b2475f11d861938ce9642.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/e550a42cc6d94c5b7866bfebdd73e16e.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/15218fcce6159777c7985751a353f7b6.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-2&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-no004--双笙---经过时你我相遇&quot;&gt;🎵 NO.[004] | [双笙] - [经过时你我相遇]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2024 年 12 月 30 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [北京展览馆剧场]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ 一层 27排 74号 ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #国风 #老粉&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-3&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;大学时特别喜欢&lt;strong&gt;双笙&lt;/strong&gt;的歌曲，声音清甜，歌曲时而温柔，时而清脆。这次演唱会开到了北京，终于有机会可以现场听她唱的歌。&lt;/p&gt;

&lt;p&gt;现场的人数没有满座，但是也有很多人来捧场，上次关注双笙的时间我已经记不清了，我的记忆里还是她之前唱过的歌，所以演唱会上很多歌我都不太熟悉，算是个小遗憾吧。&lt;/p&gt;

&lt;h4 id=&quot;2--memory-3&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/57e8bbeebc68f673226fc632cdf1af5e.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/7dc997c6941d520ae27eaa5c99089d9d.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/9d43b58f0aabe1f2cf45910caa1d968f.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/bf662e347ad4267f56099d337ac1e3d1.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/5cbd4184524954e55f8c0aa403f5a525.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/3d11d108aab3971c2f81224e7eedbd07.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/9b495142e3b4af457bd9bdcd9123036a.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-3&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-no005--张杰---未live---开往1982&quot;&gt;🎵 NO.[005] | [张杰] - [未·LIVE - 开往1982]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2025 年 04 月 19 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [国家体育场-鸟巢]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ G区 529通道 五层 19排 25号 ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #逆战 #哪个男孩子不想现场听张杰唱逆战 #直接给到夯&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-4&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;遥想12年的夏天，我拥有了人生中的第一台电脑，第一件事就是把《逆战》（游戏）下载下来。无他，因为&lt;strong&gt;逆战&lt;/strong&gt;这首歌在当时就是现在小学生心目中的&lt;strong&gt;孤勇者&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;张杰&lt;/strong&gt;的演唱会真的太顶了，不论是氛围、嗓音、歌曲、编舞、音效还是灯光都是无敌的存在！&lt;/p&gt;

&lt;p&gt;还有个小插曲，演唱会结束后发现我的一位初中同学和另一位朋友竟然和我一块在现场。&lt;/p&gt;

&lt;h4 id=&quot;2--memory-4&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/b28c1685eb4743eb21ab2986f0750d45.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/842b5b707b6db0d659e13a7d292d19b5.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/e99d4ffbce3959249a29e2a1045b4c42.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/fcc01ffc42829688b50d782019e66d6b.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/059de7b30040024af60e69b08e08bfb7.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/a7d38cca39226b693c41a854492baf27.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/aff90d71d1257b3f8520bd1b93f4010e.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/4b18796a1d5883e642d1f1ea8e291307.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/f675fd3bdd93dd46098a61e6e71990fd.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/e29cb6bd399aafca0fb923fe7606e1d2.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-4&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-no006--凤凰传奇---吉祥如意&quot;&gt;🎵 NO.[006] | [凤凰传奇] - [吉祥如意]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2025 年 05 月 24 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [北京] · [国家体育场-鸟巢]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ H区 635通道 六层 26排 7~10号 ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #组队看演唱会 #蹦迪&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-5&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;这一次，四人终于抵达了他们忠诚的鸟巢！&lt;/strong&gt;&lt;/p&gt;

&lt;h4 id=&quot;2--memory-5&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/a54d93c781ef47f0f8ddb1637ebb7a2b.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/94c0b136f85d70fb02f49b208070b8d5.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/f2ed607b6e326f2e5b7fe388a869bce0.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/4a0e4c8c8e75c6e242ebb87f62eaf6e5.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/07b83a6cf11f23014e9c68704b1b2baa.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/f657397dad165ca1f5e1d670ef46e4a4.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/5b56bd318c476f65dce021c7b070b500.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/5fdc7c1d644c05f1148a86bbcdf9e8fb.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-5&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-no007--房东的猫---世界青年---2025巡回演唱会--南京站&quot;&gt;🎵 NO.[007] | [房东的猫] - [世界/青年 - 2025巡回演唱会- 南京站]&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;📅 时间：&lt;/strong&gt; 2025 年 06 月 14 日&lt;br /&gt;
&lt;strong&gt;📍 地点：&lt;/strong&gt; [南京] · [南京奥体中心国缘V9体育馆]&lt;br /&gt;
&lt;strong&gt;🎫 座位：&lt;/strong&gt; [ 看台六十五区 看台6F 3排 4座 ]
&lt;strong&gt;🏷️ 关键词：&lt;/strong&gt; #毕业旅行&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;1--content-6&quot;&gt;1. 📜 Content&lt;/h4&gt;

&lt;p&gt;临近毕业的阶段，买到了南京站的🎫（卡点抢的票，结果后面打折卖，可恶的大麦！）。下午去参加粉丝活动的时候认识了一位南林大的新朋友，从而使这段旅程没有太过“安静”。晚上演唱会结束后下起了暴雨⛈️，没有带伞，而免费雨披也送完了，所以就做了一次“雨中追雨的少年”，回到酒店后衣服都湿透了。&lt;/p&gt;

&lt;p&gt;之后在南京玩了三天，美丽的南京，去了还想去。“旅途”最后两天去了上海找我同学，25岁第一次踏上了我曾梦想去的城市-上海。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;无论在何处，祝你美梦成真&lt;/strong&gt;&lt;/p&gt;

&lt;h4 id=&quot;2--memory-6&quot;&gt;2. 📸 Memory&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://img.yucol.uk/2026/02/ad24a56a290d4ba114b755465661b09c.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/2dd6aa01f510c8f605d047e7eebe001d.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/ab9644a46148cdcdd090204fbb04c5fd.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/224605f108ac8205dd767e3e2648de3a.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/7cd6790b2ac8938c8946256479b8900c.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/7a6ee0db182e98c183e92d16f8789ac4.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/9e7136d0f5a64e093ad0de3ef28b3e00.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/7c16fa33c0b4fa5d95c7426d335a7dbf.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/e4283321f950066abf9d43c24fdd106b.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/51341cf870e66bd1fdf1bd95a36b4795.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/1beaa9477f2f0363afb028cec83299f5.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/c92e27acfc7c79442ea914015072e09c.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/71e01ee963fa31b66f11df3247abed7a.webp&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://img.yucol.uk/2026/02/4ddd9f16a8e1802cf77421aa868e0b05.webp&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;3--个人评分-6&quot;&gt;3. ⭐ 个人评分&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;曲目编排：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;舞美视听：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;歌手状态：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;推荐指数：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;综合评分：&lt;/strong&gt; ⭐⭐⭐⭐⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
</description>
        <pubDate>Wed, 25 Feb 2026 04:00:00 +0000</pubDate>
        <link>https://yucol.top/life/concert.html</link>
        <guid isPermaLink="true">https://yucol.top/life/concert.html</guid>
        
        <category>演唱会</category>
        
        <category>房东的猫</category>
        
        <category>成果</category>
        
        <category>夏日入侵企画</category>
        
        <category>双笙</category>
        
        <category>张杰</category>
        
        <category>凤凰传奇</category>
        
        
        <category>life</category>
        
      </item>
    
      <item>
        <title>从零到一：阿里云 200M 带宽服务器的全栈基建（1Panel + Docker + GitHub Actions）</title>
        <description>&lt;h1 id=&quot;1-前言为什么放弃手动搬运&quot;&gt;1 前言：为什么放弃“手动搬运”？&lt;/h1&gt;

&lt;p&gt;在拥有了自己的服务器后，第一反应是手动上传文件。但这存在三个弊端：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;效率低&lt;/strong&gt;：改一个字也要开一遍 FTP。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;易出错&lt;/strong&gt;：容易漏传或传错目录。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;无版本控制&lt;/strong&gt;：无法回溯历史。
本篇记录如何利用 &lt;strong&gt;GitHub Actions&lt;/strong&gt; 打造一条自动化流水线，实现“本地代码一推，服务器即刻更新”。&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;2-环境说明&quot;&gt;2 环境说明&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;服务器&lt;/strong&gt;：阿里云 2核2G / 200M 带宽 / Ubuntu 系统。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;运维面板&lt;/strong&gt;：1Panel（基于 Docker 的现代化管理面板）。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;静态引擎&lt;/strong&gt;：Jekyll (Ruby 3.4.4)。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;部署通道&lt;/strong&gt;：SSH + Rsync。&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;3-核心步骤详解&quot;&gt;3 核心步骤详解&lt;/h1&gt;

&lt;h2 id=&quot;第一步服务器基建-1panel&quot;&gt;第一步：服务器基建 (1Panel)&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;安装 1Panel 并在应用商店安装 &lt;strong&gt;OpenResty&lt;/strong&gt;（Nginx 的增强版）。&lt;/li&gt;
  &lt;li&gt;在“网站”菜单下创建一个静态网站。&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;路径&lt;/strong&gt;：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/opt/1panel/apps/openresty/openresty/www/sites/test/index&lt;/code&gt;（此路径为后期同步的目标 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TARGET&lt;/code&gt;）。&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;确保服务器防火墙已开启 80/443 端口，以及 SSH 通讯所需的 22 端口。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;第二步建立信任关系-ssh-key&quot;&gt;第二步：建立“信任关系” (SSH Key)&lt;/h2&gt;

&lt;p&gt;为了让 GitHub 机器人能直接登录我们的服务器，需要配置免密登录：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;本地生成密钥对&lt;/strong&gt;：
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh-keygen -t rsa -b 4096 -f id_rsa_github&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;分发公钥&lt;/strong&gt;：将 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id_rsa_github.pub&lt;/code&gt; 的内容追加到服务器的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/root/.ssh/authorized_keys&lt;/code&gt; 中。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;权限加固&lt;/strong&gt;：确保 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ssh&lt;/code&gt; 目录权限为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;700&lt;/code&gt;，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;authorized_keys&lt;/code&gt; 权限为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;600&lt;/code&gt;。&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;第三步配置-github-secrets&quot;&gt;第三步：配置 GitHub Secrets&lt;/h2&gt;

&lt;p&gt;在 GitHub 仓库的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Settings -&amp;gt; Secrets and variables -&amp;gt; Actions&lt;/code&gt; 中配置四个关键变量：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REMOTE_HOST&lt;/code&gt;: 服务器公网 IP。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REMOTE_USER&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_PRIVATE_KEY&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id_rsa_github&lt;/code&gt; 文件里的完整私钥内容。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REMOTE_TARGET&lt;/code&gt;: 服务器上的静态目录路径。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;第四步编写自动化流水线-yaml&quot;&gt;第四步：编写自动化流水线 (YAML)&lt;/h2&gt;

&lt;p&gt;在 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.github/workflows/&lt;/code&gt; 下创建 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jekyll.yml&lt;/code&gt;。核心逻辑是利用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;easingthemes/ssh-deploy&lt;/code&gt; 插件执行 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rsync&lt;/code&gt;。&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# 关键配置摘要&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Deploy to Aliyun Server&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;uses&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;easingthemes/ssh-deploy@v5.1.0&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;SSH_PRIVATE_KEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;ARGS&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-rltzvi&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;--delete&quot;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# 增量同步，删除服务器多余文件&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;SOURCE&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;_site/&quot;&lt;/span&gt;         &lt;span class=&quot;c1&quot;&gt;# Jekyll 构建后的产物目录&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;REMOTE_HOST&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;REMOTE_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;TARGET&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;$&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;4-外部资源集成&quot;&gt;4 外部资源集成：&lt;/h1&gt;

&lt;p&gt;为了追求极致的性能和稳定性，我并没有将所有功能都死磕在自己的服务器上，而是引入了更成熟的云原生方案：&lt;/p&gt;

&lt;h2 id=&quot;a-评论系统waline--vercel--neon&quot;&gt;A. 评论系统：Waline + Vercel + Neon&lt;/h2&gt;

&lt;p&gt;为了不让评论数据的存储和处理占用阿里云的 2G 内存，我采用了 &lt;strong&gt;Serverless（无服务器）&lt;/strong&gt; 架构：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;后端部署 (Vercel)&lt;/strong&gt;：利用 Vercel 的免费额度托管 Waline 后端程序。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;数据库 (Neon)&lt;/strong&gt;：所有的评论内容存储在 Neon 的云数据库中，安全且免费。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;集成方式&lt;/strong&gt;：在 Jekyll 模板中引入 Waline 的 JS 脚本，通过 API 与 Vercel 通信。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;深度心得&lt;/strong&gt;：这种方案实现了“数据随人走”，即便我以后重装服务器系统，评论数据也不会丢失。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;b-极致图床cloudflare-r2--picgo&quot;&gt;B. 极致图床：Cloudflare R2 + PicGo&lt;/h2&gt;

&lt;p&gt;虽然服务器有 200M 带宽，但为了节省宝贵的公网流量以及应对未来可能的并发访问，我搭建了专业的对象存储图床：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;存储底座 (Cloudflare R2)&lt;/strong&gt;：利用 Cloudflare 的 R2 存储（S3 兼容模式），免流量费且自带全球 CDN 加速。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;自动化工具 (PicGo)&lt;/strong&gt;：在本地配置 PicGo 插件，实现“截图 -&amp;gt; 上传 -&amp;gt; 自动生成 Markdown 链接”的一键流。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;安全加固 (V2 签名)&lt;/strong&gt;：使用 V2 签名机制确保上传接口的安全，防止图床被恶意盗刷。&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;5-未来扩展&quot;&gt;5 未来扩展：&lt;/h1&gt;

&lt;p&gt;目前的基建仅完成了博客的部署。后续计划：&lt;/p&gt;

&lt;ul class=&quot;task-list&quot;&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;&lt;strong&gt;后端 API&lt;/strong&gt;：在 1Panel 中使用 Docker 部署 Python (FastAPI) 容器。&lt;/li&gt;
  &lt;li class=&quot;task-list-item&quot;&gt;&lt;input type=&quot;checkbox&quot; class=&quot;task-list-item-checkbox&quot; disabled=&quot;disabled&quot; /&gt;&lt;strong&gt;移动端联调&lt;/strong&gt;：Kotlin 开发的安卓 App 通过 HTTP 请求调用服务器 IP 上的 Python 接口，实现数据上云。&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Wed, 25 Feb 2026 00:00:00 +0000</pubDate>
        <link>https://yucol.top/server/server-setup.html</link>
        <guid isPermaLink="true">https://yucol.top/server/server-setup.html</guid>
        
        <category>服务器</category>
        
        <category>GitHub Actions</category>
        
        <category>blog</category>
        
        
        <category>server</category>
        
      </item>
    
      <item>
        <title>我的第一款酒局神器App“摇了么”</title>
        <description>&lt;h1 id=&quot;-我的第一款酒局神器app摇了么诞生记&quot;&gt;🚀 我的第一款酒局神器App“摇了么”诞生记！&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;源代码、安装包及效果图在文章结尾处。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;一直想做一个既好玩又实用的东西。终于，在AI的帮助下，我的第一款 Android 独立应用——&lt;strong&gt;“摇了么”&lt;/strong&gt;，正式诞生啦！&lt;/p&gt;

&lt;p&gt;这是一款专为酒局、聚会打造的摇骰子小工具。虽然市面上有很多类似的小程序，但作为一个强迫症+体验控，决定亲自操刀，给它注入真正的“灵魂”。&lt;/p&gt;

&lt;h3 id=&quot;-为什么叫摇了么&quot;&gt;🎲 为什么叫“摇了么”？&lt;/h3&gt;

&lt;p&gt;在酒桌上，最常听到的一句话可能就是“该你了，摇了么？”。这个名字既是对朋友的催促，也是这款 App 核心交互的体现——别点屏幕了，直接拿起手机摇吧！&lt;/p&gt;

&lt;h3 id=&quot;-核心亮点把细节死磕到底&quot;&gt;✨ 核心亮点：把细节死磕到底&lt;/h3&gt;

&lt;p&gt;在体验上主要有以下亮点：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;告别反人类UI，单手掌控全局：&lt;/strong&gt;
抛弃了早期版本中需要呼出软键盘来输入骰子数量的繁琐设计。利用线性布局（LinearLayout）的权重属性，将核心视觉区（骰子展示）固定在中上方，而在底部手指出没的最舒适区域，加入了丝滑的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt; 按钮。1到15个骰子，单手一秒切换。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;注入灵魂的“物理外挂”（摇一摇）：&lt;/strong&gt;
酒局游戏，怎么能只用手指点按钮呢？调用了 Android 的底层硬件——&lt;strong&gt;加速度传感器 (Accelerometer)&lt;/strong&gt;。通过计算 X、Y、Z 三个维度的综合重力加速度，只要你像握着真实骰盅一样用力甩动手机，代码就会自动捕捉你的动作并触发掷骰子！&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;沉浸式的声感与触觉反馈：&lt;/strong&gt;
为了模拟真实的物理反馈，加入了双重感官刺激：
    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;听觉&lt;/strong&gt;：接入 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MediaPlayer&lt;/code&gt;，摇晃时伴随清脆的“哗啦哗啦”骰子碰撞声。&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;触觉&lt;/strong&gt;：调用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Vibrator&lt;/code&gt; 震动马达。在骰子滚动的 1 秒内，配合动画发出极其高频的轻微震动，停住的瞬间来一次重震。闭上眼睛，你手里握着的仿佛就是个真骰盅！&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;安全纯净无广告：&lt;/strong&gt;
代码完全开源，没有任何联网和收集隐私信息的行为；界面干净整洁，没有任何广告及干扰信息！&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;-核心代码-show-me-the-code&quot;&gt;💻 核心代码 (Show Me The Code)&lt;/h3&gt;

&lt;p&gt;这里分享一下“摇了么”最核心的两个逻辑实现：&lt;/p&gt;

&lt;h4 id=&quot;1-如何让手机听懂摇晃传感器逻辑&quot;&gt;1. 如何让手机听懂“摇晃”？(传感器逻辑)&lt;/h4&gt;

&lt;p&gt;这里用到了初中的物理和数学知识 。手机的加速度传感器会实时返回 X、Y、Z 三个轴的受力。们算出它们除以地球重力加速度后的 G 力，然后利用勾股定理  算出综合受力：&lt;/p&gt;

&lt;div class=&quot;language-kotlin highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 传感器检测到手机运动时自动调用&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onSensorChanged&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SensorEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isRolling&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 计算加速度，除以地球重力加速度得出 G 力&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;gX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SensorManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GRAVITY_EARTH&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;gY&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SensorManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GRAVITY_EARTH&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;gZ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SensorManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GRAVITY_EARTH&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 勾股定理计算综合受力大小&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;gForce&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gY&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gY&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gZ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gZ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toDouble&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 阈值设定为 2.7：大约是用力甩一下手机的力度&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gForce&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.7f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;val&lt;/span&gt; &lt;span class=&quot;py&quot;&gt;now&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 设置 1 秒的冷却防抖时间&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lastShakeTime&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;lastShakeTime&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;now&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// 模拟用户点击了摇骰子按钮&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;findViewById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;btnRoll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;performClick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-如何实现逼真的骰子翻滚与触觉反馈&quot;&gt;2. 如何实现逼真的“骰子翻滚”与触觉反馈？&lt;/h4&gt;

&lt;p&gt;为了不让结果显得太突兀，利用安卓自带的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CountDownTimer&lt;/code&gt; 写了一个 1 秒钟的动画循环。在这 1 秒内，不仅疯狂切换图片、随机倾斜角度，还同步调用了震动马达：&lt;/p&gt;

&lt;div class=&quot;language-kotlin highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 开始摇骰子动画（持续1000毫秒，每100毫秒刷新一次）&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;: &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CountDownTimer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onTick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;millisUntilFinished&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diceViews&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 随机切图并赋予 -30 到 30 度的随机倾斜角&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;view&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setImageResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;diceImages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nextInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;view&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rotation&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nextInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 摇晃过程中：触发 20 毫秒的极轻微震动（模拟骰子撞击杯壁）&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VERSION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SDK_INT&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;vibrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;vibrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VibrationEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;createOneShot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VibrationEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DEFAULT_AMPLITUDE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;vibrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;vibrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onFinish&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diceViews&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 定格最终点数，并将角度摆正&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;view&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;setImageResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;diceImages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nextInt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;view&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rotation&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0f&lt;/span&gt; 
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 摇晃结束：触发 100 毫秒的重震（模拟落桌定音）&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VERSION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SDK_INT&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;vibrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;vibrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;VibrationEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;createOneShot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;VibrationEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DEFAULT_AMPLITUDE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;vibrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;vibrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;isRolling&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;-写在最后&quot;&gt;💡 写在最后&lt;/h3&gt;

&lt;p&gt;如果你也想体验一下这款小工具，或者对源码感兴趣，欢迎讨论与交流！&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;项目地址：&lt;a href=&quot;https://github.com/JMbaozi/PartyDice&quot;&gt;https://github.com/JMbaozi/PartyDice&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;安装包地址：&lt;a href=&quot;https://github.com/JMbaozi/PartyDice/releases/tag/v1.0&quot;&gt;摇了么 v1.0&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://youke.xn--y7xa690gmna.cn/s1/2026/02/22/699b03b332e82.webp&quot; alt=&quot;home.jpg&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 22 Feb 2026 13:20:00 +0000</pubDate>
        <link>https://yucol.top/app/PartyDice.html</link>
        <guid isPermaLink="true">https://yucol.top/app/PartyDice.html</guid>
        
        <category>安卓</category>
        
        <category>骰子</category>
        
        <category>游戏</category>
        
        <category>独立开发</category>
        
        
        <category>app</category>
        
      </item>
    
      <item>
        <title>从 H2O 到 H2O-ac：我的博客迁移与填坑笔记</title>
        <description>&lt;h2 id=&quot;前言&quot;&gt;前言&lt;/h2&gt;

&lt;p&gt;博客最初的采用的模板是由&lt;a href=&quot;https://github.com/kaeyleo&quot;&gt;kaeyleo&lt;/a&gt;基于&lt;a href=&quot;https://jekyllrb.com/&quot;&gt;jekyll&lt;/a&gt;开发的&lt;a href=&quot;https://github.com/kaeyleo/jekyll-theme-H2O&quot;&gt;H2O&lt;/a&gt;主题。我在此基础上添加了评论区、友链、归档、音乐播放器、访客记录、目录等功能。但是限于能力有限，写的代码一堆BUG。最近我浏览到了一个基于&lt;a href=&quot;https://github.com/kaeyleo/jekyll-theme-H2O&quot;&gt;H2O&lt;/a&gt;修改的&lt;a href=&quot;https://github.com/zhonger/jekyll-theme-H2O-ac&quot;&gt;H2O-ac&lt;/a&gt;主题，其内容丰富，视觉效果和阅读体验非常好。&lt;/p&gt;

&lt;p&gt;所以我决定对博客进行了一次“大手术”，将原本一直使用的H2O模板替换成了目前视觉效果非常出色的 &lt;strong&gt;H2O-ac&lt;/strong&gt; 主题。&lt;/p&gt;

&lt;p&gt;虽然 H2O-ac 带来了极佳的阅读体验和学术风界面，但在迁移和配置自动化的过程中，我遇到了不少令人头大的 Bug。&lt;/p&gt;

&lt;p&gt;为了方便日后查阅，也为了给同样使用该主题的小伙伴提供参考，特写下这篇笔记。&lt;/p&gt;

&lt;h2 id=&quot;迁移过程从手动到全自动&quot;&gt;迁移过程：从手动到全自动&lt;/h2&gt;

&lt;p&gt;最初的迁移并不顺利，旧模板留下的残留文件（如 Azure 的部署脚本等）频繁导致构建失败。&lt;/p&gt;

&lt;h3 id=&quot;1-自动化-cicd-的重建&quot;&gt;1. 自动化 CI/CD 的重建&lt;/h3&gt;
&lt;p&gt;为了实现“推送即发布”，我弃用了原本混乱的部署脚本，重新编写了 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.github/workflows/jekyll.yml&lt;/code&gt;。通过以下逻辑确保了环境的纯净：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;环境初始化&lt;/strong&gt;：使用 Ruby 3.4.4 环境。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;强制清理&lt;/strong&gt;：在编译前运行 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bundle exec jekyll clean&lt;/code&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;强制覆盖&lt;/strong&gt;：发布到 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt; 分支时使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;force_orphan: true&lt;/code&gt;，彻底杜绝旧文件缓存。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-版权与开源协议&quot;&gt;2. 版权与开源协议&lt;/h3&gt;
&lt;p&gt;由于 H2O-ac 是基于 H2O 主题的 fork 版本，遵循 &lt;strong&gt;MIT 开源协议&lt;/strong&gt;。在迁移过程中，我保留了原作者的版权信息。&lt;/p&gt;

&lt;h2 id=&quot;遇到的问题与-bug-排查重点&quot;&gt;遇到的问题与 Bug 排查（重点）&lt;/h2&gt;

&lt;p&gt;这次迁移最核心的挑战在于：文章在标签（Tags）页能看，但在首页（Blog）和归档（Archives）页却神秘失踪。经过反复排查，我定位到了以下几个“元凶”：&lt;/p&gt;

&lt;h3 id=&quot;bug-1pin-false-逻辑陷阱&quot;&gt;Bug 1：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pin: false&lt;/code&gt; 逻辑陷阱&lt;/h3&gt;
&lt;p&gt;这是最难发现的一个点。H2O-ac 主题自带了置顶功能，但我发现：&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;当我在文章头部显式写下 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pin: false&lt;/code&gt; 时，首页和归档页会完全无法显示该文章。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;解决方案&lt;/strong&gt;：普通文章直接&lt;strong&gt;删除 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pin&lt;/code&gt; 属性&lt;/strong&gt;即可。如果不置顶，就不要写这一行，写成 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt; 反而会被主题逻辑误判并过滤掉。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bug-2分支挂载错位&quot;&gt;Bug 2：分支挂载错位&lt;/h3&gt;
&lt;p&gt;在 GitHub Pages 设置中，如果将部署源选为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;，可能无法看到经过 Actions 机器人编译后的成品。&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;解决方法&lt;/strong&gt;：将 GitHub Pages 的部署分支切换到 &lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gh-pages&lt;/code&gt;&lt;/strong&gt;，这才是机器人存放 HTML 成品的地方。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;参考文档&quot;&gt;参考文档&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/zhonger/jekyll-theme-H2O-ac&quot;&gt;H2O-ac主题仓库&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://lisz.me/tech/new-theme-h2o-ac&quot;&gt;H2O-ac主题介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://h2o-ac-doc.lisz.me/&quot;&gt;H2O-ac主题文档&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;结语&quot;&gt;结语&lt;/h2&gt;

&lt;p&gt;感谢 H2O 系列主题的作者们提供的优秀代码。&lt;/p&gt;
</description>
        <pubDate>Sun, 22 Feb 2026 00:00:00 +0000</pubDate>
        <link>https://yucol.top/blog/blog-migration-notes.html</link>
        <guid isPermaLink="true">https://yucol.top/blog/blog-migration-notes.html</guid>
        
        <category>Jekyll</category>
        
        <category>GitHub Actions</category>
        
        <category>填坑</category>
        
        <category>blog</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>HTTP 状态码</title>
        <description>&lt;h1 id=&quot;http-状态码完全指南详解版&quot;&gt;HTTP 状态码完全指南（详解版）&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;一篇面向 &lt;strong&gt;Web / 后端 / 前端 / GIS Web 应用开发者&lt;/strong&gt; 的 HTTP 状态码系统性参考文章。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;一什么是-http-状态码&quot;&gt;一、什么是 HTTP 状态码&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;HTTP 状态码（HTTP Status Code）&lt;/strong&gt; 是服务器在响应客户端（浏览器、APP、程序）请求时，返回的一个 &lt;strong&gt;三位数字&lt;/strong&gt;，用于说明：&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;👉 &lt;strong&gt;这次请求发生了什么、结果如何、是否需要进一步操作&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;HTTP 状态码是 &lt;strong&gt;HTTP 协议语义的核心组成部分&lt;/strong&gt;，对于：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;前后端接口设计&lt;/li&gt;
  &lt;li&gt;RESTful API 规范&lt;/li&gt;
  &lt;li&gt;错误处理与调试&lt;/li&gt;
  &lt;li&gt;网络性能与安全分析&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;都具有非常重要的意义。&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;二http-状态码的五大类&quot;&gt;二、HTTP 状态码的五大类&lt;/h2&gt;

&lt;p&gt;HTTP 状态码按照 &lt;strong&gt;首位数字&lt;/strong&gt; 分为五大类：&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;分类&lt;/th&gt;
      &lt;th&gt;范围&lt;/th&gt;
      &lt;th&gt;含义&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1xx&lt;/td&gt;
      &lt;td&gt;100–199&lt;/td&gt;
      &lt;td&gt;信息性响应（请求已接收）&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2xx&lt;/td&gt;
      &lt;td&gt;200–299&lt;/td&gt;
      &lt;td&gt;成功（请求已成功处理）&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3xx&lt;/td&gt;
      &lt;td&gt;300–399&lt;/td&gt;
      &lt;td&gt;重定向（需要进一步操作）&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4xx&lt;/td&gt;
      &lt;td&gt;400–499&lt;/td&gt;
      &lt;td&gt;客户端错误&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5xx&lt;/td&gt;
      &lt;td&gt;500–599&lt;/td&gt;
      &lt;td&gt;服务器错误&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;三1xx信息性状态码informational&quot;&gt;三、1xx：信息性状态码（Informational）&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;表示请求已被接收，正在处理，&lt;strong&gt;很少在业务代码中直接使用&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;100-continue&quot;&gt;100 Continue&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：客户端可以继续发送请求体&lt;/li&gt;
  &lt;li&gt;场景：大文件上传前的确认机制&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;101-switching-protocols&quot;&gt;101 Switching Protocols&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：服务器同意切换协议&lt;/li&gt;
  &lt;li&gt;场景：HTTP → WebSocket&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;四2xx成功状态码success&quot;&gt;四、2xx：成功状态码（Success）&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;最重要、最常用的一类状态码&lt;/strong&gt;，表示请求被正确处理。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;200-ok&quot;&gt;200 OK&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：请求成功&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;GET 查询成功&lt;/li&gt;
      &lt;li&gt;PUT / PATCH 更新成功&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;GET /api/fields/123
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;OK&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;201-created&quot;&gt;201 Created&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：资源创建成功&lt;/li&gt;
  &lt;li&gt;场景：POST 新建资源&lt;/li&gt;
  &lt;li&gt;建议：返回新资源的 URL&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;POST /api/fields
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;201&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Created&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/api/fields/456&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;202-accepted&quot;&gt;202 Accepted&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：请求已接收，但尚未处理完成&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;异步任务&lt;/li&gt;
      &lt;li&gt;后台计算（如 GIS 插值、模型分析）&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;204-no-content&quot;&gt;204 No Content&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：请求成功，但无返回内容&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;删除成功&lt;/li&gt;
      &lt;li&gt;仅触发动作的接口&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;DELETE /api/fields/123
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;204&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;No Content&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;五3xx重定向状态码redirection&quot;&gt;五、3xx：重定向状态码（Redirection）&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;表示资源位置发生变化，需要客户端采取进一步操作。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;301-moved-permanently&quot;&gt;301 Moved Permanently&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：永久重定向&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;域名迁移&lt;/li&gt;
      &lt;li&gt;SEO 优化&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;302-found&quot;&gt;302 Found&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：临时重定向（历史遗留）&lt;/li&gt;
  &lt;li&gt;注意：可能被浏览器当作 GET 请求处理&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;303-see-other&quot;&gt;303 See Other&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：使用 GET 访问另一个 URI&lt;/li&gt;
  &lt;li&gt;场景：POST 后跳转页面&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;304-not-modified&quot;&gt;304 Not Modified&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：资源未修改&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;浏览器缓存&lt;/li&gt;
      &lt;li&gt;ETag / If-Modified-Since&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;六4xx客户端错误client-error&quot;&gt;六、4xx：客户端错误（Client Error）&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;表示问题出在客户端请求本身&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;400-bad-request&quot;&gt;400 Bad Request&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：请求格式错误&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;常见原因：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;JSON 语法错误&lt;/li&gt;
      &lt;li&gt;参数缺失&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;401-unauthorized&quot;&gt;401 Unauthorized&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：未认证&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;特点：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;需要登录&lt;/li&gt;
      &lt;li&gt;通常配合 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WWW-Authenticate&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;⚠️ 注意：401 ≠ 权限不足&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;403-forbidden&quot;&gt;403 Forbidden&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：已认证，但无权限&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;普通用户访问管理员接口&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;404-not-found&quot;&gt;404 Not Found&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：资源不存在&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;URL 错误&lt;/li&gt;
      &lt;li&gt;资源被删除&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;405-method-not-allowed&quot;&gt;405 Method Not Allowed&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：请求方法不被允许&lt;/li&gt;
  &lt;li&gt;示例：&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-http highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;POST /api/fields/123
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;405&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Method Not Allowed&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Allow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;GET, PUT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;409-conflict&quot;&gt;409 Conflict&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：资源冲突&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;重复创建&lt;/li&gt;
      &lt;li&gt;乐观锁冲突&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;422-unprocessable-entity&quot;&gt;422 Unprocessable Entity&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：语义正确，但业务校验失败&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;表单校验&lt;/li&gt;
      &lt;li&gt;数据规则不满足&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;七5xx服务器错误server-error&quot;&gt;七、5xx：服务器错误（Server Error）&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;表示服务器在处理请求时发生异常&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;500-internal-server-error&quot;&gt;500 Internal Server Error&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：服务器内部错误&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;原因：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;未捕获异常&lt;/li&gt;
      &lt;li&gt;代码 Bug&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;502-bad-gateway&quot;&gt;502 Bad Gateway&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：上游服务器返回无效响应&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;反向代理&lt;/li&gt;
      &lt;li&gt;微服务调用失败&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;503-service-unavailable&quot;&gt;503 Service Unavailable&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：服务暂不可用&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;服务维护&lt;/li&gt;
      &lt;li&gt;系统过载&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;504-gateway-timeout&quot;&gt;504 Gateway Timeout&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;含义：上游服务超时&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;场景：&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;GIS 大规模计算&lt;/li&gt;
      &lt;li&gt;数据库响应过慢&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;八restful-api-状态码设计建议&quot;&gt;八、RESTful API 状态码设计建议&lt;/h2&gt;

&lt;h3 id=&quot;1️⃣-成功不要只用-200&quot;&gt;1️⃣ 成功不要只用 200&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;场景&lt;/th&gt;
      &lt;th&gt;推荐状态码&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;创建资源&lt;/td&gt;
      &lt;td&gt;201&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;删除成功&lt;/td&gt;
      &lt;td&gt;204&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;异步处理&lt;/td&gt;
      &lt;td&gt;202&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;2️⃣-错误状态码要语义准确&quot;&gt;2️⃣ 错误状态码要“语义准确”&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;错误场景&lt;/th&gt;
      &lt;th&gt;正确做法&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;未登录&lt;/td&gt;
      &lt;td&gt;401&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;无权限&lt;/td&gt;
      &lt;td&gt;403&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;参数错误&lt;/td&gt;
      &lt;td&gt;400 / 422&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;资源不存在&lt;/td&gt;
      &lt;td&gt;404&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;3️⃣-状态码--错误信息结构示例&quot;&gt;3️⃣ 状态码 + 错误信息结构示例&lt;/h3&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;code&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;422&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Validation failed&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;details&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;area&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;must be greater than 0&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;九常见误区总结&quot;&gt;九、常见误区总结&lt;/h2&gt;

&lt;p&gt;❌ 所有错误都返回 200&lt;/p&gt;

&lt;p&gt;❌ 用 500 表示业务校验失败&lt;/p&gt;

&lt;p&gt;❌ 401 和 403 混用&lt;/p&gt;

&lt;p&gt;❌ 前端只判断 code，不看 HTTP 状态码&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;十结语&quot;&gt;十、结语&lt;/h2&gt;

&lt;p&gt;HTTP 状态码不仅是 &lt;strong&gt;网络协议的一部分&lt;/strong&gt;，更是 &lt;strong&gt;接口设计质量的重要体现&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;一个设计良好的接口，应该做到：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;状态码语义清晰&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;前后端理解一致&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;错误可定位、可处理&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Tue, 06 Jan 2026 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/HTTP-%E7%8A%B6%E6%80%81%E7%A0%81.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/HTTP-%E7%8A%B6%E6%80%81%E7%A0%81.html</guid>
        
        <category>HTTP</category>
        
        <category>前端</category>
        
        <category>后端</category>
        
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>土壤采样点</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;以 &lt;strong&gt;ArcGIS Pro 3.0.2&lt;/strong&gt; 版本为例，制作某区域土壤采样点。
投影坐标系：WGS-84墨卡托&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;目视采样&quot;&gt;目视采样&lt;/h1&gt;

&lt;p&gt;按照能谱或其他数据（本文所有“异常点”采集样本均为&lt;strong&gt;能谱总计数Total&lt;/strong&gt;）进行空间插值，对高/低值进行目视解译，根据需求选取合适数量的土壤采样点。&lt;/p&gt;

&lt;p&gt;该方法过于简单，不再赘述。&lt;/p&gt;

&lt;h1 id=&quot;完全随机采样&quot;&gt;完全随机采样&lt;/h1&gt;

&lt;h2 id=&quot;全局完全随机采样&quot;&gt;全局完全随机采样&lt;/h2&gt;

&lt;p&gt;将空间插值后的栅格数据进行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;栅格转点&lt;/code&gt;，之后使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;值提取至点&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多值提取至点&lt;/code&gt;。使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据管理工具&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;采样&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建随机点&lt;/code&gt;，根据数据设置参数。&lt;/p&gt;

&lt;p&gt;当前方法是在整个区域内进行采样，只考虑数量，不考虑任何其它因素。虽然使用了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;值提取至点&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多值提取至点&lt;/code&gt;，但仅是为了后续制图时可以借助参考。&lt;/p&gt;

&lt;h2 id=&quot;探测器行进轨迹上随机采样&quot;&gt;探测器行进轨迹上随机采样&lt;/h2&gt;

&lt;p&gt;与上述方法不同的点在于，随机分为不是全局，而是探测器（无人机、探测车等）的&lt;strong&gt;行进轨迹&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;根据数据点的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;采集时间&lt;/code&gt;字段生成轨迹路线：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据管理工具&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;要素&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;点集转线&lt;/code&gt;，&lt;strong&gt;排序字段&lt;/strong&gt;选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;采集时间&lt;/code&gt;字段。&lt;/p&gt;

&lt;p&gt;之后，再将轨迹路线转为点要素：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据管理工具&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;采样&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;沿线生成点&lt;/code&gt;。&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;谨记：切勿使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;要素转点&lt;/code&gt;工具，该工具只会生成一个点（中心点）。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建随机点&lt;/code&gt;，根据数据设置参数。&lt;/p&gt;

&lt;h1 id=&quot;沿线性要素的分层随机采样&quot;&gt;沿线性要素的分层随机采样&lt;/h1&gt;

&lt;p&gt;该方法是&lt;strong&gt;ArcGIS Pro&lt;/strong&gt;环境下的随机土壤采样点方式之一，其考虑了探测器行进路径及不同属性高低值的因素。&lt;/p&gt;

&lt;p&gt;使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;值提取至点&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多值提取至点&lt;/code&gt;，将空间插值数据（Total）提取至轨迹点中。打开点数据的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;属性表&lt;/code&gt;，&lt;strong&gt;添加&lt;/strong&gt;一个新字段，用以对当前点进行分类，例如字段&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt;，值有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;coldPoint&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hotPoint&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normalPoint&lt;/code&gt;。随后选中对应的分类，使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建随机点&lt;/code&gt;，根据数据设置参数。这里三种分类各自的数量可以为5/5/3，最小间隔距离为100米。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img14.360buyimg.com/ddimg/jfs/t1/368946/2/1327/174372/691aec6eF98883664/f1f40b9a051b4d08.jpg&quot; alt=&quot;Sampling_Point.png&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 17 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/%E5%9C%9F%E5%A3%A4%E9%87%87%E6%A0%B7%E7%82%B9.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/%E5%9C%9F%E5%A3%A4%E9%87%87%E6%A0%B7%E7%82%B9.html</guid>
        
        <category>智慧农业</category>
        
        <category>测土</category>
        
        <category>土壤采样</category>
        
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>土壤属性网格图</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;以 &lt;strong&gt;ArcGIS Pro 3.0.2&lt;/strong&gt; 版本为例，制作某区域pH空间分布网格图。
投影坐标系：WGS-84墨卡托&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;制作插值图&quot;&gt;制作插值图&lt;/h1&gt;

&lt;p&gt;对已有点数据进行插值，生成当前区域内的pH空间分布图，差值方法为克里金插值。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img11.360buyimg.com/ddimg/jfs/t1/355481/40/7951/105945/69141d4cF02e773d9/df5da46c63f068fb.jpg&quot; alt=&quot;Kriging_Region_A_pH.png&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;创建渔网&quot;&gt;创建渔网&lt;/h1&gt;

&lt;p&gt;选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建渔网&lt;/code&gt;工具，设置范围及像元大小，该演示设置像元宽度x高度为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;30x30&lt;/code&gt;，几何类型选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Polygon&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img14.360buyimg.com/ddimg/jfs/t1/355827/7/8056/95896/69141d4cFc76e7528/3675c3c8bcc1f288.jpg&quot; alt=&quot;Fishnet_Region_A.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;这会创建包围设置范围的一个矩形区域的渔网面要素及点要素。&lt;/p&gt;

&lt;p&gt;之后选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;裁剪&lt;/code&gt;工具对渔网面及及点进行裁剪，以当前区域为掩膜，只保留区域范围内的面及点。&lt;/p&gt;

&lt;p&gt;打开渔网面要素的属性表，对面积字段&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shape_Area&lt;/code&gt;进行降序/升序排列，将边缘不规则的网格进行删除（面积＜规则网格面积）。&lt;/p&gt;

&lt;h1 id=&quot;数据关联&quot;&gt;数据关联&lt;/h1&gt;

&lt;p&gt;选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;值提取至点&lt;/code&gt;，将克里金插值栅格数据提取至渔网点数据中。&lt;/p&gt;

&lt;p&gt;右键渔网面要素，选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;连接和关联&lt;/code&gt;–&amp;gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;添加空间连接&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://img13.360buyimg.com/ddimg/jfs/t1/346486/40/26084/128448/69141d4bF7c8bac77/9d032a96a2ce653c.jpg&quot; alt=&quot;Grid_Region_A_pH.png&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 12 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/%E5%9C%9F%E5%A3%A4%E5%B1%9E%E6%80%A7%E7%BD%91%E6%A0%BC%E5%9B%BE.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/%E5%9C%9F%E5%A3%A4%E5%B1%9E%E6%80%A7%E7%BD%91%E6%A0%BC%E5%9B%BE.html</guid>
        
        <category>网格图</category>
        
        <category>智慧农业</category>
        
        <category>测土</category>
        
        
        <category>tech</category>
        
      </item>
    
      <item>
        <title>Vue基础知识</title>
        <description>&lt;p&gt;&lt;img src=&quot;https://img10.360buyimg.com/ddimg/jfs/t1/359854/5/117/12576/690db88cF095ad0bd/686b3ea8314345f2.jpg&quot; alt=&quot;image.png&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;数组变化侦听&quot;&gt;数组变化侦听&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;数组变化侦听&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;click=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;addListHandle&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;添加数据&lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;li&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;v-for=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;(item,index) of names&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:key=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;index&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;{{ item }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Alice&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Bob&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Charlie&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Diana&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;methods&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;addListHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// this.names.push(&apos;New Name &apos; + (this.names.length + 1));&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;New Name &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 使用concat不会触发视图更新&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;New Name &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 重新赋值可以触发视图更新&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;计算属性computed&quot;&gt;计算属性computed&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;{{ yucol.name }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- &amp;lt;p&amp;gt;{{ yucol.kills.length &amp;gt; 0 ? &apos;Yes&apos;: &quot;No&quot; }}&amp;lt;/p&amp;gt; --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ killCount }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ yucolCounts() }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 这里可以添加一些数据属性&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;yucol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:{&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;yucol&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;kills&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;coding&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gaming&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;reading&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 计算属性&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 代码不更改时，只会计算一次，提升性能&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;killCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;yucol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;kills&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Yes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;No&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;methods&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 这里可以添加一些方法&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;yucolCounts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;yucol&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;kills&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Yes&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;No&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;class样式绑定&quot;&gt;Class样式绑定&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- &amp;lt;p :class=&quot;myClass&quot;&amp;gt;Class样式绑定&amp;lt;/p&amp;gt; --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{&apos;active&apos;:isActive,&apos;text-danger&apos;:hasError}&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Class样式绑定&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;classObject&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Class样式绑定（多个对象绑定）&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;arrs&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Class样式绑定（数组绑定）&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[isActive ? &apos;active&apos; : &apos;&apos;, {&apos;text-danger&apos;:hasError}]&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Class样式绑定（数组和对象）&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 这里可以添加一些数据属性&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// myClass:&apos;red-text&apos;&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;isActive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;hasError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;classObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:{&lt;/span&gt;
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;active&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;text-danger&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;arrs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;active&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;text-danger&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;arrActive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;active&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;arrDanger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;text-danger&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;style&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nc&quot;&gt;.active&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nl&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nl&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;30px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nc&quot;&gt;.text-danger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nl&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;yellow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;style绑定&quot;&gt;Style绑定&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{color:activeColor, fontSize:&apos;30px&apos;}&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Style绑定&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;styleObject&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Style绑定&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 这里可以添加一些数据属性&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;activeColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;styleObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:{&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;na&quot;&gt;fontSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;30px&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;侦听器watch&quot;&gt;侦听器watch&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;侦听器&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ message }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;click=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;updateHandle&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;修改数据&lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 这里可以添加一些数据属性&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Hello, Watch Demo!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;methods&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;updateHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Data has been updated!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 监听 message 属性的变化&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// newVal: 新值 oldVal: 旧值&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 函数名必须与要监听的数据属性名相同&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;newVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;oldVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 当 message 变化时执行的代码&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`message changed from &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;oldVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot; to &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;newVal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;表单输入绑定&quot;&gt;表单输入绑定&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;表单输入绑定&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;form&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;action=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;text&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;v-model.lazy=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ message }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;checkbox&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;checkbox&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;v-model=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;checked&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;label&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;for=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;checkbox&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;{{ checked }}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;checked&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;模板引用&quot;&gt;模板引用&lt;/h1&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;container&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        {{ contents }}
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;text&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;button&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;click=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getElementHandle&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;获取元素&lt;span class=&quot;nt&quot;&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;    
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;contents&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;内容&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;methods&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;getElementHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// innerHTML:原生js的属性&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$refs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;hhhhh&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$refs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;others&quot;&gt;others…&lt;/h1&gt;
</description>
        <pubDate>Fri, 07 Nov 2025 00:00:00 +0000</pubDate>
        <link>https://yucol.top/tech/Vue%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.html</link>
        <guid isPermaLink="true">https://yucol.top/tech/Vue%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86.html</guid>
        
        <category>Vue</category>
        
        <category>前端</category>
        
        
        <category>tech</category>
        
      </item>
    
  </channel>
</rss>
