Browse Source

模版编辑

moshaorui 5 months ago
parent
commit
dfdcccc63e

+ 1 - 1
app/Admin/Controllers/BaseProductController.php

@@ -33,7 +33,7 @@ class BaseProductController extends AdminController
     protected function grid()
     {
         return Grid::make(BaseProduct::with(['baseProductCategory','images']), function (Grid $grid) {
-            $grid->column('id','ID')->sortable();
+            $grid->column('id')->sortable();
             $grid->column('title');
             $grid->column('sku');
             $grid->column('base_product_category.name','Category Name');

+ 1 - 1
app/Admin/Controllers/BaseVideoController.php

@@ -52,7 +52,7 @@ class BaseVideoController extends AdminController
                 $filter->equal('sku');
                 $filter->like('title');
                 $filter->equal('category_id','Category')->select(BaseVideoCategory::selectOptions());
-                $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'));
+                $filter->equal('enabled', 'Enabled')->select(config('dictionary.enabled'));
             });
             //排序
             $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');

+ 171 - 0
app/Admin/Controllers/DistAppearanceTemplateController.php

@@ -0,0 +1,171 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Repositories\DistAppearanceTemplate;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Show;
+use Dcat\Admin\Http\Controllers\AdminController;
+use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Admin;
+use App\Admin\Forms\monacoLeft;
+use Illuminate\Http\Request;
+
+
+class DistAppearanceTemplateController extends AdminController
+{
+
+    /*
+     * monaco editor 编辑代码
+     */
+    public function monaco(Content $content,Request $request) {
+        if ($request->isMethod('post')) {
+            if($request->get('act') == 'tree') {
+                //获取代码树形结构
+                $appearance_id = $request->get('appearance_id');
+                $dist_id = $request->get('dist_id');
+                return $this->showTree($appearance_id, $dist_id);
+            } elseif ($request->get('act') == 'content') {
+                //得到文件内容
+                $id = $request->get('id');
+                return DistAppearanceTemplate::getContent($id);
+            } elseif ($request->get('act') == 'save') {
+                //保存文件内容
+                $template_id = $request->get('template_id');
+                $content = $request->get('content');
+                return DistAppearanceTemplate::saveContent($template_id, $content);
+            }
+        }
+        $leftForm = new monacoLeft();
+        return $content->body(admin_view('admin.pages-custom.monaco',['leftForm'=>$leftForm]));
+    }
+
+    /*
+     * 显示代码树
+     */
+    private function showTree($appearance_id, $dist_id) {
+        $appearance_id = empty($appearance_id) ? 0 : $appearance_id;
+        $dist_id = empty($dist_id) ? 0 : $dist_id;
+        $tree = DistAppearanceTemplate::getTemplateTree($appearance_id, $dist_id);
+        $html = '<ul class="list-group list-group-flush">';
+        foreach ($tree as $key => $value) {
+            $fa = 'fa-angle-down';
+            $file_name = $value['file_name'];
+            if ($value['file_type'] == 1) {
+                $fa = 'fa-angle-right';
+                $file_name = '<a href="#" class="file-action" file_id="'. $value['id'].'">'. $file_name.'</a>';
+            }
+            $html .= '<li class="list-group-item has-submenu">';
+            $html .= '<i class="fa '.$fa.'"></i> '. $file_name;
+            $html .= $this->treeBuilder($value);
+            $html .= '</li>';
+        }
+        $html .= '</ul>';
+        return $html;
+    }
+
+    private function treeBuilder($value) {
+        $html = '';
+        if (!empty($value['children'])) {
+            $html = '<ul class="submenu">';
+            foreach ($value['children'] as $k => $v) {
+                $fa = 'fa-angle-down';
+                $file_name = $v['file_name'];
+                if ($v['file_type'] == 1) {
+                    $fa = 'fa-angle-right';
+                    $file_name = '<a href="#" class="file-action" file_id="'. $v['id'].'">'. $file_name.'</a>';
+                }
+                $html .= '<li class="list-group-item"><i class="fa '.$fa.'"></i> '. $file_name;
+                if (!empty($v['children'])) {
+                    $html .= $this->treeBuilder($v);
+                }
+                $html .=  '</li>';
+
+            }
+            $html .= '</ul>';
+        }
+        return $html;
+    }
+
+
+
+
+//
+//    /**
+//     * page index
+//     */
+//    public function index(Content $content)
+//    {
+//        return $content
+//            ->header('列表')
+//            ->description('全部')
+//            ->breadcrumb(['text'=>'列表','url'=>''])
+//            ->body($this->grid());
+//    }
+//
+//    /**
+//     * Make a grid builder.
+//     *
+//     * @return Grid
+//     */
+//    protected function grid()
+//    {
+//        return Grid::make(new DistAppearanceTemplate(), function (Grid $grid) {
+//            $grid->column('id')->sortable();
+//            $grid->column('dist_id');
+//            $grid->column('appearance_id');
+//            $grid->column('file_name');
+//            $grid->column('file_path');
+//            $grid->column('content');
+//            $grid->column('created_at');
+//            $grid->column('updated_at')->sortable();
+//
+//            $grid->filter(function (Grid\Filter $filter) {
+//                $filter->equal('id');
+//
+//            });
+//        });
+//    }
+//
+//    /**
+//     * Make a show builder.
+//     *
+//     * @param mixed $id
+//     *
+//     * @return Show
+//     */
+//    protected function detail($id)
+//    {
+//        return Show::make($id, new DistAppearanceTemplate(), function (Show $show) {
+//            $show->field('id');
+//            $show->field('dist_id');
+//            $show->field('appearance_id');
+//            $show->field('file_name');
+//            $show->field('file_path');
+//            $show->field('content');
+//            $show->field('created_at');
+//            $show->field('updated_at');
+//        });
+//    }
+//
+//    /**
+//     * Make a form builder.
+//     *
+//     * @return Form
+//     */
+//    protected function form()
+//    {
+//        return Form::make(new DistAppearanceTemplate(), function (Form $form) {
+//            $form->display('id');
+//            $form->text('dist_id');
+//            $form->text('appearance_id');
+//            $form->text('file_name');
+//            $form->text('file_path');
+//            $form->text('content');
+//
+//            $form->display('created_at');
+//            $form->display('updated_at');
+//        });
+//    }
+}

+ 91 - 0
app/Admin/Controllers/DistAppearanceVariableController.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Repositories\DistAppearanceVariable;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Show;
+use Dcat\Admin\Http\Controllers\AdminController;
+use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Admin;
+
+class DistAppearanceVariableController extends AdminController
+{
+    /**
+     * page index
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('列表')
+            ->description('全部')
+            ->breadcrumb(['text'=>'列表','url'=>''])
+            ->body($this->grid());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        return Grid::make(new DistAppearanceVariable(), function (Grid $grid) {
+            $grid->column('id')->sortable();
+            $grid->column('dist_id');
+            $grid->column('appearance_id');
+            $grid->column('variable_name');
+            $grid->column('variable_value');
+            $grid->column('variable_type');
+            $grid->column('created_at');
+            $grid->column('updated_at')->sortable();
+        
+            $grid->filter(function (Grid\Filter $filter) {
+                $filter->equal('id');
+        
+            });
+        });
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     *
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        return Show::make($id, new DistAppearanceVariable(), function (Show $show) {
+            $show->field('id');
+            $show->field('dist_id');
+            $show->field('appearance_id');
+            $show->field('variable_name');
+            $show->field('variable_value');
+            $show->field('variable_type');
+            $show->field('created_at');
+            $show->field('updated_at');
+        });
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        return Form::make(new DistAppearanceVariable(), function (Form $form) {
+            $form->display('id');
+            $form->text('dist_id');
+            $form->text('appearance_id');
+            $form->text('variable_name');
+            $form->text('variable_value');
+            $form->text('variable_type');
+        
+            $form->display('created_at');
+            $form->display('updated_at');
+        });
+    }
+}

+ 1 - 1
app/Admin/Controllers/DistInquiryController.php

@@ -83,7 +83,7 @@ class DistInquiryController extends AdminController
     {
         return Show::make($id, new DistInquiry(), function (Show $show) {
             $show->field('id');
-            $show->field('order_noumber');
+            $show->field('order_number');
             $show->field('whats_app');
             $show->field('company_name');
             $show->field('customer_name');

+ 1 - 1
app/Admin/Controllers/TestController.php

@@ -57,7 +57,7 @@ class TestController extends AdminController
         return Form::make(new Test(), function (Form $form) {
             $form->display('id');
 
-            $form->text('name')->default("123");
+            $form->textarea('name');
 
             $form->display('created_at');
             $form->display('updated_at');

+ 54 - 0
app/Admin/Forms/monacoLeft.php

@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Admin\Forms;
+
+use App\Admin\Renderable\DistDistributorTable;
+use Symfony\Component\HttpFoundation\Response;
+use Dcat\Admin\Widgets\Form;
+use App\Admin\Repositories\DistAppearance;
+
+class monacoLeft extends Form
+{
+    public function form()
+    {
+        // 定义表单字段
+        //$this->text('name', '姓名')->width(12,12)->setLabelClass('d-flex');
+        //主题选择
+        $this->select('appearance_id','Select Appearance')
+            ->options(DistAppearance::selectOptions())
+            ->width(12,12)
+            ->setLabelClass('d-flex');
+        //供应商选择
+        $this->selectTable('dist_id', 'Select Distributor')
+            ->width(12,12)
+            ->setLabelClass('d-flex')
+            ->title('Select Distributor')
+            ->placeholder('Select Distributor')
+            ->from(DistDistributorTable::make())
+            ->help('If empty, use the original template.');
+        $this->divider();
+        $this->disableSubmitButton();
+        $this->disableResetButton();
+        $this->method('GET');
+    }
+
+    // 处理表单提交请求
+    public function handle(array $input)
+    {
+        // dump($input);
+
+        return $this->response()->success('Processed successfully.')->refresh();
+    }
+
+    /**
+     * 返回表单数据,如不需要可以删除此方法
+     *
+     * @return array
+     */
+    public function default()
+    {
+        return [
+        ];
+    }
+
+}

+ 11 - 0
app/Admin/Repositories/DistAppearance.php

@@ -13,4 +13,15 @@ class DistAppearance extends EloquentRepository
      * @var string
      */
     protected $eloquentClass = Model::class;
+
+    public static function selectOptions()
+    {
+        $data = Model::all();
+        $options = [];
+        foreach ($data as $item) {
+            $options[$item->id] = $item->title;
+        }
+        return $options;
+    }
+
 }

