UI框架-通知组件

UI框架-通知组件

介绍

一个基于 Vue 3 的轻量级通知组件库,提供了丰富的消息通知功能。支持多种通知类型、自定义样式、进度条显示等特性。

特性

  • 🎨 支持多种通知类型:信息、成功、警告、错误
  • ⏳ 支持进度条显示
  • 🔄 支持加载中状态
  • ⚙️ 可自定义显示时长
  • 🎯 支持手动关闭
  • 💫 优雅的动画效果
  • 📱 响应式设计

安装

npm install bbyh-ui-notifaction

使用方法

基础用法

import { showNotification } from 'bbyh-ui-notifaction'// 显示基础通知
showNotification({type: 'info',title: '提示',message: '这是一条消息通知'
})

不同类型

// 成功提示
showNotification({type: 'success',title: '成功',message: '操作成功完成!',icon: '✅'
})// 警告提示
showNotification({type: 'warning',title: '警告',message: '请注意这个警告信息!',icon: '⚠️'
})// 错误提示
showNotification({type: 'error',title: '错误',message: '操作失败,请重试!',icon: '❌'
})

进度条

showNotification({type: 'info',title: '文件上传中',message: '正在上传文件,请勿关闭窗口...',progress: true,duration: 5000
})

加载中状态

const notification = showNotification({type: 'info',title: '加载中',message: '正在处理,请稍候...',loading: true,duration: 0
})// 手动关闭
setTimeout(() => {notification.close()
}, 3000)

API

Options

参数说明类型默认值
type通知类型‘info’ | ‘success’ | ‘warning’ | ‘error’‘info’
title标题string-
message消息内容string-
duration显示时间(毫秒),设为 0 则不会自动关闭number4500
icon自定义图标stringnull
progress是否显示进度条booleanfalse
loading是否显示加载动画booleanfalse
controlProgress是否手动控制进度booleanfalse
progressValue进度条初始值number100

方法

方法名说明参数
close关闭当前通知-
setProgress设置进度条值value: number

源码下载

UI框架-通知组件

npm仓库

UI框架-通知组件

核心代码

code/src/components/Notification.vue

