Commit 58c4f0e0 authored by liuyang's avatar liuyang

角色管理功能完成

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