AppAsset.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace wechat\assets;
  3. use yii\web\AssetBundle;
  4. use Yii;
  5. use yii\helpers\ArrayHelper;
  6. /**
  7. * Main frontend application asset bundle.
  8. */
  9. class AppAsset extends AssetBundle
  10. {
  11. public $basePath = '@webroot';
  12. public $baseUrl = '@web';
  13. public $css = [
  14. 'css/public.css',
  15. 'js/alert/alert.css', /*公共弹窗样式*/
  16. //'css/public/font.css',
  17. ];
  18. public $js = [
  19. 'js/jquery-3.2.1.min.js',
  20. 'js/nav.js?v=11',
  21. 'js/signup/signup.js',
  22. 'js/applyVerify.js',
  23. // 'js/public.js',
  24. 'js/csrftoken.js',
  25. 'js/alert/alert.js', /*公共弹窗JS*/
  26. ];
  27. public $depends = [
  28. 'yii\web\YiiAsset',
  29. // 'yii\bootstrap\BootstrapAsset',
  30. ];
  31. public static function addScript($view, $jsfile) {
  32. $view->registerJsFile($jsfile.static::Clear(), [AppAsset::className(), "depends" => "wechat\assets\AppAsset"]);
  33. }
  34. public static function addCss($view, $jsfile)
  35. {
  36. $view->registerCssFile($jsfile.static::Clear(), [AppAsset::className(), "depends" => "wechat\assets\AppAsset"]);
  37. }
  38. public function registerAssetFiles($view)
  39. {
  40. $manager = $view->getAssetManager();
  41. foreach ($this->js as $js) {
  42. if (is_array($js)) {
  43. $file = array_shift($js);
  44. $options = ArrayHelper::merge($this->jsOptions, $js);
  45. $view->registerJsFile($manager->getAssetUrl($this, $file), $options);
  46. } else {
  47. if ($js !== null) {
  48. $view->registerJsFile($manager->getAssetUrl($this, $js.static::Clear()), $this->jsOptions);
  49. }
  50. }
  51. }
  52. foreach ($this->css as $css) {
  53. if (is_array($css)) {
  54. $file = array_shift($css);
  55. $options = ArrayHelper::merge($this->cssOptions, $css);
  56. $view->registerCssFile($manager->getAssetUrl($this, $file), $options);
  57. } else {
  58. if ($css !== null) {
  59. $view->registerCssFile($manager->getAssetUrl($this, $css.static::Clear()), $this->cssOptions);
  60. }
  61. }
  62. }
  63. }
  64. public static function Clear()
  65. {
  66. $cache = Yii::$app->cache;
  67. $name = Yii::$app->params['resourceCacheKey']['wechat'];
  68. $con = $cache->get($name);
  69. if($con != false)
  70. {
  71. return '?v='.$con;
  72. }
  73. else
  74. {
  75. return '?v=1111001s';
  76. }
  77. }
  78. }