li.shaoyi 2 lat temu
rodzic
commit
8533646238

+ 32 - 0
src/filters/index.ts

@@ -26,6 +26,38 @@ export function getFileUrl(filePath?: string) {
 }
 
 /**
+ * 格式化html字符串
+ * @param text 
+ * @returns 
+ */
+export function formatHtmlString(text: string) {
+    const html = text.replace(/[\n\r]/g, '<br />')
+    return html.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, capture) => {
+        // 替换img标签src地址为绝对路径
+        const url = getUrl(capture)
+        return `<img src="${url.href}"  alt=""/>`
+    })
+}
+
+/**
+ * 获取html中的图片链接
+ * @param text 
+ * @returns 
+ */
+export function getImageSrc(text?: string) {
+    const images = text?.match(/<img.*?>/g)
+    const urls = images?.reduce((res, img) => {
+        const src = img.match(/\ssrc=['"](.*?)['"]/)
+        if (src) {
+            const url = getUrl(src[1])
+            res.push(url.href)
+        }
+        return res
+    }, [] as string[])
+    return urls ?? []
+}
+
+/**
  * 处理价格颜色的显示
  */
 export function handlePriceColor(curValue: number, preValue: number) {

+ 2 - 2
src/packages/pc/components/layouts/header/components/notice/index.vue

@@ -20,7 +20,7 @@
                             <span style="font-size: 12px; color: #999;margin: 8px 0;">{{ formatDate(item.createtime)
                             }}</span>
                         </h4>
-                        <p style="line-height: 26px;color: #555;">{{ item.content }}</p>
+                        <div style="line-height: 24px;color: #555;" v-html="formatHtmlString(item.content)"></div>
                     </div>
                 </el-tab-pane>
             </template>
@@ -31,7 +31,7 @@
 
 <script lang="ts" setup>
 import { shallowRef, computed, onMounted } from 'vue'
-import { formatDate } from '@/filters'
+import { formatDate, formatHtmlString } from '@/filters'
 import { useNotice } from '@/stores'
 import AppDrawer from '@pc/components/base/drawer/index.vue'
 

+ 1 - 1
src/packages/pc/views/customs/exit/components/edit/index.vue

@@ -370,7 +370,7 @@ const onSubmit = (draft = false) => {
 }
 
 const downloadFile = () => {
-    window.open('/file/20230608.zip')
+    window.open('file/20230608.zip')
 }
 
 onMounted(() => {