2.2.2 • Published 2 years ago

improved-vue-fortune-wheel v2.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Improved-Vue-Fortune-Wheel

Component name: Wheel of Fortune, Wheel of Fortune, Wheel of Fortune

Application scenario: lottery

Install

yarn add improved-vue-fortune-wheel

or

npm install improved-vue-fortune-wheel

Language

English

Demo

online

https://xiaolin1995.github.io/vue-fortune-wheel/demo/

Usage

<template>
  <div>
    <!-- type: image -->
    <fortune-wheel
      style="width: 500px"
      type="image"
      :useWeight="true"
      :prizes="prizes"
      :angleBase="-10"
      @rotateStart="onImageRotateStart"
      @rotateEnd="onRotateEnd"
    >
      <img slot="wheel" src="@/assets/wheel.png" alt=""/>
      <img slot="button" src="@/assets/button.png" alt=""/>
    </fortune-wheel>

    <!-- type: canvas -->
    <fortune-wheel
      ref="wheel"
      :verify="canvasVerify"
      :canvas="canvasOptions"
      :prizes="prizes"
      @rotateEnd="onRotateEnd"
      @buttonClick="btnClicked"
    />
  </div>
</template>
import FortuneWheel from 'vue-fortune-wheel'
import 'vue-fortune-wheel/lib/vue-fortune-wheel.css'

export default {
  components: {
    FortuneWheel
  },
  data () {
    return {
      prizeId: 0,
      canvasVerify: false,
      canvasOptions: {
        borderColor: '#000000',
        borderWidth: 6,
        lineHeight: 50,
        textRadius: 220,
        radius: 300,
        btnBgColor: '#178704',
        btnTextColor: '#ffffff',
        btnText: 'GO',
        btnWidth: 80,
        btnFontSize: 32,
        btnBorderColor: '#000000',
        btnImageSrc: ''
      },
      prizes: [
        {
          id: 1,
          name: 'Blue',
          value: 'Blue\'s value',
          bgColor: '#75bcff',
          color: '#ffffff',
          probability: 25,
          weight: 5
        },
        {
          id: 2,
          name: 'Red',
          value: 'Red\'s value',
          bgColor: '#F10025',
          color: '#ffffff',
          probability: 25,
          weight: 5
        },
        {
          id: 3,
          name: 'Green',
          value: 'Green\'s value',
          bgColor: '#4CB300',
          color: '#ffffff',
          probability: 25,
          weight: 5
        },
        {
          id: 4,
          name: 'Yellow',
          value: 'Yellow\'s value',
          bgColor: '#F7F70A',
          color: '#000000',
          probability: 25,
          weight: 5
        }
      ],
    }
  },
  computed: {
    wheel() :any {
      return this.$refs.wheel
    },
    image() :any {
      return this.$refs.image
    }
  },
  methods: {
    spin(){
      this.wheel.spin()
    },
    spinImage(){
      this.image.spin()
    },
    btnClicked(){
      console.log('button clicked')
      //spin canvas
      this.spin()
    },
    onRotateEnd (prize: PrizeConfig) {
      console.log(prize.value)
    },
  }
};

FortuneWheel Functions

You can access the functions inside the component by referencing the component.

Function nameDescription
spinThis function will start spinning canvas wheel
spinImageThis function will start spinning then image wheel

FortuneWheel Events

Event nameDescriptionCallback parameters
buttonClickTriggered when the dial button is clicked/
rotateEndTriggered at the end of the turntable animationThe entire prize Object

FortuneWheel Attributes

ParametersDescriptionTypeDefault Value
typeType of turntable (canvas, image)Stringcanvas
useWeightWhether to calculate probability by weightBooleanfalse
disabledWhether to disable (after disabled, click the button will not rotate)Booleanfalse
verifyWhether to enable verification modeBooleanfalse
canvas.radiusRadius of circle (type: canvas)Number250
canvas.textRadiusThe distance of the text from the center of the circle (type: canvas)Number190
canvas.textLengthA few characters in one line of the prize, beyond the line break (maximum two lines)Number6
canvas.textDirectionPrize text direction (horizontal, vertical)Stringhorizontal
canvas.textFontSizePrize text font size (px)Number34
canvas.lineHeightText line height (type: canvas)Number20
canvas.borderWidthRound outer border (type: canvas)Number0
canvas.borderColorColor value of the outer border (type: canvas)Stringtransparent
canvas.btnTextButton text (type: canvas)StringGO
canvas.btnWidthButton width (px)Number140
canvas.btnBgColorButton background colorString#5d119c
canvas.btnTextColorButton text colorString#FFFFFF
canvas.btnFontSizeButton text font sizeNumber42
canvas.btnBorderColorButton border colorString#FFFFFF
canvas.btnImageSrcImage src to show in a buttonString''
canvas.prizeImageHeightHeight of prize imagesNumber100
canvas.prizeImageWidthWidth of prize imagesNumber100
durationTime to complete one rotation (unit: ms)Number6000
timingFunCss time function of rotation transitionStringcubic-bezier(0.36, 0.95, 0.64, 1)
angleBaseNumber of rotations (angleBase * 360 is the total angle of one rotation, it can be reversed when it is a negative number)Number10
prizeIdSpecify the id, it will spin to the prize of this id every time (when it is 0, the value can be changed during the rotation according to the probability of each prize itself to complete various show operations)Number0
prizesPrize list (structure reference Usage)Array/
2.2.1

2 years ago

2.2.2

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago