营销组件 / 九宫格翻牌 cu-bingo-square-nine

cu-bingo-square-nine

8 张卡围成九宫格(中心为开始按钮);点开始后卡片换位洗牌,用户点任意一张卡翻开,翻到哪张就中哪张的奖品。

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

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

程序控制

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

uvue
<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()
}
03

风格与主题

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

uvue
<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>
04 / Props · Events · Methods · Slots

全量 API

props

参数说明类型默认值
prize-list8 项,第 i 项是第 i 张卡的奖品;不足 8 项时后面的卡为空卡Array[]
card-image卡背图;空串用内置纯色卡背 + ?String''
card-width单卡宽(只解析 px 数值,非法值按 80 兜底)String'80px'
card-height单卡高(同上)String'80px'
shuffle-duration洗牌总时长(ms),平均分给每一轮;0 立即完成Number1500
shuffle-rounds换位轮数,最小值 1Number2
flip-duration单卡翻开时长(ms)Number500
disabled禁用开始与翻牌Booleanfalse

events

事件说明载荷
@start开始洗牌;index 恒为 -1(本件无落点概念){ index: -1 }
@hit用户点中第 index 张卡(数据下标),只发一次{ index }
@end翻牌完成;prize 为 prize-list[index],空卡为 null{ index, prize }

methods

方法签名说明
startstart(): void开始洗牌;洗牌中与翻牌中调用无效
resetreset(): void8 张卡回卡背、摆位回初始、清结果

slots

插槽说明
start替换中心开始按钮内容;点击仍由组件接管
05 / Notes

注意事项

本件没有 prize-index:结果由用户翻哪张卡决定;需要固定结果时把 prize-list 8 项传成同一奖品。

card-image 同时用作卡背;prize-list[i].image 只用于翻开后的正面。

页面被入栈 / 切走不会卸载组件,宿主需在 onHide 调 reset()。

start 插槽只替换按钮内容,不接受作用域参数。