amis icon indicating copy to clipboard operation
amis copied to clipboard

当使用多个page里包含crud组件的页面作为app的子菜单时,切换导航会产生干扰导

Open belongwqz opened this issue 5 years ago • 4 comments

描述问题:

当使用多个page里包含crud组件的页面作为app的子菜单时,切换导航会产生干扰导

截图或视频:

可以的话,尽可能提供截图或视频来补充描述你的问题...

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的? sdk

  2. 粘贴有问题的完整 amis schema 代码:

首页调用方式为:

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>debug</title>
    
    <link rel="stylesheet" href="/static_om/amis/sdk/antd.css" >
    
    <link rel="stylesheet" href="/static_om/amis/sdk/helper.css" >
    <style>
        html, body, .app-wrapper {position: relative; width: 100%; height: 100%; margin: 0; padding: 0;}
    </style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="/static_om/amis/sdk/sdk.js"></script>
<script type="text/javascript">
    const app = {type: 'service', 'schemaApi': 'schema的api';
    const props = {};
    
    
    function normalizeLink(to, location = window.location) {
        to = to || "";
        if (to && to[0] === "#") {
            to = location.pathname + location.search + to;
        } else if (to && to[0] === "?") {
            to = location.pathname + to;
        }

        const idx = to.indexOf("?");
        const idx2 = to.indexOf("#");
        let pathname = ~idx ? to.substring(0, idx) : ~idx2 ? to.substring(0, idx2) : to;
        let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : "";
        let hash = ~idx2 ? to.substring(idx2) : location.hash;

        if (!pathname) {
            pathname = location.pathname;
        } else if (pathname[0] !== "/" && !/^https?\:\/\//.test(pathname)) {
            let relativeBase = location.pathname;
            const paths = relativeBase.split("/");
            paths.pop();
            let m;
            while ((m = /^\.\.?\//.exec(pathname))) {
                if (m[0] === "../") {
                    paths.pop();
                }
                pathname = pathname.substring(m[0].length);
            }
            pathname = paths.concat(pathname).join("/");
        }
        return pathname + search + hash;
    }
    const match = amisRequire("path-to-regexp").match;
    
    const env = {
        watchRouteChange: (fn) => {
            window.addEventListener("hashchange", fn);
            return () => {
                window.removeEventListener("hashchange", fn);
            };
        },
        jumpTo: (to) => {location.hash = to;},
        isCurrentUrl: (to, ctx) => {
          if (!to) {
            return false;
          }
          const pathname = location.hash ? location.hash.substring(1) : "/";
          const link = normalizeLink(to, {...location, pathname, hash: ""});

          if (!~link.indexOf("http") && ~link.indexOf(":")) {
              let strict = ctx && ctx.strict;
              return match(link, {
                  decode: decodeURIComponent, strict: typeof strict !== "undefined" ? strict : true
              })(pathname);
          }

          return pathname === link;
        },
        theme: 'antd'
    };
    amisRequire('amis/embed').embed('#root', app, props, env)</script>
</body>
</html>

首页schema:

{
  "type": "app",
  "brandName": "my system",
  "header": {
    "type": "tpl",
    "inline": false,
    "className": "w-full",
    "tpl": "abc"
  },
  "pages": [
    {
      "children": [
        {
          "label": "page_a",
          "isDefaultPage": true,
          "url": "/page_a/",
          "schemaApi": "page_a_config_api"
        },
        {
          "label": "page_b",
          "url": "/page_b/",
          "schemaApi": "page_b_config_api"
        }
      ]
    }
  ]
}

页面A的schema:

{
  "type": "page_a",
  "title": "页面A",
  "body": [
    {
      "type": "crud",
      "api": "get_page_a_data_api",
      "columns": [xxx]
    }
  ]
}

页面B的schema:

{
  "type": "page_b",
  "title": "页面B",
  "body": [
    {
      "type": "crud",
      "api": "get_page_b_data_api",
      "columns": [xxx]
    }
  ]
}
  1. 操作步骤

1、上述app页面(使用hash模式导航),在页面A和页面B之间切换,浏览器F12观察网络请求。

2、发现点击“页面A”的时候发起了页面B的get_page_b_data_api请求,点击"页面B"则发起了页面A的get_page_a_data_api请求。

3、观察发现,在几个crud的页面之间切换时api请求会如前面两步一样错位(前端页面正常显示,但是crud里的api调用会错位),如果是crud页面和其他类型的页面之间切换则不会有问题。

4、不使用app导航二单独去访问页面A和页面B都正常。

@nwind

belongwqz avatar Mar 05 '21 05:03 belongwqz

I can confirm this issue. I have the same problem. Switching between crud pages will result in two networks requests, one for the current page and one for the page I try to open.

abasse avatar Mar 09 '21 17:03 abasse

同问题,蹲一波解决方式

subei12 avatar Mar 31 '21 14:03 subei12

先用 1.1.6-beta.20

RickCole21 avatar Apr 20 '21 13:04 RickCole21

啥时发布新版本呢?

belongwqz avatar Apr 20 '21 23:04 belongwqz