01
基础用法
给出奖品数据,接住开始与结果事件;完整字段见 04 段。
<cu-bingo-guess-gift
:prize="prize"
@start="onStart"
@select="onSelect"
@end="onEnd"
></cu-bingo-guess-gift>
多个碗扣住 1 个奖品,先快速换位,停下后由用户选一个碗;选对抬碗露奖,选错抬起空碗。
营销组件放在独立模块 colorui-bingo 里,依赖 colorui-x 的主题 token;两个目录一并放进工程的 uni_modules/ 即可,easycom 按标签逐个解析,不写 import,也没有全局注册这一步。本仓不是 npm 包,不提供 npm 安装命令。
your-project/
└── uni_modules/
├── colorui-x/
└── colorui-bingo/
<cu-bingo-guess-gift
:prize="prize"
></cu-bingo-guess-gift>
奖品字段、活动与抽奖响应的示例见 数据与接口规范(仓库内 docs/01-交付与接入/Bingo-数据与接口规范.md)。组件本身不连后端,落点与结果由宿主决定。
| 能力 | App-Android | H5 预览 | 微信 / 支付宝小程序 | iOS |
|---|---|---|---|---|
| 基础渲染 / 点击 | 支持 | 支持 | 编译门 | 未验收 |
| JS ticker 动画 | 支持 | 支持 | 编译门 | 未验收 |
| Canvas(转盘 / 刮卡) | 支持 | 支持 | 编译门 | 未验收 |
| 真实摇一摇 | 不支持(加速度计 API 不可用) | 可选 devicemotion,需 HTTPS / 权限 | 未验收 | 未验收 |
| 震动反馈 | 不支持(类型层无 API) | 未验收 | 未验收 | 未验收 |
| 3D 翻转 / 3D 骰子 | 不支持 | 不支持(统一 2D) | 不支持 | 不支持 |
「编译门」只表示已被编译流程覆盖,不构成真机渲染承诺;「未验收」不写支持。摇一摇的宿主接线见 平台与限制 与组件 05 段说明。
给出奖品数据,接住开始与结果事件;完整字段见 04 段。
<cu-bingo-guess-gift
:prize="prize"
@start="onStart"
@select="onSelect"
@end="onEnd"
></cu-bingo-guess-gift>
用 ref 拿到组件实例后直接调方法;签名与返回值见 04 段 Methods 表。
<cu-bingo-guess-gift ref="boardRef" :prize="prize"></cu-bingo-guess-gift>
import type { CuBingoGuessGiftComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-guess-gift/cu-bingo-guess-gift.uvue'
const boardRef = ref<CuBingoGuessGiftComponentPublicInstance | null>(null)
function callStart(): void {
const inst = boardRef.value
if (inst == null) { return }
inst.start()
}
function callStop(): void {
const inst = boardRef.value
if (inst == null) { return }
inst.stop()
}
页面根节点挂主题类和 Bingo 风格类;风格 A–F 由 store/style.uts 切换。
<template>
<view :class="'cu-page ' + themeClass + ' ' + styleClass">
<cu-bingo-guess-gift :prize="prize"></cu-bingo-guess-gift>
</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>
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| prize | 隐藏奖品 { id, name, image, color };空对象等同无奖品(以空对象承载,避免 App 端 null prop 反射问题) | Object | {} |
| prize-index | 奖品初始所在碗 0–N-1;-1 或越界随机 | Number | -1 |
| bowl-count | 碗数,夹到 2–5 | Number | 3 |
| bowl-image | 碗图;空串用内置 CSS 碗 | String | '' |
| bowl-width | 单碗宽;碗高 = 宽 × 0.62 | String | '80px' |
| bowl-gap | 碗间距;允许 0px | String | '20px' |
| raise-height | 抬碗高度 | String | '50px' |
| shuffle-count | 换位次数;0 直接进入待选 | Number | 20 |
| shuffle-interval | 单次换位时长(ms);0 表示瞬时换完 | Number | 500 |
| raise-duration | 抬碗时长(ms);0 直接抬到顶 | Number | 300 |
| disabled | 禁用开始与选择 | Boolean | false |
| 事件 | 说明 | 载荷 |
|---|---|---|
| @start | 换位开始;index 为奖品所在碗(从 0 起,左→右) | { index } |
| @select | 用户选中第 index 个碗(可视位置),hit 是否选对;每次选择只发一次 | { index, hit } |
| @end | 抬碗完成;index 为奖品所在碗,未中时 prize 仍回传正确答案 | { index, prize } |
| 方法 | 签名 | 说明 |
|---|---|---|
| start | start(prizeIndex: number = -1): boolean | 开始换位;显式 prizeIndex 与 prize-index 都无效时随机;禁用 / 换位中 / 待选中 / 抬碗中返回 false |
| stop | stop(): void | 立即停止换位进入待选;不在换位中时无操作 |
| reset | reset(): void | 所有碗落下、奖品回到 prize-index 碗下(-1 随机);不改变 prop |
本件没有插槽。
12 件里唯一不用 prize-list 的组件:prize 传单个对象,prize-index 语义是「奖品初始在哪个碗」,不是奖品下标。
prize 在 App 端以空对象为默认值,宿主不要传 null;模板需把空对象当无奖品处理。
碗数 5 时默认 80px 宽会超出 375 宽页面,宿主按 bowl-width × N + bowl-gap × (N-1) ≤ 容器宽自行收窄。
换位动画只写原始值 ref;slots 交换时整体重新赋值数组,App(VDOM)端才能重绘。