|
@@ -1,15 +1,332 @@
|
|
|
<template>
|
|
|
<div class="sy-content">
|
|
|
- Role
|
|
|
+ <el-row>
|
|
|
+ <el-col>
|
|
|
+ <!-- 搜索信息 -->
|
|
|
+ <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
|
|
+ <el-form-item label="角色名称" prop="roleName">
|
|
|
+ <el-input
|
|
|
+ v-model="queryParams.roleName"
|
|
|
+ placeholder="请输入角色名称"
|
|
|
+ clearable
|
|
|
+ style="width: 150px"
|
|
|
+ @keyup.enter.native="handleQuery"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="权限字符" prop="roleCode">
|
|
|
+ <el-input
|
|
|
+ v-model="queryParams.roleCode"
|
|
|
+ placeholder="请输入权限字符"
|
|
|
+ clearable
|
|
|
+ style="width: 150px"
|
|
|
+ @keyup.enter.native="handleQuery"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
|
+ <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <!-- 操作按钮 -->
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ icon="el-icon-plus"
|
|
|
+ size="mini"
|
|
|
+ @click="handleAdd"
|
|
|
+ >新增</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5" style="margin-left: 15px;">
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ plain
|
|
|
+ icon="el-icon-delete"
|
|
|
+ size="mini"
|
|
|
+ :disabled="multiple"
|
|
|
+ @click="handleDelete"
|
|
|
+ >删除</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <!-- 表格数据信息 -->
|
|
|
+ <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
|
|
|
+ <el-table-column type="selection" width="50" align="center"/>
|
|
|
+ <el-table-column label="角色编号" align="center" key="id" prop="id" v-if="false"/>
|
|
|
+ <el-table-column label="角色名称" align="center" key="roleName" prop="roleName" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="权限字符" align="center" key="roleCode" prop="roleCode" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column
|
|
|
+ label="操作"
|
|
|
+ align="center"
|
|
|
+ width="350"
|
|
|
+ class-name="small-padding fixed-width"
|
|
|
+ >
|
|
|
+ <template slot-scope="scope" v-if="scope.row.userId !== 1">
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-edit"
|
|
|
+ @click="handleUpdate(scope.row)"
|
|
|
+ >修改</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ @click="handleDelete(scope.row)"
|
|
|
+ >删除</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-user"
|
|
|
+ @click="handleAuthUser(scope.row)"
|
|
|
+ >分配用户</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-menu"
|
|
|
+ @click="handleAuthMenu(scope.row)"
|
|
|
+ >分配菜单</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <!-- 分页信息 -->
|
|
|
+ <pagination
|
|
|
+ v-show="total > 0"
|
|
|
+ :total="total"
|
|
|
+ :page.sync="queryParams.page"
|
|
|
+ :limit.sync="queryParams.limit"
|
|
|
+ align="right"
|
|
|
+ @pagination="getRoleList"
|
|
|
+ />
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <!-- 添加或修改对话框 -->
|
|
|
+ <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
|
|
+ <el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
|
+ <el-row>
|
|
|
+ <el-col>
|
|
|
+ <el-form-item label="角色名称" prop="roleName">
|
|
|
+ <el-input v-model="form.roleName" placeholder="请输入角色名称" maxlength="20" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-col>
|
|
|
+ <el-form-item label="权限字符" prop="roleCode">
|
|
|
+ <el-input v-model="form.roleCode" placeholder="请输入权限字符" maxlength="20" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
+ <el-button @click="cancel">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getRoleList, addRoleInfo, updateRoleInfo, delRoleById } from '@/api/system/role'
|
|
|
+
|
|
|
export default {
|
|
|
- name: 'Index'
|
|
|
+ name: 'Index',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ // 遮罩层
|
|
|
+ loading: true,
|
|
|
+ // 显示搜索条件
|
|
|
+ showSearch: true,
|
|
|
+ // 非多个禁用
|
|
|
+ multiple: true,
|
|
|
+ // 查询参数
|
|
|
+ queryParams: {
|
|
|
+ page: 1,
|
|
|
+ limit: 10,
|
|
|
+ roleName: undefined,
|
|
|
+ roleCode: undefined
|
|
|
+ },
|
|
|
+ // 总条数
|
|
|
+ total: 0,
|
|
|
+ // 用户表格数据
|
|
|
+ roleList: null,
|
|
|
+ // 弹出层标题
|
|
|
+ title: '',
|
|
|
+ // 是否显示弹出层
|
|
|
+ open: false,
|
|
|
+ // 表单参数
|
|
|
+ form: {},
|
|
|
+ // 表单校验
|
|
|
+ rules: {
|
|
|
+ roleName: [
|
|
|
+ { required: true, message: '角色名称不能为空', trigger: 'blur' },
|
|
|
+ { min: 2, max: 20, message: '角色名称长度必须介于 2 和 20 之间', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ roleCode: [
|
|
|
+ { required: true, message: '权限字符不能为空', trigger: 'blur' },
|
|
|
+ { min: 5, max: 20, message: '权限字符长度必须介于 5 和 20 之间', trigger: 'blur' },
|
|
|
+ { validator: this.testKey }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getRoleList()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ /** 表单验证判断只能输入数字和字母 */
|
|
|
+ testKey(rule, value, callback) {
|
|
|
+ const key = /^[\a-\z\A-\Z0-9]+$/
|
|
|
+ if (!key.test(value)) {
|
|
|
+ callback(new Error('只能输入数字和字母'))
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /** 搜索按钮操作 */
|
|
|
+ handleQuery() {
|
|
|
+ this.queryParams.page = 1
|
|
|
+ this.getRoleList()
|
|
|
+ },
|
|
|
+ /** 重置按钮操作 */
|
|
|
+ resetQuery() {
|
|
|
+ this.$refs['queryForm'].resetFields()
|
|
|
+ this.handleQuery()
|
|
|
+ },
|
|
|
+ /** 多选框选中数据 */
|
|
|
+ handleSelectionChange(selection) {
|
|
|
+ this.ids = selection.map(item => item.userId)
|
|
|
+ this.multiple = !selection.length
|
|
|
+ },
|
|
|
+ /** 查询用户列表 */
|
|
|
+ getRoleList() {
|
|
|
+ this.loading = true
|
|
|
+ getRoleList(this.queryParams).then(response => {
|
|
|
+ const data = response.data
|
|
|
+ this.roleList = data.roleList
|
|
|
+ this.total = data.count
|
|
|
+ this.loading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 删除按钮操作 */
|
|
|
+ handleDelete(row) {
|
|
|
+ const roleId = row.id
|
|
|
+ if (!roleId) {
|
|
|
+ const roleIdList = this.ids
|
|
|
+ if (!roleIdList || roleIdList.length === 0) {
|
|
|
+ this.$message({
|
|
|
+ message: '请选择您要删除的角色',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.$confirm('您确定要删除选中的角色吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ for (const i in roleIdList) {
|
|
|
+ const id = roleIdList[i]
|
|
|
+ delRoleById({
|
|
|
+ 'roleId': id
|
|
|
+ }).then(response => {
|
|
|
+ this.getRoleList()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }).catch(() => {
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.$confirm('您确定要删除角色【' + row.userName + '】吗?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ delRoleById({
|
|
|
+ roleId
|
|
|
+ }).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: '删除成功',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.getRoleList()
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 修改按钮操作 */
|
|
|
+ handleUpdate(row) {
|
|
|
+ this.reset()
|
|
|
+ this.form = {
|
|
|
+ id: row.id,
|
|
|
+ roleName: row.roleName,
|
|
|
+ roleCode: row.roleCode
|
|
|
+ }
|
|
|
+ this.open = true
|
|
|
+ this.title = '修改角色'
|
|
|
+ },
|
|
|
+ /** 分配角色人员 */
|
|
|
+ handleAuthUser(row) {
|
|
|
+ const roleId = row.id
|
|
|
+ console.log(row)
|
|
|
+ console.log('/system/role/user-auth/role/' + roleId)
|
|
|
+ this.$router.push('/system/role/user-auth/role/' + roleId)
|
|
|
+ },
|
|
|
+ /** 分配角色菜单 */
|
|
|
+ handleAuthMenu(row) {
|
|
|
+ },
|
|
|
+ /** 新增按钮操作 */
|
|
|
+ handleAdd() {
|
|
|
+ this.reset()
|
|
|
+ this.open = true
|
|
|
+ this.title = '添加角色'
|
|
|
+ },
|
|
|
+ /** 表单提交 */
|
|
|
+ submitForm() {
|
|
|
+ this.$refs['form'].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.form.id !== undefined) {
|
|
|
+ updateRoleInfo(this.form).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: '修改成功',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.open = false
|
|
|
+ this.getRoleList()
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ addRoleInfo(this.form).then(response => {
|
|
|
+ this.$message({
|
|
|
+ message: '新增成功',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.open = false
|
|
|
+ this.getRoleList()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /** 表单重置 */
|
|
|
+ cancel() {
|
|
|
+ this.open = false
|
|
|
+ this.reset()
|
|
|
+ },
|
|
|
+ /** 表单重置 */
|
|
|
+ reset() {
|
|
|
+ this.form = {
|
|
|
+ id: undefined,
|
|
|
+ roleName: undefined,
|
|
|
+ roleCode: undefined
|
|
|
+ }
|
|
|
+ if (this.$refs['form']) {
|
|
|
+ this.$refs['form'].resetFields()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style scoped>
|
|
|
-
|
|
|
+<style rel="stylesheet/scss" lang="scss">
|
|
|
</style>
|