github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/src/router/index.ts (about)

     1  import { createRouter, createWebHashHistory } from 'vue-router'
     2  import type { RouteRecordRaw } from 'vue-router'
     3  import type { App } from 'vue'
     4  import { Dashboard, Develop, Landing, getParentLayout } from '@/utils/routerHelper'
     5  import { useI18n } from '@/hooks/web/useI18n'
     6  
     7  const { t } = useI18n()
     8  
     9  export const constantRouterMap: AppRouteRecordRaw[] = [
    10    {
    11      path: '/',
    12      component: Dashboard,
    13      redirect: '/board',
    14      meta: {
    15        title: t('router.Dashboard'),
    16        icon: 'vaadin:dashboard'
    17      },
    18      children: [
    19        {
    20          path: '/board',
    21          name: 'Dashboard',
    22          component: () => import('@/views/Dashboard/main.vue'),
    23          meta: {
    24            hidden: true,
    25            title: t('router.Dashboard'),
    26            noTagsView: true
    27          }
    28        }
    29      ]
    30    },
    31    {
    32      path: '/landing',
    33      component: Landing,
    34      redirect: 'index',
    35      meta: {
    36        title: t('router.Landing'),
    37        hidden: true,
    38        noTagsView: true
    39      },
    40      children: [
    41        {
    42          path: '/landing/:id',
    43          name: 'Landing',
    44          component: () => import('@/views/Dashboard/landing.vue'),
    45          meta: {
    46            hidden: true,
    47            title: t('router.Dashboard'),
    48            noTagsView: true
    49          }
    50        }
    51      ]
    52    },
    53    {
    54      path: '/redirect',
    55      component: Dashboard,
    56      name: 'Redirect',
    57      children: [
    58        {
    59          path: '/redirect/:path(.*)',
    60          name: 'Redirect',
    61          component: () => import('@/views/Redirect/Redirect.vue'),
    62          meta: {}
    63        }
    64      ],
    65      meta: {
    66        hidden: true,
    67        noTagsView: true
    68      }
    69    },
    70    {
    71      path: '/login',
    72      component: () => import('@/views/Login/Login.vue'),
    73      name: 'Login',
    74      meta: {
    75        hidden: true,
    76        title: t('router.login'),
    77        noTagsView: true
    78      }
    79    },
    80    {
    81      path: '/password_reset',
    82      component: () => import('@/views/PasswordReset/PasswordReset.vue'),
    83      name: 'Password Reset',
    84      meta: {
    85        hidden: true,
    86        title: t('router.passwordReset'),
    87        noTagsView: true
    88      }
    89    },
    90    {
    91      path: '/404',
    92      component: () => import('@/views/Error/404.vue'),
    93      name: 'NoFind',
    94      meta: {
    95        hidden: true,
    96        title: '404',
    97        noTagsView: true
    98      }
    99    }
   100  ]
   101  
   102  export const dashboardRouterMap: AppRouteRecordRaw[] = [
   103    {
   104      path: '/development',
   105      component: Develop,
   106      redirect: '/development/index',
   107      meta: {
   108        title: t('router.Development'),
   109      },
   110      children: [
   111        {
   112          path: 'index',
   113          name: 'Development',
   114          component: () => import('@/views/Development/index.vue'),
   115          meta: {
   116            title: t('router.Development'),
   117            icon: 'mdi:tools'
   118          }
   119        }
   120      ]
   121    }
   122  ]
   123  
   124  export const developRouterMap: AppRouteRecordRaw[] = [
   125    {
   126      path: '/entities',
   127      component: Develop,
   128      redirect: '/entities/index',
   129      meta: {
   130        title: t('router.Entities'),
   131        icon: 'icon-park-solid:layers'
   132      },
   133      children: [
   134        {
   135          path: 'index',
   136          name: 'Entities',
   137          component: () => import('@/views/Entities/index.vue'),
   138          meta: {
   139            title: t('router.ListEntities'),
   140            // noTagsView: true,
   141            hidden: true,
   142            canTo: true,
   143            activeMenu: '/entities'
   144          }
   145        },
   146        {
   147          path: 'new',
   148          name: 'newEntities',
   149          component: () => import('@/views/Entities/new.vue'),
   150          meta: {
   151            title: t('router.New'),
   152            noTagsView: true,
   153            hidden: true,
   154            canTo: true,
   155            activeMenu: '/entities'
   156          }
   157        },
   158        {
   159          path: 'edit/:id',
   160          name: 'editEntities',
   161          component: () => import('@/views/Entities/edit.vue'),
   162          props: true,
   163          meta: {
   164            title: t('router.EditEntity'),
   165            // noTagsView: true,
   166            hidden: true,
   167            canTo: true,
   168            activeMenu: '/entities'
   169          }
   170        }
   171      ]
   172    },
   173    {
   174      path: '/waterfall',
   175      component: Develop,
   176      name: 'waterfall',
   177      redirect: '/waterfall/index',
   178      meta: {
   179        hidden: true,
   180        title: 'waterfall'
   181      },
   182      children: [
   183        {
   184          path: 'index',
   185          name: 'waterfall',
   186          component: () => import('@/views/components/Waterfall.vue'),
   187          meta: {
   188            title: t('router.ListScripts'),
   189            // noTagsView: true,
   190            hidden: true,
   191            canTo: true,
   192            activeMenu: '/waterfall'
   193          }
   194        },
   195      ]
   196    },
   197    {
   198      path: '/image-cropping',
   199      component: Develop,
   200      name: 'ImageCropping',
   201      redirect: '/image-cropping/index',
   202      meta: {
   203        hidden: true,
   204        title: 'ImageCropping'
   205      },
   206      children: [
   207        {
   208          path: 'index',
   209          name: 'ImageCropping',
   210          component: () => import('@/views/components/ImageCropping.vue'),
   211          meta: {
   212            title: t('router.imageCropping'),
   213            // noTagsView: true,
   214            hidden: true,
   215            canTo: true,
   216            activeMenu: '/image-cropping'
   217          }
   218        },
   219      ]
   220    },
   221    {
   222      path: '/scripts',
   223      component: Develop,
   224      redirect: '/scripts/index',
   225      meta: {
   226        title: t('router.Scripts'),
   227        icon: 'fluent-mdl2:coffee-script'
   228      },
   229      children: [
   230        {
   231          path: 'index',
   232          name: 'Scripts',
   233          component: () => import('@/views/Scripts/index.vue'),
   234          meta: {
   235            title: t('router.ListScripts'),
   236            // noTagsView: true,
   237            hidden: true,
   238            canTo: true,
   239            activeMenu: '/scripts'
   240          }
   241        },
   242        {
   243          path: 'new',
   244          name: 'newScripts',
   245          component: () => import('@/views/Scripts/new.vue'),
   246          meta: {
   247            title: t('router.New'),
   248            noTagsView: true,
   249            hidden: true,
   250            canTo: true,
   251            activeMenu: '/scripts'
   252          }
   253        },
   254        {
   255          path: 'edit/:id',
   256          name: 'editScripts',
   257          component: () => import('@/views/Scripts/edit.vue'),
   258          props: true,
   259          meta: {
   260            title: t('router.EditScript'),
   261            // noTagsView: true,
   262            hidden: true,
   263            canTo: true,
   264            activeMenu: '/scripts'
   265          }
   266        }
   267      ]
   268    },
   269    {
   270      path: '/automation',
   271      component: Develop,
   272      redirect: '/automation/tasks',
   273      meta: {
   274        title: t('router.Automation'),
   275        icon: 'fa6-solid:circle-nodes'
   276      },
   277      children: [
   278        {
   279          path: 'tasks',
   280          name: 'Tasks',
   281          component: () => import('@/views/Automation/Tasks/index.vue'),
   282          meta: {
   283            title: t('router.Tasks'),
   284          },
   285          children: [
   286            {
   287              path: 'new',
   288              name: 'newTask',
   289              component: () => import('@/views/Automation/Tasks/new.vue'),
   290              meta: {
   291                title: t('router.New'),
   292                // noTagsView: true,
   293                hidden: true,
   294                canTo: true,
   295                activeMenu: '/automation/tasks'
   296              }
   297            },
   298            {
   299              path: 'edit/:id',
   300              name: 'editTask',
   301              component: () => import('@/views/Automation/Tasks/edit.vue'),
   302              props: true,
   303              meta: {
   304                title: t('router.EditTask'),
   305                // noTagsView: true,
   306                hidden: true,
   307                canTo: true,
   308                activeMenu: '/automation/tasks'
   309              }
   310            }
   311          ]
   312        },
   313        {
   314          path: 'triggers',
   315          name: 'Triggers',
   316          component: () => import('@/views/Automation/Triggers/index.vue'),
   317          meta: {
   318            title: t('router.Triggers'),
   319          },
   320          children: [
   321            {
   322              path: 'new',
   323              name: 'newTrigger',
   324              component: () => import('@/views/Automation/Triggers/new.vue'),
   325              meta: {
   326                title: t('router.New'),
   327                noTagsView: true,
   328                hidden: true,
   329                canTo: true,
   330                activeMenu: '/automation/triggers'
   331              }
   332            },
   333            {
   334              path: 'edit/:id',
   335              name: 'editTrigger',
   336              component: () => import('@/views/Automation/Triggers/edit.vue'),
   337              props: true,
   338              meta: {
   339                title: t('router.EditTrigger'),
   340                // noTagsView: true,
   341                hidden: true,
   342                canTo: true,
   343                activeMenu: '/automation/triggers'
   344              }
   345            }
   346          ]
   347        },
   348        {
   349          path: 'conditions',
   350          name: 'Conditions',
   351          component: () => import('@/views/Automation/Conditions/index.vue'),
   352          meta: {
   353            title: t('router.Conditions'),
   354          },
   355          children: [
   356            {
   357              path: 'new',
   358              name: 'newCondition',
   359              component: () => import('@/views/Automation/Conditions/new.vue'),
   360              meta: {
   361                title: t('router.New'),
   362                noTagsView: true,
   363                hidden: true,
   364                canTo: true,
   365                activeMenu: '/automation/conditions'
   366              }
   367            },
   368            {
   369              path: 'edit/:id',
   370              name: 'editCondition',
   371              component: () => import('@/views/Automation/Conditions/edit.vue'),
   372              props: true,
   373              meta: {
   374                title: t('router.EditCondition'),
   375                // noTagsView: true,
   376                hidden: true,
   377                canTo: true,
   378                activeMenu: '/automation/conditions'
   379              }
   380            }
   381          ]
   382        },
   383        {
   384          path: 'actions',
   385          name: 'Actions',
   386          component: () => import('@/views/Automation/Actions/index.vue'),
   387          meta: {
   388            title: t('router.Actions'),
   389          },
   390          children: [
   391            {
   392              path: 'new',
   393              name: 'newAction',
   394              component: () => import('@/views/Automation/Actions/new.vue'),
   395              meta: {
   396                title: t('router.New'),
   397                noTagsView: true,
   398                hidden: true,
   399                canTo: true,
   400                activeMenu: '/automation/actions'
   401              }
   402            },
   403            {
   404              path: 'edit/:id',
   405              name: 'editAction',
   406              component: () => import('@/views/Automation/Actions/edit.vue'),
   407              props: true,
   408              meta: {
   409                title: t('router.EditAction'),
   410                // noTagsView: true,
   411                hidden: true,
   412                canTo: true,
   413                activeMenu: '/automation/actions'
   414              }
   415            }
   416          ]
   417        },
   418      ]
   419    },
   420    {
   421      path: '/dashboards',
   422      component: Develop,
   423      redirect: '/dashboards/index',
   424      meta: {
   425        title: t('router.Dashboards'),
   426        icon: 'ic:sharp-dashboard-customize'
   427      },
   428      children: [
   429        {
   430          path: 'index',
   431          name: 'Dashboards',
   432          component: () => import('@/views/Dashboard/index.vue'),
   433          meta: {
   434            title: t('router.ListDashboards'),
   435            // noTagsView: true,
   436            hidden: true,
   437            canTo: true,
   438            activeMenu: '/dashboards'
   439          }
   440        },
   441        {
   442          path: 'view/:id',
   443          name: 'viewDashboards',
   444          component: () => import('@/views/Dashboard/view.vue'),
   445          props: true,
   446          meta: {
   447            title: t('router.DashboardsView'),
   448            // noTagsView: true,
   449            hidden: true,
   450            canTo: true,
   451            activeMenu: '/dashboards'
   452          }
   453        },
   454        {
   455          path: 'edit/:id',
   456          name: 'editDashboards',
   457          component: () => import('@/views/Dashboard/editor/editor.vue'),
   458          props: true,
   459          meta: {
   460            title: t('router.EditDashboard'),
   461            // noTagsView: true,
   462            hidden: true,
   463            canTo: true,
   464            activeMenu: '/dashboards'
   465          }
   466        },
   467      ]
   468    },
   469    {
   470      path: '/logs',
   471      component: Develop,
   472      redirect: '/logs/index',
   473      meta: {
   474        title: t('router.Logs'),
   475      },
   476      children: [
   477        {
   478          path: 'index',
   479          name: 'Logs',
   480          component: () => import('@/views/Logs/index.vue'),
   481          meta: {
   482            title: t('router.Logs'),
   483            icon: 'icon-park-outline:upload-logs'
   484          }
   485        }
   486      ]
   487    },
   488    {
   489      path: '/etc',
   490      component: Develop,
   491      meta: {
   492        title: t('router.etc'),
   493        icon: 'mdi:cog'
   494      },
   495      children: [
   496        {
   497          path: 'settings',
   498          component: Develop,
   499          meta: {
   500            title: t('router.Settings'),
   501          },
   502          children: [
   503            {
   504              path: 'main',
   505              name: 'Main',
   506              component: () => import('@/views/Settings/index.vue'),
   507              meta: {
   508                title: t('router.Main'),
   509              },
   510            },
   511            {
   512              path: 'plugins',
   513              name: 'Plugins',
   514              component: () => import('@/views/Plugins/index.vue'),
   515              meta: {
   516                title: t('router.Plugins'),
   517              },
   518              children: [
   519                {
   520                  path: 'edit/:name',
   521                  name: 'viewPlugin',
   522                  component: () => import('@/views/Plugins/edit.vue'),
   523                  props: true,
   524                  meta: {
   525                    title: t('router.EditPlugin'),
   526                    // noTagsView: true,
   527                    hidden: true,
   528                    canTo: true,
   529                  }
   530                }
   531              ]
   532            },
   533            {
   534              path: 'backups',
   535              name: 'Backups',
   536              component: () => import('@/views/Backups/index.vue'),
   537              meta: {
   538                title: t('router.Backups'),
   539              },
   540            },
   541          ],
   542        },
   543        {
   544          path: 'develop',
   545          component: Develop,
   546          meta: {
   547            title: t('router.Develop'),
   548          },
   549          children: [
   550            {
   551              path: 'tools',
   552              name: 'Tools',
   553              component: () => import('@/views/Tools/EventBus/index.vue'),
   554              meta: {
   555                title: t('router.Tools'),
   556              },
   557              children: [
   558              ]
   559            },
   560            {
   561              path: 'swagger',
   562              name: 'Swagger',
   563              component: () => import('@/views/Swagger/index.vue'),
   564              meta: {
   565                title: t('router.Swagger'),
   566              },
   567            },
   568            {
   569              path: 'typedoc',
   570              name: 'Typedoc',
   571              component: () => import('@/views/Typedoc/index.vue'),
   572              meta: {
   573                title: t('router.Typedoc'),
   574              },
   575            },
   576          ],
   577        },
   578        {
   579          path: 'variables',
   580          name: 'Variables',
   581          component: () => import('@/views/Variables/index.vue'),
   582          meta: {
   583            title: t('router.Variables'),
   584          },
   585          children: [
   586            {
   587              path: 'new',
   588              name: 'newVariable',
   589              component: () => import('@/views/Variables/new.vue'),
   590              meta: {
   591                title: t('router.New'),
   592                noTagsView: true,
   593                hidden: true,
   594                canTo: true,
   595                activeMenu: '/etc/variables'
   596              }
   597            },
   598            {
   599              path: 'edit/:name',
   600              name: 'editVariable',
   601              component: () => import('@/views/Variables/edit.vue'),
   602              props: true,
   603              meta: {
   604                title: t('router.EditVariable'),
   605                // noTagsView: true,
   606                hidden: true,
   607                canTo: true,
   608                activeMenu: '/etc/variables'
   609              }
   610            }
   611          ]
   612        },
   613        {
   614          path: 'images',
   615          name: 'Image browser',
   616          component: () => import('@/views/Images/index.vue'),
   617          meta: {
   618            title: t('router.Imagebrowser'),
   619          },
   620        },
   621        {
   622          path: 'areas',
   623          name: 'Areas',
   624          component: () => import('@/views/Areas/index.vue'),
   625          meta: {
   626            title: t('router.Areas'),
   627          },
   628          children: [
   629            {
   630              path: 'new',
   631              name: 'newArea',
   632              component: () => import('@/views/Areas/new.vue'),
   633              meta: {
   634                title: t('router.New'),
   635                noTagsView: true,
   636                hidden: true,
   637                canTo: true,
   638                activeMenu: '/etc/areas'
   639              }
   640            },
   641            {
   642              path: 'edit/:id',
   643              name: 'editArea',
   644              component: () => import('@/views/Areas/edit.vue'),
   645              props: true,
   646              meta: {
   647                title: t('router.EditArea'),
   648                // noTagsView: true,
   649                hidden: true,
   650                canTo: true,
   651                activeMenu: '/etc/areas'
   652              }
   653            }
   654          ]
   655        },
   656        {
   657          path: 'mqtt',
   658          name: 'Mqtt',
   659          component: () => import('@/views/Mqtt/index.vue'),
   660          meta: {
   661            title: t('router.Mqtt'),
   662          },
   663          children: [
   664            {
   665              path: 'index',
   666              name: 'indexMqtt',
   667              component: () => import('@/views/Mqtt/index.vue'),
   668              meta: {
   669                title: t('router.View'),
   670                // noTagsView: true,
   671                hidden: true,
   672                canTo: true,
   673                activeMenu: '/etc/plugins'
   674              }
   675            },
   676            {
   677              path: 'client/:id',
   678              name: 'viewMqttClient',
   679              component: () => import('@/views/Mqtt/client.vue'),
   680              props: true,
   681              meta: {
   682                title: t('router.View'),
   683                // noTagsView: true,
   684                hidden: true,
   685                canTo: true,
   686                activeMenu: '/etc/mqtt'
   687              }
   688            }
   689          ]
   690        },
   691        {
   692          path: 'zigbee2mqtt',
   693          name: 'Zigbee2mqtt',
   694          component: () => import('@/views/Zigbee2mqtt/index.vue'),
   695          meta: {
   696            title: t('router.Zigbee2mqtt'),
   697          },
   698          children: [
   699            {
   700              path: 'index',
   701              name: 'Zigbee2mqtt',
   702              component: () => import('@/views/Zigbee2mqtt/index.vue'),
   703              meta: {
   704                title: t('router.ListZigbee2mqtt'),
   705                // noTagsView: true,
   706                hidden: true,
   707                canTo: true,
   708                activeMenu: '/etc/zigbee2mqtt'
   709              }
   710            },
   711            {
   712              path: 'new',
   713              name: 'newZigbee2mqtt',
   714              component: () => import('@/views/Zigbee2mqtt/new.vue'),
   715              meta: {
   716                title: t('router.New'),
   717                noTagsView: true,
   718                hidden: true,
   719                canTo: true,
   720                activeMenu: '/etc/zigbee2mqtt'
   721              }
   722            },
   723            {
   724              path: 'edit/:id',
   725              name: 'editZigbee2mqtt',
   726              component: () => import('@/views/Zigbee2mqtt/edit.vue'),
   727              props: true,
   728              meta: {
   729                title: t('router.EditZigbee2mqtt'),
   730                // noTagsView: true,
   731                hidden: true,
   732                canTo: true,
   733                activeMenu: '/etc/zigbee2mqtt'
   734              }
   735            }
   736          ]
   737        },
   738        {
   739          path: 'users',
   740          name: 'Users',
   741          component: () => import('@/views/Users/index.vue'),
   742          meta: {
   743            title: t('router.Users'),
   744          },
   745          children: [
   746            {
   747              path: 'new',
   748              name: 'newUser',
   749              component: () => import('@/views/Users/new.vue'),
   750              meta: {
   751                title: t('router.New'),
   752                noTagsView: true,
   753                hidden: true,
   754                canTo: true,
   755                activeMenu: '/etc/users'
   756              }
   757            },
   758            {
   759              path: 'edit/:id',
   760              name: 'editUser',
   761              component: () => import('@/views/Users/edit.vue'),
   762              props: true,
   763              meta: {
   764                title: t('router.EditUser'),
   765                // noTagsView: true,
   766                hidden: true,
   767                canTo: true,
   768                activeMenu: '/etc/users'
   769              }
   770            }
   771          ]
   772        },
   773        {
   774          path: 'message_delivery',
   775          name: 'MessageDelivery',
   776          component: () => import('@/views/MessageDelivery/index.vue'),
   777          meta: {
   778            title: t('router.MessageDelivery'),
   779          },
   780        }
   781      ]
   782    }
   783  ]
   784  
   785  const router = createRouter({
   786    history: createWebHashHistory(),
   787    strict: true,
   788    routes: constantRouterMap as RouteRecordRaw[],
   789    scrollBehavior: () => ({ left: 0, top: 0 })
   790  })
   791  
   792  export const resetRouter = (): void => {
   793    const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
   794    router.getRoutes().forEach((route) => {
   795      const { name } = route
   796      if (name && !resetWhiteNameList.includes(name as string)) {
   797        router.hasRoute(name) && router.removeRoute(name)
   798      }
   799    })
   800  }
   801  
   802  export const setupRouter = (app: App<Element>) => {
   803    app.use(router)
   804  }
   805  
   806  export default router