朋友圈首页样式

    public function diaryList()
    {
        $data = Diary::with(['u_d'])->orderBy('created_at','desc')->paginate();
        $time = time();//现在时间戳
        foreach ($data as $k=>$v){
            $data[$k]['stat'] = explode(',',$v['states']);
            $data[$k]['files'] = explode('#',$v['file']);
            if($time-strtotime($v['created_at']) < 60){
                $data[$k]['time'] = '刚刚';
            }
            if($time-strtotime($v['created_at']) > 60){
                $data[$k]['time'] = '1分钟前';
            }
            if($time-strtotime($v['created_at']) > 60*5){
                $data[$k]['time'] = '5分钟前';
            }
            if($time-strtotime($v['created_at']) > 7200){
                $data[$k]['time'] = '2小时前';
            }
            if($time-strtotime($v['created_at']) > 86400){
                $data[$k]['time'] = '1天前';
            }
            if($time-strtotime($v['created_at']) > 259200){
                $data[$k]['time'] = '3天前';
            }
        }
        return ['code'=>200,'msg'=>'用户动态列表查询成功','data'=>$data];
    }
    public function u_d()
    {
        return $this->belongsTo(U_d::class,'diary_id');
    }
<view class="arr" wx:for="{{ logs }}" wx:key="index">
          <view>
          <image src="{{item.u_d.img}}" class="img"></image>
          {{item.u_d.nickname}}
          {{item.time}}
          <button open-type="share" size="mini"><image class="imgs" src="/img/share.png" ></image>分享</button>
          </view>
          
          <view>
            {{item.text}}
            <image src="{{item.files[0]}}" bindtap="preview" data-src="{{index}}"></image> 
            <text>{{ item.stat }}</text>
            <button bindtap="like" id="{{item.id}}">{{like}}</button>
<navigator url="/pages/report/report?id={{item.id}}">
<l-button type="error" class="rest">举报</l-button>
</navigator>
            </view>
 let token = wx.getStorageSync('token');
     wx.request({
       url: 'http://www.transfer.com/api/diaryList',
       method:'POST',
       header:{token},
       success : res=>{
         let logs = res.data.data.data;
         console.log(logs);
         this.setData({
           logs,
         })
       }
     })
  //预览图片,放大预览
  preview(event) {
    let currentUrl = event.currentTarget.dataset.src
    console.log(this.data.logs[currentUrl].files)
    this.setData({ 
      imgs:this.data.logs[currentUrl].files
    })
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.imgs // 需要预览的图片http链接列表
    })
  },

点赞

  like(e){
    let id = e.target.id;
    console.log(id);
    let token =wx.getStorageSync('token'); 
    wx.request({
      url: 'http://www.transfer.com/api/like',
      data:{token,id},
      success:res=>{
       if(res.data.code==200){
         this.setData({
           like:'已赞'
         })
        wx.showToast({
          title: '点赞成功',
       })
       }
       if(res.data.data=='1'){
        this.setData({
          like:'赞'
        })
       wx.showToast({
         title: '点赞已取消',
        })
       }

       if(res.data.data=='2'){
        this.setData({
          like:'已赞'
        })
       wx.showToast({
         title: '点赞成功',
        })
       }
      }
    })
  }
    public function like(Request $request)
    {
        $data = $request->except('token');
        $res =  Love::where(['d_id'=>$data['id'],'u_id'=>1])->first();

        //如果没有 就点赞, 数据入库
        if(!isset($res)){
            Love::create([
                'u_id'=>'1',
                'd_id'=>$data['id'],
                'status'=>'1'
            ]);
            return ['code'=>200,'msg'=>'点赞成功','data'=>''];
        }else{

             if($res['status']=='2'){
                $res['status']='1';
            }else{
                $res['status']='2';
            }
            $ress =  Love::where(['d_id'=>$data['id'],'u_id'=>1])->update(['status'=>$res['status']]);

            return ['code'=>201,'msg'=>'ok','data'=>$res['status']];
        }

    }
    setTimeout(function(){
      wx.switchTab({ 
        url: '../index/index'
      });  
    },3000)

加载页

<view>
    <l-arc-popup show="{{show}}" max-height="300" min-height="200">
<view>
<navigator url="/pages/words/words">
<l-button type="default" class="res">文字</l-button>
</navigator>
</view>
<view>
<navigator url="/pages/hire/hire">
<l-button type="error" class="rest">视频</l-button>
</navigator>
</view>
<view>
<navigator url="/pages/hire/hire">
<l-button type="warning" class="ress">图片</l-button>
</navigator>
</view>
</l-arc-popup>
<view class="add">
<l-icon name="add" bindtap="dj"   size="120"/>
</view>
</view>
.img{
  width: 100rpx;
  height: 100rpx;
}
.arr{
  margin-bottom: 100rpx;
}
.add{
  font-size: 30rpx;
  color: red;
}
.add{
  margin-left: 330rpx;
  margin-top: 940rpx;
}
.res{
  float: left;
  margin-left: 50rpx;
 
}
.rest{
  float:right;
  margin-right: 50rpx;
}
.ress{
  float: left;
  margin-left: 30rpx;
}
  dj(){
    var status=this.data.hidden
    if(status==true){
      this.setData({
        show:false
      })
    }else{
     this.setData({
       show:true
     })
    }
   },
   data:{
      expers:[],
      show:false
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值