npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flow-ui-auth

v1.0.0

Published

An auth component for react

Readme

react-auth

v1.0.0


安装

npm install @terminus/react-auth --save

使用方法

  • AuthProvider

    最外层容器

    参数:

      value(object) : {
        auth: [], // 当前拥有权限
        allAuth: [], // 所有权限集合
        strict: false, // 严格模式,默认 false
      }
    • 严格模式下当前资源必要在 auth 中才会显示
    • 非严格模式下当前资源在 auth 中或不在 allAuth 中即可显示
  • AuthConsumer

    权限点容器

    参数:

    • name(string): 资源点标识

    静态方法:

    • True:用于包裹匹配权限点的内容
    • False:用于包裹未匹配权限点时的内容
  • AuthWrapper

    HOC,向组件内传入参数authList,可以配合hasAuth方法,实现非JSX的逻辑

  • flatten

    用于解析传入资源文件,返回资源点集合

      const { apis, operations } = flatten(resoucres: Array)
    • apis: api类型的资源点
    • operations: 其他资源点
  • hasAuth

    权限判断逻辑,需要传入资源集合和当前权限点,支持传入扩展逻辑判断方法,可单独使用

      hasAuth(list: Array, name: String[, onAuth: Function])
    
      return Boolean

例子

资源文件

module.exports = () => ({
  productKey: 'cp-source',
  productName: '供应链寻源招投标',
  description: '供应链寻源招投标(包含招标、竞价、询价、答疑、保证金、标管理)',
  resources: [
    {
      type: 'menu',
      name: '寻源管理',
      permissions: [],
      data: {
        icon: 'xunyuanguanli',
      },
      children: [
        {
          name: '招标管理',
          permissions: [],
          type: 'menu',
          data: {
            link: '/bid/list',
          },
          key: 'bid-manage',
          title: 'dashboard.sider.bidManage',
          description: '招标管理',
          children: [
            {
              name: '查看标详情',
              type: 'operation',
              key: 'bid.list.detail'
            }
          ]
        },
        {
          name: '询价管理',
          permissions: [],
          type: 'menu',
          data: {
            link: '/inquiry/list',
          },
          key: 'inquiry-manage',
          title: 'dashboard.sider.inquiryManage',
          description: '询价管理',
        },
      ],
      key: 'source-manage',
      title: 'dashboard.sider.sourceManage',
      description: '寻源管理',
    },
  ],
})

Provider

import React from 'react'
import { AuthProvider, flatten } from '@terminus/react-auth'
import resources from 'files/auth'

class App extends React.Component {
  render () {
    return (
      <AuthProvider value={flatten(resources)}>
        ...
      </AuthProvider>
    )
  }
}

Consumer

import React from 'react'
import { AuthConsumer } from '@terminus/react-auth'

// 单独使用
class Component extends React.Component {
  render () {
    return (
      <AuthConsumer name="bid.list.detail">
        ... // 有权限时
      </AuthConsumer>
    )
  }
}

// 配合 True, False
const { True, False } = AuthConsumer

class Component extends React.Component {
  render () {
    return (
      <AuthConsumer name="bid.list.detail">
        <True>
          ... // 有权限时
        </True>
        <False>
          ... // 无权限时
        </False>
      </AuthConsumer>
    )
  }
}

AuthWrapper

import React from 'react'
import { AuthWrapper, hasAuth } from '@terminus/react-auth'
import { Input } from 'antd'

@AuthWrapper
class Component extends React.Component {
  render () {
    return (
      <Input
        disable={hasAuth(this.props.authList, 'bid.setup.edit')}
      />
    )
  }
}