chore: 优化权限菜单
This commit is contained in:
@@ -24,8 +24,13 @@ class Components implements OptionInterface
|
|||||||
$components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue');
|
$components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue');
|
||||||
|
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
|
$_component = Str::of($component)
|
||||||
|
->replace(CatchAdmin::moduleRootPath(), '')
|
||||||
|
->explode(DIRECTORY_SEPARATOR);
|
||||||
|
$_component->shift(2);
|
||||||
|
|
||||||
$this->components[] = [
|
$this->components[] = [
|
||||||
'label' => Str::of($component)->explode(DIRECTORY_SEPARATOR)->pop(2)->pop(),
|
'label' => Str::of($_component->implode('/'))->replace('.vue', ''),
|
||||||
|
|
||||||
'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
|
'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
|
||||||
];
|
];
|
||||||
|
BIN
modules/Permissions/.DS_Store
vendored
Normal file
BIN
modules/Permissions/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -9,6 +9,7 @@ use Catch\CatchAdmin;
|
|||||||
use Catch\Enums\Status;
|
use Catch\Enums\Status;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Modules\Permissions\Enums\MenuStatus;
|
use Modules\Permissions\Enums\MenuStatus;
|
||||||
use Modules\Permissions\Enums\MenuType;
|
use Modules\Permissions\Enums\MenuType;
|
||||||
|
|
||||||
@@ -156,49 +157,50 @@ class Permissions extends Model
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return bool
|
* @return mixed
|
||||||
* @throws \ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function storeBy(array $data): bool
|
public function storeBy(array $data): mixed
|
||||||
{
|
{
|
||||||
if ($data['actions'] ?? false) {
|
return DB::transaction(function () use ($data){
|
||||||
/* @var static $parentMenu */
|
if ($data['actions'] ?? false) {
|
||||||
$parentMenu = $this->firstBy(value: $data['parent_id'], field: 'id');
|
/* @var static $parentMenu */
|
||||||
|
$parentMenu = $this->firstBy(value: $data['parent_id'], field: 'id');
|
||||||
|
|
||||||
if (! $parentMenu->isMenu()) {
|
if (! $parentMenu->isMenu()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
$actions = CatchAdmin::getControllerActions($parentMenu->module, $parentMenu->permission_mark);
|
|
||||||
foreach ($actions as $k => $action) {
|
|
||||||
if (! isset($this->defaultActions[$action])) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addAction($this->newInstance([
|
$actions = CatchAdmin::getControllerActions($parentMenu->module, $parentMenu->permission_mark);
|
||||||
'type' => MenuType::Action->value(),
|
foreach ($actions as $k => $action) {
|
||||||
'parent_id' => $data['parent_id'],
|
if (! isset($this->defaultActions[$action])) {
|
||||||
'permission_name' => $this->defaultActions[$action],
|
continue;
|
||||||
'permission_mark' => $action,
|
}
|
||||||
'sort' => $k + 1
|
|
||||||
]), $parentMenu);
|
$this->addAction($this->newInstance([
|
||||||
|
'type' => MenuType::Action->value(),
|
||||||
|
'parent_id' => $data['parent_id'],
|
||||||
|
'permission_name' => $this->defaultActions[$action],
|
||||||
|
'permission_mark' => $action,
|
||||||
|
'sort' => $k + 1
|
||||||
|
]), $parentMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
$model = $this->fill($data);
|
||||||
}
|
|
||||||
|
|
||||||
$model = $this->fill($data);
|
if ($model->isAction()) {
|
||||||
|
$parentMenu = $this->firstBy($model->parent_id, 'id');
|
||||||
|
return $this->addAction($model, $parentMenu);
|
||||||
|
}
|
||||||
|
|
||||||
if ($model->isAction()) {
|
if ($model->isTopMenu()) {
|
||||||
$parentMenu = $this->firstBy($model->parent_id, 'id');
|
$data['route'] = '/'.trim($data['route'], '/');
|
||||||
return $this->addAction($model, $parentMenu);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($model->isTopMenu()) {
|
return parent::storeBy($data);
|
||||||
$data['route'] = '/'.trim($data['route'], '/');
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return parent::storeBy($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
BIN
modules/Permissions/views/.DS_Store
vendored
Normal file
BIN
modules/Permissions/views/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -21,7 +21,7 @@
|
|||||||
<el-input v-model="formData.permission_name" name="permission_name" clearable />
|
<el-input v-model="formData.permission_name" name="permission_name" clearable />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="所属模块" prop="module" :rules="[{ required: true, message: '所属模块必须填写' }]" v-if="!isAction">
|
<el-form-item label="所属模块" prop="module" :rules="[{ required: true, message: '所属模块必须填写' }]" v-if="!isAction">
|
||||||
<Select v-model="formData.module" api="modules" @clear="clearModule" />
|
<Select v-model="formData.module" api="modules" allow-create @clear="clearModule" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="路由Path" prop="route" :rules="[{ required: true, message: '路由Path必须填写' }]" v-if="!isAction">
|
<el-form-item label="路由Path" prop="route" :rules="[{ required: true, message: '路由Path必须填写' }]" v-if="!isAction">
|
||||||
<el-input v-model="formData.route" name="route" clearable />
|
<el-input v-model="formData.route" name="route" clearable />
|
||||||
|
Reference in New Issue
Block a user