Skip to content

组件文档

项目通过 uni-app 的 easycom 机制自动注册了 13 个通用组件,使用时无需手动 import。另有 5 个 Layout 组件按需引入。

1. easycom 自动注册

以特定前缀命名的组件会自动识别并注册:

  • ^TabBar@/components/common/TabBar.vue
  • ^LifeLayout@/components/common/LifeLayout.vue
  • ^LifeModal@/components/common/LifeModal.vue
  • ^LifeButton@/components/common/LifeButton.vue
  • ^LifeHeader@/components/common/LifeHeader.vue
  • ^LifeEmpty@/components/common/LifeEmpty.vue
  • ^LifeField@/components/common/LifeField.vue
  • ^EmptyState@/components/common/EmptyState.vue
  • ^LoadingSpinner@/components/common/LoadingSpinner.vue
  • ^PageHeader@/components/common/PageHeader.vue
  • ^DynamicForm@/components/common/DynamicForm.vue

注:DashboardViewMagicView 的 easycom 映射无效,其对应文件不存在。实际使用时通过显式 import 从页面目录引入。


2. 布局组件

LifeLayout

通用页面布局容器,自动撑满视口。

Props

属性类型默认值说明
bgstring背景色
safeBottombooleanfalse为底部 TabBar 留白
showFabbooleanfalse显示浮动操作按钮
fabColorstringvar(--color-primary)FAB 颜色

Events

事件说明
fabClick浮动按钮点击

Slots

插槽说明
default主内容区
top顶部区域(放置 PageHeader)

使用示例

vue
<LifeLayout safe-bottom show-fab @fab-click="handleAdd">
  <template #top>
    <PageHeader title="任务列表" />
  </template>
  <view>内容区域</view>
</LifeLayout>

TabBar

底部导航栏占位组件,内部根据 pages.json 的原生 TabBar 配置自动工作。5 个 Tab:首页、任务、功能、日程、我的。无对外 Props/Events。


3. 导航组件

页面头部栏,支持返回、标题、右侧操作。

Props

属性类型默认值说明
titlestring必填标题
subtitlestring副标题
showBackbooleantrue显示返回按钮
backTextstring返回按钮文字
bgColorstringvar(--color-bg)背景色
rightIconstring右侧图标(文字/emoji)
rightBgstring右侧按钮背景
rightColorstring右侧按钮颜色

Events

