123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <template>
- <view class="tm-choujiangGame py-32">
- <view class="tm-choujiangGame-theme-1 flex-center flex-col">
- <view class="tm-choujiangGame-bg ">
- <view
- @click="clickImgPlay"
- class="tm-choujiangGame-bg-image"
- :style="{
- backgroundImage: `url(${them_data.bg})`
- }"
- ></view>
- <view class="tm-choujiangGame-bg-prod ">
- <view
- class="tm-choujiangGame-bg-cp text-red text-align-center "
- :style="{
- width: '25%',
- height: '100%',
- transform: `translateY(${reisetInitTop}px)`
- }"
- :animation="animationData0"
- >
- <view
- v-for="(item, index) in listData"
- :key="index"
- style="height: 100%;"
- class="flex-center flex-col"
- >
- <tm-images v-if="item.img" :previmage="false" :width="60" :src="item.img"></tm-images>
- {{item.name}}
- </view>
- </view>
- <view
- class="tm-choujiangGame-bg-cp text-red text-align-center "
- :style="{
- width: '25%',
- height: '100%',
- transform: `translateY(${reisetInitTop}px)`
- }"
- :animation="animationData1"
- >
- <view
- v-for="(item, index) in listData"
- :key="index"
- style="height: 100%;"
- class="flex-center flex-col"
- >
- <tm-images v-if="item.img" :previmage="false" :width="60" :src="item.img"></tm-images>
- {{item.name}}
- </view>
- </view>
- <view
- class="tm-choujiangGame-bg-cp text-red text-align-center "
- :style="{
- width: '25%',
- height: '100%',
- transform: `translateY(${reisetInitTop}px)`
- }"
- :animation="animationData2"
- >
- <view
- v-for="(item, index) in listData"
- :key="index"
- style="height: 100%;"
- class="flex-center flex-col"
- >
- <tm-images v-if="item.img" :previmage="false" :width="60" :src="item.img"></tm-images>
- {{item.name}}
- </view>
- </view>
- <view
- class="tm-choujiangGame-bg-cp text-red text-align-center "
- :style="{
- width: '25%',
- height: '100%',
- transform: `translateY(${reisetInitTop}px)`
- }"
- :animation="animationData3"
- >
- <view
- v-for="(item, index) in listData"
- :key="index"
- style="height: 100%;"
- class="flex-center flex-col"
- >
- <tm-images v-if="item.img" :previmage="false" :width="60" :src="item.img"></tm-images>
- {{item.name}}
- </view>
- </view>
- </view>
-
- <view class="flex-end tm-choujiangGame-point">
- <view class="tm-choujiangGame-point-bar"
- :style="{
- transform: aniOff?'rotate(0)':'rotate(25deg)'
- }"
- >
- <tm-images :previmage="false" :width="120" :src="them_data.point"></tm-images>
- </view>
- </view>
- </view>
- <!-- transform: choujiangJieGuo==null?`translateY(-100%)`:`translateY(0)` -->
- <view class="tm-choujiangGame-pingtai flex-center">
- <view class="tm-choujiangGame-pingtai-coll" :style="{
- transition: 'all 0.5s',
- transform: choujiangJieGuo==null?`translateY(-100%)`:`translateY(0)`
- }">
- <view class="tm-choujiangGame-pingtai-text">中奖啦~</view>
- <tm-images :previmage="false" :width="380" :height="200" :src="them_data.dizuo"></tm-images>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- /**
- * 转盘抽奖
- * @property {Number} theme-index = [] 默认0,主题索引,我已内置两套皮肤。
- * @property {Array} theme-list = [] 默认[已内置两套],主题列表数据,已有两套。
- * @property {Boolean} disabled = [] 默认 false,是否禁用
- * @property {Boolean} disabledCenter = [] 默认 false,是否禁用点中间图片开始。
- * @property {Number} duration = [] 默认 3000,动画时长
- * @property {Array} list = [] 默认 [测试的数据],奖品数据。
- * @property {Function} start 游戏开始时触发。
- * @property {Function} end 游戏结束触发,并返回奖品数据。
- * @example <tm-choujiangGame ></tm-choujiangGame>
- */
- import tmImages from "@/tm-vuetify/components/tm-images/tm-images.vue"
- export default {
- components:{tmImages},
- name: 'tm-choujiangGame',
- props: {
- themeIndex: {
- type: Number,
- default: 0
- },
- themeList: {
- type: Array,
- default: () => {
- return [
- {
- bg: 'https://jx2d.cn/yuwuimages/choujiangGame_1.png?k=9',
- point: 'https://jx2d.cn/yuwuimages/choujiangGame_1_0.png',
- dizuo: 'https://jx2d.cn/yuwuimages/choujiangGame_2_1.png'
- },
- {
- bg: 'https://jx2d.cn/yuwuimages/choujiangGame_2.png?k=9',
- point: 'https://jx2d.cn/yuwuimages/choujiangGame_2_0.png',
- dizuo: 'https://jx2d.cn/yuwuimages/choujiangGame_2_1.png'
- }
- ];
- }
- },
- disabled: {
- type: Boolean,
- default: false
- },
- //是否禁用点中间图片开始。
- disabledCenter:{
- type: Boolean,
- default: false
- },
- // 动画时长
- duration: {
- type: Number,
- default: 150
- },
- list: {
- type: Array,
- default: () => {
- return [
- { name: '1', gailv: 30, id: 1, img: 'https://jx2d.cn/yuwuimages/jiangping_2.png' },
- { name: '2', gailv: 10, id: 2, img: 'https://jx2d.cn/yuwuimages/jiangping_1.png' },
- { name: '3', gailv: 10, id: 3, img: 'https://jx2d.cn/yuwuimages/jiangping_2.png' },
- { name: '4', gailv: 10, id: 4, img: 'https://jx2d.cn/yuwuimages/jiangping_1.png' },
- { name: '5', gailv: 10, id: 5, img: 'https://jx2d.cn/yuwuimages/jiangping_2.png' },
- { name: '7', gailv: 10, id: 7, img: 'https://jx2d.cn/yuwuimages/jiangping_1.png' },
- { name: '8', gailv: 10, id: 8, img: 'https://jx2d.cn/yuwuimages/jiangping_2.png' },
- { name: '9', gailv: 10, id: 9, img: 'https://jx2d.cn/yuwuimages/jiangping_1.png' }
-
- ];
- }
- }
- },
- data() {
- return {
- animationData0: '',
- animationData1: '',
- animationData2: '',
- animationData3: '',
- aniOff: true,
- choujiangJieGuo:null,
- listData: [],
-
-
- };
- },
- mounted() {
- this.listData = this.list;
-
- },
- computed: {
- reisetInitTop:function(){
- return -(this.listData.length-1)*uni.upx2px(160)
- },
- them_index: function() {
- return this.themeIndex;
- },
- them_data: function() {
- return this.themeList[this.them_index];
- }
- },
- methods: {
- clickImgPlay(){
- if (this.disabledCenter) return;
- this.play();
- },
- chuliganlv() {
- var ml = new this.$tm.choujiang(this.listData);
- let zhongle = [];
- let xh = [
- ml.getResult(),
- ml.getResult(),
- ml.getResult(),
- ml.getResult()
- ]
-
- for(let i=0 ;i<xh.length;i++){
-
- let index = 0
- for(let j=0;j<this.listData.length;j++){
- if(this.listData[j].id === xh[i].id){
- index = j;
-
- break;
- }
- }
- //(this.listData.length-1)*2
- let cisu = (this.listData.length-1)*2+1 + (this.listData.length - index);
- zhongle.push({
- index:index,
- data:xh[i],
- playNum:cisu
- })
- }
-
- return zhongle;
- },
- async play() {
- let t = this;
- if (this.disabled) return;
- if (!this.aniOff) {
- console.warn('未结束动画,不能连续点击.');
- return;
- }
- // 开始动画.
- this.$emit('start');
- this.choujiangJieGuo = null;
- let zhongjiang = this.chuliganlv();
-
- this.$nextTick(async function() {
- await this.resetInit();
-
- this.aniOff = false;
- let duration = this.duration;
- let dhIndex=[0,0,0,0];//内部播放次数。
- let ydIndex =[0,0,0,0] ; //达到长度时,要循环。
- let isok = [false,false,false,false]
- async function aniOpen(ix){
- if(ydIndex[ix]>t.listData.length-1){
-
-
- if(ix==0){
- var animation0 = uni.createAnimation({
- duration: 0
- });
- t.animationData0 = animation0;
- animation0.translateY(-(t.listData.length-1)*uni.upx2px(160)).step({duration:0});
- t.animationData0 = animation0.export();
- }else if(ix==1){
- var animation1 = uni.createAnimation({
- duration: 0
- });
- t.animationData1 = animation1;
- animation1.translateY(-(t.listData.length-1)*uni.upx2px(160)).step({duration:0});
- t.animationData1 = animation1.export();
- }else if(ix==2){
- var animation2 = uni.createAnimation({
- duration: 0
- });
- t.animationData2 = animation2;
- animation2.translateY(-(t.listData.length-1)*uni.upx2px(160)).step({duration:0});
- t.animationData2 = animation2.export();
- }else if(ix==3){
- var animation3 = uni.createAnimation({
- duration: 0
- });
- t.animationData3 = animation3;
- animation3.translateY(-(t.listData.length-1)*uni.upx2px(160)).step({duration:0});
- t.animationData3 = animation3.export();
- }
- await uni.$tm.sleep(50);
- ydIndex[ix] = 0;
- }else{
- var animation = uni.createAnimation({
- duration: duration,
- timingFunction: 'linear'
- });
-
-
- if(ix==0){
- t.animationData0 = animation;
- let jl = -(t.listData.length-1)*160+ydIndex[ix]*160;
- animation.translateY(uni.upx2px(jl)).step();
- t.animationData0 = animation.export();
- }else if(ix==1){
- t.animationData1 = animation;
- let jl = -(t.listData.length-1)*160+ydIndex[ix]*160;
- animation.translateY(uni.upx2px(jl)).step();
- t.animationData1 = animation.export();
- }else if(ix==2){
- t.animationData2 = animation;
- let jl = -(t.listData.length-1)*160+ydIndex[ix]*160;
- animation.translateY(uni.upx2px(jl)).step();
- t.animationData2 = animation.export();
- }else if(ix==3){
- let jl = -(t.listData.length-1)*160+ydIndex[ix]*160;
- animation.translateY(uni.upx2px(jl)).step();
- t.animationData3 = animation.export();
-
- }
-
- await uni.$tm.sleep(duration);
-
-
- }
-
- dhIndex[ix] = dhIndex[ix]+1;
- ydIndex[ix] = ydIndex[ix]+1;
-
- if(dhIndex[ix] > zhongjiang[ix].playNum){
- isok[ix] = true;
- if(isok[0]&&isok[1]&&isok[2]&&isok[3]){
- // 结束动画.
- t.aniOff = true;
- t.$emit('end',zhongjiang)
- t.choujiangJieGuo = zhongjiang;
- }
- }else{
- await aniOpen(ix);
- }
-
- }
-
-
- for(let i =0;i<zhongjiang.length;i++){
- aniOpen(i);
- }
-
-
- });
- },
- // 重置 角度。
- async resetInit() {
- this.animationData0 = '';
- var animation0 = uni.createAnimation({duration: 0});
- this.animationData0 = animation0;
- animation0.translateY(-uni.upx2px((this.listData.length-1)*160)).step();
- this.animationData0 = animation0.export();
-
- this.animationData1 = '';
- var animation1 = uni.createAnimation({duration: 0});
- this.animationData1 = animation1;
- animation1.translateY(-uni.upx2px((this.listData.length-1)*160)).step();
- this.animationData1 = animation1.export();
-
- this.animationData2 = '';
- var animation2 = uni.createAnimation({duration: 0});
- this.animationData2 = animation2;
- animation2.translateY(-uni.upx2px((this.listData.length-1)*160)).step();
- this.animationData2 = animation2.export();
-
- this.animationData3 = '';
- var animation3 = uni.createAnimation({duration: 0});
- this.animationData3 = animation3;
- animation3.translateY(-uni.upx2px((this.listData.length-1)*160)).step();
- this.animationData3 = animation3.export();
- await uni.$tm.sleep(50);
-
- }
- }
- };
- </script>
- <style lang="less" scoped>
- .tm-choujiangGame {
- overflow: hidden;
- .tm-choujiangGame-theme-1 {
- .tm-choujiangGame-bg {
- width: 600upx;
- height: 600upx;
- position: relative;
- z-index: 2;
- .tm-choujiangGame-bg-image {
- width: 100%;
- height: 100%;
- position: relative;
- z-index: 3;
- background-repeat: no-repeat;
- background-size: cover;
- }
- .tm-choujiangGame-point {
- position: absolute;
- width: 100%;
- height: 100%;
- top: 0;
- left: 0;
- right: 0;
- .tm-choujiangGame-point-bar{
- position: relative;
- right: 0;
- z-index: 0;
- top: -50upx;
- transform-origin: left right;
- transition:all 0.5s;
- }
- }
- .tm-choujiangGame-bg-prod {
- position: absolute;
- overflow: hidden;
- width: 370upx;
- height: 160upx;
- top: 95upx;
- left: 103upx;
- display: flex;
- z-index: 4;
- .tm-choujiangGame-bg-cp {
- transform-origin: center bottom;
-
- }
- }
- }
- .tm-choujiangGame-pingtai {
- position: relative;
- z-index: 2;
- margin-left: -20upx;
- margin-top: -140upx;
- overflow: hidden;
- height: 190upx;
- .tm-choujiangGame-pingtai-coll{
- position: relative;
- .tm-choujiangGame-pingtai-text{
- position: absolute;
- z-index: 3;
- font-size: 48upx;
- text-align: center;
- width: 100%;
- top: 10upx;
- color: red;
- font-weight: bold;
- }
- }
- }
- }
- }
- </style>
|