页面调用
@php $lesson_list=$lessons; @endphp
@include('home.module.lesson_list')
lesson_list模块
{{--1、用php变量接收外部变量,在外部要把lesson数据赋值给$lesson_list--}}
<div class="row">
@foreach($lesson_list as $lesson)
<div class="col-md-3 col-xs-6">
<div class="choose_lesson_box" >
<div class="choose_lesson_imgbox">
<a href="/lesson/{{$lesson['l_id']}}">
<img src="{{$lesson['l_preview']}}" style="max-width: 100%;" alt="">
</a>
<a href="/lesson/{{$lesson['l_id']}}" class="choose_lesson_start_learn">
<span class="choose_lesson_start_learn_content">
开始学习
</span>
</a>
</div>
<div class="choose_lesson_info_box">
<div class="choose_lesson_info_box_author">
<span class="label label-info">范仁义</span>
</div>
<div class="choose_lesson_info_box_time">
<span class="label label-info">36课时</span>
</div>
</div>
<div class="choose_lesson_title" style="text-align: center;margin-top: 5px;">
<a class="choose_lesson_title_a font_cut" style="display: inline-block;" href="/lesson/{{$lesson['l_id']}}">
{{$lesson['l_title']}}
</a>
<div style="display: none;">会员优惠:8元 <del><i>10元</i></del></div>
<div class="video_interaction_box font_cut" style="font-size: 12px;width: 100%;">
{{--点赞--}}
<div class="video_interaction_box_like" style="margin-right: 3px;">
<span style="@if(in_array($lesson['l_id'],$likeLessons_l_ids)) display:none; @endif" l_id="{{$lesson['l_id']}}" class="fa_like">
<i class="fa fa-thumbs-o-up fa-fw" aria-hidden="true"></i>
<span>@if(in_array($lesson['l_id'],$likeLessons_l_ids)) {{$lesson['l_like']-1}} @else {{$lesson['l_like']}} @endif </span>
</span>
<span style="color: red;@if(!in_array($lesson['l_id'],$likeLessons_l_ids)) display:none; @endif" l_id="{{$lesson['l_id']}}" class="fa_like_no">
<i class="fa fa-thumbs-up fa-fw" aria-hidden="true"></i>
<span>@if(in_array($lesson['l_id'],$likeLessons_l_ids)) {{$lesson['l_like']}} @else {{$lesson['l_like']+1}} @endif</span>
</span>
</div>
{{--收藏--}}
<div class="video_interaction_box_collect" style="margin-right: 3px;">
<span style="@if(in_array($lesson['l_id'],$collectLessons_l_ids)) display:none; @endif" l_id="{{$lesson['l_id']}}" class="fa_collect">
<i class="fa fa-heart-o fa-fw " aria-hidden="true"></i>
<span>@if(in_array($lesson['l_id'],$collectLessons_l_ids)) {{$lesson['l_collect_num']-1}} @else {{$lesson['l_collect_num']}} @endif </span>
</span>
<span style="color: red;@if(!in_array($lesson['l_id'],$collectLessons_l_ids)) display:none; @endif" l_id="{{$lesson['l_id']}}" class="fa_collect_no">
<i class="fa fa-heart fa-fw" aria-hidden="true"></i>
<span>@if(in_array($lesson['l_id'],$collectLessons_l_ids)) {{$lesson['l_collect_num']}} @else {{$lesson['l_collect_num']+1}} @endif </span>
</span>
</div>
{{--浏览--}}
<div class="video_interaction_box_click" style="margin-right: 0;">
<i class="fa fa-play-circle-o fa-fw" aria-hidden="true"></i>
<span>{{$lesson['l_click']}}</span>
</div>
</div>
<a href="/lesson/{{$lesson['l_id']}}">
<span class="splay" style="opacity: 0; margin-top: 105px;display: none;">开始学习</span>
</a>
</div>
</div>
</div>
@endforeach
</div>
<script>
//课程的点赞操作
$('.fa_like').click(function () {
let l_id=$(this).attr('l_id');
let _this=$(this);
//console.log(l_id);
$.post("/like_lesson", {'l_id':l_id,'_token':'{{csrf_token()}}'} ,function (data) {
console.log(data);
if(parseInt(data.valid)==1){
_this.hide();
_this.parent().find('.fa_like_no').show();
layer_alert_success(data.message);
}else{
layer_alert_fail(data.message);
}
});
});
//取消课程点赞操作
$('.fa_like_no').click(function () {
let l_id=$(this).attr('l_id');
let _this=$(this);
//console.log(l_id);
$.post("/cancel_like_lesson", {'l_id':l_id,'_token':'{{csrf_token()}}'} ,function (data) {
console.log(data);
if(parseInt(data.valid)==1){
_this.hide();
_this.parent().find('.fa_like').show();
layer_alert_success(data.message);
}else{
layer_alert_fail(data.message);
}
});
});
//课程的收藏操作
$('.fa_collect').click(function () {
let l_id=$(this).attr('l_id');
let _this=$(this);
//console.log(l_id);
$.post("/collect_lesson", {'l_id':l_id,'_token':'{{csrf_token()}}'} ,function (data) {
console.log(data);
if(parseInt(data.valid)==1){
_this.hide();
_this.parent().find('.fa_collect_no').show();
layer_alert_success(data.message);
}else{
layer_alert_fail(data.message);
}
});
});
//课程的取消收藏操作
$('.fa_collect_no').click(function () {
let l_id=$(this).attr('l_id');
let _this=$(this);
//console.log(l_id);
$.post("/cancel_collect_lesson", {'l_id':l_id,'_token':'{{csrf_token()}}'} ,function (data) {
console.log(data);
if(parseInt(data.valid)==1){
_this.hide();
_this.parent().find('.fa_collect').show();
layer_alert_success(data.message);
}else{
layer_alert_fail(data.message);
}
});
});
</script>
require.config({ baseUrl: 'js/', paths: { jquery: 'lib/jquery-2.1.4', mCustomScrollbar:'lib/jquery.mousewheel', }, shim: {
}, urlArgs: "v=" + (new Date()).getTime()
});
应该是js文件外面加
<script id="main"></script>
<script type="text/javascript">
var js = document.getElementById('main');
js.src = 'main.js?v='+ new Date().getTime();
</script>