From 10e66a97f919c8fdf877622070b8f877abdc9f42 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 19 Oct 2018 12:59:15 +0800 Subject: [PATCH] func(processData): finish --- src/disqus.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/src/disqus.js b/src/disqus.js index cc9c477..a1dd666 100644 --- a/src/disqus.js +++ b/src/disqus.js @@ -116,9 +116,7 @@ function DisqusJS(config) { h = h < 10 ? (`0${h}`) : h; let minute = date.getMinutes(); minute = minute < 10 ? (`0${minute}`) : minute; - let second = date.getSeconds(); - second = minute < 10 ? (`0${second}`) : second; - return `${y}-${m}-${d} ${h}:${minute}:${second}`; + return `${y}-${m}-${d} ${h}:${minute}`; } /* @@ -231,6 +229,11 @@ function DisqusJS(config) { if (res.code === 0 && res.response.length > 0) { // 已获得评论列表 renderComment(res.response) + if (res.cursor.hasNext) { + // 显示 加载更多评论 按钮 + } else { + // 没有更多评论了,注意确保按钮隐藏 + } } else if (res.code === 0 && res.response.length === 0) { // 当前没有评论 } else { @@ -280,7 +283,7 @@ function DisqusJS(config) { (comment.parent ? childComments : topLevelComments)['push'](comment); }); - var commentLists = topLevelComments.map((comment) => { + let commentLists = topLevelComments.map((comment) => { return { comment, author: comment.author.name, @@ -293,15 +296,88 @@ function DisqusJS(config) { } /* - * parseCommentData(data) - 渲染评论列表 + * processData(data) - 处理评论列表 + * + * @param {Object} data - 解析后的评论列表 JSON + */ + let processData = (data) => { + // 处理 Disqus Profile + if (data.comment.author.profileUrl) { + /* + Avatar Element + + + + + Author Element + + ${data.comment.author.name} + + */ + data.comment.avatarEl = `` + data.comment.authorEl = `${data.comment.author.name}` + } else { + data.comment.avatarEl = `` + data.comment.authorEl = `${data.comment.author.name}` + } + + // 处理 Admin Label + if (data.isPrimary) { + data.comment.authorEl += `${disqusjs.config.adminLabel}`; + } + + // 处理评论嵌套级数 + if (data.children) { + // 如果有子评论,设置当前评论前套数为 1 + data.nesting = 1; + } + + return data; + } + + let renderPostItem = (s) => { + /* +
+
+ ${s.avatarEl} +
+
+
+ ${s.authorEl} + + +
+
+ ${s.message} +
+
+
+ */ + let html = `
${s.avatarEl}
${s.authorEl}
${s.message}
` + + return html; + } + + + + /* + * renderCommentData(data) - 渲染评论列表 * * @param {Object} data - 从 getComment() 获取到的 JSON */ let renderComment = (data) => { + var html = ''; + data = parseCommentData(data); - console.log(data) + data.map((comment) => { + comment = processData(comment); + console.log(comment) + html += `
  • ${renderPostItem(comment.comment)}${childrenComments(s)}
  • `; + }) + + console.log(html) } } - + loadDsqjs() }