From ab4f24febed54bc70aaf301e6887d2f2566823d8 Mon Sep 17 00:00:00 2001
From: yin5th <541304803@qq.com>
Date: Sat, 5 Nov 2022 23:35:58 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controller/Base.php | 18 +++++++++++++++++-
app/controller/manager/Category.php | 21 ++++++++++++++++++++-
app/model/Article.php | 2 +-
app/widget/manager/Upload.php | 1 +
view/manager/article/edit.html | 2 +-
view/manager/category/add.html | 23 +++++++++++++++++++----
view/manager/category/edit.html | 18 ++++++++++++++++--
view/manager/widget/image.html | 12 ++++++------
view/manager/widget/multi.html | 2 +-
view/public/menu.html | 24 +++++++++++++++++++++---
10 files changed, 103 insertions(+), 20 deletions(-)
diff --git a/app/controller/Base.php b/app/controller/Base.php
index f3e8f63..51c58e4 100755
--- a/app/controller/Base.php
+++ b/app/controller/Base.php
@@ -125,7 +125,7 @@ class Base extends BaseController
return $list;
}
- // 获取所在一级栏目背景图
+ // 获取所在一级栏目banner图
protected function firstBanner($category): array
{
// 一级栏目的banner
@@ -143,4 +143,20 @@ class Base extends BaseController
return $bgImg;
}
+
+ // 获取所在一级栏目背景图
+ protected function firstBg($category)
+ {
+ // 一级栏目的banner
+ $firstCategoryId = Category::firstGradeId($category['path'], $category['id']);
+
+ if ($firstCategoryId == $category['id']) {
+ $this->data['bg_pc'] = $category['bg'];
+ $this->data['bg_mobile'] = $category['bg_mobile'];
+ } else {
+ $firstCategory = Category::where('id', $firstCategoryId)->field('id,title,bg,bg_mobile')->find();
+ $this->data['bg_pc'] = $firstCategory['bg'];
+ $this->data['bg_mobile'] = $firstCategory['bg_mobile'];
+ }
+ }
}
diff --git a/app/controller/manager/Category.php b/app/controller/manager/Category.php
index 5c01916..4d5b358 100755
--- a/app/controller/manager/Category.php
+++ b/app/controller/manager/Category.php
@@ -162,6 +162,10 @@ class Category extends Base
$id = input('post.id');
$img = input('post.img');
$img_mobile = input('post.img_mobile');
+
+ $bg_img = input('post.img_bg');
+ $bg_img_mobile = input('post.img_bg_mobile');
+
$icon = input('post.imgicon');
if (count($item) > 0 && (is_numeric($id) === true && $id > 0)) {
Db::startTrans();
@@ -169,6 +173,8 @@ class Category extends Base
validate(VCategory::class)->scene("edit")->check($item);
$item['src'] = empty($img) ? '' : $img;
$item['src_mobile'] = empty($img_mobile) ? '' : $img_mobile;
+ $item['bg'] = empty($bg_img) ? '' : $bg_img;
+ $item['bg_mobile'] = empty($bg_img_mobile) ? '' : $bg_img_mobile;
$item['icon_img'] = empty($icon) ? '' : $icon;
// 只允许文章类栏目可以设置汇总查看
@@ -239,13 +245,26 @@ class Category extends Base
$item = input('post.item/a');
$img = input('post.img');
$img_mobile = input('post.img_mobile');
+
+ $bg_img = input('post.img_bg');
+ $bg_img_mobile = input('post.img_bg_mobile');
+
$icon = input('post.imgicon');
if (is_array($item) === true && count($item) > 0) {
if (!empty($img)) {
$item['src'] = $img;
- }if (!empty($img_mobile)) {
+ }
+ if (!empty($img_mobile)) {
$item['src_mobile'] = $img_mobile;
}
+
+ if (!empty($bg_img)) {
+ $item['bg'] = $bg_img;
+ }
+ if (!empty($bg_img_mobile)) {
+ $item['bg_mobile'] = $bg_img_mobile;
+ }
+
if(!empty($icon)){
$item['icon_img'] = $icon;
}
diff --git a/app/model/Article.php b/app/model/Article.php
index 456b841..62e0ec3 100755
--- a/app/model/Article.php
+++ b/app/model/Article.php
@@ -165,7 +165,7 @@ class Article extends Base
* @param bool $onlyChild 仅获取下级 默认true false=获取所有后代分类
* @return Paginator
*/
- public static function getList($categoryId, $per = 20, $keyword = '', $param = [], $status = -1, $orderList = ['sort' => 'desc'], bool $onlyChild = true)
+ public static function getList($categoryId, $per = 20, $keyword = '', $param = [], $status = -1, $orderList = ['top' => 'desc','sort' => 'desc'], bool $onlyChild = true)
{
$whereMap = [];
$pageParam = [];
diff --git a/app/widget/manager/Upload.php b/app/widget/manager/Upload.php
index 75b733b..70583ac 100755
--- a/app/widget/manager/Upload.php
+++ b/app/widget/manager/Upload.php
@@ -111,6 +111,7 @@ class Upload
$this->data['imgSize'] = $imgSize;
$this->data['num'] = $num;
$this->data['fields'] = $fields;
+ $this->data['fieldsJson'] = json_encode($fields, JSON_UNESCAPED_UNICODE);
return $this->showView('manager/widget/multi');
}
diff --git a/view/manager/article/edit.html b/view/manager/article/edit.html
index 703d544..9ebb25b 100755
--- a/view/manager/article/edit.html
+++ b/view/manager/article/edit.html
@@ -145,7 +145,7 @@
diff --git a/view/manager/category/add.html b/view/manager/category/add.html
index f9d1dd9..40454bd 100755
--- a/view/manager/category/add.html
+++ b/view/manager/category/add.html
@@ -63,15 +63,30 @@
{:widget('manager.upload/image',['append'=>'icon', 'imgSize' => $iconImgSize])}