diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 21a8754b0d1dde0de9c9daa26e4f3b36a0fe84e9..6c5659d131413afdb0e586adb79046852e207eaf 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,6 +2,7 @@ namespace App\Http; +use App\Http\Middleware\ConvertEmptyStringsToNull; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel @@ -20,7 +21,12 @@ class Kernel extends HttpKernel \App\Http\Middleware\PreventRequestsDuringMaintenance::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, - \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, + + // 空字符串自动转换为null的中间件 + // \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, + + // 自定义的:空字符串自动转换为null的中间件 + ConvertEmptyStringsToNull::class, ]; /** diff --git a/app/Http/Middleware/ConvertEmptyStringsToNull.php b/app/Http/Middleware/ConvertEmptyStringsToNull.php new file mode 100644 index 0000000000000000000000000000000000000000..386c627cefbe52a9b0b37813c14ce682d7f2b59a --- /dev/null +++ b/app/Http/Middleware/ConvertEmptyStringsToNull.php @@ -0,0 +1,32 @@ +getMethod()); + if ( + $method == 'POST' + || + $method == 'PUT' + ){ + // 希望在POST、PUT时,新增与更新数据时,移除[空字符串自动转换为null的中间件]效果。 + }else{ + (new \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull)->handle($request, $next); + } + + return $next($request); + } +} diff --git a/app/Modules/Admin/Entities/Article/Article.php b/app/Modules/Admin/Entities/Article/Article.php index f8c9daaff7e4c502e0091bdb66bd9d4c563f4895..cda0eeea82bc5fd240c9c2eda6991dcd52373ad3 100644 --- a/app/Modules/Admin/Entities/Article/Article.php +++ b/app/Modules/Admin/Entities/Article/Article.php @@ -27,4 +27,9 @@ class Article extends Model { return $this->hasOne(ArticleCategory::class, 'category_id', 'category_id'); } + + public function labels() + { + return $this->belongsToMany(ArticleLabel::class, ArticleWithLabel::class, 'article_id' , 'label_id' , 'article_id', 'label_id')->withPivot(['article_id', 'label_id']); + } } diff --git a/app/Modules/Admin/Entities/Article/ArticleCategory.php b/app/Modules/Admin/Entities/Article/ArticleCategory.php index e9ea8c333451548ea708f3ecf319a9034dd3f516..82ef61fcd7b55d7a22cb868358e45419c32b67bc 100644 --- a/app/Modules/Admin/Entities/Article/ArticleCategory.php +++ b/app/Modules/Admin/Entities/Article/ArticleCategory.php @@ -3,14 +3,85 @@ namespace App\Modules\Admin\Entities\Article; use App\Models\Model; +use Illuminate\Support\Facades\Cache; class ArticleCategory extends Model { protected $primaryKey = 'category_id'; - protected $is_delete = 0; + protected $is_delete = 0; + protected $cache_key = 'article_categories'; public function getSelectLists() { - return list_to_tree($this->orderBy('category_sort', 'ASC')->get()->toArray(), $this->getKeyName()); + return $this->getCacheTree(); + } + + /** + * 删除缓存 + * + * @return bool + */ + public function delCache() + { + Cache::forget($this->cache_key); + return true; + } + + /** + * 获取文章分类的数据缓存 + * + * @param string $get_type + * + * @return mixed + */ + private function getCache(string $get_type = '') + { + return Cache::remember($this->cache_key, 3600, function() use ($get_type) { + $all = $this->orderBy('category_sort', 'ASC')->get()->toArray(); + $tree = list_to_tree($all, $this->getKeyName()); + return compact('all', 'tree'); + }); + } + + /** + * 获取Tree格式化数据 + * + * @return array|mixed + */ + public function getCacheTree() + { + return $this->getCache()['tree'] ?? []; + } + + /** + * 获取所有文章数据 + * + * @return array|mixed + */ + public function getCacheAll() + { + return $this->getCache()['all'] ?? []; + } + + /** + * 获取所有子集的Id集合(包含自己) + * + * @param int $parent_id + * @param array $all + * + * @return array|int[] + */ + public function getChildIds(int $parent_id, array $all = []) + { + $ids = [$parent_id]; + empty($all) && $all = $this->getCacheAll(); + foreach ($all as $key => $value) { + if ( $value['parent_id'] == $parent_id ) { + unset($all[$key]); + $child_ids = $this->getChildIds((int)$value['category_id'], $all); + !empty($child_ids) && $ids = array_merge($ids, $child_ids); + } + } + return $ids; } } diff --git a/app/Modules/Admin/Entities/Article/ArticleWithLabel.php b/app/Modules/Admin/Entities/Article/ArticleWithLabel.php index f92e920e7ca46584153854a4937bb89ade34a43e..2894fcd49c60f1d855b1339564ff3e395d5ebcaf 100644 --- a/app/Modules/Admin/Entities/Article/ArticleWithLabel.php +++ b/app/Modules/Admin/Entities/Article/ArticleWithLabel.php @@ -7,4 +7,5 @@ use App\Models\Model; class ArticleWithLabel extends Model { protected $primaryKey = 'with_id'; + public $timestamps = false; } diff --git a/app/Modules/Admin/Entities/System/Config.php b/app/Modules/Admin/Entities/System/Config.php index 5d3f328f7ddd970a9f05895597b49db31da57c03..91b85bf5631c58a7b960b957c6e5c75d984fc1e0 100644 --- a/app/Modules/Admin/Entities/System/Config.php +++ b/app/Modules/Admin/Entities/System/Config.php @@ -8,4 +8,85 @@ class Config extends Model { protected $primaryKey = 'config_id'; protected $is_delete = 0; + + /** + * 配置同步到config文件中 + * + * @return false|int + */ + public function pushRefreshConfig() + { + $config_data = $this->where('is_check', 1) + ->select('config_value', 'config_name', 'config_type') + ->get() + ->toArray();//字段进行过滤 + $_data = $data_list = []; + array_walk($config_data, function ($value) use (&$data_list) { + /** + * 对于数组格式的处理 + * + * in_array(strtoupper($value['config_name']), ['CONFIG_GROUP_LIST', 'CONFIG_TYPE_LIST', 'MENU_TYPE_LIST']) || + */ + if ($value['config_type'] == 3) { + $value_ary = array_filter(explode('|', str_replace(["\r", "\r\n", "\n"], '|', $value['config_value']))); + foreach ($value_ary as $k => $v) { + if (empty($value['config_name'])) continue; + $array = explode(':', str_replace(["'", '"', "\r", "\r\n", "\n"], '', $v)); + $_data[$array[0]] = $array[1]; + } + $data_list[$value['config_name']] = $_data; + }else{ + /** + * 配置项的值,对于不同字符类型的格式进行处理 + */ + switch ($value['config_type']){ + case 2: // 数字 + $config_value = floatval($value['config_value']); + break; + default: + $config_value = $value['config_value']; + break; + } + /** + * 如果存在某一类的设置项: + * 如:user.login_days、user.pass 这一类,自动设置为数据格式数据,便于使用config的 . 找到数组下坐标 + */ + if (strstr($value['config_name'], '.')){ + $ary = explode('.', $value['config_name']); + if (count($ary) > 2){ + list($key, $val, $third) = $ary; + $data_list[$key][$val][$third] = $config_value; + }else{ + list($key, $val) = $ary; + $data_list[$key][$val] = $config_value; + } + }else{ + $data_list[$value['config_name']] = $config_value; + } + } + }); + // 文件写入 + $res = file_put_contents( config_path() . '/cnpscy.php', 'select()->toArray(); + if (!empty($configs)) { + foreach ($configs as &$v) { + if (in_array($v['config_type'], [4])){ + if (!empty($v['config_extra'])) $v['config_extra'] = config_array_analysis($v['config_extra']); + } + } + } + $configs = array_field_group($configs, 'config_group');//按照配置进行分组 + if (empty($configs[0])) $configs[0] = []; + return $configs; + } } diff --git a/app/Modules/Admin/Http/Controllers/Article/ArticleLabelController.php b/app/Modules/Admin/Http/Controllers/Article/ArticleLabelController.php new file mode 100644 index 0000000000000000000000000000000000000000..7aaf19da1c109545dd37e2061f1e22365281e806 --- /dev/null +++ b/app/Modules/Admin/Http/Controllers/Article/ArticleLabelController.php @@ -0,0 +1,25 @@ +service = $articleLabelService; + } + + public function create(ArticleLabelRequest $request) + { + return $this->createService($request); + } + + public function update(ArticleLabelRequest $request) + { + return $this->updateService($request); + } +} diff --git a/app/Modules/Admin/Http/Controllers/BaseController.php b/app/Modules/Admin/Http/Controllers/BaseController.php index c7209c26f28e7345c0de5370314ce3fff921687b..6006d7ceed566951c17129216cf020d4c7493251 100644 --- a/app/Modules/Admin/Http/Controllers/BaseController.php +++ b/app/Modules/Admin/Http/Controllers/BaseController.php @@ -40,7 +40,11 @@ class BaseController extends Controller if (!isset($this->service)){ return $this->successJson([], '请先设置Service或者重写方法!'); } - return $this->successJson($this->service->detail($request)); + if ($detail = $this->service->detail($request)){ + return $this->successJson($detail); + }else{ + return $this->errorJson('数据不存在!'); + } } /** diff --git a/app/Modules/Admin/Http/Controllers/System/ConfigController.php b/app/Modules/Admin/Http/Controllers/System/ConfigController.php index 78b6ce9b26819738a74b403c16430fe8922c250b..3ab6f3097d634a227194b8f3f49cb08b276030df 100644 --- a/app/Modules/Admin/Http/Controllers/System/ConfigController.php +++ b/app/Modules/Admin/Http/Controllers/System/ConfigController.php @@ -22,4 +22,38 @@ class ConfigController extends BaseController { return $this->updateService($request); } + + public function getConfigGroupType() + { + $config_type_list = $config_group_list = []; + $config_group = cnpscy_config('config_group_list'); + foreach ($config_group as $key => $value){ + $config_group_list[] = [ + 'value' => $key, + 'name' => $value, + ]; + } + $config_type = cnpscy_config('config_type_list'); + foreach ($config_type as $key => $value){ + $config_type_list[] = [ + 'value' => $key, + 'name' => $value, + ]; + } + return $this->successJson([ + 'config_group_list' => $config_group_list, + 'config_type_list' => $config_type_list, + ]); + } + + /** + * 同步配置 + * + * @return \Illuminate\Http\JsonResponse + */ + public function pushRefreshConfig() + { + $this->service->pushRefreshConfig(); + return $this->successJson([], '配置文件已同步成功!'); + } } diff --git a/app/Modules/Admin/Http/Requests/Article/ArticleLabelRequest.php b/app/Modules/Admin/Http/Requests/Article/ArticleLabelRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..cc7dd143fe68ae64de3b717658d045c0480ea250 --- /dev/null +++ b/app/Modules/Admin/Http/Requests/Article/ArticleLabelRequest.php @@ -0,0 +1,39 @@ +instance = ArticleLabel::getInstance(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'label_name' => [ + 'required', + 'max:256', + 'unique:' . $this->instance->getTable() . ',label_name' . $this->validate_id + ], + ]; + } + + public function messages() + { + return [ + 'label_name.required' => '请输入标签名称!', + 'label_name.max' => '标签名称字数不可超过 256!', + 'label_name.unique' => '标签名称已存在,请更换!', + ]; + } +} diff --git a/app/Modules/Admin/Resources/vue-element-admin/api/article_labels.js b/app/Modules/Admin/Resources/vue-element-admin/api/article_labels.js new file mode 100644 index 0000000000000000000000000000000000000000..ebc012661ce2950d43e8bbc45000299467ee964d --- /dev/null +++ b/app/Modules/Admin/Resources/vue-element-admin/api/article_labels.js @@ -0,0 +1,41 @@ +import request from '@/utils/request' + +export function getArticleLabelSelect(params) { + return request({ + url: '/article_labels/getSelectLists', + method: 'get', + params + }); +} + +export function getList(params) { + return request({ + url: '/article_labels', + method: 'get', + params + }); +} + +export function create(data) { + return request({ + url: '/article_labels/create', + method: 'post', + data + }); +} + +export function update(data) { + return request({ + url: '/article_labels/update', + method: 'put', + data + }); +} + +export function setDel(data) { + return request({ + url: '/article_labels/delete', + method: 'delete', + data + }); +} diff --git a/app/Modules/Admin/Resources/vue-element-admin/api/configs.js b/app/Modules/Admin/Resources/vue-element-admin/api/configs.js index 13371c1c16a7f87fa02d8a0c2bbd9c809f87c10c..4a9b2fa72b387da34999ff24cbcffc0fe0221629 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/api/configs.js +++ b/app/Modules/Admin/Resources/vue-element-admin/api/configs.js @@ -8,6 +8,14 @@ export function getList(query) { }) } +// 获取配置分组与配置类型 +export function getConfigGroupType() { + return request({ + url: '/configs/getConfigGroupType', + method: 'get', + }) +} + export function detail(id) { return request({ url: '/configs/detail', @@ -47,3 +55,11 @@ export function changeFiledStatus(data) { data }) } + +// 同步配置文件 +export function pushRefreshConfig() { + return request({ + url: '/configs/pushRefreshConfig', + method: 'put', + }) +} diff --git a/app/Modules/Admin/Resources/vue-element-admin/api/friendlinks.js b/app/Modules/Admin/Resources/vue-element-admin/api/friendlinks.js index d4804eeea2af2255d2f2984b7453c82e178ca9ce..7635f0979f31f71060e0b9c3ec9cba04de9cf014 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/api/friendlinks.js +++ b/app/Modules/Admin/Resources/vue-element-admin/api/friendlinks.js @@ -17,7 +17,6 @@ export function create(data) { } export function update(data) { - console.log(data) return request({ url: '/friendlinks/update', method: 'put', diff --git a/app/Modules/Admin/Resources/vue-element-admin/components/PanThumb/index.vue b/app/Modules/Admin/Resources/vue-element-admin/components/PanThumb/index.vue index eca3910c0e38abe79e1f16e70b1231ecc6cb4b8f..16b18fa7773c483359ed0e3f9786690c79f36b7a 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/components/PanThumb/index.vue +++ b/app/Modules/Admin/Resources/vue-element-admin/components/PanThumb/index.vue @@ -1,146 +1,146 @@ diff --git a/app/Modules/Admin/Resources/vue-element-admin/components/ThemePicker/index.vue b/app/Modules/Admin/Resources/vue-element-admin/components/ThemePicker/index.vue index 3879c5ad027dbb259063410ecde826529d26b43b..b0df471ca48ccdbff699589ba864532eb9e819fc 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/components/ThemePicker/index.vue +++ b/app/Modules/Admin/Resources/vue-element-admin/components/ThemePicker/index.vue @@ -35,7 +35,6 @@ export default { if (typeof val !== 'string') return const themeCluster = this.getThemeCluster(val.replace('#', '')) const originalCluster = this.getThemeCluster(oldVal.replace('#', '')) - console.log(themeCluster, originalCluster) const $message = this.$message({ message: ' Compiling the theme', diff --git a/app/Modules/Admin/Resources/vue-element-admin/components/Uploads/image/index.vue b/app/Modules/Admin/Resources/vue-element-admin/components/Uploads/image/index.vue index aef2da5bfa52010e4985792459acf9fa697cbb27..c9c339d17a498751abb010a883bc406f5c5fea94 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/components/Uploads/image/index.vue +++ b/app/Modules/Admin/Resources/vue-element-admin/components/Uploads/image/index.vue @@ -872,8 +872,6 @@ } } client.upload.addEventListener('progress', uploadProgress, false) // 监听进度 - // console.log(headers) - // console.log(getToken()) // 设置header if (typeof headers === 'object' && headers) { Object.keys(headers).forEach((k) => { @@ -881,7 +879,6 @@ }) } headers['Authorization'] = getToken(); - // console.log(headers) client.send(fmData) }).then( // 上传成功 diff --git a/app/Modules/Admin/Resources/vue-element-admin/lang/en.js b/app/Modules/Admin/Resources/vue-element-admin/lang/en.js index 9598bf95d7b9b243c26d52cb866b64c6442121ba..1273e0b2094df00357767a51952b3db03c04248b 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/lang/en.js +++ b/app/Modules/Admin/Resources/vue-element-admin/lang/en.js @@ -3,8 +3,11 @@ export default { admin: 'Admin', banner: 'Banner', article: 'Article', + friendlinks: 'Friendly link', number: 'Number', route: { + articleLabels: '文章标签', + articleLabelDetail: '标签详情', systemSettings: 'System settings', bannerManage: 'Banner Manage', permissionManage: 'Permission Manage', diff --git a/app/Modules/Admin/Resources/vue-element-admin/lang/es.js b/app/Modules/Admin/Resources/vue-element-admin/lang/es.js index cab54ec4829638fdffa586909912b83cb28ccf81..3532a333a147684f7575465e5dc4fabe57957e2a 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/lang/es.js +++ b/app/Modules/Admin/Resources/vue-element-admin/lang/es.js @@ -3,8 +3,11 @@ export default { admin: 'Administrador', banner: 'Banner', article: 'Artículo', + friendlinks: '友情链接', number: 'Cantidad', route: { + articleLabels: '文章标签', + articleLabelDetail: '标签详情', systemSettings: 'Configuración del sistema', bannerManage: 'Gestión de Banner', permissionManage: 'Gestión de permisos', diff --git a/app/Modules/Admin/Resources/vue-element-admin/lang/ja.js b/app/Modules/Admin/Resources/vue-element-admin/lang/ja.js index bbd4fb4d4c33181bb5269c42f9daff2b1b173d87..7629bc632a60008fe59db88beaaebe3069722609 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/lang/ja.js +++ b/app/Modules/Admin/Resources/vue-element-admin/lang/ja.js @@ -3,8 +3,11 @@ export default { admin: '管理者', banner: 'Banner', article: '文章', + friendlinks: '友情链接', number: '数', route: { + articleLabels: '文章标签', + articleLabelDetail: '标签详情', systemSettings: 'システム設定', bannerManage: 'Banner管理', permissionManage: '権限管理', diff --git a/app/Modules/Admin/Resources/vue-element-admin/lang/zh.js b/app/Modules/Admin/Resources/vue-element-admin/lang/zh.js index afbb5830e64f046dd718fd6ab4f6d96a9aac4a63..99d2ecb19a51e61f5197044570e08e2a1b55c894 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/lang/zh.js +++ b/app/Modules/Admin/Resources/vue-element-admin/lang/zh.js @@ -2,8 +2,11 @@ export default { admin: '管理员', banner: 'Banner', article: '文章', + friendlinks: '友情链接', number: '数量', route: { + articleLabels: '文章标签', + articleLabelDetail: '标签详情', systemSettings: '系统设置', bannerManage: 'Banner管理', permissionManage: '权限管理', diff --git a/app/Modules/Admin/Resources/vue-element-admin/layout/components/Navbar.vue b/app/Modules/Admin/Resources/vue-element-admin/layout/components/Navbar.vue index 0ec8f525c77757f3d69ee4f851863c35074bee77..f90cac1e652e080b1e8e40183f86bac5c5cc44dd 100644 --- a/app/Modules/Admin/Resources/vue-element-admin/layout/components/Navbar.vue +++ b/app/Modules/Admin/Resources/vue-element-admin/layout/components/Navbar.vue @@ -7,7 +7,6 @@