Commit 21fea5e2 authored by 赵伟庚's avatar 赵伟庚

update:菜单管理对接接口,字典配置对接上下移

parent f5a9cb0b
...@@ -38,6 +38,7 @@ export default { ...@@ -38,6 +38,7 @@ export default {
} }
}, },
clickAction({ callback }) { clickAction({ callback }) {
this.$parent.hideBox()
typeof callback === "function" && callback(); typeof callback === "function" && callback();
}, },
getName({ name }) { getName({ name }) {
......
...@@ -53,6 +53,9 @@ export default { ...@@ -53,6 +53,9 @@ export default {
}, },
}, },
methods: { methods: {
hideBox() {
this.showMore = false
},
isDisabled({ disabled }) { isDisabled({ disabled }) {
if (typeof disabled === "function") { if (typeof disabled === "function") {
return disabled(); return disabled();
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</template> </template>
</bg-filter-group> </bg-filter-group>
<div class="table_container"> <div class="table_container">
<bg-table ref="bgTable" :headers="headers" :rows="tableRows" :isIndex="true" :stripe="true" :select="true"> <bg-table ref="bgTable" :headers="headers" :rows="tableRows" :isIndex="true" :stripe="true">
<template v-slot:updated_time="{ row }"> <template v-slot:updated_time="{ row }">
{{ row.updated_time.split("+")[0].replace("T", " ").replace("Z", " ") }} {{ row.updated_time.split("+")[0].replace("T", " ").replace("Z", " ") }}
</template> </template>
...@@ -521,20 +521,20 @@ const moveRow = (row,type) => { ...@@ -521,20 +521,20 @@ const moveRow = (row,type) => {
sort: row.sort sort: row.sort
} }
] ]
// axios axios
// .put(``,[...params]) .put(`/apaas/system/v5/dictionary/sort`,[...params])
// .then((res) => { .then((res) => {
// if (res.data.code == 200) { if (res.data.code == 200) {
// ElMessage.success(res.data.data) ElMessage.success(res.data.data)
// state.tableRows = [] state.tableRows = []
// changePage(1) changePage(1)
// }else { }else {
// ElMessage.error(res.data.data) ElMessage.error(res.data.data)
// } }
// }) })
// .catch((err) => { .catch((err) => {
// console.log(err) console.log(err)
// }) })
} }
onBeforeMount(() => { onBeforeMount(() => {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
:highlight-current="true" :highlight-current="true"
node-key="menu_id" node-key="menu_id"
ref="menuTree" ref="menuTree"
:filter-node-method="filterNode"
> >
<template #default="{ node, data }"> <template #default="{ node, data }">
<div class="custom-tree-node" pointer-events="none"> <div class="custom-tree-node" pointer-events="none">
...@@ -74,7 +75,7 @@ ...@@ -74,7 +75,7 @@
<div class="flex_right"> <div class="flex_right">
<div class="main_container"> <div class="main_container">
<div class="base-info bg-scroll"> <div class="base-info bg-scroll">
<menuForm ref="menuFormRef" :data="menuFormData" @action="getMenuFormData"></menuForm> <menuForm ref="menuFormRef" :data="menuFormData"></menuForm>
</div> </div>
<div class="base-btn"> <div class="base-btn">
<el-button type="primary" @click="saveMenu(menuFormRef,addType)"> <el-button type="primary" @click="saveMenu(menuFormRef,addType)">
...@@ -89,51 +90,61 @@ ...@@ -89,51 +90,61 @@
<script setup> <script setup>
import { Search } from '@element-plus/icons-vue' import { Search } from '@element-plus/icons-vue'
import { reactive, toRefs, ref, nextTick, computed, onBeforeMount, onBeforeUnmount } from 'vue' import { reactive, toRefs, ref, nextTick, computed, onBeforeMount, onBeforeUnmount, watch } from 'vue'
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import axios from '../../../../request/http.js' import axios from '../../../../request/http.js'
import menuForm from './menu-form.vue' import menuForm from './menu-form.vue'
const router = useRouter(); const router = useRouter();
const menuTree = ref(null) const menuTree = ref(null) // 树形
const treeAction = ref(null) const treeAction = ref(null) // 树形操作弹出框
const menuFormRef = ref(null) const menuFormRef = ref(null) // 右侧表单
const acTop = ref(''); const acTop = ref('');
const acLeft = ref(''); const acLeft = ref('');
const acBottom = ref(''); const acBottom = ref('');
const actionFlag = ref(false) const actionFlag = ref(false) // 弹出框状态标识
const state = reactive({ const state = reactive({
data: [], data: [], // 树形数据
search: "", search: "", // 树形搜索
selectData:null, selectData:null, // 当前选中的节点
selectParentData:null, selectParentData:null, // 当前选中节点的父节点
treeAction, treeAction,
menuTree, menuTree,
bottomGap:30,//弹窗吸底高度 bottomGap:30,//弹窗吸底高度
defaultProps: { defaultProps: {
children: 'Child', children: 'Child',
label: 'menu_name', label: 'menu_name',
}, }, // 树形配置
actionDataIndex: 0, actionDataIndex: 0, // 当前选中节点在本级的位置,用来判断是否可以上下移动
menuFormData: null, menuFormData: null, // 菜单数据
addType: 1, // 1-新增本级 2-新增下级 addType: 1, // 1-新增本级 2-新增下级
newMenuId: 0, newMenuId: 0, // 新增菜单时用来指定menu_id,达到选中效果
timer: null, // 定时器
}) })
const moveIndex = computed({ const moveIndex = computed({
get: () => { get: () => {
let index = 0 let index = 0
if(state.selectData) { if(state.selectData) {
console.log(state.selectData)
findIndex(state.selectData.menu_id,state.data) findIndex(state.selectData.menu_id,state.data)
index = state.actionDataIndex index = state.actionDataIndex
} }
return index return index
} }
}) }) // 计算上下移动
watch(() => state.search,(n,o) => {
if (state.timer) {
clearTimeout(state.timer);
}
state.timer = setTimeout(() => {
state.menuTree.filter(n)
}, 500);
}) // 树形搜索值
const getMenuTree = () => { const getMenuTree = () => {
axios axios
.get(`/apaas/system/v5/menu/tree`) .get(`/apaas/system/v5/menu/tree`)
...@@ -155,11 +166,11 @@ const getMenuTree = () => { ...@@ -155,11 +166,11 @@ const getMenuTree = () => {
} }
}) })
} // 获取菜单树 } // 获取菜单树
const findIndex= (code,arr) => { const findIndex= (code,arr) => {
arr.forEach((e,i) => { arr.forEach((e,i) => {
if (e.menu_id == code) { if (e.menu_id == code) {
state.actionDataIndex = i state.actionDataIndex = i
console.log(e,i)
}else { }else {
if (e.Child && e.Child.length > 0) { if (e.Child && e.Child.length > 0) {
findIndex(code,e.Child) findIndex(code,e.Child)
...@@ -174,7 +185,6 @@ const showAction = (e, data,node) => { ...@@ -174,7 +185,6 @@ const showAction = (e, data,node) => {
acBottom.value = '' acBottom.value = ''
const rect = e.target.getBoundingClientRect(); //获取点击的dom的位置 const rect = e.target.getBoundingClientRect(); //获取点击的dom的位置
var allHeight = document.body.scrollHeight var allHeight = document.body.scrollHeight
console.log(rect, data,node);
actionFlag.value = true; actionFlag.value = true;
state.selectData = data state.selectData = data
...@@ -200,7 +210,6 @@ const showAction = (e, data,node) => { ...@@ -200,7 +210,6 @@ const showAction = (e, data,node) => {
}) })
} // 树形操作框 } // 树形操作框
const handleNodeClick = (data) => { const handleNodeClick = (data) => {
if (state.selectData && state.selectData.menu_id == data.menu_id) { if (state.selectData && state.selectData.menu_id == data.menu_id) {
return return
...@@ -210,10 +219,16 @@ const handleNodeClick = (data) => { ...@@ -210,10 +219,16 @@ const handleNodeClick = (data) => {
closeAction() closeAction()
} // 菜单树节点点击 } // 菜单树节点点击
const filterNode = (val,data) => {
if (!val) {
return true
}
return data.menu_name.includes(val)
} // 树形筛选
const fileAction = (val,data,parent,disabled=false) => { const fileAction = (val,data,parent,disabled=false) => {
if (val == 1) { if (val == 1) { // 新建本级菜单
state.addType = 1 state.addType = 1
console.log("新建本级", data ,parent,disabled)
let newChild = { let newChild = {
menu_name: "新菜单", menu_name: "新菜单",
menu_id: 'new' + state.newMenuId, menu_id: 'new' + state.newMenuId,
...@@ -227,9 +242,8 @@ const fileAction = (val,data,parent,disabled=false) => { ...@@ -227,9 +242,8 @@ const fileAction = (val,data,parent,disabled=false) => {
state.menuTree && state.menuTree.setCurrentKey(newChild.menu_id); state.menuTree && state.menuTree.setCurrentKey(newChild.menu_id);
handleNodeClick(newChild); handleNodeClick(newChild);
state.newMenuId++ state.newMenuId++
}else if (val == 2) { }else if (val == 2) { // 新建下级菜单
state.addType = 2 state.addType = 2
console.log("新建下级",data,parent,disabled)
let newChild = { let newChild = {
menu_name: "新菜单", menu_name: "新菜单",
menu_id: 'new' + state.newMenuId, menu_id: 'new' + state.newMenuId,
...@@ -244,9 +258,7 @@ const fileAction = (val,data,parent,disabled=false) => { ...@@ -244,9 +258,7 @@ const fileAction = (val,data,parent,disabled=false) => {
handleNodeClick(newChild); handleNodeClick(newChild);
state.selectParentData = data state.selectParentData = data
state.newMenuId++ state.newMenuId++
test() }else if (val == 3) { // 删除菜单
}else if (val == 3) {
console.log("删除",data,parent,disabled)
axios axios
.delete(`/apaas/system/v5/menu/${data.id}`) .delete(`/apaas/system/v5/menu/${data.id}`)
.then((res) => { .then((res) => {
...@@ -258,20 +270,44 @@ const fileAction = (val,data,parent,disabled=false) => { ...@@ -258,20 +270,44 @@ const fileAction = (val,data,parent,disabled=false) => {
ElMessage.error(res.data.data) ElMessage.error(res.data.data)
} }
}) })
test() }else if (val == 4) { // 菜单上移
}else if (val == 4) {
console.log("上移",data,parent,disabled)
test()
if (disabled) { if (disabled) {
return return
} }
test() let nextObj = null
if (parent) {
parent.Child.forEach((e,i)=> {
if (data.id == e.id) {
nextObj = parent.Child[i-1]
}
})
}else { }else {
console.log("下移",data,parent,disabled) state.data.forEach((e,i) => {
if (data.id == e.id) {
nextObj = state.data[i-1]
}
})
}
changeSort(data,nextObj)
}else { // 菜单下移
if (disabled) { if (disabled) {
return return
} }
test() let nextObj = null
if (parent) {
parent.Child.forEach((e,i)=> {
if (data.id == e.id) {
nextObj = parent.Child[i+1]
}
})
}else {
state.data.forEach((e,i) => {
if (data.id == e.id) {
nextObj = state.data[i+1]
}
})
}
changeSort(data,nextObj)
} }
if (menuFormRef) { if (menuFormRef) {
nextTick().then(() => { nextTick().then(() => {
...@@ -281,22 +317,37 @@ const fileAction = (val,data,parent,disabled=false) => { ...@@ -281,22 +317,37 @@ const fileAction = (val,data,parent,disabled=false) => {
} }
}) })
}) })
} } // 清除表单验证
} // 各种操作按钮 } // 各种操作按钮
const test = () => { const changeSort = (data,nextObj) => {
console.log("执行了") let params = [
} {
id: data.id,
sort: nextObj.sort
},
{
id: nextObj.id,
sort: data.sort
}
]
axios
.put(`/apaas/system/v5/menu/sort`,params)
.then((res) => {
if (res.data.code == 200) {
ElMessage.success(res.data.data)
getMenuTree()
}else {
ElMessage.error(res.data.data)
}
})
} // 菜单上下移
const closeAction = () => { const closeAction = () => {
actionFlag.value = false; actionFlag.value = false;
} // 点击其他地方,菜单操作框关闭 } // 点击其他地方,菜单操作框关闭
const getMenuFormData = (date) => {
}
const saveMenu = (el,type) => { const saveMenu = (el,type) => {
console.log(el,type)
let params = { let params = {
menu_name: el.menuForm.menu_name, menu_name: el.menuForm.menu_name,
menu_type: el.menuForm.menu_type, menu_type: el.menuForm.menu_type,
...@@ -322,24 +373,25 @@ const saveMenu = (el,type) => { ...@@ -322,24 +373,25 @@ const saveMenu = (el,type) => {
}else { // 新增下级 }else { // 新增下级
params.p_menu_id = state.selectParentData.menu_id params.p_menu_id = state.selectParentData.menu_id
} }
console.log(123)
axios axios
.post(`/apaas/system/v5/menu/add`,params) .post(`/apaas/system/v5/menu/add`,params)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
ElMessage.success(res.data.data) ElMessage.success(res.data.data)
state.selectData = null
getMenuTree() getMenuTree()
}else { }else {
ElMessage.error(res.data.data) ElMessage.error(res.data.data)
} }
}) })
} }
} } // 保存按钮,新增或编辑菜单
onBeforeMount(()=>{ onBeforeMount(()=>{
window.addEventListener("click", closeAction) window.addEventListener("click", closeAction)
window.addEventListener("scroll", closeAction,true) window.addEventListener("scroll", closeAction,true)
getMenuTree() getMenuTree()
}) })
onBeforeUnmount(()=>{ onBeforeUnmount(()=>{
...@@ -360,24 +412,45 @@ const { ...@@ -360,24 +412,45 @@ const {
</script> </script>
<style scoped> <style scoped>
.flex_left {
background-color: #fff;
height: calc(100% - 16px);
width: 320px;
box-shadow: 0px 1px 4px 0px
rgba(0, 7, 101, 0.15);
border-radius: 6px;
margin-right: 10px;
overflow: hidden;
}
.flex_right {
background-color: #fff;
height: calc(100% - 16px);
flex: 1;
box-shadow: 0px 1px 4px 0px
rgba(0, 7, 101, 0.15);
border-radius: 6px;
overflow: hidden;
}
.tree_content { .tree_content {
overflow: hidden; overflow: hidden;
height: calc(100% - 4px); height: calc(100% - 4px);
position: relative; position: relative;
} }
.search { .search {
padding: 16px 16px 10px; padding: 16px 16px 10px;
} }
.tree { .tree {
overflow: auto; overflow: auto;
height: calc(100% - 65px); height: calc(100% - 65px);
} }
.tree :deep().el-tree-node .el-tree-node__content { .tree :deep().el-tree-node>.el-tree-node__content {
padding: 0 16px!important; /* padding: 0 16px!important; */
} }
.tree :deep() .el-tree-node>.el-tree-node__children { .tree :deep() .el-tree-node>.el-tree-node__children {
overflow: unset; overflow: unset;
padding-left: 16px; /* padding-left: 16px; */
} }
.tree-action-box { .tree-action-box {
...@@ -393,6 +466,17 @@ padding-left: 16px; ...@@ -393,6 +466,17 @@ padding-left: 16px;
.tree .el-tree-node__content:hover .tree-action-box { .tree .el-tree-node__content:hover .tree-action-box {
display: inline-block; display: inline-block;
} }
.tree .el-tree {
position: static!important;
}
.tree .el-tree :deep().el-tree-node__content{
height: 36px!important;
}
.tree .el-tree :deep().el-tree-node__content:hover {
background-image: linear-gradient(90deg,
rgba(255, 255, 255, 0.05) 83%,
rgba(0, 0, 0, 0.05) 86%);
}
.tree-more { .tree-more {
font-size: 12px; font-size: 12px;
color: #3759be; color: #3759be;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<el-option <el-option
v-for="item in groupList" v-for="item in groupList"
:key="item.dict_id" :key="item.dict_id"
:label="item.name" :label="item.dict_name"
:value="item.dict_id" :value="item.dict_id"
/> />
</el-select> </el-select>
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
</el-input> </el-input>
</div> </div>
<div class="icon_content bg-scroll"> <div class="icon_content bg-scroll">
<div class="icon_item" v-for="(e,i) in iconArr" :key="i+100" @click="changeIcon(e)"> <div class="icon_item" v-for="(e,i) in showIconArr" :key="i+100" @click="changeIcon(e)">
<span> <span>
<bg-icon <bg-icon
class="selectBgIcon" class="selectBgIcon"
...@@ -106,7 +106,7 @@ const props = defineProps({ ...@@ -106,7 +106,7 @@ const props = defineProps({
data: { data: {
type: Object, type: Object,
default: null, default: null,
} },
}) })
const state = reactive({ const state = reactive({
menuRef, menuRef,
...@@ -133,83 +133,85 @@ const state = reactive({ ...@@ -133,83 +133,85 @@ const state = reactive({
] ]
}, },
groupList: [], groupList: [],
iconFlag: false, iconFlag: false, // 图标盒子
icon_search: "", icon_search: "", // 图标筛选
iconArr: [], iconArr: [], // 所有的图标
showIconArr: [], // 展示的图标
timer: null,
}) })
const emit = defineEmits(['action'])
const submitForm = async () => {
if (!state.menuRef) return
await state.menuRef.validate((valid, fields) => {
if (valid) {
emit('action', state.menuForm)
} else {
emit('action',null)
}
})
}
const getGroupList = () => { const getGroupList = () => {
axios axios
.get(`/apaas/system/v5/dictionary/list?state=1&id=5`) .get(`/apaas/system/v5/menu/group/dict`)
.then((res) => { .then((res) => {
if (res.data.code == 200) { if (res.data.code == 200) {
state.groupList = res.data.data || [] state.groupList = res.data.data || []
console.log(state.groupList)
}else { }else {
ElMessage.error(res.data.data) ElMessage.error(res.data.data)
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}) })
} } // 获取分组数据
const openIconbox = () => { const openIconbox = () => {
state.iconFlag = !state.iconFlag state.iconFlag = !state.iconFlag
} state.icon_search = ""
searchIcon()
} // 打开/关闭图标盒子
const searchIcon = () => { const searchIcon = () => {
if (state.timer) {
clearTimeout(state.timer);
}
state.timer = setTimeout(() => {
let iconList = []
if (state.icon_search == "") {
state.showIconArr = state.iconArr
}else {
state.iconArr.map(e => {
if (e.name.indexOf(state.icon_search) !== -1) {
iconList.push(e)
}
})
state.showIconArr = iconList
}
},500)
} // 图标筛选
}
const clearForm = () => {
if (!state.menuRef) return
state.menuRef.resetFields()
}
const setForm = (data) => { const setForm = (data) => {
state.menuForm = Object.assign(state.menuForm, data); state.menuForm = Object.assign(state.menuForm, data);
} } // 表单赋值
const clearIcon = () => { const clearIcon = () => {
state.menuForm.menu_logo = "" state.menuForm.menu_logo = ""
} } // 清除选中的图标
const changeIcon = (e) => { const changeIcon = (e) => {
console.log(e)
state.menuForm.menu_logo = e.icon state.menuForm.menu_logo = e.icon
state.iconFlag = false state.iconFlag = false
} state.icon_search = ""
searchIcon()
} // 选中图标
onMounted(() => { onMounted(() => {
// 处理图标数据
allIconArr.forEach(e => { allIconArr.forEach(e => {
state.iconArr.push({ state.iconArr.push({
icon: e, icon: e,
name: e.replace("bg-ic-","") name: e.replace("bg-ic-","")
}) })
}) })
state.showIconArr = state.iconArr
getGroupList()
}) })
const { const {
menuForm, menuForm,
formRules, formRules,
groupList, groupList,
iconFlag, iconFlag,
iconArr showIconArr,
icon_search,
} = toRefs(state) } = toRefs(state)
onMounted(() => { defineExpose({ setForm , menuForm, menuRef })
getGroupList()
})
defineExpose({ submitForm, clearForm, setForm , menuForm, menuRef })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
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