|
|
@@ -3,19 +3,43 @@ import service from '@/services'
|
|
|
import moment from 'moment'
|
|
|
|
|
|
/**
|
|
|
+ * 获取url对象方法
|
|
|
+ * @param url
|
|
|
+ * @param base
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export function getUrl(url: string, base?: string) {
|
|
|
+ const { uploadUrl } = service.config
|
|
|
+ return new URL(url, base ?? uploadUrl)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* 获取图片地址
|
|
|
* @param fileUrl
|
|
|
*/
|
|
|
export function getImageUrl(fileUrl: string) {
|
|
|
if (fileUrl) {
|
|
|
- const { openApiUrl } = service.config
|
|
|
- return openApiUrl + fileUrl.replace('./', '/')
|
|
|
+ const url = getUrl(fileUrl)
|
|
|
+ return url.href
|
|
|
}
|
|
|
- // 返回默认图片
|
|
|
return ''
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 格式化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=""/>`
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* 处理价格颜色的显示
|
|
|
*/
|
|
|
export function handlePriceColor(curValue: number, preValue: number) {
|
|
|
@@ -110,17 +134,6 @@ export function formatDate(date: string, format = 'YYYY-MM-DD HH:mm:ss') {
|
|
|
return moment(date).format(format)
|
|
|
}
|
|
|
|
|
|
-export function formatText(text: string) {
|
|
|
- const { uploadUrl } = service.config
|
|
|
- const html = text.replace(/[\n\r]/g, '<br />')
|
|
|
-
|
|
|
- //return html.replace(/(<img[^>]*src=['"])(?:(?!(https|http)))([^>]*>)/g, `$1${uploadUrl}$2/$3`)
|
|
|
-
|
|
|
- return html.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, capture) => {
|
|
|
- return `<img src="${uploadUrl.replace('upload', '') + capture.replace('./', '')}" alt=""/>`
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Des密钥
|
|
|
* 手机发送验证码时加密方法
|