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>

  

效果预览:

页落网_YEALUO_轻博客.png页落网_YEALUO_轻博客2.png

posted @ 2018-11-15 15:34  落日知暮  阅读(781)  评论(0编辑  收藏  举报
作者:boyzi007 出处:http://www.cnblogs.com/boyzi/ QQ:470797533 QQ交流群:364307742 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。