兰宝车间质量管理系统-前端
疯狂的狮子Li
2023-10-09 a2f13185e18c274d80cadade406e2b47253b038a
src/components/HeaderSearch/index.vue
@@ -12,7 +12,8 @@
      class="header-search-select"
      @change="change"
    >
      <el-option v-for="option in options" :key="option.item.path" :value="option.item" :label="option.item.title.join(' > ')" />
      <el-option v-for="option in options" :key="option.item.path" :value="option.item"
                 :label="option.item.title.join(' > ')"/>
    </el-select>
  </div>
</template>
@@ -51,12 +52,17 @@
}
const change = (val: any) => {
    const path = val.path;
  const query = val.query;
    if (isHttp(path)) {
        // http(s):// 路径新窗口打开
        const pindex = path.indexOf("http");
        window.open(path.substr(pindex, path.length), "_blank");
    } else {
    if (query) {
      router.push({ path: path, query: JSON.parse(query) });
    } else {
        router.push(path)
    }
    }
    search.value = ''
    options.value = []
@@ -82,7 +88,7 @@
}
// Filter out the routes that can be displayed in the sidebar
// And generate the internationalized title
const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: string[] = []) => {
const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: string[] = [], query: any = {}) => {
    let res: Router = []
    routes.forEach(r => {
        // skip hidden router
@@ -90,7 +96,8 @@
            const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path;
            const data = {
                path: !isHttp(r.path) ? getNormalPath(basePath + p) : r.path,
                title: [...prefixTitle]
        title: [...prefixTitle],
        query: ''
            }
            if (r.meta && r.meta.title) {
                data.title = [...data.title, r.meta.title];
@@ -100,9 +107,14 @@
                    res.push(data);
                }
            }
      if (r.query) {
        data.query = r.query
      }
            // recursive child routes
            if (r.children) {
                const tempRoutes = generateRoutes(r.children, data.path, data.title);
        const tempRoutes = generateRoutes(r.children, data.path, data.title, data.query);
                if (tempRoutes.length >= 1) {
                    res = [...res, ...tempRoutes];
                }