feat: 添加 Husky 和 commit 限制配置

This commit is contained in:
zhongyidian committed 2025-09-14 11:38:52 +08:00
commit 27e0c23b3f
125 files changed
+5760

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
.cursor/
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit ${1}
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged
+7
View File
@@ -0,0 +1,7 @@
/dist/*
/html/*
.local
/node_modules/**
**/*.svg
**/*.sh
/public/*
+12
View File
@@ -0,0 +1,12 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"printWidth": 100,
"endOfLine": "lf",
"arrowParens": "avoid",
"bracketSpacing": true,
"bracketSameLine": false,
"vueIndentScriptAndStyle": false
}
+15
View File
@@ -0,0 +1,15 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": true,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "always",
"htmlWhitespaceSensitivity": "ignore",
"vueIndentScriptAndStyle": false,
"endOfLine": "auto",
"singleAttributePerLine": false
}
+3
View File
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}
+5
View File
@@ -0,0 +1,5 @@
# Vue 3 + TypeScript + Vite
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
+18
View File
@@ -0,0 +1,18 @@
import globals from 'globals'
import tseslint from 'typescript-eslint'
import pluginVue from 'eslint-plugin-vue'
import { defineConfig } from 'eslint/config'
export default defineConfig([
{ files: ['**/*.{js,mjs,cjs,ts,mts,cts,vue}'], languageOptions: { globals: globals.browser } },
tseslint.configs.recommended,
pluginVue.configs['flat/essential'],
{
files: ['**/*.vue'],
languageOptions: { parserOptions: { parser: tseslint.parser } },
rules: {
'vue/multi-word-component-names': 'off',
'@typescript-eslint/no-unused-vars': 'warn'
}
}
])
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<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>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+94
View File
@@ -0,0 +1,94 @@
{
"name": "super_video",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview",
"lint": "eslint src",
"fix": "eslint src --fix",
"prepare": "husky"
},
"dependencies": {
"vue": "^3.5.18",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.8.1",
"@types/node": "^24.3.3",
"@vitejs/plugin-vue": "^6.0.1",
"@vue/tsconfig": "^0.7.0",
"autoprefixer": "^10.4.21",
"eslint": "^9.35.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-vue": "^10.4.0",
"globals": "^16.4.0",
"husky": "^9.1.7",
"jiti": "^2.5.1",
"lint-staged": "^16.1.6",
"postcss": "^8.5.6",
"prettier": "^3.6.2",
"tailwindcss": "^3.4.17",
"typescript": "~5.8.3",
"typescript-eslint": "^8.43.0",
"vite": "^7.1.2",
"vue-tsc": "^3.0.5"
},
"lint-staged": {
"*.{js,ts,vue}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,css,html}": [
"prettier --write"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
],
"rules": {
"type-enum": [
2,
"always",
[
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"chore",
"revert"
]
],
"subject-case": [
2,
"never",
[
"sentence-case",
"start-case",
"pascal-case",
"upper-case"
]
],
"subject-max-length": [
2,
"always",
50
],
"body-max-line-length": [
2,
"always",
100
]
}
}
}
+3676
View File
File diff suppressed because it is too large. Load diff
+6
View File
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
}
+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="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></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.5 KiB

+33
View File
@@ -0,0 +1,33 @@
<template>
<div class="app-container" :style="containerStyle">
<div class="app-content" :style="scaleStyle">
<router-view />
</div>
</div>
</template>
<script setup lang="ts">
import { useScale } from '@/composables/useScale'
// 使用等比例缩放hook
const { scaleStyle } = useScale()
// 容器样式
const containerStyle = {
width: '100vw',
height: '100vh',
overflow: 'hidden',
position: 'relative' as const,
background: '#000'
}
</script>
<style>
#app {
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',
'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File
Whitespace-only changes.
+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="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