<template><div class="ui-notification" :class="['ui-notification--' + type, { 'is-closing': closing }]" ref="notification"><div class="ui-notification__icon"><span v-if="icon">{{ icon }}</span><span v-else-if="loading" class="ui-notification__loading"></span></div><div class="ui-notification__content"><h4 class="ui-notification__title">{{ title }}</h4><p class="ui-notification__message">{{ message }}</p></div><span class="ui-notification__close" @click="close">×</span><div v-if="progress" class="ui-notification__progress" :style="{ width: progressWidth + '%' }"></div></div>
</template><script setup>
import {defineExpose, defineProps, onMounted, ref} from "vue";const props = defineProps({type: {type: String,default: "info",},title: {type: String,required: true,},message: {type: String,required: true,},icon: {type: String,default: null,},duration: {type: Number,default: 4500,},progress: {type: Boolean,default: false,},controlProgress: {type: Boolean,default: false,},progressValue: {type: Number,default: 100,},loading: {type: Boolean,default: false,},
});const notification = ref();
const closing = ref(false);
const progressWidth = ref(props.progressValue);onMounted(() => {if (props.controlProgress) {if (props.progress) {if (props.duration > 0) {const interval = setInterval(() => {progressWidth.value -= 1;if (progressWidth.value <= 0) {clearInterval(interval);}}, props.duration / 100);}}} else {if (props.duration > 0) {setTimeout(() => close(), props.duration);}if (props.progress) {const interval = setInterval(() => {progressWidth.value -= 1;if (progressWidth.value <= 0) {clearInterval(interval);close();}}, props.duration / 100);}}
});function close() {closing.value = true;setTimeout(() => {notification.value.parentElement.remove();}, 300);
}function setProgress(value) {progressWidth.value = value;
}defineExpose({close,setProgress
});
</script><style>
/* 定义根变量 */
:root {/* 主题色 */--primary-color: #409eff;--success-color: #67c23a;--warning-color: #e6a23c;--danger-color: #f56c6c;--info-color: #909399;--error-color: #f56c6c;/* 文字颜色 */--text-primary: #303133;--text-regular: #606266;--text-secondary: #909399;--text-placeholder: #c0c4cc;/* 边框颜色 */--border-color: #dcdfe6;--border-light: #e4e7ed;--border-lighter: #ebeef5;/* 背景颜色 */--background-color: #ffffff;--background-hover: #f5f7fa;/* 字体大小 */--font-size-large: 18px;--font-size-medium: 16px;--font-size-base: 14px;--font-size-small: 13px;--font-size-mini: 12px;/* 边框圆角 */--border-radius-base: 4px;--border-radius-small: 2px;--border-radius-round: 20px;--border-radius-circle: 100%;
}/* 通知容器 */
.ui-notification-container {position: fixed;z-index: 9999;display: flex;flex-direction: column;gap: 12px;padding: 16px;
}.ui-notification-container--top-right {top: 0;right: 0;
}.ui-notification-container--top-left {top: 0;left: 0;
}.ui-notification-container--bottom-right {bottom: 0;right: 0;
}.ui-notification-container--bottom-left {bottom: 0;left: 0;
}/* 通知项 */
.ui-notification {min-width: 300px;max-width: 400px;padding: 16px;border-radius: var(--border-radius-base);background-color: var(--background-color);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);display: flex;align-items: flex-start;position: relative;animation: notification-in 0.3s ease-out;
}.ui-notification.is-closing {animation: notification-out 0.3s ease-in forwards;
}/* 通知类型样式 */
.ui-notification--info {border-left: 4px solid var(--primary-color);
}.ui-notification--success {border-left: 4px solid var(--success-color);
}.ui-notification--warning {border-left: 4px solid var(--warning-color);
}.ui-notification--error {border-left: 4px solid var(--error-color);
}/* 通知图标 */
.ui-notification__icon {margin-right: 16px;font-size: 24px;
}.ui-notification--info .ui-notification__icon {color: var(--primary-color);
}.ui-notification--success .ui-notification__icon {color: var(--success-color);
}.ui-notification--warning .ui-notification__icon {color: var(--warning-color);
}.ui-notification--error .ui-notification__icon {color: var(--error-color);
}/* 通知内容 */
.ui-notification__content {flex: 1;
}.ui-notification__title {font-size: var(--font-size-large);font-weight: 500;margin: 0 0 8px;color: var(--text-primary);
}.ui-notification__message {font-size: var(--font-size-base);color: var(--text-regular);margin: 0;
}/* 关闭按钮 */
.ui-notification__close {position: absolute;top: 16px;right: 16px;font-size: 16px;color: var(--text-secondary);cursor: pointer;transition: color 0.3s;
}.ui-notification__close:hover {color: var(--text-regular);
}/* 进度条 */
.ui-notification__progress {position: absolute;bottom: 0;left: 0;height: 2px;background-color: var(--primary-color);transition: width 0.3s linear;
}/* 动画 */
@keyframes notification-in {from {transform: translateX(100%);opacity: 0;}to {transform: translateX(0);opacity: 1;}
}@keyframes notification-out {from {transform: translateX(0);opacity: 1;}to {transform: translateX(100%);opacity: 0;}
}/* 加载中动画 */
.ui-notification__loading {display: inline-block;width: 24px;height: 24px;border: 2px solid currentColor;border-top-color: transparent;border-radius: 50%;animation: notification-loading 0.8s infinite linear;
}@keyframes notification-loading {to {transform: rotate(360deg);}
}
</style>

code/src/components/NotificationManager.js

import {createApp} from "vue";
import Notification from "./Notification.vue";let container;function getContainer() {if (!container) {container = document.createElement("div");container.className = "ui-notification-container ui-notification-container--top-right";document.body.appendChild(container);}return container;
}export function showNotification(options) {const app = createApp(Notification, options);const wrapper = document.createElement("div");app.mount(wrapper);getContainer().appendChild(wrapper);return app._instance.exposed;
}

