怎么在微信小程序中實(shí)現(xiàn)評論功能?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、東寶網(wǎng)站維護(hù)、網(wǎng)站推廣。
wxml:
{{talks.length}} 條評論 {{item.nickName}} {{item.talkTime}} {{item.content}}
.wxss
page { height: 100%; overflow: hidden; } /* 框架 */ .talks-layer { position: absolute; bottom: -100%; height: 0; width: 100%; overflow: hidden; /* background-color: blue; */ } .layer-white-space { height: 100%; width: 100%; background-color: #ccc; opacity: 0.5; /* background-color: green; */ } .talks { position: absolute; height: 900rpx; width: 100%; bottom: 0rpx; background-color: #2f2d2e; border-top-left-radius: 3%; border-top-right-radius: 3%; /* background-color: red; */ } .talk-header { width: 100%; height: 70rpx; padding-top: 30rpx; text-align: center; } .talk-body { height: 700rpx; } .talk-footer { position: absolute; bottom: 0rpx; width: 100%; height: 100rpx; background-color: #151515; display: flex; justify-content: space-between; align-items: center; padding: 0 30rpx; box-sizing: border-box; } .footer_boxmovein{ position: absolute; bottom: 400rpx; width: 100%; height: 100rpx; z-index:1000; background-color: #151515; display: flex; justify-content: space-between; align-items: center; padding: 0 30rpx; box-sizing: border-box; transition:all 0.6s; } .footer_box { display: flex; justify-content: space-between; align-items: center; width: 100%; } /* 頂部元素 */ .talk-count { font-size: 26rpx; height: 40rpx; color: #6b696a; } .talk-close { position: absolute; top: 30rpx; right: 40rpx; width: 40rpx; height: 40rpx; } /* 中部元素 */ .talk-item { display: flex; flex-direction: row; align-items: flex-start; width: 100%; color: white; } .talk-item-left { display: flex; flex-direction: row; margin: 20rpx 30rpx; } .talk-item-face { width: 80rpx; height: 80rpx; border-radius: 50%; } .talk-item-right { width: 100%; border-bottom: solid 1rpx #6a6869; margin-right: 30rpx; /* margin-bottom: 30rpx; */ padding-bottom: 20rpx; } .right-left { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; } .talk-item-nickname { font-size: 28rpx; color: #aaa8a9; } .talk-item-time { font-size: 24rpx; color: #6a6869; } .talk-item-content { display: block; font-size: 30rpx; margin-right: 30rpx; width: 92%; white-space: pre-line; word-break: break-all; word-wrap: break-word;; } /* 底部元素 */ .talk-input { width: 100%; font-size: 30rpx; padding: 20rpx 0; padding-left: 30rpx; /* box-sizing: border-box; */ color: white; border-top-left-radius: 5%; border-top-right-radius: 5%; } .fabu-input { background: red; font-size: 26rpx; color: #fff; width: 127rpx; height: 60rpx; line-height: 60rpx; text-align: center; border-radius: 30rpx; padding: 0; } .emoji { background-color: #fff; width: 30px; height: 30px; text-align: center; padding-top: 2px; box-sizing: border-box; font-size: 20px; } .emoji-box { position: absolute; bottom:-390rpx; left:0rpx; height: 200px; padding: 5px 16rpx; box-sizing: border-box; background:#000; } .emoji-cell { width: 9.09%; height: 33px; display: inline-block; } .emoji-cell image { width: 23px; height: 23px; padding: 5px; border-radius: 3px; } .emoji-move-in { -webkit-animation: emoji-move-in 0.3s forwards; animation: emoji-move-in 0.3s forwards; } .emoji-move-out { -webkit-animation: emoji-move-out 0.3s forwards; animation: emoji-move-out 0.3s forwards; } .no-emoji-move { -webkit-animation: none; animation: none; } @-webkit-keyframes emoji-move-in { 0% { margin-bottom: -200px; } 100% { margin-bottom: 0; } } @keyframes emoji-move-in { 0% { margin-bottom: -200px; } 100% { margin-bottom: 0; } } @-webkit-keyframes emoji-move-out { 0% { margin-bottom: 0; } 100% { margin-bottom: -200px; } } @keyframes emoji-move-out { 0% { margin-bottom: 0; } 100% { margin-bottom: -200px; } } @-webkit-keyframes pd-left-move { 0% { padding-left: 5px; } 100% { padding-left: 15px; } } @keyframes pd-left-move { 0% { padding-left: 5px; } 100% { padding-left: 15px; } } .cf-bg { position: fixed; top: 0; left: 0; bottom: 0; right: 0; background-color: transparent; z-index: 99; }
.js
Page({ data: { talks: [], touchStart: 0, inputValue: '', inputBiaoqing: '', faces: ['/upload/otherpic54/32052.html', '/upload/otherpic54/32053.html', '/upload/otherpic54/32054.html'], names: ['貝貝', '晶晶', '歡歡', '妮妮'], isShow: false, //控制emoji表情是否顯示 isLoad: true, //解決初試加載時(shí)emoji動(dòng)畫執(zhí)行一次 cfBg: false, emojiChar: "?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?-?", //0x1f--- emoji: [ "60a", "60b", "60c", "60d", "60f", "61b", "61d", "61e", "61f", "62a", "62c", "62e", "602", "603", "605", "606", "608", "612", "613", "614", "615", "616", "618", "619", "620", "621", "623", "624", "625", "627", "629", "633", "635", "637", "63a", "63b", "63c", "63d", "63e", "63f", "64a", "64b", "64f", "681", "68a", "68b", "68c", "344", "345", "346", "347", "348", "349", "351", "352", "353", "414", "415", "416", "466", "467", "468", "469", "470", "471", "472", "473", "483", "484", "485", "486", "487", "490", "491", "493", "498", "6b4" ], emojis: [], //qq、微信原始表情 alipayEmoji: [], //支付寶表情 }, onLoad: function() { var em = {}, that = this, emChar = that.data.emojiChar.split("-"); var emojis = [] that.data.emoji.forEach(function(v, i) { em = { char: emChar[i], emoji: "0x1f" + v }; emojis.push(em) }); that.setData({ emojis: emojis }) }, //解決滑動(dòng)穿透問題 emojiScroll: function(e) { console.log(e) }, //點(diǎn)擊表情顯示隱藏表情盒子 emojiShowHide: function() { this.setData({ isShow: !this.data.isShow, isLoad: false, cfBg: !this.data.false }) }, //表情選擇 emojiChoose: function(e) { console.log(e) //當(dāng)前輸入內(nèi)容和表情合并 // let value = e.currentTarget.dataset.emoji; this.data.inputBiaoqing += e.currentTarget.dataset.emoji; console.log(this.data.inputBiaoqing) this.setData({ inputValue: this.data.inputBiaoqing }) }, //點(diǎn)擊emoji背景遮罩隱藏emoji盒子 cemojiCfBg: function() { console.log('womenlai') this.setData({ isShow: false, cfBg: false }) }, onReady: function() { // 評論彈出層動(dòng)畫創(chuàng)建 this.animation = wx.createAnimation({ duration: 400, // 整個(gè)動(dòng)畫過程花費(fèi)的時(shí)間,單位為毫秒 timingFunction: "ease", // 動(dòng)畫的類型 delay: 0 // 動(dòng)畫延遲參數(shù) }) }, showTalks: function() { // 加載數(shù)據(jù) this.loadTalks(); // 設(shè)置動(dòng)畫內(nèi)容為:使用絕對定位顯示區(qū)域,高度變?yōu)?00% this.animation.bottom("0rpx").height("100%").step() this.setData({ talksAnimationData: this.animation.export() }) }, hideTalks: function() { // 設(shè)置動(dòng)畫內(nèi)容為:使用絕對定位隱藏整個(gè)區(qū)域,高度變?yōu)? this.animation.bottom("-100%").height("0rpx").step() this.setData({ talks: [], talksAnimationData: this.animation.export() }) }, // 加載數(shù)據(jù) loadTalks: function() { // 隨機(jī)產(chǎn)生一些評論 wx.showNavigationBarLoading(); let that = this; let talks = []; let faces = ['https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1535701703&di=bfde939cc559b0f8edcbfd1adb6e667d&src=/upload/otherpic54/32055', '/upload/otherpic54/32056.html', '/upload/otherpic54/32057.html', ]; let names = ['佳佳', '晶晶', '歡歡', '妮妮', '娜娜', '鍋鍋']; let contents = ['為什么你總是對我不理不睬呢', '干嘛老是不見你了', '我們都有字節(jié)的夢想', '你有什么資格不努力呢']; let talktime = '剛剛'; console.log(talktime) talks = talks.concat(that.data.talks); // 隨機(jī)產(chǎn)生10條評論 for (var i = 0; i < 10; i++) { talks.push({ avatarUrl: faces[Math.floor(Math.random() * faces.length)], nickName: names[Math.floor(Math.random() * names.length)], content: contents[Math.floor(Math.random() * contents.length)], talkTime: talktime }); } this.setData({ talks: talks, talksAnimationData: that.animation.export() }) wx.hideNavigationBarLoading(); }, onScrollLoad: function() { // 加載新的數(shù)據(jù) this.loadTalks(); }, //下拉評論框隱藏 touchStart: function(e) { let touchStart = e.touches[0].clientY; this.setData({ touchStart, }) }, touchMove: function(e) { // console.log(this.data.touchStart) let touchLength = e.touches[0].clientY - this.data.touchStart; console.log(touchLength - 100) if (touchLength > 100) { this.animation.bottom("-100%").height("0rpx").step() this.setData({ talks: [], talksAnimationData: this.animation.export(), }) } }, //輸入框失去焦點(diǎn)時(shí)觸發(fā) bindInputBlur: function(e) { console.log(e) console.log(this.data.inputBiaoqing) this.data.inputValue = e.detail.value + this.data.inputBiaoqing; }, //點(diǎn)擊發(fā)布,發(fā)布評論 faBu: function() { let that = this; this.data.talks.unshift({ avatarUrl: this.data.faces[Math.floor(Math.random() * this.data.faces.length)], nickName: this.data.names[Math.floor(Math.random() * this.data.names.length)], content: this.data.inputValue, talkTime: '剛剛' }) that.data.inputValue = ''; that.setData({ talks: that.data.talks, inputValue: that.data.inputValue, talksAnimationData: that.animation.export() }) } })
關(guān)于怎么在微信小程序中實(shí)現(xiàn)評論功能問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。