Polyv Help Center

Help Center

Timer

Updated: 2021-10-14 16:31:49

Import Component

import Timer from '@polyv/interactions-launch-sdk-ui-default/lib/Timer';

Code Example

<template>
    <button v-if="isTeacher" @click="timerVisible = true">计时器</button>
  <div id="pane" class="c-interactions-pane">
    <timer
      v-if="timerCore"
      :lang="lang"
      :visible="timerVisible"
      :main-area-id="'pane'"
      :position="isTeacher ? 'center' : 'bottomLeft'"
      :is-teacher="isTeacher"
      :core="timerCore"
      @close="handleTimerClose"
      @update-visible="timerVisible = true"
    />
  </div>
</template>

<script>
import * as InteractionsLaunchSDK from '@polyv/interactions-launch-sdk';
import Timer from '@polyv/interactions-launch-sdk-ui-default/lib/Timer';

export default {
  components: {
    Timer,
  },
  data() {
    return {
      // 中英文设置 'zh_CN'/'en'
      lang: 'zh_CN',
      // 计时器 SDK 实例
      timerCore: null,
      timerVisible: false,
    };
  },
  mounted() {
    // TODO: 关于初始化 InteractionsLaunchSDK 的其他设置
    this.timerCore = new InteractionsLaunchSDK.Timer();
  },
  methods: {
    // 关闭计时器需要二次确认
    handleTimerClose(isOngoing) {
      if (!isOngoing) {
        this.timerVisible = false;
        return;
      }
      if (window.confirm(this.$t('timerCloseTips'))) {
        this.timerVisible = false;
      }
    },
  }
};
</script>

Attributes

Attribute Type Default Description
core object null Timer SDK instance
lang string 'zh_CN' Language pack type. Possible values:
'zh_CN' Chinese
'en' English
canStart boolean true Whether interaction can be initiated currently.
cantStartTips string '当前不可以发起互动' Prompt text when clicking the start button if interaction cannot be initiated.
visible boolean false Whether the timer popup is visible
isTeacher boolean false Whether the current user is a teacher. Only teachers have permission to start the timer.
mainAreaId string '' Unique ID of the positioning context element. The timer popup will be positioned relative to this context.
position string 'center' Display position of the timer popup relative to the positioning context. Possible values:
'center' Centered both horizontally and vertically
'bottomRight' Aligned to bottom right
'bottomLeft' Aligned to bottom left
'topRight' Aligned to top right
'topLeft' Aligned to top left
zIndex number 101 Z-index of the timer popup style

Events

Event Name Description Callback Parameter Type Callback Parameter Meaning
close Triggered when the popup close button is clicked. The timer will stop after closing the popup. boolean Whether timing is still ongoing.
update-visible Triggered when there is an ongoing timer or when the timer ends. boolean Whether the popup should be visible currently.
联系客服,在线咨询