zs 1 год назад
Родитель
Сommit
01b6fc3aab
3 измененных файлов с 49 добавлено и 6 удалено
  1. 22 3
      src/views/brain/index.vue
  2. 13 1
      src/views/home/index.vue
  3. 14 2
      src/views/news/index.vue

+ 22 - 3
src/views/brain/index.vue

@@ -29,7 +29,7 @@
                     {{ item.title || '暂无标题' }}
                   </el-col>
                   <el-col :span="24" class="right_2 textMore">
-                    <div v-html="item.content"></div>
+                    <div v-html="removeHtmlStyle(item.content)"></div>
                   </el-col>
                   <el-col :span="24" class="right_3">
                     {{ item.time || '暂无' }}
@@ -146,7 +146,18 @@ const toView = (item) => {
 const toMore = () => {
   router.push({ path: `/achievement` })
 }
-
+const removeHtmlStyle = (html) => {
+  let relStyle = /style\s*?=\s*?([‘"])[\s\S]*?\1/g //去除样式
+  let relTag = /<.+?>/g //去除标签
+  let relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g // 清除类名
+  let newHtml = ''
+  if (html) {
+    newHtml = html.replace(relStyle, '')
+    newHtml = newHtml.replace(relTag, '')
+    newHtml = newHtml.replace(relClass, '')
+  }
+  return newHtml
+}
 const currentPage = ref(1)
 // 分页
 const changePage = (page = currentPage.value) => {
@@ -217,6 +228,7 @@ const sizeChange = (limits) => {
           }
         }
         .right {
+          margin: 0 0 0 10px;
           .right_1 {
             height: 24px;
             font-size: 18px;
@@ -230,9 +242,16 @@ const sizeChange = (limits) => {
             margin-bottom: 20px;
           }
           .right_2 {
-            height: 48px;
             margin-bottom: 20px;
+            height: 48px;
+            overflow: hidden;
             font-size: 14px;
+            font-family:
+              PingFangSC-Regular,
+              PingFang SC;
+            font-weight: 400;
+            color: #999;
+            line-height: 24px;
           }
           .right_3 {
             font-size: 12px;

+ 13 - 1
src/views/home/index.vue

@@ -41,7 +41,7 @@
                       </el-tooltip>
                     </el-col>
                     <el-col :span="24" class="content">
-                      <div v-html="item.content"></div>
+                      <div v-html="removeHtmlStyle(item.content)"></div>
                     </el-col>
                   </el-col>
                 </el-col>
@@ -472,6 +472,18 @@ const mouseOver = async (item) => {
 const toChat = (item) => {
   router.push({ path: '/chat', query: { id: item.id || item._id } })
 }
+const removeHtmlStyle = (html) => {
+  let relStyle = /style\s*?=\s*?([‘"])[\s\S]*?\1/g //去除样式
+  let relTag = /<.+?>/g //去除标签
+  let relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g // 清除类名
+  let newHtml = ''
+  if (html) {
+    newHtml = html.replace(relStyle, '')
+    newHtml = newHtml.replace(relTag, '')
+    newHtml = newHtml.replace(relClass, '')
+  }
+  return newHtml
+}
 </script>
 <style scoped lang="scss">
 .main {

+ 14 - 2
src/views/news/index.vue

@@ -35,7 +35,7 @@
                         </el-tooltip>
                       </el-col>
                       <el-col :span="24" class="content">
-                        <div v-html="item.content"></div>
+                        <div v-html="removeHtmlStyle(item.content)"></div>
                       </el-col>
                     </el-col>
                   </el-col>
@@ -67,7 +67,7 @@
                         </el-tooltip>
                       </el-col>
                       <el-col :span="24" class="content">
-                        <div v-html="item.content"></div>
+                        <div v-html="removeHtmlStyle(item.content)"></div>
                       </el-col>
                     </el-col>
                   </el-col>
@@ -140,6 +140,18 @@ const search = async () => {
 const toView = (item) => {
   router.push({ path: `/news/detail`, query: { id: item.id || item._id } })
 }
+const removeHtmlStyle = (html) => {
+  let relStyle = /style\s*?=\s*?([‘"])[\s\S]*?\1/g //去除样式
+  let relTag = /<.+?>/g //去除标签
+  let relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g // 清除类名
+  let newHtml = ''
+  if (html) {
+    newHtml = html.replace(relStyle, '')
+    newHtml = newHtml.replace(relTag, '')
+    newHtml = newHtml.replace(relClass, '')
+  }
+  return newHtml
+}
 </script>
 <style scoped lang="scss">
 .main {