Forráskód Böngészése

grid displayer qrcode

Jiang qinghua 5 éve
szülő
commit
4aa933203a
2 módosított fájl, 45 hozzáadás és 0 törlés
  1. 2 0
      src/Grid/Column.php
  2. 43 0
      src/Grid/Displayers/QRCode.php

+ 2 - 0
src/Grid/Column.php

@@ -32,6 +32,7 @@ use Illuminate\Support\Str;
  * @method $this select($options = [])
  * @method $this modal($title = '', \Closure $callback = null)
  * @method $this tree($callbackOrNodes = null)
+ * @method $this qrcode($formatter = null, $width = 150, $height = 150)
  *
  * @method $this limit($limit = 100, $end = '...')
  * @method $this ascii()
@@ -77,6 +78,7 @@ class Column
         'expand'      => Displayers\Expand::class,
         'modal'       => Displayers\Modal::class,
         'tree'        => Displayers\Tree::class,
+        'qrcode'      => Displayers\QRCode::class,
     ];
 
     /**

+ 43 - 0
src/Grid/Displayers/QRCode.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace Dcat\Admin\Grid\Displayers;
+
+use Dcat\Admin\Admin;
+
+/**
+ * Class QRCode.
+ */
+class QRCode extends AbstractDisplayer
+{
+    protected function addScript()
+    {
+        $script = <<<'JS'
+$('.grid-column-qrcode').popover({
+    html: true,
+    trigger: 'focus'
+});
+JS;
+        Admin::script($script);
+    }
+
+    public function display($formatter = null, $width = 150, $height = 150)
+    {
+        $this->addScript();
+
+        $content = $this->column->getOriginal();
+
+        if ($formatter instanceof \Closure) {
+            $formatter->bindTo($this->row);
+
+            $content = call_user_func($formatter, $content);
+        }
+
+        $img = "<img src='https://api.qrserver.com/v1/create-qr-code/?size={$width}x{$height}&data={$content}' style='height: {$width}px;width: {$height}px;'/>";
+        return <<<HTML
+<a href="javascript:void(0);" class="grid-column-qrcode text-muted" data-content="{$img}" data-toggle='popover' tabindex='0'>
+    <i class="fa fa-qrcode"></i>
+</a>&nbsp;{$this->value}
+HTML;
+    }
+
+}