营销组件 / 砸金蛋 cu-bingo-hiteggs

cu-bingo-hiteggs

点中一枚金蛋后,锤子往返抖动、蛋壳裂开,奖品文字落定。一次只处理一枚,破壳态保持到重置。

新 App / H5
01 / Install

引入组件

营销组件放在独立模块 colorui-bingo 里,依赖 colorui-x 的主题 token;两个目录一并放进工程的 uni_modules/ 即可,easycom 按标签逐个解析,不写 import,也没有全局注册这一步。本仓不是 npm 包,不提供 npm 安装命令。

install
your-project/
└── uni_modules/
    ├── colorui-x/
    └── colorui-bingo/

<cu-bingo-hiteggs
    :prize-list="prizeList"
></cu-bingo-hiteggs>

奖品字段、活动与抽奖响应的示例见 数据与接口规范(仓库内 docs/01-交付与接入/Bingo-数据与接口规范.md)。组件本身不连后端,落点与结果由宿主决定。

02 / Platform

平台支持

能力App-AndroidH5 预览微信 / 支付宝小程序iOS
基础渲染 / 点击支持支持编译门未验收
JS ticker 动画支持支持编译门未验收
Canvas(转盘 / 刮卡)支持支持编译门未验收
真实摇一摇不支持(加速度计 API 不可用)可选 devicemotion,需 HTTPS / 权限未验收未验收
震动反馈不支持(类型层无 API)未验收未验收未验收
3D 翻转 / 3D 骰子不支持不支持(统一 2D)不支持不支持

「编译门」只表示已被编译流程覆盖,不构成真机渲染承诺;「未验收」不写支持。摇一摇的宿主接线见 平台与限制 与组件 05 段说明。

03 / Demo

代码演示

01

基础用法

给出奖品数据,接住开始与结果事件;完整字段见 04 段。

uvue
<cu-bingo-hiteggs
    :prize-list="prizeList"
    @hit="onHit"
    @start="onStart"
    @end="onEnd"
></cu-bingo-hiteggs>
02

程序控制

用 ref 拿到组件实例后直接调方法;签名与返回值见 04 段 Methods 表。

uvue
<cu-bingo-hiteggs ref="boardRef"     :prize-list="prizeList"></cu-bingo-hiteggs>

import type { CuBingoHiteggsComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-hiteggs/cu-bingo-hiteggs.uvue'

const boardRef = ref<CuBingoHiteggsComponentPublicInstance | null>(null)

function callStart(): void {
    const inst = boardRef.value
    if (inst == null) { return }
    inst.start()
}

function callReset(): void {
    const inst = boardRef.value
    if (inst == null) { return }
    inst.reset()
}
03

风格与主题

页面根节点挂主题类和 Bingo 风格类;风格 A–F 由 store/style.uts 切换。

uvue
<template>
  <view :class="'cu-page ' + themeClass + ' ' + styleClass">
    <cu-bingo-hiteggs    :prize-list="prizeList"></cu-bingo-hiteggs>
  </view>
</template>

<script setup lang="uts">
  import { cuThemeRootClass } from '../../uni_modules/colorui-x/store/theme.uts'
  import { cuBingoStyleRootClass, setBingoStyle } from '../../uni_modules/colorui-bingo/store/style.uts'

  const themeClass = computed((): string => cuThemeRootClass())
  const styleClass = computed((): string => cuBingoStyleRootClass())

  setBingoStyle('f') // a–f 六套风格,演示页顶部分段器可切换
</script>
04 / Props · Events · Methods · Slots

全量 API

props

参数说明类型默认值
prize-list奖池;蛋数 = 列表长度(最多 12),空列表渲染 1 个占位蛋Array[]
prize-index预置中奖蛋位;-1 时点哪枚出哪枚的奖品Number-1
columns每行蛋数;间距用 margin,不用 gapNumber3
egg-width单枚蛋宽String'80px'
egg-height单枚蛋高String'80px'
intact-image完整蛋图;空串用 CSS 蛋形兜底String''
broken-image破壳图;空串用内置裂纹层String''
hammer-image锤子图;空串不显示锤子,直接裂开String''
duration单次砸蛋总时长(ms)Number600
disabled整组禁用Booleanfalse

events

事件说明载荷
@hit用户点中某枚蛋的瞬间{ index }
@start动画开始;用户点击时与 hit 同帧,程序化 start() 时只发它{ index }
@end破壳完成,奖品落定;空奖池为 null{ index, prize }

methods

方法签名说明
startstart(index: number = -1): boolean程序化砸一枚;index 越界或已破壳时回退随机一枚未破的蛋;运行中、disabled 或无完整蛋返回 false
resetreset(): void全部复原、清锤子与锁定

slots

本件没有插槽。

05 / Notes

注意事项

running 期间的重复点击由组件自身挡住,不排队、不叠加。

一次只处理一枚,破壳态保持到 reset()。

页面卸载时组件会取消内部 ticker;页面隐藏不强停,由宿主决定是否 reset()。

页面根节点需同时挂主题类与风格类,否则暗黑与风格 A–F 不生效。