Commit 5aa54a93 by 施宇

3213

parent e0eaf2e3
......@@ -55,15 +55,9 @@
</div>
</div>
<div class="search_command clr">
<span class="fl comman_title">热门搜索:</span>
<div class="fl command_name">
<volist name="hot_goods" id="vo">
<a class="fl" href="{$vo.url}" title="{$vo.title}" target="_blank">{$vo.title}</a>
</volist>
</div>
</div>
</div>
<div class="my_xj">
<div class="my_xj_title xj_title">
<span class="lineBlock"></span>
......@@ -88,6 +82,16 @@
</div>
<include file="public/foot" />
<script src="__PUBLIC__/js/home/index.js"></script>
<script type="text/html" id="hotTpl">
{{# if(d.length != 0){ }}
<span class="fl comman_title">热门搜索:</span>
<div class="fl command_name">
{{# layui.each(d, function(index, item){ }}
<div class="fl hot_item" title="{{item.title}}">{{item.title}}</div>
{{# }); }}
</div>
{{# } }}
</script>
<script type="text/html" id="xjTpl">
<!-- 询价模板 -->
<div class="my_xj_list clr">
......
......@@ -110,14 +110,14 @@
color: #8A9299;
width: 625px;
}
.home_content .search_section .search_command .command_name a {
.home_content .search_section .search_command .command_name div {
margin-left: 20px;
cursor: pointer;
transition: all 0.2s ease-in-out;
display: block;
}
.home_content .search_section .search_command .command_name a.active,
.home_content .search_section .search_command .command_name a:hover {
.home_content .search_section .search_command .command_name div div.active,
.home_content .search_section .search_command .command_name div:hover {
color: #0D84D1;
}
.home_content .xj_title {
......@@ -257,4 +257,3 @@
.home_content .new_xj .new_xj_list .new_xj_item:hover {
box-shadow: 0px 5px 10px 0px rgba(216, 223, 230, 0.5);
}
/*# sourceMappingURL=home.css.map */
\ No newline at end of file
......@@ -136,13 +136,12 @@
color: #8A9299;
width: 625px;
a {
div {
margin-left: 20px;
cursor: pointer;
transition: all 0.2s ease-in-out;
display: block;
&.active ,&:hover{
div.active ,&:hover{
color: #0D84D1;
}
}
......
......@@ -61,6 +61,10 @@
* 获取会员认证信息
*/
authInfo: user_url + '/user/authinfo',
/****
* 获取热门搜索商品
*/
hotgoods: home_url + '/hotgoods',
/***
* 上传文件的接口
*/
......@@ -89,7 +93,7 @@
* 商品修改
*/
goodsSave: goods_url + '/goods/save',
/***
/***
* 商品上下架
*/
goodsStatus: goods_url + "/goods/status",
......@@ -117,7 +121,7 @@
* 询价统计
*/
inquirycount: offer_url + "/inquiry/count",
/***
* 报价统计
*/
......
!function () {
! function () {
window.IcController = {
init: function () {
this.created(this).mounted(this).handleBind(this);
},
getData: function (url, type, param, callback, isload, isheader) {
//是否启动loadin效果
if (isload == undefined) {
var index = layer.load(1, {
offset: ['50%', "50%"],
shade: false
});
}
var platform = {
source: 2
};
var params = $.extend({}, platform, param);
//跨域模式切换 兼容
var dataTypeXpx = "json";
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) {
dataTypeXpx = "jsonp";
}
if (isheader) {
$.ajaxSetup({
headers: {
......@@ -34,7 +34,7 @@
},
});
}
$.ajax({
type: type,
url: url,
......@@ -44,170 +44,174 @@
withCredentials: true
},
success: function (data) {
//处理token失效的情况
if (data.errcode === 501 || data.err_code === 501) {
layer.msg('登录已失效,请重新登录', {
time: 600
}, function () {
window.location.href = passport_url + '/login';
});
} else {
typeof callback == 'function' && callback(data);
layer.close(index);
}
return false;
},
error: function () {
layer.close(index);
layer.msg('网络出现问题,请重试!');
$(".btn").removeClass('layui-btn-disabled');
return false;
}
});
},
created: function (opt) {
if ($('#head_pic').length > 0) {
//获取用户信息
this.getData(apis.userInfo, 'GET', {token: Util.getCookie('token') || ''}, function (res) {
this.getData(apis.userInfo, 'GET', {
token: Util.getCookie('token') || ''
}, function (res) {
if (res.errcode === 0) {
//消息数量
$("#count_num").empty().html(res.data['msg_notification']);
//设置头像
if (res.data.avatar) {
$("#head_pic").find('img').attr('src', res.data['avatar']);
$(".info_logo").attr('src', res.data['avatar']);
}
//首页信息
if ($(".user_home").length > 0) {
$(".user_home").find(".company").empty().html(res.data['company_name']);
$(".user_home").find(".tel").empty().html(res.data['mobile']);
$(".user_home").find(".last_login_time").empty().html(res.data['last_login_time']);
$(".user_home").find(".info_desc").children('p').empty().html('Hi,' + Util.getTimeState());
}
//首页统计
if ($(".price_info").length > 0) {
IcController.getData(apis.countBusiness, 'GET', {token: Util.getCookie('token') || ''}, function (res) {
IcController.getData(apis.countBusiness, 'GET', {
token: Util.getCookie('token') || ''
}, function (res) {
$(".price_info").find('.xj').children('.xj_num').text(res.data.inquiry); //我的询价
$(".price_info").find('.hf').children('.hf_num').text(res.data.offer); //我的回复
$(".price_info").find('.sp').children('.sp_num').text(res.data.goods);//我的商品
$(".price_info").find('.sp').children('.sp_num').text(res.data.goods); //我的商品
});
}
}
});
}
return this;
},
mounted: function (opt) {
//导航栏
var isShow = $('.xbj_li').find('dl').css('display');
if (isShow == 'none') {
$('.xbj_li').find('.li_right').removeClass('iconjuxing15').addClass('iconjuxing12');
} else {
$('.xbj_li').find('.li_right').removeClass('iconjuxing12').addClass('iconjuxing15');
}
return this;
},
handleBind: function (opt) {
//导航栏
$('.xbj_li').on('click', function () {
var isShow = $(this).find('dl').css('display');
if (isShow == 'none') {
$(this).find('dl').slideDown();
$('.xbj_li').find('.li_right').removeClass('iconjuxing12').addClass('iconjuxing15');
} else {
$(this).find('dl').slideUp();
$('.xbj_li').find('.li_right').removeClass('iconjuxing15').addClass('iconjuxing12');
}
});
$('#nav_logo').on('click',function(){
$('#nav_logo').on('click', function () {
var token = Util.getCookie('token') || "";
if(token){
if (token) {
window.location.href = '/homes';
}else{
} else {
window.location.href = index_url;
}
})
//退出
$(".nav_end").on('click', function () {
layer.confirm('您确定退出系统嘛', {
icon: 3,
title: '提示',
move: false
}, function (index) {
opt.getData(apis.authLogout, 'POST', null, function (res) {
if (res.err_code === 0) {
Util.delCookie('token', cookieHostname);
window.location.href = index_url;
} else {
layer.msg(res.err_msg);
}
}, undefined, true);
layer.close(index);
})
});
return this;
},
}, $(function () {
......@@ -227,17 +231,17 @@
* @returns {boolean}
*/
setCookie: function (name, value, time, domain) {
domain = domain ? ";domain=" + domain : "";
var Days = time;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
document.cookie = name + "=" + value + ";expires=" + exp.toGMTString() + ";path=/" + domain;
return true;
},
/**
......@@ -246,19 +250,19 @@
* @returns {*}
*/
getCookie: function (name) {
var strCookie = document.cookie;
var arrCookie = strCookie.split("; ");
for (var i = 0; i < arrCookie.length; i++) {
var arr = arrCookie[i].split("=");
if (name == arr[0]) {
return arr[1];
}
}
return "";
......@@ -268,17 +272,17 @@
* @param name
*/
delCookie: function (name, domain) {
domain = domain ? ";domain=" + domain : "";
var exp = new Date();
exp.setTime(exp.getTime() - 10000);
document.cookie = name + "=" + '' + ";expires=" + exp.toGMTString() + ";path=/" + domain;
return true;
},
/**
* 获取参数
......@@ -286,28 +290,28 @@
* @returns {*}
*/
getRequest: function (value) {
if (window.location.pathname == "/s/") {
var url = unescape(location.search);
} else {
var url = decodeURI(location.search);
}
var object = {};
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
object[strs[i].split("=")[0]] = strs[i].split("=")[1];
}
}
return object[value];
......@@ -318,50 +322,50 @@
* @returns {string}
*/
getDateStr: function (val) {
var dd = new Date();
dd.setDate(dd.getDate() + val);
var y = dd.getFullYear();
var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);
var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
return y + "-" + m + "-" + d;
},
/**
* 时间问候语
*/
getTimeState: function () {
var timeNow = new Date();
// 获取当前小时
var hours = timeNow.getHours();
// 设置默认文字
var text = '';
// 判断当前时间段
if (hours >= 0 && hours <= 10) {
text = '早上好';
} else if (hours > 10 && hours <= 14) {
text = '中午好';
} else if (hours > 14 && hours <= 18) {
text = '下午好';
} else if (hours > 18 && hours <= 24) {
text = '晚上好';
}
return text;
},
/**
......@@ -370,25 +374,25 @@
* @returns {string}
*/
getDay: function (day) {
var today = new Date();
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
today.setTime(targetday_milliseconds);
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = this.doHandleMonth(tMonth + 1);
tDate = this.doHandleMonth(tDate);
return tYear + "-" + tMonth + "-" + tDate + ' 00:00:00';
},
/**
* 对月份进行处理
......@@ -396,56 +400,148 @@
* @returns {*|string}
*/
doHandleMonth: function (month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
}
return m;
},
randomStr: function () { //随机生成八位字符串
var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var newStr = "";
for (var i = 0; i < 8; i++) {
var randomNum = parseInt(Math.random() * ((str.length - 1) + 1), 10);
newStr += str.substr(randomNum, 1)
}
return newStr
},
dataEncryption: function () { //数据加密
var timestamp = Date.parse(new Date()) / 1000;
var randomStr = this.randomStr();
var token = 'zbPx8gDXDfIh3ZoJcO4EH';
var arr = [timestamp, randomStr, token];
var singnatrueStr = this.sha1(this.sort(arr).join('')).toUpperCase();
return {
randomStr: randomStr,
singnatrueStr: singnatrueStr,
timestampStr:timestamp
}
},
sort: function (arr) { //数组排序
for (var j = 0; j < arr.length; j++) {
for (var i = 0; i < arr.length - 1 - j; i++) {
if (arr[i] > arr[i + 1]) {
[arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]
}
}
}
return arr;
},
encodeUTF8: function (s) { //sha1的方法
var i, r = [],
c, x;
for (i = 0; i < s.length; i++)
if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
else {
if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
else r.push(0xE0 + (c >> 12 & 0xF));
r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
};
return r;
},
sha1: function (s) { //sha1的方法
var data = new Uint8Array(this.encodeUTF8(s))
var i, j, t;
var l = ((data.length + 8) >>> 6 << 4) + 16,
s = new Uint8Array(l << 2);
s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
for (t = new DataView(s.buffer), i = 0; i < l; i++) s[i] = t.getUint32(i << 2);
s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
s[l - 1] = data.length << 3;
var w = [],
f = [
function () {
return m[1] & m[2] | ~m[1] & m[3];
},
function () {
return m[1] ^ m[2] ^ m[3];
},
function () {
return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
},
function () {
return m[1] ^ m[2] ^ m[3];
}
],
rol = function (n, c) {
return n << c | n >>> (32 - c);
},
k = [1518500249, 1859775393, -1894007588, -899497514],
m = [1732584193, -271733879, null, null, -1009589776];
m[2] = ~m[0], m[3] = ~m[1];
for (i = 0; i < s.length; i += 16) {
var o = m.slice(0);
for (j = 0; j < 80; j++)
w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
for (j = 0; j < 5; j++) m[j] = m[j] + o[j] | 0;
};
t = new DataView(new Uint32Array(m).buffer);
for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2);
var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
return (e < 16 ? "0" : "") + e.toString(16);
}).join("");
return hex;
}
};
if (typeof define === "function" && define.amd) {
return Util;
} else {
window.Util = Util;
}
})(window);
//form序列化json
$.fn.serializeJson = function () {
var serializeObj = {};
var array = this.serializeArray();
var str = this.serialize();
$(array).each(function () {
if (serializeObj[this.name]) {
if ($.isArray(serializeObj[this.name])) {
serializeObj[this.name].push(this.value);
} else {
serializeObj[this.name] = [serializeObj[this.name], this.value];
}
} else {
serializeObj[this.name] = this.value;
}
});
return serializeObj;
......
......@@ -4,6 +4,35 @@ $(function () {
this.bindFun();
this.getXbData(1);
this.getNewXj();
this.getHotGoods()
},
getHotGoods: function () {
var obj = Util.dataEncryption();
IcController.getData(apis.hotgoods, 'GET', {
timestamp: obj.timestampStr,
random: obj.randomStr,
signature: obj.singnatrueStr
},
function (res) {
var hotHtml = hotTpl.innerHTML;
if (res.err_code === 0) {
if (res.data.length) {
layui.laytpl(hotHtml).render(res.data, function (html) {
$(".search_command").empty().html(html);
});
} else {
layui.laytpl(hotHtml).render([], function (html) {
$(".search_command").empty().html(html);
});
}
} else {
layui.laytpl(hotHtml).render([], function (html) {
$(".search_command").empty().html(html);
});
}
})
},
getXbData: function (type) { //1报价 2询价
var url;
......@@ -78,7 +107,7 @@ $(function () {
} else if (val.length < 3) {
layer.msg('请至少输入3个字符')
} else {
window.location.href = "/search?key=" + val+'&type=1&time=1';
window.location.href = "/search?key=" + val + '&type=1&time=1';
}
});
......@@ -97,7 +126,13 @@ $(function () {
var userid = $(this).attr('userid'),
offerid = $(this).attr('offerid')
window.location.href = "/quotedetail?id=" + userid + '&offerid=' + offerid
})
});
$('.search_command').on('click', '.hot_item', function () {
var title = $(this).attr('title');
window.location.href = "/search?key=" + title + '&type=1&time=1';
});
}
};
homeObj.init()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment