diff --git a/src/Discussion.Web/Views/Topic/Index.cshtml b/src/Discussion.Web/Views/Topic/Index.cshtml index f444981b..62ccb13b 100644 --- a/src/Discussion.Web/Views/Topic/Index.cshtml +++ b/src/Discussion.Web/Views/Topic/Index.cshtml @@ -6,13 +6,6 @@ @{ ViewData["Title"] = Model.Topic.Title; - - var user = Context.DiscussionUser(); - var canCreateReply = user != null; - if (canCreateReply && SiteSettings.RequireUserPhoneNumberVerified && !user.PhoneNumberId.HasValue) - { - canCreateReply = false; - } }
@@ -43,133 +36,32 @@ @if (Model.Topic.ReplyCount > 0) { -
-
-
- 共有 @Model.Topic.ReplyCount 条回复 -
- -
- @foreach (var reply in Model.Replies) - { -
-
-
-
@reply.Author.DisplayName
-
-
-
@Html.RenderMarkdown(reply.Content, maxHeadingLevel: 3)
- -
-
- } -
-
-
+ } @if (Context.IsAuthenticated()) { -
-
-
- 添加回复 -
- -
- @if (canCreateReply) - { - -
-
- -
-
-
- - } - else - { -

多谢登录。

-

为账号验证了实名手机号之后,才可以添加回复。@Html.ActionLink("现在验证", "VerifyPhoneNumber", "User")

- } -
-
-
+ } @section Tail{ } \ No newline at end of file diff --git a/src/Discussion.Web/Views/Topic/Partial/_NewReply.cshtml b/src/Discussion.Web/Views/Topic/Partial/_NewReply.cshtml new file mode 100644 index 00000000..60ed8a11 --- /dev/null +++ b/src/Discussion.Web/Views/Topic/Partial/_NewReply.cshtml @@ -0,0 +1,46 @@ +@using Discussion.Core.Mvc +@using Discussion.Web.Services.UserManagement.Avatar +@inject Discussion.Web.Models.SiteSettings SiteSettings +@inject IUserAvatarService AvatarService +@model TopicViewModel + +@{ + var user = Context.DiscussionUser(); + var canCreateReply = user != null; + if (canCreateReply && SiteSettings.RequireUserPhoneNumberVerified && !user.PhoneNumberId.HasValue) + { + canCreateReply = false; + } +} + + + +
+
+
+ 添加回复 +
+ +
+ @if (canCreateReply) + { + +
+
+ +
+
+
+ + } + else + { +

多谢登录。

+

为账号验证了实名手机号之后,才可以添加回复。@Html.ActionLink("现在验证", "VerifyPhoneNumber", "User")

+ } +
+
+
\ No newline at end of file diff --git a/src/Discussion.Web/Views/Topic/Partial/_ReplyList.cshtml b/src/Discussion.Web/Views/Topic/Partial/_ReplyList.cshtml new file mode 100644 index 00000000..e5ef624e --- /dev/null +++ b/src/Discussion.Web/Views/Topic/Partial/_ReplyList.cshtml @@ -0,0 +1,29 @@ +@using Discussion.Web.Services.UserManagement.Avatar +@inject IUserAvatarService AvatarService +@model TopicViewModel + +
+
+
+ 共有 @Model.Topic.ReplyCount 条回复 +
+ +
+ @foreach (var reply in Model.Replies) + { +
+
+
+
@reply.Author.DisplayName
+
+
+
@Html.RenderMarkdown(reply.Content, maxHeadingLevel: 3)
+ +
+
+ } +
+
+
diff --git a/src/Discussion.Web/wwwroot/scripts/_entry-js.js b/src/Discussion.Web/wwwroot/scripts/_entry-js.js index 6a62349b..d99876a1 100644 --- a/src/Discussion.Web/wwwroot/scripts/_entry-js.js +++ b/src/Discussion.Web/wwwroot/scripts/_entry-js.js @@ -11,7 +11,8 @@ import '../lib/node_modules/prismjs'; import * as utils from './functions' import * as mdeditor from './markdown-editor' +import * as topic from './topic' window.jQuery = window.$ = jQuery; -window.DiscussionApp = { utils, mdeditor }; +window.DiscussionApp = { utils, mdeditor, topic }; diff --git a/src/Discussion.Web/wwwroot/scripts/topic.js b/src/Discussion.Web/wwwroot/scripts/topic.js new file mode 100644 index 00000000..874c1656 --- /dev/null +++ b/src/Discussion.Web/wwwroot/scripts/topic.js @@ -0,0 +1,69 @@ + + +export function submitNewReply(editorSelector, postUrl) { + return function() { + var editor = $(editorSelector); + var replyContent = editor.val(); + if (!$.trim(replyContent)) { + editor.focus(); + return false; + } + + $.ajax({ + url: postUrl, + method: 'POST', + data: { + content: replyContent, + __RequestVerificationToken: window.__RequestVerificationToken + }, + dataType: 'json', + success: function() { + location.reload(); + }, + error: function(xhr) { + var errors = JSON.parse(xhr.responseText); + console.log(errors); + } + }); + }; +} + + +export function setupReplyPreview(selectors, previewApiUrl){ + + $(selectors.tabPreview).on('shown.bs.tab', + function(e) { + var editor = $(selectors.contentEditor); + var replyContent = editor.val(); + if (!$.trim(replyContent)) { + editor.focus(); + e.preventDefault(); + return false; + } + + $(selectors.contentPreview).html('正在加载预览...'); + $.ajax({ + url: previewApiUrl, + method: 'POST', + data: { + markdown: replyContent, + __RequestVerificationToken: window.__RequestVerificationToken }, + success: function(res) { + if (res.hasSucceeded) { + $(selectors.contentPreview).html(res.result.html); + } else { + $(selectors.contentPreview).html('' + res.errorMessage + ''); + } + }, + error: function() { + $(selectors.contentPreview).html('暂时无法预览'); + } + }); + }); + + $(selectors.tabEditor).on('shown.bs.tab', + function() { + $(selectors.contentEditor).focus(); + $(selectors.contentPreview).empty(); + }); +} \ No newline at end of file