懒得勤快 il y a 5 ans
Parent
commit
ecb9061378

+ 2 - 3
src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml

@@ -362,7 +362,6 @@
 <script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/shCore.min.js"></script>
 <script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/bundle.min.js"></script>
 <script src="~/Assets/jquery.tocify/jquery.tocify.js"></script>
-@*<script src="~/Assets/directory/script.min.js"></script>*@
 <script src="~/Scripts/global/article.min.js"></script>
 <script>
 	window.onload = function() {
@@ -376,7 +375,7 @@
 			count: @Model.Comment.Count(c =>c.ParentId==0&& c.Status==Status.Pended),
 			toolbar: true,
 			callback: function(page, size, count) {
-				$.post("/comment/getcomments", {
+				window.post("/comment/getcomments", {
 					id: @Model.Id,
 					page: page,
 					size: size
@@ -397,7 +396,7 @@
    * 获取评论
    */
 	function getcomments() {
-		$.post("/comment/getcomments", {
+		window.post("/comment/getcomments", {
 			id: $("#postId").val(),
 			page: 1,
             size: 10,

+ 59 - 34
src/Masuit.MyBlogs.Core/Views/Post/Details_Admin.cshtml

@@ -56,19 +56,19 @@
                                 @{
                                     if (!string.IsNullOrEmpty(Model.Label))
                                     {
-                                    <div class="pull-right margin-right20">
-                                        <div>
-                                            @foreach (string s in Model.Label.Split(',', ',', ' '))
+                                        <div class="pull-right margin-right20">
+                                            <div>
+                                                @foreach (string s in Model.Label.Split(',', ',', ' '))
                                                 {
                                                     if (!string.IsNullOrEmpty(s))
                                                     {
-                                            <a asp-controller="Home" asp-action="Tag" asp-route-id="@s">
-                                                <span class="label label-@colors[new Random().Next() % colors.Length]">@s</span>
-                                            </a>
+                                                        <a asp-controller="Home" asp-action="Tag" asp-route-id="@s">
+                                                            <span class="label label-@colors[new Random().Next() % colors.Length]">@s</span>
+                                                        </a>
                                                     }
                                                 }
+                                            </div>
                                         </div>
-                                    </div>
                                     }
                                 }
                             </div>
@@ -77,24 +77,27 @@
                                     分类:<i class="icon-map-pin"></i>@Html.ActionLink(Model.Category.Name, "Category", "Home", new { id = Model.CategoryId }, new { @class = "label label-" + colors[new Random().Next() % colors.Length] }) | 评论总数:<span class="text-danger">@Model.Comment.Count</span>条 | 热度:<span class="text-danger">@Model.TotalViewCount</span>℃ | 状态:@Model.Status.GetDisplay()
                                     @if (Model.Seminar.Any())
                                     {
-                                    <span> | 所属专题:</span>
+                                        <span> | 所属专题:</span>
                                         var seminars = Model.Seminar;
                                         foreach (var s in seminars)
                                         {
-                                    @Html.ActionLink(s.Seminar.Title, "Index", "Seminar", new { id = s.SeminarId }, new { @class = "label label-" + colors[new Random().Next() % colors.Length] })<text> </text>
+                                            @Html.ActionLink(s.Seminar.Title, "Index", "Seminar", new { id = s.SeminarId }, new { @class = "label label-" + colors[new Random().Next() % colors.Length] })<text> </text>
                                         }
                                     }
                                     <div class="pull-right margin-right20">
                                         <div class="btn-group">
                                             @Html.ActionLink("刷新", "Refresh", "Post", new { id = Model.Id }, new { @class = "btn btn-info" })
-                                            @if(Model.IsFixedTop) {
-                                            <button class="btn btn-success" id="pin">取消置顶</button>
-                                            }else {
-                                            <button class="btn btn-success" id="pin">置顶</button>
+                                            @if (Model.IsFixedTop)
+                                            {
+                                                <button class="btn btn-success" id="pin">取消置顶</button>
+                                            }
+                                            else
+                                            {
+                                                <button class="btn btn-success" id="pin">置顶</button>
                                             }
                                             @if (Model.Status == Status.Pending)
                                             {
-                                            <button class="btn btn-primary" id="pass">通过</button>
+                                                <button class="btn btn-primary" id="pass">通过</button>
                                             }
                                             <a asp-controller="Dashboard" asp-action="Index" asp-fragment="/post/[email protected]" class="btn btn-primary" target="_blank">修改</a>
                                             <button class="btn btn-danger" id="del">删除</button>
@@ -107,9 +110,9 @@
                             @Html.Raw(Model.Content)
                             @if (!string.IsNullOrEmpty(Model.ProtectContent))
                             {
-                            <div class="row protected">
-                                @Html.Raw(Model.ProtectContent)
-                            </div>
+                                <div class="row protected">
+                                    @Html.Raw(Model.ProtectContent)
+                                </div>
                             }
                         </article>
                         <h3>分享到:</h3>
@@ -308,17 +311,17 @@
 <script src="~/Assets/highlight/js/highlight.js"></script>
 <script>
     function getcomments() {
-		$.post("/comment/getcomments", {
+        window.post("/comment/getcomments",{
 			id: $("#postId").val(),
 			page: 1,
 			size: 10,
 			cid: @cid
-		}, (data) => {
-			data = data.Data;
+		},function(data) {
+            data = data.Data;
 			document.querySelector(".media-list").innerHTML = loadParentComments(data);
 			bindReplyBtn();
 			commentVoteBind(); //评论投票
-		});
+        });
     }
 	window.onload = function() {
         var keywords = @Html.Raw(ViewData["keywords"] ?? "[]");
@@ -331,7 +334,7 @@
 			count: @Model.Comment.Count(c =>c.ParentId==0&& c.Status==Status.Pended),
 			toolbar: true,
 			callback: function(page, size, count) {
-				$.post("/comment/getcomments", {
+				window.post("/comment/getcomments", {
 					id: @Model.Id,
 					page: page,
 					size: size
@@ -357,35 +360,51 @@
 				animation: true,
 				allowOutsideClick: false
 			}).then(function () {
-				$.post("/post/delete", {
-					id: @Model.Id
-				}, function (data) {
+				window.post("/post/delete", { id: @Model.Id}, function (data) {
 					window.notie.alert({
 						type: 1,
 						text: data.Message,
 						time: 4
 					});
-				});
+                }, () => {
+                    window.notie.alert({
+						type: 3,
+						text: "请求失败,请稍候再试!",
+						time: 4
+					});
+                });
 			}, function () {
 			});
 		});
 		$("#pass").on("click", function (e) {
-			$.post("/post/pass", { id:@Model.Id}, function (data) {
+			window.post("/post/pass", { id:@Model.Id}, function (data) {
 				window.notie.alert({
 					type: 1,
 					text: data.Message,
 					time: 4
-				});
+				}, () => {
+                    window.notie.alert({
+						type: 3,
+						text: "请求失败,请稍候再试!",
+						time: 4
+					});
+                });
                 location.reload();
 			});
 		});
 		$("#pin").on("click", function (e) {
-			$.post("/post/Fixtop", { id: @Model.Id }, function (data) {
+			window.post("/post/Fixtop", { id: @Model.Id }, function (data) {
 				window.notie.alert({
 					type: 1,
 					text: data.Message,
 					time: 4
-				});
+				}, () => {
+                    window.notie.alert({
+						type: 3,
+						text: "请求失败,请稍候再试!",
+						time: 4
+					});
+                });
                 location.reload();
 			});
 		});
@@ -468,10 +487,16 @@
 	}
 
 	function pass(id) {
-		$.post("/comment/pass", { id: id }, function (res) {
+		window.post("/comment/pass", { id: id }, function (res) {
 			swal(res.Message, "", res.Success ? "success" : "error");
 			getcomments();
-		});
+		}, () => {
+                    window.notie.alert({
+						type: 3,
+						text: "请求失败,请稍候再试!",
+						time: 4
+					});
+                });
 	}
 	function del(id) {
 		swal({
@@ -484,11 +509,11 @@
 			cancelButtonText: '取消',
 			preConfirm: function() {
 				return new Promise(function (resolve) {
-					$.post("/comment/delete", {
+					window.post("/comment/delete", {
 						id: id
 					}, function (res) {
 						resolve(res);
-					});
+					}, (e) => reject(e));
 				});
 			},
 			allowOutsideClick: false

+ 67 - 26
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/article.js

@@ -16,7 +16,7 @@
 	});
 	$("#code-token").on("submit", function(e) {
 		e.preventDefault();
-		$.post("/post/CheckViewToken", $(this).serialize(), function(data) {
+		window.post("/post/CheckViewToken", $(this).serializeObject(), function(data) {
 			if (data.Success) {
 				window.location.reload();
 			} else {
@@ -26,15 +26,20 @@
 					time: 4
 				});
 			}
-		});
+		}, () => {
+            window.notie.alert({
+				type: 3,
+				text: "请求失败,请稍候再试!",
+				time: 4
+			});
+        });
 	});
 	$(".getcode").on("click", function(e) {
 		e.preventDefault();
-		$.post("/post/getviewtoken",
-			{
-				__RequestVerificationToken:$("[name=__RequestVerificationToken]").val(),
-				email:$("#email3").val()
-			}, function(data) {
+		window.post("/post/getviewtoken", {
+			__RequestVerificationToken:$("[name=__RequestVerificationToken]").val(),
+			email:$("#email3").val()
+		}, function(data) {
 			if (data.Success) {
 				window.notie.alert({
 					type: 1,
@@ -60,7 +65,13 @@
 					time: 4
 				});
 			}
-		});
+		}, () => {
+            window.notie.alert({
+				type: 3,
+				text: "请求失败,请稍候再试!",
+				time: 4
+			});
+        });
 	});
 	var user = JSON.parse(localStorage.getItem("user"));
 	if (user) {
@@ -158,7 +169,7 @@
 		}
 
 		localStorage.setItem("user",  JSON.stringify(formData));
-		$.post("/comment/put", $(this).serialize(), (data) => {
+		window.post("/comment/put", formData, (data) => {
 			loadingDone();
 			if (data.Success) {
 				window.notie.alert({
@@ -179,11 +190,17 @@
 					time: 4
 				});
 			}
-		});
+		}, () => {
+            window.notie.alert({
+				type: 3,
+				text: "请求失败,请稍候再试!",
+				time: 4
+			});
+        });
 	});
 
 	$("#donate").on("click", function (e) {
-		$.post("/system/getsetting", { name: "Donate" }, function (data) {
+		window.post("/system/getsetting", { name: "Donate" }, function (data) {
 			swal({
 				title: "支付宝扫一扫付款打赏!",
 				html:"<a href='/donate'>更多方式</a>",
@@ -201,7 +218,13 @@
 			}, function() {
 				swal("您的打赏将会支持本站做的更好!", null, "error");
 			});
-		});
+		}, () => {
+            window.notie.alert({
+				type: 3,
+				text: "请求失败,请稍候再试!",
+				time: 4
+			});
+        });
 	});
 });
 
@@ -212,7 +235,7 @@
 function submitComment(_this) {
 	loading();
 	localStorage.setItem("user", JSON.stringify($(_this).serializeObject()));
-	$.post("/comment/put", $(_this).serialize(), (data) => {
+	window.post("/comment/put", $(_this).serializeObject(), (data) => {
 		loadingDone();
 		if (data.Success) {
 			window.notie.alert({
@@ -231,7 +254,13 @@ function submitComment(_this) {
 				time: 4
 			});
 		}
-	});
+	}, () => {
+        window.notie.alert({
+			type: 3,
+			text: "请求失败,请稍候再试!",
+			time: 4
+		});
+    });
 }
 
 //评论回复按钮事件
@@ -274,9 +303,7 @@ function bindReplyBtn() {
 //绑定评论投票
 function commentVoteBind() {
 	$(".cmvote").on("click", function(e) {
-		$.post("/comment/CommentVote", {
-			id: $(this).data("id")
-		}, (data) => {
+		window.post("/comment/CommentVote", { id: $(this).data("id") }, (data) => {
 			if (data) {
 				if (data.Success) {
 					console.log($(this).children("span.count"));
@@ -297,14 +324,18 @@ function commentVoteBind() {
 				}
 			}
 		});
-	});
+	}, () => {
+        window.notie.alert({
+			type: 3,
+			text: "请求失败,请稍候再试!",
+			time: 4
+		});
+    });
 }
 
 function bindVote() {
     $("#voteup").on("click", function(e) {
-        $.post("/post/voteup", {
-			id: $("#postId").val()
-		}, (data) => {
+        window.post("/post/voteup", { id: $("#postId").val() }, (data) => {
 			if (data) {
 				if (data.Success) {
 					$(this).children()[1].innerText = parseInt($(this).children()[1].innerText) + 1;
@@ -323,12 +354,16 @@ function bindVote() {
 					});
 				}
 			}
-		});
+		}, () => {
+            window.notie.alert({
+				type: 3,
+				text: "请求失败,请稍候再试!",
+				time: 4
+			});
+        });
 	});
     $("#votedown").on("click", function(e) {
-        $.post("/post/votedown", {
-			id: $("#postId").val()
-		}, (data) => {
+        window.post("/post/votedown", { id: $("#postId").val() }, (data) => {
 			if (data) {
 				if (data.Success) {
 					$(this).children()[1].innerText = parseInt($(this).children()[1].innerText) + 1;
@@ -348,7 +383,13 @@ function bindVote() {
 				}
 			}
 		});
-	});
+	}, () => {
+        window.notie.alert({
+		    type: 3,
+		    text: "请求失败,请稍候再试!",
+		    time: 4
+	    });
+    });
 }
 
 //递归加载评论

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/article.min.js


+ 2 - 2
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/leavemsg.js

@@ -103,7 +103,7 @@
             return;
         }
 		localStorage.setItem("user", JSON.stringify($(this).serializeObject()));
-		$.post("/Msg/Put", $(this).serialize(), (data) => {
+		window.post("/Msg/Put", $(this).serializeObject(), (data) => {
             loadingDone();
             if (data && data.Success) {
 		        window.notie.alert({
@@ -134,7 +134,7 @@
 function submitComment(_this) {
     loading();
 	localStorage.setItem("user", JSON.stringify($(_this).serializeObject()));
-    $.post("/Msg/Put", $(_this).serialize(), (data) => {
+    window.post("/Msg/Put", $(_this).serializeObject(), (data) => {
         loadingDone();
         if (data && data.Success) {
 			window.notie.alert({

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/leavemsg.min.js


+ 36 - 10
src/Masuit.MyBlogs.Core/wwwroot/Scripts/global/scripts.js

@@ -77,7 +77,7 @@ $(function() {
 
     function subscribe() {
         loading();
-        $.post("/subscribe/subscribe", $("#subscribe").serialize(), function(data) {
+        window.post("/subscribe/subscribe", $("#subscribe").serializeObject(), function(data) {
                 loadingDone();
                 if (data && data.Success) {
                     window.notie.alert({
@@ -93,6 +93,12 @@ $(function() {
                         time: 4
                     });
                 }
+            }, () => {
+                window.notie.alert({
+					type: 3,
+					text: "请求失败,请稍候再试!",
+					time: 4
+				});
             });
     }
 
@@ -198,10 +204,10 @@ $(function() {
 
     var nid = window.localStorage.getItem("notice") || '0';
     window.fetch("/notice/last", {
-            credentials: 'include',
-            method: 'POST',
-            mode: 'cors'
-        }).then(function(response) {
+        credentials: 'include',
+        method: 'POST',
+        mode: 'cors'
+    }).then(function(response) {
         return response.json();
     }).then(function(data) {
         data = data.Data;
@@ -234,7 +240,7 @@ $(function() {
     });
 });
 
-//两个全局加载动画
+//全局加载动画
 function loading() {
     $(".loading1").show();
 }
@@ -284,9 +290,7 @@ function GetBrowser(browser) {
 }
 
 function getFile(obj, inputName) {
-    var file_name = $(obj).val();
-    console.log(file_name);
-    $("input[name='" + inputName + "']").val(file_name);
+    $("input[name='" + inputName + "']").val($(obj).val());
 }
 
 function popBrowserTips() {
@@ -295,7 +299,7 @@ function popBrowserTips() {
         if (window.screen.width <= 320 && !deny) {
             swal({
                 title: '访问受限制?',
-                html: "首先欢迎您的访问,由于检测到您的设备<span style='color:red'>屏幕宽度过小</span>,网站的部分功能可能不会兼容你的设备,但是您<span style='color:red'>可以继续浏览</span>,为确保最佳用户体验,建议使用<span style='color:red'>5寸以上移动设备</span>,或分辨率大于<span style='color:red'>1360 x 768</span>的<span style='color:red'>电脑浏览器</span>访问本站,感谢您的来访和支持!",
+                html: "由于检测到您的设备<span style='color:red'>屏幕宽度过小</span>,网站的部分功能可能不会兼容你的设备,但是您<span style='color:red'>可以继续浏览</span>,为确保最佳用户体验,建议使用<span style='color:red'>5寸以上移动设备</span>,或分辨率大于<span style='color:red'>1360 x 768</span>的<span style='color:red'>电脑浏览器</span>访问本站,感谢您的来访和支持!",
                 type: 'error',
                 showCloseButton: true,
                 showCancelButton: true,
@@ -312,6 +316,28 @@ function popBrowserTips() {
     }
 }
 
+function post(url, params, callback, error) {
+    var formData = new FormData();
+    Object.keys(params).forEach((key) => {
+        formData.append(key, params[key]);
+    });
+    window.fetch(url, {
+        credentials: 'include',
+        method: 'POST',
+        mode: 'cors',
+        body: formData
+    }).then(function(response) {
+        return response.json();
+    }).then(function(data) {
+        callback(data);
+    }).catch(function(e) {
+        loadingDone();
+        if (error) {
+            error(e);
+        }
+    });
+}
+
 /**
  * 鼠标桃心
  */

+ 154 - 0
src/Masuit.MyBlogs.Core/wwwroot/Scripts/publish/publish.js

@@ -0,0 +1,154 @@
+window.onload = function () {
+    if (window.UE) {
+		window.ue = UE.getEditor('editor', {
+			initialFrameWidth: null
+		});
+	}
+    
+    var user = JSON.parse(localStorage.getItem("user"));
+    if (user) {
+        $("[name='Author']").val(user.NickName);
+        $("[name='Email']").val(user.Email);
+    }
+
+	$('.ui.dropdown.tags').dropdown({
+		allowAdditions: true,
+		maxSelections: 5,
+		message: {
+			maxSelections: '最多选择 {maxCount} 项',
+			noResults: '无搜索结果!'
+		}
+	});
+	$('.ui.dropdown.category').dropdown({
+		message: {
+			maxSelections: '最多选择 {maxCount} 项',
+			noResults: '无搜索结果!'
+		}
+	});
+	$('.ui.dropdown.category').dropdown("set selected" , 1);
+
+    //异步提交表单开始
+    $("#submit").on("click", function (e) {
+        e.preventDefault();
+        loading();
+        if ($("#article").val().trim().length <= 2 || $("#article").val().trim().length > 128) {
+	        window.notie.alert({
+		        type: 3,
+                text: '文章标题必须在2到128个字符以内!',
+		        time: 4
+	        });
+            loadingDone();
+            return;
+        }
+        if ($("#Author").val().trim().length <= 0 || $("#Author").val().trim().length > 36) {
+	        window.notie.alert({
+		        type: 3,
+                text: '再怎么你也应该留个合理的名字吧,非主流的我可不喜欢!',
+		        time: 4
+	        });
+            loadingDone();
+            return;
+        }
+        if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($("#Email").val().trim())) {
+	        window.notie.alert({
+		        type: 3,
+                text: '请输入正确的邮箱格式!',
+		        time: 4
+	        });
+            loadingDone();
+            return;
+        }
+        if (ue.getContent().length < 200 || ue.getContent().length > 1000000) {
+	        window.notie.alert({
+		        type: 3,
+                text: '文章内容过短或者超长的,我都认为你是在制造垃圾!',
+		        time: 4
+	        });
+            loadingDone();
+            return;
+        }
+		window.post("/Post/Publish", $("#article-form").serializeObject(), (data) => {
+	        loadingDone();
+            if (data.Success) {
+	            window.notie.alert({
+		            type: 1,
+		            text: data.Message,
+		            time: 4
+	            });
+	            $(':input', '#article-form').not(':button,:submit,:reset,:hidden').val('').removeAttr('checked').removeAttr('checked'); //评论成功清空表单
+	            ue.setContent("");
+				clearInterval(window.interval);
+            } else {
+				window.notie.alert({
+		            type: 3,
+		            text: data.Message,
+		            time: 4
+	            });
+            }
+        });
+    });
+    //异步提交表单结束
+    
+    $("#getcode").on("click", function (e) {
+        e.preventDefault();
+        window.post("/validate/sendcode", {
+            __RequestVerificationToken: $("[name=__RequestVerificationToken]").val(),
+            email: $("#Email").val()
+        }, function (data) {
+            if (data.Success) {
+                layer.tips('验证码发送成功,请注意查收邮件,若未收到,请检查你的邮箱地址或邮件垃圾箱!', '#getcode', {
+                  tips: [1, '#3595CC'],
+                  time: 4000
+                });
+                user.NickName = $("[name='NickName']").val();
+                user.Email = $("[name='Email']").val();
+                localStorage.setItem("user", JSON.stringify(user));
+                $("#getcode").attr('disabled', true);
+                var count = 0;
+                var timer = setInterval(function () {
+                    count++;
+                    $("#getcode").text('重新发送(' + (120 - count) + ')');
+                    if (count > 120) {
+                        clearInterval(timer);
+                        $("#getcode").attr('disabled', false);
+                        $("#getcode").text('重新发送');
+                    }
+                }, 1000);
+            } else {
+                layer.tips(data.Message, '#getcode', {
+                  tips: [1, '#3595CC'],
+                  time: 4000
+                });
+            }
+        });
+    });
+	
+	//检查草稿
+	if (localStorage.getItem("write-post-draft")) {
+		notie.confirm({
+			text: "检查到上次有未提交的草稿,是否加载?",
+			submitText: "确定", 
+			cancelText: "取消",
+			position: "bottom", 
+			submitCallback: function () {
+				var post=JSON.parse(localStorage.getItem("write-post-draft"));
+				$("#article").val(post.Title);
+				ue.setContent(post.Content);
+				$('.ui.dropdown.category').dropdown('set selected', [post.CategoryId]);
+				$('.ui.dropdown.tags').dropdown('set selected', post.Label.split(","));
+                window.interval = setInterval(function () {
+		            localStorage.setItem("write-post-draft",JSON.stringify($("#article-form").serializeObject()));
+	            },5000);
+			},
+            cancelCallback: function() {
+                window.interval = setInterval(function () {
+		            localStorage.setItem("write-post-draft",JSON.stringify($("#article-form").serializeObject()));
+	            },5000);
+            }
+		});	
+	} else {
+        window.interval = setInterval(function () {
+		    localStorage.setItem("write-post-draft",JSON.stringify($("#article-form").serializeObject()));
+	    },5000);
+    }
+};

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/Scripts/publish/publish.min.js


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff