Zhouzhendong 5 роки тому
батько
коміт
2884190207

+ 1 - 1
app/Authority.php

@@ -14,7 +14,7 @@ class Authority extends Model
     use ModelLogChanging;
     use ModelLogChanging;
     use SoftDeletes;
     use SoftDeletes;
     use ModelTimeFormat;
     use ModelTimeFormat;
-    protected $fillable = ['name','remark','id_parent','alias_name','type','relevance','permission'];
+    protected $fillable = ['name','remark','parent_id','alias_name','type','relevance','permission'];
     function roles(){
     function roles(){
         return $this->belongsToMany('App\Role','authority_role','id_authority','id_role');
         return $this->belongsToMany('App\Role','authority_role','id_authority','id_role');
     }
     }

+ 4 - 0
database/migrations/2021_05_08_143922_change_authority_table_deleted_at_column.php

@@ -17,6 +17,8 @@ class ChangeAuthorityTableDeletedAtColumn extends Migration
             $table->timestamp("deleted_at")->nullable()->comment("软删除");
             $table->timestamp("deleted_at")->nullable()->comment("软删除");
             $table->dropUnique("authorities_name_unique");
             $table->dropUnique("authorities_name_unique");
             $table->unique("alias_name");
             $table->unique("alias_name");
+            $table->renameColumn("id_parent","parent_id");
+            $table->dropColumn("remark");
         });
         });
 
 
     }
     }
@@ -32,6 +34,8 @@ class ChangeAuthorityTableDeletedAtColumn extends Migration
             $table->dropColumn("deleted_at");
             $table->dropColumn("deleted_at");
             $table->unique("name");
             $table->unique("name");
             $table->dropUnique("authorities_alias_name_unique");
             $table->dropUnique("authorities_alias_name_unique");
+            $table->renameColumn("parent_id","id_parent");
+            $table->string("remark")->nullable()->comment("备注");
         });
         });
     }
     }
 }
 }

+ 36 - 0
resources/views/maintenance/authority/_add.blade.php

@@ -0,0 +1,36 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="addModal">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="font-weight-bold">新增</h5>
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <label class="col-2 offset-1" for="parent_id">父级</label>
+                    <select :disabled="!!authority.id" class="col-5 form-control" id="parent_id" type="text" v-model="menu.parent_id">
+                        <option selected value="">顶级</option>
+                        <option v-for="m in parentList" :value="m.id" v-html="m.name"></option>
+                    </select>
+                </div>
+                <div class="row mt-2">
+                    <label class="col-2 offset-1" for="name"><b class="text-danger">*&nbsp;</b>权限名</label>
+                    <input class="col-5 form-control" :class="errors.name ? 'is-invalid' : ''" id="name" type="text" v-model="authority.name">
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.name">
+                        <strong>@{{ errors.name[0] }}</strong>
+                    </span>
+                </div>
+                <div class="row mt-2">
+                    <label class="col-2 offset-1" for="alias_name"><b class="text-danger">*&nbsp;</b>唯一标识</label>
+                    <input class="col-5 form-control" :class="errors.alias_name ? 'is-invalid' : ''" id="alias_name" type="text" v-model="menu.alias_name">
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.alias_name">
+                        <strong>@{{ errors.alias_name[0] }}</strong>
+                    </span>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" :value="menu.font" @click="submitMenu()">  提  交  </button>
+            </div>
+        </div>
+    </div>
+</div>

+ 36 - 0
resources/views/maintenance/authority/_edit.blade.php

