|
|
@@ -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) {
|