Appearance
xtf-notify
组件说明
xtf-notify 是顶部通知,用于展示可堆叠的全局状态通知。当前实现读取 items 数据、通过 close 等事件反馈交互、提供实例方法。
- 实际 Demo 路由:
#/pages/components/xtf-notify/index - Demo 源码
基础用法
1. 最小可用
提供能够直接看到或操作组件的最少业务内容。
vue
<template>
<view class="doc-minimum">
<XtfNotify :items="fixture" />
</view>
</template>
<script setup lang="uts">
import XtfNotify from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/xtf-notify.uvue"
const fixture = [{ id: 'sync', title: '同步完成', message: '账单已更新', type: 'success' }] as Array<any>
</script>
<style>
.doc-minimum { display: flex; flex-direction: column; padding: 24rpx; }
</style>2. 核心数据与主要事件
使用组件真实数据入口,并记录当前源码声明的主要事件。
vue
<template>
<view class="doc-core">
<XtfNotify :items="fixture" @close="onPrimaryEvent" />
</view>
</template>
<script setup lang="uts">
import XtfNotify from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/xtf-notify.uvue"
const fixture = [{ id: 'sync', title: '同步完成', message: '账单已更新', type: 'success' }] as Array<any>
function onPrimaryEvent(payload: any): void { console.log("xtf-notify:close", payload) }
</script>
<style>
.doc-core { display: flex; flex-direction: column; padding: 24rpx; }
</style>3. 动态 service 状态
运行时切换 service,观察组件对应状态变化。
vue
<template>
<view class="doc-dynamic">
<XtfNotify :items="fixture" :service="state" />
<button class="doc-action-button" @click="toggleState">切换 service</button>
<text class="doc-state-text">service: {{ state }}</text>
</view>
</template>
<script setup lang="uts">
import XtfNotify from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/xtf-notify.uvue"
import { ref } from "vue"
const fixture = [{ id: 'sync', title: '同步完成', message: '账单已更新', type: 'success' }] as Array<any>
const state = ref(false)
function toggleState(): void { state.value = !state.value; console.log("service", state.value) }
</script>
<style>
.doc-dynamic { display: flex; flex-direction: column; padding: 24rpx; }
.doc-action-button { margin-top: 16rpx; }
.doc-state-text { margin-top: 12rpx; color: #475569; font-size: 24rpx; }
</style>4. 调用 clear()
清空内容;签名为 clear(): void。
vue
<template>
<view class="doc-method">
<XtfNotify :items="fixture" ref="componentRef" />
<button class="doc-action-button" @click="callMethod">清空内容</button>
</view>
</template>
<script setup lang="uts">
import XtfNotify from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/xtf-notify.uvue"
import { ref } from "vue"
const fixture = [{ id: 'sync', title: '同步完成', message: '账单已更新', type: 'success' }] as Array<any>
const componentRef = ref<any>(null)
function callMethod(): void { componentRef.value?.clear(); console.log("调用 clear") }
</script>
<style>
.doc-method { display: flex; flex-direction: column; padding: 24rpx; }
.doc-action-button { margin-top: 16rpx; }
</style>5. Manager 服务调用
先挂载 service 宿主,再调用对应 manager 的实际显示 API。
vue
<template>
<view class="doc-service">
<XtfNotify :items="fixture" service />
<button class="doc-action-button" @click="openService">服务式调用</button>
</view>
</template>
<script setup lang="uts">
import { notifyManager } from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/service.uts"
import XtfNotify from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/xtf-notify.uvue"
const fixture = [{ id: 'sync', title: '同步完成', message: '账单已更新', type: 'success' }] as Array<any>
function openService(): void { notifyManager.success('账单已保存'); console.log("notifyManager 已调用") }
</script>
<style>
.doc-service { display: flex; flex-direction: column; padding: 24rpx; }
.doc-action-button { margin-top: 16rpx; }
</style>全部属性
| 属性 | 源码类型 | withDefaults 默认值 | 实际行为 / 范围 | 适用范围 |
|---|---|---|---|---|
service | boolean | false | 参与组件运行逻辑;源码在 7 处读取该值;消费位置:script 行 14、script 行 49、script 行 60、script 行 64 | 需要控制显示、可用性或交互状态时设置。 |
items | NotifyItem[] | () => [] as NotifyItem[] | 参与组件运行逻辑;源码在 3 处读取该值;消费位置:script 行 26、script 行 97、script 行 100 | 数据驱动或选项渲染场景。 |
top | number | 24 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 28 | 需要覆盖组件默认业务值时设置。 |
bottom | number | 24 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 28 | 需要覆盖组件默认业务值时设置。 |
placement | "top" | "bottom" | "top" | 参与组件运行逻辑;源码在 5 处读取该值;可选值:top / bottom;消费位置:script 行 25、script 行 27、script 行 28、script 行 30 | 需要覆盖组件默认业务值时设置。 |
variant | "solid" | "soft" | "outline" | "solid" | 参与组件运行逻辑;源码在 1 处读取该值;可选值:solid / soft / outline;消费位置:script 行 25 | 需要调整布局或视觉表现时设置。 |
shape | "rounded" | "pill" | "tile" | "rounded" | 参与组件运行逻辑;源码在 1 处读取该值;可选值:rounded / pill / tile;消费位置:script 行 25 | 需要覆盖组件默认业务值时设置。 |
align | "left" | "center" | "left" | 参与组件运行逻辑;源码在 2 处读取该值;可选值:left / center;消费位置:script 行 25、script 行 27 | 需要调整布局或视觉表现时设置。 |
gap | number | 16 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 30 | 需要覆盖组件默认业务值时设置。 |
maxWidth | number | 0 | 设置对应区域宽度;消费位置:script 行 28 | 需要调整布局或视觉表现时设置。 |
showIcon | boolean | true | 设置对应区域的图标名称;消费位置:script 行 25 | 需要控制显示、可用性或交互状态时设置。 |
zIndex | number | 2060 | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 28 | 需要覆盖组件默认业务值时设置。 |
customClass | string | "" | 参与组件运行逻辑;源码在 1 处读取该值;消费位置:script 行 27 | 需要调整布局或视觉表现时设置。 |
customStyle | UTSJSONObject | () => ({} as UTSJSONObject) | 参与组件运行逻辑;源码在 2 处读取该值;消费位置:script 行 28 | 需要调整布局或视觉表现时设置。 |
NotifyItem 数据结构
| 字段 | 源码类型 | 字段语义 |
|---|---|---|
id | string | number | 数据标识 |
type | string | 类型标识 |
variant | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
shape | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
placement | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
align | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
title | string | 主标题 |
message | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
text | string | 显示文本 |
description | string | 补充说明 |
icon | string | 图标名称 |
showIcon | boolean | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
showProgress | boolean | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
actionText | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
actionTheme | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
duration | number | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
closeable | boolean | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
accentColor | string | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
offset | number | 源码声明的业务扩展字段;当前实现未提供更具体语义。 |
事件
| 事件名称 | 源码触发边界 | 回调参数 | 参数说明 |
|---|---|---|---|
close | close 内触发(script 行 48);参数表达式:id;前置 guard:disposed || !visibleItems.value.some((item: NormalizedItem) => item.id == id)clear 内触发(script 行 59);参数表达式:"";前置 guard:disposed、items.length == 0 | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
action | handleAction 内触发(script 行 63);参数表达式:item | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
click-item | handleItemClick 内触发(script 行 70);参数表达式:item | (...args: any[]) | 表中参数表达式来自当前源码直接调用点;禁用、守卫失败或未进入该函数分支时不会触发。 |
插槽
| 插槽 | Scope 参数 | 实际渲染位置 |
|---|---|---|
| - | - | 当前模板没有公开 slot。 |
方法
实例方法
| 方法 | 签名 / 返回值 | 调用边界 |
|---|---|---|
close | close(id: string): void | 请求关闭组件;通过组件 ref 调用,参数和返回值按签名处理。 |
clear | clear(): void | 清空内容;通过组件 ref 调用,参数和返回值按签名处理。 |
reschedule | reschedule(): void | 调用该公开实例能力;通过组件 ref 调用,参数和返回值按签名处理。 |
公开状态
| 状态 | 类型 / 包装 | 读取边界 |
|---|---|---|
| - | - | 当前组件没有公开状态。 |
Manager 宿主与导入
- 宿主:在页面中挂载
<XtfNotify service />。 - 导入:
import { notifyManager } from "@/uni_modules/xtf-linkuiunix/components/xtf-notify/service.uts"。 - 调用:基础用法中的 Manager 示例调用真实显示 API,而不是只读取
getState()。 - 返回:manager 返回当前状态快照或通知项,不是等待用户操作的 Promise;用户结果继续监听宿主事件。
- 相同 type/variant/title/message/description 在 240ms 内连续调用且旧项仍保留时会 dedup,返回同一保留通知项及其 id,可用 notifyManager.remove(id) 精确移除;它不是新通知句柄或 Promise。旧项已移除后再调用会创建新 id,notifyManager.clear() 清空全部通知并重置去重记录;只清理本页通知时应按持有的 id 调用 remove。
主题说明
var(--xtf-color-danger):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-danger-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-info):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-info-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-primary):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-primary-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-success):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-success-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-surface):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-warning):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-color-warning-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-notify-accent):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-notify-edge):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-notify-max-width):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。var(--xtf-notify-soft):组件样式实际读取的主题变量,可在xtf-config-provider作用域或主题 class 下覆盖。
平台与实现边界
- 基线为 HBuilderX 5.26+ 与 uni-app x;当前报告已验证 Web Chromium 的对应 Demo,不据此承诺 Safari、小程序或 App 原生端等价。
- Android、iOS、HarmonyOS、Vapor 原生路径、触摸手势、字体、Canvas、安全区和系统权限能力,只有源码或完整性报告明确覆盖的部分才可视为已验证。
- 本文按当前源码生成,不补入旧版
xtf-linkui存在但迁移版未实现的 props、事件、slot 或方法。 - 详细公共边界见 平台与实现边界,逐项运行证据见项目根目录 COMPONENT_COMPLETENESS.md。