Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mini-program-wepy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
mini-program-wepy
Commits
44bbf8d9
Commit
44bbf8d9
authored
Jul 27, 2020
by
zhijie.xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
概率用百分比展示
parent
92ce716d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
43 deletions
+52
-43
raffleProbability.js
src/common/raffleProbability.js
+32
-17
raffleProbability.wxs
src/common/raffleProbability.wxs
+19
-2
utils.js
src/common/utils.js
+0
-23
video.wpy
src/components/custom/video.wpy
+1
-1
No files found.
src/common/raffleProbability.js
View file @
44bbf8d9
function
getCommonDivisor
(
firstNum
,
secondNum
)
{
//
function getCommonDivisor(firstNum, secondNum) {
if
(
secondNum
===
0
)
return
firstNum
;
//
if (secondNum === 0) return firstNum;
var
remainder
=
parseInt
(
firstNum
%
secondNum
);
//
var remainder = parseInt(firstNum % secondNum);
return
getCommonDivisor
(
secondNum
,
remainder
);
//
return getCommonDivisor(secondNum, remainder);
}
//
}
function
getProbability
(
quantity
,
coinQuantity
)
{
// function getProbability (quantity, coinQuantity) {
// 如果用户克币数是0
// // 如果用户克币数是0
if
(
quantity
===
0
)
{
// if (quantity === 0) {
return
'
0
'
;
// return '0';
}
// }
var
divisor
=
getCommonDivisor
(
quantity
,
coinQuantity
);
// var divisor = getCommonDivisor(quantity, coinQuantity);
var
value
=
quantity
/
divisor
;
// var value = quantity / divisor;
var
value2
=
coinQuantity
/
divisor
;
// var value2 = coinQuantity / divisor;
// 如果分子比分母大说明中奖概率是100%,那么返回中奖概率
// // 如果分子比分母大说明中奖概率是100%,那么返回中奖概率
if
(
value
>=
value2
)
{
// if (value >= value2) {
// return '100%';
// } else {
// return value + '/' + value2;
// }
// }
function
getProbabilityByPercent
(
quantity
,
coinQuantity
)
{
if
(
quantity
===
0
)
return
'
0%
'
;
const
quotient
=
quantity
/
coinQuantity
;
if
(
quotient
<
0.01
)
{
return
'
0.01%
'
;
}
else
if
(
quotient
>=
1
)
{
return
'
100%
'
;
return
'
100%
'
;
}
else
{
}
else
{
return
value
+
'
/
'
+
value2
;
const
reg
=
new
RegExp
(
'
\\
.?0+$
'
);
let
str
=
quotient
.
toFixed
(
2
);
return
str
.
replace
(
reg
,
''
)
+
'
%
'
;
}
}
}
}
...
@@ -56,6 +71,6 @@ function checkUpdateVersion() {
...
@@ -56,6 +71,6 @@ function checkUpdateVersion() {
});
});
}
}
module
.
exports
=
{
module
.
exports
=
{
getProbability
,
getProbability
:
getProbabilityByPercent
,
checkUpdateVersion
checkUpdateVersion
};
};
src/common/raffleProbability.wxs
View file @
44bbf8d9
...
@@ -4,8 +4,22 @@ function getCommonDivisor(firstNum, secondNum) {
...
@@ -4,8 +4,22 @@ function getCommonDivisor(firstNum, secondNum) {
return getCommonDivisor(secondNum, remainder);
return getCommonDivisor(secondNum, remainder);
}
}
module.exports = {
function getProbabilityByPercent(quantity, coinQuantity) {
getProbability: function (quantity, coinQuantity) {
if (quantity === 0) return '0%';
var quotient = quantity / coinQuantity;
if (quotient < 0.01) {
return '0.01%';
} else if (quotient >= 1) {
return '100%';
} else {
var reg = getRegExp('\\.?0+$')
var str = quotient.toFixed(2);
return str.replace(reg, '') + '%';
}
}
function getProbability(quantity, coinQuantity) {
if (!quantity) return 0;
if (!quantity) return 0;
// 如果用户克币数是0
// 如果用户克币数是0
if (quantity === 0) {
if (quantity === 0) {
...
@@ -21,4 +35,7 @@ module.exports = {
...
@@ -21,4 +35,7 @@ module.exports = {
return value + '/' + value2;
return value + '/' + value2;
}
}
}
}
module.exports = {
getProbability: getProbabilityByPercent
};
};
src/common/utils.js
View file @
44bbf8d9
...
@@ -55,26 +55,3 @@ export function compressShareImage(url) {
...
@@ -55,26 +55,3 @@ export function compressShareImage(url) {
}
}
return
url
;
return
url
;
}
}
function
getCommonDivisor
(
firstNum
,
secondNum
)
{
if
(
secondNum
===
0
)
return
firstNum
;
var
remainder
=
parseInt
(
firstNum
%
secondNum
);
return
getCommonDivisor
(
secondNum
,
remainder
);
}
export
function
getProbability
(
quantity
,
coinQuantity
)
{
if
(
!
quantity
)
return
0
;
// 如果用户克币数是0
if
(
quantity
===
0
)
{
return
'
0%
'
;
}
var
divisor
=
getCommonDivisor
(
quantity
,
coinQuantity
);
var
value
=
quantity
/
divisor
;
var
value2
=
coinQuantity
/
divisor
;
// 如果分子比分母大说明中奖概率是100%,那么返回中奖概率
if
(
value
>=
value2
)
{
return
'
100%
'
;
}
else
{
return
value
+
'
/
'
+
value2
;
}
}
src/components/custom/video.wpy
View file @
44bbf8d9
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
<script>
<script>
import wepy from '@wepy/core';
import wepy from '@wepy/core';
import { getAwardsDetail, getPrizeList } from '../../common/api.js';
import { getAwardsDetail, getPrizeList } from '../../common/api.js';
import {getProbability} from '../../common/
utils
';
import {getProbability} from '../../common/
raffleProbability
';
wepy.component({
wepy.component({
props: {
props: {
videoList: {
videoList: {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment