last.js 576 B

12345678910111213141516171819
  1. // 树状结构构建插件
  2. const last = {
  3. install (Vue) {
  4. Vue.prototype.$last = function(options) {
  5. const last = item => {
  6. const isCode = options.menus.filter(j => j.code == item);
  7. if (isCode.length > 0) {
  8. const children = options.menus.filter(k => k.parentCode == isCode[0]?.code);
  9. if (children.length > 0) return last(children[0]?.code);
  10. }
  11. return isCode[0];
  12. };
  13. const item = last(options.code);
  14. sessionStorage.setItem('code', item.code);
  15. return item;
  16. };
  17. }
  18. };
  19. export default last;