MVC判断登录


@{
ViewBag.Title = "StorecollectIndex";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>StorecollectIndex</h2>
<script>
var UId = 0;
$(function () {
//判断是否登录
if (getCookie("UsersInfo") == null) {
this.location.href = '/Sale/LoginIndex';
}
else {
var list = JSON.parse(getCookie("UsersInfo"));
UId = list[0].UId;
}
StoreBound();
GoodsBound();
})
function StoreBound() {
$.ajax({
url: "http://localhost:57190/api/Sale/GetStroesCollectInfos",
async: false,
data: { UId: UId },
type: "get",
dataType: "json",
success: function (d) {
var str = "";
$("#Store").empty();
$(d).each(function (i, n) {
str += "<div style='float:left;margin-left:20px;margin-top:20px'><input id='SId' type='hidden' value='" + n.SId + "'/><img src='http://localhost:57190" + n.StoresInfoSId.SImge + "' width='85px' height='85px'/><br/> <a href='/Sale/GoodsInfoDetailIndex?SId=" + n.SId + "''><lable>" + n.StoresInfoSId.SName + "</lable></a><lable>" + n.StoresInfoSId.SPeople + "</lable></div>"
})
$("#Store").append(str);
},
complete: function (d) {

}

})
}
function GoodsBound() {
$.ajax({
url: "http://localhost:57190/api/Sale/GetGoodsInfos",
async: false,
data: { SId: $("#SId").val() },
type: "get",
dataType: "json",
success: function (d) {
var str = "";
$("#Goods").empty();
$(d).each(function (i, n) {
str += "<div style='float:left;margin-left:20px'><input id='GId' type='hidden' value='" + n.GId + "'/><img src='http://localhost:57190" + n.GImg + "' width='60px' height='60px'/><br/> <a href='/Sale/GoodsInfoDetailIndex?GId=" + n.GId + "''><lable>" + n.GName + "</lable></a></div>"

})
$("#Goods").append(str);
}
})
}

/* cookie中存值
*/
function setCookie(name, value) {
if (value) {
var days = 1; //定义一天
var exp = new Date();
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
// 写入Cookie, toGMTString将时间转换成字符串
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
}
};

/**
* cookie中取值
* */
function getCookie(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
if (arr = document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return null;
}
};
</script>
<div id="Store" style="float:left">

</div>
<div id="Goods" style="float:right">

</div>

 

posted @ 2020-07-09 18:56  N_o  阅读(11)  评论(0编辑  收藏  举报