效果展示

示例页面
在这里插入图片描述

普通消息提示
在这里插入图片描述

加载消息提示
在这里插入图片描述

进度消息提示
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/news/908978.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WordZero:让Markdown与Word文档自由转换的Golang利器

在日常工作中&#xff0c;我们经常需要在Markdown和Word文档之间进行转换。Markdown方便编写和版本控制&#xff0c;而Word文档更适合正式的商务环境。作为一名Golang开发者&#xff0c;我开发了WordZero这个库&#xff0c;专门解决这个痛点。 项目背景 GitHub仓库&#xff1…

计算机网络面试汇总(完整版)

基础 1.说下计算机网络体系结构 计算机网络体系结构&#xff0c;一般有三种&#xff1a;OSI 七层模型、TCP/IP 四层模型、五层结构。 简单说&#xff0c;OSI是一个理论上的网络通信模型&#xff0c;TCP/IP是实际上的网络通信模型&#xff0c;五层结构就是为了介绍网络原理而折…

动端React表格组件:支持合并

前言 在移动端开发中&#xff0c;表格组件是一个常见但复杂的需求。相比PC端&#xff0c;移动端表格面临着屏幕空间有限、交互方式不同、性能要求更高等挑战。本文将详细介绍如何从零开始构建一个功能完整的移动端React表格组件&#xff0c;包含固定列、智能单元格合并、排序等…

广告系统中后链路数据为什么要使用流批一体技术?流批一体技术是什么?

在大规模广告系统的后链路(离线和实时特征计算、模型训练与上线、效果监控等)中,往往既有对海量历史数据的批量计算需求(离线特征、离线模型训练、报表汇总),又有对在线请求的低延迟实时计算需求(实时特征、在线打分、实时监控/告警)。传统将二者割裂、用 Lambda 架构…

6.10 - 常用 SQL 语句以及知识点

MySQL 技术 SQL 是结构化查询语言&#xff0c;他是关系型数据库的通用语言 SQL 可以分为分为以下三个类别 DDL (data definition languages) 语句 数据定义语言&#xff0c;定义了 不同的数据库、表、索引等数据库对象的定义。常用的的语句关键字包括 **create、drop、alter …

OpenCV CUDA 模块光流计算------稀疏光流算法类SparsePyrLKOpticalFlow

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 OpenCV CUDA 模块中实现的稀疏光流算法类&#xff0c;基于 Lucas-Kanade 方法&#xff0c;并支持图像金字塔结构。适用于特征点跟踪任务&#xf…

免费工具-微软Bing Video Creator

目录 引言 一、揭秘Bing Video Creator 二、轻松上手&#xff1a;三步玩转Bing Video Creator 2.1 获取与访问&#xff1a; 2.2 创作流程&#xff1a; 2.3 提示词撰写技巧——释放AI的想象力&#xff1a; 三、核心特性详解&#xff1a;灵活满足多样化需求 3.1 双重使用模…

MySQL技术内幕1:内容介绍+MySQL编译使用介绍

文章目录 1.整体内容介绍2.下载编译流程2.1 安装编译工具和依赖库2.2 下载编译 3.配置MySQL3.1 数据库初始化3.2 编辑配置文件3.3 启动停止MySQL3.4 登录并修改密码 1.整体内容介绍 MySQL技术系列文章将从MySQL下载编译&#xff0c;使用到MySQL各组件使用原理源码分析&#xf…

MySQL 事务详解

MySQL 事务详解 一、事务是什么&#xff1f;为什么需要事务&#xff1f; 二、事务的四大特性&#xff08;ACID&#xff09;举例说明&#xff1a;转账操作 三、MySQL 中事务的支持四、事务分类&#xff1a;隐式 vs 显式1. 隐式事务&#xff08;自动提交&#xff09;2. 显式事务&…

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…

利用coze工作流制作一个自动生成PPT的智能体