+ 60 - 0
app/Admin/Repositories/DistAppearanceTemplate.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace App\Admin\Repositories;
+
+use App\Models\DistAppearanceTemplate as Model;
+use Dcat\Admin\Repositories\EloquentRepository;
+
+class DistAppearanceTemplate extends EloquentRepository
+{
+    /**
+     * Model.
+     *
+     * @var string
+     */
+    protected $eloquentClass = Model::class;
+
+    public static function getContent($id)
+    {
+        $data = Model::where('id', $id)->first();
+        if ($data) {
+            return $data->content;
+        }
+        return '';
+    }
+    public static function getTemplateTree($appearance_id,$dist_id)
+    {
+        $data = Model::where('appearance_id', $appearance_id)->where('dist_id', $dist_id)->get(['id', 'file_name', 'parent_id','file_type','file_path']);
+        return self::buildTree($data->toArray(),0);
+    }
+
+    public static function buildTree(array $elements, $parentId = 0) {
+        $branch = [];
+
+        foreach ($elements as $element) {
+            if ($element['parent_id'] == $parentId) {
+                $children = self::buildTree($elements, $element['id']);
+                if ($children) {
+                    $element['children'] = $children;
+                }
+                $branch[] = $element;
+            }
+        }
+
+        return $branch;
+    }
+
+    /*
+     * 保存模板内容
+     */
+    public static function saveContent($id, $content)
+    {
+        $data = Model::where('id', $id)->first();
+        if ($data) {
+            $data->content = $content;
+            $data->save();
+            return true;
+        }
+        return false;
+    }
+}

