营销组件 / 大转盘 cu-bingo-turntable

cu-bingo-turntable

圆形转盘按奖品数均分扇区,指针固定在顶部;转盘旋转多圈后缓出,停在 prize-index 指定的扇区。

新 App / H5 canvas
01 / Install

引入组件

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

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

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

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

程序控制

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

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

import type { CuBingoTurntableComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-turntable/cu-bingo-turntable.uvue'

const boardRef = ref<CuBingoTurntableComponentPublicInstance | 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-turntable    :prize-list="prizeList"></cu-bingo-turntable>
  </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-list2–12 项;空列表只显示底盘、不旋转Array[]
prize-index目标扇区 0–N-1;-1 随机Number-1
turns-number基础整圈数Number5
duration旋转总时长(ms);<= 0 直接落到目标Number5000
lock-time停稳后的锁定时间(ms);期间点击中心只发 lockNumber0
size转盘直径String'300px'
pointer-image指针图;空串用内置 CSS 三角String''
pointer-size指针尺寸String'40px'
sector-colors扇区颜色按序循环;空数组用内置金 / 橙交替Array[]
label-color扇区文字颜色;空串用 #5A3A00String''
font-size扇区文字字号String'12px'
hub-text中心圆文字String''
hub-image中心圆图片;非空时覆盖 hub-textString''

events

事件说明载荷
@start开始旋转;index 为最终落点{ index }
@end停稳;prize 为目标奖品对象{ index, prize }
@lock锁定期间点击中心圆;每次点击发一次无

methods

方法签名说明
startstart(index: number = -1): boolean程序化旋转;index 越界按随机处理;运行中或空奖品列表返回 false
resetreset(): void回 0°、清锁定与目标,不改变 prize-index

slots

插槽说明
pointer替换指针节点;提供后 pointer-image 失效
05 / Notes

注意事项

扇区画在 canvas,读不到 CSS 变量,颜色只来自 sector-colors;暗黑模式下扇区色不变(已知限制),底盘与中心文字跟随主题。

程序化 start() 被忽略时返回 false,不排队;签名保持返回 boolean,改回 void 会在 App 端复现反射 NPE(台账 109)。

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

375px 宽下 size=300px 不溢出;改 size 时同步调 font-size,扇区与文字才能一起缩放。