+26
View File
@@ -0,0 +1,26 @@
<!--
按钮组件
传入背景图片
-->
<template>
<img class="cursor-pointer" :src="getStaticImage(image)" @click="handleClick" />
</template>
<script lang="ts" setup>
import { getStaticImage } from '@/utils'
import { useRouter, type RouteLocationRaw } from 'vue-router'
const router = useRouter()
const props = defineProps<{
image: string
path?: RouteLocationRaw
}>()
const handleClick = () => {
if (props.path) {
router.push(props.path)
}
}
</script>
+3
View File
@@ -0,0 +1,3 @@
import ImgButton from './ImgButton.vue'
export { ImgButton }
+252
View File
@@ -0,0 +1,252 @@
<template>
<div class="guide-dragon-container">
<!-- 背景图片 -->
<!-- <div
class="guide-bg absolute inset-0 bg-cover bg-center bg-no-repeat"
:style="{ backgroundImage: getBackgroundImage(IMAGE_PATHS.GUIDE_DRAGON_BG) }"></div> -->
<!-- 导学小龙UI区域 -->
<div class="guide-ui absolute left-16 top-1/2 transform -translate-y-1/2">
<!-- 主UI面板 -->
<div class="guide-panel">
<!-- 标题区域 -->
<ImgButton
v-if="showSkip"
:image="IMAGE_PATHS.BUTTONS.ESCAPE"
@click="handleSkip"
class="skip-button"
/>
<!-- 内容区域 -->
<div class="guide-content" @click="handleContinue">
<!-- <div class="content-icon">
<div class="icon-outer"></div>
<div class="icon-inner"></div>
</div> -->
<div class="content-text">
<slot>
<p>
试着用这些方法记录身边的小事,你会发现,原来平凡的日子里有这么多值得捕捉的瞬间。
</p>
</slot>
</div>
</div>
<!-- 进度指示器 -->
<div class="progress-indicator">
<div class="progress-dots">
<span
v-for="i in totalSteps"
:key="i"
class="progress-dot"
:class="{ active: i <= currentStep }"
></span>
</div>
</div>
</div>
</div>
<!-- 小龙角色区域 -->
<div class="dragon-character absolute right-16 top-1/2 transform -translate-y-1/2">
<div class="dragon-container">
<!-- 小龙角色图片 -->
<img :src="getStaticImage(IMAGE_PATHS.GUIDE_PERSON)" alt="导学小龙" class="dragon-image" />
<!-- 发光效果 -->
<div class="dragon-glow"></div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { getStaticImage, IMAGE_PATHS } from '@/utils'
import { ImgButton } from '@/components/Button'
interface Props {
/** 是否显示跳过按钮 */
showSkip?: boolean
/** 当前步骤 */
currentStep?: number
/** 总步骤数 */
totalSteps?: number
}
interface Emits {
(e: 'next'): void
(e: 'skip'): void
(e: 'complete'): void
}
withDefaults(defineProps<Props>(), {
showSkip: true,
currentStep: 1,
totalSteps: 1
})
const emit = defineEmits<Emits>()
// 处理跳过
const handleSkip = () => {
try {
emit('skip')
} catch (error) {
console.error('GuideDragon handleSkip error:', error)
}
}
//继续
const handleContinue = () => {
emit('next')
}
</script>
<style scoped>
.guide-dragon-container {
@apply w-full h-full relative overflow-hidden;
}
.guide-ui {
width: 80%;
z-index: 10;
}
.guide-panel {
@apply relative bg-white rounded-2xl shadow-2xl;
/* background: linear-gradient(135deg, #60a5fa 0%, #a855f7 100%);
border: 2px solid #60a5fa;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); */
width: 1547px;
height: 279px;
padding: 75px 30px 30px 120px;
background-image: url('../../assets/images/components/box.png');
background-color: rgba(0, 0, 0, 0); /* 背景完全透明 */
}
.guide-header {
@apply flex items-center justify-between p-4;
}
.header-button {
@apply relative px-4 py-2 rounded-lg;
background: linear-gradient(135deg, #60a5fa 0%, #06b6d4 100%);
border: 2px solid #60a5fa;
}
.header-text {
@apply text-white text-sm font-bold;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.skip-button {
@apply text-white text-sm underline hover:no-underline;
position: absolute;
right: 30px;
top: 35px;
}
.guide-content {
@apply flex items-start p-6 h-full;
}
.content-icon {
@apply relative mr-4 flex-shrink-0;
}
.icon-outer {
@apply w-6 h-6 rounded-full border-2 border-blue-400;
background: #60a5fa;
}
.icon-inner {
@apply absolute top-1 left-1 w-4 h-4 rounded-full;
background: #1e40af;
}
.content-text {
@apply text-white leading-relaxed font-bold text-4xl flex-1;
}
.progress-indicator {
@apply absolute bottom-6 right-6;
}
.progress-dots {
@apply flex space-x-2;
}
.progress-dot {
@apply w-2 h-2 rounded-full;
background: rgba(255, 255, 255, 0.3);
transition: all 0.3s ease;
}
.progress-dot.active {
background: #60a5fa;
box-shadow: 0 0 8px rgba(96, 165, 250, 0.6);
}
.dragon-character {
width: 250px;
height: 350px;
z-index: 5;
}
.dragon-container {
@apply w-full h-full relative;
}
.dragon-image {
@apply w-full h-full object-contain;
filter: drop-shadow(0 0 20px rgba(255, 255, 0, 0.3));
}
.dragon-glow {
@apply absolute inset-0 rounded-full;
background: radial-gradient(circle, rgba(255, 255, 0, 0.2) 0%, transparent 70%);
animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
from {
opacity: 0.5;
transform: scale(1);
}
to {
opacity: 0.8;
transform: scale(1.1);
}
}
/* 操作按钮样式已移除,因为不再需要底部按钮区域 */
/* 动画效果 */
.guide-dragon-container {
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: scale(0.95);
}
to {
opacity: 1;
transform: scale(1);
}
}
.dragon-character {
animation: float 3s ease-in-out infinite;
}
@keyframes float {
0%,
100% {
transform: translateY(-50%) translateY(0);
}
50% {
transform: translateY(-50%) translateY(-10px);
}
}
</style>
+233
View File
@@ -0,0 +1,233 @@
<template>
<div class="guide-steps-container" v-if="show">
<GuideDragon
:show-skip="currentStep < totalSteps"
:current-step="currentStep"
:total-steps="totalSteps"
@next="handleNext"
@skip="handleSkip"
@complete="handleComplete"
>
<template #default>
<!-- 支持插槽形式的步骤内容 -->
<div v-if="useSlotMode">
<component
:is="currentStepComponent"
@continue="handleNext"
:is-last-step="currentStep >= totalSteps"
:current-step="currentStep"
:total-steps="totalSteps"
/>
</div>
<!-- 兼容原有的配置形式 -->
<div v-else v-html="currentStepContent"></div>
</template>
</GuideDragon>
</div>
</template>
<script setup lang="ts">
import { ref, computed, useSlots, onMounted, onUnmounted } from 'vue'
import GuideDragon from './GuideDragon.vue'
interface GuideStep {
id: string
title?: string
content: string
nextText?: string
}
interface Props {
/** 引导步骤配置 - 当使用插槽模式时可以为空 */
steps?: GuideStep[]
/** 是否自动开始 */
autoStart?: boolean
/** 是否启用键盘导航 */
keyboardNavigation?: boolean
/** 自动播放间隔时间(毫秒),0表示不自动播放 */
autoPlayInterval?: number
}
interface Emits {
(e: 'complete'): void
(e: 'skip'): void
(e: 'step-change', step: GuideStep | null, index: number): void
}
const props = withDefaults(defineProps<Props>(), {
steps: () => [],
autoStart: true,
keyboardNavigation: true,
autoPlayInterval: 0
})
const emit = defineEmits<Emits>()
const slots = useSlots()
const show = ref(true)
const currentStepIndex = ref(0)
const useSlotMode = computed(() => {
return slots.default && slots.default().length > 0
})
const slotSteps = computed(() => {
if (!useSlotMode.value) return []
return slots.default?.() || []
})
const currentStep = computed(() => currentStepIndex.value + 1)
const totalSteps = computed(() => {
return useSlotMode.value ? slotSteps.value.length : props.steps.length
})
const currentStepData = computed(() => {
if (useSlotMode.value) {
return null // 插槽模式不需要step数据
}
if (props.steps.length === 0) {
return null
}
return props.steps[currentStepIndex.value] || null
})
const currentStepComponent = computed(() => {
if (!useSlotMode.value) return null
return slotSteps.value[currentStepIndex.value] || null
})
const currentStepContent = computed(() => {
if (useSlotMode.value) return ''
const step = currentStepData.value
if (!step) return ''
if (!step.title) {
return `<p>${step.content}</p>`
}
return `
<h3 class="text-lg font-bold mb-2">${step.title}</h3>
<div class="leading-relaxed">${step.content}</div>
`
})
const handleNext = () => {
const maxSteps = useSlotMode.value ? slotSteps.value.length : props.steps.length
if (maxSteps === 0) {
handleComplete()
return
}
if (currentStepIndex.value < maxSteps - 1) {
currentStepIndex.value++
emit('step-change', currentStepData.value, currentStepIndex.value)
} else {
handleComplete()
}
}
const handleSkip = () => {
handleComplete()
}
const handleComplete = () => {
show.value = false
emit('complete')
}
const goToStep = (index: number) => {
const maxSteps = useSlotMode.value ? slotSteps.value.length : props.steps.length
if (maxSteps === 0) {
console.warn('GuideSteps goToStep: No steps available')
return
}
if (index >= 0 && index < maxSteps) {
currentStepIndex.value = index
emit('step-change', currentStepData.value, currentStepIndex.value)
} else {
console.warn('GuideSteps goToStep: Invalid step index', index, 'max:', maxSteps - 1)
}
}
const resetGuide = () => {
currentStepIndex.value = 0
show.value = true
}
// 键盘导航
const handleKeydown = (event: KeyboardEvent) => {
if (!props.keyboardNavigation || !show.value) return
switch (event.key) {
case 'ArrowRight':
case ' ':
event.preventDefault()
handleNext()
break
case 'ArrowLeft':
event.preventDefault()
if (currentStepIndex.value > 0) {
currentStepIndex.value--
emit('step-change', currentStepData.value, currentStepIndex.value)
}
break
case 'Escape':
event.preventDefault()
handleSkip()
break
}
}
// 自动播放
let autoPlayTimer: number | null = null
const startAutoPlay = () => {
if (props.autoPlayInterval > 0) {
autoPlayTimer = window.setInterval(() => {
const maxSteps = useSlotMode.value ? slotSteps.value.length : props.steps.length
if (currentStepIndex.value < maxSteps - 1) {
handleNext()
} else {
stopAutoPlay()
handleComplete()
}
}, props.autoPlayInterval)
}
}
const stopAutoPlay = () => {
if (autoPlayTimer) {
clearInterval(autoPlayTimer)
autoPlayTimer = null
}
}
// 生命周期
onMounted(() => {
document.addEventListener('keydown', handleKeydown)
if (props.autoStart && props.autoPlayInterval > 0) {
startAutoPlay()
}
})
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown)
stopAutoPlay()
})
defineExpose({
goToStep,
resetGuide,
currentStep,
totalSteps,
startAutoPlay,
stopAutoPlay
})
</script>
<style scoped>
.guide-steps-container {
@apply w-full h-full relative;
}
</style>
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff. Show more