From 3c29fb17a98facd9b1a324610b15801a22de68ff Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Wed, 15 Feb 2023 11:16:04 +0800 Subject: [PATCH] * zin: output page data to client --- zin/core/props.class.php | 6 +++--- zin/core/wg.class.php | 21 +++++++++++++++++---- zin/wg/pagebase/v1.php | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/zin/core/props.class.php b/zin/core/props.class.php index 46d3efec71..8562fe899e 100755 --- a/zin/core/props.class.php +++ b/zin/core/props.class.php @@ -105,7 +105,7 @@ class props extends \zin\utils\dataset public function addChildren($items) { - $this->addBlock('default', $items); + $this->addBlock('children', $items); } public function getBlock($name) @@ -116,7 +116,7 @@ class props extends \zin\utils\dataset public function getChildren() { - return $this->getBlock('default'); + return $this->getBlock('children'); } /** @@ -197,7 +197,7 @@ class props extends \zin\utils\dataset { $data = $this->data; $data['style'] = $this->style->data; - $data['class'] = $this->class->list; + $data['class'] = $this->class->toStr(); return $data; } diff --git a/zin/core/wg.class.php b/zin/core/wg.class.php index b253003a44..3ba92a4284 100644 --- a/zin/core/wg.class.php +++ b/zin/core/wg.class.php @@ -243,13 +243,26 @@ class wg } } - protected function created() - { - } + protected function created() {} protected function toJsonData() { - + $data = $this->props->toJsonData(); + foreach($data as $key => $value) + { + if($key[0] !== '#') continue; + foreach($value as $index => $child) + { + if($child instanceof wg || (is_object($child) && method_exists($child, 'toJsonData'))) + { + $value[$index] = $child->toJsonData(); + } + } + $data[$key] = $value; + } + $data['$type'] = get_called_class(); + if(strpos($data['$type'], 'zin\\') === 0) $data['$type'] = substr($data['$type'], 4); + return $data; } protected static function getDefaultProps() diff --git a/zin/wg/pagebase/v1.php b/zin/wg/pagebase/v1.php index 0e0ab916b6..b5963e17ff 100644 --- a/zin/wg/pagebase/v1.php +++ b/zin/wg/pagebase/v1.php @@ -42,7 +42,7 @@ class pagebase extends wg ( set($this->prop('bodyProps')), parent::build(), - $config->debug ? h::js('window.zin = ' . json_encode($this->props->toJsonData()) . ';console.log("page", window.zin)') : null // TODO: support to export page data to client + $config->debug ? h::js('window.zin = ' . json_encode($this->toJsonData()) . ';console.log("page", window.zin)') : null ) ); }