关于ImagePreview组件,新增一个判断是否为外部链接的utill方法,简单粗暴,干净又卫生啊兄弟们,另外加了一个判断如果地址为空则使用若依logo进行显示

This commit is contained in:
XCSDN 2022-04-17 13:38:32 +00:00 committed by Gitee
parent b42a8176ca
commit 429f63cfb7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 23 additions and 3 deletions

View File

@ -12,7 +12,8 @@
</template>
<script>
import { isExternal } from "@/utils/validate";
import { isExternalNew } from "@/utils/validate";
import logoImg from '@/assets/logo/logo.png'
export default {
name: "ImagePreview",
@ -33,18 +34,26 @@ export default {
computed: {
realSrc() {
let real_src = this.src.split(",")[0];
if (isExternal(real_src)) {
if (isExternalNew(real_src)) {
return real_src;
}
//使logo
if(real_src===""){
return logoImg;
}
return process.env.VUE_APP_BASE_API + real_src;
},
realSrcList() {
let real_src_list = this.src.split(",");
let srcList = [];
real_src_list.forEach(item => {
if (isExternal(item)) {
if (isExternalNew(item)) {
return srcList.push(item);
}
//使logo
if(item===""){
return srcList.push(logoImg);
}
return srcList.push(process.env.VUE_APP_BASE_API + item);
});
return srcList;

View File

@ -1,4 +1,5 @@
/**
* 判断是否为外部链接
* @param {string} path
* @returns {Boolean}
*/
@ -6,6 +7,16 @@ export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
/**
* 判断是否为外部链接
* 例如http://xxxx https://xxxx chrome:// tcp:// ....等都会返回true
* @param {string} path
* @returns {Boolean}
*/
export function isExternalNew(path) {
return path.indexOf("://") !== -1
}
/**
* @param {string} str
* @returns {Boolean}