diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 0c672f0..8259386 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -1,4 +1,4 @@ -import { defineConfigWithTheme } from 'vitepress' +import {defineConfigWithTheme, type MarkdownRenderer} from 'vitepress' import enGetNavs from "./src/en/nav"; import zhGetNavs from "./src/zh/nav"; import enGetConfig from "./src/en/config"; @@ -6,6 +6,7 @@ import zhGetConfig from "./src/zh/config"; import zhGetSidebar from "./src/zh/sidebars"; import enGetSidebar from "./src/en/sidebars"; import { AnnouncementPlugin } from 'vitepress-plugin-announcement' +import { plantuml } from "@mdit/plugin-plantuml"; // https://vitepress.dev/reference/site-config @@ -118,4 +119,12 @@ export default defineConfigWithTheme ({ } }, srcDir: 'docs', + markdown:{ + config:(md:MarkdownRenderer)=>{ + md.use(plantuml,{ + type:"fence", + fence:"plantuml", + }) + } + } }) diff --git a/docs/zh/backend/base/lifecycle.md b/docs/zh/backend/base/lifecycle.md index d07e411..b5d5533 100644 --- a/docs/zh/backend/base/lifecycle.md +++ b/docs/zh/backend/base/lifecycle.md @@ -29,4 +29,62 @@ MineAdmin 是构建运行在 [PHP](https://php.net) + ([Swoole](https://swoole.c ::: -![时序图](token.png) +--- + +### 时序图 + +```plantuml +participant "客户端" as Client +participant "服务端" as Server + +Client -> Server : 登录请求 +Server -> Client : 登录成功,返回 access_token 和 refresh_token +Client -> Local : 存储 access_token 和 refresh_token 到本地 + +Client -> Server : 发送请求 +Server -> Client : 返回 401 错误码且本地 refresh_token 未过期 +Client -> Queue : 暂存请求信息 +Client -> Server : 用 refresh_token 换取新 token +alt 换 token 接口返回 401 + Client -> Local : 清除本地缓存 + Client -> Server : 重定向到登录页面 +else 换 token 成功 + Client -> Local : 更新本地 token + Client -> Server : 重试请求失败的接口 +end +``` + +### 流程图 + +```plantuml +start +:登录成功; +-> +:存储 access_token 和 refresh_token 到本地; +-> +:发送请求; +if (请求失败,code = 401 且本地 refresh_token 未过期) then (yes) +-> +:暂存请求信息到队列; +-> +:用 refresh_token 换新 token; +if (换 token 接口返回 401) then (yes) +-> +:清除本地缓存,重定向到登录页面; +else (no) +-> +:更新本地 token,重试请求失败的接口; +endif +else (no) +endif +``` + +### 讲解 + +在登录成功后,将 access token 与 refresh token 存储于本地。 + +当某次请求出现失败,且错误码为 401,同时本地的 refresh_token 未过期时,需先将当前请求信息暂存至队列中。此队列旨在防止同一时刻多个请求同时去刷新 token。 + +随后,利用 refresh token 换取新的 access_token 与 refresh_token。 + +倘若换 token 的接口同样返回 401 错误码,则意味着 acces \ No newline at end of file diff --git a/package.json b/package.json index 9aa741a..190fffa 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "vitepress-plugin-announcement": "^0.1.2" }, "devDependencies": { + "@mdit/plugin-plantuml": "^0.13.1", "simple-git": "^3.27.0", "vitepress": "^1.4.0", "vitepress-plugin-comment-with-giscus": "^1.1.15", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 33c5268..240ac19 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,9 @@ importers: specifier: ^0.1.2 version: 0.1.2(vitepress@1.4.0(@algolia/client-search@4.24.0)(async-validator@4.2.5)(postcss@8.4.47)(search-insights@2.17.2)(sortablejs@1.15.2)) devDependencies: + '@mdit/plugin-plantuml': + specifier: ^0.13.1 + version: 0.13.1 simple-git: specifier: ^3.27.0 version: 3.27.0 @@ -368,6 +371,23 @@ packages: '@lit/reactive-element@2.0.4': resolution: {integrity: sha512-GFn91inaUa2oHLak8awSIigYz0cU0Payr1rcFsrkf5OJ5eSPxElyZfKh0f2p9FsTiZWXQdWGJeXZICEfXXYSXQ==} + '@mdit/plugin-plantuml@0.13.1': + resolution: {integrity: sha512-qupMO/lG1mDYaGHSutB9AO1TsxHjmp4yFnvp3VBNNRdVh9lqWhXFv/htrnr0IGEWAmlik6zlkCvz/YrKRONV5A==} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + + '@mdit/plugin-uml@0.13.1': + resolution: {integrity: sha512-JdCOg25OyG+QJFAba6AWwdpkaOjuht5VmOqYt4/h/AzLsIHh/2j+TnCZBn0XQm3D8yJ9Y4w4oouS4wpPduRW0A==} + engines: {node: '>= 18'} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + '@mineadmin/echarts@1.0.1': resolution: {integrity: sha512-dVdJZReDsQyoi+lwcTl0SpVg86zBQyBmdEqu1ooyfQPgaWNa0MKoD0pno02GxUnVvOYoe+GzkcSBpFhNZvmZZQ==} peerDependencies: @@ -1350,6 +1370,15 @@ snapshots: dependencies: '@lit-labs/ssr-dom-shim': 1.2.1 + '@mdit/plugin-plantuml@0.13.1': + dependencies: + '@mdit/plugin-uml': 0.13.1 + '@types/markdown-it': 14.1.2 + + '@mdit/plugin-uml@0.13.1': + dependencies: + '@types/markdown-it': 14.1.2 + '@mineadmin/echarts@1.0.1(element-plus@2.8.3(vue@3.5.7))': dependencies: '@vueuse/core': 10.11.1(vue@3.5.7)