feat(playground): 新增示例项目

This commit is contained in:
2026-06-30 11:21:16 +08:00
parent 4759dfe6b2
commit c22b72ac7b
78 changed files with 9058 additions and 213 deletions
+7
View File
@@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent<object, object, unknown>;
export default component;
}
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@r-utils/vue2 Playground</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+24
View File
@@ -0,0 +1,24 @@
{
"name": "@r-utils/playground-vue2",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview",
"lint": "eslint . --fix",
"format": "prettier --write src"
},
"dependencies": {
"@r-utils/vue2": "workspace:^",
"vue": "^2.7.16",
"vue-router": "^3.6.5"
},
"devDependencies": {
"@vitejs/plugin-vue2": "^2.0.1",
"typescript": "^5.9.3",
"vite": "^5.4.0",
"vue-tsc": "^2.2.8"
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFBD4F"></stop><stop offset="100%" stop-color="#FF9640"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

+62
View File
@@ -0,0 +1,62 @@
<template>
<div class="app">
<header class="header">
<router-link to="/" class="logo">@r-utils/vue2</router-link>
</header>
<main class="main">
<router-view />
</main>
</div>
</template>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, sans-serif;
background: #f5f5f5;
color: #333;
}
.app {
min-height: 100vh;
}
.header {
background: #fff;
border-bottom: 1px solid #eee;
padding: 12px 24px;
position: sticky;
top: 0;
z-index: 100;
}
.logo {
font-size: 16px;
font-weight: bold;
color: #42b883;
text-decoration: none;
}
.logo:hover {
text-decoration: underline;
}
.main {
max-width: 800px;
margin: 0 auto;
padding: 24px;
}
code {
background: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-size: 13px;
}
</style>
+12
View File
@@ -0,0 +1,12 @@
import Vue from "vue";
import { VisibilityPlugin } from "@r-utils/vue2";
import App from "./App.vue";
import router from "./router";
Vue.use(VisibilityPlugin);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new Vue({
router,
render: (h: any) => h(App),
} as any).$mount("#app");
+24
View File
@@ -0,0 +1,24 @@
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "index",
component: () => import("@/views/IndexPage.vue"),
},
{
path: "/visibility-plugin",
name: "visibilityPlugin",
component: () => import("@/views/VisibilityPluginDemo.vue"),
},
];
const router = new VueRouter({
mode: "history",
routes,
});
export default router;
@@ -0,0 +1,74 @@
<template>
<div>
<h1>Playground</h1>
<p class="desc">以下是 @r-utils/vue2 各模块的使用示例点击进入独立页面</p>
<section class="section">
<h2>@r-utils/vue2</h2>
<ul class="nav-list">
<li><router-link to="/visibility-plugin">VisibilityPlugin 页面可见性生命周期</router-link></li>
</ul>
</section>
</div>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend({});
</script>
<style scoped>
h1 {
font-size: 24px;
margin-bottom: 8px;
color: #1a1a1a;
}
.desc {
color: #666;
margin-bottom: 24px;
}
.section {
margin-bottom: 24px;
}
.section h2 {
font-size: 16px;
margin-bottom: 12px;
color: #42b883;
border-bottom: 1px solid #eee;
padding-bottom: 8px;
}
.nav-list {
list-style: none;
padding: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.nav-list li {
background: #fff;
border-radius: 6px;
padding: 12px 16px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
transition: box-shadow 0.2s;
}
.nav-list li:hover {
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.nav-list a {
text-decoration: none;
color: #333;
font-size: 14px;
display: block;
}
.nav-list a:hover {
color: #42b883;
}
</style>
@@ -0,0 +1,48 @@
<template>
<div class="demo-page">
<h2 class="demo-title">VisibilityPlugin onShow / onHide</h2>
<p class="demo-desc"> Vue2 组件提供 onShow / onHide 生命周期钩子监听页面可见性变化</p>
<div class="demo-block">
<p>切换浏览器标签页可以触发 onShow / onHide 钩子</p>
<p>当前状态: <code :style="{ color: visible ? 'green' : 'red' }">{{ visible ? '✓ 可见' : '✗ 隐藏' }}</code></p>
<p>onShow 触发次数: <code>{{ showCount }}</code></p>
<p>onHide 触发次数: <code>{{ hideCount }}</code></p>
</div>
</div>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend({
name: "VisibilityPluginDemo",
data() {
return {
visible: true,
showCount: 0,
hideCount: 0,
};
},
// VisibilityPlugin 注入的自定义生命周期钩子
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onShow(this: any) {
this.visible = true;
this.showCount++;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onHide(this: any) {
this.visible = false;
this.hideCount++;
},
});
</script>
<style scoped>
.demo-block {
background: #fff;
border-radius: 8px;
padding: 20px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
</style>
+11
View File
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"types": ["vite/client"]
},
"include": ["src/**/*.ts", "src/**/*.vue", "env.d.ts"]
}
+1
View File
@@ -0,0 +1 @@
{"root":["./src/main.ts","./src/router/index.ts","./src/app.vue","./src/views/indexpage.vue","./src/views/visibilityplugindemo.vue","./env.d.ts"],"version":"5.9.3"}
+12
View File
@@ -0,0 +1,12 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue2";
import { resolve } from "path";
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
});