v2.2.4 2022-10-28

1.更新部分代码
This commit is contained in:
2022-10-28 22:35:00 +08:00
parent 385946bc85
commit bb7d4ae74a
6 changed files with 305 additions and 150 deletions
+1 -1
View File
@@ -1,4 +1,5 @@
{ {
"pages": [{ "pages": [{
"path": "pages/home/home", "path": "pages/home/home",
"style": { "style": {
@@ -81,7 +82,6 @@
"navigationBarTitleText": "随机骰子", "navigationBarTitleText": "随机骰子",
"navigationBarBackgroundColor": "#f6f7f9" "navigationBarBackgroundColor": "#f6f7f9"
} }
}, { }, {
"path": "pages/subpages/choujiangzhushou/choujiangzhushou", "path": "pages/subpages/choujiangzhushou/choujiangzhushou",
"style": { "style": {
+2 -2
View File
@@ -30,11 +30,11 @@
<text class="i-name">开发日志</text> <text class="i-name">开发日志</text>
<text class="i-more iconfont icon-arrow-right"></text> <text class="i-more iconfont icon-arrow-right"></text>
</button> </button>
<button class="item love" @tap="admire()"> <!-- <button class="item love" @tap="admire()">
<image class="i-icon" src="/static/icons/icon_love.png" mode="widthFix"></image> <image class="i-icon" src="/static/icons/icon_love.png" mode="widthFix"></image>
<text class="i-name">捐赠作者</text> <text class="i-name">捐赠作者</text>
<text class="i-more iconfont icon-arrow-right"></text> <text class="i-more iconfont icon-arrow-right"></text>
</button> </button> -->
<button class="item share" open-type="share"> <button class="item share" open-type="share">
<image class="i-icon" src="/static/icons/icon_share.png" mode="widthFix"></image> <image class="i-icon" src="/static/icons/icon_share.png" mode="widthFix"></image>
<text class="i-name">分享好友</text> <text class="i-name">分享好友</text>
@@ -60,9 +60,11 @@
<!-- 我的抽奖 --> <!-- 我的抽奖 -->
<view class="gift-history"> <view class="gift-history">
<!-- <text class="history-tip">我的抽奖</text> --> <!-- <text class="history-tip">我的抽奖</text> -->
<view class="item item-history" v-for="(item,index) in giftList" :key="index"> <view class="item item-history" v-for="(item,index) in awardList" :key="index" @tap="turnTo(item.id)" @longtap="del(item.id)" :hidden="item.isDelete==1">
<text class="item-tip">{{item.name}}</text> <text class="item-tip">{{item.awardName}}</text>
<text class="item-tip">{{item.open?'已开奖':'待开奖'}}</text> <text class="item-tip award-detail">{{item.awardDetail}}</text>
<text class="item-tip"
:class="item.isOpened == 1?'award-opened':'award-unopened'">{{item.isOpened==1?'已开奖':'待开奖'}}</text>
</view> </view>
</view> </view>
<!-- 发起抽奖 --> <!-- 发起抽奖 -->
@@ -94,7 +96,7 @@
openNeedUsers: 0, openNeedUsers: 0,
awardId: '', awardId: '',
isCreate: false, isCreate: false,
giftList: [] awardList: []
} }
}, },
computed: { computed: {
@@ -105,6 +107,9 @@
return this.getDate('end'); return this.getDate('end');
} }
}, },
onLoad() {
this.init();
},
methods: { methods: {
changeImage() { changeImage() {
const that = this; const that = this;
@@ -148,28 +153,38 @@
// 发起抽奖 // 发起抽奖
start() { start() {
const that = this; const that = this;
if(that.awardName=='') { if (that.awardName == '') {
that.toast('奖品名称','error'); that.toast('奖品名称', 'error');
return; return false;
} }
if(that.awardNum == 0) { if (that.awardNum == 0) {
that.toast('奖品数量','error'); that.toast('奖品数量', 'error');
return; return false;
} }
if(that.awardDetail == '') { if (that.awardDetail == '') {
that.toast('奖品说明','error'); that.toast('奖品说明', 'error');
return; return false;
} }
if((that.typeIndex == 1)&&(that.openNeedUsers == 0)) { if ((that.typeIndex == 1) && (that.openNeedUsers == 0)) {
that.toast('抽奖人数','error'); that.toast('抽奖人数', 'error');
return; return false;
} }
if((that.typeIndex == 1)&&(that.awardNum >= that.openNeedUsers)) { if ((that.typeIndex == 1) && (that.awardNum >= that.openNeedUsers)) {
that.toast('奖品太多','error'); that.toast('奖品太多', 'error');
return; return false;
} }
const openDateTime = this.date + ' ' + this.time; const openDateTime = this.date + ' ' + this.time;
const startDateTime = this.getDate() + ' ' + this.getTime(); const startDateTime = this.getDate() + ' ' + this.getTime();
const pretime = new Date(startDateTime);
const opentime = new Date(openDateTime);
if ((that.typeIndex == 0)&&(pretime >= opentime)) {
that.toast("时光倒流", 'error');
return false;
}
if ((that.typeIndex == 0)&&(opentime.getTime() - pretime.getTime() < 300000)) {
that.toast(((opentime.getTime() - pretime.getTime()) / 60000) + "分钟太短", 'error');
return false;
}
let rst = { let rst = {
ownerId: app.globalData.openId, ownerId: app.globalData.openId,
ownerImage: app.globalData.userInfo.avatarUrl, ownerImage: app.globalData.userInfo.avatarUrl,
@@ -192,7 +207,7 @@
method: 'POST', method: 'POST',
data: rst, data: rst,
success(res) { success(res) {
console.log(res); console.log("1.加入抽奖",res);
if (res.data.err == 1) { if (res.data.err == 1) {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
@@ -203,6 +218,7 @@
if (that.awardId != '') { if (that.awardId != '') {
that.isCreate = true; that.isCreate = true;
} }
that.init();
} else if (res.data.err == 0) { } else if (res.data.err == 0) {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
@@ -219,6 +235,35 @@
} }
}) })
}, },
del(id) {
const that = this;
uni.showModal({
title:'提示',
content:'是否删除此次抽奖',
confirmText:'是的',
cancelText:'点错了',
success(res) {
if(res.confirm) {
uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/delAwardInfo.php',
method: 'POST',
data: {
openId: app.globalData.openId,
awardId: id
},
success(res) {
if(res.data.err == 1){
that.init();
} else {
that.toast("删除失败", 'error');
}
}
});
}
}
})
},
getDate(type) { getDate(type) {
const date = new Date(); const date = new Date();
let year = date.getFullYear(); let year = date.getFullYear();
@@ -226,9 +271,11 @@
let day = date.getDate(); let day = date.getDate();
if (type === 'start') { if (type === 'start') {
year = year - 60; year = year;
month = month;
} else if (type === 'end') { } else if (type === 'end') {
year = year + 2; year = year;
month = month + 1;
} }
month = month > 9 ? month : '0' + month; month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day; day = day > 9 ? day : '0' + day;
@@ -247,6 +294,28 @@
title: title, title: title,
icon: icon icon: icon
}) })
},
turnTo(id) {
console.log('2.抽奖跳转');
uni.navigateTo({
url: '/pages/subpages/choujiangzhushou/jiaruchoujiang?awardId=' + id,
})
},
init() {
const that = this;
uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/getUserAward.php',
method: 'POST',
data: {
'openId': app.globalData.openId
},
success(res) {
console.log('1.获取用户所建抽奖', res);
if (res.data.result) {
that.awardList = res.data.result;
}
}
})
} }
}, },
onShareAppMessage() { onShareAppMessage() {
@@ -263,7 +332,7 @@
icon: 'error' icon: 'error'
}) })
} }
} },
} }
</script> </script>
@@ -374,7 +443,7 @@
display: block; display: block;
width: auto; width: auto;
justify-content: space-between; justify-content: space-between;
float:right; float: right;
/* background-color: red; */ /* background-color: red; */
margin-right: 10px; margin-right: 10px;
} }
@@ -383,6 +452,7 @@
flex: 7; flex: 7;
text-align: right; text-align: right;
} }
.picker-time { .picker-time {
flex: 1; flex: 1;
} }
@@ -434,4 +504,25 @@
border-radius: 0; border-radius: 0;
border-bottom: 3px solid white; border-bottom: 3px solid white;
} }
/* 所有开奖 */
/* 开奖详情 */
.award-detail {
font-size: 14px;
color: #888888;
text-align: left;
}
/* 开奖情况 */
.award-opened {
font-size: 12px;
color: #888888;
text-align: right;
}
.award-unopened {
font-size: 12px;
color: red;
text-align: right;
}
</style> </style>
+177 -117
View File
@@ -36,6 +36,7 @@
userId: 0, userId: 0,
joinList: [], joinList: [],
joinCount: 0, joinCount: 0,
requestStatus: false,
isOpened: false, isOpened: false,
isJoin: false, isJoin: false,
isClick: false, isClick: false,
@@ -45,61 +46,39 @@
onLoad(option) { onLoad(option) {
const that = this; const that = this;
that.awardId = option.awardId; that.awardId = option.awardId;
uni.showLoading({
title: '正在加载...',
icon: 'loading'
})
that.refresh(); that.refresh();
}, },
methods: { methods: {
join() { async join() {
const that = this; const that = this;
uni.showLoading({ if(that.requestStatus) {
title: '正在加入', uni.showToast({
icon: 'loading' title: '点的太快了',
}); icon: 'error',
uni.request({ });
url: app.globalData return false;
.website + }
"/tools/choujiangzhushou/userJoin.php", if((!that.userId)||(that.userId == 0)||(that.userId == '')){
method: 'POST', uni.showToast({
data: { title: '加入失败',
awardId: that.awardId, icon: 'loading'
userId: that.userId });
}, return false;
success(res1) { }else {
console.log('5.用户加入', res1); uni.showLoading({
uni.hideLoading(); title: '正在加入',
if (res1.data.err == 0) { icon: 'loading'
uni.showToast({ });
title: '加入失败', await that.joinAward();
icon: 'error', }
}); that.requestStatus = true;
} else if (res1.data.err == 1) { setTimeout(()=>{
uni.showToast({ that.requestStatus = false;
title: '加入成功', }, 2000);
icon: 'success'
})
that.isJoin = true;
} else if (res1.data.err == 2) {
that.isClick = false;
uni.showLoading({
title: '正在开奖中',
icon: 'loading'
});
// 是否中奖
that.checkLuckyClover();
} else if (res1.data.err == 3) {
that.isClick = false;
uni.showToast({
title: "开奖失败",
icon: 'error'
})
} else {
uni.showModal({
title: '提示',
content: res1.data.msg
})
}
that.refresh();
}
});
}, },
load() { load() {
var msg = '条件'; var msg = '条件';
@@ -114,11 +93,99 @@
content: msg, content: msg,
}) })
}, },
refresh() { async refresh() {
const that = this; const that = this;
that.joinList = []; that.joinList = [];
that.isJoin = false; that.isJoin = false;
that.isClick = false; that.isClick = false;
// 1.通过奖品号获取奖品信息
await that.getAwardInfo();
// 2.通过openId获取用户Id
await that.getUserId();
// 3.通过奖品Id获取参与用户ID
await that.showUsers();
// 若开奖停用按钮
if (that.isLockyClover) {
that.isClick = false;
uni.hideLoading();
}
if (that.isOpened) {
that.isClick = false;
}
},
checkLuckyClover() {
const that = this;
uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/checkLuckyClover.php',
method: 'POST',
data: {
awardId: that.awardId,
userId: that.userId
},
success(res) {
console.log('6.查看是否中奖', res);
uni.hideLoading();
if (res.data.result.length > 0) {
that.isLockyClover = (res.data.result[0].luckyClover == 1);
}
}
})
},
showUsers() {
const that = this;
// 通过奖品ID查询各种信息
uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/joinUserInfo.php',
method: 'POST',
data: {
awardId: that.awardId
},
success(res) {
console.log('3.通过奖品Id获取参与用户ID', res);
const users = res.data.result;
that.joinUserID = users;
that.joinCount = Number(users.length);
for (var i = 0; i < users.length; i++) {
const user = users[i];
uni.request({
url: app.globalData.website + '/api/getUserInfoById.php',
method: 'POST',
data: {
id: user.userId
},
success(res1) {
console.log('4.通过userId获取用户信息(图像)', res1);
for (var i = 0; i < res1.data.result.length; i++) {
that.joinList.push({
userImg: res1.data.result[0].avatarUrl
});
}
}
});
if (user.userId == that.userId) {
that.isJoin = true;
console.log("用户已参与抽奖");
}
}
setTimeout(function() {
uni.hideLoading();
if(!that.isOpened){
that.isClick = true;
}
}, 1000);
// 若开奖,查看是否中奖品,放这里因为这里产生userId
if(that.isOpened) {
// 检测是否中奖
that.checkLuckyClover();
}
},
fail(res) {
console.log('访问失败', res);
}
});
},
getAwardInfo() {
const that = this;
// 请求奖品信息 // 请求奖品信息
uni.request({ uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/getAwardInfo.php', url: app.globalData.website + '/tools/choujiangzhushou/getAwardInfo.php',
@@ -144,11 +211,11 @@
icon: 'error' icon: 'error'
}) })
} }
if (that.isOpened) {
that.isClick = false;
}
} }
}); });
},
getUserId() {
const that = this;
uni.request({ uni.request({
url: app.globalData.website + "/api/getUserInfo.php", url: app.globalData.website + "/api/getUserInfo.php",
method: 'POST', method: 'POST',
@@ -159,85 +226,76 @@
console.log('2.通过openId获取用户Id', res); console.log('2.通过openId获取用户Id', res);
if (res.data.result) { if (res.data.result) {
that.userId = res.data.result[0].id; that.userId = res.data.result[0].id;
if(that.userId == 0){
uni.hideLoading();
uni.showToast({
title: '加载失败',
icon: 'error'
});
that.isClick = false;
return false;
}
} else { } else {
uni.hideLoading(); uni.hideLoading();
console.log(res); console.log('通过OpenId获取userId失败',res);
uni.showToast({ uni.showToast({
title: '加载成功', title: '加载失败',
icon: 'success' icon: 'success'
}) })
} }
// 若开奖,查看是否中奖品,放这里因为这里产生userId
if(that.isOpened) {
// 检测是否中奖
that.checkLuckyClover();
}
} }
}); });
// 通过奖品ID查询各种信息
uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/userJoinInfo.php',
method: 'POST',
data: {
awardId: that.awardId
},
success(res) {
console.log('3.通过奖品Id获取参与用户ID', res);
const users = res.data.result;
that.joinCount = Number(users.length);
for (var i = 0; i < users.length; i++) {
const user = users[i];
uni.request({
url: app.globalData.website + '/api/getUserInfoById.php',
method: 'POST',
data: {
id: user.userId
},
success(res1) {
console.log('4.通过userId获取用户信息(图像)', res1);
for (var i = 0; i < res1.data.result.length; i++) {
that.joinList.push({
userImg: res1.data.result[0].avatarUrl
});
}
}
});
if (user.userId == that.userId) {
that.isJoin = true;
}
}
setTimeout(function() {
if(!that.isOpened){
that.isClick = true;
}
}, 1000);
},
fail(res) {
console.log('访问失败', res);
}
});
// 若开奖停用按钮
if (that.isLockyClover) {
that.isClick = false;
}
}, },
checkLuckyClover() { joinAward() {
const that = this; const that = this;
uni.request({ uni.request({
url: app.globalData.website + '/tools/choujiangzhushou/isluckyClover.php', url: app.globalData
.website +
"/tools/choujiangzhushou/joinUser.php",
method: 'POST', method: 'POST',
data: { data: {
awardId: that.awardId, awardId: that.awardId,
userId: that.userId userId: that.userId
}, },
success(res) { success(res1) {
console.log('6.查看是否中奖', res); console.log('5.用户加入', res1);
uni.hideLoading(); uni.hideLoading();
if (res.data.result) { if (res1.data.err == 0) {
that.isLockyClover = res.data.result[0].luckyClover == 1; uni.showToast({
title: '加入失败',
icon: 'error',
});
} else if (res1.data.err == 1) {
uni.showToast({
title: '加入成功',
icon: 'success'
})
that.isJoin = true;
} else if (res1.data.err == 2) {
that.isClick = false;
uni.showLoading({
title: '正在开奖中',
icon: 'loading'
});
setTimeout(function(){
// 是否中奖
that.checkLuckyClover();
},2000);
} else if (res1.data.err == 3) {
that.isClick = false;
uni.showToast({
title: "开奖失败",
icon: 'error'
})
} else {
uni.showModal({
title: '提示',
content: res1.data.msg
})
} }
that.refresh();
} }
}) });
} }
}, },
onPullDownRefresh() { onPullDownRefresh() {
@@ -250,9 +308,11 @@
}, },
onShareAppMessage() { onShareAppMessage() {
return { return {
title: '参与抽奖' title: '参与 ' + this.awardName + 'x' + this.awardNum + ' 抽奖',
path: `/pages/subpages/choujiangzhushou/jiaruchoujiang?awardId=${this.awardId}`,
imageUrl: this.picUrl
} }
} },
} }
</script> </script>
+1 -1
View File
@@ -24,7 +24,7 @@
</picker> </picker>
<button class="btn-start" @tap="start()">{{sum}}</button> <button class="btn-start" @tap="start()">{{sum}}</button>
<ad class="sjtz-ad" adpid="1211145435"></ad> <!-- <ad class="sjtz-ad" adpid="1211145435"></ad> -->
</view> </view>
</template> </template>
+4
View File
@@ -35,3 +35,7 @@ v2.2.2 2022-10-25
v2.2.3 2022-10-26 v2.2.3 2022-10-26
1.实现根据人数自动开奖的功能 1.实现根据人数自动开奖的功能
v2.2.4 2022-10-28
1.更新部分代码