微信小程序评论/留言功能,附:前端+后端代码+视频讲解!

前端界面:

演示:

<!-- 表单 -->
<form bindsubmit="formSubmit">
<input type="text" name="liuyantext" placeholder=‘输入留言内容‘ class="input-style"/>
<button formType="submit" class="btn" wx:if="{{nickName == empty}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" bindtap=‘login‘>授权登录</button>
<button formType="submit" class="btn" wx:else>留言</button>
<input type="text" name="nickname" value=‘{{nickName}}‘ style="display:none;"/>
<input type="text" name="headimg" value=‘{{avatarUrl}}‘ style="display:none;"/>
</form>

<view wx:for="{{re}}" wx:key="re">
  <view class="result">{{item.result}}</view>
</view>
<view style="text-align:center;font-size:14px;color:#ccc;margin-top:20px;">以下是留言内容</view>
<view wx:for="{{liuyanlist}}" wx:key="liuyanlist" class="liuyanview">
  <view class="headimg"><image src="{{item.headimg}}"></image></view>
  <view class="nickname_liuyantext">
    <view class="nickname">{{item.nickname}} <view class="time">{{item.lytime}}</view></view>
    <view class="text">{{item.liuyantext}}</view>
  </view>
  <!-- 占位符 -->
  <view style="width:100%;height:10px;"></view>
</view>

//index.js
//获取应用实例
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {

  },

  //授权登录
  login: function () {
    var that = this;
    // 查看是否授权
    wx.getSetting({
      success(res) {
        if (res.authSetting[‘scope.userInfo‘]) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo),
                that.setData({
                  nickName: res.userInfo.nickName,
                  avatarUrl: res.userInfo.avatarUrl,
                })
            }
          })
        }
      }
    })
  },
  bindGetUserInfo(e) {
    console.log(e.detail.userInfo)
  },

  formSubmit: function (e) {
    wx.showToast({
      title: ‘已留言‘,
      icon: ‘success‘
    })
    var that = this;
    var liuyantext = e.detail.value.liuyantext; //获取表单所有name=liuyantext的值
    var nickName = e.detail.value.nickname; //获取表单所有name=nickName的值
    var headimg = e.detail.value.headimg; //获取表单所有name=headimg的值
    wx.request({
      url: ‘http://localhost/liuyanserver/liuyan.php?liuyantext=‘ + liuyantext + ‘&nickname=‘ + nickName + ‘&headimg=‘ + headimg,
      data: {
        liuyantext,
        nickName,
        headimg
      },
      header: { ‘Content-Type‘: ‘application/json‘ },
      success: function (res) {
        console.log(res.data)
        that.setData({
          re: res.data,
        })
        wx.hideToast();
      }
    })
  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    var that = this
    wx.request({
      url: ‘http://localhost/liuyanserver/loadliuyan.php‘,
      headers: {
        ‘Content-Type‘: ‘application/json‘
      },
      success: function (res) {
        //将获取到的json数据,存在名字叫list的这个数组中
        that.setData({
          liuyanlist: res.data,
          //res代表success函数的事件对,data是固定的,liuyanlist是数组
        })
        // 隐藏导航栏加载框
        wx.hideNavigationBarLoading();
        // 停止下拉动作
        wx.stopPullDownRefresh();
      }
    })
  },

  //加载最新数据
  onLoad: function () {
    var that = this
    wx.request({
      url: ‘http://localhost/liuyanserver/loadliuyan.php‘,
      headers: {
        ‘Content-Type‘: ‘application/json‘
      },
      success: function (res) {
        //将获取到的json数据,存在名字叫list的这个数组中
        that.setData({
          liuyanlist: res.data,
          //res代表success函数的事件对,data是固定的,liuyanlist是数组
        })
      }
    })
  }
})
/**index.wxss**/
.input-style{
  width: 90%;
  height: 50px;
  border:1px solid #ccc;
  margin:10px auto;
}

.btn{
  width: 88%;
  margin:5px auto;
}

.liuyanview{
  width: 90%;
  margin: 10px auto;
}

.result{
  text-align: center;
  font-size: 14px;
  color: #f00;
  margin-top: 20px;
}

.headimg{
  width: 45px;
  height: 45px;
  border-radius: 100%;
}

.headimg image{
  width: 45px;
  height: 45px;
  border-radius: 100%;
}

.nickname_liuyantext{
  width: calc(100% - 55px);
  float: right;
  margin-top:-45px;
}

.nickname_liuyantext .nickname{
  font-size: 15px;
  color: #999;
}

.nickname_liuyantext .nickname .time{
  font-size: 11px;
  color: #999;
  float: right;
}

.nickname_liuyantext .text{
  font-size: 16px;
  color: #666;
}

以上是前端部分
后端有两个文件。