事件说明
back返回按钮点击(未监听时自动 navigateBack
rightClick右侧图标按钮点击

Slots

插槽说明
left返回按钮右侧自定义内容
right右侧自定义内容(覆盖 rightIcon

使用示例

vue
<PageHeader
  title="设置"
  right-icon="⚙"
  @back="handleBack"
  @right-click="openSettings"
/>

LifeHeader

简化版头部组件,功能与 PageHeader 类似但更轻量。

Props

属性类型默认值说明
titlestring必填标题
subtitlestring副标题
showBackboolean显示返回按钮
headerBgstringvar(--color-bg)背景色

Events

事件说明
back返回按钮点击(需父组件手动 navigateBack

Slotsright — 右侧自定义内容。


4. 表单组件

LifeField

单个表单字段组件,根据 type 自动渲染不同控件。

Props

属性类型默认值说明
modelValueanyv-model 绑定值
typeenumtext控件类型(见下方表格)
labelstring标签文字
placeholderstring占位文字
requiredbooleanfalse显示必填标记 *
optionsstring[]select 类型的选项
textareaHeightstring160rpxtextarea 高度
hintstring底部提示(红色)

type 取值

渲染控件
text单行文本输入
number数字输入(系统数字键盘)
password密码输入(掩码显示)
textarea多行文本域
date日期选择器
select单选标签组
toggle开关

使用示例

vue
<LifeField
  v-model="name"
  type="text"
  label="姓名"
  required
  placeholder="请输入姓名"
  hint="至少 2 个字符"
/>

DynamicForm

动态表单组件,通过 fields 配置数组驱动渲染,支持 13 种字段类型。

Props

属性类型默认值说明
modelValueRecord<string, any>必填v-model 绑定的表单数据
fieldsFieldConfig[]必填字段配置数组
gapnumber0行间距 (px)

字段类型text / number / textarea / select / multi-select / emoji / color / toggle / date / time / stepper / star / slot

FieldConfig 结构

属性类型说明
keystring字段 key,对应 modelValue 的属性
typeFieldType字段类型
labelstring标签文字
labelIconstring标签图标
placeholderstring占位文字
requiredboolean是否必填
optionsFieldOption[]select/emoji/color 的选项列表
textareaHeightstringtextarea 高度
showSecondsbooleantime 类型是否显示秒
min / maxnumberstepper 的数值范围
stepnumberstepper 步长
disabledboolean禁用
suffixFieldSuffix后缀按钮配置
slotNamestringslot 类型的插槽名

使用示例

vue
<DynamicForm
  v-model="formData"
  :fields="[
    { key: 'name', type: 'text', label: '姓名', required: true },
    { key: 'priority', type: 'select', label: '优先级', options: [
      { label: '高', value: 'high' },
      { label: '中', value: 'medium' },
      { label: '低', value: 'low' }
    ]},
    { key: 'dueDate', type: 'date', label: '截止日期' },
    { key: 'rating', type: 'star', label: '重要程度', max: 5 },
    { key: 'notify', type: 'toggle', label: '提醒' }
  ]"
/>

5. 反馈组件

LifeModal

底部弹出式模态框。

Props

属性类型默认值说明
visibleboolean必填是否显示
titlestring弹窗标题
maxHeightstring85vh最大高度
heightstringauto固定高度
scrollablebooleanfalse内容可滚动
dragBarbooleantrue显示拖拽条
closeBtnbooleantrue显示关闭按钮

Eventsclose — 点击遮罩或关闭按钮时触发。

使用示例

vue
<LifeModal visible title="添加任务" @close="showModal = false">
  <DynamicForm v-model="form" :fields="fields" />
  <LifeButton label="提交" variant="primary" block @click="submit" />
</LifeModal>

LifeButton

通用按钮,支持 3 种变体。

Props

属性类型默认值说明
labelstring按钮文字
variantenumprimary / ghost / danger
blockbooleanfalse占满宽度
activebooleanfalse高亮激活态
disabledbooleanfalse禁用(不触发 click)
gradientstring激活态渐变背景
smbooleanfalse小尺寸
lgbooleanfalse大尺寸

使用示例

vue
<LifeButton label="完成" variant="primary" block @click="save" />
<LifeButton label="取消" variant="ghost" @click="cancel" />
<LifeButton label="删除" variant="danger" sm @click="remove" />

LoadingSpinner

加载动画。

Props

属性类型默认值说明
textstring加载中…提示文字
sizestring32px转圈尺寸

使用示例

vue
<LoadingSpinner text="AI 思考中…" size="48px" />

6. 状态组件

LifeEmpty

空状态占位,居中图标 + 文字布局。

Props

属性类型默认值说明
iconstring图标(emoji/文字)
textstring提示文字
paddingTopstring160rpx上边距(rpx)
iconSizestring96rpx图标字号

EmptyState

空状态占位(与 LifeEmpty 类似,上边距单位为 px,文字有宽度限制)。

Props

属性类型默认值说明
iconstring图标(emoji/文字)
textstring提示文字
paddingTopstring80px上边距(px)
iconSizestring96rpx图标字号

使用示例

vue
<LifeEmpty icon="📝" text="还没有任务,点击下方创建" />
<EmptyState icon="🔍" text="未找到结果" />

7. Layout 组件(非 easycom,需手动 import)

组件路径说明
Layout@/components/Layout/Layout.vue页面外层容器
StatusBar@/components/Layout/StatusBar.vue状态栏高度适配
BottomBar@/components/Layout/BottomBar.vue底部安全区适配
BioAuthOverlay@/components/common/BioAuthOverlay.vue生物认证全屏解锁
DashboardView@/pages/dashboard/index.vue首页仪表盘(页面组件)
MagicView@/pages/magic/index.vue快捷操作面板(页面组件)