From 06b230fb95d29a2b5ab21c00eb562affd2eda10f Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 25 Oct 2024 22:06:59 +0800 Subject: [PATCH] bugfix --- bricks/accordion.js | 4 ++++ bricks/audio.js | 2 +- bricks/bricks.js | 8 +++++++- bricks/jsoncall.js | 10 +++++++++- bricks/layout.js | 3 +++ bricks/utils.js | 9 ++++++++- bricks/widget.js | 12 ++++++++++-- 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/bricks/accordion.js b/bricks/accordion.js index 0b95307..5d74cb6 100644 --- a/bricks/accordion.js +++ b/bricks/accordion.js @@ -63,6 +63,10 @@ bricks.Accordion = class extends bricks.VBox { } var c = objget(this.subcontents,name); if (refresh || ! c ){ + if (!this.opts.items[pos].content){ + console.log('***', pos, 'item dont has content'); + return; + } c = await bricks.widgetBuild(this.opts.items[pos].content); this.subcontents[name] = c; } diff --git a/bricks/audio.js b/bricks/audio.js index ecaa48f..2f06e57 100755 --- a/bricks/audio.js +++ b/bricks/audio.js @@ -232,7 +232,7 @@ bricks.AudioRecorder = class extends bricks.HBox { downA.href=this.recordData.url; downA.download=fileName; // document.querySelector("."+cls).appendChild(downA); - if(/mobile/i.test(navigator.userAgent)){ + if(bricks.is_mobile()){ bricks.debug('mobile device'); } downA.click(); diff --git a/bricks/bricks.js b/bricks/bricks.js index a74a717..d18d591 100755 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -460,7 +460,7 @@ bricks.App = class extends bricks.Layout { */ super(opts); bricks.app = this; - bricks.bug = opts.debug or false; + bricks.bug = opts.debug || false; bricks.Body = this; this.deviceid = bricks.deviceid(opts.appname || 'appname'); this.login_url = opts.login_url; @@ -483,6 +483,12 @@ bricks.App = class extends bricks.Layout { this._Height = this.dom_element.offsetHeight; document.addEventListener('keydown', this.key_down_action.bind(this)); } + screenHeight(){ + return this.dom_element.clientHeight; + } + screenWidth(){ + return this.dom_element.clientWidth; + } create(){ this.dom_element = document.getElementsByTagName('body')[0]; this.set_baseURI(this.dom_element.baseURI); diff --git a/bricks/jsoncall.js b/bricks/jsoncall.js index 24f6be6..8b29503 100755 --- a/bricks/jsoncall.js +++ b/bricks/jsoncall.js @@ -43,8 +43,16 @@ bricks.HttpText = class { "Accept":"text/html", }; bricks.extend(this.headers, headers); + var width=0, height=0; + if (bricks.app) { + width = bricks.app.screenWidth(); + height = bricks.app.screenHeight(); + } this.params = { - "_webbricks_":1 + "_webbricks_":1, + "width":width, + "height":height, + "_is_mobile":bricks.is_mobile() } } url_parse(url){ diff --git a/bricks/layout.js b/bricks/layout.js index e251d82..51d1cdf 100755 --- a/bricks/layout.js +++ b/bricks/layout.js @@ -139,6 +139,9 @@ bricks.Layout = class extends bricks.JsWidget { } else { // append child at end w.parent = this; + if (this.baseURI && !w.baseURI){ + w.set_baseURI(this.baseURI); + } this.children.push(w); this.dom_element.appendChild(w.dom_element); } diff --git a/bricks/utils.js b/bricks/utils.js index eb52d15..810377e 100755 --- a/bricks/utils.js +++ b/bricks/utils.js @@ -21,7 +21,11 @@ bricks.debug = function(...args){ try { throw new Error(); } catch (e) { - callInfo = e.stack.split('\n')[2].trim(); + try { + callInfo = e.stack.split('\n')[2].trim(); + } catch (e1) { + callInfo = e.toString(); + } } console.log(callInfo, ...args); } @@ -259,6 +263,9 @@ bricks.absurl = function(url, widget){ return url; } var base_uri = widget.baseURI; + if (!base_uri){ + base_uri = bricks.Body.baseURI; + } if (url.startsWith('/')){ base_uri = bricks.Body.baseURI; url = url.substring(1); diff --git a/bricks/widget.js b/bricks/widget.js index cae5872..b20a143 100755 --- a/bricks/widget.js +++ b/bricks/widget.js @@ -211,8 +211,16 @@ bricks.JsWidget = class { this.id = id; this.dom_element.id = id; } - set_baseURI(url){ - this.baseURI = url; + set_baseURI(uri){ + this.baseURI = uri; + if (!this._container){ + return; + } + this.children.forEach(c =>{ + if (!c.baseURI){ + c.set_baseURI(uri); + } + }); } show(){ this.dom_element.style.display = '';