actionType为link的时候 会刷新浏览器
{
"$schema": "https://houtai.baidu.com/v2/schemas/page.json",
"type": "page",
"title": "大禹容器管理平台",
"body": [
{
"type": "form",
"target": "main",
"mode": "inline",
"submitOnInit": true,
"wrapWithPanel": false,
"controls": [
{
"name": "page",
"type": "button-group",
"label": false,
"value": "service",
"submitOnChange": true,
"options": [
{
"label": "仪表板",
"value": "dashboard"
},
{
"label": "节点",
"value": "node"
},
{
"label": "编排",
"value": "stack"
},
{
"label": "服务",
"value": "service"
},
{
"label": "任务",
"value": "task"
}
]
},
{
"type": "button",
"label": "刷新",
"level": "success",
"align": "right",
"actionType": "reload",
"target": "main"
}
]
},
{
"type": "divider"
},
{
"name": "main",
"type": "service",
"initFetchSchema": false,
"schemaApi": "get:/page/manager/${page}"
}
]
}
/page/manager/dashboard 返回的结果是
{
"$schema": "https://houtai.baidu.com/v2/schemas/crud.json",
"api": "/dashboard/cards",
"type": "crud",
"mode": "cards",
"loadDataOnce": true,
"syncLocation": false,
"card": {
"header": {
"title": "${title}",
"subTitle": "${subTitle|raw}"
},
"body": "${body}",
"actions": [
{
"type": "button",
"label": "前往",
"syncLocation": false,
"actionType": "link",
"link": "/?page=${name}"
}
]
}
}
我想用下层的页面 修改上层的那个page变量 然后跳转页面
发下配置
@RickCole21
https://frp-dayu-temp.miaowoo.cc/ 这个是展示页面
@RickCole21 有时间麻烦帮忙看下
JSSDK 跳转默认不是单页的,需要传入 env.updateLocation 和 env.jumpTo
可以参考这个:https://github.com/baidu/amis/blob/master/examples/components/SchemaRender.jsx#L79-L94
@2betop emm 好像JSSDK没有路由的概念?
那我问下 JSSDK有没有全局的State对象
然后我直接修改这个对象能不能改下我上面例子里面的${page} 然后触发跳转
是没有路由的概念,你想要上面切换的时候自动提交,只需要给 form 配置 submitOnChange: true
自动提交那个我知道 现在问题是 下面的页面 点击跳转 怎么修改上面的
{
"$schema": "https://houtai.baidu.com/v2/schemas/crud.json",
"api": "/dashboard/cards",
"type": "crud",
"mode": "cards",
"loadDataOnce": true,
"syncLocation": false,
"card": {
"header": {
"title": "${title}",
"subTitle": "${subTitle|raw}"
},
"body": "${body}",
"actions": [
{
"type": "button",
"label": "前往",
"syncLocation": false,
"actionType": "link",
"link": "/?page=${name}"
}
]
}
}
你可以看下这个页面 https://frp-dayu-temp.miaowoo.cc/
你现在不是已经修改了吗?你是担心spa模式不行?结果应该都是一样的。
现在点击仪表板的下面的前往 是直接跳转的
我想这里可以实现上面一样的跳转

哦,你可以给 form 的 target 设置成 "window" ,是把数据发送给地址栏。下面的 service 应该会自动重新拉取。
下面的前往按钮我用的是Card的Action
这样的话 是不是要自己写一个form 然后把值传递到上面的Form
啥意思啊,到底是要谁跟谁一样呢?
下面的 card 你是配置的 actionType: "link" 这就是页面跳转的一种,把数据会同步到地址栏,然后 form 里面会自动被更新到,你啥也不用做。目前对于 sdk 版本 link 类型貌似跟url 类型是一样,是因为不确定目标框架是否存在单页路由,所以固定就是页面跳转,如果你想实现单页跳转,前面其实已经回复你了,env.updateLocation 和 e.jumpTo 作为第三个参数传入即可。
上面的 form 其实是配置 target 为下面的 service, 切换的时候,下面的 service 会重新拉取。这种方式没有修改地址栏,我之前以为你是想让跟下面的按钮的效果一样要修改地址栏,如果确实是要这么做,就把 target 配置成 window 即可。
就是点击下面的前往按钮 不刷新页面 直接更新service内容 效果和上面的点击切换一样
actionType: "link" 怎么做到不刷新
env.updateLocation 和 e.jumpTo 你给我的那个代码链接
里面是有route这些变量的没法用
我用的是JSSDK
这样吧 我截图描述一下
我希望 前往 这个按钮的点击效果和点击 节点 这个效果一样
我能找到通过Action刷新数据的方法 只有 link 但是 link 又会刷新页面
能不能 不刷新页面 达到这种效果
你上面说的 env.updateLocation 和 e.jumpTo 作为第三个参数传入 JSSDK 怎么写
(async function() {
let amis = amisRequire('amis/embed');
let page = window.location.hash.substring(1) || 'main';
let root = amis.embed('#root', {
type: "service",
schemaApi: "get:/page/manager/" + page
}, {}, {
updateLocation: (location, replace) => {
console.log("updateLocation", location, replace)
},
jumpTo: to => {
console.log("jumpTo", to)
window.location.replace(to);
},
});
console.log(root)
})();
因为 JSSDK 没有 router 所以我也没法复制你提供的那几行代码
供参考
{
updateLocation: (to, replace) => {
switch (to) {
case 'goBack':
return window.history.back();
case 'goHome':
return window.location.replace('/');
}
const location = window.location;
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;
window.history.pushState(null, '', pathname + search + hash);
}
}
@faceair link 触发的好像是 jumpTo 麻烦问下要怎么修改
@faceair link 触发的好像是 jumpTo 麻烦问下要怎么修改
应该没啥区别,改下函数名就是了
@faceair 加了之后 好像连跳转都不会了
点击 link 之后 url 已经改变了,看起来是 reload 没生效,或者 reload service 拿不到 url query 的参数,这个我就解答不了了 cc @2betop