@@ -0,0 +1,36 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="editModal">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="font-weight-bold">修改</h5>
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <label class="col-2 offset-1" for="parent_id">父级</label>
+                    <select :disabled="!!menu.id" class="col-5 form-control" id="parent_id" type="text" v-model="menu.parent_id">
+                        <option selected value="">顶级</option>
+                        <option v-for="m in menuList" :value="m.id" v-html="m.name"></option>
+                    </select>
+                </div>
+                <div class="row mt-2">
+                    <label class="col-2 offset-1" for="name"><b class="text-danger">*&nbsp;</b>菜单名称</label>
+                    <input class="col-5 form-control" :class="errors.name ? 'is-invalid' : ''" id="name" type="text" v-model="menu.name">
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.name">
+                        <strong>@{{ errors.name[0] }}</strong>
+                    </span>
+                </div>
+                <div class="row mt-2">
+                    <label class="col-2 offset-1" for="route"><b class="text-danger">*&nbsp;</b>URL</label>
+                    <input class="col-5 form-control" :class="errors.route ? 'is-invalid' : ''" id="route" type="text" v-model="menu.route">
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.route">
+                        <strong>@{{ errors.route[0] }}</strong>
+                    </span>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" :value="menu.font" @click="submitMenu()">  确  定  </button>
+            </div>
+        </div>
+    </div>
+</div>

+ 28 - 5
resources/views/maintenance/authority/index.blade.php

@@ -3,14 +3,24 @@
 
 
 @section('content')
 @section('content')
     <div class="container-fluid" id="container">
     <div class="container-fluid" id="container">
+        @include('maintenance.authority._add')
+        {{--@include('maintenance.authority._edit')--}}
         <div class="card">
         <div class="card">
             <div class="card-body">
             <div class="card-body">
-                <button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
-                <div class="btn-group pull-right">
-                    <button class="btn border btn-primary" @click="expand(true)">展开全部</button>
-                    <button class="btn border btn-primary" @click="expand(false)">收起全部</button>
+                <div class="w-100 mb-5">
+                    <div class="btn-group pull-left">
+                        <button class="btn btn-outline-primary" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
+                        <button class="btn btn-outline-info" @click="openModal()"><span class="fa fa-edit"></span>&nbsp;修&nbsp;&nbsp;改</button>
+                        <button class="btn btn-outline-danger" @click="openModal()"><span class="fa fa-close"></span>&nbsp;删&nbsp;&nbsp;除</button>
+                    </div>
+                    <div class="btn-group pull-right">
+                        <button class="btn border btn-primary" @click="expand(true)">展开全部</button>
+                        <button class="btn border btn-primary" @click="expand(false)">收起全部</button>
+                    </div>
+                </div>
+                <div class="w-100">
+                    <tree class="offset-2 h5 font-weight-bold" :list="list" :column="'name'"></tree>
                 </div>
                 </div>
-                <tree class="offset-2 h5 font-weight-bold" :list="list" :column="'name'"></tree>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>
@@ -22,15 +32,28 @@
             el:"#container",
             el:"#container",
             data:{
             data:{
                 list:[@foreach($authorities as $authority)@json($authority),@endforeach],
                 list:[@foreach($authorities as $authority)@json($authority),@endforeach],
+                parentList:[],
+                authority:{},
             },
             },
             components:{
             components:{
                 'tree':"url:{{asset("js/vue/tree.vue")}}"
                 'tree':"url:{{asset("js/vue/tree.vue")}}"
             },
             },
+            mounted(){
+                this.parentList = this._mergeArray(this.list);
+            },
             methods:{
             methods:{
                 expand(isExpand){
                 expand(isExpand){
                     if (isExpand) $(".up").slideDown();
                     if (isExpand) $(".up").slideDown();
                     else $(".up").slideUp();
                     else $(".up").slideUp();
                 },
                 },
+                _mergeArray(arr,result = [],before = '&nbsp;'){
+                    if (!arr)return result;
+                    for (let i=0;i<arr.length;i++){
+                        result.push({id:arr[i].id,name:before+'└─'+arr[i].name});
+                        if (arr[i].child && arr[i].child.length>0)this._mergeArray(arr[i].child,result,before+='&nbsp;')
+                    }
+                    return result;
+                },
             },
             },
         })
         })
     </script>
     </script>