diff --git a/zin/config.php b/zin/config.php index 01b3db0a3e..0da4b03096 100755 --- a/zin/config.php +++ b/zin/config.php @@ -15,6 +15,7 @@ global $app, $config; $config->zin = new \stdClass(); +$config->zin->lang = $app->getClientLang(); $config->zin->wgVer = isset($config->wgVer) ? $config->wgVer : '1'; $config->zin->wgVerMap = isset($config->wgVerMap) ? $config->wgVerMap : array(); $config->zin->zuiPath = isset($config->zuiPath) ? $config->zuiPath : ($app->getWebRoot() . 'js/zui3/'); diff --git a/zin/func.php b/zin/func.php index 12cefcb475..b9c40b9831 100644 --- a/zin/func.php +++ b/zin/func.php @@ -45,3 +45,5 @@ function import() {return call_user_func_array('\zin\core\import', func_get_a function icon() {return createWg('icon', func_get_args());} function btn() {return createWg('btn', func_get_args());} +function pagebase() {return createWg('pagebase', func_get_args());} +function page() {return createWg('page', func_get_args());} diff --git a/zin/wg/page/v1.php b/zin/wg/page/v1.php index b79ebcf763..e11b8b6a02 100644 --- a/zin/wg/page/v1.php +++ b/zin/wg/page/v1.php @@ -6,12 +6,12 @@ require_once dirname(__DIR__) . DS . 'pagebase' . DS . 'v1.php'; class page extends pagebase { - static $defaultProps = array('zui' => true); - - public function init() - { - // $this->setDefaultProps(array('zui' => true)); - - parent::init(); - } + static $defineProps = array + ( + 'metas' => array('type' => 'string|array', 'default' => array('', '', '', '')), + 'title' => array('type' => 'string', 'default' => ''), + 'bodyProps' => array('type' => 'array', 'optional' => true), + 'zui' => array('type' => 'bool', 'default' => true), + 'print' => array('type' => 'bool', 'default' => false) + ); } diff --git a/zin/wg/pagebase/v1.php b/zin/wg/pagebase/v1.php index e6cb4d12d4..381056207e 100644 --- a/zin/wg/pagebase/v1.php +++ b/zin/wg/pagebase/v1.php @@ -2,37 +2,30 @@ namespace zin\wg; require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'wg.class.php'; +require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'h.class.php'; +require_once dirname(dirname(__DIR__)) . DS . 'core' . DS . 'directive.func.php'; + +use zin\core\h; +use function zin\core\html; +use function zin\core\set; +use function zin\core\before; +use function zin\core\import; +use function zin\core\js; class pagebase extends \zin\core\wg { static $tag = 'html'; - static $customProps = 'metas,title,bodyProps,zui,print'; + static $defineProps = array + ( + 'metas' => array('type' => 'string|array', 'default' => array('', '', '', '')), + 'title' => array('type' => 'string', 'default' => ''), + 'bodyProps' => array('type' => 'array', 'optional' => true), + 'zui' => array('type' => 'bool', 'default' => false), + 'print' => array('type' => 'bool', 'default' => false) + ); - public $bodyProps; - - public function init() - { - global $app, $config; - $clientLang = $app->getClientLang(); - - $this->bodyProps = \zin\core\wg::createClass($this->prop('bodyProps')); - - $this->setDefaultProps(array('lang' => $clientLang, 'print' => true)); - - $this->addMeta('') - ->addMeta('') - ->addMeta('') - ->addMeta(''); - - if($this->prop('zui') && isset($config->zin->zuiPath)) - { - $this->importJs($config->zin->zuiPath . 'zui.zentao.umd.cjs') - ->importCss($config->zin->zuiPath . 'zui.zentao.css'); - } - } - - public function onCreated() + protected function created() { if($this->prop('print')) { @@ -40,74 +33,29 @@ class pagebase extends \zin\core\wg } } - public function title($title) + protected function build($isPrinted = false) { - return $this->prop('title', $title); - } + global $lang, $config; - public function addMeta($meta) - { - $metas = $this->props->get('metas', array()); - $metas[] = $meta; - $this->prop('metas', $metas); - return $this; - } - - public function bodyClass($className, $reset = false) - { - $this->bodyProps->class->set($className, $reset); - } - - public function bodyStyle($prop, $value = NULL, $removeEmpty = false) - { - $this->bodyProps->style->set($prop, $value, $removeEmpty); - return $this; - } - - protected function buildHead($isPrint = false, $parent = NULL) - { - global $lang; - - $headBuilder = \zin\core\wg::createBuilder('head') - ->before($this->prop('metas')) - ->before('' . htmlspecialchars($this->props->get('title', '')) . " - $lang->zentaoPMS") - ->css($this->cssList) - ->importCss($this->cssImports) - ->renderInTag(); - - if(isset($this->blocks['head'])) - { - $headBuilder->append($this->buildChildren($this->blocks['head'], $isPrint, $parent)); - } - - $headBuilder->js('window.domReady = function(fn){if (document.readyState !== \'loading\') {fn();} else {document.addEventListener(\'DOMContentLoaded\', fn);}}'); - - return $headBuilder; - } - - protected function buildBody($isPrint = false, $parent = NULL) - { - $builder = \zin\core\wg::createBuilder('body', $this->bodyProps) - ->importJs($this->jsImports) - ->js($this->jsList) - ->append($this->buildInnerHtml($isPrint, $parent)) - ->renderInTag(); - - global $config; - if($config->debug) - { - $builder->jsVar('window.zin', array('page' => $this)); - $builder->js('console.log("zin.page", window.zin.page)'); - } - - return $builder; - } - - public function build($isPrint = false, $parent = NULL) - { - return \zin\core\wg::createBuilder('html', $this->props) - ->before('') - ->append($this->buildHead()->build()) - ->append($this->buildBody()->build()); + $zui = $this->prop('zui'); + return h::html + ( + before(html('')), + h::head + ( + html($this->prop('metas')), + h::title($this->props->get('title', '') . " - $lang->zentaoPMS"), + $zui ? h::import(array($config->zin->zuiPath . 'zui.zentao.umd.cjs', $config->zin->zuiPath . 'zui.zentao.css')) : null, + h::js('window.domReady = function(fn){if (document.readyState !== \'loading\') {fn();} else {document.addEventListener(\'DOMContentLoaded\', fn);}}'), + $this->block('head'), + ), + h::body + ( + set($this->prop('bodyProps')), + $this->block('body'), + parent::build($isPrinted), + $config->debug ? h::js('window.zin = ' . json_encode($this) . ';console.log("page", window.zin.page)') : null + ) + ); } }