+ 19 - 0
app/Admin/Repositories/DistAppearanceVariable.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Admin\Repositories;
+
+use App\Models\DistAppearanceVariable as Model;
+use Dcat\Admin\Repositories\EloquentRepository;
+
+class DistAppearanceVariable extends EloquentRepository
+{
+    /**
+     * Model.
+     *
+     * @var string
+     */
+    protected $eloquentClass = Model::class;
+
+
+
+}

+ 5 - 0
app/Admin/routes.php

@@ -1,5 +1,6 @@
 <?php
 
+use App\Admin\Controllers\DistAppearanceTemplateController;
 use Illuminate\Routing\Router;
 use Illuminate\Support\Facades\Route;
 use Dcat\Admin\Admin;
@@ -33,4 +34,8 @@ Route::group([
     $router->resource('dist-inquiry', 'DistInquiryController');
     //外观管理
     $router->resource('dist-appearance', 'DistAppearanceController');
+    //模板管理
+    $router->any('dist-template/monaco', [DistAppearanceTemplateController::class, 'monaco']);
+    //模板变量
+    $router->resource('dist-template-var', 'DistAppearanceVariableController');
 });

+ 14 - 0
app/Models/DistAppearanceTemplate.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
+use Illuminate\Database\Eloquent\Model;
+
+class DistAppearanceTemplate extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'dist_appearance_template';
+    
+}

