Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aside中badge 动态设置数据 #10135

Open
kscale opened this issue Apr 29, 2024 · 0 comments
Open

aside中badge 动态设置数据 #10135

kscale opened this issue Apr 29, 2024 · 0 comments

Comments

@kscale
Copy link

kscale commented Apr 29, 2024

实现场景:

使用amis-admin,我想要实现aside中badge 动态设置数据的功能,比如api获得数据,怎么用动态设置数据.
尤其是表格数据更新后,aside中badge 数据会变更。

存在的问题:

我目前的方法
是在index.html中 data: {
// 全局数据,是受控的数据
testdata_1: "8" //这个数据是传到site.json 用来设置badge, "badge": "${testdata_1}",
},

当前方案:

      let amisInstance = amis.embed(
        '#root',
        app,
        {
          location: history.location,
          data: {
            // 全局数据,是受控的数据
            testdata_1: "8"     //这个数据是传到site.json 用来设置badge,  "badge": "${testdata_1}",
          },
          context: {
            // 全局上下文数据, 非受控的数据,无论哪一层都能获取到,包括弹窗自定义数据映射后都能获取到。
            // 可以用来放一下全局配置等。比如 API_HOST, 这样页面配置里面可以通过 ${API_HOST} 来获取到。
            API_HOST: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com',
          }
        },
        {
          // watchRouteChange: fn => {
          //   return history.listen(fn);
          // },
          updateLocation: (location, replace) => {
            location = normalizeLink(location);
            if (location === 'goBack') {
              return history.goBack();
            } else if (
              (!/^https?\:\/\//.test(location) &&
                location ===
                history.location.pathname + history.location.search) ||
              location === history.location.href
            ) {
              // 目标地址和当前地址一样,不处理,免得重复刷新
              return;
            } else if (/^https?\:\/\//.test(location) || !history) {
              return (window.location.href = location);
            }

            history[replace ? 'replace' : 'push'](location);
          },
          jumpTo: (to, action) => {
            if (to === 'goBack') {
              return history.goBack();
            }

            to = normalizeLink(to);

            if (isCurrentUrl(to)) {
              return;
            }

            if (action && action.actionType === 'url') {
              action.blank === false
                ? (window.location.href = to)
                : window.open(to, '_blank');
              return;
            } else if (action && action.blank) {
              window.open(to, '_blank');
              return;
            }

            if (/^https?:\/\//.test(to)) {
              window.location.href = to;
            } else if (
              (!/^https?\:\/\//.test(to) &&
                to === history.pathname + history.location.search) ||
              to === history.location.href
            ) {
              // do nothing
            } else {
              history.push(to);
            }
          },
          isCurrentUrl: isCurrentUrl,
          theme: 'cxd'
        }
      );
     {
            "label": "页面B",
            "badge":"${testdata_1}",
            "badgeClassName": "bg-info",
            "schema": {
              "type": "page",
              "title": "页面B",
              "body": "页面B"
            }
          },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant