Commit 894a45b6 authored by ziyu's avatar ziyu

improvement: 合并代码

parents 926f9624 fa28adbf
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
const baseUrl = 'https://luckiiapi.q-gp.com/yapi/mock/325'; const baseUrl = 'https://luckii-qa.liangkebang.net';
const request = async (url, options) => { const request = async (url, options) => {
const pages = getCurrentPages();
const safeAreaInsetTop = pages && pages.length > 0 ? pages[pages.length - 1].route === 'pages/index' : false;
const defaultOptions = { const defaultOptions = {
method: 'post', method: 'post',
header: { 'content-type': 'applicction/x-www-form-urlencoded' } header: { 'content-type': 'applicction/x-www-form-urlencoded' }
}; };
options = { ...defaultOptions, ...options }; options = { ...defaultOptions, ...options };
options.header = {
...options.header,
openid: wx.getStorageSync('openId') || ''
};
url = baseUrl + url; url = baseUrl + url;
const isConnected = wx.getStorageSync('onNetworkStatusChange'); const isConnected = wx.getStorageSync('onNetworkStatusChange');
...@@ -31,11 +38,10 @@ const request = async (url, options) => { ...@@ -31,11 +38,10 @@ const request = async (url, options) => {
if (res.data.code === 2000) { if (res.data.code === 2000) {
return res.data.data; return res.data.data;
} }
Notify({ message: res.data.detail || '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop });
throw new Error(res.data.detail || '请求异常,请稍后重试');
} }
Notify({ message: res.data.detail || '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true }); Notify({ message: '请求异常,请稍后重试', background: '#FF5D15', safeAreaInsetTop });
}).catch(res => {
Notify({ message: '请求失败,请稍后重试', background: '#FF5D15', safeAreaInsetTop: true });
}); });
}; };
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</div> </div>
<div class="popup-item"> <div class="popup-item">
<button class="help-button" open-type="contact"></button> <button class="help-button" open-type="contact"></button>
<image class="image" src="/static/images/help@2x.png"></image> <image class="image" src="/static/images/feedback@2x.png"></image>
<span class="desc">问题反馈</span> <span class="desc">问题反馈</span>
</div> </div>
</div> </div>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
data: { data: {
menus: [ menus: [
{ img: '/static/images/awards@2x.png', title: '我的抽奖', path: '/pages/myraffles' }, { img: '/static/images/awards@2x.png', title: '我的抽奖', path: '/pages/myraffles' },
{ img: '/static/images/feedback@2x.png', title: '规则与帮助', path: '/pages/help' }, { img: '/static/images/help@2x.png', title: '规则与帮助', path: '/pages/help' }
], ],
show: false, show: false,
popupStyle: '' popupStyle: ''
......
...@@ -131,6 +131,9 @@ ...@@ -131,6 +131,9 @@
} }
}, },
gold(v) { gold(v) {
if (v) {
this.addCount = 0;
}
if (this.isFirst) { if (this.isFirst) {
this.isFirst = false; this.isFirst = false;
return; return;
...@@ -171,7 +174,6 @@ ...@@ -171,7 +174,6 @@
created() { created() {
let statusHeight = this.$app.$options.globalData.statusBarHeight || ''; let statusHeight = this.$app.$options.globalData.statusBarHeight || '';
statusHeight && (this.containerStyle = 'position:relative; top:' + statusHeight + 'px'); statusHeight && (this.containerStyle = 'position:relative; top:' + statusHeight + 'px');
console.log(this.type, this.$app.$options.globalData.statusBarHeight, this.containerStyle);
} }
}); });
</script> </script>
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
line-height: 20rpx; line-height: 20rpx;
} }
.orange { .orange {
width: 0;
height:100%; height:100%;
transition:all 1s; transition:all 1s;
background-color: #FF5D15; background-color: #FF5D15;
...@@ -84,10 +85,10 @@ ...@@ -84,10 +85,10 @@
</video> < !--> </video> < !-->
<view class="rightcont"> <view class="rightcont">
<view class="info">奖品库存: 1/8</view> <view class="info">奖品库存: 1/8</view>
<view class="info">中奖概率: {{userAccount}}/3000</view> <view class="info">中奖概率: {{item.probability}}</view>
<view class="progress"> <view class="progress">
<view class="text">{{progress}}%</view> <view class="text">{{item.progress}}</view>
<view class="orange" style="{{progressStyle}}"></view> <view class="orange" style="{{item.progressStyle}}"></view>
</view> </view>
</view> </view>
<!-- <video-loading v-if="item.time === 0"/> --> <!-- <video-loading v-if="item.time === 0"/> -->
...@@ -99,6 +100,8 @@ ...@@ -99,6 +100,8 @@
</template> </template>
<script> <script>
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import { getProbability } from '../../common/raffleProbability';
import { getAwardsDetail } from '../../common/api.js';
wepy.component({ wepy.component({
props: { props: {
videoList: { videoList: {
...@@ -133,27 +136,94 @@ ...@@ -133,27 +136,94 @@
_invalidUp: 0, _invalidUp: 0,
_invalidDown: 0, _invalidDown: 0,
_videoContexts: [], _videoContexts: [],
progress: 0,
progressStyle: '',
loading: false loading: false
}, },
watch: { watch: {
videoList () { videoList () {
const newVal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; const newVal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this.loading = false; this.loading = false;
this.init();
if (newVal.length) this._videoListChanged(newVal); if (newVal.length) this._videoListChanged(newVal);
this.compute(this.userAccount);
},
userAccount(newVal) {
this.compute(newVal);
} }
}, },
attached() { attached() {
this.progress = 47;
this.progressStyle = 'width:' + this.progress + '%';
this._videoContexts = [ this._videoContexts = [
wx.createVideoContext('video_0', this.$wx), wx.createVideoContext('video_0', this.$wx),
wx.createVideoContext('video_1', this.$wx), wx.createVideoContext('video_1', this.$wx),
wx.createVideoContext('video_2', this.$wx) wx.createVideoContext('video_2', this.$wx)
]; ];
}, },
created() {
this.compute(this.userAccount);
},
methods: { methods: {
compute (newVal) {
this.nextQueue.forEach(v => {
v.probability = getProbability(+newVal, +v.coinQuantity);
});
this.curQueue.forEach(v => {
v.probability = getProbability(+newVal, +v.coinQuantity);
});
this.prevQueue.forEach(v => {
v.probability = getProbability(+newVal, +v.coinQuantity);
});
this.curQueue = [...this.curQueue];
this.nextQueue = [...this.nextQueue];
this.prevQueue = [...this.prevQueue];
},
async getProgress(id) {
const detail = await getAwardsDetail();
const progress = Math.round((detail.join / detail.quantity) * 100) + '%';
this.nextQueue.forEach(v => {
if (v.id === id) {
if (v.id === id) {
v.progress = progress;
v.batchId = detail.id;
v.progressStyle = 'width:' + progress;
}
}
});
this.curQueue.forEach(v => {
if (v.id === id) {
v.progress = progress;
v.batchId = detail.id;
v.progressStyle = 'width:' + progress;
}
});
this.prevQueue.forEach(v => {
if (v.id === id) {
v.progress = progress;
v.batchId = detail.id;
v.progressStyle = 'width:' + progress;
}
});
this.curQueue = [...this.curQueue];
this.nextQueue = [...this.nextQueue];
this.prevQueue = [...this.prevQueue];
},
init() {
this.pause = false;
this.nextQueue = [];
this.prevQueue = [];
this.curQueue = [];
this.circular = false;
this._last = 1;
this._change = -1;
this._invalidUp = 0;
this._invalidDown = 0;
this._videoContexts = [];
this.loading = false;
},
_videoListChanged (newVal) { _videoListChanged (newVal) {
newVal.forEach((item, index) => { newVal.forEach((item, index) => {
item.time = 0; item.time = 0;
...@@ -178,8 +248,6 @@ ...@@ -178,8 +248,6 @@
const direction = diff === 1 || diff === -2 ? 'up' : 'down'; const direction = diff === 1 || diff === -2 ? 'up' : 'down';
if (direction === 'up') { if (direction === 'up') {
if (this._invalidDown === 0) { if (this._invalidDown === 0) {
// console.log(this.nextQueue, this.nextQueue.length, this.prevQueue, this.prevQueue.length);
// if (this.nextQueue.length === 0) {this.nextQueue.push(this.prevQueue.shift())}
const change = (this._change + 1) % 3; const change = (this._change + 1) % 3;
const add = this.nextQueue.shift(); const add = this.nextQueue.shift();
const remove = this.curQueue[change]; const remove = this.curQueue[change];
...@@ -197,7 +265,6 @@ ...@@ -197,7 +265,6 @@
} }
if (direction === 'down') { if (direction === 'down') {
if (this._invalidUp === 0) { if (this._invalidUp === 0) {
// if (this.prevQueue.length === 0) {this.prevQueue.push(this.nextQueue.pop())}
const _change2 = this._change; const _change2 = this._change;
const _remove = this.curQueue[_change2]; const _remove = this.curQueue[_change2];
const _add = this.prevQueue.pop(); const _add = this.prevQueue.pop();
...@@ -214,13 +281,6 @@ ...@@ -214,13 +281,6 @@
} }
} }
this.circular = true; this.circular = true;
// if (this.nextQueue.length === 0 && current !== 0) {
// this.circular = false;
// }
// if (this.prevQueue.length === 0 && current !== 2) {
// console.log('circular2');
// this.circular = false;
// }
}); });
}, },
onWaiting (e) { onWaiting (e) {
...@@ -244,7 +304,17 @@ ...@@ -244,7 +304,17 @@
this.curQueue = [...this.curQueue]; this.curQueue = [...this.curQueue];
} }
}, },
playCurrent(current) { async playCurrent(current) {
await this.getProgress(this.curQueue[current].id);
const { batchId, photoUrl, name, probability, progress } = this.curQueue[current];
this.$emit('getAwardsInfo', {
batchId,
photoUrl,
quantity: this.userAccount,
name,
chance: probability,
progress: progress
});
this._videoContexts.forEach((ctx, index) => { this._videoContexts.forEach((ctx, index) => {
if (index !== current) { if (index !== current) {
ctx.pause(); ctx.pause();
......
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
<view class="video-wrapper"> <view class="video-wrapper">
<view id="myvideo"> <view id="myvideo">
<van-notify id="van-notify" /> <van-notify id="van-notify" />
<video-list :videoList.sync="videoList" :userAccount="mainInfo && mainInfo.account && mainInfo.account.quantity || 0" :total="total" bindchange="changeVideo"> <video-list :videoList.sync="videoList" :userAccount="mainInfo && mainInfo.account && mainInfo.account.quantity || 0" :total="total" bindchange="changeVideo" @getAwardsInfo="getAwardsInfo">
</video-list> </video-list>
</view> </view>
<view class="userInfo" style="{{userImgStyle}}" @tap="showMenu(!showMenus)"> <view class="userInfo" style="{{userImgStyle}}" @tap="showMenu(!showMenus)">
...@@ -194,7 +194,7 @@ ...@@ -194,7 +194,7 @@
</swiper> </swiper>
</view> </view>
</view> </view>
<!--<view class="footer"> <!-- <view class="footer">
<swiper <swiper
class="footswiper" class="footswiper"
display-multiple-items="{{swiperItem}}" display-multiple-items="{{swiperItem}}"
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</view> </view>
</swiper-item> </swiper-item>
</swiper> </swiper>
</view>--> </view> -->
<view class="authmodal" v-show="authmodal"> <view class="authmodal" v-show="authmodal">
<view class="wrap"> <view class="wrap">
<view class="text">来到lukii,再平凡的人,<br>也有幸运的权利!</view> <view class="text">来到lukii,再平凡的人,<br>也有幸运的权利!</view>
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
import { mapState, mapActions } from '@wepy/x'; import { mapState, mapActions } from '@wepy/x';
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
import { register, getUserInfo, addGold, getPrizeList } from '../common/api.js'; import { register, getUserInfo, addGold, getPrizeList, signIn } from '../common/api.js';
wepy.page({ wepy.page({
store, store,
hooks: { hooks: {
...@@ -275,7 +275,8 @@ ...@@ -275,7 +275,8 @@
inviter: '', inviter: '',
mainInfo: null, mainInfo: null,
showShareModal: false, showShareModal: false,
showAwardsModal: false showAwardsModal: false,
awardsInfo: {}
}, },
computed: { computed: {
...@@ -339,7 +340,6 @@ ...@@ -339,7 +340,6 @@
}, },
toViewPage(e) { toViewPage(e) {
let item = e.$wx.currentTarget.dataset.item; let item = e.$wx.currentTarget.dataset.item;
// console.log(sku,12)
// 解决长按触发tap事件的bug // 解决长按触发tap事件的bug
wx.navigateToMiniProgram({ wx.navigateToMiniProgram({
appId: 'wx91d27dbf599dff74', appId: 'wx91d27dbf599dff74',
...@@ -405,7 +405,6 @@ ...@@ -405,7 +405,6 @@
}, },
async getUserInfo (e) { async getUserInfo (e) {
if (e.$wx.detail.userInfo) { if (e.$wx.detail.userInfo) {
console.log('userInfo', e.$wx.detail.userInfo);
this.setUserInfo(e.$wx.detail.userInfo); this.setUserInfo(e.$wx.detail.userInfo);
await this.getMainInfo(); await this.getMainInfo();
this.authmodal = false; this.authmodal = false;
...@@ -421,7 +420,6 @@ ...@@ -421,7 +420,6 @@
}, },
changeVideo(e) { changeVideo(e) {
this.setIsConnected(); this.setIsConnected();
console.log(this.length, e.activeId);
// if (this.length - e.activeId === 1) { // if (this.length - e.activeId === 1) {
// this.videoList = [{id: e.activeId + 2, url: 'https://ip1707952229.mobgslb.tbcache.com/youku/6974c3708c0337150e1743b1c/03000801005EA2A6C8FB4C2003E8807282A547-8207-4F52-9663-969096765248.mp4?sid=158960247500010009412_00_Bac09720260d484f23ac2ccebe5206930&sign=b76f4099e108fc306d3db993d1bec0a8&ctype=50&ali_redirect_domain=vali.cp31.ott.cibntv.net&ali_redirect_ex_ftag=5898cd25832bbff232de6d9fa668e8ddf8bacc5fef3f2e7b&ali_redirect_ex_tmining_ts=1589602477&ali_redirect_ex_tmining_expire=3600&ali_redirect_ex_hot=111'}]; // this.videoList = [{id: e.activeId + 2, url: 'https://ip1707952229.mobgslb.tbcache.com/youku/6974c3708c0337150e1743b1c/03000801005EA2A6C8FB4C2003E8807282A547-8207-4F52-9663-969096765248.mp4?sid=158960247500010009412_00_Bac09720260d484f23ac2ccebe5206930&sign=b76f4099e108fc306d3db993d1bec0a8&ctype=50&ali_redirect_domain=vali.cp31.ott.cibntv.net&ali_redirect_ex_ftag=5898cd25832bbff232de6d9fa668e8ddf8bacc5fef3f2e7b&ali_redirect_ex_tmining_ts=1589602477&ali_redirect_ex_tmining_expire=3600&ali_redirect_ex_hot=111'}];
// this.length += 1; // this.length += 1;
...@@ -457,13 +455,14 @@ ...@@ -457,13 +455,14 @@
}, 500); }, 500);
} }
}, },
signIn: function() { signIn: async function() {
let that = this; let that = this;
const tmplIds = [ const tmplIds = [
'xbA7XopO2j0V0Ne0F61UzSxoyfKrf92GQk6Z4pQvnd4', 'xbA7XopO2j0V0Ne0F61UzSxoyfKrf92GQk6Z4pQvnd4',
'_yZWJYT-3lGCQG6g7Wa7F-0zxvGaPe4zwAI9D4zW4EY', '_yZWJYT-3lGCQG6g7Wa7F-0zxvGaPe4zwAI9D4zW4EY',
'7YzXgiVNGXiRvXNmR6WUtH_WplUyo97eAy45dsyviKQ' '7YzXgiVNGXiRvXNmR6WUtH_WplUyo97eAy45dsyviKQ'
]; ];
wx.requestSubscribeMessage({ wx.requestSubscribeMessage({
tmplIds: [ tmplIds: [
'xbA7XopO2j0V0Ne0F61UzSxoyfKrf92GQk6Z4pQvnd4', 'xbA7XopO2j0V0Ne0F61UzSxoyfKrf92GQk6Z4pQvnd4',
...@@ -471,16 +470,12 @@ ...@@ -471,16 +470,12 @@
'7YzXgiVNGXiRvXNmR6WUtH_WplUyo97eAy45dsyviKQ' '7YzXgiVNGXiRvXNmR6WUtH_WplUyo97eAy45dsyviKQ'
], ],
success (res) { success (res) {
console.log('requestSubscribeMessage success', res);
if (res.errMsg === 'requestSubscribeMessage:ok') { if (res.errMsg === 'requestSubscribeMessage:ok') {
const rs = tmplIds.some(v => res[v] === 'accept'); const rs = tmplIds.some(v => res[v] === 'accept');
if (rs) { if (rs) {
that.sign = true; that.sign = true;
// if (!that.sign) {
// that.showAnimation = false; setTimeout(() => {
// timeout = null;
// timeout1 = null;
// } else {
const innerAudioContext = wx.createInnerAudioContext(); const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.autoplay = true; innerAudioContext.autoplay = true;
innerAudioContext.src = '/static/audio/supermarie.mp3'; innerAudioContext.src = '/static/audio/supermarie.mp3';
...@@ -491,17 +486,11 @@ ...@@ -491,17 +486,11 @@
console.log(res.errMsg); console.log(res.errMsg);
console.log(res.errCode); console.log(res.errCode);
}); });
// setTimeout(() => { that.mainInfo.account.quantity += 1;
// that.showAnimation = that.sign; signIn();
// setTimeout(() => { }, 1500);
// const num = [1, 2, 4, 501, 2501, 5001];
// that.goldNum = 1;
// }, 600);
// }, 1100);
// }
} else { } else {
Notify({message: '请先勾选协议!', background: '#FF5D15', safeAreaInsetTop: true }); Notify({ message: '签到必须同意推送授权!', background: '#FF5D15', safeAreaInsetTop: true });
// Notify({ backgroundColor: '#ff976a', text: '签到必须同意推送授权', safeAreaInsetTop: true });
} }
} }
}, },
...@@ -532,13 +521,15 @@ ...@@ -532,13 +521,15 @@
}; };
}, },
getAwards: function() { getAwards: function() {
const { batchId, photoUrl, quantity, name, chance, progress } = this.awardsInfo;
wx.navigateTo({ wx.navigateTo({
url: '/pages/raffle?batchId=1&progress=70&chance=1/780&quantity=50000&photoUrl=/static/images/test2.png&name=Nintendo Switch任天堂游戏机任天堂游戏机' url: `/pages/raffle?batchId=${batchId}&progress=${progress}&chance=${chance}&photoUrl=${photoUrl}&quantity=${quantity}&name=${name}`
}); });
// this.awards = !this.awards; },
getAwardsInfo: function(v) {
this.awardsInfo = v;
}, },
showMenu: function(v) { showMenu: function(v) {
console.log(v);
this.showMenus = v; this.showMenus = v;
}, },
getSharedGold: async function(v) { getSharedGold: async function(v) {
...@@ -565,7 +556,6 @@ ...@@ -565,7 +556,6 @@
let self = this; let self = this;
let statusHeight = this.$app.$options.globalData.statusBarHeight || ''; let statusHeight = this.$app.$options.globalData.statusBarHeight || '';
statusHeight && (this.userImgStyle = 'top:' + statusHeight + 'px'); statusHeight && (this.userImgStyle = 'top:' + statusHeight + 'px');
console.log(this.userImgStyle);
if (store.state.userInfo) { if (store.state.userInfo) {
this.userInfo = store.state.userInfo; this.userInfo = store.state.userInfo;
} else { } else {
...@@ -617,7 +607,6 @@ ...@@ -617,7 +607,6 @@
]; ];
// console.log(this.$app.$options.globalData.info,111) // console.log(this.$app.$options.globalData.info,111)
// 如果已经存在store里就不用再获取用户信息了 // 如果已经存在store里就不用再获取用户信息了
console.log('userInfo', this.userInfo);
if (!this.userInfo) { if (!this.userInfo) {
const setting = await wepy.wx.getSetting(); const setting = await wepy.wx.getSetting();
if (setting.authSetting['scope.userInfo']) { if (setting.authSetting['scope.userInfo']) {
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<template> <template>
<view class="raffle-wrapper"> <view class="raffle-wrapper">
<view class="raffle-content"> <view class="raffle-content">
<van-image use-loading-slot src="{{photoUrl}}" class="img" width="610rpx" height="610rpx" radius="10rpx"> <van-image use-loading-slot src="{{photoUrl}}" class="img" width="610rpx" height="610rpx" radius="10rpx" fit="cover">
<van-loading slot="loading" type="spinner" size="20" vertical /> <van-loading slot="loading" type="spinner" size="20" vertical />
</van-image> </van-image>
<view class="goodsinfo"> <view class="goodsinfo">
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
<view class="progress"> <view class="progress">
<view class="orange" style="{{progressStyle}}"></view> <view class="orange" style="{{progressStyle}}"></view>
</view> </view>
<text class="pronumber">{{progress}}%</text> <text class="pronumber">{{progress}}</text>
</view> </view>
</view> </view>
<view class="user-wish" bindtap="check"> <view class="user-wish" bindtap="check">
...@@ -139,10 +139,12 @@ ...@@ -139,10 +139,12 @@
import wepy from '@wepy/core'; import wepy from '@wepy/core';
import Notify from '../components/vant/notify/notify'; import Notify from '../components/vant/notify/notify';
import Dialog from '../components/vant/dialog/dialog'; import Dialog from '../components/vant/dialog/dialog';
import { updateUserPhone, confirmRaffle } from '../common/api' import { updateUserPhone, confirmRaffle, register } from '../common/api'
import store from '../store';
wepy.page({ wepy.page({
store,
data: { data: {
progress: 0, progress: '0%',
progressStyle: '', progressStyle: '',
isCheck: false, isCheck: false,
batchId: null, batchId: null,
...@@ -160,6 +162,11 @@ ...@@ -160,6 +162,11 @@
let title = ['参与成功!','参与失败!','参与失败!']; let title = ['参与成功!','参与失败!','参与失败!'];
let message = ['','当前抽奖已结束。','当前奖品已经没有库存了。'] let message = ['','当前抽奖已结束。','当前奖品已经没有库存了。']
let detail = e.$wx.detail || {}; let detail = e.$wx.detail || {};
let isRegister = wx.getStorageSync('isRegister');
//如果用户还未注册
if(isRegister === false) {
await register(store.state.userInfo);
}
if(detail.encryptedData) { if(detail.encryptedData) {
wx.checkSession({ wx.checkSession({
success () { success () {
...@@ -216,7 +223,7 @@ ...@@ -216,7 +223,7 @@
let {batchId, quantity, name, chance, photoUrl, progress} = query; let {batchId, quantity, name, chance, photoUrl, progress} = query;
if (progress) { if (progress) {
this.progress = progress; this.progress = progress;
this.progressStyle = 'width:' + progress + '%'; this.progressStyle = 'width:' + progress;
} }
this.batchId = batchId; this.batchId = batchId;
this.quantity = quantity; this.quantity = quantity;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment