mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-06-11 12:49:30 +08:00
fix: 修复投票状态显示问题
This commit is contained in:
@@ -31,4 +31,56 @@ export const voteCacheUtil = {
|
||||
}
|
||||
uni.setStorageSync(UnihaloVoteUid, JSON.stringify(data))
|
||||
}
|
||||
}
|
||||
|
||||
export const VOTE_TYPES = {
|
||||
"pk": "双选PK",
|
||||
"multiple": "多选",
|
||||
"single": "单选"
|
||||
}
|
||||
|
||||
export const VOTE_STATES = {
|
||||
"未开始": {
|
||||
state: "未开始",
|
||||
color: "orange"
|
||||
},
|
||||
"进行中": {
|
||||
state: "进行中",
|
||||
color: "green"
|
||||
},
|
||||
"已结束": {
|
||||
state: "已结束",
|
||||
color: "red"
|
||||
},
|
||||
}
|
||||
|
||||
export const calcVoteState = (vote) => {
|
||||
if (vote.spec.timeLimit !== 'custom') {
|
||||
return vote.spec.hasEnded ? VOTE_STATES["已结束"] : VOTE_STATES["进行中"]
|
||||
}
|
||||
|
||||
const nowTime = new Date().getTime()
|
||||
const startTime = new Date(vote.spec.startDate).getTime()
|
||||
const endTime = new Date(vote.spec.endDate).getTime()
|
||||
|
||||
if (nowTime < startTime) {
|
||||
return VOTE_STATES["未开始"]
|
||||
}
|
||||
if (nowTime < endTime) {
|
||||
return VOTE_STATES["进行中"]
|
||||
}
|
||||
return vote.spec.hasEnded ? VOTE_STATES["已结束"] : VOTE_STATES["进行中"]
|
||||
}
|
||||
|
||||
export const calcVotePercent = (vote, voteOption) => {
|
||||
if (!vote || !voteOption) return 0
|
||||
const votedDataList = vote?.stats?.voteDataList || []
|
||||
if (votedDataList.length == 0) return 0
|
||||
const voteCount = vote?.stats?.voteCount || 0
|
||||
if (voteCount == 0) return 0
|
||||
|
||||
const _voteOption = votedDataList.find(x => x.id == voteOption.id)
|
||||
if (!_voteOption) return 0;
|
||||
const percent = (_voteOption.voteCount / voteCount) * 100
|
||||
return Math.round(percent)
|
||||
}
|
||||
Reference in New Issue
Block a user