优化附件未归类功能

pull/342/MERGE
Karson 2021-07-28 09:59:58 +08:00
parent 0c7a4850a2
commit 6178a5c231
3 changed files with 20 additions and 14 deletions

View File

@ -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();
}

View File

@ -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;
}
});
}
}

View File

@ -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},