setParentsetSession.js 609 B

123456789101112131415161718
  1. // 树状结构构建插件
  2. const setParentsetSession = {
  3. install (Vue) {
  4. Vue.prototype.$setParentsetSession = function(options) {
  5. // 点击制造当前菜单父级项
  6. const tree = item => {
  7. const parent = options.menus.filter(j => item.parentCode === j.code).map(e => tree({ ...e, children: item }));
  8. if (parent.length > 0) {
  9. return { ...parent[0] };
  10. }
  11. return { ...item };
  12. };
  13. const childrens = tree(options.iscode);
  14. sessionStorage.setItem('childrens', JSON.stringify(childrens));
  15. };
  16. }
  17. };
  18. export default setParentsetSession;