Giter Site home page Giter Site logo

如何实现全局拦截器呢? about amis HOT 9 CLOSED

baidu avatar baidu commented on April 26, 2024
如何实现全局拦截器呢?

from amis.

Comments (9)

2betop avatar 2betop commented on April 26, 2024 2

所有的请求都走 fetcher , fetcher 里面加个 then 用来做拦截就行。

from amis.

g770728y avatar g770728y commented on April 26, 2024

感觉这个需求是个伪需求, 理由如下:

  1. 对于无权限的菜单, 不显示 ( 在实操中, 菜单是由后台根据权限列出来的 )
  2. 对于无权限的按钮, 不显示 , 或置灰.
  3. 对于无权限的数据, 完全是后台控制, 前台根本没有控制权

所以, 貌似在 " 正常操作 " 流程下, 并不会涉及到 " 需要跳转到 无权限页面 " 这种操作 ?


所以我们考虑 " 非正常操作":
如果用户通过浏览器地址栏 , 跳转到某个前台路由, 而这个路由是没有权限访问的
这时, 我们有两种策略:

  1. 用户可以看到页面, 但由于数据权限控制在后台, 因此他进入页面可能会看到空白界面 + 越权提示, 也无法保存
  2. 控制 react router 的路由, 当出现 越权访问时, 重定向到 403 页面.

考虑前端路由并不安全, 所以本质上, 方式2 与 方式1是一回事, 只是用户体验更好.
对于一般的 企业内部应用, 感觉第一种策略就够用了, 实际使用中也基本不会遇到问题.

不知是否正确?

from amis.

Soar360 avatar Soar360 commented on April 26, 2024

如果服务端更新权限,接口会返回403错误码或其他形式,此时就需要提示用户进行重新登录之类的操作。所以,拦截,或者说过滤器是很必要的。

from amis.

Songziyuan avatar Songziyuan commented on April 26, 2024

所有的请求都走 fetcher , fetcher 里面加个 then 用来做拦截就行。

你好,是在App.tsx里添加then么?
如果不是的话,能否告知是在哪里添加呢?或者有没有一个demo可以参考,amis-admin这个demo里,没有找到类似的写法

from amis.

2betop avatar 2betop commented on April 26, 2024

在这 补个 then 就可以了 https://github.com/fex-team/amis-admin/blob/master/App.tsx#L44

from amis.

Songziyuan avatar Songziyuan commented on April 26, 2024

在这 补个 then 就可以了 https://github.com/fex-team/amis-admin/blob/master/App.tsx#L44

成功了,感谢你!
image

from amis.

renpengben avatar renpengben commented on April 26, 2024

jssdk 怎么实现啊?

from amis.

ZainCheung avatar ZainCheung commented on April 26, 2024

jssdk 怎么实现啊?

同问

from amis.

qiu-1231 avatar qiu-1231 commented on April 26, 2024

jssdk 怎么实现啊?

有结果了吗,同问

from amis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.