+ 14 - 0
app/Models/DistAppearanceVariable.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
+use Illuminate\Database\Eloquent\Model;
+
+class DistAppearanceVariable extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'dist_appearance_variable';
+    
+}

+ 1 - 1
config/admin.php

@@ -334,7 +334,7 @@ return [
     */
     'layout' => [
         // default, blue, blue-light, green
-        'color' => 'blue',
+        'color' => 'default',
 
         // sidebar-separate
         'body_class' => [],

+ 16 - 0
lang/en/dist-appearance-template.php

@@ -0,0 +1,16 @@
+<?php 
+return [
+    'labels' => [
+        'DistAppearanceTemplate' => 'DistAppearanceTemplate',
+        'dist-appearance-template' => 'DistAppearanceTemplate',
+    ],
+    'fields' => [
+        'dist_id' => 'dist_id',
+        'appearance_id' => 'appearance_id',
+        'file_name' => 'file_name',
+        'file_path' => 'file_path',
+        'content' => 'content',
+    ],
+    'options' => [
+    ],
+];

+ 16 - 0
lang/en/dist-appearance-variable.php

@@ -0,0 +1,16 @@
+<?php 
+return [
+    'labels' => [
+        'DistAppearanceVariable' => 'DistAppearanceVariable',
+        'dist-appearance-variable' => 'DistAppearanceVariable',
+    ],
+    'fields' => [
+        'dist_id' => 'dist_id',
+        'appearance_id' => 'appearance_id',
+        'variable_name' => 'variable_name',
+        'variable_value' => 'variable_value',
+        'variable_type' => 'variable_type',
+    ],
+    'options' => [
+    ],
+];

File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/ace.js


File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/mode-html.js


File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/mode-javascript.js


File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/theme-tomorrow.js


File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/worker-html.js


File diff suppressed because it is too large
+ 0 - 0
public/vendor/ace/worker-javascript.js


+ 140 - 0
resources/views/admin/pages-custom/monaco.blade.php

@@ -0,0 +1,140 @@
+<style>
+    .content-header {
+        display: none;
+    }
+    .left-panel {
+        background-color: #fff; /* 左侧面板的背景色 */
+        height: 89vh; /* 高度占满 */
+    }
+    .right-panel {
+        background-color: #e9ecef; /* 右侧面板的背景色 */
+        height: 86vh; /* 高度占满 */
+    }
+    .right-panel-header {
+        background-color: #fff;
+    }
+    .card-body {
+        max-height: 60vh; /* 设置最大高度 */
+        overflow-y: auto; /* 启用垂直滚动条 */
+        border-radius: 4px; /* 圆角 */
+    }
+
+    #editor {
+        height: 600px; /* 设置编辑器的高度 */
+        width: 800px; /* 设置编辑器的宽度 */
+        background-color: #fff;
+    }
+
+    .submenu {
+        list-style: none;
+        padding-left: 3px;
+    }
+    .submenu .list-group-item {
+        padding: 10px 0px 10px 20px;
+    }
+</style>
+
+
+<div class="container-fluid">
+    <div class="row">
+        <div class="col-2 left-panel"> <!-- 左侧20% -->
+            {!!$leftForm!!}
+            <!-- 代码树 start-->
+            <div class="card-body"></div>
+            <!-- 代码树 end-->
+        </div>
+        <div class="col-10 right-panel"> <!-- 右侧80% -->
+            <div class="right-panel-header">
+                <button type="button" class="btn btn-primary btn-sm" id="save-btn">保存</button>
+            </div>
+            <div class="right-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
+            <input type="hidden" name="template_id"  id="template_id" />
+        </div>
+    </div>
+</div>
+
+<script src="/vendor/ace/ace.js" type="text/javascript"></script>
+
+<script>
+    // 创建 Ace 编辑器实例
+    var editor = ace.edit("editor");
+    // 设置语言
+    editor.getSession().setMode("ace/mode/html");
+    // 设置主题
+    editor.setTheme("ace/theme/tomorrow");
+    editor.setAutoScrollEditorIntoView(true);
+    // 其他配置
+    editor.setOptions({
+        showPrintMargin: true // 不显示打印边距
+    });
+
+    $(document).ready(function() {
+        // 创建 Ace 编辑器实例
+        var actionclick = function() {
+            $('.file-action').click(function() {
+                var id = $(this).attr('file_id');
+                $.ajax({
+                    url: '/prime-control/dist-template/monaco',
+                    type: 'POST',
+                    data: {
+                        act:'content',
+                        id: id
+                    },
+                    success: function(response) {
+                        $("#template_id").val(id);
+                        editor.setValue(response);
+                    }
+                });
+            });
+        }
+        var postData = function () {
+            var appearance_id = $('select[name="appearance_id"]').val();
+            var dist_id = $('input[name="dist_id"]').val();
+            $.ajax({
+                url: '/prime-control/dist-template/monaco',
+                type: 'POST',
+                data: {
+                    act:'tree',
+                    appearance_id: appearance_id,
+                    dist_id: dist_id
+                },
+                success: function(response) {
+                    $('.card-body').html(response);
+                    actionclick();
+                }
+            });
+        }
+        $('select[name="appearance_id"]').change(function() {
+            postData();
+        });
+        $('input[name="dist_id"]').change(function() {
+            postData();
+        });
+        $("#save-btn").click(function() {
+            var template_id = $("#template_id").val();
+            var content = editor.getValue();
+            if (template_id == '') {
+                Dcat.error('操作失败:请先选择模板');
+                return false;
+            }
+            $.ajax({
+                url: '/prime-control/dist-template/monaco',
+                type: 'POST',
+                data: {
+                    act:'save',
+                    template_id: template_id,
+                    content: content
+                },
+                success: function(response) {
+                    if (response == '1') {
+                        Dcat.success('保存成功');
+                    }else{
+                        Dcat.error('保存失败');
+                    }
+                }
+            });
+        })
+    });
+</script>
+
+

Some files were not shown because too many files changed in this diff