|
@@ -49,6 +49,11 @@ abstract class Widget implements Renderable
|
|
|
*/
|
|
|
protected $options = [];
|
|
|
|
|
|
+ /**
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected $runScript = true;
|
|
|
+
|
|
|
/**
|
|
|
* @param mixed ...$params
|
|
|
*
|
|
@@ -141,14 +146,22 @@ abstract class Widget implements Renderable
|
|
|
/**
|
|
|
* 收集静态资源.
|
|
|
*/
|
|
|
- protected function collectAssets()
|
|
|
+ public static function collectAssets()
|
|
|
{
|
|
|
- $this->script && Admin::script($this->script);
|
|
|
-
|
|
|
static::$js && Admin::js(static::$js);
|
|
|
static::$css && Admin::css(static::$css);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 运行JS.
|
|
|
+ */
|
|
|
+ protected function withScript()
|
|
|
+ {
|
|
|
+ if ($this->runScript && $this->script) {
|
|
|
+ Admin::script($this->script);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param $value
|
|
|
*
|
|
@@ -164,9 +177,13 @@ abstract class Widget implements Renderable
|
|
|
*/
|
|
|
public function render()
|
|
|
{
|
|
|
- $this->collectAssets();
|
|
|
+ static::collectAssets();
|
|
|
+
|
|
|
+ $html = $this->html();
|
|
|
|
|
|
- return $this->html();
|
|
|
+ $this->withScript();
|
|
|
+
|
|
|
+ return $html;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -205,6 +222,20 @@ abstract class Widget implements Renderable
|
|
|
$this->view = $view;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置是否执行JS代码.
|
|
|
+ *
|
|
|
+ * @param bool $run
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function runScript(bool $run = true)
|
|
|
+ {
|
|
|
+ $this->runScript = $run;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|