1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace frontend\assets;
- use yii\web\AssetBundle;
- use Yii;
- use yii\helpers\ArrayHelper;
- /**
- * Main frontend application asset bundle.
- */
- class AppAsset extends AssetBundle
- {
- public $basePath = '@webroot';
- public $baseUrl = '@web';
- public $css = [
- '/overseas/css/public.css',
- '/overseas/js/alert/alert.css',
- ];
- public $js = [
- '/overseas/js/jquery-3.2.1.min.js',
- '/overseas/js/csrftoken.js',
- '/overseas/js/search_ajax.js',
- '/overseas/js/public.js',
- '/overseas/js/alert/alert.js',
- '/overseas/js/customerservice.js', //53商务通
- ];
- public $depends = [
- 'yii\web\YiiAsset',
- ];
- /**
- * @param $view
- * @param $jsfile
- */
- public static function addScript($view, $jsfile)
- {
- $view->registerJsFile($jsfile . static::Clear(), [AppAsset::className(), "depends" => "frontend\assets\AppAsset"]);
- }
- /**
- * @param $view
- * @param $jsfile
- */
- public static function addCss($view, $jsfile)
- {
- $view->registerCssFile($jsfile . static::Clear(), [AppAsset::className(), "depends" => "frontend\assets\AppAsset"]);
- }
- /**
- * @param \yii\web\View $view
- */
- public function registerAssetFiles($view)
- {
- $manager = $view->getAssetManager();
- foreach ($this->js as $js) {
- if (is_array($js)) {
- $file = array_shift($js);
- $options = ArrayHelper::merge($this->jsOptions, $js);
- $view->registerJsFile($manager->getAssetUrl($this, $file), $options);
- } else {
- if ($js !== null) {
- $view->registerJsFile($manager->getAssetUrl($this, $js . static::Clear()), $this->jsOptions);
- }
- }
- }
- foreach ($this->css as $css) {
- if (is_array($css)) {
- $file = array_shift($css);
- $options = ArrayHelper::merge($this->cssOptions, $css);
- $view->registerCssFile($manager->getAssetUrl($this, $file), $options);
- } else {
- if ($css !== null) {
- $view->registerCssFile($manager->getAssetUrl($this, $css . static::Clear()), $this->cssOptions);
- }
- }
- }
- }
- /**
- * @return string
- */
- public static function Clear()
- {
- $cache = Yii::$app->cache;
- $name = Yii::$app->params['resourceCacheKey']['mobile'];
- $con = $cache->get($name);
- if ($con != false) {
- return '?v=' . $con;
- } else {
- return '?v=11111111';
- }
- }
- }
|