营销组件 / 神秘大礼盒 cu-bingo-gift-box

cu-bingo-gift-box

点击礼盒后盒盖弹起,奖品从盒内升起并淡入。一次只开一盒,开盒态保持到 reset(),支持初始露奖。

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

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

程序控制

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

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

import type { CuBingoGiftBoxComponentPublicInstance } from './uni_modules/colorui-bingo/components/cu-bingo-gift-box/cu-bingo-gift-box.uvue'

const boardRef = ref<CuBingoGiftBoxComponentPublicInstance | 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-gift-box    :prize-list="prizeList"></cu-bingo-gift-box>
  </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取 prize-index 对应项展示;空列表只开盒不露奖Array[]
prize-index展示哪一项;-1 随机Number-1
box-image闭合盒图;空串用 CSS 礼盒String''
open-image开盖后盒身图;空串沿用 box-imageString''
lid-image独立盒盖图;空串时盒盖与盒身同图,开盖只位移、不旋转String''
box-width礼盒宽String'160px'
box-height礼盒高String'160px'
duration开盒总时长(ms)Number1200
init-prizetrue 时首屏就展示奖品,点击只做开盖装饰Booleanfalse
disabled禁用点击Booleanfalse

events

事件说明载荷
@start开始开盒;index 为本次展示的奖品下标,空奖池为 -1{ index }
@end开盒完成;prize 为空奖池时为 null{ index, prize }

methods

方法签名说明
startstart(index: number = -1): boolean程序化开盒;index 越界回退 prize-index / 随机;运行中或禁用返回 false
resetreset(): void盒盖复位、奖品隐藏;init-prize=true 时回到露奖静止态

slots

插槽说明
默认插槽自定义奖品层;prize-list 非空时渲染内置奖品,插槽不渲染
05 / Notes

注意事项

running 与 result 期间再次点击不会重播;需要重开必须先 reset(),程序化 start() 被忽略时返回 false。

开盖与露奖全部由 JS ticker 按 Date.now() 计算,不依赖 CSS 过渡事件。

init-prize 只在初始化与 reset() 时读取;运行中改 prop 需再 reset() 才生效。

仅独立盒盖图(lid-image 非空)才追加旋转,否则开盖只位移。