Browse Source

扩展别名显示 #1004

jqh 4 years ago
parent
commit
fb1a48e5c8

+ 21 - 10
resources/views/grid/displayer/extensions/name.blade.php

@@ -1,14 +1,25 @@
-@if($row->homepage)
-    <a href='{!! $row->homepage !!}' target='_blank' class="feather {{ $linkIcon }}"></a>
-@endif
-<span class="ext-name">
-    {{ $value }}
-</span>
+<div class="d-flex">
+    @if($row->logo)
+        <img data-action='preview-img' src='{!! $row->logo !!}' style='max-width:40px;max-height:40px;cursor:pointer' class='img img-thumbnail' />&nbsp;&nbsp;
+    @endif
 
-@if($row->new_version || ! $row->version)
-    &nbsp;
-    <span class="badge bg-primary">New</span>
-@endif
+    <span class="ext-name">
+        @if($row->homepage)
+            <a href='{!! $row->homepage !!}' target='_blank' class="feather {{ $linkIcon }}"></a>
+        @endif
+
+        @if($row->alias)
+            {{ $row->alias }} <br><small class="text-80">{{ $value }}</small>
+        @else
+            {{ $value }}
+        @endif
+    </span>
+
+    @if($row->new_version || ! $row->version)
+        &nbsp;
+        <span class="badge bg-primary">New</span>
+    @endif
+</div>
 
 <div style="height: 10px"></div>
 

+ 2 - 2
src/Console/ExtensionMakeCommand.php

@@ -187,8 +187,8 @@ TREE;
 
         // make composer.json
         $composerContents = str_replace(
-            ['{package}', '{namespace}', '{className}'],
-            [$this->package, str_replace('\\', '\\\\', $this->namespace).'\\\\', $this->className],
+            ['{package}', '{alias}', '{namespace}', '{className}'],
+            [$this->package, '', str_replace('\\', '\\\\', $this->namespace).'\\\\', $this->className],
             file_get_contents(__DIR__.'/stubs/extension/composer.json.stub')
         );
         $this->putFile('composer.json', $composerContents);

+ 1 - 0
src/Console/stubs/extension/composer.json.stub

@@ -1,5 +1,6 @@
 {
     "name": "{package}",
+    "alias": "{alias}",
     "description": "Description...",
     "type": "library",
     "keywords": ["dcat-admin", "extension"],

+ 45 - 0
src/Extend/ServiceProvider.php

@@ -143,6 +143,20 @@ abstract class ServiceProvider extends LaravelServiceProvider
         return $this->name ?: ($this->name = str_replace('/', '.', $this->getPackageName()));
     }
 
+    /**
+     * 获取扩展别名.
+     *
+     * @return string
+     */
+    public function getAlias()
+    {
+        if (! $this->composerProperty) {
+            return;
+        }
+
+        return $this->composerProperty->alias;
+    }
+
     /**
      * 获取包名.
      *
@@ -227,6 +241,37 @@ abstract class ServiceProvider extends LaravelServiceProvider
         return $path ? $this->path.'/'.$path : $this->path;
     }
 
+    /**
+     * 获取logo路径.
+     *
+     * @return string
+     *
+     * @throws \ReflectionException
+     */
+    public function getLogoPath()
+    {
+        return $this->path('logo.png');
+    }
+
+    /**
+     * @return string
+     */
+    public function getLogoBase64()
+    {
+        try {
+            $logo = $this->getLogoPath();
+
+            if (is_file($logo) && $file = fopen($logo, 'rb', 0)) {
+                $content = fread($file, filesize($logo));
+                fclose($file);
+                $base64 = chunk_split(base64_encode($content));
+
+                return 'data:image/png;base64,'.$base64;
+            }
+        } catch (\ReflectionException $e) {
+        }
+    }
+
     /**
      * 判断扩展是否启用.
      *

+ 1 - 4
src/Http/Controllers/ExtensionController.php

@@ -35,11 +35,8 @@ class ExtensionController extends Controller
     {
         return new Grid(new Extension(), function (Grid $grid) {
             $grid->number();
-            $grid->column('logo')->display(function (){
-                return $this->logo;
-            })->image('',50,50);
             $grid->column('name')->displayUsing(Extensions\Name::class);
-            $grid->column('description')->displayUsing(Extensions\Description::class)->width('58%');
+            $grid->column('description')->displayUsing(Extensions\Description::class)->width('50%');
 
             $grid->column('authors')->display(function ($v) {
                 if (! $v) {

+ 1 - 1
src/Http/Displayers/Extensions/Name.php

@@ -19,7 +19,7 @@ class Name extends AbstractDisplayer
             'enableAction'    => $this->resolveAction(Enable::class),
             'disableAction'   => $this->resolveAction(Disable::class),
             'uninstallAction' => $this->resolveAction(Uninstall::class),
-            'linkIcon'        => Str::contains($this->row->homepage, 'github.com') ? 'icon-github' : 'icon-link',
+            'linkIcon'        => 'icon-link',
         ]);
     }
 

+ 2 - 17
src/Http/Repositories/Extension.php

@@ -34,29 +34,14 @@ class Extension extends Repository
     {
         $property = $extension->composerProperty;
 
-        // 处理包的Logo
-        $logo = null;
-        try {
-            $logo_path = $extension->path().'/logo.png';
-            if(file_exists($logo_path) && $file = fopen($logo_path,"rb", 0))
-            {
-                $content = fread($file,filesize($logo_path));
-                fclose($file);
-                $base64 = chunk_split(base64_encode($content));
-                $logo = 'data:image/png;base64,' . $base64;
-            }
-        } catch (ReflectionException $e) {
-            // 捕获异常,不用输出
-        }
-
         $name = $extension->getName();
         $current = $extension->getVersion();
         $latest = $extension->getLocalLatestVersion();
 
         return [
             'id'           => $name,
-            'alias'        => $name,
-            'logo'         => $logo,
+            'alias'        => $extension->getAlias(),
+            'logo'         => $extension->getLogoBase64(),
             'name'         => $name,
             'version'      => $current,
             'type'         => $extension->getType(),