php后台+微信小程序 列表页面

//php查询数据

static public function selfs($id){
return self::where('id',$id)->first();
}
//内置验证
$this->validate(request(),[
'username'=>'required',
'pwd'=>'required'
],[
'username.min'=>'名称过短'
]);
//登录
$info=Db::table('user')->where('username',$data['username'])->where('pwd',$data['pwd'])->get()->Toarray();
//swoole

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>Title</title>
</head>
<body>
<div style=”display: block” id=”data1″>
<input type=”text” id=”a”>
<button type=”button” onclick=”datas()”>设置姓名</button>
</div>
<div style=”display: none” id=”data2″>
<input type=”text” id=”img”>
<button type=”button” onclick=”datas1()”>发送信息</button>
</div>
<div style=”display: none”>
<input type=”text”>
</div>
<div style=”display:block”>
<div id=”b”></div>
</div>
</body>
</html>
<script src=”https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js”>
</script>
<script>
var wsServer = ‘ws://121.4.180.50:9501’;
var websocket = new WebSocket(wsServer);
websocket.onopen = function (evt) {
console.log(“已连接”)
};

websocket.onclose = function (evt) {
console.log(“Disconnected”);
};

websocket.onmessage = function (evt) {
console.log(“已发送”)
console.log(evt.data);
$(“#b”).append(“<div>”+evt.data+”</div>”)
};

websocket.onerror = function (evt, e) {
console.log(‘Error occured: ‘ + evt.data);
};
function datas() {
var name=$(“#a”).val();
if (name=!””){
$(“#data1”).prop(“style”,”display:none”);
$(“#data2”).prop(“style”,”display:block”);
}
}
function datas1() {

var datad=”name”+”:”+$(“#a”).val()+”,”+”img”+”:”+$(“#img”).val();
// console.log(data);
websocket.send(datad);
}
</script>

//js

// pages/home/home.js Page({

  /**    * 页面的初始数据    */   data: {     list:[],     indicatorDots: true,     vertical: false,     autoplay: true,     interval: 3000,     duration: 500,     text:[],     hao:[],     winWidth: 0,     winHeight: 0,     currentTab: 0,

  },   /**    * 生命周期函数–监听页面加载    */   onLoad: function (options) {     wx.getSystemInfo( {

      success: function( res ) {           that.setData( {               winWidth: res.windowWidth,               winHeight: res.windowHeight           });       }

  });   

      wx.request({                  url: ‘http://www.monthexam.com/api/hao’,         success :(res) => {           console.log(res)           this.setData({             list:res.data.data           })         }       }),       wx.request({                  url: ‘http://www.monthexam.com/api/self’,         success :(res) => {           console.log(res)           this.setData({             text:res.data.data.data           })         }       }),       wx.request({                  url: ‘http://www.monthexam.com/api/selgood’,         success :(res) => {           console.log(res)           this.setData({             hao:res.data.data           })         }       })

         },   swichNav: function( e ) {

    var that = this;

    if( this.data.currentTab === e.target.dataset.current ) {         return false;     } else {         that.setData( {             currentTab: e.target.dataset.current         })     } },

bindChange: function( e ) {

    var that = this;     that.setData( { currentTab: e.detail.current });

},

  /**    * 生命周期函数–监听页面初次渲染完成    */   onReady: function () {

  },

  /**    * 生命周期函数–监听页面显示    */   onShow: function () {

  },

  /**    * 生命周期函数–监听页面隐藏    */   onHide: function () {

  },

  /**    * 生命周期函数–监听页面卸载    */   onUnload: function () {

  },

  /**    * 页面相关事件处理函数–监听用户下拉动作    */   onPullDownRefresh: function () {

  },

  /**    * 页面上拉触底事件的处理函数    */   onReachBottom: function () {

  },

  /**    * 用户点击右上角分享    */   onShareAppMessage: function () {

  }, }) //详情的写法  console.log(options.id);     var id=options.id;       wx.request({         url: ‘http://www.monthexam.com/api/selegood?id=’+id,         success :(res) => {             console.log(res.data.data)             this.setData({               list:res.data.data             })         },       })

原文地址:https://www.cnblogs.com/ahao513/p/14765912.html