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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@uiw-admin/authorized

v6.1.9

Published

authorized

Downloads

14

Readme

权限组件

npm version

判断组件的权限

何时使用

当项目需要根据权限判断组件是否展示 使用组件时,请在 .kktprc.js文件中配置全局变量

export default {
  define:{
+   AUTH:true,
    //  ...
  }
  //  ...
}

安装

npm i @uiw-admin/authorized --save # yarn add @uiw-admin/authorized

AuthPage

可用于页面重定向

参数说明

| 参数 | 必填 | 类型 | 默认值 | 说明 | | :----------- | :--- | :------------ | :------- | :--------------- | | authority | 否 | boolean | | 判断是否有权限展示内容 | | redirectPath | 否 | string | /login | 未登录重定向路径 | | children | 是 | JSX.Element | | 是否已经登录 |


import AuthPage  from "@uiw-admin/authorized"
export default ()=>{
  return <AuthPage authority={false} redirectPath="/login">展示</AuthPage>
}

getAuthPath

判断是否有权限

type getAuthPath = (path?: string)=>boolean 

import {getAuthPath}  from "@uiw-admin/authorized"

const isAuth = getAuthPath("/api/path")

AuthBtn

外层嵌套 组件,判断子组件是否有权限展示或使用

参数说明

| 参数 | 说明 | 必填 | 类型 | 默认值 | | :--- | :--- | :--- | :--- | :--- | | path | 路径 | 否 | string | - | | disabled | 禁用 状态 展示(适用于 存在 disabled 属性的组件) | 否 | boolean | false | | children | 内容 | 是 | React.ReactNode | - |


window.AUTH = true // 是否开启权限校验
window.STORAGE = "session" // 本地存储数据方式
// 上面这两种变量可以在`.kktprc.js`文件中配置全局变量(`define`)
sessionStorage.setItem('auth',JSON.stringify(["/dom/save","/dom/edit"])) // 权限数据
// 以上数据只能为了能正常渲染设置的变量

import React from "react"
import { AuthBtn } from "@uiw-admin/authorized"
import { createRoot } from 'react-dom';

const Demos = ()=>{
  return (
   <div>
     <AuthBtn path="/dom/save" >
       子集渲染1
     </AuthBtn>
     <AuthBtn path="/dom/edit" disabled >
       <button>子集渲染2</button>
     </AuthBtn>
      <AuthBtn path="/dom/edit1" disabled >
       <button>子集渲染3</button>
     </AuthBtn>
      <AuthBtn path="/dom/edit1"  >
       <button>子集渲染4</button>
     </AuthBtn>
   </div>
  )
}
createRoot(_mount_).render(<Demos />);

贡献者

感谢所有的贡献者,欢迎开发者为开源项目贡献力量。

License

Licensed under the MIT License.