审查视图

src/views/nav1/DataPerm.vue 14.9 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9 10
<template>
    <div>
        <el-row>
            <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
                <el-form :inline="true">
                    <el-button type="primary" @click="getDataList" icon="el-icon-search">查询</el-button>
                    <el-button type="success" @click="showAddDialog" icon="el-icon-document">新增</el-button>
                </el-form>
            </el-col>
        </el-row>
11 12 13 14 15 16
        <el-table :data="tableList"
                  tooltip-effect="dark"
                  style="border-radius: 10px 10px 0px 0px;line-height: 25px"
                  height="600px"
                  :header-cell-style="{background:'#6F8294',color:'#FFFFFF'}" size="small"
                  border>
朱兆平 authored
17 18
            <el-table-column type="expand">
                <template slot-scope="scope">
19 20
                    <el-form label-position="left" label-width="80px" class="demo-table-expand" :inline="true">
                        <el-form-item label="创建时间" style="margin-left: 20px">
朱兆平 authored
21 22
                            <span>{{ scope.row.create_time }}</span>
                        </el-form-item>
23
                        <el-form-item label="更新时间" style="margin-left: -250px">
朱兆平 authored
24 25
                            <span>{{ scope.row.update_time }}</span>
                        </el-form-item>
26
                        <el-form-item label="创建人" style="margin-left: 20px">
朱兆平 authored
27 28
                            <span>{{ scope.row.create_user }}</span>
                        </el-form-item>
29
                        <el-form-item label="接口描述" style="margin-left: -250px">
朱兆平 authored
30 31
                            <span>{{ scope.row.perm_des }}</span>
                        </el-form-item>
32
                        <el-form-item label="路由ID" style="margin-left: 20px">
朱兆平 authored
33 34
                            <span>{{ scope.row.permission_id }}</span>
                        </el-form-item>
35
                        <el-form-item label="路由地址" style="margin-left: -250px">
朱兆平 authored
36 37
                            <span>{{ scope.row.path }}</span>
                        </el-form-item>
38
                        <el-form-item label="路由名称" style="margin-left: 20px">
朱兆平 authored
39 40
                            <span>{{ scope.row.interface_name }}</span>
                        </el-form-item>
41
                        <el-form-item label="服务名称" style="margin-left: -250px">
朱兆平 authored
42 43
                            <span>{{ scope.row.service_name }}</span>
                        </el-form-item>
44
                        <el-form-item label="列条件" style="margin-left: 20px">
朱兆平 authored
45 46
                            <span>{{ scope.row.cols_list }}</span>
                        </el-form-item>
47
                        <el-form-item label="服务描述" style="margin-left: -250px">
朱兆平 authored
48 49 50 51 52 53
                            <span>{{ scope.row.service_name_des }}</span>
                        </el-form-item>
                    </el-form>
                </template>
            </el-table-column>
            <!-- 表格列配置 -->
54 55 56
            <el-table-column prop="data_perm_id" label="ID" fixed="left"></el-table-column>
            <el-table-column prop="perm_name" label="名称" width="200px"></el-table-column>
            <el-table-column prop="perm_sort" label="排序" width="50px"></el-table-column>
朱兆平 authored
57 58 59 60 61 62 63 64 65 66 67
            <el-table-column prop="row_condition" label="行条件"></el-table-column>
            <el-table-column prop="row_condition_property" label="属性名"></el-table-column>
            <el-table-column prop="cols_list" label="列条件" show-overflow-tooltip></el-table-column>
            <el-table-column prop="perm_keyword" label="关键字"></el-table-column>
            <el-table-column prop="perm_type" label="权限类别"></el-table-column>
            <el-table-column prop="perm_status" label="禁用状态">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="!scope.row.perm_status">正常</el-tag>
                    <el-tag type="danger" v-else>禁用</el-tag>
                </template>
            </el-table-column>
68
            <el-table-column label="操作" width="150" fixed="right">
朱兆平 authored
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
                <template slot-scope="scope">
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.row.data_perm_id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-pagination
                :current-page="form.pageNum"
                :page-sizes="[10, 50, 100, 500]"
                :page-size="form.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        />
        <!-- 新增/编辑对话框 -->
        <el-dialog :title="dialogMap[dialogStatus]" :visible.sync="dialogVisible" width="90%">
            <el-form ref="dataForm" :model="formData" label-width="100px" :inline="true">
<!--                <div>-->
<!--                    &lt;!&ndash; 其他内容 &ndash;&gt;-->
<!--                    <pre>{{ formData }}</pre>-->
<!--                    &lt;!&ndash; 其他内容 &ndash;&gt;-->
<!--                </div>-->
                <el-row>
                    <el-col :span="6" v-for="(item, index) in dynamicFormItems" :key="index">
                        <!-- 根据表格字段动态生成表单项 -->
                        <el-form-item  label=" " :prop="item.prop">
                            <!-- 根据不同的数据类型渲染不同的输入组件 -->
                            <template v-if="item.type === 'text'">
                                <el-input v-model="formData[item.prop]" :placeholder="item.placeholder" :disabled="item.disabled">
                                    <template slot="prepend">{{item.label}}</template>
                                </el-input>
                            </template>
                            <template v-else-if="item.type === 'textarea'">
                                <div class="my-text-area">
                                    <div class="el-input-group__prepend prepand">{{item.label}}</div>
                                    <el-input type="textarea"
                                              v-model="formData[item.prop]"
                                              autosize
                                              style="float: left;width:calc(100% - 110px)">
                                    </el-input>
                                </div>
                            </template>
                            <template v-else-if="item.type === 'select'">
                                <div class="my-text-area">
                                    <div class="el-input-group__prepend prepand">{{item.label}}</div>
                                    <el-select v-model="formData[item.prop]">
                                        <el-option v-for="option in item.options" :key="option.value" :label="option.label" :value="option.value"></el-option>
                                    </el-select>
                                </div>

                            </template>
                            <!-- 其他类型的输入组件可以根据需要添加 -->
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="saveData">保存</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { getList, addDataPerm, deleteDataPerm, updateDataPerm } from '@/api/user/data_perm_api.js'
    import {loginedUserInfo} from "@/api/user.js";
    import jsutil from "@/common/js/util";
    export default {
        data() {
            return {
                tableList: [],
                total: 0,
                form: {
                    pageNum: 1,
                    pageSize: 10
                },
                dialogTitle: '',
                currentUserInfo:{},
                dialogVisible: false,
                formData: {},
                dialogMap: {
                    update: '编辑',
                    create: '新增',
                    find: '查看',
                },
                dialogStatus: 'create',
                dynamicFormItems: [
                    // 直接映射到表单项的字段,todo:增加区域界线,并用横线进行区域录入区分
                    { label: 'ID', prop: 'data_perm_id', type: 'text',placeholder:'' ,disabled:true},
                    { label: '权限名称', prop: 'perm_name', type: 'text',placeholder:'如:用户列表数据权限' },
                    { label: '排序', prop: 'perm_sort', type: 'text' ,placeholder:'如:1'},
                    { label: '行条件', prop: 'row_condition', type: 'text',placeholder:'如:username' },
                    { label: '属性名', prop: 'row_condition_property', type: 'text' ,placeholder:'如:username'},
                    { label: '列条件', prop: 'cols_list', type: 'text' ,placeholder:'如:[username,age,tel]为json格式数组'},
                    { label: '关键字', prop: 'perm_keyword', type: 'text' ,placeholder:'如:用户'},
                    { label: '权限类别', prop: 'perm_type', type: 'text' ,placeholder:''},
                    { label: '路由ID', prop: 'permission_id', type: 'text' ,placeholder:'如: 35'},
                    { label: '路由地址', prop: 'path', type: 'text' ,placeholder:'如:/user/list'},
                    { label: '路由名称', prop: 'interface_name', type: 'text' ,placeholder:'如:用户列表接口'},
                    { label: '服务名称', prop: 'service_name', type: 'text' ,placeholder:'如:user-center'},
                    { label: '服务描述', prop: 'service_name_des', type: 'text' ,placeholder:'如:用户管理服务'},
                    // 需要特殊处理的字段
                    {
                        label: '禁用状态',
                        prop: 'perm_status',
                        type: 'select',
                        placeholder: '请选择状态',
                        options: [
                            { value: false, label: '正常' },
                            { value: true, label: '禁用' }
                        ]
                    },
                    { label: '创建人', prop: 'create_user', type: 'text' ,placeholder: '',disabled:true},
                    { label: '权限描述', prop: 'perm_des', type: 'textarea' }
                    // 其他特殊处理的字段可以在这里添加
                ]
            }
        },
        mounted() {
            this.getDataList();
            this.getCurrentUserInfo();
        },
        methods: {
            getCurrentUserInfo(){
                let userinfo = loginedUserInfo();
                if (!jsutil.checkNull(userinfo) && !jsutil.checkNull(userinfo.username)){
                    this.$message.error("获取用户信息出错")
                }else{
                    this.currentUserInfo = userinfo
                }
            },
            getDataList() {
                getList({
                    pageNum: this.form.pageNum,
                    pageSize: this.form.pageSize
                }).then(res => {
                    this.$message.success('获取列表成功')
                    this.tableList = res.list
                    this.total = res.total
                }).catch(error => {
                    this.$message.error(error)
                })
            },
            handleSizeChange(size) {
                this.form.pageSize = size
                this.getDataList()
            },
            handleCurrentChange(page) {
                this.form.pageNum = page
                this.getDataList()
            },
            showAddDialog() {
                this.dialogStatus= 'create'
                this.formData = {}
                this.formData.create_user = this.currentUserInfo.username
                this.dialogVisible = true
            },
            handleEdit(row) {
                this.dialogStatus= 'update'
                this.formData = { ...row }
                this.dialogVisible = true
            },
            saveData() {
                this.$refs.dataForm.validate(valid => {
                    if (valid) {
                        if (this.formData.data_perm_id) {
                            // 编辑操作
                            updateDataPerm(this.formData.data_perm_id, this.formData)
                                .then(() => {
                                    this.$message.success('编辑成功')
                                    this.dialogVisible = false
                                    this.getDataList()
                                })
                                .catch(error => {
                                    this.$message.error(error)
                                })
                        } else {
                            // 新增操作
                            addDataPerm(this.formData)
                                .then(() => {
                                    this.$message.success('新增成功')
                                    this.dialogVisible = false
                                    this.getDataList()
                                })
                                .catch(error => {
                                    this.$message.error(error)
                                })
                        }
                    }
                })
            },
            handleDelete(id) {
                this.$confirm('确认删除该数据权限吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteDataPerm(id)
                        .then(() => {
                            this.$message.success('删除成功')
                            this.getDataList()
                        })
                        .catch(error => {
                            this.$message.error(error)
                        })
                }).catch(() => {
                    this.$message.info('已取消删除')
                })
            }
        }
    }
</script>

<style>
    .demo-table-expand {
        font-size: 0;
    }
    .demo-table-expand label {
        width: 90px;
        color: #99a9bf;
    }
    .demo-table-expand .el-form-item {
        margin-right: 0;
        margin-bottom: 0;
        width: 50%;
    }
    .my-text-area .el-textarea__inner{
        min-height: 28px;
        height: 28px;
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
    }
</style>

<style scoped>
    .my-text-area .prepand{
        float: left;
        width:89px;
        height: 28px;
        font-size: 12px;
        line-height: 28px;
    }
</style>