|
@@ -49,10 +49,8 @@ class SiteAlbumController extends AdminController
|
|
|
$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;
|
|
|
}
|
|
|
|
|
@@ -80,7 +78,7 @@ class SiteAlbumController extends AdminController
|
|
|
$form->block(10, function (Form\BlockForm $form) {
|
|
|
$form->html($this->grid())->width(12);
|
|
|
});
|
|
|
- //加入JS
|
|
|
+ //以下JS代码用于点击文件夹时,自动跳转到相应页面
|
|
|
Admin::script(
|
|
|
<<<JS
|
|
|
setTimeout(() => {
|
|
@@ -98,17 +96,17 @@ class SiteAlbumController extends AdminController
|
|
|
});
|
|
|
});
|
|
|
}, 200);
|
|
|
-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 = '';
|
|
|
-}
|
|
|
+ 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
|
|
|
);
|
|
|
});
|
|
@@ -127,6 +125,12 @@ JS
|
|
|
return CommonHelper::displayImage($dataImages,80);
|
|
|
});
|
|
|
$grid->column('model');
|
|
|
+ $grid->column('folder_id',admin_trans_label('folder'))
|
|
|
+ ->display(function ($folder_id) {
|
|
|
+ $folderModel = new SiteAlbumFolderModel();
|
|
|
+ $folderName = $folderModel->find($folder_id)->title;
|
|
|
+ return $folderName;
|
|
|
+ });
|
|
|
$grid->column('enabled')->using(admin_trans_array(config('dictionary.enabled'))) ->label([
|
|
|
0 => 'danger',
|
|
|
1 => 'success',
|
|
@@ -144,10 +148,12 @@ JS
|
|
|
});
|
|
|
// 筛选
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
|
+ $selectOptions = SiteAlbumFolderModel::selectOptions();
|
|
|
+ unset($selectOptions[0]);
|
|
|
$filter->panel();
|
|
|
$filter->expand();
|
|
|
$filter->like('model')->width(2);
|
|
|
- $filter->equal('folder_id',admin_trans_label('folder'))->select(SiteAlbumFolderModel::selectOptions())->width(3);
|
|
|
+ $filter->equal('folder_id',admin_trans_label('folder'))->select($selectOptions)->width(3);
|
|
|
});
|
|
|
$grid->disableViewButton();
|
|
|
$grid->disablePerPages();
|
|
@@ -190,8 +196,13 @@ JS
|
|
|
$form->input('pdf', $pdfs);
|
|
|
});
|
|
|
$form->tab(admin_trans_label('basic_info'), function (Form $form) {
|
|
|
+ $selectOptions = SiteAlbumFolder::selectOptions();
|
|
|
+ unset($selectOptions[0]);
|
|
|
$folderId = getTempValue('folderId');
|
|
|
- $form->select('folder_id')->options(SiteAlbumFolder::selectOptions())->default($folderId)->required();
|
|
|
+ if ($folderId == 0) {
|
|
|
+ $folderId = array_key_first($selectOptions);
|
|
|
+ }
|
|
|
+ $form->select('folder_id')->options($selectOptions)->default($folderId)->required();
|
|
|
$form->text('model')->required();
|
|
|
$form->table('parameters',admin_trans_label('attribute_name'), function (Form\NestedForm $table) {
|
|
|
$table->text('key')->required();
|
|
@@ -261,7 +272,7 @@ JS
|
|
|
$form->html($imgHtml,admin_trans_label('image_preview'));
|
|
|
$count++;
|
|
|
|
|
|
- $form->text('cover',admin_trans_label('video_cover'))->placeholder('为空则自动生成');
|
|
|
+ $form->text('cover',admin_trans_label('video_cover'))->placeholder('自动生成')->readOnly();
|
|
|
$form->tradFile('video_src')
|
|
|
->retainable()//禁止删OSS图
|
|
|
->removable() // 可移除图片
|
|
@@ -342,25 +353,74 @@ JS
|
|
|
return json_encode($data);
|
|
|
});
|
|
|
});
|
|
|
+ $folderTabs = SiteAlbumFolder::getAllFolderTabs();
|
|
|
+ $folderTabs = json_encode($folderTabs);
|
|
|
|
|
|
- $folderId = getTempValue('folderId');
|
|
|
- if ($folderId >0) {
|
|
|
+ //以下JS作用:1.点击列表时,把folder_id参数传递给表单 2.切换文件夹时,显示隐藏相应的tab
|
|
|
Admin::script(
|
|
|
<<<JS
|
|
|
const featherIcon = document.querySelector('i.feather.icon-list');
|
|
|
-
|
|
|
if (featherIcon) {
|
|
|
// 找到 <i> 的上级 <a> 元素
|
|
|
const parentLink = featherIcon.closest('a');
|
|
|
+ if (parentLink) {
|
|
|
+ // 绑定 onclick 事件
|
|
|
+ parentLink.onclick = function(event) {
|
|
|
+ // 阻止默认行为(如跳转)
|
|
|
+ event.preventDefault();
|
|
|
|
|
|
- if (parentLink && parentLink.href) {
|
|
|
- // 在 href 后追加 ?folder_id=3
|
|
|
- parentLink.href = parentLink.href + '?folder_id={$folderId}';
|
|
|
+ // 获取 folder_id 的值
|
|
|
+ let folderIdValue = $('select[name="folder_id"]').val();
|
|
|
+
|
|
|
+ // 在 href 后追加 ?folder_id=xxx
|
|
|
+ if (parentLink.href) {
|
|
|
+ const newHref = parentLink.href + '?folder_id=' + folderIdValue;
|
|
|
+ window.location.href = newHref; // 跳转到新的 URL
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
+// 监听 <select name="folder_id"> 的变化事件
|
|
|
+$('select[name="folder_id"]').change(function() {
|
|
|
+ showHideTabs($(this).val());
|
|
|
+});
|
|
|
+folderIdValue = $('select[name="folder_id"]').val();
|
|
|
+showHideTabs(folderIdValue);
|
|
|
+function showHideTabs(fid) {
|
|
|
+ // 获取当前选中的值
|
|
|
+ let folderTabs = {$folderTabs};
|
|
|
+ const folderIdValue = fid;
|
|
|
+ // 获取当前 folderIdValue 对应的标签索引
|
|
|
+ const tabIndexes = folderTabs[folderIdValue];
|
|
|
+ //console.log(tabIndexes);
|
|
|
+
|
|
|
+ if (tabIndexes) {
|
|
|
+ // 处理上方的 <li>,限定在 .nav-tabs 内
|
|
|
+ $('.nav-tabs .nav-item').each(function(index) {
|
|
|
+ if (index > 0) { // 跳过第一个固定元素
|
|
|
+ $(this).hide();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ tabIndexes.forEach(function(index) {
|
|
|
+ $('.nav-tabs .nav-item:eq(' + (Number(index) + 1) + ')').show(); // 使用字符串拼接
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理下方的 tab-pane,限定在 .tab-content 内
|
|
|
+ // $('.tab-content .tab-pane').each(function(index) {
|
|
|
+ // if (index > 0) { // 跳过第一个固定元素
|
|
|
+ // $(this).hide();
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // tabIndexes.forEach(function(index) {
|
|
|
+ // $('.tab-content .tab-pane:eq(' + (Number(index) + 1) + ')').show(); // 使用字符串拼接
|
|
|
+ // });
|
|
|
+ }
|
|
|
+}
|
|
|
JS
|
|
|
);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
});
|
|
|
|