diff --git a/app/admin/view/system/config/upload.html b/app/admin/view/system/config/upload.html index a71cbc6..895ab17 100644 --- a/app/admin/view/system/config/upload.html +++ b/app/admin/view/system/config/upload.html @@ -1,10 +1,10 @@ -
+
{foreach ['local_public'=>'本地存储','alioss'=>'阿里云oss','qnoss'=>'七牛云oss','txcos'=>'腾讯云cos'] as $key=>$val} - + {/foreach}
@@ -25,7 +25,7 @@ -
+
@@ -33,7 +33,7 @@
-
+
@@ -41,7 +41,7 @@
-
+
@@ -49,7 +49,7 @@
-
+
@@ -57,7 +57,7 @@
-
+
@@ -65,7 +65,7 @@
-
+
@@ -73,7 +73,7 @@
-
+
@@ -81,7 +81,7 @@
-
+
@@ -89,14 +89,14 @@
-
+
例子:ulthon-admin-1251997243
-
+
@@ -104,7 +104,7 @@
-
+
@@ -112,7 +112,7 @@
-
+
@@ -120,7 +120,7 @@
-
+
@@ -128,7 +128,7 @@
-
+
diff --git a/app/common.php b/app/common.php index df3ef20..ffbceef 100644 --- a/app/common.php +++ b/app/common.php @@ -3,6 +3,7 @@ use app\common\service\AuthService; use think\facade\Cache; +use think\facade\Filesystem; use think\facade\Request; use think\route\Url; @@ -222,32 +223,11 @@ if (!function_exists('unparse_url')) { } -function build_upload_url($url) +function build_upload_url($url, $upload_type = null) { - $config = sysconfig('upload'); - - $upload_type = $config['upload_type'] ?? 'local_public'; - - $prefix_url = ''; - - switch ($upload_type) { - case 'local_public': - $prefix_url = Request::domain().'/storage'; - break; - case 'qnoss': - $prefix_url = $config['qnoss_domain']; - break; - case 'alioss': - $prefix_url = $config['alioss_domain']; - break; - case 'txcos': - $prefix_url = $config['txcos_domain']; - break; - - default: - # code... - break; + if (is_null($upload_type)) { + $upload_type = sysconfig('upload', 'upload_type', 'local_public'); } - return rtrim($prefix_url, '/') . '/' . ltrim($url, '/'); + return Filesystem::disk($upload_type)->url($url); } diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 0176b97..ee3bdfa 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -50,6 +50,12 @@ class UploadService return $this->validate($file, $allow_ext, $allow_size, true); } + public function url($save_name) + { + $url = Filesystem::disk($this->uploadType)->url($save_name); + return $url; + } + public function save(File $file) { @@ -73,7 +79,7 @@ class UploadService return date('Ymd') . '/' . uniqid(); }); - $url = build_upload_url($save_name); + $url = $this->url($save_name); $model_file->url = $url; $model_file->save_name = $save_name; diff --git a/config/filesystem.php b/config/filesystem.php index 46d3491..99439cc 100644 --- a/config/filesystem.php +++ b/config/filesystem.php @@ -1,6 +1,7 @@ app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 - 'url' => '/storage', + 'url' => Request::domain() . '/storage', // 可见性 'visibility' => 'public', ], diff --git a/extend/think/filesystem/driver/Alioss.php b/extend/think/filesystem/driver/Alioss.php index b2b26be..3b59e68 100644 --- a/extend/think/filesystem/driver/Alioss.php +++ b/extend/think/filesystem/driver/Alioss.php @@ -22,4 +22,9 @@ class Alioss extends Driver $config ); } + + public function url(string $path): string + { + return $this->concatPathToUrl(sysconfig('upload', 'alioss_domain'), $path); + } } diff --git a/extend/think/filesystem/driver/Qiniu.php b/extend/think/filesystem/driver/Qiniu.php index 8a6f059..8b4b936 100644 --- a/extend/think/filesystem/driver/Qiniu.php +++ b/extend/think/filesystem/driver/Qiniu.php @@ -16,5 +16,10 @@ class Qiniu extends Driver sysconfig('upload','qnoss_domain') ); } + + public function url(string $path): string + { + return $this->concatPathToUrl(sysconfig('upload', 'qnoss_domain'), $path); + } } diff --git a/extend/think/filesystem/driver/Txcos.php b/extend/think/filesystem/driver/Txcos.php index 4abd283..9116a84 100644 --- a/extend/think/filesystem/driver/Txcos.php +++ b/extend/think/filesystem/driver/Txcos.php @@ -32,4 +32,9 @@ class Txcos extends Driver return $adapter; } + + public function url(string $path): string + { + return $this->concatPathToUrl(sysconfig('upload', 'txcos_domain'), $path); + } } diff --git a/public/static/admin/js/system/config.js b/public/static/admin/js/system/config.js index e3554b1..7929936 100644 --- a/public/static/admin/js/system/config.js +++ b/public/static/admin/js/system/config.js @@ -5,15 +5,12 @@ define(["jquery", "easy-admin", "vue"], function ($, ea, Vue) { var Controller = { index: function () { - var app = new Vue({ - el: '#app', - data: { - upload_type: upload_type - } - }); - + $('.show-type-item').hide(); + $('.show-type-item.' + upload_type).show(); form.on("radio(upload_type)", function (data) { - app.upload_type = this.value; + + $('.show-type-item').hide(); + $('.show-type-item.' + this.value).show(); }); ea.listen();