获取某个学生的信息
// 获取某个学生的信息 public function select($id=''){ $where['id'] = $id; $ret = M('student')-where($where)-find(); return $this-ajaxReturn(array('msg'=$ret)); }获取全部学生的信息
// 获取全部学生信息 public function select_index(){ $pagesize=10; $condition = $_GET['condition']; $where=array(); if(!empty($condition)){ $where['a.no|a.name']=$condition; } $data = M('student')- alias('a')- where($where)- // join('__IMAGE__ b ON b.no=a.no')- page($_GET['page'],$pagesize)- select(); foreach ($data as &$row) { $path = $row['path']; if(!empty($path)){ if(!file_exists($path)){ $dir = dirname($path); mkdir($dir,0777,true); file_put_contents($path, base64_decode($row['base64'])); } $row['path'] = self::HOST . ltrim($path,'.'); } unset($row['base64']); } $this-ajaxReturn(array('data'=$data)); }刷脸登录// 刷脸登录 public function login(){ // 上传文件路径 $dir = "./Uploads/temp/"; if(!file_exists($dir)){ mkdir($dir,0777,true); } $upload = new ThinkUpload(); $upload-maxSize = 2048000 ;// 设置附件上传大小 $upload-exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload-savepath = ''; $upload-autoSub = false; $upload-rootPath = $dir; // 设置附件上传根目录 // 上传单个文件 $info = $upload-uploadOne($_FILES['file']); if(!$info) {// 上传错误提示错误信息 echo json_encode(array('error'=true,'msg'=$upload-getError()),JSON_UNESCAPED_UNICODE); }else{// 上传成功 获取上传文件信息 $file = $dir . $info['savepath'].$info['savename']; $image = base64_encode(file_get_contents($file)); $client = $this-init_face(); $options['liveness_control'] = 'NORMAL'; $options['max_user_num'] = '1'; $ret = $client-search($image,'BASE64','1001',$options); // echo json_encode($ret,JSON_UNESCAPED_UNICODE); // exit; if($ret['error_code']==0){ $user = $ret['result']['user_list'][0]; $no = $user['user_id']; $score = $user['score']; if($score=95){ $data = M('student')-where("no = '{$no}'")-find(); $data['score'] = $score; // $data['name'] = json_decode($data['name'],true); // $data['sex'] = json_decode($data['sex'],true); echo '识别成功' . json_encode($data,JSON_UNESCAPED_UNICODE); } } } }拍照页面view class='camera'切换摄像头 view class='weui-cell_ft' switch checked bindchange='switch1Change'/switch /view/view view class='photo' camera device-position="{{camera}}" flash="off" binderror="error" style="width: 100%; height: 300px;"/camera button type="primary" bindtap="takePhoto"拍照/button/viewjs// pages/camera/camera.jsPage({ data: { src: null }, switch1Change: function (e) { if (e.detail.value) { this.setData({ camera: 'front' }) } else { this.setData({ camera: 'back' }) } }, takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) = { this.setData({ src: res.tempImagePath }) wx.uploadFile({ url: 'http://****.top/program-php/server/index.php/home/index/login', //仅为示例,非真实的接口地址 filePath: this.data.src, name: 'file', formData: { }, success: function (res) { // var data = res.data console.log(res) wx.showModal({ title: '提示', content: res.data, showCancel:false, confirmText:'确定' }) } }) } }) }, error(e) { console.log(e.detail) },在学生列表页面需要实现页面的下拉刷新和上拉加载功能onPullDownRefresh,页面相关事件处理函数--监听用户下拉动作onReachBottom,页面上拉触底事件的处理函数//获取应用实例const app = getApp()var page = 1;var isfinish = false;//加载完毕function loadmore(that){ if(isfinish) return; wx.showLoading({ title: '正在加载中', }) wx.request({ url: 'http://*****.top/program-php/server/index.php/home/index/select_index', data: { page:page, condition:that.data.condition }, success: (res) = { console.log(res.data.data); var data =res.data.data; wx.hideLoading(); if(data.length0){ var student=that.data.student; for(var i = 0;idata.length;i++){ student.push(data[i]); } that.setData({student:student}); page++; }else{ isfinish = true; } wx.stopPullDownRefresh(); } })}Page({ data: { student: [], inputShowed: false, inputVal: "", condition:'' }, //搜索框 showInput: function () { this.setData({ inputShowed: true }); }, hideInput: function () { this.setData({ inputVal: "", inputShowed: false, condition:'', student:[] }); page=1 loadmore(this) }, clearInput: function () { this.setData({ inputVal: "" }); }, inputTyping: function (e) { this.setData({ inputVal: e.detail.value }); }, onPullDownRefresh: function () { page = 1; isfinish = false; this.setData({ student: [] }); loadmore(this); }, onReachBottom: function () { var that = this; loadmore(that); console.log(page) }, formSubmit:function(e){ console.log(e.detail.value.condition); this.setData({condition:e.detail.value.condition}); var that = this page = 1 this.setData({student:[]}) loadmore(that) }, onShow: function(){ loadmore(this) }})













