Commit a9d6bb18 by cwq0219

修改

1 parent d8d6500a
...@@ -5,7 +5,7 @@ const roleCreateStructure = { ...@@ -5,7 +5,7 @@ const roleCreateStructure = {
roleName: '', roleName: '',
description: '', description: '',
departName: '', departName: '',
// rights: Array, rights: Array,
state: 1, state: 1,
createTime: '' createTime: ''
} }
......
<!-- createRoleComponent --> <!-- createRoleComponent -->
<template> <template>
<gl-dialog :title="createOrEditTitle" :visible.sync="createVisible" :before-close="handleCreateCancel"> <gl-dialog :title="title" :visible.sync="createVisible" :before-close="handleCreateCancel">
<gl-form :model="createRuleForm" :rules="createRules" ref="createRuleForm" label-width="105px"> <gl-form :model="createRuleForm" :rules="createRules" ref="createRuleForm" label-width="105px">
<gl-form-item label="角色名称:" prop="roleName"> <gl-form-item label="角色名称:" prop="roleName">
<gl-input v-model="createRuleForm.roleName" clearable></gl-input> <gl-input v-model="createRuleForm.roleName" clearable></gl-input>
...@@ -17,14 +17,16 @@ ...@@ -17,14 +17,16 @@
<gl-option label="运营平台" value="运营平台"></gl-option> <gl-option label="运营平台" value="运营平台"></gl-option>
</gl-select> </gl-select>
</gl-form-item> </gl-form-item>
<gl-form-item label="菜单选项:"> <gl-form-item label="菜单选项:" prop="rights">
<!-- <tree <tree
ref='tree' ref='tree'
v-model="createRuleForm.rights"
:show-checkbox="show_checkbox" :show-checkbox="show_checkbox"
:defaultExpandAll="defaultExpandAll" :defaultExpandAll="defaultExpandAll"
:defaultCheckedKeys="roleMenuTree"
@input="getMenuOption" @input="getMenuOption"
style="height:160px" style="height:160px"
></tree> --> ></tree>
</gl-form-item> </gl-form-item>
</gl-form> </gl-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
...@@ -35,25 +37,31 @@ ...@@ -35,25 +37,31 @@
</template> </template>
<script> <script>
// import { roleCreateStructure } from '@/common/commonConst'
import { saveRoleList, updateRole } from '@/api/api'
export default { export default {
name: 'RoleCreate', name: 'RoleCreate',
props: { props: {
createOrEditTitle: String,
createVisible: Boolean, createVisible: Boolean,
createRuleForm: Object createRuleForm: Object,
flagCOrE: [Boolean, Array, Function],
roleMenuTree: Array
}, },
watch: { watch: {
createVisible(val) { createVisible(val) {
!val && this.$refs['createRuleForm'].resetFields() !val && this.$refs['createRuleForm'].resetFields()
// 考虑一下放这里还是放下面
this.changeMenuTree = this.roleMenuTree
},
flagCOrE(val) {
this.title = val ? '新建角色' : '角色列表'
// this.changeMenuTree = this.roleMenuTree
} }
}, },
data() { data() {
return { return {
show_checkbox: true, show_checkbox: true,
defaultExpandAll: true, defaultExpandAll: true,
// createOrEditTitle: String, changeMenuTree: [],
title: '',
createRules: { createRules: {
roleName: [ roleName: [
{ required: true, message: '请输入角色名称!', trigger: 'blur' } { required: true, message: '请输入角色名称!', trigger: 'blur' }
...@@ -64,6 +72,9 @@ export default { ...@@ -64,6 +72,9 @@ export default {
], ],
departName: [ departName: [
{ required: true, message: '请输入所属部门!', trigger: 'change' } { required: true, message: '请输入所属部门!', trigger: 'change' }
],
rights: [
{ required: true, message: '请选择菜单选项!', trigger: 'change' }
] ]
} }
} }
...@@ -71,54 +82,26 @@ export default { ...@@ -71,54 +82,26 @@ export default {
methods: { methods: {
// tree-strat // tree-strat
getMenuOption(params) { getMenuOption(params) {
// this.createRuleForm.rights = params.treeData.checkedKeys.concat(params.treeData.halfCheckedKeys) this.changeMenuTree = params.treeData.checkedKeys.concat(params.treeData.halfCheckedKeys)
}, },
// tree-end // tree-end
getParams() { getParams() {
this.createRuleForm.rights = this.changeMenuTree
return this.$deep_clone(this.createRuleForm) return this.$deep_clone(this.createRuleForm)
}, },
// 接口
addRole(flagEOrC, editData) {
editData = { roleName: editData.roleName }
const aa = { role: editData }
// const aa = JSON.stringify(editData)
console.log(aa)
console.log(editData)
const cc = { roleName: 'ggg' }
saveRoleList.req(cc).then((data) => {
console.log(data)
this.$emit('createClose', flagEOrC, editData)
}).catch(err => {
console.log(err)
})
},
updateRoleInfo(flagEOrC, editData) {
updateRole.req(editData).then((data) => {
console.log(data)
this.$emit('createClose', flagEOrC, editData)
}).catch(err => {
console.log(err)
})
},
// 接口
handleCreateSubmit(formName) { handleCreateSubmit(formName) {
const editData = this.getParams() const editData = this.getParams()
console.log(editData) // console.log(editData)
// eidt:true;create:false
const flagEOrC = editData.id !== Number
// console.log(flagEOrC)
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
!flagEOrC && this.addRole(flagEOrC, editData) this.$emit('createClose', editData)
flagEOrC && this.updateRoleInfo(flagEOrC, editData)
// this.$emit('createClose', flagEOrC, editData)
} else { } else {
return false return false
} }
}) })
}, },
handleCreateCancel() { handleCreateCancel() {
this.$emit('createClose') this.$emit('createClose', false)
} }
} }
} }
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
</div> </div>
<hr> <hr>
<div class="default p-t15"> <div class="default p-t15">
<gl-button class="control-tabledata-button" size="small" @click="handleCreateOrEdit('新增角色')">创建</gl-button> <gl-button class="control-tabledata-button" size="small" @click="handleCreateOrEdit(flagCOrE = true)">创建</gl-button>
<role-create :createVisible="createVisible" :createRuleForm="roleParam" :createOrEditTitle="createOrEditTitle" @createClose="handleCreateClose"></role-create> <role-create :createVisible="createVisible" :createRuleForm="roleParam" :flagCOrE="flagCOrE" :roleMenuTree="roleMenuTree" @createClose="handleCreateClose"></role-create>
<div class="m-b8"> <div class="m-b8">
<transition> <transition>
<gl-table :table="roleData"></gl-table> <gl-table :table="roleData"></gl-table>
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<script> <script>
import { RoleCreate, RoleDetail, UserDetail } from '@/components/index' import { RoleCreate, RoleDetail, UserDetail } from '@/components/index'
// 接口 // 接口
import { getRoleList, deleteRoleById } from '@/api/api' import { getRoleList, deleteRoleById, selectMenuTreeRoleId, saveRoleList, updateRole } from '@/api/api'
import { roleCreateStructure, roleDataColumn, userRoleDetailColumn, userRoleDetailConsole } from '@/common/commonConst' import { roleCreateStructure, roleDataColumn, userRoleDetailColumn, userRoleDetailConsole } from '@/common/commonConst'
export default { export default {
name: 'role', name: 'role',
...@@ -45,7 +45,9 @@ export default { ...@@ -45,7 +45,9 @@ export default {
columnParam: [], columnParam: [],
consoleParam: [], consoleParam: [],
apiParam: Number, apiParam: Number,
flagRoleOrUser: Boolean, flagRoleOrUser: true,
flagCOrE: Boolean,
roleMenuTree: [],
createOrEditTitle: '新增角色', createOrEditTitle: '新增角色',
userDetailTitle: '用户列表', userDetailTitle: '用户列表',
// 分页所需参数-start // 分页所需参数-start
...@@ -66,7 +68,7 @@ export default { ...@@ -66,7 +68,7 @@ export default {
type: 'text', type: 'text',
callback: (index, rows) => { callback: (index, rows) => {
this.roleParam = this.$deep_clone(rows[index]) this.roleParam = this.$deep_clone(rows[index])
this.handleCreateOrEdit('角色列表') this.handleCreateOrEdit(this.flagCOrE = false)
} }
}, { }, {
label: '详细', label: '详细',
...@@ -139,6 +141,7 @@ export default { ...@@ -139,6 +141,7 @@ export default {
// console.log(res) // console.log(res)
this.total = res.total this.total = res.total
this.roleData.data = res.list this.roleData.data = res.list
// console.log(this.roleData.data)
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
}) })
...@@ -152,6 +155,45 @@ export default { ...@@ -152,6 +155,45 @@ export default {
this.message(message, 'error') this.message(message, 'error')
}) })
}, },
// 获得角色的相关权限详细信息,并返回树形数据
getMenuTree(params) {
selectMenuTreeRoleId.req({ id: params }).then(res => {
res.forEach(item => {
this.roleMenuTree.push(item.id)
})
this.createDialogVisible()
}).catch(err => {
console.log(err)
})
},
// 添加角色
addRole(params) {
console.log(params)
this.createOrEditSuccess()
// editData = { roleName: editData.roleName }
// const aa = { role: editData }
// const aa = JSON.stringify(editData)
// console.log(aa)
// console.log(editData)
// const cc = { roleName: 'ggg' }
saveRoleList.req(params).then((data) => {
// console.log(data)
// this.createOrEditSuccess()
}).catch(err => {
console.log(err)
})
},
// 编辑角色
updateRoleInfo(params) {
console.log(params)
this.createOrEditSuccess()
updateRole.req(params).then((data) => {
// console.log(data)
// this.createOrEditSuccess()
}).catch(err => {
console.log(err)
})
},
// 接口请求-end--------------------------------------- // 接口请求-end---------------------------------------
createDialogVisible() { createDialogVisible() {
this.createVisible = !this.createVisible this.createVisible = !this.createVisible
...@@ -162,6 +204,11 @@ export default { ...@@ -162,6 +204,11 @@ export default {
userDetailDialogVisible() { userDetailDialogVisible() {
this.userDetailVisible = !this.userDetailVisible this.userDetailVisible = !this.userDetailVisible
}, },
createOrEditSuccess() {
this.createDialogVisible()
this.message(this.flagCOrE ? '创建角色成功!' : '已经成功修改数据!', 'success')
this.getList()
},
// 调取接口相关函数 // 调取接口相关函数
handleSizeChange(val) { handleSizeChange(val) {
this.pageSize = val this.pageSize = val
...@@ -194,19 +241,22 @@ export default { ...@@ -194,19 +241,22 @@ export default {
this.getList() this.getList()
this.apiParam = Number this.apiParam = Number
}, },
handleCreateOrEdit(title) { handleCreateOrEdit() {
this.createOrEditTitle = title this.roleParam = this.flagCOrE ? roleCreateStructure : this.roleParam
this.roleParam !== roleCreateStructure ? this.roleParam : roleCreateStructure this.flagCOrE && this.createDialogVisible()
this.createDialogVisible() !this.flagCOrE && this.getMenuTree(this.roleParam.id)
}, },
// 关闭新增用户组件 // 关闭新增用户组件
handleCreateClose(flagEOrC, data) { handleCreateClose(data) {
this.roleMenuTree = []
if (!data) {
this.createDialogVisible() this.createDialogVisible()
this.roleParam = roleCreateStructure this.message(this.flagCOrE ? '取消创建角色' : '取消编辑角色')
!data && this.message('取消创建角色') return false
}
// 将数据提交给后台,根据返回结果做判断 // 将数据提交给后台,根据返回结果做判断
data && !flagEOrC && this.getList() && this.message('创建角色成功!', 'success') this.flagCOrE && this.addRole(data)
data && flagEOrC && this.getList() && this.message('已经成功修改数据!', 'success') !this.flagCOrE && this.updateRoleInfo(data)
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!