From 23f2b7e861519ceb86fd5786c26aab4818d1feaa Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 7 Apr 2023 08:13:40 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Repository/Options/Components.php | 7 +- modules/Permissions/.DS_Store | Bin 0 -> 6148 bytes modules/Permissions/Models/Permissions.php | 68 +++++++++--------- modules/Permissions/views/.DS_Store | Bin 0 -> 6148 bytes .../views/permissions/form/create.vue | 2 +- 5 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 modules/Permissions/.DS_Store create mode 100644 modules/Permissions/views/.DS_Store diff --git a/modules/Common/Repository/Options/Components.php b/modules/Common/Repository/Options/Components.php index 4c1d577..03854cd 100644 --- a/modules/Common/Repository/Options/Components.php +++ b/modules/Common/Repository/Options/Components.php @@ -24,8 +24,13 @@ class Components implements OptionInterface $components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue'); foreach ($components as $component) { + $_component = Str::of($component) + ->replace(CatchAdmin::moduleRootPath(), '') + ->explode(DIRECTORY_SEPARATOR); + $_component->shift(2); + $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('/') ]; diff --git a/modules/Permissions/.DS_Store b/modules/Permissions/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fb85148567c9753f4a8657599d3ac7ef027ac82b GIT binary patch literal 6148 zcmeHKL2DC182u(q(oI7l2ZdgQ1+S&XD23uBjV;)NAV&0{60_adE^c>1cGCzUkhA^= z|AJS4iT}luzVDkUY$n#Dh@CIYyxH0JX1;mJ?qrBa^``NCq81SaD2&xDRKE$n&t)wt zwr3ltWQ>H)PEvgur8-(;`ws7bci>-hfS=tuosy=E-qY&y%P)mPl)ax4l6pWf4XHqh zP;wfTo_FSdb@(+p#>i8;pnR37?l{aXFh3%b5sfi^A{n`w&yJ=_Prxl`?2P@x;ce3i zvdAUxlv2zwp*_rV?kX#1j-NvwTIEmWHcMJZavmnF-)@2L9w*i?(lW1dX6EXzk4BorC?|@L{{N*bV0goi^GJ_7{sraQp7PN6!Zz(u+)gLiPxS zeMf?S$K_xjN^8IDPqI{J{Ow*T%IurjwoU}io4I_yYVUw|;13S)`yoVO>{?tJlvf8T zIRXHy=$1g6{|2xowAi({G>AJ0Wu!nORrZLXj2!);<#jDC4H`Kqd-zaxW@S$(N@mCS zq0mWn4f@(U;2l_XV8dLtc>h1X{`|ix@>kvg@4$cMfT|w#k9t^=-CNfd$9rvv@(zWA oc}s&LL1njNY4BFOgCc=@Avb_si%Wy(LHIucVuP=|1AobpQYW literal 0 HcmV?d00001 diff --git a/modules/Permissions/Models/Permissions.php b/modules/Permissions/Models/Permissions.php index 831a2a4..d7101c2 100644 --- a/modules/Permissions/Models/Permissions.php +++ b/modules/Permissions/Models/Permissions.php @@ -9,6 +9,7 @@ use Catch\CatchAdmin; use Catch\Enums\Status; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Facades\DB; use Modules\Permissions\Enums\MenuStatus; use Modules\Permissions\Enums\MenuType; @@ -156,49 +157,50 @@ class Permissions extends Model /** * * @param array $data - * @return bool - * @throws \ReflectionException + * @return mixed */ - public function storeBy(array $data): bool + public function storeBy(array $data): mixed { - if ($data['actions'] ?? false) { - /* @var static $parentMenu */ - $parentMenu = $this->firstBy(value: $data['parent_id'], field: 'id'); + return DB::transaction(function () use ($data){ + if ($data['actions'] ?? false) { + /* @var static $parentMenu */ + $parentMenu = $this->firstBy(value: $data['parent_id'], field: 'id'); - if (! $parentMenu->isMenu()) { - return false; - } - - $actions = CatchAdmin::getControllerActions($parentMenu->module, $parentMenu->permission_mark); - foreach ($actions as $k => $action) { - if (! isset($this->defaultActions[$action])) { - continue; + if (! $parentMenu->isMenu()) { + return false; } - $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); + $actions = CatchAdmin::getControllerActions($parentMenu->module, $parentMenu->permission_mark); + foreach ($actions as $k => $action) { + if (! isset($this->defaultActions[$action])) { + continue; + } + + $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()) { - $parentMenu = $this->firstBy($model->parent_id, 'id'); - return $this->addAction($model, $parentMenu); - } + if ($model->isTopMenu()) { + $data['route'] = '/'.trim($data['route'], '/'); + } - if ($model->isTopMenu()) { - $data['route'] = '/'.trim($data['route'], '/'); - } - - return parent::storeBy($data); + return parent::storeBy($data); + }); } /** diff --git a/modules/Permissions/views/.DS_Store b/modules/Permissions/views/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..56ecc79320e1989dba401159b534556d29eb1446 GIT binary patch literal 6148 zcmeHKL2uJA6n^fyEmeio14z3dMdCU^DQMEfC6w*Jl^{3(DhY`oklIy~(nD1#=k3Sr z$}id98Q-&Av}NqF0}|7F)$`{(zt4$3r*=$4YP`sv5)FtbfHQV_DE?yH&VJ20KC%N; zwvRd0G^Lz0Q0#wDfak7H8Rl$830UC+pq@_ub!LP?l_~Q#}s1bGPI~hu;op;vC z>!ar!Jx{5i3cms@-DatWE!H*|hDtD7{j1ZPGt*@?^H2OMos~sZ4~OTfv(??+*$sAs ze()*&W|ncC)Qf7I%s=qeTVu*}Q%}-&MZTO2?!Pj+P70mREuqMAq0t{07i;%C zZh%L3Y3x7axh{?Vis**1$rKa?L;+FY_6qnFCFtM23t@@^qQD(hfY*l*&KP-Y9NMJ= zg*^fQy9irDoj(?t6MBq1HV)AOQ;rIBROOEt%Fz)IeO~0Tap>rz{NY3SJ1c)eQTFcW zKeXwjB8O6n0;0fG1-9JffcO97o6rAONpd9$hyr&?0o6T -