WapAsset.php 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\assets;
  3. use app\modules\admin\models\Config;
  4. use yii\web\AssetBundle;
  5. use Yii;
  6. class WapAsset extends AssetBundle
  7. {
  8. //资源文件的源文件位置
  9. public $sourcePath;
  10. //当前事例引入的文件
  11. public $css = [
  12. ];
  13. public $js = [
  14. ];
  15. //没有依赖
  16. public $depends = [
  17. ];
  18. public function init()
  19. {
  20. parent::init();
  21. $wapconfigResult = Config::find()->where("name='wapconfig'")->one();
  22. $wapconfig = string2array($wapconfigResult->value);
  23. if(!empty($wapconfig['style']))
  24. {
  25. $this->sourcePath = Yii::$app->params['themePath'].$wapconfig['theme'].'/h5/assets/'.$wapconfig['style'];
  26. }
  27. else
  28. {
  29. $this->sourcePath = Yii::$app->params['themePath'].$wapconfig['theme'].'/h5/assets';
  30. }
  31. }
  32. static function getInitCls()
  33. {
  34. static $initCls = NULL;
  35. if(!isset($initCls)) $initCls = new WapAsset();
  36. return $initCls;
  37. }
  38. }