條件抽獎元件
更新時間:2024-04-22 19:18:32
本文件主要說明如何接入互動功能接收端的條件抽獎元件,接入後可實現觀眾端顯示抽獎活動詳情、抽獎結果、中獎名單、中獎記錄等操作。
在引入及使用本功能元件前,需要先對互動功能接收端SDK進行公共配置,詳情請查看:互動功能接收端 UI 元件 - 配置 SDK。
引入
線上檔案引入方式
// script 标签引入,根据版本号引入JS版本。
<script src="https://websdk.videocc.net/interactions-receive-sdk-ui-default/0.24.0/lib/PcWelfareLottery/PcWelfareLottery.umd.min.js"></script>
// PC端
<script>
const PcWelfareLottery = window.PolyvIRScene.PcWelfareLottery.default;
</script>
// script 标签引入,根据版本号引入JS版本。
<script src="https://websdk.videocc.net/interactions-receive-sdk-ui-default/0.24.0/lib/MobileWelfareLottery/MobileWelfareLottery.umd.min.js"></script>
// 移动端
<script>
const MobileWelfareLottery = window.PolyvIRScene.MobileWelfareLottery.default;
</script>
import 方式引入(推薦)
// PC 端
import PcWelfareLottery from '@polyv/interactions-receive-sdk-ui-default/lib/PcWelfareLottery';
// 移动端
import MobileWelfareLottery from '@polyv/interactions-receive-sdk-ui-default/lib/MobileWelfareLottery';
程式碼範例
先實例化條件抽獎SDK,然後將其傳入到條件抽獎元件中,以便內部進行相應邏輯處理。
以 行動端 接入為例:
<template>
<mobile-welfare-lottery
:welfare-lottery-sdk="conditionLotterySdk"
:watch-url="watchUrl"
:invite-url="inviteUrl"
:lang="lang"
@entry-visible-changed="onEntryVisibleChanged"
@lotteryCallback="lotteryCallback"
@comment-success="commentSuccess"
/>
</template>
<script>
import { WelfareLottery } from '@polyv/interactions-receive-sdk';
import MobileWelfareLottery from '@polyv/interactions-receive-sdk-ui-default/lib/MobileWelfareLottery';
export default {
components: {
MobileWelfareLottery,
},
props: {
lang: {
type: String,
default: 'zh_CN',
},
watchUrl: String,
inviteUrl: String,
},
data() {
return {
// 条件抽奖 SDK 实例
conditionLotterySdk: null,
};
},
mounted() {
this.conditionLotterySdk = new WelfareLottery();
// $eventBus 为全局事件总线, 监听自己发言,判断是否满足评论抽奖条件。
this.$eventBus.$on('SPEAK_LOTTERY_COMMENT', async (comment) => {
const isBoolean = await this.conditionLotterySdk.isBooleanToCommentLottery(comment);
if (isBoolean) {
this.conditionLotterySdk.finishCommentLottery();
}
});
},
beforeDestroy() {
this.conditionLotterySdk?.destroy();
},
methods: {
onEntryVisibleChanged(visible) {
console.info('条件抽奖挂件是否显示:', visible);
},
lotteryCallback(data) {
console.info('各按钮触发的回调:', data);
},
commentSuccess(comment) {
// 点击自动评论按钮后,需要本地插入一条自己的发言内容
// TODO 聊天列表:插入一条自己发言内容
}
}
};
</script>
Attributes
| 屬性名 | 類型 | 預設值 | 含義 |
|---|---|---|---|
| welfareLotterySdk | Object | null | 條件抽獎 SDK 實例 |
| lang | String:'zh_CN', 'en' | 'zh_CN' |
語言 |
| watchUrl | String' | - | 觀看地址url,用於掃碼進入到觀看地址,複製觀看連結等功能 |
| inviteUrl | String' | - | 邀請連結,用於抽獎條件為邀請海報類型時的邀請入口 |
| isShowCustomLottery | Boolean | false | 是否顯示自訂抽獎,如果是的話,將屏蔽領取獎品的後續流程 |
| linkSkipEnabled | Boolean | true | 是否禁用內部頁面跳轉 |
| customLangConfig | Object | - | 用於覆蓋內部中英文配置 預設中英文設定檔 |
Event
| 事件名 | 參數類型 | 參數含義 | 說明 |
|---|---|---|---|
| entry-visible-changed | boolean | 入口掛件狀態是否顯示 | 入口掛件狀態是否顯示 |
| comment-success | string | 評論內容 | 點擊自動評論,並回調評論內容 |
| lotteryCallback | object | 點擊各按鈕之後的回調 type: ' ', 觸發的事件類型 data: object 返回當前的中獎記錄 |
生效條件:開啟了外部邀請且在行動端環境 type: 'setLottery' 立即參與抽獎,無data返回 type: 'seeLottery' 查看 type: 'getLottery' 領取 |
