Commit 25c87351 authored by cx49085's avatar cx49085
Browse files

修改路由备注样式,增加角色表单校验

parent 098c6731
...@@ -4,4 +4,5 @@ ENV = 'development' ...@@ -4,4 +4,5 @@ ENV = 'development'
# base api 后端url # base api 后端url
#VUE_APP_BASE_API = 'http://192.168.10.107:7080' #VUE_APP_BASE_API = 'http://192.168.10.107:7080'
VUE_APP_BASE_API = 'http://192.168.10.109:11523' VUE_APP_BASE_API = 'http://192.168.10.109:11523'
#'http://www.aishuhong.com:11549/prod-api/'
#VUE_APP_BASE_API = 'http://192.168.31.100:7081' #VUE_APP_BASE_API = 'http://192.168.31.100:7081'
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<el-table-column align="center" label="序号" width="80"> <el-table-column align="center" label="序号" width="80">
<template slot-scope="scope"> <template slot-scope="scope">
{{ {{
(roleQuery.pageNum - 1) * roleQuery.pageSize + scope.$index + 1 (roleQuery.pageNum - 1) * roleQuery.pageSize + scope.$index + 1
}} }}
</template> </template>
</el-table-column> </el-table-column>
...@@ -22,51 +22,36 @@ ...@@ -22,51 +22,36 @@
</el-table-column> </el-table-column>
<el-table-column align="center" label="操作"> <el-table-column align="center" label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="primary" size="small" @click="handleEdit(scope)" >编辑角色信息和分配角色路由</el-button> <el-button type="primary" size="small" @click="handleEdit(scope)">编辑角色信息和分配角色路由</el-button>
<el-button type="danger" size="small" @click="handleDelete(scope)" >删除角色</el-button> <el-button type="danger" size="small" @click="handleDelete(scope)">删除角色</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<div class="footer"> <div class="footer">
<el-pagination <el-pagination :current-page.sync="roleQuery.pageNum" :page-size="roleQuery.pageSize"
:current-page.sync="roleQuery.pageNum" layout="total, prev, pager, next" :total="total" @current-change="handleCurrentChange" />
:page-size="roleQuery.pageSize"
layout="total, prev, pager, next"
:total="total"
@current-change="handleCurrentChange"
/>
</div> </div>
<el-dialog :visible.sync="dialogVisible" :title="dialogType"> <el-dialog :visible.sync="dialogVisible" :title="dialogType">
<el-form :model="role" label-width="80px" label-position="left"> <el-form :model="role" label-width="80px" label-position="left" :rules="rules">
<el-form-item label="角色名称"> <el-form-item label="角色名称" prop="rlName">
<el-input v-model="role.rlName" placeholder="角色名称" /> <el-input v-model="role.rlName" placeholder="角色名称" />
</el-form-item> </el-form-item>
<el-form-item label="角色描述"> <el-form-item label="角色描述" prop="rlDesc">
<el-input <el-input v-model="role.rlDesc" :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" placeholder="角色描述" />
v-model="role.rlDesc"
:autosize="{ minRows: 2, maxRows: 4}"
type="textarea"
placeholder="角色描述"
/>
</el-form-item> </el-form-item>
<el-form-item label="路由树"> <el-form-item label="路由树">
<el-tree <el-tree ref="tree" :check-strictly="true" :data="routesData" @check="checkTree" show-checkbox default-expand-all node-key="id">
ref="tree" <span slot-scope="{data}">
:check-strictly="checkStrictly" {{data.title}}
:data="routesData" <span class="explain-text">{{ data.explain }}</span>
:props="defaultProps" </span>
@check="checkTree" </el-tree>
show-checkbox
default-expand-all
node-key="id"
class="permission-tree"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div style="text-align:right;"> <div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button> <el-button type="danger" @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="confirmRole">提交</el-button> <el-button type="primary" @click="confirmRole">提交</el-button>
</div> </div>
</el-dialog> </el-dialog>
...@@ -78,20 +63,20 @@ ...@@ -78,20 +63,20 @@
<script> <script>
import path from 'path' import path from 'path'
import { deepClone } from '@/utils' import { deepClone } from '@/utils'
import { getRoles,addRole,deleteRole, updateRole} from '@/api/role' import { getRoles, addRole, deleteRole, updateRole } from '@/api/role'
import { getRoutes} from '@/api/auth' import { getRoutes } from '@/api/auth'
const defaultRole = { const defaultRole = {
rlId: 0, rlId: 0,
rlName: '', rlName: '',
rlDesc: '', rlDesc: '',
routes: [], routes: [],
companyId:'', companyId: '',
} }
export default { export default {
data(){ data() {
return{ return {
roleQuery: { roleQuery: {
companyId: null, companyId: null,
pageNum: 1, pageNum: 1,
...@@ -99,54 +84,53 @@ export default { ...@@ -99,54 +84,53 @@ export default {
}, },
total: 0, total: 0,
role: Object.assign({}, defaultRole), role: Object.assign({}, defaultRole),
rolesList:[], rolesList: [],
routes:null, routes: null,
dialogType:"新增角色", dialogType: "新增角色",
dialogVisible:false, dialogVisible: false,
companyId: '',
checkStrictly: true,// 父子节点 checkbox的选择是否关联 rules: {
defaultProps: { // 角色树 rlName: [{ required: true, message: "角色名称"}],
children: 'children', rlDesc: [{ required: true, message: "角色描述" }]
label: 'title' }
},
companyId:'',
} }
}, },
created() { created() {
this.roleQuery.companyId = this.$store.getters.companyId this.roleQuery.companyId = this.$store.getters.companyId
this.companyId=this.$store.getters.companyId; this.companyId = this.$store.getters.companyId;
this.getRoutes() this.getRoutes()
this.getRoles() this.getRoles()
}, },
computed: { computed: {
routesData() { routesData() {
console.log(this.routes)
return this.routes return this.routes
}, },
}, },
methods:{ methods: {
//handleCurrentChange //handleCurrentChange
handleCurrentChange(val){ handleCurrentChange(val) {
this.roleQuery.pageNum = val this.roleQuery.pageNum = val
this.getRoles() this.getRoles()
}, },
//获取角色 //获取角色
getRoles() { getRoles() {
getRoles (this.roleQuery).then((res)=>{ getRoles(this.roleQuery).then((res) => {
if(res.status == "success"){ if (res.status == "success") {
this.rolesList = res.data.list this.rolesList = res.data.list
this.total = res.data.total this.total = res.data.total
}else{ } else {
this.$message.error(res.data) this.$message.error(res.data)
} }
}).catch((error)=>{ }).catch((error) => {
this.$message.error("查询数据失败") this.$message.error("查询数据失败")
}) })
}, },
//获取路由 //获取路由
getRoutes() { getRoutes() {
getRoutes().then((res)=>{ getRoutes().then((res) => {
if(res.status == "success"){ if (res.status == "success") {
this.serviceRoutes = res.data this.serviceRoutes = res.data
this.routes = this.generateRoutes(res.data) this.routes = this.generateRoutes(res.data)
} }
...@@ -155,45 +139,47 @@ export default { ...@@ -155,45 +139,47 @@ export default {
//处理路由数据 //处理路由数据
generateRoutes(routes, basePath = '/') { generateRoutes(routes, basePath = '/') {
const res = [] const res = []
console.log(routes) // console.log(routes)
if(this.$store.getters.roles[0] != 1){ if (this.$store.getters.roles[0] != 1) {
//不是超管 //不是超管
for (let route of routes) { for (let route of routes) {
if(route.id != 1 && route.id != 113){ if (route.id != 1 && route.id != 113) {
const data = { const data = {
path: path.resolve(basePath, route.path), path: path.resolve(basePath, route.path),
title: route.meta && (route.menuExplain ? `${route.meta.title}${route.menuExplain})`: route.meta.title), title: route.meta && route.meta.title,
id: route.id explain: route.menuExplain,
} id: route.id
if (route.children.length>0) {
data.children = this.generateRoutes(route.children, data.path)
}
res.push(data)
}
} }
}else{ if (route.children.length > 0) {
//是超管 data.children = this.generateRoutes(route.children, data.path)
for (let route of routes) {
const data = {
path: path.resolve(basePath, route.path),
title: route.meta && (route.menuExplain ? `${route.meta.title}${route.menuExplain})`: route.meta.title),
id: route.id
}
if (route.children.length>0) {
data.children = this.generateRoutes(route.children, data.path)
}
res.push(data)
} }
res.push(data)
}
}
} else {
//是超管
for (let route of routes) {
const data = {
path: path.resolve(basePath, route.path),
title: route.meta && route.meta.title,
explain: route.menuExplain,
id: route.id
}
if (route.children.length > 0) {
data.children = this.generateRoutes(route.children, data.path)
}
res.push(data)
} }
}
return res return res
}, },
//新增角色 //新增角色
handleAddRole(){ handleAddRole() {
this.role = Object.assign({}, defaultRole) this.role = Object.assign({}, defaultRole)
this.role.companyId = this.$store.getters.companyId this.role.companyId = this.$store.getters.companyId
if (this.$refs.tree) { if (this.$refs.tree) {
...@@ -203,10 +189,10 @@ export default { ...@@ -203,10 +189,10 @@ export default {
this.dialogVisible = true this.dialogVisible = true
}, },
//编辑角色 //编辑角色
handleEdit(scope){ handleEdit(scope) {
this.dialogType = '编辑角色' this.dialogType = '编辑角色'
this.dialogVisible = true this.dialogVisible = true
console.log(scope) // console.log(scope)
this.role = deepClone(scope.row) this.role = deepClone(scope.row)
this.$nextTick(() => { this.$nextTick(() => {
const selectedKeys = this.generateArr(this.role.routes) const selectedKeys = this.generateArr(this.role.routes)
...@@ -221,70 +207,70 @@ export default { ...@@ -221,70 +207,70 @@ export default {
if (temp.length > 0) { if (temp.length > 0) {
data = [...data, ...temp] data = [...data, ...temp]
} }
}else{ } else {
data.push(route.id) data.push(route.id)
} }
}) })
return data return data
}, },
//删除角色 //删除角色
handleDelete({ $index, row }){ handleDelete({ $index, row }) {
this.$confirm('确定要删除该角色吗?', 'Warning', { this.$confirm('确定要删除该角色吗?', 'Warning', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}) })
.then(() => { .then(() => {
deleteRole(row.rlId).then((res)=>{ deleteRole(row.rlId).then((res) => {
if(res.status == 'success'){ if (res.status == 'success') {
this.$message.success("删除成功") this.$message.success("删除成功")
this.rolesList.splice($index, 1) this.rolesList.splice($index, 1)
}else{ } else {
this.$message.error(res.data) this.$message.error(res.data)
} }
}).catch((error)=>{ }).catch((error) => {
this.$message.error("删除失败") this.$message.error("删除失败")
}) })
}) })
.catch(err => { console.error(err) }) .catch(err => { console.error(err) })
}, },
//提交 //提交
confirmRole(){ confirmRole() {
const isEdit = this.dialogType === '编辑角色' const isEdit = this.dialogType === '编辑角色'
// 获取选中权限树id // 获取选中权限树id
const checkedKeys = this.$refs.tree.getCheckedKeys() const checkedKeys = this.$refs.tree.getCheckedKeys()
if (checkedKeys){ if (checkedKeys) {
let routes = [] let routes = []
checkedKeys.forEach(key => { checkedKeys.forEach(key => {
let obj = {id:key} let obj = { id: key }
routes.push(obj) routes.push(obj)
}) })
// 将menu对象数组,赋给要添加的role // 将menu对象数组,赋给要添加的role
this.role.routes = routes this.role.routes = routes
} }
if (isEdit) { // 修改角色 if (isEdit) { // 修改角色
updateRole(this.role).then((res)=>{ updateRole(this.role).then((res) => {
if(res.status=="success"){ if (res.status == "success") {
this.$message.success("修改成功") this.$message.success("修改成功")
this.getRoles() this.getRoles()
}else{ } else {
this.$message.error(res.data) this.$message.error(res.data)
} }
}).catch((error)=>{ }).catch((error) => {
this.$message.error("修改失败") this.$message.error("修改失败")
}) })
}else{ } else {
//新增角色 //新增角色
addRole(this.role).then((res)=>{ addRole(this.role).then((res) => {
if(res.status=="success"){ if (res.status == "success") {
this.$message.success("添加成功") this.$message.success("添加成功")
this.getRoles() this.getRoles()
}else{ } else {
this.$message.error(res.data) this.$message.error(res.data)
} }
}).catch((error)=>{ }).catch((error) => {
this.$message.error("添加失败") this.$message.error("添加失败")
}) })
} }
...@@ -294,7 +280,7 @@ export default { ...@@ -294,7 +280,7 @@ export default {
//点击树 //点击树
checkTree(data){ checkTree(data) {
const node = this.$refs.tree.getNode(data.id); const node = this.$refs.tree.getNode(data.id);
this.setNode(node); this.setNode(node);
}, },
...@@ -332,4 +318,11 @@ export default { ...@@ -332,4 +318,11 @@ export default {
.footer { .footer {
text-align: right; text-align: right;
} }
.explain-text {
font-size: 12px;
font-weight: 400;
display: inline-block;
padding-left: 10px;
color: #949494;
}
</style> </style>
\ No newline at end of file
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