点击下载后端,后端需要修改自己的数据库配置!
http://www.youka.la/product/5...

数据库格式:

原文地址:https://www.cnblogs.com/jlfw/p/12696108.html

时间: 2024-08-30 00:08:50

微信小程序评论/留言功能,附:前端+后端代码+视频讲解!的相关文章

微信小程序开发-蓝牙功能开发

0. 前言 这两天刚好了解了一下微信小程序的蓝牙功能.主要用于配网功能.发现微信的小程序蓝牙API已经封装的很好了.编程起来很方便.什么蓝牙知识都不懂的情况下,不到两天就晚上数据的收发了,剩下的就是数据帧格式的定义,当然这部分就不是本次博客的重点.1. 准备硬件 这里我准备了CH341SER这个作为USB转串口.用sscom5.13.1 串口工具.由于我不太懂硬件开发.硬件部分都是由公司其他人开发的.我只是负责把环境搭建起来.然后负责我的微信小程序开发. 2. 开发小程序简单讲解 onLoad

微信小程序开发总结(附源代码)

最近公司项目不是很忙,有时间研究研究微信小程序.参考了目前市场上各类答题类的app.小程序等等,做了一款自己的微信答题小程序,包括前端和后端,后端是用node做的.现在已经上线了,名字叫[你问我猜猜猜],大家感兴趣的话可以去试玩一下. 会vue.react, 微信小程序,so easy 如果之前用过vue或者react,直接看看文档上手微信小程序完全没问题.整体开发思路很相似,包括其中的一些语法,基本上都是一样的.或者用美团的mpvue框架,那就根本不用学习小程序的语法了,写起来跟vue一样.但

一号旺铺微信小程序三大新功能:可相互跳转、批量管理门店

可相互跳转.批量管理门店,小程序是抓住零售新机会的一把利器吗?一号旺铺专业.专注开发小程序,就微信小程序的三个功能与大家分享. 同一个公众号下关联的 10 个同主体小程序和 3 个非同主体小程序之间,可以调用接口直接相互跳转. 微信小程序新动向:可相互跳转.批量管理门店 可相互跳转.批量管理门店,小程序是抓住零售新机会的一把利器吗? 小程序到底能不能抓住零售新机会,成效还在验证中.不过为了实现这一目标,小程序又释放了一个重大功能. 6 月 21 日深夜,微信官方表示,与同一公众号关联的小程序之间

微信小程序人脸识别功能

本文档以微信小程序为例,微信小程序开发人脸核身功能需要两个申请:腾讯云申请人脸识别服务和小程序申请人脸识别服务(注意:只有符合以下条件的机构才能在小程序端申请) 政务:政府机构或事业单位金融:银行.保险医疗:公立医疗机构运营商:电信运营商教育:公立教育机构交通:航空.客运.网约车.交通卡.共享交通.轨道交通.租车旅游:酒店物流:快递.邮政.物流 主要参考文档: 1.腾讯云人脸核身文档 :https://cloud.tencent.com/product/faceid/developer 2.腾讯

微信小程序实现支付功能

小程序支付,没有封装支付代码:直接上一段可用的流程代码吧:微信小程序支付官网文档有详细的说明,这里我就不再赘述啦:客户端js: wx.request({ url:'https://www.xxxx.com/api/payfee.php',//改成你自己的链接 header:{ 'Content-Type':'application/x-www-form-urlencoded' }, method:'POST', success:function(res){ console.log(res.dat

微信小程序评论功能源码

wxml: <textarea class="input" bindinput='bindContent' value="" placeholder="请填写评论内容 "></textarea> <button class='button show-button' bindtap="Submit" data-item_data1='{{item_data1}}' id="vid"

微信小程序 五星评价功能

要实现的效果:点击到第几颗星,就要显示到第几颗星,///////////////// 接下来直接查看源码: <view class="l-evalbox row"> <text class="l-evaltxt">满意度:</text> <view class="l-evalist flex-1" bindtap="chooseicon"> <icon class=&quo

NopCommerce 4.2 之微信小程序 - 每日签到功能

/// <summary> /// 调用接口自动签到,并返回签到结果 /// </summary> /// <returns></returns> [Route("index")] [APIFilter(true, true)] public APIResult<object> index() { //设置为驼峰命名(即将实体全部首字母小写处理) var serializerSettings = new JsonSeriali

【微信开发】微信小程序通过经纬度计算两地距离php代码实现

需求: 要求做个根据用户当前位置获取周围商家地址,并且按照由近到远排序, 方法一: 代码层实现 封装方法: /** * @desc 根据两点间的经纬度计算距离 * @param float $lat 纬度值 * @param float $lng 经度值 * @param $status true KM,M显示;false 只返回M */ function system_getdistance($lat1, $lng1, $lat2, $lng2, $status = true, $single