This commit is contained in:
yumoqing 2025-09-13 15:07:42 +08:00
parent 1f94b7f635
commit 166edbd237

View File

@ -10,24 +10,13 @@ bricks.Image = class extends bricks.JsWidget {
constructor(opts){ constructor(opts){
super(opts); super(opts);
this.opts = opts; this.opts = opts;
this.options_parse(); if (this.opts.url){
this.set_url(this.opts.url);
}
} }
create(){ create(){
this.dom_element = document.createElement('img'); this.dom_element = document.createElement('img');
} }
options_parse(){
if (this.opts.hasOwnProperty('url')){
this.set_url(this.opts.url);
}
if (this.opts.hasOwnProperty('width')){
this.width = this.opts.width;
this.dom_element.style.width = this.width;
}
if (this.opts.hasOwnProperty('height')){
this.height = this.opts.height;
this.dom_element.style.height = this.height;
}
}
removeBase64Header(base64String) { removeBase64Header(base64String) {
return base64String.replace(/^data:[^;]*;base64,/, ''); return base64String.replace(/^data:[^;]*;base64,/, '');
} }
@ -51,8 +40,15 @@ bricks.Image = class extends bricks.JsWidget {
} }
set_url(url){ set_url(url){
this.url = url; this.url = url;
if (this.opts.default_url) {
this.dom_element.onerror = this.set_defualt_url
}
this.dom_element.src = url; this.dom_element.src = url;
} }
set_default_url(){
this.dom_element.onerror = null;
this.dom_element.src = this.opts.default_url;
}
} }
bricks.Icon = class extends bricks.Image { bricks.Icon = class extends bricks.Image {