diff --git a/application/admin/controller/general/Attachment.php b/application/admin/controller/general/Attachment.php index 2963a099..3b749b5b 100644 --- a/application/admin/controller/general/Attachment.php +++ b/application/admin/controller/general/Attachment.php @@ -42,7 +42,7 @@ class Attachment extends Backend $filter = $this->request->request('filter'); $filterArr = (array)json_decode($filter, true); if (isset($filterArr['category']) && $filterArr['category'] == 'unclassed') { - $filterArr['category'] = ''; + $filterArr['category'] = ',unclassed'; $this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['category' => '']))]); } if (isset($filterArr['mimetype']) && preg_match("/[]\,|\*]/", $filterArr['mimetype'])) { @@ -153,6 +153,7 @@ class Attachment extends Backend if ($category && !isset($categoryList[$category])) { $this->error(__('Category not found')); } + $category = $category == 'unclassed' ? '' : $category; \app\common\model\Attachment::where('id', 'in', $ids)->update(['category' => $category]); $this->success(); } diff --git a/application/common/model/Attachment.php b/application/common/model/Attachment.php index c4540bc0..4c047819 100644 --- a/application/common/model/Attachment.php +++ b/application/common/model/Attachment.php @@ -19,6 +19,21 @@ class Attachment extends Model 'thumb_style' ]; + protected static function init() + { + // 如果已经上传该资源,则不再记录 + self::beforeInsert(function ($model) { + if (self::where('url', '=', $model['url'])->where('storage', $model['storage'])->find()) { + return false; + } + }); + self::beforeWrite(function ($row) { + if (isset($row['category']) && $row['category'] == 'unclassed') { + $row['category'] = ''; + } + }); + } + public function setUploadtimeAttr($value) { return is_numeric($value) ? $value : strtotime($value); @@ -69,21 +84,11 @@ class Attachment extends Model */ public static function getCategoryList() { - $data = config('site.attachmentcategory')??[]; + $data = config('site.attachmentcategory') ?? []; foreach ($data as $index => &$datum) { $datum = __($datum); } $data['unclassed'] = __('Unclassed'); return $data; } - - protected static function init() - { - // 如果已经上传该资源,则不再记录 - self::beforeInsert(function ($model) { - if (self::where('url', '=', $model['url'])->where('storage', $model['storage'])->find()) { - return false; - } - }); - } } diff --git a/public/assets/js/backend/general/attachment.js b/public/assets/js/backend/general/attachment.js index 70e87eaa..7e296ed8 100644 --- a/public/assets/js/backend/general/attachment.js +++ b/public/assets/js/backend/general/attachment.js @@ -24,7 +24,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin [ {field: 'state', checkbox: true}, {field: 'id', title: __('Id')}, - {field: 'category', title: __('Category'), formatter: Table.api.formatter.label, searchList: Config.categoryList}, + {field: 'category', title: __('Category'), operate: 'in', formatter: Table.api.formatter.label, searchList: Config.categoryList}, {field: 'admin_id', title: __('Admin_id'), visible: false, addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"}, {field: 'user_id', title: __('User_id'), visible: false, addClass: "selectpage", extend: "data-source='user/user/index' data-field='nickname'"}, {field: 'preview', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false}, @@ -147,7 +147,7 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin [ {field: 'state', checkbox: multiple, visible: multiple, operate: false}, {field: 'id', title: __('Id')}, - {field: 'category', title: __('Category'), formatter: Table.api.formatter.label, searchList: Config.categoryList}, + {field: 'category', title: __('Category'), operate: 'in', formatter: Table.api.formatter.label, searchList: Config.categoryList}, {field: 'admin_id', title: __('Admin_id'), formatter: Table.api.formatter.search, visible: false}, {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search, visible: false}, {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false},