01
基础用法
给出奖品数据,接住开始与结果事件;完整字段见 04 段。
<cu-bingo-square-nine
:prize-list="prizeList"
@start="onStart"
@hit="onHit"
@end="onEnd"
></cu-bingo-square-nine>
8 张卡围成九宫格(中心为开始按钮);点开始后卡片换位洗牌,用户点任意一张卡翻开,翻到哪张就中哪张的奖品。
营销组件放在独立模块 colorui-bingo 里,依赖 colorui-x 的主题 token;两个目录一并放进工程的 uni_modules/ 即可,easycom 按标签逐个解析,不写 import,也没有全局注册这一步。本仓不是 npm 包,不提供 npm 安装命令。
your-project/
└── uni_modules/
├── colorui-x/
└── colorui-bingo/
<cu-bingo-square-nine
:prize-list="prizeList"
></cu-bingo-square-nine>
奖品字段、活动与抽奖响应的示例见 数据与接口规范(仓库内 docs/01-交付与接入/Bingo-数据与接口规范.md)。组件本身不连后端,落点与结果由宿主决定。
| 能力 | App-Android | H5 预览 | 微信 / 支付宝小程序 | iOS |
|---|---|---|---|---|
| 基础渲染 / 点击 | 支持 | 支持 | 编译门 | 未验收 |
| JS ticker 动画 | 支持 | 支持 | 编译门 | 未验收 |
| Canvas(转盘 / 刮卡) | 支持 | 支持 | 编译门 | 未验收 |
| 真实摇一摇 | 不支持(加速度计 API 不可用) | 可选 devicemotion,需 HTTPS / 权限 | 未验收 | 未验收 |
| 震动反馈 | 不支持(类型层无 API) | 未验收 | 未验收 | 未验收 |
| 3D 翻转 / 3D 骰子 | 不支持 | 不支持(统一 2D) | 不支持 | 不支持 |
「编译门」只表示已被编译流程覆盖,不构成真机渲染承诺;「未验收」不写支持。摇一摇的宿主接线见 平台与限制 与组件 05 段说明。
给出奖品数据,接住开始与结果事件;完整字段见 04 段。
<cu-bingo-square-nine
:prize-list="prizeList"
@start="onStart"
@hit="onHit"
@end="onEnd"
></cu-bingo-square-nine>
用 ref 拿到组件实例后直接调方法;签名与返回值见 04 段 Methods 表。
<cu-bingo-square-nine ref="boardRef" :prize-list="prizeList"></cu-bingo-square-nine>
import type { CuBingoSquareNineComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-square-nine/cu-bingo-square-nine.uvue'
const boardRef = ref<CuBingoSquareNineComponentPublicInstance | 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()
}
页面根节点挂主题类和 Bingo 风格类;风格 A–F 由 store/style.uts 切换。
<template>
<view :class="'cu-page ' + themeClass + ' ' + styleClass">
<cu-bingo-square-nine :prize-list="prizeList"></cu-bingo-square-nine>
</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-list | 8 项,第 i 项是第 i 张卡的奖品;不足 8 项时后面的卡为空卡 | Array | [] |
| card-image | 卡背图;空串用内置纯色卡背 + ? | String | '' |
| card-width | 单卡宽(只解析 px 数值,非法值按 80 兜底) | String | '80px' |
| card-height | 单卡高(同上) | String | '80px' |
| shuffle-duration | 洗牌总时长(ms),平均分给每一轮;0 立即完成 | Number | 1500 |
| shuffle-rounds | 换位轮数,最小值 1 | Number | 2 |
| flip-duration | 单卡翻开时长(ms) | Number | 500 |
| disabled | 禁用开始与翻牌 | Boolean | false |
| 事件 | 说明 | 载荷 |
|---|---|---|
| @start | 开始洗牌;index 恒为 -1(本件无落点概念) | { index: -1 } |
| @hit | 用户点中第 index 张卡(数据下标),只发一次 | { index } |
| @end | 翻牌完成;prize 为 prize-list[index],空卡为 null | { index, prize } |
| 方法 | 签名 | 说明 |
|---|---|---|
| start | start(): void | 开始洗牌;洗牌中与翻牌中调用无效 |
| reset | reset(): void | 8 张卡回卡背、摆位回初始、清结果 |
| 插槽 | 说明 |
|---|---|
| start | 替换中心开始按钮内容;点击仍由组件接管 |
本件没有 prize-index:结果由用户翻哪张卡决定;需要固定结果时把 prize-list 8 项传成同一奖品。
card-image 同时用作卡背;prize-list[i].image 只用于翻开后的正面。
页面被入栈 / 切走不会卸载组件,宿主需在 onHide 调 reset()。
start 插槽只替换按钮内容,不接受作用域参数。