var id = ''; //资讯id var view_num = '';//资讯阅读量 var sessionid = '';//sessionid var is_login = '';//判断用户是否登录 var qs = parseQueryString(window.location.href); $().ready(function () { if(qs.sessionid){ document.cookie="PHPSESSID=" + qs.sessionid + ';path=/' ; } if(qs.id) {id = qs.id;} if(qs.view_num) {view_num = qs.view_num} newsDetailEvent();//详情页接口 }) function newsDetailEvent () { //详情页接口数据 $.ajax({ type:'post', url:'/user/huaJiangHu/newsDetail', dataType:'json', data:{ id:id, view_num:view_num }, success:function(res){ if(res && res.errno == 0){ is_login = res.rst.is_login; var html = '',conHtml,contentHtml,commodityHtml=''; conHtml = `

${res.rst.title}

媒体来源:${res.rst.source} ${res.rst.publish_time}
${res.rst.view_num}阅读
${res.rst.content}
`; res.rst.product.forEach(function (item, index) { var amount = ''; if(item.upper_amount != item.lower_amount){ amount = `${item.upper_amount}-${item.lower_amount}` }else{ amount = `${item.upper_amount}` } commodityHtml += `
  • ${item.name} 期限${item.term}
    ${amount} 额度(元)
  • ` }) contentHtml = `

    产品推荐

    `; html = `${conHtml}${contentHtml}`; $(".container").html(html) goDetail();//点击推荐列表去详情 var jsons = { title:res.rst.title, desc:$(".con .content p").eq(0).text() }; jsons = JSON.stringify(jsons); webViewTitleContent(jsons) } console.log(res) } }) } //获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, ($0, $1, $2) => { urlObj[$1] = decodeURIComponent($2); }) return urlObj; } //点击推荐列表去详情 function goDetail () { $(".details").click(function () { var id = $(this).context.dataset.id; //判断用户是否登录 if (is_login == 1){ //用户已经登录 window.location.href = './details.html?id=' + id }else if (is_login == 0){ //用户未登录 window.location.href = './login.html?id=' + id } }) } //提示信息 function showMsg(msg) { var msg = msg; var msgBox = $('.alert-info'); msgBox.children('p').text(msg); msgBox.show(); setTimeout(function() { msgBox.hide(); }, 2000); } function webViewTitleContent(jsons) { console.log("点击") console.log(jsons) if(navigator.userAgent.indexOf('Android') != -1){ messageHandlers.webViewTitleContent(jsons) }else{ window.webkit.messageHandlers.webViewTitleContent.postMessage(jsons) } }