|
@@ -3,50 +3,141 @@
|
|
|
namespace App\Distributor\Controllers;
|
|
|
|
|
|
|
|
|
+use App\Distributor\Repositories\NullRepository;
|
|
|
use App\Distributor\Actions\Extensions\DistProductImportForm;
|
|
|
use App\Distributor\Repositories\RpcAlbum;
|
|
|
use App\Distributor\Repositories\RpcAlbumFolder;
|
|
|
-use App\Distributor\Repositories\BaseProduct;
|
|
|
use App\Libraries\CommonHelper;
|
|
|
+use Dcat\Admin\Admin;
|
|
|
+use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
|
|
use Dcat\Admin\Show;
|
|
|
use Dcat\Admin\Layout\Content;
|
|
|
|
|
|
class ImportProductController extends AdminDistController
|
|
|
{
|
|
|
+
|
|
|
/**
|
|
|
* page index
|
|
|
*/
|
|
|
public function index(Content $content)
|
|
|
{
|
|
|
- return $content
|
|
|
+// return $content
|
|
|
+// ->header(admin_trans( 'admin.product_import'))
|
|
|
+// ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
|
|
|
+// ->breadcrumb(['text'=>'list','url'=>''])
|
|
|
+// ->body($this->grid());
|
|
|
+
|
|
|
+ //记录folder_id
|
|
|
+ $folderId = isset($_GET['folder_id']) ? intval($_GET['folder_id']) : 0;
|
|
|
+ //保存临时变量
|
|
|
+ setTempValue('folderId', $folderId);
|
|
|
+ $html = $content
|
|
|
->header(admin_trans( 'admin.product_import'))
|
|
|
- ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
|
|
|
- ->breadcrumb(['text'=>'list','url'=>''])
|
|
|
- ->body($this->grid());
|
|
|
+ ->body($this->indexForm());
|
|
|
+ $html = $html->render();
|
|
|
+ return $this->filterHtml($html);
|
|
|
}
|
|
|
|
|
|
+ protected function indexForm()
|
|
|
+ {
|
|
|
+ return Form::make(new NullRepository(), function (Form $form) {
|
|
|
+ $lang = config('app.locale');//当前语言
|
|
|
+ $form->action('/site-album');
|
|
|
+ $folderTree = RpcAlbumFolder::siteAlbumFolderAllNodes();
|
|
|
+ //显示左边树形菜单
|
|
|
+ $form->block(2, function (Form\BlockForm $form) use ($lang,$folderTree) {
|
|
|
+ $type = [
|
|
|
+ 'default' => [
|
|
|
+ 'icon' => true,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ $plugins = ['types'];
|
|
|
+ if ($lang == 'en') {
|
|
|
+ $form->tree()
|
|
|
+ ->setTitleColumn('title_en')
|
|
|
+ ->nodes($folderTree)
|
|
|
+ ->type($type)
|
|
|
+ ->plugins($plugins)
|
|
|
+ ->width(12,0);
|
|
|
+ } else {
|
|
|
+ $form->tree()
|
|
|
+ ->setTitleColumn('title')
|
|
|
+ ->nodes($folderTree)
|
|
|
+ ->type($type)
|
|
|
+ ->plugins($plugins)
|
|
|
+ ->width(12,0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //右边相删内容
|
|
|
+ $form->block(10, function (Form\BlockForm $form) {
|
|
|
+ $form->html($this->grid())->width(12);
|
|
|
+ });
|
|
|
+ //以下JS代码用于点击文件夹时,自动跳转到相应页面
|
|
|
+ Admin::script(
|
|
|
+ <<<JS
|
|
|
+// 使用定时器检测容器是否存在
|
|
|
+const interval = setInterval(() => {
|
|
|
+ const containerUl = document.getElementsByClassName('jstree-node');
|
|
|
+ if (containerUl.length > 0) {
|
|
|
+ clearInterval(interval); // 找到容器后停止检测
|
|
|
+ // 以下是原有逻辑(已优化)
|
|
|
+ const folderId = $('select[name="folder_id"]').data('value'); // 提取 folderId 到外层,避免重复查询[1](@ref)
|
|
|
+ const anchors = document.querySelectorAll('a.jstree-anchor');
|
|
|
|
|
|
+ anchors.forEach(anchor => {
|
|
|
+ const id = anchor.id.split('_')[0];
|
|
|
+ const href = `/dist/import-product?folder_id=`+id;
|
|
|
|
|
|
- //屏蔽删除
|
|
|
- public function destroy($id)
|
|
|
- {
|
|
|
- abort(404);
|
|
|
+ // 绑定点击事件(阻止默认行为)
|
|
|
+ anchor.addEventListener('click', event => {
|
|
|
+ event.preventDefault();
|
|
|
+ window.location.href = href;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 高亮当前节点
|
|
|
+ if (folderId == id) {
|
|
|
+ anchor.classList.add('jstree-clicked');
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+}, 100); // 每100ms检测一次
|
|
|
|
|
|
- //屏蔽创建
|
|
|
- public function create(Content $content)
|
|
|
- {
|
|
|
- abort(404);
|
|
|
+ const firstCheckbox = document.querySelector('.vs-checkbox-primary');
|
|
|
+ // 如果找到元素,则隐藏它
|
|
|
+ if (firstCheckbox) {
|
|
|
+ firstCheckbox.style.display = 'none';
|
|
|
+ }
|
|
|
+ //清空_previous_
|
|
|
+ const input = document.querySelector('input[name="_previous_"]');
|
|
|
+ if (input) {
|
|
|
+ // 清空其值
|
|
|
+ input.value = '';
|
|
|
+ }
|
|
|
+JS
|
|
|
+ );
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- //屏蔽编辑
|
|
|
- public function edit($id, Content $content)
|
|
|
+ /**
|
|
|
+ * @return void 过滤html 把form去掉,修复form引起的BUG
|
|
|
+ */
|
|
|
+ private function filterHtml($html)
|
|
|
{
|
|
|
- abort(404);
|
|
|
+ //删除第一个formID对应的JS代码
|
|
|
+ preg_match('/<form[^>]*id="([^"]*)"[^>]*>/', $html, $matches);
|
|
|
+ if (isset($matches[1])) {
|
|
|
+ $formId = $matches[1]; // 获取 id 的值
|
|
|
+ // echo "找到的 form id: " . $formId . "\n";
|
|
|
+ // 2. 根据 id 值,删除对应的 JavaScript 代码
|
|
|
+ $pattern = '/\$\(\'#' . preg_quote($formId, '/') . '\'\)\.form\(\{.*?\}\);/s';
|
|
|
+ $html = preg_replace($pattern, '', $html);
|
|
|
+ }
|
|
|
+ //把第一个form标签替换成div标签
|
|
|
+ $html = preg_replace('/<form([^>]*)>(.*?)<\/form>/s', '<div$1>$2</div>', $html, 1);
|
|
|
+ return $html;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Make a grid builder.
|
|
|
*
|
|
@@ -60,41 +151,36 @@ class ImportProductController extends AdminDistController
|
|
|
$grid->column('id')->display(function () {
|
|
|
return $this->_index+1;
|
|
|
})->width('8%');
|
|
|
+
|
|
|
$grid->column('cover')->display(function ($images) {
|
|
|
$images = json_decode($images);
|
|
|
// 限制最多显示2个缩略图
|
|
|
$dataImages = array_slice($images, 0, 1);
|
|
|
return CommonHelper::displayImage($dataImages,100,1024,2);
|
|
|
});
|
|
|
+
|
|
|
if ($lang == 'en') {
|
|
|
$grid->column('title_en');
|
|
|
} else {
|
|
|
$grid->column('title');
|
|
|
}
|
|
|
- $grid->column('model');
|
|
|
- $grid->column('missing_content')->display(function ($missing_content) {
|
|
|
- $missing_content = [];
|
|
|
- if ($this->cover == '[]') {$missing_content[] = '主图';}
|
|
|
- if ($this->en_detail == '[]') {$missing_content[] = '英文详情';}
|
|
|
- if ($this->cn_detail == '[]') {$missing_content[] = '中文详情';}
|
|
|
- if ($this->video == '[]') {$missing_content[] = '视频';}
|
|
|
- if ($this->poster == '[]') {$missing_content[] = '海报';}
|
|
|
- if ($this->cert == '[]') {$missing_content[] = '证书';}
|
|
|
- if ($this->pdf == '[]') {$missing_content[] = 'PDF';}
|
|
|
- return implode(' / ', $missing_content);
|
|
|
- });
|
|
|
|
|
|
$grid->column('created_at')->sortable();
|
|
|
$grid->column('updated_at')->sortable();
|
|
|
|
|
|
// 筛选
|
|
|
- $grid->filter(function (Grid\Filter $filter) {
|
|
|
+ $grid->filter(function (Grid\Filter $filter) {
|
|
|
$filter->panel();
|
|
|
$filter->expand();
|
|
|
- $filter->equal('model')->width(2);
|
|
|
$lang = config('app.locale');//当前语言
|
|
|
+ if ($lang == 'en') {
|
|
|
+ $filter->equal('title_cn')->width(3);
|
|
|
+ } else {
|
|
|
+ $filter->equal('title')->width(3);
|
|
|
+ }
|
|
|
$filter->equal('folder_id',admin_trans_label('product_category'))->select(RpcAlbumFolder::selectOptions($lang))->width(3);
|
|
|
});
|
|
|
+
|
|
|
// 删除新增按钮
|
|
|
$grid->disableCreateButton();
|
|
|
//$grid->disableViewButton();
|
|
@@ -114,6 +200,8 @@ class ImportProductController extends AdminDistController
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
protected function detail($id)
|
|
|
{
|
|
|
return Show::make($id, new \App\Admin\Repositories\RpcAlbum(), function (Show $show) {
|
|
@@ -216,4 +304,23 @@ class ImportProductController extends AdminDistController
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //屏蔽删除
|
|
|
+ public function destroy($id)
|
|
|
+ {
|
|
|
+ abort(404);
|
|
|
+ }
|
|
|
+
|
|
|
+ //屏蔽创建
|
|
|
+ public function create(Content $content)
|
|
|
+ {
|
|
|
+ abort(404);
|
|
|
+ }
|
|
|
+
|
|
|
+ //屏蔽编辑
|
|
|
+ public function edit($id, Content $content)
|
|
|
+ {
|
|
|
+ abort(404);
|
|
|
+ }
|
|
|
+
|
|
|
}
|