Skip to content

为滑动验证组件添加动画效果 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions example/App.vue

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "go-captcha-vue",
"version": "2.0.6",
"name": "miharakinu-go-captcha-vue",
"version": "2.0.7",
"private": false,
"type": "module",
"license": "MIT",
"email": "wengaolng@gmail.com",
"author": "Awen <[email protected]>",
"email": "MiharaKinu1999@gmail.com",
"author": "MiharaKinu",
"description": "GoCaptcha of Vue, which implements click mode, slider mode, drag-drop mode and rotation mode.",
"keywords": [
"go-captcha-vue",
Expand All @@ -17,13 +17,13 @@
"gocapts"
],
"bugs": {
"url": "https://github.com/wenlng/go-captcha-vue/issues"
"url": "https://github.com/MiharaKinu/go-captcha-vue/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wenlng/go-captcha-vue.git"
"url": "git+https://github.com/MiharaKinu/go-captcha-vue.git"
},
"homepage": "https://github.com/wenlng/go-captcha-vue",
"homepage": "https://github.com/MiharaKinu/go-captcha-vue",
"main": "dist/go-captcha-vue.umd.js",
"module": "dist/go-captcha-vue.es.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -70,5 +70,8 @@
"vue": "^3.0.0",
"vite": "4.4.11",
"vue-tsc": "^2.0.11"
},
"dependencies": {
"caniuse-lite": "^1.0.30001717"
}
}
121 changes: 121 additions & 0 deletions packages/components/base/Tips.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<template>
<div
ref="notification"
class="notification"
:class="[typeClass, { show: isVisible }]"
>
{{ content }}
</div>
</template>

<script setup>
import { ref, computed, watch, onMounted } from 'vue'

const props = defineProps({
// 是否显示
show: {
type: Boolean,
default: false
},
// 显示内容
content: {
type: String,
default: ''
},
// 状态类型
type: {
type: String,
default: 'SUCCESS',
validator: (value) => ['SUCCESS', 'WARNING', 'ERROR'].includes(value)
},
// 自动关闭时间(毫秒),设为0则不自动关闭
duration: {
type: Number,
default: 1500
}
})

const emit = defineEmits(['update:show'])

const notification = ref(null)
const isVisible = ref(false)
let hideTimeout = null

const typeClass = computed(() => `notification-${props.type.toLowerCase()}`)

watch(
() => props.show,
(newVal) => {
if (newVal) {
showNotification()
} else {
hideNotification()
}
}
)

onMounted(() => {
if (props.show) {
showNotification()
}
})

function showNotification() {
clearTimeout(hideTimeout)
isVisible.value = true

if (props.duration > 0) {
hideTimeout = setTimeout(() => {
hideNotification()
}, props.duration)
}
}

function hideNotification() {
isVisible.value = false
emit('update:show', false)
}
</script>

<style lang="less">
.notification {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
color: white;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
font-size: 16px;
z-index: 1000;
padding: 2px;

opacity: 0;
visibility: hidden;
transform: translateY(100%);

transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55),
opacity 0.4s ease-in-out,
visibility 0s linear 0.5s;

&.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
transition-delay: 0s, 0s, 0s;
}

// 不同类型样式
&-success {
background-color: #34a853;
}

&-warning {
background-color: #fbbc05;
}

&-error {
background-color: #ea4335;
}
}
</style>
19 changes: 18 additions & 1 deletion packages/components/slide/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
</div>
<div
class="gc-body"
:class="`gc-body ${innerTips.type == 'SUCCESS' && innerTips.show ? 'shine-effect-tr-bl' : ''}`"
ref="containerRef"
:style="imageStyles"
>
Expand All @@ -35,6 +35,11 @@
:src="localData.image"
alt=""
/>
<Tips
v-model:show="innerTips.show"
:content="innerTips.content"
:type="innerTips.type"
/>
<div
class="gc-tile"
ref="tileRef"
Expand Down Expand Up @@ -82,6 +87,13 @@ import {defaultSlideData, SlideData} from "./meta/data";
import {SlideEvent} from "./meta/event";
import {SlideExpose} from "./meta/expose";
import {useHandler} from "./hooks/handler";
import Tips from "../base/Tips.vue";

const innerTips = reactive({
show: false,
content: '',
type: 'SUCCESS',
})

// @ts-ignore
const props = withDefaults(
Expand Down Expand Up @@ -197,6 +209,11 @@ defineExpose<SlideExpose>({
clear: handler.clearData,
refresh: handler.refresh,
close: handler.close,
setTips: (show: boolean, content: string, type: string) => {
innerTips.show = show
innerTips.content = content
innerTips.type = type
}
});
</script>

Expand Down
1 change: 1 addition & 0 deletions packages/components/slide/meta/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface SlideExpose {
clear: () => void,
refresh: () => void,
close: () => void,
setTips: (show: boolean, content: string, type: string) => void,
}
Loading