Commit a2525cdc by 胡悦

提交组织、菜单接口

1 parent 8af2fb3e
......@@ -51,7 +51,8 @@ const ORGINIZA_API = {
ORGINIZA_TREEORY: BASE_URL + '/usercenter/organization/orgtree',
ORGINIZA_ADD: BASE_URL + '/usercenter/organization/add',
ORGINIZA_EDIT: BASE_URL + '/usercenter/organization/edit',
ORGINIZA_DELETE: BASE_URL + '/usercenter/organization/delete'
ORGINIZA_DELETE: BASE_URL + '/usercenter/organization/delete',
ORGINIZA_INFO: BASE_URL + '/usercenter/organization/info'
}
const DICT_API = {
DICT_SEARCH: BASE_URL + '/publiccenter/dict/type/search',
......
......@@ -32,9 +32,14 @@ function editOrganiza (params) {
const url = ORGINIZA_API.ORGINIZA_EDIT
return request(params, url, 'post')
}
// 添加组织
// 删除组织
function deleteOrganiza (params) {
const url = ORGINIZA_API.ORGINIZA_DELETE
return request(params, url)
}
export { getTableList, getChildren, getSimpleList, getTreeOrg, addOrganiza, editOrganiza, deleteOrganiza }
// 组织详情
function organizaInfo (params) {
const url = ORGINIZA_API.ORGINIZA_INFO
return request(params, url)
}
export { getTableList, getChildren, getSimpleList, getTreeOrg, addOrganiza, editOrganiza, deleteOrganiza, organizaInfo }
......@@ -24,6 +24,10 @@ const Constants = {
2: '菜单',
3: '按钮'
},
MENU_OTYPE: {
2: '菜单',
3: '按钮'
},
// 菜单状态
MENU_STATUS: {
1: '正常, green',
......@@ -81,8 +85,7 @@ const Constants = {
// 菜单管理状态
MENUSTATUS: {
'1': '显示,green',
'0': '不显示,gray',
'2': '注销,red'
'2': '不显示,gray'
},
// 菜单类型
MENUMANAGEMENUTYPE: {
......
......@@ -33,7 +33,6 @@
:data="menuTableData"
style="width: 100%"
row-key="id"
border
lazy
:load="load"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
......@@ -62,6 +61,7 @@
</template>
</el-table-column>
<el-table-column
ref="table"
align="center"
width="170"
fixed="right"
......@@ -136,6 +136,7 @@
</div>
</template>
<script>
import _ from 'lodash'
import { getMenuList, getMenuChildren, addMenu, editMenu, menuInfo, deleteMenu, getPermtree } from 'services/menu';
export default {
data() {
......@@ -155,7 +156,7 @@ export default {
placeholder: '请选择菜单状态',
options: [{
value: '1',
label: '显示'
label: '正常'
}, {
value: '2',
label: '不显示'
......@@ -165,7 +166,7 @@ export default {
menuTableData: [],
// 列表 头部设置 数据
listHeadData: [
{ prop: 'menuName', label: '菜单名称' },
{ prop: 'menuName', label: '菜单名称', width: '200' },
{ prop: 'orderNum', label: '排序' },
{ prop: 'frontRoute', label: '请求地址' },
{ prop: 'type', label: '菜单类型' },
......@@ -183,7 +184,7 @@ export default {
{
type: 'primary',
name: '新增',
pType: 'create'
pType: 'btnCreate'
},
{
type: 'primary',
......@@ -205,6 +206,10 @@ export default {
parentName: '',
enableStatus: true
},
form: {
parentName: '',
enableStatus: true
},
menuData: [
{ label: '菜单类型', prop: 'type', type: 'radio', children: this.$Constants.MENU_TYPE },
{ label: '上级菜单', prop: 'parentName', type: 'input', readonly: true, clickFunc: this.selectSuperior, hidden: true },
......@@ -231,8 +236,7 @@ export default {
label: 'label'
},
loading: false,
num: 10
isOpen: true
}
},
watch: {
......@@ -269,6 +273,8 @@ export default {
if (valid) {
let params = JSON.parse(JSON.stringify(this.menuForm))
params.enableStatus = this.menuForm.enableStatus ? 1 : 2
if (params.parentName) delete params.parentName
if (params.menuNo) delete params.menuNo
this.emptyData(params)
let api = addMenu
if (params.id) api = editMenu
......@@ -279,7 +285,13 @@ export default {
message: '操作成功!'
})
this.handleClose()
this.search()
if (params.parentId) {
getMenuChildren({ parentId: params.parentId }).then(res => {
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, params.parentId, res.data)
})
} else {
this.search()
}
} else {
this.$message(res.message)
}
......@@ -295,27 +307,46 @@ export default {
this.$refs.menuForm.$children[0].resetFields()
}
this.menuVisible = !this.menuVisible
if (!this.menuVisible) this.menuForm = _.cloneDeep(this.form)
},
// 按钮事件
btnClick(pType, scope) {
console.log(pType, scope)
switch (pType) {
case 'create':
this.isOpen = true
this.menuDialogTitle = '新增菜单'
this.menuData[0].children = this.$Constants.MENU_TYPE
this.handleClose()
break
case 'btnCreate':
this.isOpen = true
this.menuDialogTitle = '新增菜单'
this.menuData[0].children = this.$Constants.MENU_OTYPE
this.handleClose()
break
case 'edit':
this.menuDialogTitle = '编辑菜单'
this.isOpen = false
this.editEvent(scope)
break
case 'delete':
this.deleteEvent(scope.id)
this.deleteEvent(scope)
break
}
},
// 编辑触发事件
editEvent(row) {
console.log(row)
if (row.parentId == 0) {
this.menuData[0].children = this.$Constants.MENU_TYPE
this.menuData[1].hidden = true
} else {
this.menuData[0].children = this.$Constants.MENU_OTYPE
this.menuData[1].hidden = false
}
menuInfo({ menuId: row.id }).then(res => {
this.menuDialogTitle = '编辑菜单'
this.menuForm = JSON.parse(JSON.stringify(res.data))
this.menuForm.enableStatus = res.data.enableStatus == 1 ? true : false
this.menuForm.type = res.data.type + ''
......@@ -323,7 +354,7 @@ export default {
})
},
// 删除触发事件
deleteEvent(id) {
deleteEvent(row) {
const that = this
const tipData = {
that: that,
......@@ -331,11 +362,24 @@ export default {
tipTitle: '提示',
type: 'error',
callBack: () => {
deleteMenu({ id: id }).then(res => {
this.$message({
type: 'success',
message: '删除成功!'
})
deleteMenu({ menuId: row.id }).then(res => {
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
})
if (row.parentId == 0) {
this.getList()
} else {
getMenuChildren({ parentId: row.parentId }).then(res => {
const nodes = res.data
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, row.parentId, nodes)
})
}
} else {
this.$message(res.message)
}
})
}
}
......@@ -343,19 +387,17 @@ export default {
},
load(tree, treeNode, resolve) {
console.log(tree, treeNode, resolve)
getMenuChildren({ id: tree.id }).then(res => {
let nodes = res.data
nodes.map(item => {
const aa = this.num++
item.id = aa + '' + item.id
})
resolve(nodes)
getMenuChildren({ parentId: tree.menuNo }).then(res => {
resolve(res.data)
})
},
// 上级弹窗
selectSuperior() {
this.getPermtree()
this.closeFilter()
if (this.isOpen) {
this.getPermtree()
this.closeFilter()
}
},
closeFilter() {
this.filterVisible = !this.filterVisible
......
......@@ -34,7 +34,6 @@
:data="orginTableData"
style="width: 100%"
row-key="id"
border
lazy
:load="load"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
......@@ -111,7 +110,8 @@
</div>
</template>
<script>
import { getTableList, getChildren, addOrganiza, editOrganiza, deleteOrganiza } from 'services/orginizaManage'
import _ from 'lodash'
import { getTableList, getChildren, addOrganiza, editOrganiza, deleteOrganiza, organizaInfo } from 'services/orginizaManage'
export default {
data() {
return {
......@@ -121,7 +121,7 @@ export default {
{
type: 'input',
inputType: 'text',
prop: 'organizationName',
prop: 'orgName',
placeholder: '请输入组织名称'
},
{
......@@ -174,21 +174,25 @@ export default {
orginizaDialogTitle: '新增组织',
orginizaVisible: false,
orginizaForm: {
superiorName: '',
enableStatus: true
},
form: {
enableStatus: true
},
orginizaData: [
{ label: '上级组织', prop: 'departmentName', type: 'input', hidden: false, readonly: true },
{ label: '组织名称', prop: 'name', type: 'input' },
{ label: '上级组织', prop: 'superiorName', type: 'input', hidden: false, readonly: true },
{ label: '组织名称', prop: 'departmentName', type: 'input' },
{ label: '显示排序', prop: 'orderNum', type: 'input' },
{ label: '组织状态', prop: 'enableStatus', type: 'switch' }
],
orginizaRules: {
name: [{ required: true, message: '请输入组织名称', trigger: 'blur' }],
departmentName: [{ required: true, message: '请输入组织名称', trigger: 'blur' }],
orderNum: [{ required: true, message: '请输入显示排序', trigger: 'blur' }],
enableStatus: [{ required: true }]
},
// 部门弹窗
num: 1
isRoot: false
}
},
......@@ -209,25 +213,44 @@ export default {
refresh() {
this.searchForm = {}
},
emptyData(params) {
let arr = params
for (let key in arr) {
if (params[key] == null || params[key] == '' || params[key] == []) {
delete params[key]
}
}
return arr
},
// 确定,新增组织、编辑组织
handleConfirm() {
console.log(this.orginizaForm)
this.$refs.orginizaForm.$children[0].validate((valid) => {
if (valid) {
let params = JSON.parse(JSON.stringify(this.orginizaForm))
params.enableStatus = this.orginizaForm.enableStatus ? 1 : 2
if (params.departmentName) delete params.departmentName
let params = {
departmentName: this.orginizaForm.departmentName,
enableStatus: this.orginizaForm.enableStatus ? 1 : 2,
orderNum: this.orginizaForm.orderNum
}
if (this.orginizaForm.superiorId) params.superiorId = this.orginizaForm.superiorId
let api = addOrganiza
if (params.id) api = editOrganiza
if (this.orginizaForm.id) {
api = editOrganiza
params.id = this.orginizaForm.id
}
api(params).then(res => {
if (res.code = 200) {
// this.$set(this.$refs.table.store.states.lazyTreeNodeMap, params.id, res.data)
this.$message({
type: 'success',
message: '操作成功'
})
if (this.orginizaDialogTitle == '新增根组织') {
if (this.isRoot) {
this.getList()
} else {
getChildren({ rootId: params.superiorId }).then(res => {
const nodes = res.data
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, params.superiorId, nodes)
})
}
this.handleClose()
}
......@@ -243,21 +266,31 @@ export default {
this.$refs.orginizaForm.$children[0].resetFields()
}
this.orginizaVisible = !this.orginizaVisible
// if (!this.orginizaVisible) {
// this.orginizaForm = {}
// this.orginizaForm = _.cloneDeep(this.form)
// console.log(this.orginizaForm)
// }
},
// 按钮事件
btnClick(pType, scope) {
console.log(pType, scope)
console.log(pType, scope, this.orginizaForm)
switch (pType) {
case 'root':
this.isRoot = true
this.orginizaData[0].hidden = true
this.orginizaDialogTitle = '新增根组织'
this.handleClose()
break
case 'create':
console.log('??????')
this.isRoot = false
this.orginizaData[0].hidden = false
this.orginizaDialogTitle = '新增组织'
this.orginizaForm.departmentName = scope.departmentName
this.orginizaForm.superiorId = scope.id
// this.$set(this.orginizaForm, 'superiorName', scope.departmentName)
this.orginizaForm['superiorName'] = _.cloneDeep(scope.departmentName)
this.orginizaForm['superiorId'] = _.cloneDeep(scope.id)
this.orginizaDialogTitle = '新增组织' + this.orginizaForm.superiorName
console.log(this.orginizaForm)
this.handleClose()
break
case 'edit':
......@@ -265,19 +298,29 @@ export default {
this.editEvent(scope)
break
case 'delete':
this.deleteEvent(scope.id)
this.deleteEvent(scope)
break
}
},
// 编辑触发事件
editEvent(row) {
console.log(row)
this.orginizaForm = JSON.parse(JSON.stringify(row))
this.orginizaForm.enableStatus = row.enableStatus == 1 ? true : false
this.handleClose()
// this.orginizaForm = JSON.parse(JSON.stringify(this.form))
organizaInfo({ id: row.id }).then(res => {
this.orginizaForm = _.cloneDeep(res.data)
this.orginizaForm.enableStatus = row.enableStatus == 1 ? true : false
if (!this.orginizaForm.superiorId) {
this.orginizaData[0].hidden = true
this.isRoot = true
} else {
this.isRoot = false
}
console.log(this.orginizaForm)
this.handleClose()
})
},
// 删除触发事件
deleteEvent(id) {
deleteEvent(row) {
const that = this
const tipData = {
that: that,
......@@ -285,14 +328,19 @@ export default {
tipTitle: '提示',
type: 'error',
callBack: () => {
deleteOrganiza({ id: id }).then(res => {
deleteOrganiza({ id: row.id }).then(res => {
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
})
if (this.orginizaDialogTitle == '新增根组织') {
if (!row.superiorId) {
this.getList()
} else {
getChildren({ rootId: params.superiorId }).then(res => {
const nodes = res.data
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, params.superiorId, nodes)
})
}
} else {
this.$message(res.message)
......@@ -325,12 +373,7 @@ export default {
// 子节点列表
getChildren(id) {
getChildren({ rootId: id }).then(res => {
let nodes = res.data
// nodes.map(item => {
// const aa = this.num++
// item.id = aa + '' + item.id
// })
return nodes
return res.data
})
},
// 页码
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!