在Coze平台中&#xff0c;通过工作流实现PPT自动化生成是一个高效且灵活的解决方案&#xff0c;尤其适合需要快速产出标准化演示文稿的场景。以下是基于Coze工作流制作PPT的核心逻辑与操作建议&#xff1a; 理论流程 一、核心流程设计 需求输入与解析 用户输入&#xff1a;主…

vue3 按钮级别权限控制

在Vue 3中实现按钮级别的权限控制&#xff0c;可以通过多种方式实现。这里我将介绍几种常见的方法&#xff1a; 方法1&#xff1a;使用Vue 3的Composition API 在Vue 3中&#xff0c;你可以使用Composition API来创建一个可复用的逻辑来处理权限控制。 创建权限控制逻辑 首…

spa首屏加载慢怎样解决

SPA&#xff08;Single Page Application&#xff0c;单页应用&#xff09;首屏加载慢是一个常见问题&#xff0c;主要原因通常是首次加载需要拉取体积较大的 JavaScript 文件、样式表、初始化数据等。以下是一些常见的 优化策略&#xff0c;可以帮助你 提升首屏加载速度&#…

UE5 音效系统

一.音效管理 音乐一般都是WAV,创建一个背景音乐类SoudClass,一个音效类SoundClass。所有的音乐都分为这两个类。再创建一个总音乐类&#xff0c;将上述两个作为它的子类。 接着我们创建一个音乐混合类SoundMix&#xff0c;将上述三个类翻入其中&#xff0c;通过它管理每个音乐…

2.Vue编写一个app

1.src中重要的组成 1.1main.ts // 引入createApp用于创建应用 import { createApp } from "vue"; // 引用App根组件 import App from ./App.vue;createApp(App).mount(#app)1.2 App.vue 其中要写三种标签 <template> <!--html--> </template>…

NTT印地赛车:数字孪生技术重构赛事体验范式,驱动观众参与度革命

引言&#xff1a;数字孪生技术赋能体育赛事&#xff0c;开启沉浸式观赛新纪元 在传统体育赛事观赛模式遭遇体验天花板之际&#xff0c;NTT与印地赛车系列赛&#xff08;NTT INDYCAR SERIES&#xff09;的深度合作&#xff0c;通过数字孪生&#xff08;Digital Twin&#xff09…

解构与重构:PLM 系统如何从管理工具进化为创新操作系统?

在智能汽车、工业物联网等新兴领域的冲击下&#xff0c;传统产品生命周期管理&#xff08;PLM&#xff09;系统正在经历前所未有的范式转换。当某头部车企因 ECU 软件与硬件模具版本失配导致 10 万辆智能电车召回&#xff0c;损失高达 6 亿美元时&#xff0c;这场危机不仅暴露了…

【Ubuntu 16.04 (Xenial)​​】安装docker及容器详细教程

Ubuntu 16.04 安装docker详细教程 一、docker安装1.1 前期准备1.2 使用 Docker 官方安装脚本安装&#xff08;推荐&#xff09; 查看ubuntu版本&#xff1a;lsb_release -a 这里我的系统是 ​​Ubuntu 16.04 (Xenial)​​&#xff0c;在 ​​Ubuntu 16.04 (Xenial)​​ 上安装…

.Net框架,除了EF还有很多很多......

文章目录 1. 引言2. Dapper2.1 概述与设计原理2.2 核心功能与代码示例基本查询多映射查询存储过程调用 2.3 性能优化原理2.4 适用场景 3. NHibernate3.1 概述与架构设计3.2 映射配置示例Fluent映射XML映射 3.3 查询示例HQL查询Criteria APILINQ提供程序 3.4 高级特性3.5 适用场…

MySQL:InnoDB架构(内存架构篇)

目录 0.前置知识 0.1二级索引的概念 二级索引查询原理 1.整体架构 1.1为什么innoDB的架构会分为两个部分? 2.内存架构 2.1BufferPool 2.2ChangeBuffer 唯一性检查不是实时性会出现的问题? ChangeBuffer的优势 2.3Adaptive Hash Index 2.4LogBuffer 0.前置知识 0.…