feat: 系统消息如果是一个链接则直接跳转

This commit is contained in:
2026-04-15 13:16:35 +08:00
parent 8a9e7205eb
commit f56718e93a
2 changed files with 21 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ import { Https } from "@/tool/https";
import { useRouter,useRoute } from 'vue-router'
import { useStore } from "vuex";
import { useI18n } from 'vue-i18n'
import { isValidUrl } from '@/tool/util';
export default defineComponent({
components:{
},
@@ -70,7 +71,13 @@ export default defineComponent({
accountMessage.isNoData = true
})
}
let setRead = (item:any)=>{
let setRead = (item: any) => {
const content = item.content.content
console.log('111', isValidUrl(content));
if (isValidUrl(content)) {
window.open(content, '_blank');
}
prop.setReadStatus(item).then((rv:any)=>{
item.isRead = 1
}).catch((err:any)=>{

View File

@@ -672,6 +672,17 @@ function sketchToMask(sketchImage) {
img.src = sketchImage;
});
}
function isValidUrl(string) {
try {
const url = new URL(string)
// 通常我们只需要 http 或 https 协议
return url.protocol === "http:" || url.protocol === "https:"
} catch (err) {
return false
}
}
export {
isEmail,
getUploadUrl,
@@ -695,5 +706,6 @@ export {
calculateGradientCoordinate,
segmentImage,
UrlToFile,
sketchToMask
sketchToMask,
isValidUrl
}