当前位置:网站首页>Wechat applet realizes five-star evaluation
Wechat applet realizes five-star evaluation
2022-06-27 11:49:00 【Draw a flourishing fireworks with a black pencil】
pingxing.js
function pingfenxing(pingfen) {
var _this = this, // The path of the picture here , I need to modify
data = {
ling: "/img/icon-ling.png",
zheng: "/img/icon-zheng.png",
ban: "/img/icon-ban.png",
},
nums =[];// Here is an array that returns the order in which the pictures are arranged , Here we should pay attention to the path of the image when the page is used , But it doesn't matter if you use web photos if((pingfen/0.2)%2==0){// If the score is positive , Such as 4.0, 5.0}
// The full score of this effect is 5 branch , if 10 Special rules
//var pingfen = Math.ceil(pingfen)/2;
if((pingfen/0.2) % 2 == 0) {
for (var i = 0; i < 5; i++) {
if (i < pingfen) {
nums.push(data.zheng);
} else {
nums.push(data.ling)
}
}
} else { // Score is not an integer , Such as 3.5, 2.5
for(var i=0; i<5; i++) {
if(i<pingfen-0.5) {
nums.push(data.zheng); // First, separate the certificates , Such as : 3.5 Here is to put 3 separate from , Put it on behalf of 1 Put the picture of
} else if(i==(pingfen-0.5)) {
nums.push(data.ban); // Separate the decimal parts , Such as : 3.5 Inside 0.5, Put it on behalf of 0.5 Put the picture of
} else {
nums.push(data.ling); // Then the rest is represented by the not full 0 Put the picture of , Such as : 3.5, It's inside 3 A representative 1 Pictures of the , Then put it in 1 A representative 0.5 Pictures of the , Finally, there is a picture left , At this time, it means 0 Pictures of the
}
}
}
return nums;
}
function information(data){
for (var i = 0; i < data.length; i++) {
// console.log(data[i].score) Find the scoring data in the data
data[i].pingfenpic = this.pingfen(parseFloat(data[i].score)); // Using functions
}
module.exports = {
pingfen: pingfenxing,
information: information
}js
var pingxin = require("../../utils/pingxing.js");
Page({
/**
* Initial data of the page
*/
data: {
tiyan: [ // score
{pingfen: 3.5}
],
}
/**
* Life cycle function -- Monitor page loading
*/
onLoad: function(options) {
var _this = this;
var tiyan = this.data.tiyan;
tiyan = pingxin.information(tiyan);
_this.setData({
tiyan: tiyan
})
},
})wxss
image {
width: 14rpx;
height: 14rpx;
margin-right: 5rpx;
}wxml
<block wx:for="{
{tiyan}}" wx:key="index">
<block wx:for="{
{item.pingfenpic}}" wx:key="index">
<image src="{
{item}}"></image>
</block>
</block>Pictures of stars

边栏推荐
- 2022CISCN华中 Web
- Institute of Microbiology, Chinese Academy of Sciences recruited 20 young PI, with a resettlement fee of 2million yuan and a start-up fund of 10million yuan (long-term effective)
- 杰理之串口通信 串口接收IO需要设置数字功能【篇】
- Xuri 3sdb, installing the original ROS
- C语言0长度数组的妙用
- 优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端
- Deep understanding of happens before principle
- R语言dplyr包arrange函数排序dataframe数据、通过多个数据列排序dataframe数据、指定第一个字段降序排序,第二字段不指定(默认升序排序)
- Qstype implementation of self drawing interface project practice (I)
- [worthy of collection] centos7 installation MySQL complete operation command
猜你喜欢

Youboxun attended the openharmony technology day to create a new generation of secure payment terminals

Challenges of machine learning system in production

巅峰小店APP仿站开发玩法模式讲解源码分享

【TcaplusDB知识库】TcaplusDB-tcaplusadmin工具介绍

0基础了解电商系统如何对接支付渠道

器审科普:创新医疗器械系列科普——胸骨板产品

AutoCAD - three pruning methods

Glide caching mechanism

Code for structural design of proe/creo household appliances - electric frying pan

干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
随机推荐
[tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
【TcaplusDB知识库】TcaplusDB分析型文本导出介绍
Usage of rxjs mergemap
[tcapulusdb knowledge base] Introduction to tcapulusdb general documents
Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
Deep understanding of happens before principle
杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
【TcaplusDB知识库】TcaplusDB常规单据介绍
杰理之添加定时器中断【篇】
AutoCAD - three pruning methods
Drive to APasS! Use Mingdao cloud to manage F1 events
R语言dplyr包arrange函数排序dataframe数据、通过多个数据列排序dataframe数据、指定第一个字段降序排序,第二字段不指定(默认升序排序)
【TcaplusDB知识库】TcaplusDB数据导入介绍
Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)
21: Chapter 3: develop pass service: 4: further improve [send SMS, interface]; (in [send SMS, interface], call Alibaba cloud SMS service and redis service; a design idea: basecontroller;)
【TcaplusDB知识库】TcaplusDB运维单据介绍
杰理之串口通信 串口接收IO需要设置数字功能【篇】
Code for structural design of proe/creo household appliances - electric frying pan
Jerry's DAC output mode setting [chapter]
[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool