feat(playground): ✨ 新增示例项目
This commit is contained in:
Vendored
+7
@@ -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;
|
||||
}
|
||||
@@ -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/vue3 Playground</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@r-utils/playground-vue3",
|
||||
"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/common": "workspace:^",
|
||||
"@r-utils/vue3": "workspace:^",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "catalog:",
|
||||
"vue-tsc": "^2.2.8"
|
||||
}
|
||||
}
|
||||
@@ -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 |
@@ -0,0 +1,106 @@
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app">
|
||||
<header class="header">
|
||||
<router-link to="/" class="logo">@r-utils/vue3 & @r-utils/common</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;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #42b883;
|
||||
color: #fff;
|
||||
border-color: #42b883;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: #42b883;
|
||||
}
|
||||
|
||||
code {
|
||||
background: #f0f0f0;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f9f9f9;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { createApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
import "./style.css";
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.mount("#app");
|
||||
@@ -0,0 +1,71 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
name: "index",
|
||||
component: () => import("@/views/IndexPage.vue"),
|
||||
},
|
||||
// @r-utils/vue3
|
||||
{
|
||||
path: "/vue3/use-load-more",
|
||||
name: "useLoadMore",
|
||||
component: () => import("@/views/vue3/UseLoadMoreDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-timer",
|
||||
name: "useTimer",
|
||||
component: () => import("@/views/vue3/UseTimerDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-number-string",
|
||||
name: "useNumberString",
|
||||
component: () => import("@/views/vue3/UseNumberStringDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-value-of-rule",
|
||||
name: "useValueOfRule",
|
||||
component: () => import("@/views/vue3/UseValueOfRuleDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/merge-class",
|
||||
name: "mergeClass",
|
||||
component: () => import("@/views/vue3/MergeClassDemo.vue"),
|
||||
},
|
||||
// @r-utils/common
|
||||
{
|
||||
path: "/common/permission",
|
||||
name: "permission",
|
||||
component: () => import("@/views/common/PermissionDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/countdown",
|
||||
name: "countdown",
|
||||
component: () => import("@/views/common/CountdownDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/timeout-timer",
|
||||
name: "timeoutTimer",
|
||||
component: () => import("@/views/common/TimeoutTimerDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/knock-test",
|
||||
name: "knockTest",
|
||||
component: () => import("@/views/common/KnockTestDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/wait",
|
||||
name: "wait",
|
||||
component: () => import("@/views/common/WaitDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/slowly-scroll",
|
||||
name: "slowlyScroll",
|
||||
component: () => import("@/views/common/SlowlyScrollDemo.vue"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Demo 页面公共样式 */
|
||||
.demo-page {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.demo-title {
|
||||
font-size: 20px;
|
||||
margin-bottom: 8px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.demo-desc {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.demo-block {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>Playground</h1>
|
||||
<p class="desc">以下是 @r-utils/vue3 和 @r-utils/common 各模块的使用示例,点击进入独立页面</p>
|
||||
|
||||
<section class="section">
|
||||
<h2>@r-utils/vue3</h2>
|
||||
<ul class="nav-list">
|
||||
<li><router-link to="/vue3/use-load-more">useLoadMore — 列表加载更多</router-link></li>
|
||||
<li><router-link to="/vue3/use-timer">useTimer — 倒计时</router-link></li>
|
||||
<li><router-link to="/vue3/use-number-string">useNumber / useString — 响应式类型转换</router-link></li>
|
||||
<li><router-link to="/vue3/use-value-of-rule">useValueOfRule — 按规则转换输入</router-link></li>
|
||||
<li><router-link to="/vue3/merge-class">mergeClass / createCustomClassObj — Vue Class 合并</router-link></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<h2>@r-utils/common</h2>
|
||||
<ul class="nav-list">
|
||||
<li><router-link to="/common/permission">Permission — 权限字符串校验</router-link></li>
|
||||
<li><router-link to="/common/countdown">Countdown — 倒计时</router-link></li>
|
||||
<li><router-link to="/common/timeout-timer">TimeoutTimer — 超时计时器</router-link></li>
|
||||
<li><router-link to="/common/knock-test">KnockTest — 顺序敲击测试</router-link></li>
|
||||
<li><router-link to="/common/wait">wait — 等待函数</router-link></li>
|
||||
<li><router-link to="/common/slowly-scroll">slowlyScroll — 缓动滚动</router-link></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<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,50 @@
|
||||
<script setup lang="ts">
|
||||
import { Countdown } from "@r-utils/common";
|
||||
import { ref, onUnmounted } from "vue";
|
||||
|
||||
const timeDisplay = ref("00:00:10");
|
||||
const status = ref<"idle" | "running" | "stopped">("idle");
|
||||
let countdown: Countdown | null = null;
|
||||
|
||||
function start() {
|
||||
countdown = new Countdown(10);
|
||||
countdown.addStepEventListener((t) => {
|
||||
timeDisplay.value = t;
|
||||
});
|
||||
countdown.addCountdownEventListener(() => {
|
||||
status.value = "stopped";
|
||||
});
|
||||
countdown.start();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
function stop() {
|
||||
countdown?.stop();
|
||||
status.value = "stopped";
|
||||
}
|
||||
|
||||
function restart() {
|
||||
countdown?.restart();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">Countdown — 倒计时</h2>
|
||||
<p class="demo-desc">基于 dayjs 的倒计时类,支持步骤监听和完成监听</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>倒计时: <code>{{ timeDisplay }}</code> ({{ status }})</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="status === 'running'" @click="start">开始</button>
|
||||
<button :disabled="status !== 'running'" @click="stop">停止</button>
|
||||
<button :disabled="status !== 'running'" @click="restart">重新开始</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import { KnockTest } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const config = {
|
||||
maxWaitTime: 5000,
|
||||
operations: [
|
||||
{ duration: 1000, delay: 500, times: 2 },
|
||||
{ duration: 1000, delay: 500, times: 3 },
|
||||
],
|
||||
};
|
||||
|
||||
const knockTest = new KnockTest(config);
|
||||
const message = ref("点击按钮按顺序触发敲击(2次 → 等待 → 3次)");
|
||||
const successCount = ref(0);
|
||||
|
||||
knockTest.addCallback(() => {
|
||||
successCount.value++;
|
||||
message.value = `🎉 敲击测试成功!(${successCount.value}次)`;
|
||||
});
|
||||
|
||||
function knock() {
|
||||
message.value = "敲击中...";
|
||||
knockTest.knock();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">KnockTest — 顺序敲击测试</h2>
|
||||
<p class="demo-desc">按指定顺序敲击/点击触发回调的状态机,可用于隐藏入口等场景</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>{{ message }}</p>
|
||||
<p>成功次数: {{ successCount }}</p>
|
||||
<button style="margin-top: 8px" @click="knock">敲击 (Knock)</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import { Permission } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const permissionList = ["user:read:profile", "admin:write:config", "invalid"];
|
||||
const permission = new Permission(permissionList);
|
||||
|
||||
const input = ref("user:read:profile");
|
||||
const isValid = ref(permission.isValid(input.value));
|
||||
|
||||
function check() {
|
||||
isValid.value = permission.isValid(input.value);
|
||||
}
|
||||
check();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">Permission — 权限字符串校验</h2>
|
||||
<p class="demo-desc">校验权限字符串是否符合指定格式(如 module:action:resource)</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>格式: <code>module:action:resource</code> (三级,冒号分隔)</p>
|
||||
<p>
|
||||
输入权限字符串:
|
||||
<input v-model="input" type="text" @input="check" />
|
||||
</p>
|
||||
<div class="result">
|
||||
<p>
|
||||
校验结果:
|
||||
<code :style="{ color: isValid ? 'green' : 'red' }">
|
||||
{{ isValid ? "✓ 有效" : "✗ 无效" }}
|
||||
</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { slowlyScroll } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const currentValue = ref(0);
|
||||
const isAnimating = ref(false);
|
||||
|
||||
async function animate() {
|
||||
isAnimating.value = true;
|
||||
await slowlyScroll(0, 500, 1000, (v) => {
|
||||
currentValue.value = Math.round(v);
|
||||
});
|
||||
isAnimating.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">slowlyScroll — 缓动滚动</h2>
|
||||
<p class="demo-desc">使用缓动函数(easeOutSine)从起始值缓动到结束值</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>当前值: <code>{{ currentValue }}</code></p>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" :style="{ width: (currentValue / 500) * 100 + '%' }"></div>
|
||||
</div>
|
||||
<button style="margin-top: 8px" :disabled="isAnimating" @click="animate">
|
||||
{{ isAnimating ? '动画中...' : '开始缓动 (0 → 500)' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.progress-bar {
|
||||
height: 20px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #42b883, #35495e);
|
||||
border-radius: 10px;
|
||||
transition: width 0.016s linear;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { TimeoutTimer } from "@r-utils/common";
|
||||
import { ref, onUnmounted } from "vue";
|
||||
|
||||
const timeDisplay = ref("5");
|
||||
const status = ref<"idle" | "running" | "stopped">("idle");
|
||||
let timer: TimeoutTimer | null = null;
|
||||
|
||||
function start() {
|
||||
timer = TimeoutTimer.start(
|
||||
5,
|
||||
0,
|
||||
1000,
|
||||
(t) => {
|
||||
timeDisplay.value = String(t);
|
||||
},
|
||||
() => {
|
||||
status.value = "stopped";
|
||||
timeDisplay.value = "0";
|
||||
},
|
||||
);
|
||||
timer.start();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
function stop() {
|
||||
timer?.stop();
|
||||
status.value = "stopped";
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">TimeoutTimer — 超时计时器</h2>
|
||||
<p class="demo-desc">可配置起始/结束时间和间隔的计时器,支持静态创建</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>剩余: <code>{{ timeDisplay }}</code> ({{ status }})</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="status === 'running'" @click="start">开始 (5s)</button>
|
||||
<button :disabled="status !== 'running'" @click="stop">停止</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import { wait } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const waiting = ref(false);
|
||||
const waitDone = ref(false);
|
||||
const waitTime = ref(2000);
|
||||
|
||||
async function handleWait() {
|
||||
waiting.value = true;
|
||||
waitDone.value = false;
|
||||
await wait(waitTime.value);
|
||||
waiting.value = false;
|
||||
waitDone.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">wait — 等待函数</h2>
|
||||
<p class="demo-desc">返回一个在指定时间后 resolve 的 Promise,用于异步等待</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
等待时间(ms):
|
||||
<input v-model.number="waitTime" type="number" :min="100" :step="100" />
|
||||
</p>
|
||||
<button style="margin-top: 8px" :disabled="waiting" @click="handleWait">
|
||||
{{ waiting ? `等待 ${waitTime}ms 中...` : `等待 ${waitTime}ms` }}
|
||||
</button>
|
||||
<p v-if="waitDone" class="result">✓ 等待完成</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import { mergeClass, createCustomClassObj } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const classStr = ref("active primary");
|
||||
const classArr = ref(["bold", "underline"]);
|
||||
|
||||
const merged = ref<Record<string, boolean>>({});
|
||||
const customObj = ref<Record<string, true>>({});
|
||||
|
||||
function handleMerge() {
|
||||
merged.value = mergeClass(classStr.value, classArr.value);
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
customObj.value = createCustomClassObj(classStr.value);
|
||||
}
|
||||
|
||||
handleMerge();
|
||||
handleCreate();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">mergeClass / createCustomClassObj — Vue Class 合并</h2>
|
||||
<p class="demo-desc">将字符串/数组形式的 Vue Class 合并为对象形式</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
class 字符串:
|
||||
<input v-model="classStr" type="text" />
|
||||
</p>
|
||||
<p>
|
||||
class 数组 (逗号分隔):
|
||||
<input
|
||||
:value="classArr.join(',')"
|
||||
type="text"
|
||||
@input="
|
||||
classArr = ($event.target as HTMLInputElement).value.split(',')
|
||||
"
|
||||
/>
|
||||
</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button @click="handleMerge">mergeClass</button>
|
||||
<button @click="handleCreate">createCustomClassObj</button>
|
||||
</div>
|
||||
<div class="result">
|
||||
<p>mergeClass: <code>{{ JSON.stringify(merged) }}</code></p>
|
||||
<p>createCustomClassObj: <code>{{ JSON.stringify(customObj) }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import { useLoadMore } from "@r-utils/vue3";
|
||||
|
||||
// 模拟分页请求
|
||||
const mockFetch = (pageNum: number, pageSize: number) => {
|
||||
return new Promise<{ total: number; list: string[] }>((resolve) => {
|
||||
setTimeout(() => {
|
||||
const total = 35;
|
||||
const start = (pageNum - 1) * pageSize;
|
||||
const end = Math.min(start + pageSize, total);
|
||||
const list = Array.from({ length: end - start }, (_, i) =>
|
||||
`Item ${start + i + 1}`,
|
||||
);
|
||||
resolve({ total, list });
|
||||
}, 500);
|
||||
});
|
||||
};
|
||||
|
||||
const { list, total, status, isLoading, isFinished, loadMore, initList } =
|
||||
useLoadMore(mockFetch, { pageSize: 10 });
|
||||
|
||||
// 首次加载
|
||||
initList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useLoadMore — 列表加载更多</h2>
|
||||
<p class="demo-desc">分页加载列表数据的组合式 API,支持加载更多、重置、加载状态管理</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>总数: {{ total }},当前: {{ list.length }} 条</p>
|
||||
<p>状态: {{ status }},加载中: {{ isLoading }},已完成: {{ isFinished }}</p>
|
||||
|
||||
<ul class="list">
|
||||
<li v-for="(item, index) in list" :key="index">{{ item }}</li>
|
||||
</ul>
|
||||
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="isLoading" @click="loadMore">加载更多</button>
|
||||
<button @click="initList">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.list li {
|
||||
padding: 4px 0;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { useNumber, useString } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const rawValue = ref("42.5");
|
||||
const { number, int, float } = useNumber(rawValue);
|
||||
const { string } = useString(rawValue);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useNumber / useString — 响应式类型转换</h2>
|
||||
<p class="demo-desc">将响应式变量在 number 和 string 之间双向转换</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
原始值:
|
||||
<input v-model="rawValue" type="text" />
|
||||
</p>
|
||||
<div class="result">
|
||||
<p>useNumber — number: <code>{{ number }}</code></p>
|
||||
<p>useNumber — int: <code>{{ int }}</code></p>
|
||||
<p>useNumber — float: <code>{{ float }}</code></p>
|
||||
<p>useString — string: <code>{{ string }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { useTimer } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const initTime = ref(10);
|
||||
const { time, start, restart, stop } = useTimer(initTime.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useTimer — 倒计时</h2>
|
||||
<p class="demo-desc">简单的倒计时 Hook,支持开始、重新开始、停止</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>倒计时: <code>{{ time }}s</code></p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button @click="start">开始</button>
|
||||
<button @click="restart">重新开始</button>
|
||||
<button @click="stop">停止</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { useValueOfRule } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const inputValue = ref("42.5");
|
||||
const rule = ref({ min: 0, max: 99999.99, digits: 2, required: true });
|
||||
|
||||
const { value, rule: ruleRef, handleChange } = useValueOfRule({
|
||||
value: inputValue,
|
||||
rule: rule.value,
|
||||
});
|
||||
|
||||
function apply() {
|
||||
handleChange();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useValueOfRule — 按规则转换输入</h2>
|
||||
<p class="demo-desc">根据自定义规则(min/max/digits/integer 等)限制和转换输入值</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
输入值:
|
||||
<input v-model="inputValue" type="text" @blur="apply" />
|
||||
</p>
|
||||
<p style="margin-top: 8px; font-size: 13px; color: #666">
|
||||
规则: min=0, max=99999.99, digits=2, required=true
|
||||
</p>
|
||||
<button style="margin-top: 8px" @click="apply">应用规则</button>
|
||||
<div class="result">
|
||||
<p>转换结果: <code>{{ value }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "env.d.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"root":["./src/main.ts","./src/router/index.ts","./src/app.vue","./src/views/indexpage.vue","./src/views/common/countdowndemo.vue","./src/views/common/knocktestdemo.vue","./src/views/common/permissiondemo.vue","./src/views/common/slowlyscrolldemo.vue","./src/views/common/timeouttimerdemo.vue","./src/views/common/waitdemo.vue","./src/views/vue3/mergeclassdemo.vue","./src/views/vue3/useloadmoredemo.vue","./src/views/vue3/usenumberstringdemo.vue","./src/views/vue3/usetimerdemo.vue","./src/views/vue3/usevalueofruledemo.vue","./env.d.ts"],"version":"5.9.3"}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import { resolve } from "path";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user