refine
This commit is contained in:
parent
3ca51f90e4
commit
1eff524d55
|
@ -29,9 +29,9 @@ export function addRole(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateRole(id, data) {
|
export function updateRole(key, data) {
|
||||||
return request({
|
return request({
|
||||||
url: `/roles/${id}`,
|
url: `/roles/${key}`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'Edit Role':'New Role'">
|
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'Edit Role':'New Role'">
|
||||||
<el-form :model="role" label-width="80px" label-position="left" >
|
<el-form :model="role" label-width="80px" label-position="left" >
|
||||||
<el-form-item label="Key">
|
<el-form-item label="Key">
|
||||||
<el-input v-model="role.key" placeholder="Role Key"/>
|
<el-input :disabled="dialogType==='edit'" v-model="role.key" placeholder="Role Key"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Name">
|
<el-form-item label="Name">
|
||||||
<el-input v-model="role.name" placeholder="Role Name"/>
|
<el-input v-model="role.name" placeholder="Role Name"/>
|
||||||
|
@ -39,9 +39,10 @@
|
||||||
<el-tree ref="tree" :check-strictly="checkStrictly" :data="routesData" :props="defaultProps" show-checkbox node-key="path" class="permission-tree"/>
|
<el-tree ref="tree" :check-strictly="checkStrictly" :data="routesData" :props="defaultProps" show-checkbox node-key="path" class="permission-tree"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
<div style="text-align:right;">
|
||||||
<el-button type="primary" @click="confirmRole">{{ $t('permission.confirm') }}</el-button>
|
<el-button type="danger" @click="dialogVisible=false">{{ $t('permission.cancel') }}</el-button>
|
||||||
<el-button type="danger" @click="dialogVisible=false">{{ $t('permission.cancel') }}</el-button>
|
<el-button type="primary" @click="confirmRole">{{ $t('permission.confirm') }}</el-button>
|
||||||
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -88,9 +89,9 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
async getRoutes() {
|
async getRoutes() {
|
||||||
const res = await getRoutes()
|
const res = await getRoutes()
|
||||||
|
this.serviceRoutes = res.data
|
||||||
const routes = this.generateRoutes(res.data)
|
const routes = this.generateRoutes(res.data)
|
||||||
this.routes = this.i18n(routes)
|
this.routes = this.i18n(routes)
|
||||||
console.log(this.routes)
|
|
||||||
},
|
},
|
||||||
async getRoles() {
|
async getRoles() {
|
||||||
const res = await getRoles()
|
const res = await getRoles()
|
||||||
|
@ -111,18 +112,18 @@ export default {
|
||||||
const res = []
|
const res = []
|
||||||
|
|
||||||
for (let route of routes) {
|
for (let route of routes) {
|
||||||
const title = route.meta && route.meta.title
|
|
||||||
// skip some route
|
// skip some route
|
||||||
if (route.hidden) { continue }
|
if (route.hidden) { continue }
|
||||||
|
|
||||||
const onlyOneShowingChild = this.onlyOneShowingChild(route.children, route)
|
const onlyOneShowingChild = this.onlyOneShowingChild(route.children, route)
|
||||||
|
|
||||||
if (route.children && onlyOneShowingChild && !route.alwaysShow) {
|
if (route.children && onlyOneShowingChild && !route.alwaysShow) {
|
||||||
route = onlyOneShowingChild
|
route = onlyOneShowingChild
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
path: path.resolve(basePath, route.path),
|
path: path.resolve(basePath, route.path),
|
||||||
title: title
|
title: route.meta && route.meta.title
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursive child routes
|
// recursive child routes
|
||||||
|
@ -179,39 +180,43 @@ export default {
|
||||||
})
|
})
|
||||||
.catch(err => { console.error(err) })
|
.catch(err => { console.error(err) })
|
||||||
},
|
},
|
||||||
|
|
||||||
async confirmRole() {
|
async confirmRole() {
|
||||||
const isEdit = this.dialogType === 'edit'
|
const isEdit = this.dialogType === 'edit'
|
||||||
|
|
||||||
|
// TODO:refactor
|
||||||
|
// this.role.routes = this.$refs.tree.getCheckedNodes()
|
||||||
|
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
await updateRole()
|
await updateRole(this.role.key, this.role)
|
||||||
|
for (let index = 0; index < this.rolesList.length; index++) {
|
||||||
|
if (this.rolesList[index].key === this.role.key) {
|
||||||
|
this.rolesList.splice(index, 1, this.role)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await addRole()
|
await addRole(this.role)
|
||||||
|
this.rolesList.push(this.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
// const $tree = this.$refs.tree
|
const { description, key, name, routes } = this.role
|
||||||
// let routeIds = $tree.getCheckedNodes(false, true).reduce((result, node) => {
|
this.dialogVisible = false
|
||||||
// // 如果父菜单被隐藏(onlyOneShowingChild),需要把父菜单的id也添加进去
|
this.$notify({
|
||||||
// return result.concat(node.id, node.parentId)
|
title: 'Success',
|
||||||
// }, [])
|
dangerouslyUseHTMLString: true,
|
||||||
// routeIds = Array.from(new Set(routeIds))
|
message: `
|
||||||
// await updateRole(this.role)
|
<div>Role Key: ${key}</div>
|
||||||
// this.$message({
|
<div>Role Nmae: ${name}</div>
|
||||||
// message: 'Edit succed',
|
<div>Description: ${description}</div>
|
||||||
// type: 'success'
|
<div>Routes: ${routes.join(',')}</div>
|
||||||
// })
|
`,
|
||||||
// this.dialogVisible = false
|
type: 'success'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// reference: src/view/layout/components/Sidebar/SidebarItem.vue
|
// reference: src/view/layout/components/Sidebar/SidebarItem.vue
|
||||||
onlyOneShowingChild(children = [], parent) {
|
onlyOneShowingChild(children = [], parent) {
|
||||||
let onlyOneChild = null
|
let onlyOneChild = null
|
||||||
const showingChildren = children.filter(item => {
|
const showingChildren = children.filter(item => !item.hidden)
|
||||||
if (item.hidden) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// When there is only one child route, the child route is displayed by default
|
// When there is only one child route, the child route is displayed by default
|
||||||
if (showingChildren.length === 1) {
|
if (showingChildren.length === 1) {
|
||||||
|
|
Loading…
Reference in New Issue