+ zin: add zui widget to use js component in zui3

This commit is contained in:
Hao Sun
2023-02-17 12:37:29 +08:00
parent fe6dbdd0f4
commit 7dfa2deac3
5 changed files with 74 additions and 6 deletions
+4 -3
View File
@@ -21,7 +21,7 @@ use stdClass;
* @access public
* @return object
*/
function directive($type, $data)
function directive($type, $data, $options = NULL)
{
if(!in_array($type, array('prop', 'class', 'style', 'cssVar', 'block', 'html', 'text')))
{
@@ -30,8 +30,9 @@ function directive($type, $data)
$directive = new stdClass();
$directive->directive = true;
$directive->type = $type;
$directive->data = $data;
$directive->type = $type;
$directive->data = $data;
$directive->options = $options;
return $directive;
}
+13 -2
View File
@@ -144,12 +144,12 @@ class h extends wg
public static function css()
{
return static::create('style', html(implode('\n', \zin\utils\flat(func_get_args()))));
return static::create('style', html(implode("\n", \zin\utils\flat(func_get_args()))));
}
public static function js()
{
return static::create('script', html('(function(){'. implode('\n', \zin\utils\flat(func_get_args())) . '}())'));
return static::create('script', html('(function(){'. implode("\n", \zin\utils\flat(func_get_args())) . '}())'));
}
public static function jsVar($name, $value)
@@ -165,6 +165,17 @@ class h extends wg
return static::js($jsCode);
}
public static function jsCall()
{
$args = func_get_args();
$func = array_shift($args);
foreach($args as $index => $arg)
{
$args[$index] = json_encode($arg, JSON_UNESCAPED_UNICODE);
}
return static::js($func . '(' . implode(',', $args) . ');');
}
protected static function convertStrToRawHtml($children)
{
$children = \zin\utils\flat($children);
+1
View File
@@ -16,6 +16,7 @@ require_once 'item.class.php';
require_once 'wg.func.php';
require_once 'set.class.php';
require_once 'to.class.php';
require_once 'zui.class.php';
function h() {return call_user_func_array('\zin\h::create', func_get_args());}
+43
View File
@@ -0,0 +1,43 @@
<?php
/**
* The zui component class file of zin lib.
*
* @copyright Copyright 2023 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @author Hao Sun <sunhao@easycorp.ltd>
* @package zin
* @version $Id
* @link https://www.zentao.net
*/
namespace zin;
require_once 'wg.class.php';
require_once 'wg.func.php';
class zui extends wg
{
static $defineProps = '_name:string, _to?:string, _tag:string="div", _toProps?: array';
protected function build()
{
list($name, $target, $tagName, $targetProps) = $this->prop(array('_name', '_to', '_tag', '_toProps'));
$selector = empty($target) ? "[data-zin-id='$this->gid']" : $target;
$options = $this->props->skip(array_keys(static::getDefinedProps()));
return array
(
empty($target) ? h
(
$tagName,
set($targetProps),
set('data-zin-id', $this->gid)
) : NULL,
$this->children(),
h::jsCall('zui.create', $name, $selector, $options)
);
}
public static function __callStatic($name, $args)
{
return new zui(set('_name', $name), $args);
}
}
+13 -1
View File
@@ -32,7 +32,19 @@ class pagebase extends wg
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);}}'),
h::js('window.domReady = function(fn){if (document.readyState !== \'loading\') {fn();} else {document.addEventListener(\'DOMContentLoaded\', fn);}};'),
$zui ? h::js
(
'zui.create = function(name, element, options){',
'if(!zui.componentsMap) zui.componentsMap = Object.keys(zui).reduce(function(map, n){',
'if(n[0] !== n[0].toUpperCase()) return map;',
'map[n.toLowerCase()] = zui[n];',
'return map;',
'}, {});',
'const Component = zui.componentsMap[name.toLowerCase()];',
'return Component ? new Component(element, options) : null;',
'};'
) : null,
$this->block('head'),
),
h::body