123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- function getParams(url) {
- var theRequest = new Object();
- if (!url)
- url = location.href;
- if (url.indexOf("?") !== -1) {
- var str = url.substr(url.indexOf("?") + 1) + "&";
- var strs = str.split("&");
- for (var i = 0; i < strs.length - 1; i++) {
- var key = strs[i].substring(0, strs[i].indexOf("="));
- var val = strs[i].substring(strs[i].indexOf("=") + 1);
- theRequest[key] = val;
- }
- }
- return theRequest;
- }
- var objUrl = {}; //获取get参数
- var url = window.location.href;
- var params = getParams(url);
- if (!$.isEmptyObject(params)) {
- $.each(params, function (key, val) {
- objUrl[key] = val;
- })
- }
- /*----------------定义页面全局变量-----------------------*/
- // 页数
- var page = 0;
- // 每页展示5个
- var size = 10;
- //资讯ID
- var thisID = 0;
- /*----------------------------------------------------------------------------------*/
- // 封装 ajax 方法
- function AjaxFn() {
- page = 0;
- page++;
- $.ajax({
- type: 'GET',
- url: '/json/homeform?&page=' + page + '&limit=' + size + '&cid=' + thisID,
- dataType: 'json',
- success: function (data) {
- if (data.code == 200) {
- $('.news_list').append(ModuleWay(data.data)) //调用选择模块
- }
- // alert(data);
- // 每次数据加载完,必须重置
- // me.resetload();
- },
- error: function (xhr, type) {
- // alert('Ajax error!');
- // 即使加载出错,也得重置
- // me.resetload();
- }
- });
- // 上滑加载
- // $('.news_list').dropload({
- // // 调用加载
- // scrollArea : window,
- // threshold:2/3,
- // loadDownFn : function(me){
- //
- // }
- // });
- }
- // 选择各个模块
- function ModuleWay(conditions) {
- var _html = "";
- $.each(conditions.data, function (key, val) {
- if (val.thumb != null && val.thumb != "" && val.thumb.length == 1 && val.thumb_size == 1) {
- _html += '<div class="plan_one">';
- _html += '<a href="/news/details/' + val.id + '">';
- _html += '<div class="plan_one_title">';
- _html += '<p>' + val.subject + '</p>';
- _html += ' <p> <span class="guis">' + val.source + '</span><span class="data">' + val.open_time + '</span> <span class="see"><img src="/image/see.png" alt="">' + val.clicks + '</span></p>';
- _html += '</div>';
- _html += '<div class="plan_one_img"><img src="' + conditions.url + val.thumb[0] + '" alt=""></div>';
- _html += '</a>';
- _html += '</div>';
- } else if (val.thumb != null && val.thumb != "" && val.thumb.length > 1) {
- _html += '<div class="plan_two">';
- _html += '<a href="/news/details/' + val.id + '">';
- _html += '<div class="plan_two_title">' + val.subject + '</div>';
- _html += '<div class="plan_two_img">';
- _html += '<ul>';
- for (k in val.thumb) {
- _html += '<li><img src="' + conditions.url + val.thumb[k] + '" alt=""></li>';
- }
- _html += '</ul>';
- _html += '</div>';
- _html += '<div class="plan_two_label">' + val.source + '<span class="data">' + val.open_time + '</span> <span class="see"><img src="/image/see.png" alt="">' + val.clicks + '</span></div>';
- _html += '</a>';
- _html += '</div>';
- } else if (val.thumb_size == 2) {
- _html += '<div class="plan_three">';
- _html += '<a href="/news/details/' + val.id + '">';
- _html += '<div class="plan_two_title">' + val.subject + '</div>';
- _html += '<div class="plan_three_img"><img src="' + conditions.url + val.thumb[0] + '" alt=""></div>';
- _html += '<div class="plan_two_label">' + val.source + '<span class="data">' + val.open_time + '</span> <span class="see"><img src="/image/see.png" alt="">' + val.clicks + '</span></div>';
- _html += '</a>';
- _html += '</div>';
- }
- })
- return _html;
- }
- $(function () {
- // 判断 objUrl 是否从别到页面跳转到这里
- if (typeof objUrl.cid == "string") {
- thisID = objUrl.cid;
- }
- // 默认遍历第一个选中的数据
- // $('.news_nav ul li').eq(0).find('a').addClass('on');
- // $('.news_nav ul li').each(function(){
- // var $that = $(this);
- // var label = $that.find('a').attr('class');
- // var oid = $that.find('a').attr('data-id');
- // if(label == 'on'){
- // thisID = oid;
- // }
- // if(oid == thisID){
- // // console.log($that.html())
- // $that.find('a').addClass('on');
- // }
- //
- // })
- // 点击切换导航栏 ajax 切换
- $(".news_nav ul").on('click', 'li', function () {
- var $this = $(this);
- thisID = $this.find('a').attr('data-id');
- $('.news_list').html(""); //切换内容之前先清空盒子
- // AjaxFn(); //调用Ajax方法
- page = 0;
- fun();
- })
- console.log(thisID)
- function fun() {
- // 上滑加载
- $('.news_list').dropload({
- // 调用加载
- scrollArea: window,
- // threshold:2/3,
- loadDownFn: function (me) {
- page++;
- $('.dropload-down').show();
- $.ajax({
- type: 'GET',
- url: '/json/homeform?&page=' + page + '&limit=' + size + '&cid=' + thisID,
- dataType: 'json',
- success: function (data) {
- // console.log(data);
- if (data.code == 200) {
- $('.news_list').append(ModuleWay(data.data)) //调用选择模块
- } else {
- // 锁定
- me.lock();
- // 无数据
- me.noData();
- }
- // alert(data);
- // 每次数据加载完,必须重置
- setTimeout(function () {
- // 插入数据到页面,放到最后面
- // $('.news_list').append(result);
- // 每次数据插入,必须重置
- me.resetload();
- }, 1000);
- // me.resetload();
- $('.dropload-down').hide();
- },
- error: function (xhr, type) {
- // alert('Ajax error!');
- // 即使加载出错,也得重置
- me.resetload();
- }
- });
- }
- });
- }
- fun();
- })
|