ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<template>
    <div class="permissions-management-page subpages-containter-box">
        <div class="header-view">
            <el-breadcrumb separator="&gt;">
                <el-breadcrumb-item v-for="(item,index) in breadcrumbs" :key="'breadcrumb-'+index">
                    <span class="title-breadcrumb-item" :class="[(index===breadcrumbs.length-1)?'last':'']" @click="onPageFatherNode(index)">{{item.Name}}</span>
                </el-breadcrumb-item>
            </el-breadcrumb>
            <el-button type="primary" size="small" @click="onNew"><el-icon class="btn-left-icon"><e-icon-plus /></el-icon>新增</el-button>
        </div>
        <div class="list-view">
            <el-table :data="list" border stripe>
                <el-table-column width="70" label="序号" align="center" fixed>
                    <template #default="scope">{{scope.$index+1}}</template>
                </el-table-column>
                <el-table-column label="权限名称">
                    <template #default="scope">
                        <el-link type="primary" v-if="scope.row.hasChildren" @click="onPageNextLevel(scope.row)">{{scope.row.Name}}</el-link>
                        <span v-else>{{scope.row.Name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="OrderSort" label="优先级" />
                <el-table-column prop="Code" label="路由地址" />
                <el-table-column prop="Description" label="权限描述" />
                <el-table-column prop="CreateTime" label="创建时间" width="160" />
                <el-table-column prop="ModifyTime" label="修改时间" width="160" />
                <el-table-column prop="CreateBy" label="创建人" width="100" />
                <el-table-column prop="ModifyBy" label="修改人" width="100" />
                <el-table-column label="操作" width="188" fixed="right" align="center">
                    <template #default="scope">
                        <el-button type="primary" size="small" @click="onOpenModifyModal(scope.row)"><el-icon class="btn-left-icon"><e-icon-edit /></el-icon>编辑</el-button>
                        <el-button type="danger" size="small" @click="onCancel(scope.row.Id)" :disabled="scope.row.hasChildren"><el-icon class="btn-left-icon"><e-icon-delete /></el-icon>删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        
        <form-modal v-model:visible="formVisible" :type="formType" :row="actionRow" :parent="parentNode" @submitCallback="onFormSubmitCallback" />
    </div>
</template>
 
<script>
import FormModal from './compontents/FormModal.vue'
import {Plus,Edit,Delete} from '@element-plus/icons'
export default {
    name:'permissionsManagementPage',
    components:{FormModal,'e-icon-plus':Plus,'e-icon-edit':Edit,'e-icon-delete':Delete},
    data(){
        return {
            rootNode:{
                Id:0,
                Name:'权限根节点'
            },
            breadcrumbs:[],
            queried:{},
            list:[],
            parentNode:{},
            actionRow:{},
            formVisible:false,
            formType:''
        }
    },
    mounted() {
        this.init()
    },
    methods:{
        /* 页面初始化 */
        init(){
            this.setDefault();
            this.newList()
        },
        setDefault(){
            this.breadcrumbs = [{...this.rootNode}]
            this.parentNode = {...this.rootNode}
        },
        /* 表格刷新至首页 */
        newList(needLoading=true){
            this.queried = {f:this.parentNode.Id}
            this.getList(()=>{},needLoading)
        },
        /* 更新数据表 */
        getList(callback,needLoading=true){
            if (needLoading) {
                this.$loading();
            }
            this.getListAjax(this.queried,(f,d)=>{
                if (f) {
                    let tempList = d || []
                    this.list = tempList.map((currentItem)=>{
                        currentItem.CreateTime = this.$utils.project.parseTimeStr(currentItem.CreateTime)
                        currentItem.ModifyTime = this.$utils.project.parseTimeStr(currentItem.ModifyTime)
                        return currentItem
                    })
                }
                if (needLoading) {
                    this.$loading().close();
                }
                callback && callback(f)
            });
        },
        getListAjax(params,callback){
            this.$api.get('GetTreeTable',params,{block:'permission'}).then((d)=>{
                callback && callback(true,d)
            }).catch((err)=>{
                callback && callback(false)
            })
        },
        onPageNextLevel(row){
            let obj = {
                Id:row.Id,
                Name:row.Name
            }
            this.breadcrumbs.push(obj);
            this.parentNode = obj;
            this.newList()
        },
        onPageFatherNode(index){
            if (index+1>=this.breadcrumbs.length) return false
            this.breadcrumbs.splice(index+1,this.breadcrumbs.length-index-1)
            this.parentNode = this.breadcrumbs[index];
            this.newList()
        },
        /* 打开新建弹窗 */
        onNew(){
            this.formType = 'add';
            this.formVisible = true;
        },
        /* 打开编辑弹窗 */
        onOpenModifyModal(obj){
            this.actionRow = obj;
            this.formType = 'modify';
            this.formVisible = true;
        },
        onCancel(id){
            this.$confirm('确定要删除该权限吗?', '删除警示').then(()=>{
                this.dealCancel(id)
            }).catch(()=>{});
        },
        onFormSubmitCallback(needLoading){
            if (this.formType==='add') {
                this.newList(needLoading)
            } else {
                this.getList()
            }
        },
        /* 删除处理事件 */
        dealCancel(id){
            this.$loading();
            this.$api.delete('Delete',{id},{block:'permission'}).then(()=>{
                this.getList(()=>{
                    this.$loading().close();
                },false)
            }).catch((err)=>{
                this.$loading().close();
            })
        }
    }
}
</script>
 
<style scoped lang="scss">
.permissions-management-page{
    &>.header-view{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 12px;
        border-bottom: 1px solid #DCDCDC;
    }
    .title-breadcrumb-item{
        font-size: 16px;
        color: $color-primary;
        cursor: pointer;
        text-decoration: underline;
        font-weight: bold;
        &:hover{
            color: $color-primary-hover;
        }
        &.last{
            cursor: default;
            color: #808080;
            text-decoration:none;
        }
    }
    &>.list-view{
        padding-top: 8px;
    }
}
</style>