ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(16)之轻博客
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c
项目到上面一步其实已经算完成了,轻博客是本项目的一个附属功能,按个人意愿加上用于记录自己的知识以及资讯以及留言评论,更多的是为了提高自己的同时分享和记录自己的成长见解,当然你也可以赋予他们不同的定义,也可以忽略这一块的功能。
该博客是基于layui的轻量级博客模板布局,喜欢的朋友可以到官网或者这里下载,期待你能创造出属于你的风格。
同理,首先我们需要在表现层的最外层Shared文件夹下创建一个布局页_LayoutArticle.cshtml:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>@ViewBag.Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="~/Content/Scripts/jquery/jquery-1.8.2.min.js"></script>
<script src="~/Content/Scripts/boboui-jshelp.js"></script>
<script src="~/Content/Scripts/layer/layer.js"></script>
<script src="~/Content/Web/js/jquery.page.js"></script>
<link href="~/Content/Styles/base.css" rel="stylesheet" />
<link href="~/Content/Scripts/layer/css/layui.css" rel="stylesheet" />
<link href="~/Content/Web/css/Article.css" rel="stylesheet" />
</head>
<body>
<div>
<div>
<h1 class="logo pull-left">
<a href="/">
<img src="~/Content/Web/img/logo2.png" />
</a>
</h1>
<div class="layui-form blog-seach pull-left" >
<div class="layui-form-item blog-sewrap">
<div class="layui-input-block blog-sebox">
<i class="icon glyphicon-search" onclick="seachFrom()"></i>
<input type="text" name="title" id="title" lay-verify="title" autocomplete="off">
</div>
</div>
</div>
<div class="blog-nav pull-right">
<ul class="layui-nav pull-left">
<li class="layui-nav-item zw layui-this"><a href="/WebArticle/Index?ArticleType=zw">杂文</a></li>
<li class="layui-nav-item lx"><a href="/WebArticle/Index?ArticleType=lx">行走</a></li>
<li class="layui-nav-item yy"><a href="/WebArticle/Index?ArticleType=yy">音乐</a></li>
<li class="layui-nav-item tx"><a href="/WebArticle/Index?ArticleType=tx">图影</a></li>
</ul>
<a href="/MemberCenterModule/MemberSystem/Index" class="personal pull-left">
<i class="icon glyphicon-user"></i>
</a>
</div>
<div class="mobile-nav pull-right" id="mobile-nav">
<a href="javascript:;">
<i class="icon glyphicon-menu-hamburger"></i>
</a>
</div>
</div> </div>
@RenderBody()
<div>
<p>
<span>© 2018</span>
<span><a href="/" target="_blank">yealuo.com</a></span>
<span>Absorbed</span>
</p>
<p><span>致力于指尖上的艺术,敲击出属于自己的代码人生</span></p>
</div>
<script type="text/javascript">
var ArticleType = GetQuery('ArticleType').replace("null", "zw");
//回车键
document.onkeydown = function (e) {
if (!e) e = window.event; //火狐中是 window.event
if ((e.keyCode || e.which) == 13) {
seachFrom();
}
}
function seachFrom() {
window.location.href = '/WebArticle/Index?ArticleTitle=' + $('#title').val() + "&ArticleType=" + ArticleType;
}
$(function () {
$(".layui-nav-item").removeClass("layui-this");
$("." + ArticleType).addClass("layui-this");
});
</script>
</body>
</html>
然后在表现层最外层的Controller文件下创建控制器WebArticleController.cs:
using Bobo.Utilities;
using Bobo.Utilities.Membership;
using IA.Business;
using IA.Entity;
using IA.WebApp.SystemExtension;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace IA.WebApp.Controllers
{
/// <summary>
/// 网站文章控制器
/// </summary>
public class WebArticleController : Controller
{
//
// GET: /WebArticle/
/// <summary>
/// 文章列表页
/// </summary>
/// <param name="ArticleType"></param>
/// <returns></returns>
public ActionResult Index(string ArticleType, string ArticleTitle, int p = 1)
{
JqGridParam jgp = new JqGridParam();
jgp.page = p;
jgp.rows = 15;
jgp.records = 0;
jgp.sidx = "CreateDate";
jgp.sord = "DESC"; var seachStr = "";
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
ArticleType = ArticleType.Replace(" ", "zw");
seachStr += "&ArticleType=" + ArticleType;
}
else
{
ArticleType = "zw";
}
if (!StringHelper.IsNullOrEmpty(ArticleTitle))
{
ArticleTitle = ArticleTitle.Replace(" ", "");
seachStr += "&ArticleTitle=" + ArticleTitle;
}
ViewBag.ArticleType = ArticleType;
ViewBag.seachStr = seachStr;
Com_ArticleBll all = new Com_ArticleBll();
ViewBag.model = all.GetListPage(ArticleTitle, ArticleType, ref jgp);
ViewBag.pageData = jgp;
return View();
}
/// <summary>
/// 文章详细页
/// </summary>
/// <param name="KeyValue"></param>
/// <param name="ArticleType"></param>
/// <returns></returns>
public ActionResult Detail(string KeyValue, string ArticleType, int p = 1)
{
#region 评论信息
JqGridParam jgp = new JqGridParam();
jgp.page = p;
jgp.rows = 15;
jgp.records = 0;
jgp.sidx = "CreateDate";
jgp.sord = "DESC";
var seachStr = "";
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
ArticleType = ArticleType.Replace(" ", "zw");
seachStr += "&ArticleType=" + ArticleType;
}
if (!StringHelper.IsNullOrEmpty(KeyValue))
{
KeyValue = KeyValue.Replace(" ", "");
seachStr += "&KeyValue=" + KeyValue;
}
ViewBag.Msg = new OND_MessageReplyBll().GetListPage(KeyValue, ref jgp);
ViewBag.pageData = jgp;
#endregion
Com_ArticleBll all = new Com_ArticleBll();
Com_Article enity = all.Factory.FindEntity(KeyValue); ViewBag.PrveArt = all.GetArticleListByTime(ArticleType, enity.CreateDate, 0).Count > 0 ? all.GetArticleListByTime(ArticleType, enity.CreateDate, 0)[0] : null;
ViewBag.NextArt = all.GetArticleListByTime(ArticleType, enity.CreateDate, 1).Count > 0 ? all.GetArticleListByTime(ArticleType, enity.CreateDate, 1)[0] : null;
return View(enity);
} //[LoginAuthorize("~/MemberCenterModule/MemberRegLogin/login")]
/// <summary>
/// 提交留言信息
/// </summary>
/// <param name="enity"></param>
/// <returns></returns>
public ActionResult SubMsgData(string msg, string DataID, string ParentID)
{
OND_MessageReplyBll bll = new OND_MessageReplyBll();
try
{
OND_MessageReply enity = new OND_MessageReply();
int IsOk = 0;
string Message = "提交失败";
bool Success = false;
if (ManageProvider.Provider.IsOverdue())
{
enity.DataID = DataID;
enity.ParentID = ParentID;
enity.MessageReplyCenter = msg;
enity.Create();
IsOk = bll.Factory.Insert(enity);
if (IsOk > 0)
{
Message = "提交成功";
IsOk = 1;
Success = true;
}
}
else
{
Message = "请登录后再提交评论信息!";
IsOk = 0;
Success = false;
}
return Content(new JsonMessage { Success = Success, Code = IsOk.ToString(), Message = Message }.ToString());
}
catch (Exception ex)
{
return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString());
}
} /// <summary>
/// 操作评论
/// </summary>
/// <param name="KeyValue"></param>
/// <returns></returns>
public ActionResult SetGiveDelMsg(string KeyValue, int? num)
{
OND_MessageReplyBll bll = new OND_MessageReplyBll();
try
{ int IsOk = 0;
string Message = "操作失败";
bool Success = false;
if (!StringHelper.IsNullOrEmpty(KeyValue))
{
OND_MessageReply enity = bll.Factory.FindEntity(KeyValue);
if (num > 0)
{
enity.DeleteMark = 1;
}
else
{
enity.GiveNum = enity.GiveNum + 1;
}
enity.Modify(KeyValue, false);
IsOk = bll.Factory.Update(enity);
if (IsOk > 0)
{
Message = "操作成功";
IsOk = 1;
Success = true;
}
} return Content(new JsonMessage { Success = Success, Code = IsOk.ToString(), Message = Message }.ToString());
}
catch (Exception ex)
{
return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString());
}
} /// <summary>
/// 设置浏览量
/// </summary>
/// <param name="KeyValue"></param>
/// <returns></returns>
public ActionResult SubSetBrwGiveNum(string KeyValue, int GiveNum = 0, int BrowseNum = 0)
{
Com_ArticleBll bll = new Com_ArticleBll(); DbTransaction transaction = bll.Factory.BeginTrans();
try
{
int IsOk = 0;
string Message = "操作失败。";
bool Success = false;
if (!StringHelper.IsNullOrEmpty(KeyValue))
{
Com_Article enity = bll.Factory.FindEntity(KeyValue);
enity.BrowseNumber = enity.BrowseNumber + BrowseNum;
enity.GiveNum = enity.GiveNum + GiveNum;
enity.Modify(KeyValue, false);
IsOk = bll.Factory.Update(enity); if (IsOk > 0)
{
Message = "操作成功";
IsOk = 1;
Success = true;
}
} return Content(new JsonMessage { Success = Success, Code = IsOk.ToString(), Message = Message }.ToString());
}
catch (Exception ex)
{
return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString());
}
} }
}
然后我们完善业务层中的方法:
(1)Com_ArticleBll.cs
using Bobo.DataAccess;
using Bobo.Repository;
using Bobo.Utilities;
using IA.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace IA.Business
{
// <summary>
/// 文章信息表
/// <author>
/// <name>YHB</name>
/// <date>2018.10.18</date>
/// </author>
/// </summary>
public class Com_ArticleBll : RepositoryFactory<Com_Article>
{
/// <summary>
/// 获取文章数据
/// </summary>
/// <param name="ArticleTitle"></param>
/// <param name="jgp"></param>
/// <returns></returns>
public DataTable GetTablePage(string ArticleTitle, string ArticleType, ref JqGridParam jgp)
{
StringBuilder whereSql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1");
if (!StringHelper.IsNullOrEmpty(ArticleTitle))
{
whereSql.Append(@" AND ArticleTitle LIKE @ArticleTitle");
param.Add(DbFactory.CreateDbParameter("@ArticleTitle", '%' + ArticleTitle + '%'));
}
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
whereSql.Append(@" AND ArticleType=@ArticleType");
param.Add(DbFactory.CreateDbParameter("@ArticleType", ArticleType));
}
return Factory.FindTablePage(whereSql.ToString(), param.ToArray(), ref jgp);
}
/// <summary>
/// 获取list分页数据
/// </summary>
/// <param name="ArticleTitle"></param>
/// <param name="ArticleType"></param>
/// <param name="jgp"></param>
/// <returns></returns>
public List<Com_Article> GetListPage(string ArticleTitle, string ArticleType, ref JqGridParam jgp)
{
StringBuilder whereSql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1");
if (!StringHelper.IsNullOrEmpty(ArticleTitle))
{
whereSql.Append(@" AND ArticleTitle LIKE @ArticleTitle");
param.Add(DbFactory.CreateDbParameter("@ArticleTitle", '%' + ArticleTitle + '%'));
}
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
whereSql.Append(@" AND ArticleType=@ArticleType");
param.Add(DbFactory.CreateDbParameter("@ArticleType", ArticleType));
}
return Factory.FindListPage(whereSql.ToString(), param.ToArray(), ref jgp);
}
/// <summary>
/// 网站分页数据
/// </summary>
/// <param name="ArticleTitle"></param>
/// <param name="ArticleType"></param>
/// <param name="PutTimeStart"></param>
/// <param name="PutTimeEnd"></param>
/// <param name="jgp"></param>
/// <returns></returns>
public DataTable GetWebTablePage(string ArticleTitle, string ArticleType, DateTime? PutTimeStart, DateTime? PutTimeEnd, ref JqGridParam jgp)
{
StringBuilder whereSql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>(); whereSql.Append(@" AND DeleteMark<>1 AND State=1");
if (!StringHelper.IsNullOrEmpty(ArticleTitle))
{
whereSql.Append(@" AND ArticleTitle LIKE @ArticleTitle");
param.Add(DbFactory.CreateDbParameter("@ArticleTitle", '%' + ArticleTitle + '%'));
}
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
whereSql.Append(@" AND ArticleType=@ArticleType");
param.Add(DbFactory.CreateDbParameter("@ArticleType", ArticleType));
}
if (!StringHelper.IsNullOrEmpty(PutTimeStart))
{
whereSql.Append(@" AND PutTime>=@PutTimeStart");
param.Add(DbFactory.CreateDbParameter("@PutTimeStart", PutTimeStart));
}
if (!StringHelper.IsNullOrEmpty(PutTimeEnd))
{
whereSql.Append(@" AND PutTime<=@PutTimeEnd");
param.Add(DbFactory.CreateDbParameter("@PutTimeEnd", PutTimeEnd));
}
return Factory.FindTablePage(whereSql.ToString(), param.ToArray(), ref jgp);
} /// <summary>
/// 获取上一篇 下一篇
/// </summary>
/// <param name="ArticleType"></param>
/// <param name="CreateDate"></param>
/// <param name="IsBig"></param>
/// <returns></returns>
public List<Com_Article> GetArticleListByTime(string ArticleType, DateTime? CreateDate, int IsBig = 0)
{
StringBuilder Sql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT TOP(1)* FROM Com_Article WHERE DeleteMark<>1");
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
Sql.Append(@" AND ArticleType=@ArticleType");
param.Add(DbFactory.CreateDbParameter("@ArticleType", ArticleType));
}
if (!StringHelper.IsNullOrEmpty(CreateDate))
{
if (IsBig > 0)
{//下一篇
Sql.Append(@" AND CreateDate>@CreateDate");
param.Add(DbFactory.CreateDbParameter("@CreateDate", CreateDate));
Sql.Append(@" ORDER BY CreateDate ASC");
}
else
{
Sql.Append(@" AND CreateDate<@CreateDate");
param.Add(DbFactory.CreateDbParameter("@CreateDate", CreateDate));
Sql.Append(@" ORDER BY CreateDate DESC");
}
} return Factory.FindListBySql(Sql.ToString(), param.ToArray());
}
/// <summary>
/// 获取文章列表
/// </summary>
/// <param name="ArticleType"></param>
/// <param name="TopNum"></param>
/// <returns></returns>
public List<Com_Article> GetArticleListByType(string ArticleType, string wma, bool IsBr, int TopNum = 0, int OptionSet = 0)
{
StringBuilder Sql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>();
string strTop = "*";
if (TopNum > 0)
{
strTop = "TOP(" + TopNum + ") *";
}
Sql.Append(@"SELECT " + strTop + " FROM Com_Article WHERE DeleteMark<>1 AND State=1");
if (!StringHelper.IsNullOrEmpty(ArticleType))
{
Sql.Append(@" AND ArticleType=@ArticleType");
param.Add(DbFactory.CreateDbParameter("@ArticleType", ArticleType));
}
if (OptionSet > 0)
{
Sql.Append(@" AND OptionSet=1 AND PicUrl!='' AND PicUrl IS NOT NULL");
}
//else
//{
// Sql.Append(@" AND (OptionSet<>1 OR OptionSet IS NULL)");
//}
if (!StringHelper.IsNullOrEmpty(wma))
{
if (wma == "week")
{
Sql.Append(@" AND datediff(week,PutTime,getdate())=0");//本周
}
if (wma == "month")
{
Sql.Append(@" AND datediff(month,PutTime,getdate())=0");//本月
}
} if (IsBr)
{
Sql.Append(@" ORDER BY BrowseNumber DESC");
}
else
{
Sql.Append(@" ORDER BY PutTime DESC");
}
return Factory.FindListBySql(Sql.ToString(), param.ToArray());
} }
}
(2)OND_MessageReplyBll.cs
using Bobo.DataAccess;
using Bobo.Repository;
using Bobo.Utilities;
using IA.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace IA.Business
{
// <summary>
/// 评论信息表
/// <author>
/// <name>YHB</name>
/// <date>2018.10.18</date>
/// </author>
/// </summary>
public class OND_MessageReplyBll : RepositoryFactory<OND_MessageReply>
{ /// <summary>
/// 获取list分页数据
/// </summary>
/// <param name="DataID"></param>
/// <param name="jgp"></param>
/// <returns></returns>
public List<OND_MessageReply> GetListPage(string DataID,ref JqGridParam jgp)
{
StringBuilder Sql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>(); Sql.Append(@"SELECT * FROM(
SELECT y.[MessageReplyID]
,y.[DataID]
,y.[MessageReplyCenter]
,CASE ParentID WHEN '' THEN '' WHEN null THEN ''
ELSE (SELECT
'<p>引用'+x.CreateUserName +'发表于 '+CONVERT(nvarchar(50),x.CreateDate)+' 的回复:</p>'
+'<span>'+x.MessageReplyCenter +'</span>'
FROM OND_MessageReply x WHERE x.DeleteMark<>1 AND x.MessageReplyID=y.ParentID) END
AS ParentID
,y.[DeleteMark]
,y.[GiveNum]
,y.[CreateDate]
,y.[CreateUserId]
,y.[CreateUserName]
,y.[ModifyDate]
,y.[ModifyUserId]
,y.[ModifyUserName]
FROM [dbo].[OND_MessageReply] y WHERE y.DeleteMark<>1) T WHERE 1=1"); if (!StringHelper.IsNullOrEmpty(DataID))
{
Sql.Append(@" AND DataID=@DataID");
param.Add(DbFactory.CreateDbParameter("@DataID", DataID));
}
return Factory.FindListPageBySql(Sql.ToString(), param.ToArray(), ref jgp);
}
/// <summary>
/// 获取会员评论信息
/// </summary>
/// <param name="MemeberID"></param>
/// <param name="jgp"></param>
/// <returns></returns>
public DataTable GetOtherTablePage(string MemeberID, ref JqGridParam jgp)
{
StringBuilder Sql = new StringBuilder();
List<DbParameter> param = new List<DbParameter>();
Sql.Append(@"SELECT * FROM(
SELECT
x2.ArticleTitle,x2.ArticleType
,(SELECT COUNT(*) FROM OND_MessageReply y1 WHERE y1.DeleteMark<>1 AND y1.ParentID=x1.MessageReplyID) AS ReplyNum
,x1.* FROM dbo.OND_MessageReply x1
INNER JOIN dbo.Com_Article x2 ON x1.DataID=x2.ArticleID AND x2.DeleteMark<>1
) T WHERE DeleteMark<>1");
if (!StringHelper.IsNullOrEmpty(MemeberID))
{
Sql.Append(@" AND CreateUserId=@CreateUserId");
param.Add(DbFactory.CreateDbParameter("@CreateUserId", MemeberID));
}
return Factory.FindTablePageBySql(Sql.ToString(), param.ToArray(), ref jgp);
} }
}
接着我们创建博客的两个视图,一个列表一个详情页:
(1)列表页Index.cshtml
@using System.Data
@using Bobo.Utilities
@{
ViewBag.Title = "页落网_YEALUO_轻博客";
Layout = "~/Views/Shared/_LayoutArticle.cshtml";
}
<div class="container-wrap">
<div class="container">
<div class="contar-wrap">
<h4 class="item-title">
<p><i class="icon glyphicon-volume-up"></i>公告:<span>欢迎欢迎,热烈欢迎!</span></p>
</h4>
@foreach (var item in ViewBag.model) {
<div class="item">
<div class="item-box other-item-box layer-photos-demo1 layer-photos-demo">
<h3><a href="/WebArticle/Detail?KeyValue=@item.ArticleID&ArticleType=@ViewBag.ArticleType">@item.ArticleTitle</a></h3>
<h5>发布于:<span>@item.CreateDate</span></h5>
<p>@StringHelper.ClipString(StringHelper.ClearHtml(item.ArticleContent), 300)</p> <a href="/WebArticle/Detail?KeyValue=@item.ArticleID&ArticleType=@ViewBag.ArticleType" class="text-link">
<i class="icon glyphicon-link"></i>
</a>
</div>
<div class="comment count">
<a href="/WebArticle/Detail?KeyValue=@item.ArticleID&ArticleType=@ViewBag.ArticleType#msg-form"><i class="icon glyphicon-edit"></i> 评论</a>
<a href="javascript:;" class="like"><i class="icon glyphicon-thumbs-up"></i> 点赞</a>
</div>
</div>
}
</div>
<div class="tcdPageCode"></div>
</div>
</div> <script type="text/javascript">
$(function () {
$(".item-box").hover(function () {
$(this).siblings().removeClass("on");
$(this).addClass("on");
}, function () {
$(this).removeClass("on");
});
})
$(".tcdPageCode").createPage({
pageCount: @ViewBag.pageData.total,
current: @ViewBag.pageData.page,
backFn: function (p) {
location.href = "/WebArticle/Index?p=" + p + "@ViewBag.seachStr";
}
});
</script>
(2)详情页Detail.cshtml @using IA.Entity
@using Bobo.Utilities
@using Bobo.Utilities.Membership
@model Com_Article
@{
ViewBag.Title = "页落网_YEALUO_轻博客";
Layout = "~/Views/Shared/_LayoutArticle.cshtml";
}
<link href="~/Content/Scripts/ueditor/prettify.css" rel="stylesheet" />
<script src="~/Content/Scripts/ueditor/prettify.js"></script>
<div class="container-wrap">
<div class="container container-message container-details container-comment">
<div class="contar-wrap">
<div class="item">
<div class="item-box layer-photos-demo1 layer-photos-demo">
<h3>@Model.ArticleTitle</h3>
<h5>发布于:<span>@Model.CreateDate</span></h5>
<p>@Html.Raw(Model.ArticleContent)</p>
<div class="count layui-clear">
<span class="pull-left">阅读 <em>@Model.BrowseNumber</em></span>
<span class="pull-right like"><i class="icon glyphicon-thumbs-up" onclick="addGive()"></i><em id="Give">@Model.GiveNum</em></span>
</div>
<div class="count layui-clear">
@if (!StringHelper.IsNullOrEmpty(ViewBag.PrveArt))
{
<a href="/WebArticle/Detail?KeyValue=@ViewBag.PrveArt.ArticleID&ArticleType=@ViewBag.PrveArt.ArticleType" class="L" style="color:#174bb6;" title="@ViewBag.PrveArt.ArticleTitle"><span style="color:#999;">上一篇:</span>@StringHelper.ClipString(ViewBag.PrveArt.ArticleTitle, 30)</a>
}
@if (!StringHelper.IsNullOrEmpty(ViewBag.NextArt))
{
<a href="/WebArticle/Detail?KeyValue=@ViewBag.NextArt.ArticleID&ArticleType=@ViewBag.NextArt.ArticleType" class="R" style="color:#174bb6;" title="@ViewBag.NextArt.ArticleTitle"><span style="color:#999;">下一篇:</span>@StringHelper.ClipString(ViewBag.NextArt.ArticleTitle, 30)</a>
}
</div>
</div>
</div>
<a name="comment"> </a> <form class="layui-form" action="" id="msg-form">
<div class="layui-form-item layui-form-text">
<input type="hidden" id="DataID" name="DataID" value="@Model.ArticleID" />
<input type="hidden" id="ParentID" name="ParentID" value="" />
<textarea class="layui-textarea" id="MessageReplyCenter" name="MessageReplyCenter" style="resize:none" placeholder="写点什么啊"></textarea>
</div>
<div class="btnbox">
@if (ManageProvider.Provider.IsOverdue())
{
<div onclick="subMsgInfo()" class="subTrue" id="sure">
确定
</div>
}
else
{
<div onclick="noLoginFun()" class="subTrue" id="sure">
确定
</div>
}
</div>
</form> <div id="LAY-msg-box">
@foreach (var item in ViewBag.Msg) {
<div class="info-item">
<img class="info-img" src="/Content/Images/slice/pht.png" width="60"/>
<div class="info-text">
<div class="title count">
<div class="name">@item.CreateUserName</div>
<div class="info-img like"><i class="icon glyphicon-thumbs-up" data-messagereplyid="@item.MessageReplyID" onclick="addMsgGive($(this))"></i><em>@item.GiveNum</em></div>
</div>
<div class="info-intr">
@Html.Raw(item.ParentID)
<div class="info-intr-txt">评论:@item.MessageReplyCenter</div>
<div class="info-intr-tip text-right"><span class="L">@item.CreateDate</span>
@if (ManageProvider.Provider.IsOverdue() && ManageProvider.Provider.Current().UserId == item.CreateUserId)
{
<a href="javascript:;" data-messagereplyid="@item.MessageReplyID" onclick="SetGiveDelMsg($(this))" style="color:#0094ff">删除</a>
}
else
{
<a href="javascript:;" data-createdate="@item.CreateDate" data-username="@item.CreateUserName" data-messagereplyid="@item.MessageReplyID" onclick="Reply($(this))" style="color:#ff9d00">回复</a>
}
</div>
</div>
</div>
</div>
}
<div class="tcdPageCode"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
prettyPrint(); //代码高亮
var KeyId='@Model.ArticleID';
//登录跳转
function noLoginFun() {
layer.msg("请先进行登录喔!", { icon: 0, time: 2000 }, function () {
location.href = "/MemberCenterModule/MemberRegLogin/Login?ReturnUrl=/WebArticle/Detail?KeyValue=@Model.ArticleID#msg-form";
});
}
$(".tcdPageCode").createPage({
pageCount: @ViewBag.pageData.total,
current: @ViewBag.pageData.page,
backFn: function (p) {
location.href = "/WebArticle/Index?p=" + p + "@ViewBag.seachStr";
}
});
//提交评论信息
function subMsgInfo() {
var msg = $("#MessageReplyCenter").val();
if (!msg) {
layer.tips('请输入您想说的话喔!', '#MessageReplyCenter');
return false;
}
$.post("/WebArticle/SubMsgData", {msg: msg, DataID: $("#DataID").val(), ParentID: $("#ParentID").val() }, function (data) {
if (data.Success) {
layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () {
location.reload();
}); }
else {
layer.alert(data.Message, { icon: data.Code });
}
}, "json");
}
//回复
function Reply(elem){
location.href = "#msg-form";
$(".ReplyUser").remove();
$("#ParentID").after('<div class="ReplyUser">引用“'+elem.attr("data-username")+'”发表于'+elem.attr("data-createdate")+'的回复:</div>');
$("#ParentID").val(elem.attr("data-messagereplyid"));
}
//操作评论
function SetGiveDelMsg(elem,num){
var messagereplyid=elem.attr("data-messagereplyid");
$.post("/WebArticle/SetGiveDelMsg",{KeyValue:messagereplyid,num:num},function(data){
if (data.Success) {
if(num>0){
layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () {
location.reload();
});
}
else{
setCookie(messagereplyid + "MsgGive", messagereplyid + "MsgGive", 1);
}
}
else {
layer.alert(data.Message, { icon: data.Code });
}
},"json");
}
//评论点赞
function addMsgGive(elem) {
if (getCookie(elem.attr("data-messagereplyid") + "MsgGive")=="") {
SetGiveDelMsg(elem,0);
elem.parent().find("em").text(parseInt(elem.parent().find("em").text())+1);
layer.tips('点赞成功!', elem.parent().find("em"));
}
else {
layer.msg('你已点赞了喔!');
} return false;
}
//设置cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));//24小时
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//获取cookie
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
} //浏览量
function SetBrwGive() {
if (getCookie(KeyId + "Brw") == "") {
SubSetBrwGiveNum(0, 1, "Brw");
}
return false;
}
//点赞
function addGive(elem) {
if (getCookie(KeyId + "Give")=="") {
SubSetBrwGiveNum(1, 0, "Give");
$("#Give").text(parseInt($("#Give").text())+1);
layer.tips('点赞成功!', '#Give');
}
else {
layer.msg('你已点赞了喔!');
} return false;
} //设置文章点赞浏览
function SubSetBrwGiveNum(GiveNum, BrowseNum, type) {
$.post("/WebArticle/SubSetBrwGiveNum", { KeyValue: KeyId, GiveNum: GiveNum, BrowseNum: BrowseNum }, function (data) {
if (data.Code > 0) {
setCookie(KeyId + type, KeyId + type, 1);
} }, "json");
} $(function(){
SetBrwGive();
setTimeout("SetInicPage()","500");
}); //代码展开收缩操作
function SetInicPage(){
var str='<i class="closeAddBtn" onclick="openShk($(this))" title="展开查看代码"></i>';
$(".prettyprint .linenums").each(function(){
$(this).after(str);
$(this).parent().addClass("hid");
});
}
function openShk(elem){
if(elem.hasClass("on")){
elem.removeClass("on");
elem.parent().removeClass("on");
}
else{
elem.addClass("on");
elem.parent().addClass("on");
}
}
</script>
效果预览:
ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(16)之轻博客的更多相关文章
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(13)之会员登录注册
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 会员中心,是我们与用户交 ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(15)之前台网站页面
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 本项目主要是一个素材的分 ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(1)之数据库设计
本文主要讲解本项目网站所应用到的知识点,及数据库的相关设计: 一.知识点 (1)本项目主要采取ASP.NET MVC的编程模式,相信你已经了解到了MVC的具体含义是什么,这里不再赘述,有不了解的朋友, ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(14)之会员中心管理
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 会员中心,主要包含了会员 ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(9)之系统登录
前面我们已经做好了一个文章管理功能模块,接下来,我们回头来做登录窗口,登录不仅涉及到登录验证还涉及到登录日志还有缓存时长等. 对于缓存的相关设置,我们已经写好封装在Bobo.Utilities.dll ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(7)之扩展基类和区域创建以及文本编辑配置
一.扩展基类和区域创建 (1)在应用之前,我们先在表现层创建一个公共的系统扩展文件来(SystemExtension)存放我们需要延伸和扩展的方法类. 在常规的项目系统操作中,我们都需要用到增删查改的 ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(2)之创建项目
我们在创建项目的时候一定要遵循层次和命名的原则,同时也要有统一的规范,无论是多人项目还是单人项目,能够让人看着一目了然并赏析悦目,做一个有追求的程序员. 例如IA.WebApp是视图控制器层(表现层) ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(8)之文章管理
到这一步,我们整个项目的核心搭建已经算是完成了,接下来就是我们业务功能的实际应用,也就是表现层的设计和实现,如果你是一个项目负责人,到这一步,接下来的工作就可以交给下面的兄弟去完成了,在这里我们用文章 ...
- ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(11)之支付管理及广告管理
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c 本项目属于个人项目,不支 ...
随机推荐
- Hdu 1007 最近点对
题目链接 Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- epiinfo是美国CDC开发维护的流行病学数据录入和分析软件,在DOS时代占主流,随着Windows的普及用的人越来越少了,epiinfo重新开发Windows版本后,体积庞大且不好用。在数据录入方面已被EpiData取代,不过epiinfo的分析模块,比如地理信息系统某些情况下还是挺有用的。
Manual: https://www.cdc.gov/epiinfo/support/userguide.html https://en.wikipedia.org/wiki/Epi_Info 教程 ...
- 【JZOJ4848】【GDOI2017模拟11.3】永恒的契约
题目描述 宅邸迅速的燃烧着,必须带贝蒂走出禁书库!凭着感觉,又一次直接找到禁书库的门. "你,是那个人嘛?"400年了,当初圣域建立结界时没有进入圣域,被伤了心的人工精灵贝蒂,与强 ...
- python ASCII编码集
- 使用pstack和gdb调试死锁
1:代码 下面是一个简单的能够发生死锁的代码: #include <unistd.h> #include <pthread.h> #include <string.h&g ...
- @hdu - 6687@ Rikka with Stable Marriage
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个稳定婚姻匹配问题,其中第 i 个男生与第 j 个女生之间 ...
- ELK练习
1.ELK练习 PUT s3/_doc/ { "mappings" : { "doc" : { "properties" : { " ...
- 如何将英文PDF文献翻译成中文
方法一:利用Google的本地文档翻译功能 这种方法比较简单,打开Google翻译首页http://translate.google.cn/, 选择"上传文档" 选择文件,开始翻译 ...
- BigData NoSQL —— ApsaraDB HBase数据存储与分析平台概览
一.引言 时间到了2019年,数据库也发展到了一个新的拐点,有三个明显的趋势: 越来越多的数据库会做云原生(CloudNative),会不断利用新的硬件及云本身的优势打造CloudNative数据库, ...
- iptables 防止DoS攻击
SYN洪水是攻击者发送海量的SYN请求到目标服务器上的一种DoS攻击方法,下面的脚本用于预防轻量级的DoS攻击:ipt-tcp.sh: iptables -N syn-flood (如果您的防火墙默认 ...