From cc107420feb11ef8a5773ca5733d246824d8a501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JadeYang=28=E6=9D=A8=E7=90=BC=E7=92=9E=29?= Date: Tue, 22 Feb 2022 22:06:25 +0800 Subject: [PATCH] :sparkles: add similar recommend for post page #62 --- package.json | 2 +- src/assets/scss/common.scss | 18 ++- src/components/SimilarRecommend.vue | 178 ++++++++++++++++++++++++++ src/components/linksList/Index.vue | 19 +-- src/components/linksList/LinkItem.vue | 4 +- src/helper/util.js | 19 ++- src/views/Post.vue | 7 +- 7 files changed, 216 insertions(+), 31 deletions(-) create mode 100644 src/components/SimilarRecommend.vue diff --git a/package.json b/package.json index 8c5fae95..e9f068f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nicelinks-vue-client", - "version": "2.0.1", + "version": "2.1.0", "description": "A nice website for assembling nice links created using Vue.js", "author": "jeffjade ", "private": true, diff --git a/src/assets/scss/common.scss b/src/assets/scss/common.scss index 3efabc23..b6bdd2ee 100644 --- a/src/assets/scss/common.scss +++ b/src/assets/scss/common.scss @@ -248,12 +248,20 @@ input:-ms-input-placeholder { display: block; } .v { - padding: 15px 20px; + padding: 0 20px; } - .v[data-class='v'] blockquote { - border-left-width: 4px; - p { - color: $silver-grey; + .v[data-class='v'] { + blockquote { + border-left-width: 4px; + p { + color: $silver-grey; + } + } + .vcomment { + display: block; + } + .vpanel { + margin: 0.5em auto; } } } diff --git a/src/components/SimilarRecommend.vue b/src/components/SimilarRecommend.vue new file mode 100644 index 00000000..60a1147f --- /dev/null +++ b/src/components/SimilarRecommend.vue @@ -0,0 +1,178 @@ + + + + + diff --git a/src/components/linksList/Index.vue b/src/components/linksList/Index.vue index 56e4082d..cd6598f7 100644 --- a/src/components/linksList/Index.vue +++ b/src/components/linksList/Index.vue @@ -12,11 +12,11 @@ - @@ -172,14 +165,6 @@ export default { text-align: left; border-bottom: 1px solid $item-border-color; } - .advert-area { - width: 100%; - padding-top: 15px; - img { - width: 100%; - box-shadow: 0px 0px 20px lightgrey; - } - } } } diff --git a/src/components/linksList/LinkItem.vue b/src/components/linksList/LinkItem.vue index 328466ef..aea542ad 100644 --- a/src/components/linksList/LinkItem.vue +++ b/src/components/linksList/LinkItem.vue @@ -414,14 +414,14 @@ export default { word-break: break-all; } .link-desc { - color: $black-grey; + color: $silver-grey; margin: 15px auto; padding-left: 10px; word-break: break-all; line-height: $font-medium; font-size: $font-small; word-spacing: 3px; - border-left: 2px solid $black-grey; + border-left: 2px solid $border-grey; } .segmenting-line { border-top: 1px solid #8c8b8b; diff --git a/src/helper/util.js b/src/helper/util.js index 9dc25297..dbc37b5d 100644 --- a/src/helper/util.js +++ b/src/helper/util.js @@ -254,15 +254,24 @@ export default { // 获取字符串实际长度(包含汉字,汉字统一按照 2 字节算;) getByteLength(str = '') { if (typeof str !== 'string') return str.length - return str.replace(/[^\x00-\xff]/g, 'aa').length + return str.replace(/[\\u4E00-\\u9FFF]+/g, 'aa').length }, interceptString(string = '', length = 140) { - if (this.getByteLength(string) > 140) { - return string.substring(0, length) + '...' - } else { - return string + let count = 0 + let reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g') + let result = '' + for (let i = 0, len = string.length; i < len; i++) { + const target = string[i] + const isChinese = reg.test(target) + result += target + const step = isChinese ? 2 : 1 + count += step + if (count >= length) { + return result + '...' + } } + return string }, updateAfterFilterEmptyValue(obj) { diff --git a/src/views/Post.vue b/src/views/Post.vue index c8824f89..db2cf870 100644 --- a/src/views/Post.vue +++ b/src/views/Post.vue @@ -5,6 +5,7 @@
+
@@ -15,6 +16,8 @@