瀏覽代碼

静态资源加上版本号

jqh 5 年之前
父節點
當前提交
09fda707cd
共有 1 個文件被更改,包括 20 次插入3 次删除
  1. 20 3
      src/Layout/Asset.php

+ 20 - 3
src/Layout/Asset.php

@@ -4,6 +4,7 @@ namespace Dcat\Admin\Layout;
 
 use Dcat\Admin\Admin;
 use Dcat\Admin\Color;
+use Illuminate\Support\Str;
 
 class Asset
 {
@@ -574,13 +575,29 @@ class Asset
             }
 
             foreach ((array) $paths as $path) {
-                $html .= "<link rel=\"stylesheet\" href=\"{$path}\">";
+                $html .= "<link rel=\"stylesheet\" href=\"{$this->withVersionQuery($path)}\">";
             }
         }
 
         return $html;
     }
 
+    /**
+     * @param string $url
+     *
+     * @return string
+     */
+    public function withVersionQuery($url)
+    {
+        if (! Str::contains($url, '?')) {
+            $url .= '?';
+        }
+
+        $ver = 'v'.Admin::VERSION;
+
+        return Str::endsWith($url, '?') ? $url.$ver : $url.'&'.$ver;
+    }
+
     /**
      * 合并基础js脚本.
      */
@@ -608,7 +625,7 @@ class Asset
             }
 
             foreach ((array) $paths as $path) {
-                $html .= "<script src=\"{$path}\"></script>";
+                $html .= "<script src=\"{$this->withVersionQuery($path)}\"></script>";
             }
         }
 
@@ -628,7 +645,7 @@ class Asset
             }
 
             foreach ((array) $paths as $path) {
-                $html .= "<script src=\"{$path}\"></script>";
+                $html .= "<script src=\"{$this->withVersionQuery($path)}\"></script>";
             }
         }