附件分类显示修改

This commit is contained in:
evoxwht 2021-10-28 17:43:55 +08:00
parent 89a1bda0e4
commit cd68d42a31
3 changed files with 11 additions and 17 deletions

View File

@ -38,8 +38,10 @@ class SystemAttachmentCategory extends AuthController
public function index()
{
$where = $this->request->getMore([
['name', '']
['name', ''],
['pid', 0]
]);
if ($where['name'] != '') $where['pid'] = '';
return app('json')->success($this->service->getAll($where));
}

View File

@ -44,7 +44,7 @@ class SystemAttachmentCategory extends BaseModel
*/
public function searchNameAttr($query, $value)
{
if ($value) $query->where('name', 'like', '%' . $value . '%');
if ($value != '') $query->where('name', 'like', '%' . $value . '%');
}
/**
@ -54,7 +54,7 @@ class SystemAttachmentCategory extends BaseModel
*/
public function searchPidAttr($query, $value)
{
$query->where('pid', $value);
if ($value !== '') $query->where('pid', $value);
}
}

View File

@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
declare (strict_types = 1);
namespace app\services\system\attachment;
@ -45,20 +45,12 @@ class SystemAttachmentCategoryServices extends BaseServices
*/
public function getAll(array $where)
{
$categoryList = $this->dao->getList($where);
if ($where['name'] != '') {
$pids = Arr::getUniqueKey($categoryList, 'pid');
$parentList = $this->dao->getList(['id' => $pids]);
$categoryList = array_merge($categoryList, $parentList);
foreach ($categoryList as $key => $item) {
$arr = $categoryList[$key];
unset($categoryList[$key]);
if (!in_array($arr, $categoryList)) {
$categoryList[] = $arr;
}
}
$list = $this->dao->getList($where);
foreach ($list as &$item) {
$item['title'] = $item['name'];
$item['children'] = [];
if ($where['name'] == '' && $this->dao->count(['pid' => $item['id']])) $item['loading'] = false;
}
$list = $this->tidyMenuTier($categoryList);
return compact('list');
}