1234567891011121314151617181920212223242526 |
- // 树状结构构建插件
- const tree = {
- install (Vue) {
- Vue.prototype.$tree = function(options) {
- // 子级菜单构建函数
- const children = items => {
- /*
- * 根据items.code与所有菜单parentCode比较
- * 如果相等所有菜单当前项就是子级菜单
- * 同时调用当前函数创建多级菜单
- */
- const childrenList = options.filter(j => items.code == j.parentCode).map(e => children(e));
- // 如果当前子菜单项存在 就添加children属性
- if (childrenList.length > 0) {
- return { ...items, children: childrenList };
- }
- // 不存在就不添加
- return { ...items };
- };
- // 过滤一级菜单并添加子级菜单
- const list = options.filter(e => e.parentCode == 'null').map(e => children(e));
- return list;
- };
- }
- };
- export default tree;
|