From 6178a5c2318e1ed97605461a14e9c9ba4203e488 Mon Sep 17 00:00:00 2001 From: Karson Date: Wed, 28 Jul 2021 09:59:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=99=84=E4=BB=B6=E6=9C=AA?= =?UTF-8?q?=E5=BD=92=E7=B1=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/general/Attachment.php | 3 ++- application/common/model/Attachment.php | 27 +++++++++++-------- .../assets/js/backend/general/attachment.js | 4 +-- 3 files changed, 20 insertions(+), 14 deletions(-) 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},