/* 更新时间:2021-05-19 更新人:change */ (function ($) { bt = $.fn; var imgmodel = {}; var filemodel = {}; bt.extend({ //bt: function () {}, //html转字符串 converthtmltostring: function (str) { var html = str || ""; html = html.replace(//g, ">"); return html; }, //字符串转html convertstringtohtml: function (str) { var html = str || ""; html = html.replace(/</g, "<"); html = html.replace(/>/g, ">"); return html; }, //过滤html removehtmltag: function (str) { str = str || ""; str = str.replace(/<\/?[^>]*>/g, ''); //去除html tag str = str.replace(/[ | ]*\n/g, ''); //去除行尾空白 str = str.replace(/ /ig, '');//去掉  str = str.replace(/\n[\s| | ]*\r/g, ''); //去除多余空行 return str; }, //跟据id得到子类所有控件(from中的交互控件)以json形式返回 getjsonbyid: function (id) { var this$ = $(id); return this$.serializearray(); }, //ajax post post: function (url, obj, callback) { $.post(url, obj, callback) .error(function (xhr, errortext, errortype) { //异常时执行 alert(xhr.responsetext); }) .complete(function () { }); //完成后执行 }, /*********************************************** 获取url的参数值 参数说明 name:url内参数名称 返回:参数值,字符型 ***********************************************/ getquerystring: function (name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeuricomponent(r[2]); return ""; }, /*********************************************** 转换json的日期值(如:/date(1555554794000)/) 参数说明 val:"/date(123456789***)/"格式的日期串 返回结果类型:字符型 ***********************************************/ changedateformat: function (val) { if (val != null) { var date = new date(parseint(val.replace("/date(", "").replace(")/", ""), 10)); //月份为0-11,所以+1,月份小于10时补个0 var month = date.getmonth() + 1 < 10 ? "0" + (date.getmonth() + 1) : date.getmonth() + 1; var currentdate = date.getdate() < 10 ? "0" + date.getdate() : date.getdate(); var hour = date.gethours() < 10 ? "0" + date.gethours() : date.gethours(); var minute = date.getminutes() < 10 ? "0" + date.getminutes() : date.getminutes(); var second = date.getseconds() < 10 ? "0" + date.getseconds() : date.getseconds(); return date.getfullyear() + "-" + month + "-" + currentdate + " " + hour + ":" + minute + ":" + second; } return ""; }, /*********************************************** 函数:格式化date型数据 参数:val:格式化字符串,完整格式如(可按需简化):"yyyy-mm-dd hh:mm:ss" 返回:字符型数据 ***********************************************/ dateformat: function (obj, val) { var o = { "m+": obj.getmonth() + 1, //month 月 "d+": obj.getdate(), //day 日 "h+": obj.gethours(), //hour 时 "m+": obj.getminutes(), //minute 分 "s+": obj.getseconds(), //second 秒 "q+": math.floor((obj.getmonth() + 3) / 3), //quarter 季度 "s": obj.getmilliseconds() //millisecond 毫秒 } if (/(y+)/.test(val)) { //年 val = val.replace(regexp.$1, (obj.getfullyear() + "").substr(4 - regexp.$1.length)); } for (var k in o) { if (new regexp("(" + k + ")").test(val)) { val = val.replace(regexp.$1, regexp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return val; }, /*********************************************** 拆分日期进行排版 参数说明 obj:父元素标识,如:".news .time" child1:子1元素标识,如:".day" format1:子1元素内容格式,如:"dd" child2:子2元素标识,如:".month" format2:子2元素内容格式,如:"mm" child3:子3元素标识,如:".year" format3:子3元素内容格式,如:"yyyy" 返回:无 ***********************************************/ splitdate: function (obj, child1, format1, child2, format2, child3, format3) { child1 = typeof child1 == "undefined" ? ".year" : child1; format1 = typeof format1 == "undefined" ? "yyyy" : format1; if (typeof child2 != "undefined") { child2 = typeof child2 == "undefined" ? ".month" : child2; format2 = typeof format2 == "undefined" ? "mm" : format2; } if (typeof child3 != "undefined") { child3 = typeof child3 == "undefined" ? ".day" : child3; format3 = typeof format3 == "undefined" ? "dd" : format3; } $(obj).each(function () { var datearr = $(this).attr("date"); datearr = datearr.replace(/\-/g, "/"); var datetime = new date(datearr); $(this).find(child1).html(datetime.format(format1)); if (typeof child2 != "undefined") $(this).find(child2).html(datetime.format(format2)); if (typeof child3 != "undefined") $(this).find(child3).html(datetime.format(format3)); }); }, /*********************************************** 栏目选中效果 公用 参数说明 obj:父元素标识,如:".menu li" css:选中的样式表,如:"active" domain:和父元素中子元素对比的url,若不传则从地址栏动态获取,若传值格式如:"/101_newslist.html" default_select1: 是否默认选中第一个元素 返回:子元素索引值,数值型 ***********************************************/ selectchannel: function (obj, css, domain, default_select1) { var curr_index = -1; var f = $(obj); domain = typeof domain == "undefined" ? location.href : domain; domain = domain.tolowercase(); f.each(function (index, item) { var cf = $(item); var h = cf.attr("href"); if (typeof h == "undefined") { cf = $(item).find("a"); h = cf.attr("href"); } h = h.tolowercase(); h = h.lastindexof("/") > 0 ? h.substring(h.lastindexof("/") + 1) : h; if (domain.indexof(h.split('.')[0]) >= 0) { $(item).addclass(css); curr_index = index; } }); if (curr_index < 0 && default_select1 == true) { $(obj + ':eq(0)').addclass(css); } return curr_index; }, /*********************************************** 更新、获取阅读量/点击量(文章/产品) 参数说明 type:news代表文章,pro代表产品 obj:元素对象 isupdate:0只获取不更新,1先更新再获取 返回:无 ***********************************************/ gethits: function (type, obj, isupdate) { var f = typeof $(obj) == "undefined" ? $("#hits") : $(obj); //html中定义的元素 isupdate = typeof isupdate == "undefined" ? "1" : isupdate; if (f.length > 0) { $.each(f, function () { var obj_h = $(this); var infoid = obj_h.attr("data-id"); console.log(isupdate, infoid) $.post("/viewsiteapi/handle/updateinfohits", { type: type, infoid: infoid, isupdate: isupdate }, function (res) { obj_h.text(res.message); }); }); } }, /*********************************************** 网站计数器,一般放置于网站底部 参数说明 type:pc代表pc站,m代表手机站 返回:无 ***********************************************/ getcounter: function (type) { var f = $("#counter"); //html中定义的元素 if (f.length > 0) { var _url = "/viewsiteapi/handle/getcounter?sitetype=" + type; $.get(_url, function (data, status) { try { f.text(data); } catch (err) { } }); } }, /*********************************************** “加载更多”方式翻页加载数据 参数说明 _bind:绑定数据的标签元素,如:.prolist more_data:参数集合 返回:无 ***********************************************/ getmoredata: function (_bind) { var menu_html = $(".loadmore").html(); $(".loadmore").click(function () { $(".loadmore").html(""); more_data.page += 1; $.post("/viewsiteapi/handle/more_pagelist", more_data, function (res) { $(".loadmore").html(menu_html); //console.log("第" + more_data.page + "页:", json.stringify(res)); //loggggggggggggggggggggggggggg if (res.result == 1) { if (res.data.content != "") { if (_bind != "") $(_bind).append(res.data.content); else $(".pagelist").prev().append(res.data.content); if (more_data.page >= more_pagaincount) $(".loadmore").hide(); } else $(".loadmore").hide(); } else { alert(res.message); } }); }); }, /*********************************************** 弹出上传图像窗口 参数说明 backi:上传控件id,如:file1 返回:无 ***********************************************/ uploadimg: function (backi) { imgmodel.backi = imgmodel.backi || ""; var url = "/upload/upimg?backi=" + backi + "&oldfile=" + imgmodel.backi; layer.open({ type: 1, content: "", }); imgmodel.backi = ""; }, /*********************************************** 返回上传图像结果 参数说明 backi:上传控件id,如:file1 path:上传后返回的文件路径 返回:无 ***********************************************/ uploadimgsuccess: function (backi, path) { imgmodel.backi = path; $("#" + backi).val(path); }, /*********************************************** 弹出上传附件窗口 参数说明 backi:上传控件id,如:file1 返回:无 ***********************************************/ uploadfile: function (backi) { filemodel.backi = filemodel.backi || ""; var url = "/upload/upfile?backi=" + backi + "&oldfile=" + filemodel.backi; layer.open({ type: 1, content: "", }); filemodel.backi = ""; }, /*********************************************** 返回上传附件结果 参数说明 backi:上传控件id,如:file1 path:上传后返回的文件路径 返回:无 ***********************************************/ uploadfilesuccess: function (backi, path) { filemodel.backi = path; $("#" + backi).val(path); if ($("." + backi).length > 0) { var arry = path.split('_'); $("." + backi).text(arry[arry.length - 1]); } }, /******* more function *********/ }); })(jquery); $(function () { /*********************************************** 函数:日期 加n天 参数:n:天数,正数代表加n天,负数代表减n天 返回:date型n天前/后的日期 ***********************************************/ date.prototype.adddays = date.prototype.adddays || function (n) { this.setdate(this.getdate() + n); return this; } /*********************************************** 函数:格式化date型数据 参数:val:格式化字符串,完整格式如(可按需简化):"yyyy-mm-dd hh:mm:ss" 返回:字符型数据 ***********************************************/ date.prototype.format = function (val) { return bt.dateformat(this, val); } //自动检测终端 jquery.getscript("/content/usersite/autoclient.js?210521"); //网站访问统计 jquery.getscript("http://passport.v3.hnrich.net/content/script/accesslog/custom.js?210521"); });