Skip to content

CyberNotification 消息提示

消息提示组件提供了具有未来感的通知系统,适合在赛博朋克风格界面中展示各类通知信息。

基本用法

显示通知
vue
<template>
  <cyber-button @click="showNotification">显示通知</cyber-button>
  <cyber-notification ref="notificationRef" />
</template>

<script setup>
import { ref } from 'vue';

const notificationRef = ref(null);

const showNotification = () => {
  notificationRef.value?.info({
    title: '信息通知',
    message: '这是一条信息通知',
    duration: 3000
  });
};
</script>

不同类型

信息通知
成功通知
警告通知
错误通知
vue
<template>
  <cyber-button @click="showInfo">信息通知</cyber-button>
  <cyber-button @click="showSuccess">成功通知</cyber-button>
  <cyber-button @click="showWarning">警告通知</cyber-button>
  <cyber-button @click="showError">错误通知</cyber-button>
  <cyber-notification ref="notificationRef" />
</template>

<script setup>
import { ref } from 'vue';

const notificationRef = ref(null);

const showInfo = () => {
  notificationRef.value?.info({
    title: '信息通知',
    message: '这是一条信息通知'
  });
};

const showSuccess = () => {
  notificationRef.value?.success({
    title: '成功通知',
    message: '操作已成功完成'
  });
};

const showWarning = () => {
  notificationRef.value?.warning({
    title: '警告通知',
    message: '请注意可能的风险'
  });
};

const showError = () => {
  notificationRef.value?.error({
    title: '错误通知',
    message: '操作失败,请重试'
  });
};
</script>

不同位置

显示通知(右上角)
vue
<template>
  <cyber-notification position="top-right" />
  <cyber-notification position="top-left" />
  <cyber-notification position="bottom-right" />
  <cyber-notification position="bottom-left" />
  <cyber-notification position="center" />
</template>

不同效果

故障效果
全息效果
电路效果
vue
<template>
  <cyber-button @click="showGlitch">故障效果</cyber-button>
  <cyber-button @click="showHologram">全息效果</cyber-button>
  <cyber-button @click="showCircuit">电路效果</cyber-button>
  <cyber-notification ref="notificationRef" />
</template>

<script setup>
import { ref } from 'vue';

const notificationRef = ref(null);

const showGlitch = () => {
  notificationRef.value?.info({
    title: '故障效果',
    message: '这是故障效果通知',
    effect: 'glitch'
  });
};

const showHologram = () => {
  notificationRef.value?.info({
    title: '全息效果',
    message: '这是全息效果通知',
    effect: 'hologram'
  });
};

const showCircuit = () => {
  notificationRef.value?.info({
    title: '电路效果',
    message: '这是电路效果通知',
    effect: 'circuit'
  });
};
</script>

自定义持续时间

2秒后关闭
5秒后关闭
不自动关闭
vue
<template>
  <cyber-button @click="showWithDuration(2000)">2秒后关闭</cyber-button>
  <cyber-button @click="showWithDuration(5000)">5秒后关闭</cyber-button>
  <cyber-button @click="showWithDuration(0)">不自动关闭</cyber-button>
  <cyber-notification ref="notificationRef" />
</template>

<script setup>
import { ref } from 'vue';

const notificationRef = ref(null);

const showWithDuration = (duration) => {
  notificationRef.value?.info({
    title: '持续时间',
    message: duration === 0 ? '不会自动关闭' : `${duration / 1000}秒后关闭`,
    duration
  });
};
</script>

带操作按钮

显示带操作的通知
vue
<template>
  <cyber-button @click="showWithActions">显示带操作的通知</cyber-button>
  <cyber-notification ref="notificationRef" />
</template>

<script setup>
import { ref } from 'vue';

const notificationRef = ref(null);

const showWithActions = () => {
  notificationRef.value?.warning({
    title: '带操作按钮',
    message: '这条通知包含操作按钮',
    duration: 0,
    actions: [
      {
        text: '确认',
        callback: () => {
          console.log('点击了确认');
        }
      },
      {
        text: '取消',
        callback: () => {
          console.log('点击了取消');
        }
      }
    ]
  });
};
</script>

属性

属性名说明类型可选值默认值
position通知框位置stringtop-right / top-left / bottom-right / bottom-left / centertop-right
maxCount最大通知数量number10
duration默认显示时间(毫秒)number4500
effect默认效果stringglitch / hologram / circuitglitch

方法

方法名说明参数
info显示信息通知options
success显示成功通知options
warning显示警告通知options
error显示错误通知options
create创建自定义通知options
close关闭指定通知id
clearAll清除所有通知

通知选项

选项名说明类型可选值默认值
title通知标题string
message通知内容string
type通知类型stringinfo / success / warning / errorinfo
duration显示时间(毫秒),设为0则不会自动关闭number同组件的duration属性
showClose是否显示关闭按钮booleantrue
showIcon是否显示图标booleantrue
actions操作按钮数组Array<{text: string, callback: Function}>[]
effect通知效果stringglitch / hologram / circuit同组件的effect属性
onClose关闭时的回调函数Function

事件

事件名说明回调参数
close通知关闭时触发id: number

Relcased under the Mit Lincense.