提交 0b5619b4 编写于 作者: X xjh22222228

fix(#84): img loaded multiple times

上级 e9714349
......@@ -2,7 +2,7 @@
*ngIf="url && !hasError; else noSrc"
[src]="url"
class="icon dark-border-color"
[ngStyle]="{ width: (size || 35) + 'px', height: (size || 35) + 'px' }"
[ngStyle]="{ width: size + 'px', height: size + 'px' }"
>
<ng-template #noSrc>
......
......@@ -2,6 +2,8 @@ import { Component, Input } from '@angular/core'
import { isValidImg } from '../../utils'
import { getCDN } from '../../services'
const effUrlMap = Object.create(null)
@Component({
selector: 'app-logo',
templateUrl: './logo.component.html',
......@@ -11,7 +13,7 @@ export class LogoComponent {
@Input() src: string
@Input() name: string
@Input() colour: string
@Input() size: number
@Input() size: number = 35
@Input() check: boolean = true
hasError = true
......@@ -32,6 +34,11 @@ export class LogoComponent {
return
}
if (this.url in effUrlMap) {
this.hasError = false
return
}
// base64
const regex = /^data:image\/.*;base64,/
if (regex.test(this.url)) {
......@@ -41,6 +48,7 @@ export class LogoComponent {
setTimeout(async() => {
const isValid = await isValidImg(this.url)
effUrlMap[this.url] = isValid
if (isValid) {
this.hasError = false
}
......
......@@ -83,6 +83,8 @@ export function parseBookmark(htmlStr: string) {
url,
desc: '',
urls: {},
rate: 5,
top: false,
icon
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册