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
繁體地址,請注明出處:http://hk.pswp.cn/news/908978.shtml
英文地址,請注明出處:http://en.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.…