forked from ishareme/vue3-front-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(project): add Message fuc download fullscreen guide
- Loading branch information
Showing
16 changed files
with
364 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { h, render } from 'vue'; | ||
import messageComponent from './index.vue'; | ||
|
||
export const Message = (type, content, duration = 3000) => { | ||
/** | ||
* 动画结束时的回调 | ||
*/ | ||
const onDestroy = () => { | ||
// 3. message 销毁 | ||
render(null, document.body); | ||
}; | ||
|
||
// 1. 返回 vnode | ||
const vnode = h(messageComponent, { | ||
type, | ||
content, | ||
duration, | ||
destroy: onDestroy, | ||
}); | ||
// 2. render | ||
render(vnode, document.body); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<template> | ||
<transition name="down" @after-leave="destroy"> | ||
<div | ||
v-show="isVisable" | ||
class="min-w-[420px] fixed top-[20px] left-[50%] translate-x-[-50%] z-50 flex items-center px-3 py-1.5 rounded-sm border cursor-pointer" | ||
:class="styles[type].containerClass" | ||
> | ||
<m-svg-icon | ||
:name="styles[type].icon" | ||
:fillClass="styles[type].fillClass" | ||
class="h-1.5 w-1.5 mr-1.5" | ||
/> | ||
<span class="text-sm" :class="styles[type].textClass"> | ||
{{ content }} | ||
</span> | ||
</div> | ||
</transition> | ||
</template> | ||
|
||
<script> | ||
import mSvgIcon from '../SvgIcon/index.vue'; | ||
/** | ||
* 消息类型可选项 | ||
*/ | ||
const typeEnum = ['success', 'warn', 'error']; | ||
</script> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue'; | ||
const props = defineProps({ | ||
/** | ||
* message 的消息类型 | ||
*/ | ||
type: { | ||
type: String, | ||
required: true, | ||
validator(val) { | ||
const result = typeEnum.includes(val); | ||
if (!result) { | ||
throw new Error(`type 必须是 ${typeEnum.join('、')} 中的一个`); | ||
} | ||
return result; | ||
}, | ||
}, | ||
/** | ||
* 描述文本 | ||
*/ | ||
content: { | ||
type: String, | ||
required: true, | ||
}, | ||
/** | ||
* 展示时长 | ||
*/ | ||
duration: { | ||
type: Number, | ||
}, | ||
/** | ||
* 关闭时的回调 | ||
*/ | ||
destroy: { | ||
type: Function, | ||
}, | ||
}); | ||
// 样式表数据 | ||
const styles = { | ||
// 警告 | ||
warn: { | ||
icon: 'warn', | ||
fillClass: 'fill-warn-300', | ||
textClass: 'text-warn-300', | ||
containerClass: | ||
'bg-warn-100 border-warn-200 hover:shadow-lg hover:shadow-warn-100', | ||
}, | ||
// 错误 | ||
error: { | ||
icon: 'error', | ||
fillClass: 'fill-error-300', | ||
textClass: 'text-error-300', | ||
containerClass: | ||
'bg-error-100 border-error-200 hover:shadow-lg hover:shadow-error-100', | ||
}, | ||
// 成功 | ||
success: { | ||
icon: 'success', | ||
fillClass: 'fill-success-300', | ||
textClass: 'text-success-300', | ||
containerClass: | ||
'bg-success-100 border-success-200 hover:shadow-lg hover:shadow-success-100', | ||
}, | ||
}; | ||
// 控制显示处理 | ||
const isVisable = ref(false); | ||
/** | ||
* 保证动画展示,需要在 mounted 之后进行展示 | ||
*/ | ||
onMounted(() => { | ||
isVisable.value = true; | ||
/** | ||
* 延迟时间关闭 | ||
*/ | ||
setTimeout(() => { | ||
isVisable.value = false; | ||
}, props.duration); | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.down-enter-active, | ||
.down-leave-active { | ||
transition: all 0.5s; | ||
} | ||
.down-enter-from, | ||
.down-leave-to { | ||
opacity: 0; | ||
transform: translate3d(-50%, -100px, 0); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.