This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 更改评论组件文本样式 2. 解决mac本 点击跳转的问题(大概) 3. 将所有的评论内容归类到P标签内部 4. marked渲染图片和链接时增加新的处理方式(图片增加一个class,方便后续操作,链接现在是在新窗口打开,而不是当前窗口) fix #12
- Loading branch information
Showing
10 changed files
with
242 additions
and
114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,94 @@ | ||
<template> | ||
<div> | ||
<li | ||
:id="'comment-'+comment.id" | ||
class="comment" | ||
:class="commentClass" | ||
itemtype="http://schema.org/Comment" | ||
itemprop="comment"> | ||
<div class="contents"> | ||
<div class="main shadow"> | ||
<div class="profile"> | ||
<a :href="comment.authorUrl" rel="nofollow" target="_blank"> | ||
<img :alt="comment.author" v-lazy="avatar" class="avatar" height="80" width="80"> | ||
</a> | ||
</div> | ||
<div class="commentinfo"> | ||
<section class="commeta"> | ||
<div class="left"> | ||
<h4 class="author"> | ||
<a :href="comment.authorUrl" rel="nofollow" target="_blank"> | ||
<img :alt="comment.author" :src="avatar" class="avatar" height="24" width="24"> | ||
<span v-if="comment.isAdmin" class="bb-comment isauthor" title="博主">博主</span> | ||
{{ comment.author }} | ||
</a> | ||
</h4> | ||
</div> | ||
<a rel="nofollow" class="comment-reply-link" :style="editing?'display:block;':''" href="javacript:void(0);" @click="handleReplyClick">Reply</a> | ||
<div class="right"> | ||
<div class="info"> | ||
<time | ||
class="comment-time" | ||
itemprop="datePublished" | ||
:datetime="comment.createTime" | ||
<li | ||
:id="'comment-'+comment.id" | ||
class="comment" | ||
:class="commentClass" | ||
itemtype="http://schema.org/Comment" | ||
itemprop="comment" | ||
> | ||
<div class="contents"> | ||
<div class="main shadow"> | ||
<div class="profile"> | ||
<a :href="comment.authorUrl" rel="nofollow" target="_blank"> | ||
<img :alt="comment.author" v-lazy="avatar" class="avatar" height="80" width="80"> | ||
</a> | ||
</div> | ||
<div class="commentinfo"> | ||
<section class="commeta"> | ||
<div class="left"> | ||
<h4 class="author"> | ||
<a :href="comment.authorUrl" rel="nofollow" target="_blank"> | ||
<img :alt="comment.author" :src="avatar" class="avatar" height="24" width="24"> | ||
<span v-if="comment.isAdmin" class="bb-comment isauthor" title="博主">博主</span> | ||
{{ comment.author }} | ||
</a> | ||
</h4> | ||
</div> | ||
<a | ||
rel="nofollow" | ||
class="comment-reply-link" | ||
onclick="return false;" | ||
:style="editing?'display:block;':''" | ||
href="javascript:void(0);" | ||
@click="handleReplyClick" | ||
>Reply</a> | ||
<div class="right"> | ||
<div class="info"> | ||
<time | ||
class="comment-time" | ||
itemprop="datePublished" | ||
:datetime="comment.createTime" | ||
>发布于 {{ createTimeAgo }}</time> | ||
<span v-if="configs.showUserAgent" class="useragent-info" v-html="compileUserAgent"></span> | ||
<span | ||
v-if="configs.showUserAgent" | ||
class="useragent-info" | ||
v-html="compileUserAgent" | ||
></span> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
<div class="body markdown-body" v-html="compileContent"> | ||
</section> | ||
</div> | ||
<div class="body markdown-body"> | ||
<!-- 将所有的评论内容约束为一段 --> | ||
<p v-html="compileContent"></p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<hr> | ||
<ul v-if="comment.children" class="children"> | ||
<template v-for="(children, index) in comment.children"> | ||
<CommentNode | ||
:isChild="true" | ||
:targetId="targetId" | ||
:target="target" | ||
:comment="children" | ||
:options="options" | ||
:configs="configs" | ||
:key="index" | ||
:depth="selfAddDepth" | ||
:parent="comment" | ||
/> | ||
|
||
</template> | ||
</ul> | ||
</li> | ||
<CommentEditor | ||
:targetId="targetId" | ||
:target="target" | ||
:replyComment="comment" | ||
:options="options" | ||
:configs="configs" | ||
/> | ||
<hr> | ||
<ul v-if="comment.children" class="children"> | ||
<template v-for="(children, index) in comment.children"> | ||
<CommentNode | ||
:isChild="true" | ||
:targetId="targetId" | ||
:target="target" | ||
:comment="children" | ||
:options="options" | ||
:configs="configs" | ||
:key="index" | ||
:depth="selfAddDepth" | ||
:parent="comment" | ||
/> | ||
</template> | ||
</ul> | ||
</li> | ||
<CommentEditor | ||
:targetId="targetId" | ||
:target="target" | ||
:replyComment="comment" | ||
:options="options" | ||
:configs="configs" | ||
/> | ||
</div> | ||
</template> | ||
<script> | ||
import "./index"; | ||
import { timeAgo, return2Br } from "@/utils/util"; | ||
import ua from "ua-parser-js"; | ||
import marked from "l-marked"; | ||
import { renderedEmojiHtml } from "@/utils/emojiutil" | ||
import CommentEditor from './CommentEditor.vue' | ||
import globals from '@/utils/globals.js' | ||
import { renderedEmojiHtml } from "@/utils/emojiutil"; | ||
import CommentEditor from "./CommentEditor.vue"; | ||
import globals from "@/utils/globals.js"; | ||
export default { | ||
name: "CommentNode", | ||
|
@@ -130,17 +143,58 @@ export default { | |
return { | ||
editing: false, | ||
level: [ | ||
{ name: "小萌新~", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_0.svg' }, | ||
{ name: "小魔仙", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_1.svg' }, | ||
{ name: "初露头角", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_2.svg' }, | ||
{ name: "大水笔", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_3.svg' }, | ||
{ name: "后宫团", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_4.svg' }, | ||
{ name: "有豪宅", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_5.svg' }, | ||
{ name: "德国骨科", icon: 'https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_6.svg' }, | ||
{ | ||
name: "小萌新~", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_0.svg" | ||
}, | ||
{ | ||
name: "小魔仙", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_1.svg" | ||
}, | ||
{ | ||
name: "初露头角", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_2.svg" | ||
}, | ||
{ | ||
name: "大水笔", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_3.svg" | ||
}, | ||
{ | ||
name: "后宫团", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_4.svg" | ||
}, | ||
{ | ||
name: "有豪宅", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_5.svg" | ||
}, | ||
{ | ||
name: "德国骨科", | ||
icon: | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/level/level_6.svg" | ||
} | ||
], | ||
globalData: globals, | ||
globalData: globals | ||
}; | ||
}, | ||
created() { | ||
const renderer = { | ||
image(href, title) { | ||
return ` | ||
<img src="${href}" title="${title}" class="lazyload comment_inline_img" onerror="imgError(this)">`; | ||
}, | ||
link(href, title, text) { | ||
return `<a href="${href}" title="${title}" target="_blank" rel="nofollow">${text}</a>` | ||
} | ||
} | ||
marked.use({ renderer }); | ||
}, | ||
computed: { | ||
avatar() { | ||
return ( | ||
|
@@ -151,7 +205,7 @@ export default { | |
}, | ||
compileContent() { | ||
var at = ""; | ||
if (this.parent != undefined ) { | ||
if (this.parent != undefined) { | ||
at = | ||
'<a href="' + | ||
this.parent.authorUrl + | ||
|
@@ -161,6 +215,8 @@ export default { | |
} | ||
// 获取转换后的marked | ||
let markedHtml = marked(at + this.comment.content); | ||
// 处理其中的img | ||
// 处理表情包 | ||
let emoji = renderedEmojiHtml(markedHtml); | ||
// 将回车转换为br | ||
return return2Br(emoji); | ||
|
@@ -173,7 +229,10 @@ export default { | |
parser.setUA(this.comment.userAgent); | ||
var result = parser.getResult(); | ||
var browserImg = "https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/"+ result.browser.name.toLowerCase() +".svg"; | ||
var browserImg = | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/" + | ||
result.browser.name.toLowerCase() + | ||
".svg"; | ||
var uaImg = ""; | ||
switch (result.os.name) { | ||
|
@@ -182,29 +241,53 @@ export default { | |
case "7": | ||
case "8": | ||
case "10": | ||
uaImg = "https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows_win" + result.os.version + ".svg"; | ||
uaImg = | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows_win" + | ||
result.os.version + | ||
".svg"; | ||
break; | ||
case "": | ||
uaImg = "https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows_" + result.os.version + ".svg"; | ||
uaImg = | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows_" + | ||
result.os.version + | ||
".svg"; | ||
break; | ||
default: | ||
uaImg = "https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows.svg"; | ||
uaImg = | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/windows.svg"; | ||
break; | ||
} | ||
break; | ||
default: | ||
uaImg = "https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/" + result.os.name.replace(/\s+/g,"").toLowerCase() + ".svg"; | ||
uaImg = | ||
"https://cdn.jsdelivr.net/gh/LIlGG/[email protected]/img/Sakura/images/ua/svg/" + | ||
result.os.name.replace(/\s+/g, "").toLowerCase() + | ||
".svg"; | ||
break; | ||
} | ||
return `( <img src="` + browserImg + ` "> `+ result.browser.name + " " + result.browser.version + ` | ||
<img src="` + uaImg + `"> `+ result.os.name + " " + result.os.version + ` )`; | ||
return ( | ||
`( <img src="` + | ||
browserImg + | ||
` "> ` + | ||
result.browser.name + | ||
" " + | ||
result.browser.version + | ||
` | ||
<img src="` + | ||
uaImg + | ||
`"> ` + | ||
result.os.name + | ||
" " + | ||
result.os.version + | ||
` )` | ||
); | ||
}, | ||
selfAddDepth() { | ||
return this.depth + 1; | ||
}, | ||
commentClass() { | ||
return 'depth-' + this.depth + " comment-" + this.comment.id; | ||
return "depth-" + this.depth + " comment-" + this.comment.id; | ||
} | ||
}, | ||
methods: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters