营销组件 / 摇奖机 cu-bingo-lotto-roll

cu-bingo-lotto-roll

1–5 列奖品纵向滚动,逐列错峰停止;中心行拼出最终结果,行高由 item-height 常量直接计算,不读 DOM。

新 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-lotto-roll
    :prize-list="prizeList"
></cu-bingo-lotto-roll>

奖品字段、活动与抽奖响应的示例见 数据与接口规范(仓库内 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-lotto-roll
    :prize-list="prizeList"
    @start="onStart"
    @end="onEnd"
></cu-bingo-lotto-roll>
02

程序控制

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

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

import type { CuBingoLottoRollComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-lotto-roll/cu-bingo-lotto-roll.uvue'

const boardRef = ref<CuBingoLottoRollComponentPublicInstance | 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-lotto-roll    :prize-list="prizeList"></cu-bingo-lotto-roll>
  </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奖品池;元素为 { id, name, image, color }Array[]
prize-index所有列的统一落点;-1 或越界时随机Number-1
prize-index-list逐列落点,优先级高于 prize-index;不足的列继续向下回退Array[]
reel-count列数 1–5;超出范围按 1 / 5 截断Number3
visible-count可见行数,最小 1;中心行 = floor((visibleCount - 1) / 2)Number3
item-height每行高(px),动画位移按该常量计算String'60px'
reel-width每列宽(px);整体宽 = reel-count × reel-widthString'80px'
duration第 1 列滚动时长(ms)Number6000
stagger相邻列的停止间隔(ms);第 i 列时长 = duration + i × staggerNumber2000
turns-number落点前额外滚过的整圈数Number3
disabled禁用开始Booleanfalse

events

事件说明载荷
@start开始滚动;index 为第 1 列落点{ index }
@end最后一列停稳后触发一次;indices / prizes 为逐列落点与奖品副本{ index, prize, indices, prizes }

methods

方法签名说明
startstart(indices: number[] = []): boolean程序化开始;indices 优先于 prize-index-list / prize-index;运行中或禁用返回 false
resetreset(): void停表并回到静止态(首项居中),不改 props

slots

本件没有插槽。

05 / Notes

注意事项

运行中再次 start() 或点开始会被忽略,不重置动画、不补发事件。

end.prizes 是逐列深拷贝,消费方可直接序列化,不会因多列引用同一对象而出错。

App 端动画时钟必须用原始值 ref(clock),不要退回「每帧写数组 ref」的写法,否则 VDOM 不重绘。

item-height / reel-width 只支持 px 数值串;非数值或 <= 0 时分别回退 60 / 80。