微信小程序?qū)崿F(xiàn)五星評(píng)價(jià)功能
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)五星評(píng)價(jià)的具體代碼,供大家參考,具體內(nèi)容如下
需求如圖:
1個(gè)星-很不滿意;
2個(gè)星-不滿意;
3個(gè)星-一般;
4個(gè)星-還不錯(cuò);
5個(gè)星-很滿意;
找了demo,刪刪改改,demo地址:微信小程序?qū)崿F(xiàn)星星評(píng)價(jià)效果
需要的頁面引入:
json:
{ ?? ? ?"usingComponents": { ?? ? ? ?"star": "../../components/star/star" ?? ? ?}, ?? ? ?"navigationBarTitleText": "評(píng)價(jià)" ?}
wxml:
<star></star>
組件代碼:
wxml:
<!--components/star/star.wxml--> <view class='buy' bindtap='showBuyModal'>測(cè)試版評(píng)價(jià)本次維修服務(wù)</view> <!-- 點(diǎn)擊彈出遮罩層 --> <view class="cover_screen" bindtap="hideBuyModal" wx:if="{{showModalStatus}}"></view> <!-- 點(diǎn)擊立即購(gòu)買 彈窗 --> <view animation="{{animationData}}" class="buy_box" wx:if="{{showModalStatus}}"> ? <view class='startitle'>{{tatle}}</view> ? <!-- 星星start --> ? <view class='container'> ? ? <view class='evaluate_contant'> ? ? ? <!--外層循環(huán)控制有幾個(gè)評(píng)價(jià)條目 --> ? ? ? <block wx:for='{{evaluate_contant}}' wx:key='' wx:for-index='idx'> ? ? ? ? <view class='evaluate_item'> ? ? ? ? ? <view class='evaluate_title'>{{staritem}}</view> ? ? ? ? ? <!--星星評(píng)價(jià) --> ? ? ? ? ? <view class='evaluate_box'> ? ? ? ? ? ? <!--內(nèi)層循環(huán)展示每個(gè)評(píng)價(jià)條目的星星 --> ? ? ? ? ? ? <block wx:for="{{stars}}" wx:key=''> ? ? ? ? ? ? ? <image class="star-image" style="left: {{item*80}}rpx" src="{{scores[idx] > item ?normalSrc:selectedSrc}}"> ? ? ? ? ? ? ? ? <view class="staritem" data-score="{{item + 1}}" data-idx='{{idx}}' bindtap="selectRight"></view> ? ? ? ? ? ? ? </image> ? ? ? ? ? ? </block> ? ? ? ? ? </view> ? ? ? ? </view> ? ? ? </block> ? ? ? <view class="evaluation">{{evaluation}}</view> ? ? ? <!-- <button class='sub_button' bindtap='submit_evaluate' type='primary'>提交</button> --> ? ? </view> ? </view> ? <!-- 星星end --> ? <view class="detail-btn"> ? <button class="done-person" style='border:4rpx solid #FF4A4A;background-color: #FFFFFF;font-weight: bold;color: #FF4A4A;font-size:28rpx;' bindtap='hideBuyModal' plain='{{plain}}'>取消</button> ? ? <button class="done-person" style='border:none;background-color: #FF4A4A;font-weight: bold;color: #FFFFFF;font-size:28rpx;' bindtap='submit_evaluate' plain='{{plain}}'>提交</button> ? ? <!-- <button type="primary" bindtap='hideBuyModal' class=""> 取消</button> ? ? <button type="primary" bindtap='submit_evaluate' class=""> 確定 </button> --> ? </view> </view>
js:
// components/star/star.js Component({ ? /** ? ?* 組件的屬性列表 ? ?*/ ? properties: { ? }, ? /** ? ?* 組件的初始數(shù)據(jù) ? ?*/ ? data: { ? ? showModalStatus: false, ? ? tatle: "您對(duì)這次服務(wù)的評(píng)價(jià)", ? ? // 星星 ? ? evaluate_contant: ['一', ], ? ? stars: [0, 1, 2, 3, 4], ? ? normalSrc: '../../image/star_gray.png', ? ? selectedSrc: '../../image/star_red.png', ? ? score: 0, ? ? scores: [0], ? ? evaluation:' ', ? ? plain:true ? }, ? /** ? ?* 組件的方法列表 ? ?*/ ? methods: { ? ? // 星星顆數(shù)start ? ? // 提交事件 ? ? submit_evaluate: function() { ? ? ? console.log('評(píng)價(jià)得分' + this.data.scores) ? ? }, ? ? //點(diǎn)擊星 ? ? selectRight: function(e) { ? ? ? var score = e.currentTarget.dataset.score ? ? ? console.log(score) ? ? ? this.data.scores[e.currentTarget.dataset.idx] = score ? ? ? let evaluation = score == 1 ? '很不滿意' : (score == 2 ? '不滿意' : (score == 3 ? '一般' : (score == 4 ? '還不錯(cuò)' : (score == 5 ? '很滿意' : '')))) ? ? ? this.setData({ ? ? ? ? scores: this.data.scores, ? ? ? ? score: score, ? ? ? ? evaluation: evaluation ? ? ? }) ? ? }, ? ? // 星星顆數(shù)end ? ? // onLoad: function (options) { ? ? // ? console.log(options.id) ? ? // }, ? ? showBuyModal() { ? ? ? // 顯示遮罩層 ? ? ? var animation = wx.createAnimation({ ? ? ? ? duration: 200, ? ? ? ? /** ? ? ? ? ?* http://cubic-bezier.com/? ? ? ? ? ?* linear 動(dòng)畫一直較為均勻 ? ? ? ? ?* ease 從勻速到加速在到勻速 ? ? ? ? ?* ease-in 緩慢到勻速 ? ? ? ? ?* ease-in-out 從緩慢到勻速再到緩慢 ? ? ? ? ?*? ? ? ? ? ?* http://www.tuicool.com/articles/neqMVr ? ? ? ? ?* step-start 動(dòng)畫一開始就跳到 100% 直到動(dòng)畫持續(xù)時(shí)間結(jié)束 一閃而過 ? ? ? ? ?* step-end 保持 0% 的樣式直到動(dòng)畫持續(xù)時(shí)間結(jié)束 一閃而過 ? ? ? ? ?*/ ? ? ? ? timingFunction: "ease", ? ? ? ? delay: 0 ? ? ? }) ? ? ? this.animation = animation ? ? ? animation.translateY(300).step() ? ? ? this.setData({ ? ? ? ? animationData: animation.export(), // export 方法每次調(diào)用后會(huì)清掉之前的動(dòng)畫操作。 ? ? ? ? showModalStatus: true ? ? ? }) ? ? ? setTimeout(() => { ? ? ? ? animation.translateY(0).step() ? ? ? ? this.setData({ ? ? ? ? ? animationData: animation.export() // export 方法每次調(diào)用后會(huì)清掉之前的動(dòng)畫操作。 ? ? ? ? }) ? ? ? ?? ? ? ? }, 200) ? ? }, ? ? hideBuyModal() { ? ? ? // 隱藏遮罩層 ? ? ? var animation = wx.createAnimation({ ? ? ? ? duration: 200, ? ? ? ? timingFunction: "ease", ? ? ? ? delay: 0 ? ? ? }) ? ? ? this.animation = animation ? ? ? animation.translateY(300).step() ? ? ? this.setData({ ? ? ? ? animationData: animation.export(), ? ? ? }) ? ? ? setTimeout(function() { ? ? ? ? animation.translateY(0).step() ? ? ? ? this.setData({ ? ? ? ? ? animationData: animation.export(), ? ? ? ? ? showModalStatus: false ? ? ? ? }) ? ? ? ? // console.log(this) ? ? ? }.bind(this), 200) ? ? } ? } })
wxss:
/* components/star/star.wxss */ .buy{ ? margin-top: 200rpx; ? text-align: center; } .cover_screen { ? width: 100%; ? height: 100%; ? position: fixed; ? top: 0; ? left: 0; ? background: #000; ? opacity: 0.2; ? overflow: hidden; ? z-index: 1000; ? color: #fff; } .buy_box { ? width: 100%; ? box-sizing: border-box; ? position: fixed; ? bottom: 0; ? left: 0; ? z-index: 2000; ? background: #fff; ? padding: 20rpx; ? overflow: hidden; } .buy_box .startitle { ? ? font-size: 28rpx; ? ? text-align: center; ? ? line-height: 40rpx; ? ? color: #333; ? ? padding: 20rpx 0; } /* 星星 */ .footer_end{ ? display: flex } .footer_end button{ ? width: 30%; } /* 插入星星 */ /*評(píng)價(jià)區(qū)域 */ .container .evaluate_contant .evaluate_item { ?font-size: 30rpx; ?color: gray; ?margin-left: 20rpx; ?margin-top: 30rpx; } ? /*評(píng)價(jià)標(biāo)題 */ .container .evaluate_contant .evaluate_item .evaluate_title { ?display: inline-block; } ? /*評(píng)價(jià)盒子 */ .container .evaluate_contant .evaluate_item .evaluate_box { ?position: absolute; ?left: 220rpx; ?width: 100%; ?display: inline-block; } ? /*星星評(píng)價(jià)的每個(gè)圖片 */ .container .evaluate_contant .evaluate_item .evaluate_box .star-image { ?position: absolute; ?width: 40rpx; ?height: 40rpx; ?src: "../../image/star_gray.png"; } /* 評(píng)價(jià)對(duì)應(yīng)內(nèi)容 */ .evaluation{ ? text-align: center; ? margin: 30rpx 0 40rpx; ? color: #535353; } ? /*星星區(qū)域 */ .container .evaluate_contant .evaluate_item .evaluate_box .star-image .staritem { ?position: absolute; ?top: 0rpx; ?left: 0rpx; ?width: 40rpx; ?height: 40rpx; } ? /*按鈕 */ .container .evaluate_contant .sub_button { ?height: 60rpx; ?font-size: 30rpx; ?line-height: 60rpx; ?margin: 20rpx; } .detail-btn{ ? width: 750rpx; ? display: flex; ? justify-content: space-around; ? align-items: center; ? margin-bottom: 100rpx; } .done-person{ ? width:220rpx; ? height:72rpx; ? border-radius:36rpx; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js實(shí)現(xiàn)數(shù)字從零慢慢增加到指定數(shù)字示例
今天小編就為大家分享一篇js實(shí)現(xiàn)數(shù)字從零慢慢增加到指定數(shù)字示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11微信小程序自定義toast組件的方法詳解【含動(dòng)畫】
這篇文章主要介紹了微信小程序自定義toast組件的方法,結(jié)合實(shí)例形式詳細(xì)分析了微信小程序自定義toast組件的步驟、實(shí)現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2019-05-05ES6新特性之類(Class)和繼承(Extends)相關(guān)概念與用法分析
這篇文章主要介紹了ES6新特性之類(Class)和繼承(Extends)相關(guān)概念與用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了ES6中類(Class)和繼承(Extends)的基本概念、語法、使用方法與注意事項(xiàng),需要的朋友可以參考下2017-05-05JavaScript實(shí)現(xiàn)刷新不重記的倒計(jì)時(shí)
網(wǎng)上關(guān)于JavaScript實(shí)現(xiàn)倒計(jì)時(shí)的文章有很多,但是一般都是刷新后會(huì)重新開始計(jì)時(shí),可是我們有的時(shí)候會(huì)需要刷新卻不重新計(jì)算的倒計(jì)時(shí),這該怎么做呢?下面我們一起來看看這種倒計(jì)時(shí)怎么實(shí)現(xiàn)吧。2016-08-08uniapp電商小程序?qū)崿F(xiàn)訂單30分鐘倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了uniapp電商小程序?qū)崿F(xiàn)訂單30分鐘倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11詳解關(guān)于JSON.parse()和JSON.stringify()的性能小測(cè)試
這篇文章主要介紹了詳解關(guān)于JSON.parse()和JSON.stringify()的性能小測(cè)試,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03JS實(shí)現(xiàn)仿google、百度搜索框輸入信息智能提示的實(shí)現(xiàn)方法
這篇文章主要介紹了JS實(shí)現(xiàn)仿google、百度搜索框輸入信息智能提示的實(shí)現(xiàn)方法,實(shí)例分析了javascript實(shí)現(xiàn)智能提示功能的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04