| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <view>
- <view class="flex-container">
- <view class="result" :style="'visibility:' + isShow">
- <text>恭喜,您摇到的数字是:{{ total }}</text>
- </view>
- <view class="dice-box">
- <view v-if="num1 === 0" class="first face">
- <view class="pip"></view>
- </view>
- <view v-else-if="num1 === 1" class="second face">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num1 === 2" class="third face">
- <view class="pip"></view>
- <view class="pip third-item-center"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num1 === 3" class="fourth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else-if="num1 === 4" class="fifth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column fifth-column-center">
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else class="sixth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- </view>
- <view class="second-row">
- <view class="dice-box">
- <view v-if="num2 === 0" class="first face">
- <view class="pip"></view>
- </view>
- <view v-else-if="num2 === 1" class="second face">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num2 === 2" class="third face">
- <view class="pip"></view>
- <view class="pip third-item-center"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num2 === 3" class="fourth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else-if="num2 === 4" class="fifth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column fifth-column-center">
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else class="sixth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- </view>
- <view class="dice-box">
- <view v-if="num3 === 0" class="first face">
- <view class="pip"></view>
- </view>
- <view v-else-if="num3 === 1" class="second face">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num3 === 2" class="third face">
- <view class="pip"></view>
- <view class="pip third-item-center"></view>
- <view class="pip"></view>
- </view>
- <view v-else-if="num3 === 3" class="fourth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else-if="num3 === 4" class="fifth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column fifth-column-center">
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- <view v-else class="sixth face">
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- <view class="column">
- <view class="pip"></view>
- <view class="pip"></view>
- <view class="pip"></view>
- </view>
- </view>
- </view>
- </view>
- <view class="button-box">
- <button @tap="shakeClick" class="btnc" :type="buttonType">{{ buttonValue }}</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- dice: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth'],
- buttonType: 'primary',
- buttonValue: '摇一摇',
- isShow: 'hidden',
- num1: 0,
- num2: 0,
- num3: 0,
- total: 0,
- global: {
- timer: null,
- isRand: false
- }
- };
- },
- onHide() {
- if (this.global?.timer) {
- clearInterval(this.global.timer);
- this.global.isRand = false;
- }
- },
- onUnload() {
- if (this.global?.timer) {
- clearInterval(this.global.timer);
- this.global.isRand = false;
- }
- },
- methods: {
- shakeClick: function () {
- var that = this;
- this.global.isRand = !this.global.isRand;
- if (this.global.isRand) {
- this.global.timer = setInterval(() => {
- const a = Math.floor(6 * Math.random());
- const i = Math.floor(6 * Math.random());
- const s = Math.floor(6 * Math.random());
- this.num1 = a;
- this.num2 = i;
- this.num3 = s;
- this.total = a + i + s + 3; // 0-5映射为1-6
- }, 50);
- } else {
- clearInterval(this.global.timer);
- }
- this.dice = this.dice;
- this.buttonType = this.global.isRand ? 'default' : 'primary';
- this.buttonValue = this.global.isRand ? '停止' : '摇一摇';
- this.isShow = this.global.isRand ? 'hidden' : 'visible';
- }
- }
- };
- </script>
- <style>
- @import './game.css';
- </style>
|