Commit 58c4f0e0 authored by liuyang's avatar liuyang

角色管理功能完成

parent f0f909a8
......@@ -47,8 +47,8 @@
methods: {
// 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
gotoRouteHandle (menu) {
console.log(menu)
console.log(this.dynamicMenuRoutes)
// console.log(menu)
// console.log(this.dynamicMenuRoutes)
var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.id)
if (route.length >= 1) {
this.$router.push({ name: route[0].name })
......
......@@ -4,8 +4,8 @@
:close-on-click-modal="false"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<el-form-item label="角色名称" prop="roleName">
<el-input v-model="dataForm.roleName" placeholder="角色名称"></el-input>
<el-form-item label="角色名称" prop="name">
<el-input v-model="dataForm.name" placeholder="角色名称"></el-input>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="dataForm.remark" placeholder="备注"></el-input>
......@@ -14,7 +14,7 @@
<el-tree
:data="menuList"
:props="menuListTreeProps"
node-key="menuId"
node-key="id"
ref="menuListTree"
:default-expand-all="true"
show-checkbox>
......@@ -41,11 +41,11 @@
},
dataForm: {
id: 0,
roleName: '',
name: '',
remark: ''
},
dataRule: {
roleName: [
name: [
{ required: true, message: '角色名称不能为空', trigger: 'blur' }
]
},
......@@ -56,11 +56,13 @@
init (id) {
this.dataForm.id = id || 0
this.$http({
url: this.$http.adornUrl('/sys/menu/list'),
url: this.$http.adornUrl('/api/sys/menu/list'),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
this.menuList = treeDataTranslate(data, 'menuId')
// console.log(data)
this.menuList = treeDataTranslate(data, 'id')
// console.log(this.menuList)
}).then(() => {
this.visible = true
this.$nextTick(() => {
......@@ -70,18 +72,18 @@
}).then(() => {
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`/sys/role/info/${this.dataForm.id}`),
url: this.$http.adornUrl(`/api/sys/role/info/${this.dataForm.id}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
if (data && data.code === 200) {
this.dataForm.roleName = data.role.roleName
this.dataForm.remark = data.role.remark
var idx = data.role.menuIdList.indexOf(this.tempKey)
if(data && !data.errorCode){
this.dataForm.name = data.name
this.dataForm.remark = data.remark
var idx = data.menuIdList.indexOf(this.tempKey)
if (idx !== -1) {
data.role.menuIdList.splice(idx, data.role.menuIdList.length - idx)
data.menuIdList.splice(idx, data.menuIdList.length - idx)
}
this.$refs.menuListTree.setCheckedKeys(data.role.menuIdList)
this.$refs.menuListTree.setCheckedKeys(data.menuIdList)
}
})
}
......@@ -91,17 +93,25 @@
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
// let checkIds = this.$refs.menuListTree.getCheckedKeys()
// console.log(checkIds)
// let halfIds = this.$refs.menuListTree.getHalfCheckedKeys()
// console.log(halfIds)
// console.log([].concat(this.$refs.menuListTree.getCheckedKeys(), [this.tempKey], this.$refs.menuListTree.getHalfCheckedKeys()))
this.$http({
url: this.$http.adornUrl(`/sys/role/${!this.dataForm.id ? 'save' : 'update'}`),
url: this.$http.adornUrl(`/api/sys/role/${!this.dataForm.id ? 'save' : 'update'}`),
method: 'post',
data: this.$http.adornData({
'roleId': this.dataForm.id || undefined,
'roleName': this.dataForm.roleName,
'id': this.dataForm.id || undefined,
'name': this.dataForm.name,
'remark': this.dataForm.remark,
'menuIdList': [].concat(this.$refs.menuListTree.getCheckedKeys(), [this.tempKey], this.$refs.menuListTree.getHalfCheckedKeys())
})
}).then(({data}) => {
if (data && data.code === 200) {
if(data){
this.$message.error(data.msg)
}else{
this.$message({
message: '操作成功',
type: 'success',
......@@ -111,9 +121,8 @@
this.$emit('refreshDataList')
}
})
} else {
this.$message.error(data.msg)
}
})
}
})
......
......@@ -2,7 +2,7 @@
<div class="mod-role">
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.roleName" placeholder="角色名称" clearable></el-input>
<el-input v-model="dataForm.name" placeholder="角色名称" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">查询</el-button>
......@@ -23,14 +23,14 @@
width="50">
</el-table-column>
<el-table-column
prop="roleId"
prop="id"
header-align="center"
align="center"
width="80"
label="ID">
</el-table-column>
<el-table-column
prop="roleName"
prop="name"
header-align="center"
align="center"
label="角色名称">
......@@ -48,8 +48,8 @@
width="150"
label="操作">
<template slot-scope="scope">
<el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
<el-button v-if="isAuth('sys:role:delete')" type="text" size="small" @click="deleteHandle(scope.row.roleId)">删除</el-button>
<el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
<el-button v-if="isAuth('sys:role:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>
......@@ -73,7 +73,7 @@
data () {
return {
dataForm: {
roleName: ''
name: ''
},
dataList: [],
pageIndex: 1,
......@@ -95,17 +95,17 @@
getDataList () {
this.dataListLoading = true
this.$http({
url: this.$http.adornUrl('/sys/role/list'),
url: this.$http.adornUrl('/api/sys/role/list'),
method: 'get',
params: this.$http.adornParams({
'page': this.pageIndex,
'limit': this.pageSize,
'roleName': this.dataForm.roleName
'pageIndex': this.pageIndex,
'pageSize': this.pageSize,
'name': this.dataForm.name
})
}).then(({data}) => {
if (data && data.code === 200) {
this.dataList = data.page.list
this.totalCount= data.page.totalCount
if (data && !data.errorCode) {
this.dataList = data.result
this.totalCount= data.total
} else {
this.dataList = []
this.totalCount= 0
......@@ -138,7 +138,7 @@
// 删除
deleteHandle (id) {
var ids = id ? [id] : this.dataListSelections.map(item => {
return item.roleId
return item.id
})
this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
confirmButtonText: '确定',
......@@ -146,11 +146,13 @@
type: 'warning'
}).then(() => {
this.$http({
url: this.$http.adornUrl('/sys/role/delete'),
url: this.$http.adornUrl('/api/sys/role/delete'),
method: 'post',
data: this.$http.adornData(ids, false)
}).then(({data}) => {
if (data && data.code === 200) {
if(data){
this.$message.error(data.message)
}else{
this.$message({
message: '操作成功',
type: 'success',
......@@ -159,9 +161,9 @@
this.getDataList()
}
})
} else {
this.$message.error(data.msg)
}
})
}).catch(() => {})
}
......
......@@ -21,7 +21,7 @@
</el-form-item>
<el-form-item label="角色" size="mini" prop="roleIdList">
<el-checkbox-group v-model="dataForm.roleIdList">
<el-checkbox v-for="role in roleList" :key="role.roleId" :label="role.roleId">{{ role.roleName }}</el-checkbox>
<el-checkbox v-for="role in roleList" :key="role.id" :label="role.id">{{ role.name }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="状态" size="mini" prop="status">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment